[vlc-devel] [PATCH 08/26] sout:encoder: use separate signatures for the Open callback of encoders
Steve Lhomme
robux4 at ycbcr.xyz
Mon Jan 18 08:32:47 UTC 2021
They may differ between video/audio/spu. It also allows checking the proper
callback is set.
This would not be possible outside of the core because vlc_objres_clear() can't
be called.
---
include/vlc_codec.h | 34 +++++++++++++++++
src/stream_output/stream_output.c | 62 ++++++++++++++++++++++++++++++-
2 files changed, 95 insertions(+), 1 deletion(-)
diff --git a/include/vlc_codec.h b/include/vlc_codec.h
index 7b5f4042d6e..c18bfd3d774 100644
--- a/include/vlc_codec.h
+++ b/include/vlc_codec.h
@@ -272,6 +272,40 @@ struct encoder_t
const struct encoder_owner_callbacks *cbs;
};
+typedef int (*vlc_encoder_OpenVideo)(encoder_t *p_enc);
+typedef void (*vlc_encoder_Close)(encoder_t *p_enc);
+#define set_callback_video_encoder(activate, deactivate, priority) \
+ { \
+ vlc_encoder_OpenVideo open__ = activate; \
+ vlc_encoder_Close close__ = deactivate; \
+ (void) open__; \
+ (void) close__; \
+ set_callbacks(activate, deactivate) \
+ } \
+ set_capability( "video encoder", priority )
+
+typedef int (*vlc_encoder_OpenAudio)(encoder_t *);
+#define set_callback_audio_encoder(activate, deactivate, priority) \
+ { \
+ vlc_encoder_OpenAudio open__ = activate; \
+ vlc_encoder_Close close__ = deactivate; \
+ (void) open__; \
+ (void) close__; \
+ set_callbacks(activate, deactivate) \
+ } \
+ set_capability( "audio encoder", priority )
+
+typedef int (*vlc_encoder_OpenSPU)(encoder_t *);
+#define set_callback_spu_encoder(activate, deactivate, priority) \
+ { \
+ vlc_encoder_OpenSPU open__ = activate; \
+ vlc_encoder_Close close__ = deactivate; \
+ (void) open__; \
+ (void) close__; \
+ set_callbacks(activate, deactivate) \
+ } \
+ set_capability( "spu encoder", priority )
+
/**
* @}
*
diff --git a/src/stream_output/stream_output.c b/src/stream_output/stream_output.c
index 9053a1c943c..58a006433e8 100644
--- a/src/stream_output/stream_output.c
+++ b/src/stream_output/stream_output.c
@@ -1011,10 +1011,70 @@ encoder_t *sout_EncoderCreate( vlc_object_t *p_this, size_t owner_size, enum es_
return vlc_custom_create( p_this, owner_size, encoder_caps[i_cat] );
}
+static int encoder_start_video(void *func, bool forced, va_list ap)
+{
+ encoder_t *p_enc = va_arg(ap, encoder_t *);
+ vlc_encoder_OpenVideo activate = func;
+ int ret;
+
+ p_enc->obj.force = forced;
+
+ ret = activate(p_enc);
+ if (ret != VLC_SUCCESS)
+ vlc_objres_clear(&p_enc->obj);
+ else
+ {
+ assert(p_enc->pf_encode_video != NULL);
+ }
+ return ret;
+}
+
+static int encoder_start_audio(void *func, bool forced, va_list ap)
+{
+ encoder_t *p_enc = va_arg(ap, encoder_t *);
+ vlc_encoder_OpenAudio activate = func;
+
+ p_enc->obj.force = forced;
+
+ int ret = activate(p_enc);
+ if (ret != VLC_SUCCESS)
+ vlc_objres_clear(&p_enc->obj);
+ else
+ {
+ assert(p_enc->pf_encode_audio != NULL);
+ }
+ return ret;
+}
+
+static int encoder_start_spu(void *func, bool forced, va_list ap)
+{
+ encoder_t *p_enc = va_arg(ap, encoder_t *);
+ vlc_encoder_OpenSPU activate = func;
+
+ p_enc->obj.force = forced;
+
+ int ret = activate(p_enc);
+ if (ret != VLC_SUCCESS)
+ vlc_objres_clear(&p_enc->obj);
+ else
+ {
+ assert(p_enc->pf_encode_sub != NULL);
+ }
+ return ret;
+}
+
int sout_EncoderOpen(encoder_t *p_encoder, const char *name, bool strict)
{
+ static const vlc_activate_t activates[ES_CATEGORY_COUNT] = {
+ [VIDEO_ES] = encoder_start_video,
+ [AUDIO_ES] = encoder_start_audio,
+ [SPU_ES] = encoder_start_spu,
+ };
+
p_encoder->p_module =
- module_need(p_encoder, encoder_caps[p_encoder->fmt_in.i_cat], name, strict);
+ vlc_module_load(p_encoder, encoder_caps[p_encoder->fmt_in.i_cat], name,
+ strict, activates[p_encoder->fmt_in.i_cat],
+ p_encoder );
if (!p_encoder->p_module)
return VLC_ENOMOD;
return VLC_SUCCESS;
--
2.29.2
More information about the vlc-devel
mailing list