From 25803d8daa30bc8c113b72c7f11b831ca1bf249d Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Thu, 31 Jan 2013 21:10:45 +0100 Subject: video-decode: Fix the got_picture = 0 case We actually tried to read the same packet again, but that doesnt work, so lets just drop it.. --- src/video_decode.c | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/src/video_decode.c b/src/video_decode.c index 7ce6f42..b923f93 100644 --- a/src/video_decode.c +++ b/src/video_decode.c @@ -117,7 +117,7 @@ video_decode_get_frame(struct video_decode *_vd, struct video_frame **frame) struct video_decode_priv *vd = (struct video_decode_priv *) _vd; struct video_frame_priv *f; AVPacket packet; - int decoded, got_picture; + int decoded, got_picture = 0; int ret; if (*frame != NULL) { @@ -131,8 +131,6 @@ video_decode_get_frame(struct video_decode *_vd, struct video_frame **frame) packet.data = NULL; do { - if (packet.data != NULL) - av_free_packet(&packet); ret = av_read_frame(vd->fmt_ctx, &packet); if (ret < 0) { if (ret == AVERROR_EOF) { @@ -148,28 +146,25 @@ video_decode_get_frame(struct video_decode *_vd, struct video_frame **frame) #endif return -1; } - } while (packet.stream_index != vd->stream); - - do { + if (packet.stream_index == vd->stream) { #if DEBUG - printf("packet.data: %p, packet.siz: %d, packet.strm_idx: %d\n", - packet.data, packet.size, packet.stream_index); + printf("packet.data: %p, packet.siz: %d, packet.strm_idx: %d\n", + packet.data, packet.size, packet.stream_index); #endif - decoded = avcodec_decode_video2(vd->codec_ctx, f->frame, - &got_picture, &packet); - if (decoded < 0) { - fprintf(stderr, "Error while decoding frame!\n"); - return -2; - } + decoded = avcodec_decode_video2(vd->codec_ctx, f->frame, + &got_picture, &packet); + if (decoded < 0) { + fprintf(stderr, "Error while decoding frame!\n"); + return -2; + } + #if DEBUG - printf("bytes_decoded: %d, got_picture: %d\n", - decoded, got_picture); + printf("bytes_decoded: %d, got_picture: %d\n", + decoded, got_picture); #endif - - } while (got_picture == 0 && packet.size > 0); - av_free_packet(&packet); - if (got_picture == 0) - return -3; + } + av_free_packet(&packet); + } while (got_picture == 0); f->base.data = f->frame->data[0]; f->base.width = vd->codec_ctx->width; -- cgit