[FFmpeg-devel] [PATCH] Try to make new VDPAU usable by adding context to callback.

Reimar Döffinger Reimar.Doeffinger at gmx.de
Thu Aug 8 20:17:11 CEST 2013


Using VDPAU correctly means checking for preemption
and possibly regenerating the context all the time.
With the current API there is no context or other
user-defined pointer and thus this in not possible
unless using some hack like global variables.
This introduces a new decode function that gets
both the AVCodecContext and AVFrame in addition,
in both the user can store additional opaque data.
Unfortunately the HWAccel API has no way of providing
API/ABI compatibility, so a currently disallowed
state (render pointer being NULL) is used to extend it.
An alternative would be to add the new function pointer
to the AVCodecContext.
---
 libavcodec/vdpau.c      | 13 +++++++++++++
 libavcodec/vdpau.h      | 12 ++++++++++++
 libavcodec/vdpau_h264.c |  4 ++++
 3 files changed, 29 insertions(+)

diff --git a/libavcodec/vdpau.c b/libavcodec/vdpau.c
index cf564a5..bcd1118 100644
--- a/libavcodec/vdpau.c
+++ b/libavcodec/vdpau.c
@@ -32,12 +32,21 @@
 #include "vdpau.h"
 #include "vdpau_internal.h"
 
+#include "libavutil/accessors.h"
+
 /**
  * @addtogroup VDPAU_Decoding
  *
  * @{
  */
 
+AVVDPAUContext *av_alloc_vdpau_hwaccel(void)
+{
+    return av_mallocz(sizeof(AVVDPAUContext));
+}
+
+MAKE_ACCESSORS(AVVDPAUContext, vdpau_hwaccel, AVVDPAU_Render2, render2)
+
 int ff_vdpau_common_start_frame(Picture *pic,
                                 av_unused const uint8_t *buffer,
                                 av_unused uint32_t size)
@@ -61,6 +70,10 @@ int ff_vdpau_mpeg_end_frame(AVCodecContext *avctx)
     struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
     VdpVideoSurface surf = ff_vdpau_get_surface_id(pic);
 
+    if (!hwctx->render) {
+        hwctx->render2(avctx, &pic->f, surf, (void *)&pic_ctx->info,
+                       pic_ctx->bitstream_buffers_used, pic_ctx->bitstream_buffers);
+    } else
     hwctx->render(hwctx->decoder, surf, (void *)&pic_ctx->info,
                   pic_ctx->bitstream_buffers_used, pic_ctx->bitstream_buffers);
 
diff --git a/libavcodec/vdpau.h b/libavcodec/vdpau.h
index 08116bf..d420058 100644
--- a/libavcodec/vdpau.h
+++ b/libavcodec/vdpau.h
@@ -70,6 +70,13 @@ union AVVDPAUPictureInfo {
 };
 #endif
 
+struct AVCodecContext;
+struct AVFrame;
+
+typedef int (*AVVDPAU_Render2)(struct AVCodecContext *, struct AVFrame *, VdpVideoSurface,
+                               const VdpPictureInfo *, uint32_t,
+                               const VdpBitstreamBuffer *);
+
 /**
  * This structure is used to share data between the libavcodec library and
  * the client video application.
@@ -128,8 +135,13 @@ typedef struct AVVDPAUContext {
     attribute_deprecated
     VdpBitstreamBuffer *bitstream_buffers;
 #endif
+    AVVDPAU_Render2 render2;
 } AVVDPAUContext;
 
+AVVDPAUContext *av_alloc_vdpau_hwaccel(void);
+AVVDPAU_Render2 av_vdpau_hwaccel_get_render2(const AVVDPAUContext *);
+void av_vdpau_hwaccel_set_render2(AVVDPAUContext *, AVVDPAU_Render2);
+
 #if FF_API_CAP_VDPAU
 /** @brief The videoSurface is used for rendering. */
 #define FF_VDPAU_STATE_USED_FOR_RENDER 1
diff --git a/libavcodec/vdpau_h264.c b/libavcodec/vdpau_h264.c
index 06a9582..915b5dd 100644
--- a/libavcodec/vdpau_h264.c
+++ b/libavcodec/vdpau_h264.c
@@ -194,6 +194,10 @@ static int vdpau_h264_end_frame(AVCodecContext *avctx)
     struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
     VdpVideoSurface surf = ff_vdpau_get_surface_id(pic);
 
+    if (!hwctx->render) {
+        hwctx->render2(avctx, &pic->f, surf, (void *)&pic_ctx->info,
+                       pic_ctx->bitstream_buffers_used, pic_ctx->bitstream_buffers);
+    } else
     hwctx->render(hwctx->decoder, surf, (void *)&pic_ctx->info,
                   pic_ctx->bitstream_buffers_used, pic_ctx->bitstream_buffers);
 
-- 
1.8.3.2



More information about the ffmpeg-devel mailing list