[FFmpeg-cvslog] vdpau: add av_vdpau_bind_context()

Rémi Denis-Courmont git at videolan.org
Mon Oct 6 15:10:37 CEST 2014


ffmpeg | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Oct  4 16:55:07 2014 +0300| [e3e158e81f0666b8fe66be9ce1cad63a535920e0] | committer: Anton Khirnov

vdpau: add av_vdpau_bind_context()

This function provides an explicit VDPAU device and VDPAU driver to
libavcodec, so that the application is relieved from codec specifics
and VdpDevice life cycle management.

A stub flags parameter is added for future extension. For instance, it
could be used to ignore codec level capabilities (if someone feels
dangerous).

Signed-off-by: Anton Khirnov <anton at khirnov.net>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e3e158e81f0666b8fe66be9ce1cad63a535920e0
---

 doc/APIchanges              |    4 ++++
 libavcodec/vdpau.c          |   22 +++++++++++++++++++++-
 libavcodec/vdpau.h          |   20 ++++++++++++++++++++
 libavcodec/vdpau_internal.h |    1 +
 libavcodec/version.h        |    2 +-
 5 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index f17f1cf..3df116e 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,10 @@ libavutil:     2014-08-09
 
 API changes, most recent first:
 
+2014-09-xx - xxxxxxx - lavc 56.2.0 - vdpau.h
+  Add av_vdpau_bind_context(). This function should now be used for creating
+  (or resetting) a AVVDPAUContext instead of av_vdpau_alloc_context().
+
 2014-08-xx - xxxxxxx - lavc 56.1.0 - avcodec.h
   Add AV_PKT_DATA_STEREO3D to export container-level stereo3d information.
 
diff --git a/libavcodec/vdpau.c b/libavcodec/vdpau.c
index c3a8a85..685309f 100644
--- a/libavcodec/vdpau.c
+++ b/libavcodec/vdpau.c
@@ -78,6 +78,7 @@ int ff_vdpau_common_init(AVCodecContext *avctx, VdpDecoderProfile profile,
 
     vdctx->width            = UINT32_MAX;
     vdctx->height           = UINT32_MAX;
+    hwctx->reset            = 0;
 
     if (hwctx->context.decoder != VDP_INVALID_HANDLE) {
         vdctx->decoder = hwctx->context.decoder;
@@ -138,12 +139,13 @@ int ff_vdpau_common_uninit(AVCodecContext *avctx)
 
 static int ff_vdpau_common_reinit(AVCodecContext *avctx)
 {
+    VDPAUHWContext *hwctx = avctx->hwaccel_context;
     VDPAUContext *vdctx = avctx->internal->hwaccel_priv_data;
 
     if (vdctx->device == VDP_INVALID_HANDLE)
         return 0; /* Decoder created by user */
     if (avctx->coded_width == vdctx->width &&
-        avctx->coded_height == vdctx->height)
+        avctx->coded_height == vdctx->height && !hwctx->reset)
         return 0;
 
     avctx->hwaccel->uninit(avctx);
@@ -266,4 +268,22 @@ AVVDPAUContext *av_vdpau_alloc_context(void)
     return av_mallocz(sizeof(AVVDPAUContext));
 }
 
+int av_vdpau_bind_context(AVCodecContext *avctx, VdpDevice device,
+                          VdpGetProcAddress *get_proc, unsigned flags)
+{
+    VDPAUHWContext *hwctx;
+
+    if (av_reallocp(&avctx->hwaccel_context, sizeof(*hwctx)))
+        return AVERROR(ENOMEM);
+
+    hwctx = avctx->hwaccel_context;
+
+    memset(hwctx, 0, sizeof(*hwctx));
+    hwctx->context.decoder  = VDP_INVALID_HANDLE;
+    hwctx->device           = device;
+    hwctx->get_proc_address = get_proc;
+    hwctx->reset            = 1;
+    return 0;
+}
+
 /* @}*/
diff --git a/libavcodec/vdpau.h b/libavcodec/vdpau.h
index 75cb1bf..1714b1e 100644
--- a/libavcodec/vdpau.h
+++ b/libavcodec/vdpau.h
@@ -131,6 +131,26 @@ typedef struct AVVDPAUContext {
 } AVVDPAUContext;
 
 /**
+ * Associate a VDPAU device with a codec context for hardware acceleration.
+ * This function is meant to be called from the get_format() codec callback,
+ * or earlier. It can also be called after avcodec_flush_buffers() to change
+ * the underlying VDPAU device mid-stream (e.g. to recover from non-transparent
+ * display preemption).
+ *
+ * @note get_format() must return AV_PIX_FMT_VDPAU if this function completes
+ * succesfully.
+ *
+ * @param avctx decoding context whose get_format() callback is invoked
+ * @param device VDPAU device handle to use for hardware acceleration
+ * @param get_proc_address VDPAU device driver
+ * @param flags for future use, must be zero
+ *
+ * @return 0 on success, an AVERROR code on failure.
+ */
+int av_vdpau_bind_context(AVCodecContext *avctx, VdpDevice device,
+                          VdpGetProcAddress *get_proc_address, unsigned flags);
+
+/**
  * Allocate an AVVDPAUContext.
  *
  * @return Newly-allocated AVVDPAUContext or NULL on failure.
diff --git a/libavcodec/vdpau_internal.h b/libavcodec/vdpau_internal.h
index 3e74d46..69cd455 100644
--- a/libavcodec/vdpau_internal.h
+++ b/libavcodec/vdpau_internal.h
@@ -52,6 +52,7 @@ typedef struct VDPAUHWContext {
     AVVDPAUContext context;
     VdpDevice device;
     VdpGetProcAddress *get_proc_address;
+    char reset;
 } VDPAUHWContext;
 
 typedef struct VDPAUContext {
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 8cc2fb0..849c4b2 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@
 #include "libavutil/version.h"
 
 #define LIBAVCODEC_VERSION_MAJOR 56
-#define LIBAVCODEC_VERSION_MINOR  1
+#define LIBAVCODEC_VERSION_MINOR  2
 #define LIBAVCODEC_VERSION_MICRO  0
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \



More information about the ffmpeg-cvslog mailing list