internal StreamContext(AVStream *stream, FFMPEGDecoder source) { _stream = stream; _source = source; var origCtx = _stream->codec; //find the corresponding codec _codec = ffmpeg.avcodec_find_decoder(origCtx->codec_id); if (_codec == null) { throw new NotSupportedException("This " + ffmpeg.av_get_media_type_string(origCtx->codec_type) + " codec is not supported by the current ffmpeg binaries!"); } //copy the context from ffmpeg (required because we don't own the other one) _codecCtx = ffmpeg.avcodec_alloc_context3(_codec); if (ffmpeg.avcodec_parameters_to_context(_codecCtx, _stream->codecpar) != 0) { throw new Exception("Couldn't copy stream parameters!"); } if (ffmpeg.avcodec_open2(_codecCtx, _codec, null) != 0) { throw new Exception("Couldn't copy the codec!"); } _decoded = ffmpeg.av_frame_alloc(); }
/// <summary> /// Called once for each audio stream /// </summary> internal AudioContext(AVStream *stream, FFMPEGDecoder source, AudioFormat resampleTarget) : base(stream, source) { _resampleTarget = resampleTarget; BufferCapacity = resampleTarget.SampleRate * resampleTarget.Channels * 4; _circBuf = new CircularBuffer(BufferCapacity); CreateAudio(); }