omxh264: factor out gst_omx_h264_utils_get_profile_from_enum()
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Tue, 6 Mar 2018 09:45:14 +0000 (10:45 +0100)
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Wed, 25 Apr 2018 07:20:02 +0000 (09:20 +0200)
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
omx/gstomxh264utils.c
omx/gstomxh264utils.h

index e46593a..631e31d 100644 (file)
@@ -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) {
index 828cf65..5d28097 100644 (file)
 
 #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)
 {
index 6300486..e5c35e4 100644 (file)
@@ -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__ */