From f9922a1a561e71504bc85155cf81d81078b7db42 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Tue, 6 Mar 2018 10:45:14 +0100 Subject: [PATCH] omxh265: factor out gst_omx_h265_utils_get_profile_from_enum() Move the profile <-> enum mapping to one place. Make changes easier as I'm about to add some profiles. No semantic change. https://bugzilla.gnome.org/show_bug.cgi?id=794177 --- omx/gstomxh265enc.c | 27 +++++------------------ omx/gstomxh265utils.c | 51 ++++++++++++++++++++++++++++++++----------- omx/gstomxh265utils.h | 2 ++ 3 files changed, 45 insertions(+), 35 deletions(-) diff --git a/omx/gstomxh265enc.c b/omx/gstomxh265enc.c index 6076435be1..e0994314fb 100644 --- a/omx/gstomxh265enc.c +++ b/omx/gstomxh265enc.c @@ -556,28 +556,11 @@ gst_omx_h265_enc_get_caps (GstOMXVideoEnc * enc, GstOMXPort * port, "alignment", G_TYPE_STRING, "au", NULL); if (err == OMX_ErrorNone) { - switch (param.eProfile) { - case OMX_VIDEO_HEVCProfileMain: - profile = "main"; - break; - case OMX_VIDEO_HEVCProfileMain10: - profile = "main-10"; - break; -#ifdef USE_OMX_TARGET_ZYNQ_USCALE_PLUS - case OMX_ALG_VIDEO_HEVCProfileMainStill: - profile = "main-still-picture"; - break; - case OMX_ALG_VIDEO_HEVCProfileMain422: - profile = "main-422"; - break; - case OMX_ALG_VIDEO_HEVCProfileMain422_10: - profile = "main-422-10"; - break; -#endif - default: - g_assert_not_reached (); - gst_caps_unref (caps); - return NULL; + profile = gst_omx_h265_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/gstomxh265utils.c b/omx/gstomxh265utils.c index 5141bc4cfb..c45d4d9853 100644 --- a/omx/gstomxh265utils.c +++ b/omx/gstomxh265utils.c @@ -25,26 +25,51 @@ #include "gstomxh265utils.h" +typedef struct +{ + const gchar *profile; + OMX_VIDEO_HEVCPROFILETYPE e; +} H265ProfileMapping; + +static const H265ProfileMapping h265_profiles[] = { + {"main", OMX_VIDEO_HEVCProfileMain}, + {"main-10", OMX_VIDEO_HEVCProfileMain10}, +#ifdef USE_OMX_TARGET_ZYNQ_USCALE_PLUS + {"main-still-picture", + (OMX_VIDEO_HEVCPROFILETYPE) OMX_ALG_VIDEO_HEVCProfileMainStill}, + /* Not standard: 8 bits variation of main-422-10 */ + {"main-422", (OMX_VIDEO_HEVCPROFILETYPE) OMX_ALG_VIDEO_HEVCProfileMain422}, + {"main-422-10", + (OMX_VIDEO_HEVCPROFILETYPE) OMX_ALG_VIDEO_HEVCProfileMain422_10}, +#endif +}; + OMX_VIDEO_HEVCPROFILETYPE gst_omx_h265_utils_get_profile_from_str (const gchar * profile) { - if (g_str_equal (profile, "main")) { - return OMX_VIDEO_HEVCProfileMain; - } else if (g_str_equal (profile, "main-10")) { - return OMX_VIDEO_HEVCProfileMain10; -#ifdef USE_OMX_TARGET_ZYNQ_USCALE_PLUS - } else if (g_str_equal (profile, "main-still-picture")) { - return (OMX_VIDEO_HEVCPROFILETYPE) OMX_ALG_VIDEO_HEVCProfileMainStill; - } else if (g_str_equal (profile, "main-422")) { - /* Not standard: 8 bits variation of main-422-10 */ - return (OMX_VIDEO_HEVCPROFILETYPE) OMX_ALG_VIDEO_HEVCProfileMain422; - } else if (g_str_equal (profile, "main-422-10")) { - return (OMX_VIDEO_HEVCPROFILETYPE) OMX_ALG_VIDEO_HEVCProfileMain422_10; -#endif + guint i; + + for (i = 0; i < G_N_ELEMENTS (h265_profiles); i++) { + if (g_str_equal (profile, h265_profiles[i].profile)) + return h265_profiles[i].e; } + return OMX_VIDEO_HEVCProfileUnknown; } +const gchar * +gst_omx_h265_utils_get_profile_from_enum (OMX_VIDEO_HEVCPROFILETYPE e) +{ + guint i; + + for (i = 0; i < G_N_ELEMENTS (h265_profiles); i++) { + if (e == h265_profiles[i].e) + return h265_profiles[i].profile; + } + + return NULL; +} + OMX_VIDEO_HEVCLEVELTYPE gst_omx_h265_utils_get_level_from_str (const gchar * level, const gchar * tier) { diff --git a/omx/gstomxh265utils.h b/omx/gstomxh265utils.h index 15b7d2aefd..1987a326aa 100644 --- a/omx/gstomxh265utils.h +++ b/omx/gstomxh265utils.h @@ -31,5 +31,7 @@ OMX_VIDEO_HEVCPROFILETYPE gst_omx_h265_utils_get_profile_from_str (const OMX_VIDEO_HEVCLEVELTYPE gst_omx_h265_utils_get_level_from_str (const gchar * level, const gchar * tier); +const gchar * gst_omx_h265_utils_get_profile_from_enum (OMX_VIDEO_HEVCPROFILETYPE e); + G_END_DECLS #endif /* __GST_OMX_H265_UTILS_H__ */