From 7242d0a2e2db0d1bdb5341e075d195a2f8b2e582 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Tue, 6 Mar 2018 10:45:14 +0100 Subject: [PATCH] omxh264: factor out gst_omx_h264_utils_get_profile_from_enum() Move the profile <-> enum mapping to one place. Make changes easier as I'm about to add extra profiles. No semantic change. https://bugzilla.gnome.org/show_bug.cgi?id=794177 --- omx/gstomxh264enc.c | 31 +++++---------------------- omx/gstomxh264utils.c | 49 ++++++++++++++++++++++++++++++------------- omx/gstomxh264utils.h | 2 ++ 3 files changed, 42 insertions(+), 40 deletions(-) diff --git a/omx/gstomxh264enc.c b/omx/gstomxh264enc.c index e46593afbb..631e31d224 100644 --- a/omx/gstomxh264enc.c +++ b/omx/gstomxh264enc.c @@ -737,32 +737,11 @@ gst_omx_h264_enc_get_caps (GstOMXVideoEnc * enc, GstOMXPort * port, "alignment", G_TYPE_STRING, "au", NULL); if (err == OMX_ErrorNone) { - switch (param.eProfile) { - case OMX_VIDEO_AVCProfileBaseline: - profile = "baseline"; - break; - case OMX_VIDEO_AVCProfileMain: - profile = "main"; - break; - case OMX_VIDEO_AVCProfileExtended: - profile = "extended"; - break; - case OMX_VIDEO_AVCProfileHigh: - profile = "high"; - break; - case OMX_VIDEO_AVCProfileHigh10: - profile = "high-10"; - break; - case OMX_VIDEO_AVCProfileHigh422: - profile = "high-4:2:2"; - break; - case OMX_VIDEO_AVCProfileHigh444: - profile = "high-4:4:4"; - break; - default: - g_assert_not_reached (); - gst_caps_unref (caps); - return NULL; + profile = gst_omx_h264_utils_get_profile_from_enum (param.eProfile); + if (!profile) { + g_assert_not_reached (); + gst_caps_unref (caps); + return NULL; } switch (param.eLevel) { diff --git a/omx/gstomxh264utils.c b/omx/gstomxh264utils.c index 828cf65ffb..5d28097779 100644 --- a/omx/gstomxh264utils.c +++ b/omx/gstomxh264utils.c @@ -24,28 +24,49 @@ #include "gstomxh264utils.h" +typedef struct +{ + const gchar *profile; + OMX_VIDEO_AVCPROFILETYPE e; +} H264ProfileMapping; + +static const H264ProfileMapping h264_profiles[] = { + {"baseline", OMX_VIDEO_AVCProfileBaseline}, + {"constrained-baseline", OMX_VIDEO_AVCProfileBaseline}, + {"main", OMX_VIDEO_AVCProfileMain}, + {"extended", OMX_VIDEO_AVCProfileExtended}, + {"high", OMX_VIDEO_AVCProfileHigh}, + {"high-10", OMX_VIDEO_AVCProfileHigh10}, + {"high-4:2:2", OMX_VIDEO_AVCProfileHigh422}, + {"high-4:4:4", OMX_VIDEO_AVCProfileHigh444}, +}; + OMX_VIDEO_AVCPROFILETYPE gst_omx_h264_utils_get_profile_from_str (const gchar * profile) { - if (g_str_equal (profile, "baseline")) { - return OMX_VIDEO_AVCProfileBaseline; - } else if (g_str_equal (profile, "main")) { - return OMX_VIDEO_AVCProfileMain; - } else if (g_str_equal (profile, "extended")) { - return OMX_VIDEO_AVCProfileExtended; - } else if (g_str_equal (profile, "high")) { - return OMX_VIDEO_AVCProfileHigh; - } else if (g_str_equal (profile, "high-10")) { - return OMX_VIDEO_AVCProfileHigh10; - } else if (g_str_equal (profile, "high-4:2:2")) { - return OMX_VIDEO_AVCProfileHigh422; - } else if (g_str_equal (profile, "high-4:4:4")) { - return OMX_VIDEO_AVCProfileHigh444; + guint i; + + for (i = 0; i < G_N_ELEMENTS (h264_profiles); i++) { + if (g_str_equal (profile, h264_profiles[i].profile)) + return h264_profiles[i].e; } return OMX_VIDEO_AVCProfileMax; } +const gchar * +gst_omx_h264_utils_get_profile_from_enum (OMX_VIDEO_AVCPROFILETYPE e) +{ + guint i; + + for (i = 0; i < G_N_ELEMENTS (h264_profiles); i++) { + if (e == h264_profiles[i].e) + return h264_profiles[i].profile; + } + + return NULL; +} + OMX_VIDEO_AVCLEVELTYPE gst_omx_h264_utils_get_level_from_str (const gchar * level) { diff --git a/omx/gstomxh264utils.h b/omx/gstomxh264utils.h index 6300486c8b..e5c35e4f24 100644 --- a/omx/gstomxh264utils.h +++ b/omx/gstomxh264utils.h @@ -30,5 +30,7 @@ OMX_VIDEO_AVCPROFILETYPE gst_omx_h264_utils_get_profile_from_str (const OMX_VIDEO_AVCLEVELTYPE gst_omx_h264_utils_get_level_from_str (const gchar * level); +const gchar * gst_omx_h264_utils_get_profile_from_enum (OMX_VIDEO_AVCPROFILETYPE e); + G_END_DECLS #endif /* __GST_OMX_H264_UTILS_H__ */