From: Henrik Gramner Date: Wed, 11 Oct 2017 15:58:36 +0000 (+0200) Subject: lavf: Upgrade to the new core decoding API X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0fe75403d7b40c0209c3df992632956292065cdc;p=libx264 lavf: Upgrade to the new core decoding API --- diff --git a/input/lavf.c b/input/lavf.c index 84d658fc..e3aa1e4e 100644 --- a/input/lavf.c +++ b/input/lavf.c @@ -28,9 +28,10 @@ #undef DECLARE_ALIGNED #include +#include +#include #include #include -#include #define FAIL_IF_ERROR( cond, ... ) FAIL_IF_ERR( cond, "lavf", __VA_ARGS__ ) @@ -101,31 +102,32 @@ static int read_frame_internal( cli_pic_t *p_pic, lavf_hnd_t *h, int i_frame, vi while( i_frame >= h->next_frame ) { - int finished = 0; - int ret = 0; - do - { - ret = av_read_frame( h->lavf, &pkt ); + int ret; - if( ret < 0 ) + while( (ret = avcodec_receive_frame( h->lavc, h->frame )) ) + { + if( ret == AVERROR(EAGAIN) ) { - av_init_packet( &pkt ); - pkt.data = NULL; - pkt.size = 0; + while( !(ret = av_read_frame( h->lavf, &pkt )) && pkt.stream_index != h->stream_id ) + av_packet_unref( &pkt ); + + if( ret ) + ret = avcodec_send_packet( h->lavc, NULL ); + else + { + ret = avcodec_send_packet( h->lavc, &pkt ); + av_packet_unref( &pkt ); + } } + else if( ret == AVERROR_EOF ) + return -1; - if( ret < 0 || pkt.stream_index == h->stream_id ) + if( ret ) { - if( avcodec_decode_video2( h->lavc, h->frame, &finished, &pkt ) < 0 ) - x264_cli_log( "lavf", X264_LOG_WARNING, "video decoding failed on frame %d\n", h->next_frame ); + x264_cli_log( "lavf", X264_LOG_WARNING, "video decoding failed on frame %d\n", h->next_frame ); + return -1; } - - if( ret >= 0 ) - av_packet_unref( &pkt ); - } while( !finished && ret >= 0 ); - - if( !finished ) - return -1; + } h->next_frame++; }