From d69021326922bc2029f25858460ff4f5e245f89c Mon Sep 17 00:00:00 2001 From: Ukn Unknown <4031821+uknunknown@users.noreply.github.com> Date: Tue, 17 Jun 2025 17:19:34 -0700 Subject: [PATCH] vaapi improvements - remove all '=NULL' because are not required - keep first call for vaapi_encode_close_context() and remove the second call --- src/transcoding/transcode/context.c | 1 - src/transcoding/transcode/hwaccels/vaapi.c | 11 +++++------ src/transcoding/transcode/transcoder.c | 1 + 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/transcoding/transcode/context.c b/src/transcoding/transcode/context.c index 09f935ed7..6d939e8f0 100644 --- a/src/transcoding/transcode/context.c +++ b/src/transcoding/transcode/context.c @@ -756,7 +756,6 @@ void tvh_context_destroy(TVHContext *self) { if (self) { - tvh_context_close(self, 0); TVHPKT_CLEAR(self->src_pkt); if (self->avfltgraph) { avfilter_graph_free(&self->avfltgraph); // frees filter contexts diff --git a/src/transcoding/transcode/hwaccels/vaapi.c b/src/transcoding/transcode/hwaccels/vaapi.c index 9174b7e70..15473773e 100644 --- a/src/transcoding/transcode/hwaccels/vaapi.c +++ b/src/transcoding/transcode/hwaccels/vaapi.c @@ -50,7 +50,6 @@ tvhva_context_destroy(TVHVAContext *self) if (self) { if (self->hw_device_ref) { av_buffer_unref(&self->hw_device_ref); - self->hw_device_ref = NULL; } free(self); self = NULL; @@ -676,7 +675,6 @@ vaapi_decode_close_context(AVCodecContext *avctx) #if ENABLE_FFMPEG4_TRANSCODING if (avctx->hw_device_ctx) { av_buffer_unref(&avctx->hw_device_ctx); - avctx->hw_device_ctx = NULL; } #endif tvhva_context_destroy(ctx->hw_accel_ictx); @@ -820,16 +818,17 @@ void vaapi_encode_close_context(AVCodecContext *avctx) { TVHContext *ctx = avctx->opaque; - av_buffer_unref(&ctx->hw_device_octx); - ctx->hw_device_octx = NULL; + // hw_device_octx is initialized for software decoding (line 764) + if (ctx->hw_device_octx) { + av_buffer_unref(&ctx->hw_device_octx); + } #if ENABLE_FFMPEG4_TRANSCODING + // avctx->hw_device_ctx is cleaned up only if ffmpeg exit with error and didn't perform the clean up if (avctx->hw_device_ctx) { av_buffer_unref(&avctx->hw_device_ctx); - avctx->hw_device_ctx = NULL; } if (avctx->hw_frames_ctx) { av_buffer_unref(&avctx->hw_frames_ctx); - avctx->hw_frames_ctx = NULL; } #endif } diff --git a/src/transcoding/transcode/transcoder.c b/src/transcoding/transcode/transcoder.c index d3657681d..52fe227c6 100644 --- a/src/transcoding/transcode/transcoder.c +++ b/src/transcoding/transcode/transcoder.c @@ -294,6 +294,7 @@ tvh_transcoder_stream(void *opaque, tvh_sm_t *msg) streaming_target_deliver2(self->output, msg); break; case SMT_STOP: + // this will trigger tvh_context_close_meth() tvh_transcoder_stop(self, 1); /* !!! FALLTHROUGH !!! */ default: -- 2.47.3