[vlc-devel] [PATCH] libvlc: Add a new more extensible struct libvlc_media_track_t

Martin Storsjö martin at martin.st
Mon Feb 11 22:20:44 CET 2013


On Mon, 11 Feb 2013, Rémi Denis-Courmont wrote:

> Le lundi 11 février 2013 22:23:44, Martin Storsjö a écrit :
>> I'm still slightly weary about having the union - with them being
>> structured before the last elements (or even if the union was the
>> last element of the struct, it wouldn't be after the first new
>> field is added), you can't add more fields to the unions without
>> breaking ABI, which is what this is all about avoiding. So
>> would it perhaps be best to just flatten it altogether?
>
> Hmm... One option would be to pair the values into multiple unions:
>
> +    union {
> +        char *sub_encoding;
> +        //void *audio_reserved;
> +        //void *video_reserved;
> +    };
> +    union {
> +        unsigned audio_channels;
> +        unsigned video_width;
> +    };
> +    union {
> +        unsigned audio_rate;
> +        unsigned video_height;
> +    };
> +    unsigned video_sar_num;
> +    unsigned video_sar_den;
> +    float video_frame_rate;

That'd work, but feels kinda clumsy.

> A more elegant and flexible option adds a layer of indirection:
>
> +typedef struct libvlc_audio_track_t
> +{
> +    unsigned channels;
> +    unsigned rate;
> +} libvlc_audio_track_t;
> /* ... */
> +    union {
> +        libvlc_audio_track_t *audio;
> +        libvlc_video_track_t *video;
> +        libvlc_sub_track_t *subtitle;
> +    };

That's indeed more elegant, let's see if I got it as you intended or not.

// Martin


More information about the vlc-devel mailing list