mirror of
https://github.com/mpv-player/mpv
synced 2025-02-16 20:27:23 +00:00
vda: Hwaccel 1.2 support
Use the new context and the default functions provided.
This commit is contained in:
parent
dab56b5fd5
commit
e0e79a2e7e
@ -26,6 +26,49 @@
|
|||||||
#include "video/decode/lavc.h"
|
#include "video/decode/lavc.h"
|
||||||
#include "config.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 priv {
|
||||||
struct vda_context vda_ctx;
|
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);
|
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)
|
static int init_vda_decoder(struct lavc_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct priv *p = ctx->hwdec_priv;
|
struct priv *p = ctx->hwdec_priv;
|
||||||
@ -130,6 +163,30 @@ static void uninit(struct lavc_ctx *ctx) {
|
|||||||
ff_vda_destroy_decoder(&p->vda_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)
|
static void cv_retain(void *pbuf)
|
||||||
{
|
{
|
||||||
CVPixelBufferRetain((CVPixelBufferRef)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;
|
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 = {
|
const struct vd_lavc_hwdec mp_vd_lavc_vda = {
|
||||||
.type = HWDEC_VDA,
|
.type = HWDEC_VDA,
|
||||||
.image_format = IMGFMT_VDA,
|
.image_format = IMGFMT_VDA,
|
||||||
@ -195,3 +228,5 @@ const struct vd_lavc_hwdec mp_vd_lavc_vda = {
|
|||||||
.allocate_image = allocate_image,
|
.allocate_image = allocate_image,
|
||||||
.process_image = process_image,
|
.process_image = process_image,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include "video/img_format.h"
|
#include "video/img_format.h"
|
||||||
#include "fmt-conversion.h"
|
#include "fmt-conversion.h"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
static const struct {
|
static const struct {
|
||||||
int fmt;
|
int fmt;
|
||||||
@ -172,7 +173,11 @@ static const struct {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
{IMGFMT_VDPAU, AV_PIX_FMT_VDPAU},
|
{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},
|
{IMGFMT_VDA, AV_PIX_FMT_VDA_VLD},
|
||||||
|
#endif
|
||||||
{IMGFMT_VAAPI, AV_PIX_FMT_VAAPI_VLD},
|
{IMGFMT_VAAPI, AV_PIX_FMT_VAAPI_VLD},
|
||||||
|
|
||||||
{0, AV_PIX_FMT_NONE}
|
{0, AV_PIX_FMT_NONE}
|
||||||
|
7
wscript
7
wscript
@ -675,6 +675,13 @@ hwaccel_features = [
|
|||||||
'func': check_statement ('libavcodec/vda.h',
|
'func': check_statement ('libavcodec/vda.h',
|
||||||
"""struct vda_context a = (struct vda_context) {
|
"""struct vda_context a = (struct vda_context) {
|
||||||
.use_ref_buffer = 1 }""", use='libav')
|
.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',
|
'name': '--vda-gl',
|
||||||
'desc': 'VDA with OpenGL',
|
'desc': 'VDA with OpenGL',
|
||||||
|
Loading…
Reference in New Issue
Block a user