Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH v5 1/2] lavc: add HWACCEL_CAP_RESET_WITHOUT_UNINIT capacity for hwaccel
@ 2022-11-14  1:16 Fei Wang
  2022-11-14  1:16 ` [FFmpeg-devel] [PATCH v5 2/2] lavc/vaapi_decode: add support for HWACCEL_CAP_RESET_WITHOUT_UNINIT Fei Wang
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Fei Wang @ 2022-11-14  1:16 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Fei Wang

The capacity can avoid hwaccel being uninited when do the reset. It
provides the method for hwaccel if it still want to use the previous
initialized configuration after reset. And the configuration can be
updated in AVHWAccel.init() if needed.

For example, when use vaapi vp9 decode dynamic resolution clips, need
to avoid changing vaContext in avctx->internal->hwaccel_priv_data if
current frame resolution change and it reference a pervious frame with
different resolution. Otherwise reference frame's information bound
in vaContext will be lost, then corrupt current frame.

Signed-off-by: Fei Wang <fei.w.wang@intel.com>
---
update:
1. consider the case of va_config/va_context equal to 0.

 libavcodec/decode.c   | 10 ++++++----
 libavcodec/hwconfig.h |  7 +++++++
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 6be2d3d6ed..cfada048e8 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1109,7 +1109,7 @@ static int hwaccel_init(AVCodecContext *avctx,
         return AVERROR_PATCHWELCOME;
     }
 
-    if (hwaccel->priv_data_size) {
+    if (hwaccel->priv_data_size && !avctx->internal->hwaccel_priv_data) {
         avctx->internal->hwaccel_priv_data =
             av_mallocz(hwaccel->priv_data_size);
         if (!avctx->internal->hwaccel_priv_data)
@@ -1134,10 +1134,12 @@ static int hwaccel_init(AVCodecContext *avctx,
 
 static void hwaccel_uninit(AVCodecContext *avctx)
 {
-    if (avctx->hwaccel && avctx->hwaccel->uninit)
-        avctx->hwaccel->uninit(avctx);
+    if (avctx->hwaccel && !(avctx->hwaccel->caps_internal & HWACCEL_CAP_RESET_WITHOUT_UNINIT)) {
+        if (avctx->hwaccel->uninit)
+            avctx->hwaccel->uninit(avctx);
 
-    av_freep(&avctx->internal->hwaccel_priv_data);
+        av_freep(&avctx->internal->hwaccel_priv_data);
+    }
 
     avctx->hwaccel = NULL;
 
diff --git a/libavcodec/hwconfig.h b/libavcodec/hwconfig.h
index 721424912c..5fb4e06d5f 100644
--- a/libavcodec/hwconfig.h
+++ b/libavcodec/hwconfig.h
@@ -25,6 +25,13 @@
 
 #define HWACCEL_CAP_ASYNC_SAFE      (1 << 0)
 
+/**
+ * The hwaccel supports reset without calling back AVHWAccel.uninit()
+ * and realloc avctx->internal->hwaccel_priv_data.
+ *
+ * New configuration can set up through AVHWAccel.init().
+ */
+#define HWACCEL_CAP_RESET_WITHOUT_UNINIT     (1 << 1)
 
 typedef struct AVCodecHWConfigInternal {
     /**
-- 
2.25.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-12-06  8:57 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-14  1:16 [FFmpeg-devel] [PATCH v5 1/2] lavc: add HWACCEL_CAP_RESET_WITHOUT_UNINIT capacity for hwaccel Fei Wang
2022-11-14  1:16 ` [FFmpeg-devel] [PATCH v5 2/2] lavc/vaapi_decode: add support for HWACCEL_CAP_RESET_WITHOUT_UNINIT Fei Wang
2022-11-28 13:20   ` Mark Thompson
2022-12-01  1:55     ` Wang, Fei W
2022-12-06  8:57       ` Wang, Fei W
2022-11-16  2:02 ` [FFmpeg-devel] [PATCH v5 1/2] lavc: add HWACCEL_CAP_RESET_WITHOUT_UNINIT capacity for hwaccel Wang, Fei W
2022-11-23 11:29 ` Xiang, Haihao
2022-11-23 11:39   ` Xiang, Haihao

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git