[vlc-devel] [PATCH 10/11] decoder: add the possibility to have a custom fmt_out setup to load a decoder
Rémi Denis-Courmont
remi at remlab.net
Thu Jul 13 16:18:43 CEST 2017
On jeudi 13 juillet 2017 15:44:43 EEST Steve Lhomme wrote:
> By default it is a blank fmt_out with just the category set.
> ---
> include/vlc_codec.h | 7 ++++++-
> src/input/decoder.c | 21 +++++++++++++++++----
> src/misc/image.c | 3 +--
> 3 files changed, 24 insertions(+), 7 deletions(-)
>
> diff --git a/include/vlc_codec.h b/include/vlc_codec.h
> index 76a86767f1..eacb57f5e0 100644
> --- a/include/vlc_codec.h
> +++ b/include/vlc_codec.h
> @@ -30,6 +30,7 @@
> #include <vlc_es.h>
> #include <vlc_picture.h>
> #include <vlc_subpicture.h>
> +#include <vlc_modules.h>
>
> /**
> * \defgroup codec Codec
> @@ -411,8 +412,12 @@ VLC_API int decoder_GetDisplayRate( decoder_t * )
> VLC_USED;
>
> /**
> * This function loads a decoder module matching the fmt_in of the decoder
> object. + *
> + * The probe is responsible for setting up the decoder fmt_out before/after
> + * loading a module. By default it initializes a blank fmt_out with just +
> * the category and cleans it up on module loading error.
> */
> -VLC_API module_t *decoder_LoadModule( decoder_t * ) VLC_USED;
> +VLC_API module_t *decoder_LoadModule( decoder_t *, vlc_activate_t probe )
> VLC_USED;
>
> /** @} */
> /** @} */
> diff --git a/src/input/decoder.c b/src/input/decoder.c
> index f2bb533a23..5d751157b6 100644
> --- a/src/input/decoder.c
> +++ b/src/input/decoder.c
> @@ -151,7 +151,18 @@ struct decoder_owner_sys_t
> #define DECODER_SPU_VOUT_WAIT_DURATION ((int)(0.200*CLOCK_FREQ))
> #define BLOCK_FLAG_CORE_PRIVATE_RELOADED (1 <<
> BLOCK_FLAG_CORE_PRIVATE_SHIFT)
>
> -module_t *decoder_LoadModule( decoder_t *p_dec )
> +static int DecoderStart(void *func, va_list ap)
> +{
> + decoder_t *p_dec = va_arg(ap, decoder_t *);
> + int (*activate)(vlc_object_t *) = func;
> +
> + int res = activate( VLC_OBJECT(p_dec) );
> + if ( res != VLC_SUCCESS )
> + es_format_Change( &p_dec->fmt_out, p_dec->fmt_out.i_cat, 0 );
IMO, it's far more logical and straightforward to init before activate() and
clean after failed activate.
> + return res;
> +}
> +
> +module_t *decoder_LoadModule( decoder_t *p_dec, vlc_activate_t probe )
> {
> const char caps[ES_CATEGORY_COUNT][16] = {
> [VIDEO_ES] = "video decoder",
> @@ -169,7 +180,10 @@ module_t *decoder_LoadModule( decoder_t *p_dec )
> return NULL; /* no decoder for this type */
> }
>
> - return module_need( p_dec, caps[p_dec->fmt_in.i_cat], "$codec", false
> ); + if ( probe == NULL )
> + es_format_Init( &p_dec->fmt_out, p_dec->fmt_in.i_cat, 0 );
> + return vlc_module_load( p_dec, caps[p_dec->fmt_in.i_cat], "$codec",
> + false, probe ? probe : DecoderStart, p_dec );
> }
>
> /**
> @@ -191,8 +205,7 @@ static int LoadDecoder( decoder_t *p_dec, bool
> b_packetizer, /* Find a suitable decoder/packetizer module */
> if( !b_packetizer )
> {
> - es_format_Init( &p_dec->fmt_out, p_fmt->i_cat, 0 );
> - p_dec->p_module = decoder_LoadModule( p_dec );
> + p_dec->p_module = decoder_LoadModule( p_dec, NULL );
> }
> else
> {
> diff --git a/src/misc/image.c b/src/misc/image.c
> index 19aa95cfe2..f2dbde3d2d 100644
> --- a/src/misc/image.c
> +++ b/src/misc/image.c
> @@ -647,14 +647,13 @@ static decoder_t *CreateDecoder( vlc_object_t *p_this,
> const video_format_t *fmt
>
> p_dec->p_module = NULL;
> es_format_InitFromVideo( &p_dec->fmt_in, fmt );
> - es_format_Init( &p_dec->fmt_out, VIDEO_ES, 0 );
> p_dec->b_frame_drop_allowed = false;
>
> p_dec->pf_vout_format_update = video_update_format;
> p_dec->pf_vout_buffer_new = video_new_buffer;
>
> /* Find a suitable decoder module */
> - p_dec->p_module = decoder_LoadModule( p_dec );
> + p_dec->p_module = decoder_LoadModule( p_dec, NULL );
> if( !p_dec->p_module )
> {
> msg_Err( p_dec, "no suitable decoder module for fourcc `%4.4s'. "
--
Rémi Denis-Courmont
More information about the vlc-devel
mailing list