From 7b3fde81b625431000da82fe2d524989448835c5 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Fri, 12 Jan 2018 02:02:15 +0100 Subject: FFMPEG decavcodec: Consider returned error from av_buffersrc_add_frame(..) --- libhb/decavcodec.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libhb/decavcodec.c b/libhb/decavcodec.c index 9838a0b51..8b5d367cc 100644 --- a/libhb/decavcodec.c +++ b/libhb/decavcodec.c @@ -1294,8 +1294,12 @@ static void filter_video(hb_work_private_t *pv) { int result; - av_buffersrc_add_frame(pv->video_filters.input, pv->frame); - result = av_buffersink_get_frame(pv->video_filters.output, pv->frame); + result = av_buffersrc_add_frame(pv->video_filters.input, pv->frame); + if (result < 0) { + hb_error("filter_video: failed to add frame"); + } else { + result = av_buffersink_get_frame(pv->video_filters.output, pv->frame); + } while (result >= 0) { hb_buffer_t * buf = copy_frame(pv); -- cgit v1.2.3 From c82905d5ad6e28eadab3beefc9ac186ea55ad3cc Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Fri, 12 Jan 2018 01:53:01 +0100 Subject: FFMPEG: Use avcodec_free_context(..) instead of deprecated leaking avcodec_close(..) Hence rename hb_avcodec_close -> hb_avcodec_free_context and pass the required ptr-ptr. avcodec_free_context(..) ensures releasing of all resources attached to the context. --- libhb/decavcodec.c | 13 ++++--------- libhb/decpgssub.c | 2 +- libhb/encavcodec.c | 9 +++++---- libhb/encavcodecaudio.c | 6 +++--- libhb/hb.c | 6 ++---- libhb/hbffmpeg.h | 2 +- 6 files changed, 16 insertions(+), 22 deletions(-) diff --git a/libhb/decavcodec.c b/libhb/decavcodec.c index 8b5d367cc..836c7f1be 100644 --- a/libhb/decavcodec.c +++ b/libhb/decavcodec.c @@ -390,13 +390,12 @@ static void closePrivData( hb_work_private_t ** ppv ) //if (!(pv->qsv.decode && pv->job != NULL && (pv->job->vcodec & HB_VCODEC_QSV_MASK))) #endif { - hb_avcodec_close(pv->context); + hb_avcodec_free_context(&pv->context); } } if ( pv->context ) { - av_freep( &pv->context->extradata ); - av_freep( &pv->context ); + hb_avcodec_free_context(&pv->context); } hb_audio_resample_free(pv->resample); @@ -821,9 +820,7 @@ static int decavcodecaBSInfo( hb_work_object_t *w, const hb_buffer_t *buf, if ( parser != NULL ) av_parser_close( parser ); - hb_avcodec_close( context ); - av_freep( &context->extradata ); - av_freep( &context ); + hb_avcodec_free_context(&context); return result; } @@ -2105,9 +2102,7 @@ static void decavcodecvFlush( hb_work_object_t *w ) if ( pv->title->opaque_priv == NULL ) { pv->video_codec_opened = 0; - hb_avcodec_close( pv->context ); - av_freep( &pv->context->extradata ); - av_freep( &pv->context ); + hb_avcodec_free_context(&pv->context); if ( pv->parser ) { av_parser_close(pv->parser); diff --git a/libhb/decpgssub.c b/libhb/decpgssub.c index c3621428b..463c3b9e4 100644 --- a/libhb/decpgssub.c +++ b/libhb/decpgssub.c @@ -502,7 +502,7 @@ static void decsubClose( hb_work_object_t * w ) { hb_work_private_t * pv = w->private_data; avcodec_flush_buffers( pv->context ); - avcodec_close( pv->context ); + avcodec_free_context( &pv->context ); } hb_work_object_t hb_decpgssub = diff --git a/libhb/encavcodec.c b/libhb/encavcodec.c index 9960a21b4..d9ea805ea 100644 --- a/libhb/encavcodec.c +++ b/libhb/encavcodec.c @@ -399,12 +399,13 @@ void encavcodecClose( hb_work_object_t * w ) return; } hb_chapter_queue_close(&pv->chapter_queue); - if( pv->context && pv->context->codec ) + if( pv->context ) { hb_deep_log( 2, "encavcodec: closing libavcodec" ); - avcodec_flush_buffers( pv->context ); - hb_avcodec_close( pv->context ); - av_free( pv->context ); + if( pv->context->codec ) { + avcodec_flush_buffers( pv->context ); + } + hb_avcodec_free_context(&pv->context); } if( pv->file ) { diff --git a/libhb/encavcodecaudio.c b/libhb/encavcodecaudio.c index 480d1e684..544cd3304 100644 --- a/libhb/encavcodecaudio.c +++ b/libhb/encavcodecaudio.c @@ -308,10 +308,10 @@ static void encavcodecaClose(hb_work_object_t * w) { Finalize(w); hb_deep_log(2, "encavcodecaudio: closing libavcodec"); - if (pv->context->codec != NULL) + if (pv->context->codec != NULL) { avcodec_flush_buffers(pv->context); - hb_avcodec_close(pv->context); - av_free( pv->context ); + } + hb_avcodec_free_context(&pv->context); } if (pv->output_buf != NULL) diff --git a/libhb/hb.c b/libhb/hb.c index f35090e38..112b5f5c6 100644 --- a/libhb/hb.c +++ b/libhb/hb.c @@ -140,11 +140,9 @@ int hb_avcodec_open(AVCodecContext *avctx, AVCodec *codec, return ret; } -int hb_avcodec_close(AVCodecContext *avctx) +void hb_avcodec_free_context(AVCodecContext **avctx) { - int ret; - ret = avcodec_close(avctx); - return ret; + avcodec_free_context(avctx); } diff --git a/libhb/hbffmpeg.h b/libhb/hbffmpeg.h index 76ffbe830..a148a6901 100644 --- a/libhb/hbffmpeg.h +++ b/libhb/hbffmpeg.h @@ -24,7 +24,7 @@ void hb_avcodec_init(void); int hb_avcodec_open(AVCodecContext *, AVCodec *, AVDictionary **, int); -int hb_avcodec_close(AVCodecContext *); +void hb_avcodec_free_context(AVCodecContext **avctx); const char* const* hb_av_preset_get_names(int encoder); uint64_t hb_ff_mixdown_xlat(int hb_mixdown, int *downmix_mode); -- cgit v1.2.3