[vlc-commits] [Git][videolan/vlc][master] 2 commits: avcodec: va: use explicit initialisation for ops
Steve Lhomme (@robUx4)
gitlab at videolan.org
Wed Dec 11 11:49:51 UTC 2024
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
38d1f47f by Thomas Guillem at 2024-12-11T10:53:15+00:00
avcodec: va: use explicit initialisation for ops
- - - - -
14bb1525 by Thomas Guillem at 2024-12-11T10:53:15+00:00
avcodec: va: use a configuration struct from New()
7 arguments, it started to be confusing, specially since I will need to
add a new one soon.
- - - - -
7 changed files:
- modules/codec/avcodec/d3d11va.c
- modules/codec/avcodec/dxva2.c
- modules/codec/avcodec/va.c
- modules/codec/avcodec/va.h
- modules/codec/avcodec/vaapi.c
- modules/codec/avcodec/video.c
- modules/hw/vdpau/avcodec.c
Changes:
=====================================
modules/codec/avcodec/d3d11va.c
=====================================
@@ -64,8 +64,7 @@ struct d3d11va_pic_context
#include "directx_va.h"
-static int Open(vlc_va_t *, AVCodecContext *, enum AVPixelFormat hwfmt, const AVPixFmtDescriptor *,
- const es_format_t *, vlc_decoder_device *, video_format_t *, vlc_video_context **);
+static int Open(vlc_va_t *va, struct vlc_va_cfg *cfg);
vlc_module_begin()
set_description(N_("Direct3D11 Video Acceleration"))
@@ -226,12 +225,21 @@ static void Close(vlc_va_t *va, AVCodecContext* ctx)
ctx->hwaccel_context = NULL;
}
-static const struct vlc_va_operations ops = { Get, Close, };
+static const struct vlc_va_operations ops =
+{
+ .get = Get,
+ .close = Close,
+};
-static int Open(vlc_va_t *va, AVCodecContext *ctx, enum AVPixelFormat hwfmt, const AVPixFmtDescriptor *desc,
- const es_format_t *fmt_in, vlc_decoder_device *dec_device,
- video_format_t *fmt_out, vlc_video_context **vtcx_out)
+static int Open(vlc_va_t *va, struct vlc_va_cfg *cfg)
{
+ AVCodecContext *ctx = cfg->avctx;
+ enum AVPixelFormat hwfmt = cfg->hwfmt;
+ const AVPixFmtDescriptor *desc = cfg->desc;
+ const es_format_t *fmt_in = cfg->fmt_in;
+ vlc_decoder_device *dec_device = cfg->dec_device;
+ video_format_t *fmt_out = cfg->video_fmt_out;
+
int err = VLC_EGENERIC;
ctx->hwaccel_context = NULL;
@@ -305,7 +313,7 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum AVPixelFormat hwfmt, con
va->ops = &ops;
*fmt_out = final_fmt;
- *vtcx_out = sys->vctx;
+ cfg->vctx_out = sys->vctx;
return VLC_SUCCESS;
error:
=====================================
modules/codec/avcodec/dxva2.c
=====================================
@@ -49,8 +49,7 @@ struct dxva2_pic_context
#include "directx_va.h"
-static int Open(vlc_va_t *, AVCodecContext *, enum AVPixelFormat hwfmt, const AVPixFmtDescriptor *,
- const es_format_t *, vlc_decoder_device *, video_format_t *, vlc_video_context **);
+static int Open(vlc_va_t *va, struct vlc_va_cfg *cfg);
vlc_module_begin()
set_description(N_("DirectX Video Acceleration (DXVA) 2.0"))
@@ -204,12 +203,21 @@ static void Close(vlc_va_t *va, AVCodecContext *ctx)
va_pool_Close(sys->va_pool);
}
-static const struct vlc_va_operations ops = { Get, Close, };
+static const struct vlc_va_operations ops =
+{
+ .get = Get,
+ .close = Close,
+};
-static int Open(vlc_va_t *va, AVCodecContext *ctx, enum AVPixelFormat hwfmt, const AVPixFmtDescriptor *desc,
- const es_format_t *fmt_in, vlc_decoder_device *dec_device,
- video_format_t *fmt_out, vlc_video_context **vtcx_out)
+static int Open(vlc_va_t *va, struct vlc_va_cfg *cfg)
{
+ AVCodecContext *ctx = cfg->avctx;
+ enum AVPixelFormat hwfmt = cfg->hwfmt;
+ const AVPixFmtDescriptor *desc = cfg->desc;
+ const es_format_t *fmt_in = cfg->fmt_in;
+ vlc_decoder_device *dec_device = cfg->dec_device;
+ video_format_t *fmt_out = cfg->video_fmt_out;
+
int err = VLC_EGENERIC;
if ( hwfmt != AV_PIX_FMT_DXVA2_VLD )
@@ -292,7 +300,7 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum AVPixelFormat hwfmt, con
va->ops = &ops;
*fmt_out = final_fmt;
- *vtcx_out = sys->vctx;
+ cfg->vctx_out = sys->vctx;
return VLC_SUCCESS;
error:
=====================================
modules/codec/avcodec/va.c
=====================================
@@ -44,10 +44,7 @@ bool vlc_va_MightDecode(enum AVPixelFormat hwfmt)
}
}
-vlc_va_t *vlc_va_New(vlc_object_t *obj, AVCodecContext *avctx,
- enum AVPixelFormat hwfmt, const AVPixFmtDescriptor *src_desc,
- const es_format_t *fmt_in, vlc_decoder_device *device,
- video_format_t *fmt_out, vlc_video_context **vtcx_out)
+vlc_va_t *vlc_va_New(vlc_object_t *obj, struct vlc_va_cfg *cfg)
{
struct vlc_va_t *va = vlc_object_create(obj, sizeof (*va));
if (unlikely(va == NULL))
@@ -59,8 +56,8 @@ vlc_va_t *vlc_va_New(vlc_object_t *obj, AVCodecContext *avctx,
for (ssize_t i = 0; i < total; i++) {
vlc_va_open open = vlc_module_map(obj->logger, mods[i]);
- if (open != NULL && open(va, avctx, hwfmt, src_desc, fmt_in, device,
- fmt_out, vtcx_out) == VLC_SUCCESS) {
+ if (open != NULL && open(va, cfg) == VLC_SUCCESS)
+ {
free(mods);
return va;
}
=====================================
modules/codec/avcodec/va.h
=====================================
@@ -30,6 +30,44 @@ typedef struct vlc_va_t vlc_va_t;
typedef struct vlc_decoder_device vlc_decoder_device;
typedef struct vlc_video_context vlc_video_context;
+struct vlc_va_cfg
+{
+ /**
+ * AVContext to set the hwaccel_context on.
+ *
+ * The VA can assume fields codec_id, coded_width, coded_height,
+ * active_thread_type, thread_count, framerate, profile, refs (H264) and
+ * hw_pix_fmt are set correctly */
+ AVCodecContext *avctx;
+
+ /** avcodec hardare PIX_FMT */
+ enum AVPixelFormat hwfmt;
+
+ /** Description of the hardware fornat */
+ const AVPixFmtDescriptor *desc;
+
+ /** VLC format of the content to decode */
+ const es_format_t *fmt_in;
+
+ /** Decoder device that will be used to create the video context */
+ vlc_decoder_device *dec_device;
+
+ /**
+ * Resulting Video format
+ *
+ * Valid, can be changed by the module to change the size or chroma.
+ */
+ video_format_t *video_fmt_out;
+
+ /**
+ * Pointer to the used video context
+ *
+ * The video context must be allocated from the dec_device, filled and set
+ * to this pointer.
+ */
+ vlc_video_context *vctx_out;
+};
+
struct vlc_va_operations {
int (*get)(vlc_va_t *, picture_t *pic, AVCodecContext *ctx, AVFrame *frame);
void (*close)(vlc_va_t *, AVCodecContext* ctx);
@@ -42,10 +80,7 @@ struct vlc_va_t {
const struct vlc_va_operations *ops;
};
-typedef int (*vlc_va_open)(vlc_va_t *, AVCodecContext *,
- enum AVPixelFormat hwfmt, const AVPixFmtDescriptor *,
- const es_format_t *, vlc_decoder_device *,
- video_format_t *, vlc_video_context **);
+typedef int (*vlc_va_open)(vlc_va_t *, struct vlc_va_cfg *cfg);
#define set_va_callback(activate, priority) \
{ \
@@ -66,16 +101,10 @@ bool vlc_va_MightDecode(enum AVPixelFormat hwfmt);
/**
* Creates an accelerated video decoding back-end for libavcodec.
* @param obj parent VLC object
- * @param avctx AVContext to set the hwaccel_context on. The VA can assume fields
- * codec_id, coded_width, coded_height, active_thread_type, thread_count,
- * framerate, profile, refs (H264) and hw_pix_fmt are set correctly.
- * @param fmt VLC format of the content to decode
+ * @param cfg pointer to a configuration struct
* @return a new VLC object on success, NULL on error.
*/
-vlc_va_t *vlc_va_New(vlc_object_t *obj, AVCodecContext * avctx,
- enum AVPixelFormat hwfmt, const AVPixFmtDescriptor *,
- const es_format_t *fmt, vlc_decoder_device *device,
- video_format_t *, vlc_video_context **vtcx_out);
+vlc_va_t *vlc_va_New(vlc_object_t *obj, struct vlc_va_cfg *cfg);
/**
* Get a hardware video surface for a libavcodec frame.
=====================================
modules/codec/avcodec/vaapi.c
=====================================
@@ -158,20 +158,24 @@ static void vaapi_ctx_destroy(void *priv)
av_buffer_unref(&vaapi_vctx->hwframes_ref);
}
-static const struct vlc_va_operations ops = { Get, Delete, };
+static const struct vlc_va_operations ops =
+{
+ .get = Get,
+ .close = Delete,
+};
static const struct vlc_video_context_operations vaapi_ctx_ops =
{
.destroy = vaapi_ctx_destroy,
};
-static int Create(vlc_va_t *va, AVCodecContext *ctx, enum AVPixelFormat hwfmt,
- const AVPixFmtDescriptor *desc,
- const es_format_t *fmt_in, vlc_decoder_device *dec_device,
- video_format_t *fmt_out, vlc_video_context **vtcx_out)
+static int Create(vlc_va_t *va, struct vlc_va_cfg *cfg)
{
- VLC_UNUSED(desc);
- VLC_UNUSED(fmt_in);
+ AVCodecContext *ctx = cfg->avctx;
+ enum AVPixelFormat hwfmt = cfg->hwfmt;
+ vlc_decoder_device *dec_device = cfg->dec_device;
+ video_format_t *fmt_out = cfg->video_fmt_out;
+
if ( hwfmt != AV_PIX_FMT_VAAPI || dec_device == NULL ||
dec_device->type != VLC_DECODER_DEVICE_VAAPI)
return VLC_EGENERIC;
@@ -278,7 +282,7 @@ static int Create(vlc_va_t *va, AVCodecContext *ctx, enum AVPixelFormat hwfmt,
va->ops = &ops;
va->sys = vctx;
- *vtcx_out = vctx;
+ cfg->vctx_out = vctx;
return VLC_SUCCESS;
}
=====================================
modules/codec/avcodec/video.c
=====================================
@@ -738,10 +738,16 @@ static int ffmpeg_OpenVa(decoder_t *p_dec, AVCodecContext *p_context,
vlc_mutex_unlock(open_lock);
p_dec->fmt_out.video.i_chroma = 0; // make sure the va sets its output chroma
- vlc_video_context *vctx_out;
- vlc_va_t *va = vlc_va_New(VLC_OBJECT(p_dec), p_context, hwfmt, src_desc,
- p_dec->fmt_in, init_device,
- &p_dec->fmt_out.video, &vctx_out);
+ struct vlc_va_cfg cfg = {
+ .avctx = p_context,
+ .hwfmt = hwfmt,
+ .desc = src_desc,
+ .fmt_in = p_dec->fmt_in,
+ .dec_device = init_device,
+ .video_fmt_out = &p_dec->fmt_out.video,
+ .vctx_out = NULL,
+ };
+ vlc_va_t *va = vlc_va_New(VLC_OBJECT(p_dec), &cfg);
if (init_device)
vlc_decoder_device_Release(init_device);
if (open_lock)
@@ -749,17 +755,17 @@ static int ffmpeg_OpenVa(decoder_t *p_dec, AVCodecContext *p_context,
if (va == NULL)
return VLC_EGENERIC; /* Unsupported codec profile or such */
assert(p_dec->fmt_out.video.i_chroma != 0);
- assert(vctx_out != NULL);
+ assert(cfg.vctx_out != NULL);
p_dec->fmt_out.i_codec = p_dec->fmt_out.video.i_chroma;
- if (decoder_UpdateVideoOutput(p_dec, vctx_out))
+ if (decoder_UpdateVideoOutput(p_dec, cfg.vctx_out))
{
vlc_va_Delete(va, p_context);
return VLC_EGENERIC; /* Unsupported codec profile or such */
}
p_sys->p_va = va;
- p_sys->vctx_out = vlc_video_context_Hold( vctx_out );
+ p_sys->vctx_out = vlc_video_context_Hold( cfg.vctx_out );
p_sys->pix_fmt = hwfmt;
return VLC_SUCCESS;
}
=====================================
modules/hw/vdpau/avcodec.c
=====================================
@@ -131,21 +131,26 @@ static void Close(vlc_va_t *va, AVCodecContext* ctx)
free(sys);
}
-static const struct vlc_va_operations ops = { Lock, Close, };
+static const struct vlc_va_operations ops =
+{
+ .get = Lock,
+ .close = Close,
+};
const struct vlc_video_context_operations vdpau_vctx_ops = {
NULL,
};
-static int Open(vlc_va_t *va, AVCodecContext *avctx, enum AVPixelFormat hwfmt, const AVPixFmtDescriptor *desc,
- const es_format_t *fmt_in, vlc_decoder_device *dec_device,
- video_format_t *fmt_out, vlc_video_context **vtcx_out)
+static int Open(vlc_va_t *va, struct vlc_va_cfg *cfg)
{
+ AVCodecContext *avctx = cfg->avctx;
+ enum AVPixelFormat hwfmt = cfg->hwfmt;
+ vlc_decoder_device *dec_device = cfg->dec_device;
+ video_format_t *fmt_out = cfg->video_fmt_out;
+
if ( hwfmt != AV_PIX_FMT_VDPAU || GetVDPAUOpaqueDevice(dec_device) == NULL)
return VLC_EGENERIC;
- (void) fmt_in;
- (void) desc;
void *func;
VdpStatus err;
VdpChromaType type, *chroma;
@@ -226,7 +231,7 @@ static int Open(vlc_va_t *va, AVCodecContext *avctx, enum AVPixelFormat hwfmt, c
return VLC_ENOMEM;
}
- *vtcx_out = sys->vctx;
+ cfg->vctx_out = sys->vctx;
va->ops = &ops;
return VLC_SUCCESS;
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/0b9f3f836f1c678e6d101f62545a8edaba16dcd0...14bb1525186bbc6781244ab594d294492cca066c
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/0b9f3f836f1c678e6d101f62545a8edaba16dcd0...14bb1525186bbc6781244ab594d294492cca066c
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list