[vlc-devel] [PATCH 1/7] demux: mock: assign variables per track and create all tracks

Rémi Denis-Courmont remi at remlab.net
Tue Jun 9 17:26:08 CEST 2020


Le tiistaina 9. kesäkuuta 2020, 11.38.46 EEST Francois Cartegnie a écrit :
> ---
>  modules/demux/mock.c | 138 ++++++++++++++++++++++++++++---------------
>  1 file changed, 89 insertions(+), 49 deletions(-)
> 
> diff --git a/modules/demux/mock.c b/modules/demux/mock.c
> index 6f6d555199..c75ea8bee1 100644
> --- a/modules/demux/mock.c
> +++ b/modules/demux/mock.c
> @@ -81,25 +81,31 @@ var_InheritFourcc(vlc_object_t *obj, const char *name)
>      return fourcc;
>  }
> 
> +#define LIST_OPTIONS_AUDIO \
> +    Y(audio, channels, unsigned, add_integer, var_InheritUnsigned, 2) \
> +    Y(audio, format, vlc_fourcc_t, add_string, var_InheritFourcc, "u8") \
> +    Y(audio, rate, unsigned, add_integer, var_InheritUnsigned, 44100) \
> +    Y(audio, packetized, bool, add_bool, var_InheritBool, true) \
> +    Y(audio, sample_length, vlc_tick_t, add_integer, var_InheritInteger,

I think it's more natural/readable to define LIST_OPTIONS_AUDIO(Y) and then 
pass Y as a parameter, than rely on recursive evaluation for the same result.

> VLC_TICK_FROM_MS(40) ) +
> +#define LIST_OPTIONS_VIDEO \
> +    Y(video, chroma, vlc_fourcc_t, add_string, var_InheritFourcc, "I420") \
> +    Y(video, width, unsigned, add_integer, var_InheritUnsigned, 640) \ +  
>  Y(video, height, unsigned, add_integer, var_InheritUnsigned, 480) \ +   
> Y(video, frame_rate, unsigned, add_integer, var_InheritUnsigned, 25) \ +   
> Y(video, frame_rate_base, unsigned, add_integer, var_InheritUnsigned, 1) \
> +    Y(video, packetized, bool, add_bool, var_InheritBool, true)
> +
> +#define LIST_OPTIONS_SUB \
> +    Y(sub, packetized, bool, add_bool, var_InheritBool, true)
> +
>  /* var_name, type, module_header_type, getter, default_value */
> -#define LIST_OPTIONS \
> +#define LIST_OPTIONS_GLOBAL \
>      X(length, vlc_tick_t, add_integer, var_InheritInteger,
> VLC_TICK_FROM_MS(5000)) \ X(audio_track_count, ssize_t, add_integer,
> var_InheritSsize, 0) \ -    X(audio_channels, unsigned, add_integer,
> var_InheritUnsigned, 2) \ -    X(audio_format, vlc_fourcc_t, add_string,
> var_InheritFourcc, "u8") \ -    X(audio_rate, unsigned, add_integer,
> var_InheritUnsigned, 44100) \ -    X(audio_packetized, bool, add_bool,
> var_InheritBool, true) \
> -    X(audio_sample_length, vlc_tick_t, add_integer, var_InheritInteger,
> VLC_TICK_FROM_MS(40) ) \ X(video_track_count, ssize_t, add_integer,
> var_InheritSsize, 0) \ -    X(video_chroma, vlc_fourcc_t, add_string,
> var_InheritFourcc, "I420") \ -    X(video_width, unsigned, add_integer,
> var_InheritUnsigned, 640) \ -    X(video_height, unsigned, add_integer,
> var_InheritUnsigned, 480) \ -    X(video_frame_rate, unsigned, add_integer,
> var_InheritUnsigned, 25) \ -    X(video_frame_rate_base, unsigned,
> add_integer, var_InheritUnsigned, 1) \ -    X(video_packetized, bool,
> add_bool, var_InheritBool, true) \
> -    X(input_sample_length, vlc_tick_t, add_integer, var_InheritInteger,
> VLC_TICK_FROM_MS(40) ) \ X(sub_track_count, ssize_t, add_integer,
> var_InheritSsize, 0) \ -    X(sub_packetized, bool, add_bool,
> var_InheritBool, true) \
> +    X(input_sample_length, vlc_tick_t, add_integer, var_InheritInteger,
> VLC_TICK_FROM_MS(40) ) \ X(title_count, ssize_t, add_integer,
> var_InheritSsize, 0 ) \
>      X(chapter_count, ssize_t, add_integer, var_InheritSsize, 0) \
>      X(null_names, bool, add_bool, var_InheritBool, false) \
> @@ -114,6 +120,34 @@ var_InheritFourcc(vlc_object_t *obj, const char *name)
>      X(add_video_track_at, vlc_tick_t, add_integer, var_InheritInteger,
> VLC_TICK_INVALID ) \ X(add_audio_track_at, vlc_tick_t, add_integer,
> var_InheritInteger, VLC_TICK_INVALID ) \ X(add_spu_track_at, vlc_tick_t,
> add_integer, var_InheritInteger, VLC_TICK_INVALID ) \ +    X(config, char
> *, add_string, var_InheritString, NULL )
> +
> +#define LIST_OPTIONS \
> +    LIST_OPTIONS_GLOBAL \
> +    LIST_OPTIONS_AUDIO \
> +    LIST_OPTIONS_VIDEO \
> +    LIST_OPTIONS_SUB
> +
> +#define X(var_name, type, module_header_type, getter, default_value) \
> +    type var_name;
> +#define Y(a,b,c,d,e,f) X(b,c,d,e,f)
> +
> +struct mock_video_options
> +{
> +    LIST_OPTIONS_VIDEO
> +};
> +
> +struct mock_audio_options
> +{
> +    LIST_OPTIONS_AUDIO
> +};
> +
> +struct mock_sub_options
> +{
> +    LIST_OPTIONS_SUB
> +};
> +
> +#undef Y
> 
>  struct demux_sys
>  {
> @@ -126,12 +160,12 @@ struct demux_sys
>      vlc_tick_t chapter_gap;
> 
>      unsigned int updates;
> -
> -#define X(var_name, type, module_header_type, getter, default_value) \
> -    type var_name;
> -    LIST_OPTIONS
> -#undef X
> +    LIST_OPTIONS_GLOBAL
> +    struct mock_video_options video;
> +    struct mock_audio_options audio;
> +    struct mock_sub_options sub;
>  };
> +#undef X
> 
>  static input_title_t *
>  CreateTitle(demux_t *demux, size_t idx)
> @@ -456,19 +490,19 @@ InitVideoTracks(demux_t *demux, int group, size_t
> count) return VLC_SUCCESS;
> 
>      const vlc_chroma_description_t *desc =
> -        vlc_fourcc_GetChromaDescription(sys->video_chroma);
> +        vlc_fourcc_GetChromaDescription(sys->video.chroma);
>      if (!desc || desc->plane_count == 0)
> -        sys->video_chroma = 0;
> +        sys->video.chroma = 0;
> 
>      const bool frame_rate_ok =
> -        sys->video_frame_rate != 0 && sys->video_frame_rate != UINT_MAX &&
> -        sys->video_frame_rate_base != 0 && sys->video_frame_rate_base !=
> UINT_MAX; -    const bool chroma_ok = sys->video_chroma != 0;
> -    const bool size_ok = sys->video_width != UINT_MAX &&
> -                         sys->video_height != UINT_MAX;
> -
> -    if (sys->video_frame_rate == 0 || sys->video_frame_rate_base == 0
> -     || sys->video_chroma == 0)
> +        sys->video.frame_rate != 0 && sys->video.frame_rate != UINT_MAX &&
> +        sys->video.frame_rate_base != 0 && sys->video.frame_rate_base !=
> UINT_MAX; +    const bool chroma_ok = sys->video.chroma != 0;
> +    const bool size_ok = sys->video.width != UINT_MAX &&
> +                         sys->video.height != UINT_MAX;
> +
> +    if (sys->video.frame_rate == 0 || sys->video.frame_rate_base == 0
> +     || sys->video.chroma == 0)
>      if (!frame_rate_ok || !chroma_ok || !size_ok)
>      {
>          if (!frame_rate_ok)
> @@ -483,14 +517,14 @@ InitVideoTracks(demux_t *demux, int group, size_t
> count) for (size_t i = 0; i < count; ++i)
>      {
>          es_format_t fmt;
> -        es_format_Init(&fmt, VIDEO_ES, sys->video_chroma);
> +        es_format_Init(&fmt, VIDEO_ES, sys->video.chroma);
>          fmt.video.i_chroma = fmt.i_codec;
> -        fmt.video.i_width = fmt.video.i_visible_width = sys->video_width;
> -        fmt.video.i_height = fmt.video.i_visible_height =
> sys->video_height; -        fmt.video.i_frame_rate = sys->video_frame_rate;
> -        fmt.video.i_frame_rate_base = sys->video_frame_rate_base;
> +        fmt.video.i_width = fmt.video.i_visible_width = sys->video.width;
> +        fmt.video.i_height = fmt.video.i_visible_height =
> sys->video.height; +        fmt.video.i_frame_rate = sys->video.frame_rate;
> +        fmt.video.i_frame_rate_base = sys->video.frame_rate_base;
> 
> -        if (AppendMockTrack(demux, &fmt, i, group, sys->video_packetized))
> +        if (AppendMockTrack(demux, &fmt, i, group, sys->video.packetized))
>              return VLC_ENOMEM;
>      }
>      return VLC_SUCCESS;
> @@ -504,10 +538,10 @@ InitAudioTracks(demux_t *demux, int group, size_t
> count) if (count == 0)
>          return VLC_SUCCESS;
> 
> -    const bool rate_ok = sys->audio_rate > 0 && sys->audio_rate !=
> UINT_MAX; -    const bool format_ok = aout_BitsPerSample(sys->audio_format)
> != 0; -    const bool channels_ok = sys->audio_channels > 0 &&
> -                             sys->audio_channels <= AOUT_CHAN_MAX;
> +    const bool rate_ok = sys->audio.rate > 0 && sys->audio.rate !=
> UINT_MAX; +    const bool format_ok = aout_BitsPerSample(sys->audio.format)
> != 0; +    const bool channels_ok = sys->audio.channels > 0 &&
> +                             sys->audio.channels <= AOUT_CHAN_MAX;
> 
>      if (!rate_ok || !format_ok || !channels_ok)
>      {
> @@ -521,7 +555,7 @@ InitAudioTracks(demux_t *demux, int group, size_t count)
> }
> 
>      uint16_t physical_channels = 0;
> -    switch (sys->audio_channels)
> +    switch (sys->audio.channels)
>      {
>          case 1: physical_channels = AOUT_CHAN_CENTER; break;
>          case 2: physical_channels = AOUT_CHANS_2_0; break;
> @@ -538,13 +572,13 @@ InitAudioTracks(demux_t *demux, int group, size_t
> count) for (size_t i = 0; i < count; ++i)
>      {
>          es_format_t fmt;
> -        es_format_Init(&fmt, AUDIO_ES, sys->audio_format);
> +        es_format_Init(&fmt, AUDIO_ES, sys->audio.format);
>          fmt.audio.i_format = fmt.i_codec;
> -        fmt.audio.i_rate = sys->audio_rate;
> +        fmt.audio.i_rate = sys->audio.rate;
>          fmt.audio.i_physical_channels = physical_channels;
>          aout_FormatPrepare(&fmt.audio);
> 
> -        if (AppendMockTrack(demux, &fmt, i, group, sys->audio_packetized))
> +        if (AppendMockTrack(demux, &fmt, i, group, sys->audio.packetized))
>              return VLC_ENOMEM;
>      }
> 
> @@ -564,7 +598,7 @@ InitSubTracks(demux_t *demux, int group, size_t count)
>          es_format_t fmt;
>          es_format_Init(&fmt, SPU_ES, VLC_CODEC_SUBT);
> 
> -        if (AppendMockTrack(demux, &fmt, i, group, sys->sub_packetized))
> +        if (AppendMockTrack(demux, &fmt, i, group, sys->sub.packetized))
>              return VLC_ENOMEM;
>      }
> 
> @@ -664,11 +698,11 @@ Demux(demux_t *demux)
> 
>      const vlc_tick_t video_step_length =
>          (sys->video_track_count > 0 || sys->sub_track_count > 0) ?
> -         VLC_TICK_FROM_SEC(1) * sys->video_frame_rate_base
> -                              / sys->video_frame_rate : 0;
> +         VLC_TICK_FROM_SEC(1) * sys->video.frame_rate_base
> +                              / sys->video.frame_rate : 0;
> 
>      const vlc_tick_t audio_step_length =
> -        sys->audio_track_count > 0 ? sys->audio_sample_length : 0;
> +        sys->audio_track_count > 0 ? sys->audio.sample_length : 0;
> 
>      const vlc_tick_t step_length = __MAX(audio_step_length,
> video_step_length);
> 
> @@ -777,9 +811,14 @@ Open(vlc_object_t *obj)
>      if (var_LocationParse(obj, demux->psz_location, "mock-") !=
> VLC_SUCCESS) return VLC_ENOMEM;
> 
> -#define X(var_name, type, module_header_type, getter, default_value) \
> -    sys->var_name = getter(obj, "mock-"#var_name);
> +#define READ(var_name, member_name, getter) \
> +    sys->member_name = getter(obj, "mock-"#var_name);
> +#define X(var_name, type, module_header_type, getter, default_value)
> READ(var_name, var_name, getter) +#define Y(group_name, var_name, type,
> module_header_type, getter, default_value) \ +       
> READ(group_name##_##var_name, group_name.var_name, getter) LIST_OPTIONS
> +#undef READ
> +#undef Y
>  #undef X
> 
>      if (sys->chapter_count > 0 && sys->title_count == 0)
> @@ -857,6 +896,7 @@ error:
>      module_header_type("mock-"#var_name, default_value, NULL, NULL, true) \
> change_volatile() \
>      change_safe()
> +#define Y(a,b,c,d,e,f) X(a##_##b,c,d,e,f)
> 
>  vlc_module_begin()
>      set_description("mock access demux")


-- 
雷米‧德尼-库尔蒙
http://www.remlab.net/





More information about the vlc-devel mailing list