public OggOpusFile(Stream sourceStream, bool leaveOpen = false) { if (sourceStream == null || !sourceStream.CanRead) { throw new ArgumentException("fileStream must be a readable stream."); } _sourceStream = sourceStream; _leaveOpen = leaveOpen; _read = new ReadFunc(ReadCallback); _seek = new SeekFunc(SeekCallback); _tell = new TellFunc(TellCallback); var cb = new _OpusFileCallbacks() { read = Marshal.GetFunctionPointerForDelegate(_read), seek = _sourceStream.CanSeek ? Marshal.GetFunctionPointerForDelegate(_seek) : IntPtr.Zero, tell = _sourceStream.CanSeek ? Marshal.GetFunctionPointerForDelegate(_tell) : IntPtr.Zero, close = IntPtr.Zero, }; _handle = (IntPtr)this.GetHashCode(); lock (_streams) { _streams.Add(_handle, this); } OpusError error; _opusFile = op_open_callbacks(_handle, ref cb, IntPtr.Zero, IntPtr.Zero, out error); if (_opusFile == IntPtr.Zero) { throw new OpusException(error); } }
public OggOpusFile(Stream sourceStream, bool leaveOpen = false) { if (sourceStream == null || !sourceStream.CanRead) throw new ArgumentException("fileStream must be a readable stream."); _sourceStream = sourceStream; _leaveOpen = leaveOpen; _read = new ReadFunc(ReadCallback); _seek = new SeekFunc(SeekCallback); _tell = new TellFunc(TellCallback); var cb = new _OpusFileCallbacks() { read = Marshal.GetFunctionPointerForDelegate(_read), seek = _sourceStream.CanSeek ? Marshal.GetFunctionPointerForDelegate(_seek) : IntPtr.Zero, tell = _sourceStream.CanSeek ? Marshal.GetFunctionPointerForDelegate(_tell) : IntPtr.Zero, close = IntPtr.Zero, }; OpusError error; _opusFile = op_open_callbacks(IntPtr.Zero, ref cb, IntPtr.Zero, IntPtr.Zero, out error); if (_opusFile == IntPtr.Zero) throw new OpusException(error); }