From bfe47a1ba2b5ff0342e2e6caec8b57521b0ab1f7 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 19 Apr 2022 09:36:35 +0400 Subject: [PATCH] Clear hw_device_ctx in AVCodecContext. --- Telegram/SourceFiles/ffmpeg/ffmpeg_utility.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Telegram/SourceFiles/ffmpeg/ffmpeg_utility.cpp b/Telegram/SourceFiles/ffmpeg/ffmpeg_utility.cpp index 92ff5d68b..377876ff0 100644 --- a/Telegram/SourceFiles/ffmpeg/ffmpeg_utility.cpp +++ b/Telegram/SourceFiles/ffmpeg/ffmpeg_utility.cpp @@ -86,6 +86,8 @@ void PremultiplyLine(uchar *dst, const uchar *src, int intsCount) { } [[nodiscard]] bool InitHw(AVCodecContext *context, AVHWDeviceType type) { + AVCodecContext *parent = static_cast(context->opaque); + auto hwDeviceContext = (AVBufferRef*)nullptr; AvErrorWrap error = av_hwdevice_ctx_create( &hwDeviceContext, @@ -101,11 +103,13 @@ void PremultiplyLine(uchar *dst, const uchar *src, int intsCount) { "Trying \"%1\" hardware acceleration for \"%2\" decoder." ).arg(av_hwdevice_get_type_name(type) ).arg(context->codec->name)); - if (context->hw_device_ctx) { - av_buffer_unref(&context->hw_device_ctx); + if (parent->hw_device_ctx) { + av_buffer_unref(&parent->hw_device_ctx); } - context->hw_device_ctx = av_buffer_ref(hwDeviceContext); + parent->hw_device_ctx = av_buffer_ref(hwDeviceContext); av_buffer_unref(&hwDeviceContext); + + context->hw_device_ctx = parent->hw_device_ctx; return true; } @@ -294,6 +298,7 @@ CodecPointer MakeCodecPointer(CodecDescriptor descriptor) { if (descriptor.hwAllowed) { context->get_format = GetHwFormat; + context->opaque = context; } else { DEBUG_LOG(("Video Info: Using software \"%2\" decoder." ).arg(codec->name));