Since we are adding more and more media formats to wg_format, the current wg_format struct is getting ugly.
Everytime we add a video format, we need to duplicate width, height, fps. Everytime we add a audio format, we need to duplicate channels, rate. So it would be better if we could share width, height, fps fields between different video formats, also share channels and rate fields between different audio formats.
What makes me found the current wg_format is not in a good shape is when I was writting code for Proton, I found that I need to write some code like this if want to get width/height/fps from a wg_format:
```
static bool get_video_info_from_wg_format(struct wg_format *format, int32_t *width, int32_t *height, uint32_t *fps_n, uint32_t *fps_d) { switch (format->major_type) { case WG_MAJOR_TYPE_VIDEO: *width = format->u.video.width; *height = format->u.video.height; *fps_n = format->u.video.fps_n; *fps_d = format->u.video.fps_d; return true;
case WG_MAJOR_TYPE_VIDEO_CINEPAK: *width = format->u.video_cinepak.width; *height = format->u.video_cinepak.height; *fps_n = format->u.video_cinepak.fps_n; *fps_d = format->u.video_cinepak.fps_d; return true;
case WG_MAJOR_TYPE_VIDEO_H264: *width = format->u.video_h264.width; *height = format->u.video_h264.height; *fps_n = format->u.video_h264.fps_n; *fps_d = format->u.video_h264.fps_d; return true;
case WG_MAJOR_TYPE_VIDEO_WMV: *width = format->u.video_wmv.width; *height = format->u.video_wmv.height; *fps_n = format->u.video_wmv.fps_n; *fps_d = format->u.video_wmv.fps_d; return true;
case WG_MAJOR_TYPE_VIDEO_INDEO: *width = format->u.video_indeo.width; *height = format->u.video_indeo.height; *fps_n = format->u.video_indeo.fps_n; *fps_d = format->u.video_indeo.fps_d; return true;
case WG_MAJOR_TYPE_VIDEO_MPEG1: *width = format->u.video_mpeg1.width; *height = format->u.video_mpeg1.height; *fps_n = format->u.video_mpeg1.fps_n; *fps_d = format->u.video_mpeg1.fps_d; return true;
default: GST_ERROR("Type %d is not a video format.\n", format->major_type); return false; } }
```
Apparently, the code above is ugly. By refactoring wg_format, we can avoid code like this.
This patch is a draft now, it only contains unixlib.h code.
Zeb, I'd like to confirm that if this refactoring would be acceptable for you. If do, I'll continue finishing the remaining parts.
-- v6: winegstreamer: Refactor wg_format.