summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuca Barbato <lu_zero@gentoo.org>2014-03-23 17:56:05 +0100
committerLuca Barbato <lu_zero@gentoo.org>2014-05-12 12:59:16 +0200
commite0e79a2e7edaa86e680553a47f46ebbe78c98df9 (patch)
tree9f664c12207382a28d0ae41e2ea8ce5f162e3290
parentdab56b5fd5b1e9e0b1492305c37aede88c500876 (diff)
downloadmpv-e0e79a2e7edaa86e680553a47f46ebbe78c98df9.tar.bz2
mpv-e0e79a2e7edaa86e680553a47f46ebbe78c98df9.tar.xz
vda: Hwaccel 1.2 support
Use the new context and the default functions provided.
-rw-r--r--video/decode/vda.c103
-rw-r--r--video/fmt-conversion.c5
-rw-r--r--wscript7
3 files changed, 81 insertions, 34 deletions
diff --git a/video/decode/vda.c b/video/decode/vda.c
index a8d044c14f..acfadc7be2 100644
--- a/video/decode/vda.c
+++ b/video/decode/vda.c
@@ -26,6 +26,49 @@
#include "video/decode/lavc.h"
#include "config.h"
+
+static int probe(struct vd_lavc_hwdec *hwdec, struct mp_hwdec_info *info,
+ const char *decoder)
+{
+ hwdec_request_api(info, "vda");
+
+ if (mp_codec_to_av_codec_id(decoder) != AV_CODEC_ID_H264)
+ return HWDEC_ERR_NO_CODEC;
+ return 0;
+}
+
+#if HAVE_VDA_AV_VDA_ALLOC_CONTEXT
+
+static int init(struct lavc_ctx *ctx)
+{
+ return 0;
+}
+
+static int init_decoder(struct lavc_ctx *ctx, int fmt, int w, int h)
+{
+ av_vda_default_free(ctx->avctx);
+
+ if (av_vda_default_init(ctx->avctx) < 0)
+ return -1;
+ return 0;
+}
+
+static void uninit(struct lavc_ctx *ctx)
+{
+ if (ctx->avctx)
+ av_vda_default_free(ctx->avctx);
+}
+
+const struct vd_lavc_hwdec mp_vd_lavc_vda = {
+ .type = HWDEC_VDA,
+ .image_format = IMGFMT_VDA,
+ .probe = probe,
+ .init = init,
+ .uninit = uninit,
+ .init_decoder = init_decoder,
+};
+
+#else
struct priv {
struct vda_context vda_ctx;
};
@@ -63,16 +106,6 @@ static void print_vda_error(struct mp_log *log, int lev, char *message,
mp_msg(log, lev, "%s: %d\n", message, error_code);
}
-static int probe(struct vd_lavc_hwdec *hwdec, struct mp_hwdec_info *info,
- const char *decoder)
-{
- hwdec_request_api(info, "vda");
-
- if (mp_codec_to_av_codec_id(decoder) != AV_CODEC_ID_H264)
- return HWDEC_ERR_NO_CODEC;
- return 0;
-}
-
static int init_vda_decoder(struct lavc_ctx *ctx)
{
struct priv *p = ctx->hwdec_priv;
@@ -130,6 +163,30 @@ static void uninit(struct lavc_ctx *ctx) {
ff_vda_destroy_decoder(&p->vda_ctx);
}
+// This actually returns dummy images, since vda_264 creates it's own AVFrames
+// to wrap CVPixelBuffers in planes[3].
+static struct mp_image *allocate_image(struct lavc_ctx *ctx, int fmt,
+ int w, int h)
+{
+ struct priv *p = ctx->hwdec_priv;
+
+ if (fmt != IMGFMT_VDA)
+ return NULL;
+
+ if (w != p->vda_ctx.width || h != p->vda_ctx.height)
+ init_vda_decoder(ctx);
+
+ struct mp_image img = {0};
+ mp_image_setfmt(&img, fmt);
+ mp_image_set_size(&img, w, h);
+
+ // There is an `assert(!dst->f.buf[0])` in libavcodec/h264.c
+ // Setting the first plane to some dummy value allows to satisfy it
+ img.planes[0] = (void*)"dummy";
+
+ return mp_image_new_custom_ref(&img, NULL, NULL);
+}
+
static void cv_retain(void *pbuf)
{
CVPixelBufferRetain((CVPixelBufferRef)pbuf);
@@ -162,30 +219,6 @@ static struct mp_image *process_image(struct lavc_ctx *ctx, struct mp_image *mpi
return cv_mpi;
}
-// This actually returns dummy images, since vda_264 creates it's own AVFrames
-// to wrap CVPixelBuffers in planes[3].
-static struct mp_image *allocate_image(struct lavc_ctx *ctx, int fmt,
- int w, int h)
-{
- struct priv *p = ctx->hwdec_priv;
-
- if (fmt != IMGFMT_VDA)
- return NULL;
-
- if (w != p->vda_ctx.width || h != p->vda_ctx.height)
- init_vda_decoder(ctx);
-
- struct mp_image img = {0};
- mp_image_setfmt(&img, fmt);
- mp_image_set_size(&img, w, h);
-
- // There is an `assert(!dst->f.buf[0])` in libavcodec/h264.c
- // Setting the first plane to some dummy value allows to satisfy it
- img.planes[0] = (void*)"dummy";
-
- return mp_image_new_custom_ref(&img, NULL, NULL);
-}
-
const struct vd_lavc_hwdec mp_vd_lavc_vda = {
.type = HWDEC_VDA,
.image_format = IMGFMT_VDA,
@@ -195,3 +228,5 @@ const struct vd_lavc_hwdec mp_vd_lavc_vda = {
.allocate_image = allocate_image,
.process_image = process_image,
};
+
+#endif
diff --git a/video/fmt-conversion.c b/video/fmt-conversion.c
index bb296b596d..88e10c924e 100644
--- a/video/fmt-conversion.c
+++ b/video/fmt-conversion.c
@@ -21,6 +21,7 @@
#include "video/img_format.h"
#include "fmt-conversion.h"
+#include "config.h"
static const struct {
int fmt;
@@ -172,7 +173,11 @@ static const struct {
#endif
{IMGFMT_VDPAU, AV_PIX_FMT_VDPAU},
+#if HAVE_VDA_AV_VDA_ALLOC_CONTEXT
+ {IMGFMT_VDA, AV_PIX_FMT_VDA},
+#else
{IMGFMT_VDA, AV_PIX_FMT_VDA_VLD},
+#endif
{IMGFMT_VAAPI, AV_PIX_FMT_VAAPI_VLD},
{0, AV_PIX_FMT_NONE}
diff --git a/wscript b/wscript
index 0eff9e3d18..796c0819bf 100644
--- a/wscript
+++ b/wscript
@@ -676,6 +676,13 @@ hwaccel_features = [
"""struct vda_context a = (struct vda_context) {
.use_ref_buffer = 1 }""", use='libav')
}, {
+ 'name': 'vda-av-vda-alloc-context',
+ 'desc': "libavcodec VDA hwaccel 1.2",
+ 'deps': [ 'vda-hwaccel' ],
+ 'func': check_statement('libavcodec/vda.h',
+ 'av_vda_alloc_context()',
+ use='libav')
+ }, {
'name': '--vda-gl',
'desc': 'VDA with OpenGL',
'deps': [ 'gl-cocoa', 'vda-hwaccel' ],