]> git.sesse.net Git - ffmpeg/commitdiff
Make new VDPAU easier to use by adding context to callback.
authorReimar Döffinger <Reimar.Doeffinger@gmx.de>
Wed, 7 Aug 2013 19:22:48 +0000 (21:22 +0200)
committerReimar Döffinger <Reimar.Doeffinger@gmx.de>
Sun, 11 Aug 2013 18:16:57 +0000 (20:16 +0200)
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
during decoding unless using some hack like global
variables.
The need to reinitialize both surfaces and even function
pointers makes handling preemption even more difficult.
This patch introduces a new render2 function that gets
both the AVCodecContext and AVFrame in addition,
in both the user can store additional opaque data.
This allows even advanced approaches like keeping a
"generation counter" for the surfaces so they can be
regenerated on the fly and efficiently.
In addition, the function has a return value that will
be passed through all the way instead of being silently
ignored as for the current render function.
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.

Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>
doc/APIchanges
libavcodec/vdpau.c
libavcodec/vdpau.h
libavcodec/vdpau_h264.c
libavcodec/version.h

index 147b3c722f5f23f84c3b8c04a6f8f3b3412b03b3..049d1427603edad662c8685f6fd92f80f861d4b8 100644 (file)
@@ -15,6 +15,9 @@ libavutil:     2012-10-22
 
 API changes, most recent first:
 
+2013-08-xx - xxxxxxx - lavc 55.27.100 - vdpau.h
+  Add a render2 alternative to the render callback function.
+
 2013-08-xx - xxxxxxx - lavc 55.26.100 - vdpau.h
   Add allocation function for AVVDPAUContext, allowing
   to extend it in the future without breaking ABI/API.
index 63ea75527d6c5617eac9e5325a798e5c624d4b82..a26cd92e37580c40df562b500a6e8989097f3419 100644 (file)
@@ -43,6 +43,8 @@ AVVDPAUContext *av_alloc_vdpaucontext(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)
@@ -60,19 +62,24 @@ int ff_vdpau_common_start_frame(Picture *pic,
     CONFIG_VC1_VDPAU_HWACCEL   || CONFIG_WMV3_VDPAU_HWACCEL
 int ff_vdpau_mpeg_end_frame(AVCodecContext *avctx)
 {
+    int res = 0;
     AVVDPAUContext *hwctx = avctx->hwaccel_context;
     MpegEncContext *s = avctx->priv_data;
     Picture *pic = s->current_picture_ptr;
     struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
     VdpVideoSurface surf = ff_vdpau_get_surface_id(pic);
 
+    if (!hwctx->render) {
+        res = hwctx->render2(avctx, &pic->f, (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);
 
     ff_mpeg_draw_horiz_band(s, 0, s->avctx->height);
     av_freep(&pic_ctx->bitstream_buffers);
 
-    return 0;
+    return res;
 }
 #endif
 
index 210d517d831dd9b1d7bed080bef20aa93c9ea692..b1c836c4b67e2d32c27dba1974498f59cdfdb88f 100644 (file)
@@ -70,6 +70,13 @@ union AVVDPAUPictureInfo {
 };
 #endif
 
+struct AVCodecContext;
+struct AVFrame;
+
+typedef int (*AVVDPAU_Render2)(struct AVCodecContext *, struct AVFrame *,
+                               const VdpPictureInfo *, uint32_t,
+                               const VdpBitstreamBuffer *);
+
 /**
  * This structure is used to share data between the libavcodec library and
  * the client video application.
@@ -129,6 +136,7 @@ typedef struct AVVDPAUContext {
     attribute_deprecated
     VdpBitstreamBuffer *bitstream_buffers;
 #endif
+    AVVDPAU_Render2 render2;
 } AVVDPAUContext;
 
 /**
@@ -138,6 +146,9 @@ typedef struct AVVDPAUContext {
  */
 AVVDPAUContext *av_alloc_vdpaucontext(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
index 06a958291384c5b632161a789f19cbf0f8190f53..3f6415d4f8522d35b74ac9161caeed79b2f65935 100644 (file)
@@ -188,19 +188,24 @@ static int vdpau_h264_decode_slice(AVCodecContext *avctx,
 
 static int vdpau_h264_end_frame(AVCodecContext *avctx)
 {
+    int res = 0;
     AVVDPAUContext *hwctx = avctx->hwaccel_context;
     H264Context *h = avctx->priv_data;
     Picture *pic   = h->cur_pic_ptr;
     struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
     VdpVideoSurface surf = ff_vdpau_get_surface_id(pic);
 
+    if (!hwctx->render) {
+        res = hwctx->render2(avctx, &pic->f, (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);
 
     ff_h264_draw_horiz_band(h, 0, h->avctx->height);
     av_freep(&pic_ctx->bitstream_buffers);
 
-    return 0;
+    return res;
 }
 
 AVHWAccel ff_h264_vdpau_hwaccel = {
index 2be90c450cace368fd1df2a3c38d4ee789910137..e31fea206e38d027a4580f673899e890ed74b5af 100644 (file)
@@ -29,7 +29,7 @@
 #include "libavutil/avutil.h"
 
 #define LIBAVCODEC_VERSION_MAJOR 55
-#define LIBAVCODEC_VERSION_MINOR  26
+#define LIBAVCODEC_VERSION_MINOR  27
 #define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \