This is necessary to recreate the decoder with the correct parameters,
as not all codecs invoke get_format() in this case.
---
 libavcodec/vdpau.c          | 29 +++++++++++++++++++++++++++--
 libavcodec/vdpau_internal.h |  3 +++
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/libavcodec/vdpau.c b/libavcodec/vdpau.c
index 2b61f5a..05b89ef 100644
--- a/libavcodec/vdpau.c
+++ b/libavcodec/vdpau.c
@@ -78,6 +78,8 @@ int ff_vdpau_common_init(AVCodecContext *avctx, 
VdpDecoderProfile profile,
 
     vdctx->device           = hwctx->device;
     vdctx->get_proc_address = hwctx->get_proc_address;
+    vdctx->width            = UINT32_MAX;
+    vdctx->height           = UINT32_MAX;
 
     if (hwctx->device == VDP_INVALID_HANDLE) {
         vdctx->decoder = hwctx->decoder;
@@ -101,6 +103,12 @@ int ff_vdpau_common_init(AVCodecContext *avctx, 
VdpDecoderProfile profile,
 
     status = create(vdctx->device, profile, width, height, surfaces,
                     &vdctx->decoder);
+    if (status == VDP_STATUS_OK)
+    {
+        vdctx->width  = avctx->coded_width;
+        vdctx->height = avctx->coded_height;
+    }
+
     return vdpau_error(status);
 }
 
@@ -111,8 +119,8 @@ int ff_vdpau_common_uninit(AVCodecContext *avctx)
     void *func;
     VdpStatus status;
 
-    if (vdctx->device == VDP_INVALID_HANDLE)
-        return 0; /* Decoder created and destroyed by user */
+    if (vdctx->width == UINT32_MAX && vdctx->height == UINT32_MAX)
+        return 0;
 
     status = vdctx->get_proc_address(vdctx->device,
                                      VDP_FUNC_ID_DECODER_DESTROY, &func);
@@ -125,6 +133,18 @@ int ff_vdpau_common_uninit(AVCodecContext *avctx)
     return vdpau_error(status);
 }
 
+static int ff_vdpau_common_reinit(AVCodecContext *avctx)
+{
+    VDPAUContext *vdctx = avctx->internal->hwaccel_priv_data;
+
+    if (avctx->coded_width == vdctx->width &&
+        avctx->coded_height == vdctx->height)
+        return 0;
+
+    avctx->hwaccel->uninit(avctx);
+    return avctx->hwaccel->init(avctx);
+}
+
 int ff_vdpau_common_start_frame(struct vdpau_picture_context *pic_ctx,
                                 av_unused const uint8_t *buffer,
                                 av_unused uint32_t size)
@@ -141,6 +161,11 @@ int ff_vdpau_common_end_frame(AVCodecContext *avctx, 
AVFrame *frame,
     VDPAUContext *vdctx = avctx->internal->hwaccel_priv_data;
     VdpVideoSurface surf = ff_vdpau_get_surface_id(frame);
     VdpStatus status;
+    int val;
+
+    val = ff_vdpau_common_reinit(avctx);
+    if (val < 0)
+        return val;
 
     status = vdctx->render(vdctx->decoder, surf, (void *)&pic_ctx->info,
                            pic_ctx->bitstream_buffers_used,
diff --git a/libavcodec/vdpau_internal.h b/libavcodec/vdpau_internal.h
index 54d9ad3..a19e8f2 100644
--- a/libavcodec/vdpau_internal.h
+++ b/libavcodec/vdpau_internal.h
@@ -68,6 +68,9 @@ typedef struct VDPAUContext {
      * VDPAU decoder render callback
      */
     VdpDecoderRender *render;
+
+    uint32_t width;
+    uint32_t height;
 } VDPAUContext;
 
 struct vdpau_picture_context {
-- 
1.8.1.5

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to