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

Rémi Denis-Courmont remi at remlab.net
Mon Feb 11 21:57:53 CET 2013


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;

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;
+    };

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



More information about the vlc-devel mailing list