@@ -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;
@@ -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 {
/**
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> --- libavcodec/decode.c | 10 ++++++---- libavcodec/hwconfig.h | 7 +++++++ 2 files changed, 13 insertions(+), 4 deletions(-)