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
if (self) {
if (self->hw_device_ref) {
av_buffer_unref(&self->hw_device_ref);
- self->hw_device_ref = NULL;
}
free(self);
self = NULL;
#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);
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
}
streaming_target_deliver2(self->output, msg);
break;
case SMT_STOP:
+ // this will trigger tvh_context_close_meth()
tvh_transcoder_stop(self, 1);
/* !!! FALLTHROUGH !!! */
default: