Rather than refactoring everything, add a function that resembles the avcodec_decode_audio4() API. --- avconv.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-)
diff --git a/avconv.c b/avconv.c index d878646..c74b4b8 100644 --- a/avconv.c +++ b/avconv.c @@ -1079,6 +1079,31 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p write_frame(of->ctx, &opkt, ost); } +static int decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt) +{ + int ret; + int consumed = 0; + + *got_frame = 0; + + // This relies on the fact that the decoder will not buffer additional + // packets internally, but returns AVERROR(EAGAIN) if there are still + // decoded frames to be returned. + ret = avcodec_send_packet(avctx, pkt); + if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) + return ret; + if (ret >= 0) + consumed = pkt->size; + + ret = avcodec_receive_frame(avctx, frame); + if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) + return ret; + if (ret >= 0) + *got_frame = 1; + + return consumed; +} + int guess_input_channel_layout(InputStream *ist) { AVCodecContext *dec = ist->dec_ctx; @@ -1109,7 +1134,7 @@ static int decode_audio(InputStream *ist, AVPacket *pkt, int *got_output) return AVERROR(ENOMEM); decoded_frame = ist->decoded_frame; - ret = avcodec_decode_audio4(avctx, decoded_frame, got_output, pkt); + ret = decode(avctx, decoded_frame, got_output, pkt); if (!*got_output || ret < 0) return ret; @@ -1200,8 +1225,7 @@ static int decode_video(InputStream *ist, AVPacket *pkt, int *got_output) return AVERROR(ENOMEM); decoded_frame = ist->decoded_frame; - ret = avcodec_decode_video2(ist->dec_ctx, - decoded_frame, got_output, pkt); + ret = decode(ist->dec_ctx, decoded_frame, got_output, pkt); if (!*got_output || ret < 0) return ret; @@ -1216,7 +1240,6 @@ static int decode_video(InputStream *ist, AVPacket *pkt, int *got_output) decoded_frame->pts = guess_correct_pts(&ist->pts_ctx, decoded_frame->pkt_pts, decoded_frame->pkt_dts); - pkt->size = 0; if (ist->st->sample_aspect_ratio.num) decoded_frame->sample_aspect_ratio = ist->st->sample_aspect_ratio; -- 2.7.0 _______________________________________________ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel