aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar wm4 <wm4@nowhere>2017-05-24 15:07:45 +0200
committerGravatar wm4 <wm4@nowhere>2017-05-24 15:25:48 +0200
commit83a9b0bc4840c1bb203c23194c5f07f898999034 (patch)
tree0b7047c9623e8da03b31929c84febf69abe64bed
parent2426f95e0fc232b01228457e5116b592c56b1f7f (diff)
videotoolbox: support new libavcodec API
The new API has literally no advantages (other than that we can drop mp_vt_download_image and other things later), but it's sort-of uniform with the other hwaccels. "--videotoolbox-format=no" is not supported with the new API, because it doesn't "fit in". Probably could be added later again. The iOS code change is untested (no way to test).
-rw-r--r--video/decode/hw_videotoolbox.c61
-rw-r--r--video/decode/vd_lavc.c3
-rw-r--r--video/out/opengl/hwdec_ios.m12
-rw-r--r--video/out/opengl/hwdec_osx.c12
-rw-r--r--wscript22
5 files changed, 107 insertions, 3 deletions
diff --git a/video/decode/hw_videotoolbox.c b/video/decode/hw_videotoolbox.c
index b343b1de0e..d73133582e 100644
--- a/video/decode/hw_videotoolbox.c
+++ b/video/decode/hw_videotoolbox.c
@@ -17,6 +17,10 @@
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "config.h"
+
+#if !HAVE_VIDEOTOOLBOX_HWACCEL_NEW
+
#include <libavcodec/version.h>
#include <libavcodec/videotoolbox.h>
@@ -183,3 +187,60 @@ const struct vd_lavc_hwdec mp_vd_lavc_videotoolbox_copy = {
.process_image = copy_image,
.delay_queue = HWDEC_DELAY_QUEUE_COUNT,
};
+
+#else
+
+#include <libavutil/hwcontext.h>
+
+#include "video/decode/lavc.h"
+
+static void vt_dummy_destroy(struct mp_hwdec_ctx *ctx)
+{
+ av_buffer_unref(&ctx->av_device_ref);
+ talloc_free(ctx);
+}
+
+static struct mp_hwdec_ctx *vt_create_dummy(struct mpv_global *global,
+ struct mp_log *plog, bool probing)
+{
+ struct mp_hwdec_ctx *ctx = talloc_ptrtype(NULL, ctx);
+ *ctx = (struct mp_hwdec_ctx) {
+ .type = HWDEC_VIDEOTOOLBOX_COPY,
+ .ctx = "dummy",
+ .destroy = vt_dummy_destroy,
+ };
+
+ if (av_hwdevice_ctx_create(&ctx->av_device_ref, AV_HWDEVICE_TYPE_VIDEOTOOLBOX,
+ NULL, NULL, 0) < 0)
+ {
+ vt_dummy_destroy(ctx);
+ return NULL;
+ }
+
+ return ctx;
+}
+
+const struct vd_lavc_hwdec mp_vd_lavc_videotoolbox = {
+ .type = HWDEC_VIDEOTOOLBOX,
+ .image_format = IMGFMT_VIDEOTOOLBOX,
+ .generic_hwaccel = true,
+ .set_hwframes = true,
+ .pixfmt_map = (const enum AVPixelFormat[][2]) {
+ {AV_PIX_FMT_NONE}
+ },
+};
+
+const struct vd_lavc_hwdec mp_vd_lavc_videotoolbox_copy = {
+ .type = HWDEC_VIDEOTOOLBOX_COPY,
+ .copying = true,
+ .image_format = IMGFMT_VIDEOTOOLBOX,
+ .generic_hwaccel = true,
+ .create_dev = vt_create_dummy,
+ .set_hwframes = true,
+ .pixfmt_map = (const enum AVPixelFormat[][2]) {
+ {AV_PIX_FMT_NONE}
+ },
+ .delay_queue = HWDEC_DELAY_QUEUE_COUNT,
+};
+
+#endif
diff --git a/video/decode/vd_lavc.c b/video/decode/vd_lavc.c
index 2e7d84e55b..6dda6302f3 100644
--- a/video/decode/vd_lavc.c
+++ b/video/decode/vd_lavc.c
@@ -819,6 +819,9 @@ static int init_generic_hwaccel(struct dec_video *vd)
}
}
+ if (hwdec->image_format == IMGFMT_VIDEOTOOLBOX)
+ av_sw_format = imgfmt2pixfmt(vd->opts->videotoolbox_format);
+
if (av_sw_format == AV_PIX_FMT_NONE) {
MP_VERBOSE(ctx, "Unsupported hw decoding format: %s\n",
mp_imgfmt_to_name(pixfmt2imgfmt(ctx->avctx->sw_pix_fmt)));
diff --git a/video/out/opengl/hwdec_ios.m b/video/out/opengl/hwdec_ios.m
index 3ab532ed02..6cf1b803bd 100644
--- a/video/out/opengl/hwdec_ios.m
+++ b/video/out/opengl/hwdec_ios.m
@@ -23,6 +23,10 @@
#include <CoreVideo/CoreVideo.h>
#include <OpenGLES/EAGL.h>
+#include <libavutil/hwcontext.h>
+
+#include "config.h"
+
#include "video/mp_image_pool.h"
#include "video/vt.h"
#include "formats.h"
@@ -77,6 +81,12 @@ static int create_hwdec(struct gl_hwdec *hw)
.download_image = mp_vt_download_image,
.ctx = &p->hwctx,
};
+
+#if HAVE_VIDEOTOOLBOX_HWACCEL_NEW
+ av_hwdevice_ctx_create(&p->hwctx.av_device_ref, AV_HWDEVICE_TYPE_VIDEOTOOLBOX,
+ NULL, NULL, 0);
+#endif
+
hwdec_devices_add(hw->devs, &p->hwctx);
return 0;
@@ -200,6 +210,8 @@ static void destroy(struct gl_hwdec *hw)
CFRelease(p->gl_texture_cache);
p->gl_texture_cache = NULL;
+ av_buffer_unref(&p->hwctx.av_device_ref);
+
hwdec_devices_remove(hw->devs, &p->hwctx);
}
diff --git a/video/out/opengl/hwdec_osx.c b/video/out/opengl/hwdec_osx.c
index 463f9c3f14..d4594e2dcc 100644
--- a/video/out/opengl/hwdec_osx.c
+++ b/video/out/opengl/hwdec_osx.c
@@ -24,6 +24,10 @@
#include <OpenGL/OpenGL.h>
#include <OpenGL/CGLIOSurface.h>
+#include <libavutil/hwcontext.h>
+
+#include "config.h"
+
#include "video/mp_image_pool.h"
#include "video/vt.h"
#include "formats.h"
@@ -68,6 +72,12 @@ static int create(struct gl_hwdec *hw)
.download_image = mp_vt_download_image,
.ctx = &p->hwctx,
};
+
+#if HAVE_VIDEOTOOLBOX_HWACCEL_NEW
+ av_hwdevice_ctx_create(&p->hwctx.av_device_ref, AV_HWDEVICE_TYPE_VIDEOTOOLBOX,
+ NULL, NULL, 0);
+#endif
+
hwdec_devices_add(hw->devs, &p->hwctx);
return 0;
@@ -155,6 +165,8 @@ static void destroy(struct gl_hwdec *hw)
CVPixelBufferRelease(p->pbuf);
gl->DeleteTextures(MP_MAX_PLANES, p->gl_planes);
+ av_buffer_unref(&p->hwctx.av_device_ref);
+
hwdec_devices_remove(hw->devs, &p->hwctx);
}
diff --git a/wscript b/wscript
index 75925c8098..346c319c69 100644
--- a/wscript
+++ b/wscript
@@ -769,14 +769,30 @@ hwaccel_features = [
' ? 1 : -1]',
use='libav'),
}, {
- 'name': '--videotoolbox-hwaccel',
- 'desc': 'libavcodec videotoolbox hwaccel',
+ 'name': '--videotoolbox-hwaccel-new',
+ 'desc': 'libavcodec videotoolbox hwaccel (new API)',
+ 'deps': [ 'gl-cocoa' ],
+ 'func': check_statement('libavcodec/version.h',
+ 'int x[(LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 96, 100) && '
+ ' LIBAVCODEC_VERSION_MICRO >= 100)'
+ ' ? 1 : -1]',
+ use='libav'),
+ }, {
+ 'name': '--videotoolbox-hwaccel-old',
+ 'desc': 'libavcodec videotoolbox hwaccel (old API)',
+ 'deps': [ 'gl-cocoa' ],
+ 'deps_neg': [ 'videotoolbox-hwaccel-new' ],
'func': compose_checks(
check_headers('VideoToolbox/VideoToolbox.h'),
check_statement('libavcodec/videotoolbox.h',
'av_videotoolbox_alloc_context()',
use='libav')),
- } , {
+ }, {
+ 'name': 'videotoolbox-hwaccel',
+ 'desc': 'libavcodec videotoolbox hwaccel',
+ 'deps_any': [ 'videotoolbox-hwaccel-new', 'videotoolbox-hwaccel-old' ],
+ 'func': check_true,
+ }, {
'name': '--videotoolbox-gl',
'desc': 'Videotoolbox with OpenGL',
'deps': [ 'gl-cocoa', 'videotoolbox-hwaccel' ],