[vlc-devel] [PATCH] vlc_es: unionize audio/video/subs in es_format_t

Rémi Denis-Courmont remi at remlab.net
Sat Nov 5 07:41:02 CET 2016


Le perjantaina 4. marraskuuta 2016, 18.15.18 EET Thomas Guillem a écrit :
> ---
>  include/vlc_es.h     |  8 +++++---
>  src/misc/es_format.c | 49 +++++++++++++++++++++++++++++++++----------------
> 2 files changed, 38 insertions(+), 19 deletions(-)
> 
> diff --git a/include/vlc_es.h b/include/vlc_es.h
> index bb86b40..2193b3f 100644
> --- a/include/vlc_es.h
> +++ b/include/vlc_es.h
> @@ -536,10 +536,12 @@ struct es_format_t
>      unsigned        i_extra_languages;    /**< length in bytes of extra
> language data pointer */ extra_languages_t *p_extra_languages; /**< extra
> language data needed by some decoders */
> 
> -    audio_format_t  audio;    /**< description of audio format */
> +    union {
> +        audio_format_t audio;    /**< description of audio format */
> +        video_format_t video;    /**< description of video format */
> +        subs_format_t  subs;     /**< description of subtitle format */
> +    };

i_codec should be in the union too.

But while I tried to do that a few years ago, it broke stuff in nonobvious 
ways.

>      audio_replay_gain_t audio_replay_gain; /*< audio replay gain
> information */ -    video_format_t video;     /**< description of video
> format */ -    subs_format_t  subs;      /**< description of subtitle
> format */
> 
>      unsigned int   i_bitrate; /**< bitrate of this ES */
>      int      i_profile;       /**< codec specific information (like real
> audio flavor, mpeg audio layer, h264 profile ...) */ diff --git
> a/src/misc/es_format.c b/src/misc/es_format.c
> index d646e78..5442090 100644
> --- a/src/misc/es_format.c
> +++ b/src/misc/es_format.c
> @@ -499,23 +499,33 @@ int es_format_Copy(es_format_t *restrict dst, const
> es_format_t *src) }
>      }
> 
> -    if (src->subs.psz_encoding != NULL)
> +    switch( src->i_cat )
>      {
> -        dst->subs.psz_encoding = strdup(src->subs.psz_encoding);
> -        if (unlikely(dst->subs.psz_encoding == NULL))
> -            ret = VLC_ENOMEM;
> -    }
> -    if (src->subs.p_style != NULL)
> -    {
> -        dst->subs.p_style = text_style_Duplicate(src->subs.p_style);
> -        if (unlikely(dst->subs.p_style == NULL))
> -            ret = VLC_ENOMEM;
> +        case VIDEO_ES:
> +        {
> +            int err = video_format_Copy( &dst->video, &src->video );
> +            if ( err != VLC_SUCCESS )
> +                return err;
> +            break;
> +        }
> +        case SPU_ES:
> +            if (src->subs.psz_encoding != NULL)
> +            {
> +                dst->subs.psz_encoding = strdup(src->subs.psz_encoding);
> +                if (unlikely(dst->subs.psz_encoding == NULL))
> +                    ret = VLC_ENOMEM;
> +            }
> +            if (src->subs.p_style != NULL)
> +            {
> +                dst->subs.p_style =
> text_style_Duplicate(src->subs.p_style); +                if
> (unlikely(dst->subs.p_style == NULL))
> +                    ret = VLC_ENOMEM;
> +            }
> +            break;
> +        default:
> +            break;
>      }
> 
> -    int err = video_format_Copy( &dst->video, &src->video );
> -    if ( err != VLC_SUCCESS )
> -        return err;
> -
>      if (src->i_extra_languages > 0)
>      {
>          assert(src->p_extra_languages != NULL);
> @@ -548,8 +558,15 @@ void es_format_Clean(es_format_t *fmt)
>      assert(fmt->i_extra == 0 || fmt->p_extra != NULL);
>      free(fmt->p_extra);
> 
> -    video_format_Clean( &fmt->video );
> -    free(fmt->subs.psz_encoding);
> +    switch (fmt->i_cat)
> +    {
> +        case VIDEO_ES:
> +            video_format_Clean(&fmt->video);
> +            break;
> +        case SPU_ES:
> +            free(fmt->subs.psz_encoding);
> +            break;
> +    }
> 
>      if (fmt->subs.p_style != NULL)
>          text_style_Delete(fmt->subs.p_style);


-- 
Rémi Denis-Courmont
http://www.remlab.net/



More information about the vlc-devel mailing list