mirror of
https://github.com/mpv-player/mpv
synced 2025-01-24 00:23:27 +00:00
video: remove old videotoolbox support
Like as in previous commits, you need a very recent FFmpeg (probably git master).
This commit is contained in:
parent
a730717281
commit
9b60398f4e
@ -19,177 +19,6 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#if !HAVE_VIDEOTOOLBOX_HWACCEL_NEW
|
||||
|
||||
#include <libavcodec/version.h>
|
||||
#include <libavcodec/videotoolbox.h>
|
||||
|
||||
#include "common/av_common.h"
|
||||
#include "common/msg.h"
|
||||
#include "options/options.h"
|
||||
#include "video/mp_image.h"
|
||||
#include "video/decode/lavc.h"
|
||||
#include "video/mp_image_pool.h"
|
||||
#include "video/vt.h"
|
||||
#include "config.h"
|
||||
|
||||
struct priv {
|
||||
struct mp_image_pool *sw_pool;
|
||||
};
|
||||
|
||||
static int probe_copy(struct lavc_ctx *ctx, struct vd_lavc_hwdec *hwdec,
|
||||
const char *codec)
|
||||
{
|
||||
switch (mp_codec_to_av_codec_id(codec)) {
|
||||
case AV_CODEC_ID_H264:
|
||||
case AV_CODEC_ID_H263:
|
||||
case AV_CODEC_ID_MPEG1VIDEO:
|
||||
case AV_CODEC_ID_MPEG2VIDEO:
|
||||
case AV_CODEC_ID_MPEG4:
|
||||
break;
|
||||
default:
|
||||
return HWDEC_ERR_NO_CODEC;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int probe(struct lavc_ctx *ctx, struct vd_lavc_hwdec *hwdec,
|
||||
const char *codec)
|
||||
{
|
||||
if (!hwdec_devices_load(ctx->hwdec_devs, HWDEC_VIDEOTOOLBOX))
|
||||
return HWDEC_ERR_NO_CTX;
|
||||
return probe_copy(ctx, hwdec, codec);
|
||||
}
|
||||
|
||||
static int init(struct lavc_ctx *ctx)
|
||||
{
|
||||
struct priv *p = talloc_ptrtype(NULL, p);
|
||||
p->sw_pool = talloc_steal(p, mp_image_pool_new(17));
|
||||
ctx->hwdec_priv = p;
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct videotoolbox_error {
|
||||
int code;
|
||||
char *reason;
|
||||
};
|
||||
|
||||
static const struct videotoolbox_error videotoolbox_errors[] = {
|
||||
{ AVERROR(ENOSYS),
|
||||
"Hardware doesn't support accelerated decoding for this stream"
|
||||
" or Videotoolbox decoder is not available at the moment (another"
|
||||
" application is using it)."
|
||||
},
|
||||
{ AVERROR(EINVAL),
|
||||
"Invalid configuration provided to VTDecompressionSessionCreate" },
|
||||
{ AVERROR_INVALIDDATA,
|
||||
"Generic error returned by the decoder layer. The cause can be Videotoolbox"
|
||||
" found errors in the bitstream." },
|
||||
{ 0, NULL },
|
||||
};
|
||||
|
||||
static void print_videotoolbox_error(struct mp_log *log, int lev, char *message,
|
||||
int error_code)
|
||||
{
|
||||
for (int n = 0; videotoolbox_errors[n].code < 0; n++)
|
||||
if (videotoolbox_errors[n].code == error_code) {
|
||||
mp_msg(log, lev, "%s: %s (%d)\n",
|
||||
message, videotoolbox_errors[n].reason, error_code);
|
||||
return;
|
||||
}
|
||||
|
||||
mp_msg(log, lev, "%s: %d\n", message, error_code);
|
||||
}
|
||||
|
||||
static int init_decoder(struct lavc_ctx *ctx, int w, int h)
|
||||
{
|
||||
av_videotoolbox_default_free(ctx->avctx);
|
||||
|
||||
AVVideotoolboxContext *vtctx = av_videotoolbox_alloc_context();
|
||||
if (!vtctx)
|
||||
return -1;
|
||||
|
||||
int imgfmt = ctx->opts->videotoolbox_format;
|
||||
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57, 81, 103)
|
||||
if (!imgfmt)
|
||||
imgfmt = IMGFMT_NV12;
|
||||
#endif
|
||||
vtctx->cv_pix_fmt_type = mp_imgfmt_to_cvpixelformat(imgfmt);
|
||||
MP_VERBOSE(ctx, "Requesting cv_pix_fmt_type=0x%x\n",
|
||||
(unsigned)vtctx->cv_pix_fmt_type);
|
||||
|
||||
int err = av_videotoolbox_default_init2(ctx->avctx, vtctx);
|
||||
if (err < 0) {
|
||||
print_videotoolbox_error(ctx->log, MSGL_ERR, "failed to init videotoolbox decoder", err);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void uninit(struct lavc_ctx *ctx)
|
||||
{
|
||||
if (ctx->avctx)
|
||||
av_videotoolbox_default_free(ctx->avctx);
|
||||
|
||||
struct priv *p = ctx->hwdec_priv;
|
||||
if (!p)
|
||||
return;
|
||||
|
||||
talloc_free(p->sw_pool);
|
||||
p->sw_pool = NULL;
|
||||
|
||||
talloc_free(p);
|
||||
ctx->hwdec_priv = NULL;
|
||||
}
|
||||
|
||||
static struct mp_image *copy_image(struct lavc_ctx *ctx, struct mp_image *hw_image)
|
||||
{
|
||||
struct priv *p = ctx->hwdec_priv;
|
||||
|
||||
struct mp_image *image = mp_vt_download_image(NULL, hw_image, p->sw_pool);
|
||||
if (image) {
|
||||
talloc_free(hw_image);
|
||||
return image;
|
||||
} else {
|
||||
return hw_image;
|
||||
}
|
||||
}
|
||||
|
||||
static struct mp_image *process_image(struct lavc_ctx *ctx, struct mp_image *img)
|
||||
{
|
||||
if (img->imgfmt == IMGFMT_VIDEOTOOLBOX) {
|
||||
CVPixelBufferRef pbuf = (CVPixelBufferRef)img->planes[3];
|
||||
uint32_t cvpixfmt = CVPixelBufferGetPixelFormatType(pbuf);
|
||||
img->params.hw_subfmt = mp_imgfmt_from_cvpixelformat(cvpixfmt);
|
||||
}
|
||||
return img;
|
||||
}
|
||||
|
||||
const struct vd_lavc_hwdec mp_vd_lavc_videotoolbox = {
|
||||
.type = HWDEC_VIDEOTOOLBOX,
|
||||
.image_format = IMGFMT_VIDEOTOOLBOX,
|
||||
.probe = probe,
|
||||
.init = init,
|
||||
.uninit = uninit,
|
||||
.init_decoder = init_decoder,
|
||||
.process_image = process_image,
|
||||
};
|
||||
|
||||
const struct vd_lavc_hwdec mp_vd_lavc_videotoolbox_copy = {
|
||||
.type = HWDEC_VIDEOTOOLBOX_COPY,
|
||||
.copying = true,
|
||||
.image_format = IMGFMT_VIDEOTOOLBOX,
|
||||
.probe = probe_copy,
|
||||
.init = init,
|
||||
.uninit = uninit,
|
||||
.init_decoder = init_decoder,
|
||||
.process_image = copy_image,
|
||||
.delay_queue = HWDEC_DELAY_QUEUE_COUNT,
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
#include <libavutil/hwcontext.h>
|
||||
|
||||
#include "video/decode/lavc.h"
|
||||
@ -242,5 +71,3 @@ const struct vd_lavc_hwdec mp_vd_lavc_videotoolbox_copy = {
|
||||
},
|
||||
.delay_queue = HWDEC_DELAY_QUEUE_COUNT,
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1086,12 +1086,7 @@ static void handle_err(struct dec_video *vd)
|
||||
|
||||
if (ctx->hwdec) {
|
||||
ctx->hwdec_fail_count += 1;
|
||||
// The FFmpeg VT hwaccel is buggy and can crash after 1 broken frame.
|
||||
bool force = false;
|
||||
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57, 82, 101)
|
||||
force |= ctx->hwdec && ctx->hwdec->type == HWDEC_VIDEOTOOLBOX;
|
||||
#endif
|
||||
if (ctx->hwdec_fail_count >= opts->software_fallback || force)
|
||||
if (ctx->hwdec_fail_count >= opts->software_fallback)
|
||||
ctx->hwdec_failed = true;
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,6 @@
|
||||
|
||||
#include "video/out/gpu/hwdec.h"
|
||||
#include "video/mp_image_pool.h"
|
||||
#include "video/vt.h"
|
||||
#include "ra_gl.h"
|
||||
|
||||
struct priv_owner {
|
||||
@ -71,14 +70,11 @@ static int init(struct ra_hwdec *hw)
|
||||
|
||||
p->hwctx = (struct mp_hwdec_ctx){
|
||||
.type = HWDEC_VIDEOTOOLBOX,
|
||||
.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);
|
||||
|
||||
|
@ -30,7 +30,6 @@
|
||||
|
||||
#include "video/mp_image_pool.h"
|
||||
#include "video/out/gpu/hwdec.h"
|
||||
#include "video/vt.h"
|
||||
#include "ra_gl.h"
|
||||
|
||||
struct priv_owner {
|
||||
@ -72,14 +71,11 @@ static int init(struct ra_hwdec *hw)
|
||||
|
||||
p->hwctx = (struct mp_hwdec_ctx){
|
||||
.type = HWDEC_VIDEOTOOLBOX,
|
||||
.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);
|
||||
|
||||
|
74
video/vt.c
74
video/vt.c
@ -1,74 +0,0 @@
|
||||
#include <CoreVideo/CoreVideo.h>
|
||||
|
||||
#include "video/decode/lavc.h"
|
||||
|
||||
#include "mp_image.h"
|
||||
#include "mp_image_pool.h"
|
||||
#include "vt.h"
|
||||
|
||||
static const uint32_t map_imgfmt_cvpixfmt[][2] = {
|
||||
{IMGFMT_420P, kCVPixelFormatType_420YpCbCr8Planar},
|
||||
{IMGFMT_UYVY, kCVPixelFormatType_422YpCbCr8},
|
||||
{IMGFMT_NV12, kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange},
|
||||
{0}
|
||||
};
|
||||
|
||||
uint32_t mp_imgfmt_to_cvpixelformat(int mpfmt)
|
||||
{
|
||||
for (int n = 0; map_imgfmt_cvpixfmt[n][0]; n++) {
|
||||
if (map_imgfmt_cvpixfmt[n][0] == mpfmt)
|
||||
return map_imgfmt_cvpixfmt[n][1];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mp_imgfmt_from_cvpixelformat(uint32_t cvpixfmt)
|
||||
{
|
||||
for (int n = 0; map_imgfmt_cvpixfmt[n][0]; n++) {
|
||||
if (map_imgfmt_cvpixfmt[n][1] == cvpixfmt)
|
||||
return map_imgfmt_cvpixfmt[n][0];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// (ctx is unused - it's for compatibility with mp_hwdec_ctx.download_image())
|
||||
struct mp_image *mp_vt_download_image(struct mp_hwdec_ctx *ctx,
|
||||
struct mp_image *hw_image,
|
||||
struct mp_image_pool *swpool)
|
||||
{
|
||||
if (hw_image->imgfmt != IMGFMT_VIDEOTOOLBOX)
|
||||
return NULL;
|
||||
|
||||
struct mp_image *image = NULL;
|
||||
CVPixelBufferRef pbuf = (CVPixelBufferRef)hw_image->planes[3];
|
||||
CVPixelBufferLockBaseAddress(pbuf, kCVPixelBufferLock_ReadOnly);
|
||||
size_t width = CVPixelBufferGetWidth(pbuf);
|
||||
size_t height = CVPixelBufferGetHeight(pbuf);
|
||||
uint32_t cvpixfmt = CVPixelBufferGetPixelFormatType(pbuf);
|
||||
int imgfmt = mp_imgfmt_from_cvpixelformat(cvpixfmt);
|
||||
if (!imgfmt)
|
||||
goto unlock;
|
||||
|
||||
struct mp_image img = {0};
|
||||
mp_image_setfmt(&img, imgfmt);
|
||||
mp_image_set_size(&img, width, height);
|
||||
|
||||
if (CVPixelBufferIsPlanar(pbuf)) {
|
||||
int planes = CVPixelBufferGetPlaneCount(pbuf);
|
||||
for (int i = 0; i < planes; i++) {
|
||||
img.planes[i] = CVPixelBufferGetBaseAddressOfPlane(pbuf, i);
|
||||
img.stride[i] = CVPixelBufferGetBytesPerRowOfPlane(pbuf, i);
|
||||
}
|
||||
} else {
|
||||
img.planes[0] = CVPixelBufferGetBaseAddress(pbuf);
|
||||
img.stride[0] = CVPixelBufferGetBytesPerRow(pbuf);
|
||||
}
|
||||
|
||||
mp_image_copy_attributes(&img, hw_image);
|
||||
|
||||
image = mp_image_pool_new_copy(swpool, &img);
|
||||
|
||||
unlock:
|
||||
CVPixelBufferUnlockBaseAddress(pbuf, kCVPixelBufferLock_ReadOnly);
|
||||
return image;
|
||||
}
|
16
video/vt.h
16
video/vt.h
@ -1,16 +0,0 @@
|
||||
#ifndef MPV_VT_H
|
||||
#define MPV_VT_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
int mp_imgfmt_from_cvpixelformat(uint32_t cvpixfmt);
|
||||
uint32_t mp_imgfmt_to_cvpixelformat(int mpfmt);
|
||||
|
||||
struct mp_image;
|
||||
struct mp_image_pool;
|
||||
struct mp_hwdec_ctx;
|
||||
struct mp_image *mp_vt_download_image(struct mp_hwdec_ctx *ctx,
|
||||
struct mp_image *hw_image,
|
||||
struct mp_image_pool *swpool);
|
||||
|
||||
#endif
|
16
wscript
16
wscript
@ -826,7 +826,7 @@ hwaccel_features = [
|
||||
' ? 1 : -1]',
|
||||
use='libav'),
|
||||
}, {
|
||||
'name': '--videotoolbox-hwaccel-new',
|
||||
'name': 'videotoolbox-hwaccel',
|
||||
'desc': 'libavcodec videotoolbox hwaccel (new API)',
|
||||
'deps': 'gl-cocoa || ios-gl',
|
||||
'func': check_statement('libavcodec/version.h',
|
||||
@ -834,20 +834,6 @@ hwaccel_features = [
|
||||
' LIBAVCODEC_VERSION_MICRO >= 100)'
|
||||
' ? 1 : -1]',
|
||||
use='libav'),
|
||||
}, {
|
||||
'name': '--videotoolbox-hwaccel-old',
|
||||
'desc': 'libavcodec videotoolbox hwaccel (old API)',
|
||||
'deps': '(gl-cocoa || ios-gl) && !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': 'videotoolbox-hwaccel-new || videotoolbox-hwaccel-old',
|
||||
'func': check_true,
|
||||
}, {
|
||||
'name': '--videotoolbox-gl',
|
||||
'desc': 'Videotoolbox with OpenGL',
|
||||
|
@ -345,7 +345,6 @@ def build(ctx):
|
||||
( "video/vaapi.c", "vaapi" ),
|
||||
( "video/vdpau.c", "vdpau" ),
|
||||
( "video/vdpau_mixer.c", "vdpau" ),
|
||||
( "video/vt.c", "videotoolbox-hwaccel" ),
|
||||
( "video/decode/d3d.c", "d3d-hwaccel" ),
|
||||
( "video/decode/dec_video.c"),
|
||||
( "video/decode/hw_dxva2.c", "d3d9-hwaccel" ),
|
||||
|
Loading…
Reference in New Issue
Block a user