On Wed Sep 28 21:32:17 2022 +0000, Rémi Bernon wrote:
In my opinion the advantages of generating all these arrays from the same macro outweight the drawbacks, especially when the mappings are spread out like that in several files, converting the wg_format to multiple formats back and forth. When there's a switch on the enum the compiler will catch missing values but with the arrays it's very easy to miss one, and hard to validate that all the values are handled, and in a consistent way with the other mappings elsewhere. To allow grepping the names, instead of just keeping the prefix it could use the full wg name, and keep the gst suffix, guid, etc... Though imho it gets a bit too verbose and not very necessary (like I agree you can't grep for the enum values but it's always easy to get to the enum declaration and lookup how it generates the value, or grep for the macro usage).
For instance, it could look like that instead.
```c /* List all supported raw audio formats, with their metadata. * * Each element should be X(wg, gst, guid, depth), with: * wg: the enum wg_video_format value. * gst: corresponding GStreamer constant. * guid: suffix of the corresponding MEDIASUBTYPE / MFAudioFormat guid. * depth: the number of bits of each audio sample. * */ #define FOR_EACH_WG_AUDIO_FORMAT(F) \ F(WG_AUDIO_FORMAT_U8, GST_AUDIO_FORMAT_U8, PCM, 8) \ F(WG_AUDIO_FORMAT_S16LE, GST_AUDIO_FORMAT_S16LE, PCM, 16) \ F(WG_AUDIO_FORMAT_S24LE, GST_AUDIO_FORMAT_S24LE, PCM, 24) \ F(WG_AUDIO_FORMAT_S32LE, GST_AUDIO_FORMAT_S32LE, PCM, 32) \ F(WG_AUDIO_FORMAT_F32LE, GST_AUDIO_FORMAT_F32LE, Float, 32) \ F(WG_AUDIO_FORMAT_F64LE, GST_AUDIO_FORMAT_F64LE, Float, 64) \
enum wg_audio_format { WG_AUDIO_FORMAT_UNKNOWN = 0, #define X(wg, gst, guid, depth) wg, FOR_EACH_WG_AUDIO_FORMAT(X) #undef X };
/* List all supported raw video formats, with their metadata. * * Each element should be X(wg, gst, guid, depth, type), with: * wg: the enum wg_video_format value. * gst: corresponding GStreamer constant. * guid: suffix of the corresponding MEDIASUBTYPE / MFVideoFormat guid. * depth: the number of bits of each video sample. * type: whether the video format is RGB or YUV. * */ #define FOR_EACH_WG_VIDEO_FORMAT(F) \ F(WG_VIDEO_FORMAT_BGRA, GST_VIDEO_FORMAT_BGRA, ARGB32, 32, RGB) \ F(WG_VIDEO_FORMAT_BGRx, GST_VIDEO_FORMAT_BGRx, RGB32, 32, RGB) \ F(WG_VIDEO_FORMAT_BGR, GST_VIDEO_FORMAT_BGR, RGB24, 24, RGB) \ F(WG_VIDEO_FORMAT_RGBA, GST_VIDEO_FORMAT_RGBA, ABGR32, 32, RGB) \ F(WG_VIDEO_FORMAT_RGB15, GST_VIDEO_FORMAT_RGB15, RGB555, 16, RGB) \ F(WG_VIDEO_FORMAT_RGB16, GST_VIDEO_FORMAT_RGB16, RGB565, 16, RGB) \ F(WG_VIDEO_FORMAT_AYUV, GST_VIDEO_FORMAT_AYUV, AYUV, 32, YUV) \ F(WG_VIDEO_FORMAT_I420, GST_VIDEO_FORMAT_I420, I420, 12, YUV) \ F(WG_VIDEO_FORMAT_NV12, GST_VIDEO_FORMAT_NV12, NV12, 12, YUV) \ F(WG_VIDEO_FORMAT_UYVY, GST_VIDEO_FORMAT_UYVY, UYVY, 16, YUV) \ F(WG_VIDEO_FORMAT_YUY2, GST_VIDEO_FORMAT_YUY2, YUY2, 16, YUV) \ F(WG_VIDEO_FORMAT_YV12, GST_VIDEO_FORMAT_YV12, YV12, 12, YUV) \ F(WG_VIDEO_FORMAT_YVYU, GST_VIDEO_FORMAT_YVYU, YVYU, 16, YUV) \
enum wg_video_format { WG_VIDEO_FORMAT_UNKNOWN = 0, #define X(wg, gst, guid, depth, type) wg, FOR_EACH_WG_VIDEO_FORMAT(X) #undef X }; ```