Exemple #1
0
    protected AudioFilter(MediaStream sourceStream, IEnumerator <AVFrameRef> source)
        : base(null)
    {
        _sourceStream = sourceStream;
        _source       = source;

        if (sourceStream.MediaType != AVMediaType.AVMEDIA_TYPE_AUDIO)
        {
            throw new ArgumentException("Source must be audio");
        }

        Current = new AVFrameRef {
            Value = ffmpeg.av_frame_alloc()
        };
    }
Exemple #2
0
    public bool MoveNext()
    {
        ffmpeg.av_frame_unref(_frame);
        ffmpeg.av_frame_unref(_receivedFrame);
        int error;

        do
        {
            try
            {
                do
                {
                    ffmpeg.av_packet_unref(_packet);
                    error = ffmpeg.av_read_frame(_formatContext, _packet);

                    if (error == ffmpeg.AVERROR_EOF)
                    {
                        break;
                    }

                    error.ThrowExceptionIfError();
                }while (_packet->stream_index != _streamIndex);

                error = ffmpeg.avcodec_send_packet(_codecContext, error == ffmpeg.AVERROR_EOF ? null : _packet);

                if (error != ffmpeg.AVERROR_EOF)
                {
                    error.ThrowExceptionIfError();
                }
            }
            finally
            {
                ffmpeg.av_packet_unref(_packet);
            }

            error = ffmpeg.avcodec_receive_frame(_codecContext, _frame);
        }while (error == ffmpeg.AVERROR(ffmpeg.EAGAIN));

        if (error == ffmpeg.AVERROR_EOF)
        {
            Current = default;
            return(false);
        }

        error.ThrowExceptionIfError();

        if (_codecContext->hw_device_ctx != null)
        {
            ffmpeg.av_hwframe_transfer_data(_receivedFrame, _frame, 0).ThrowExceptionIfError();
            Current = new AVFrameRef {
                Value = _receivedFrame
            };
        }
        else
        {
            Current = new AVFrameRef {
                Value = _frame
            };
        }

        return(true);
    }