[FFmpeg-devel] [PATCH 1/2] lavc/decode: recreate hw_frames_ctx instead of return if already exists
Linjie Fu
linjie.fu at intel.com
Sun Jul 7 19:38:38 EEST 2019
If hw_frames_ctx exists when calling ff_decode_get_hw_frames_ctx, it
is allowed to be recreated instead of just return.
Move hw_frames_ctx check outside ff_decode_get_hw_frames_ctx, and check
in relevant code.
Signed-off-by: Linjie Fu <linjie.fu at intel.com>
---
libavcodec/decode.c | 2 +-
libavcodec/dxva2.c | 8 +++++---
libavcodec/vdpau.c | 9 +++++----
3 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 6c31166..0863b82 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1230,7 +1230,7 @@ int ff_decode_get_hw_frames_ctx(AVCodecContext *avctx,
return AVERROR(ENOSYS);
if (avctx->hw_frames_ctx)
- return 0;
+ av_buffer_unref(&avctx->hw_frames_ctx);
if (!avctx->hw_device_ctx) {
av_log(avctx, AV_LOG_ERROR, "A hardware frames or device context is "
"required for hardware accelerated decoding.\n");
diff --git a/libavcodec/dxva2.c b/libavcodec/dxva2.c
index 3241611..0404064 100644
--- a/libavcodec/dxva2.c
+++ b/libavcodec/dxva2.c
@@ -661,9 +661,11 @@ int ff_dxva2_decode_init(AVCodecContext *avctx)
// (avctx->pix_fmt is not updated yet at this point)
sctx->pix_fmt = avctx->hwaccel->pix_fmt;
- ret = ff_decode_get_hw_frames_ctx(avctx, dev_type);
- if (ret < 0)
- return ret;
+ if (!avctx->hw_frames_ctx) {
+ ret = ff_decode_get_hw_frames_ctx(avctx, dev_type);
+ if (ret < 0)
+ return ret;
+ }
frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
sctx->device_ctx = frames_ctx->device_ctx;
diff --git a/libavcodec/vdpau.c b/libavcodec/vdpau.c
index 167f06d..b7a4e9c 100644
--- a/libavcodec/vdpau.c
+++ b/libavcodec/vdpau.c
@@ -178,10 +178,11 @@ int ff_vdpau_common_init(AVCodecContext *avctx, VdpDecoderProfile profile,
AVHWFramesContext *frames_ctx;
AVVDPAUDeviceContext *dev_ctx;
- ret = ff_decode_get_hw_frames_ctx(avctx, AV_HWDEVICE_TYPE_VDPAU);
- if (ret < 0)
- return ret;
-
+ if (!avctx->hw_frames_ctx) {
+ ret = ff_decode_get_hw_frames_ctx(avctx, AV_HWDEVICE_TYPE_VDPAU);
+ if (ret < 0)
+ return ret;
+ }
frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
dev_ctx = frames_ctx->device_ctx->hwctx;
--
2.7.4
More information about the ffmpeg-devel
mailing list