示例#1
0
        public override bool Decode(Packet packet, Frame outFrame)
        {
            if (!(outFrame is AudioFrame audioFrame))
            {
                throw new ArgumentException($"{nameof(outFrame)}必须是{nameof(AudioFrame)}类型且不为null。");
            }

            if (packet != null)
            {
                int gotPicture = 0;
                FF.avcodec_decode_audio4(codecContext, outFrame.frame, &gotPicture, packet.packet).CheckFFmpegCode("音频解码发生错误");
                if (gotPicture == 0)
                {
                    return(false);
                }

                if (stream != null)
                {
                    outFrame.presentTimestamp = new Timestamp(outFrame.frame->Pts, stream->TimeBase);
                }
                audioFrame.format = InFormat;
                if (resampler != null)
                {
                    resampler.InternalResample(audioFrame);                     // resample and update
                }
                else
                {
                    outFrame.UpdateFromNative();
                }
            }
            else if (resampler != null)
            {
                resampler.ResampleFinal(audioFrame);
                if (audioFrame.LineDataBytes == 0)
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }

            return(true);
        }