Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
 static extern IntPtr op_open_callbacks(IntPtr source, ref _OpusFileCallbacks cb, IntPtr initial_data, IntPtr initial_bytes, out OpusError error);
Ejemplo n.º 4
0
 static extern IntPtr op_open_callbacks(IntPtr source, ref _OpusFileCallbacks cb, IntPtr initial_data, IntPtr initial_bytes, out OpusError error);