From 3f2240498babef1fd906e9442f283a44a1caccdf Mon Sep 17 00:00:00 2001 From: Yeongjin Jeong Date: Mon, 30 Sep 2019 16:29:50 +0900 Subject: [PATCH] h265parser: Add simple GstH265Profile/string public utilites It makes more simplifies the conversion between GstH265Profile and string. --- gst-libs/gst/codecparsers/gsth265parser.c | 110 ++++++++++++++++++++++++++++++ gst-libs/gst/codecparsers/gsth265parser.h | 6 ++ gst/videoparsers/gsth265parse.c | 101 +-------------------------- 3 files changed, 118 insertions(+), 99 deletions(-) diff --git a/gst-libs/gst/codecparsers/gsth265parser.c b/gst-libs/gst/codecparsers/gsth265parser.c index 3f0aed4..ddf265b 100644 --- a/gst-libs/gst/codecparsers/gsth265parser.c +++ b/gst-libs/gst/codecparsers/gsth265parser.c @@ -251,6 +251,63 @@ gst_h265_parse_nalu_header (GstH265NalUnit * nalu) return TRUE; } +struct h265_profile_string +{ + GstH265Profile profile; + const gchar *name; +}; + +static const struct h265_profile_string h265_profiles[] = { + /* keep in sync with definition in the header */ + {GST_H265_PROFILE_MAIN, "main"}, + {GST_H265_PROFILE_MAIN_10, "main-10"}, + {GST_H265_PROFILE_MAIN_STILL_PICTURE, "main-still-picture"}, + {GST_H265_PROFILE_MONOCHROME, "monochrome"}, + {GST_H265_PROFILE_MONOCHROME_12, "monochrome-12"}, + {GST_H265_PROFILE_MONOCHROME_16, "monochrome-16"}, + {GST_H265_PROFILE_MAIN_12, "main-12"}, + {GST_H265_PROFILE_MAIN_422_10, "main-422-10"}, + {GST_H265_PROFILE_MAIN_422_12, "main-422-12"}, + {GST_H265_PROFILE_MAIN_444, "main-444"}, + {GST_H265_PROFILE_MAIN_444_10, "main-444-10"}, + {GST_H265_PROFILE_MAIN_444_12, "main-444-12"}, + {GST_H265_PROFILE_MAIN_INTRA, "main-intra"}, + {GST_H265_PROFILE_MAIN_10_INTRA, "main-10-intra"}, + {GST_H265_PROFILE_MAIN_12_INTRA, "main-12-intra"}, + {GST_H265_PROFILE_MAIN_422_10_INTRA, "main-422-10-intra"}, + {GST_H265_PROFILE_MAIN_422_12_INTRA, "main-422-12-intra"}, + {GST_H265_PROFILE_MAIN_444_INTRA, "main-444-intra"}, + {GST_H265_PROFILE_MAIN_444_10_INTRA, "main-444-10-intra"}, + {GST_H265_PROFILE_MAIN_444_12_INTRA, "main-444-12-intra"}, + {GST_H265_PROFILE_MAIN_444_16_INTRA, "main-444-16-intra"}, + {GST_H265_PROFILE_MAIN_444_STILL_PICTURE, "main-444-still-picture"}, + {GST_H265_PROFILE_MAIN_444_16_STILL_PICTURE, "main-444-16-still-picture"}, + {GST_H265_PROFILE_MONOCHROME_10, "monochrome-10"}, + {GST_H265_PROFILE_HIGH_THROUGHPUT_444, "high-throughput-444"}, + {GST_H265_PROFILE_HIGH_THROUGHPUT_444_10, "high-throughput-444-10"}, + {GST_H265_PROFILE_HIGH_THROUGHPUT_444_14, "high-throughput-444-14"}, + {GST_H265_PROFILE_HIGH_THROUGHPUT_444_16_INTRA, + "high-throughput-444-16-intra"}, + {GST_H265_PROFILE_SCREEN_EXTENDED_MAIN, "screen-extended-main"}, + {GST_H265_PROFILE_SCREEN_EXTENDED_MAIN_10, "screen-extended-main-10"}, + {GST_H265_PROFILE_SCREEN_EXTENDED_MAIN_444, "screen-extended-main-444"}, + {GST_H265_PROFILE_SCREEN_EXTENDED_MAIN_444_10, "screen-extended-main-444-10"}, + {GST_H265_PROFILE_SCREEN_EXTENDED_HIGH_THROUGHPUT_444, + "screen-extended-high-throughput-444"}, + {GST_H265_PROFILE_SCREEN_EXTENDED_HIGH_THROUGHPUT_444_10, + "screen-extended-high-throughput-444-10"}, + {GST_H265_PROFILE_SCREEN_EXTENDED_HIGH_THROUGHPUT_444_14, + "screen-extended-high-throughput-444-14"}, + {GST_H265_PROFILE_MULTIVIEW_MAIN, "multiview-main"}, + {GST_H265_PROFILE_SCALABLE_MAIN, "scalable-main"}, + {GST_H265_PROFILE_SCALABLE_MAIN_10, "scalable-main-10"}, + {GST_H265_PROFILE_SCALABLE_MONOCHROME, "scalable-monochrome"}, + {GST_H265_PROFILE_SCALABLE_MONOCHROME_12, "scalable-monochrome-12"}, + {GST_H265_PROFILE_SCALABLE_MONOCHROME_16, "scalable-monochrome-16"}, + {GST_H265_PROFILE_SCALABLE_MAIN_444, "scalable-main-444"}, + {GST_H265_PROFILE_3D_MAIN, "3d-main"}, +}; + /****** Parsing functions *****/ static gboolean @@ -3234,3 +3291,56 @@ gst_h265_profile_tier_level_get_profile (GstH265ProfileTierLevel * ptl) return get_format_range_extension_profile (ptl); } + +/** + * gst_h265_profile_to_string: + * @profile: a #GstH265Profile + * + * Returns the descriptive name for the #GstH265Profile. + * + * Returns: (nullable): the name for @profile or %NULL on error + * + * Since: 1.18 + */ +const gchar * +gst_h265_profile_to_string (GstH265Profile profile) +{ + guint i; + + if (profile == GST_H265_PROFILE_INVALID || profile == GST_H265_PROFILE_MAX) + return NULL; + + for (i = 0; i < G_N_ELEMENTS (h265_profiles); i++) { + if (profile == h265_profiles[i].profile) + return h265_profiles[i].name; + } + + return NULL; +} + +/** + * gst_h265_profile_from_string: + * @string: the descriptive name for #GstH265Profile + * + * Returns a #GstH265Profile for the @string. + * + * Returns: the #GstH265Profile of @string or %GST_H265_PROFILE_INVALID on error + * + * Since: 1.18 + */ +GstH265Profile +gst_h265_profile_from_string (const gchar * string) +{ + guint i; + + if (string == NULL) + return GST_H265_PROFILE_INVALID; + + for (i = 0; i < G_N_ELEMENTS (h265_profiles); i++) { + if (g_strcmp0 (string, h265_profiles[i].name) == 0) { + return h265_profiles[i].profile; + } + } + + return GST_H265_PROFILE_INVALID; +} diff --git a/gst-libs/gst/codecparsers/gsth265parser.h b/gst-libs/gst/codecparsers/gsth265parser.h index 66852d2..e88f48b 100644 --- a/gst-libs/gst/codecparsers/gsth265parser.h +++ b/gst-libs/gst/codecparsers/gsth265parser.h @@ -1558,5 +1558,11 @@ void gst_h265_quant_matrix_8x8_get_raster_from_uprightdiagonal (guint8 out_qu GST_CODEC_PARSERS_API GstH265Profile gst_h265_profile_tier_level_get_profile (GstH265ProfileTierLevel * ptl); +GST_CODEC_PARSERS_API +const gchar * gst_h265_profile_to_string (GstH265Profile profile); + +GST_CODEC_PARSERS_API +GstH265Profile gst_h265_profile_from_string (const gchar * string); + G_END_DECLS #endif diff --git a/gst/videoparsers/gsth265parse.c b/gst/videoparsers/gsth265parse.c index cafeaee..f4bffd7 100644 --- a/gst/videoparsers/gsth265parse.c +++ b/gst/videoparsers/gsth265parse.c @@ -1566,103 +1566,6 @@ digit_to_string (guint digit) } static const gchar * -get_profile_string (GstH265Profile profile) -{ - switch (profile) { - case GST_H265_PROFILE_MAIN: - return "main"; - case GST_H265_PROFILE_MAIN_10: - return "main-10"; - case GST_H265_PROFILE_MAIN_STILL_PICTURE: - return "main-still-picture"; - case GST_H265_PROFILE_MONOCHROME: - return "monochrome"; - case GST_H265_PROFILE_MONOCHROME_10: - return "monochrome-10"; - case GST_H265_PROFILE_MONOCHROME_12: - return "monochrome-12"; - case GST_H265_PROFILE_MONOCHROME_16: - return "monochrome-16"; - case GST_H265_PROFILE_MAIN_12: - return "main-12"; - case GST_H265_PROFILE_MAIN_422_10: - return "main-422-10"; - case GST_H265_PROFILE_MAIN_422_12: - return "main-422-12"; - case GST_H265_PROFILE_MAIN_444: - return "main-444"; - case GST_H265_PROFILE_MAIN_444_10: - return "main-444-10"; - case GST_H265_PROFILE_MAIN_444_12: - return "main-444-12"; - case GST_H265_PROFILE_MAIN_INTRA: - return "main-intra"; - case GST_H265_PROFILE_MAIN_10_INTRA: - return "main-10-intra"; - case GST_H265_PROFILE_MAIN_12_INTRA: - return "main-12-intra"; - case GST_H265_PROFILE_MAIN_422_10_INTRA: - return "main-422-10-intra"; - case GST_H265_PROFILE_MAIN_422_12_INTRA: - return "main-422-12-intra"; - case GST_H265_PROFILE_MAIN_444_INTRA: - return "main-444-intra"; - case GST_H265_PROFILE_MAIN_444_10_INTRA: - return "main-444-10-intra"; - case GST_H265_PROFILE_MAIN_444_12_INTRA: - return "main-444-12-intra"; - case GST_H265_PROFILE_MAIN_444_16_INTRA: - return "main-444-16-intra"; - case GST_H265_PROFILE_MAIN_444_STILL_PICTURE: - return "main-444-still-picture"; - case GST_H265_PROFILE_MAIN_444_16_STILL_PICTURE: - return "main-444-16-still-picture"; - case GST_H265_PROFILE_HIGH_THROUGHPUT_444: - return "high-throughput-444"; - case GST_H265_PROFILE_HIGH_THROUGHPUT_444_10: - return "high-throughput-444-10"; - case GST_H265_PROFILE_HIGH_THROUGHPUT_444_14: - return "high-throughput-444-14"; - case GST_H265_PROFILE_HIGH_THROUGHPUT_444_16_INTRA: - return "high-throughput-444-16-intra"; - case GST_H265_PROFILE_SCREEN_EXTENDED_MAIN: - return "screen-extended-main"; - case GST_H265_PROFILE_SCREEN_EXTENDED_MAIN_10: - return "screen-extended-main-10"; - case GST_H265_PROFILE_SCREEN_EXTENDED_MAIN_444: - return "screen-extended-main-444"; - case GST_H265_PROFILE_SCREEN_EXTENDED_MAIN_444_10: - return "screen-extended-main-444-10"; - case GST_H265_PROFILE_SCREEN_EXTENDED_HIGH_THROUGHPUT_444: - return "screen-extended-high-throughput-444"; - case GST_H265_PROFILE_SCREEN_EXTENDED_HIGH_THROUGHPUT_444_10: - return "screen-extended-high-throughput-444-10"; - case GST_H265_PROFILE_SCREEN_EXTENDED_HIGH_THROUGHPUT_444_14: - return "screen-extended-high-throughput-444-14"; - case GST_H265_PROFILE_MULTIVIEW_MAIN: - return "multiview-main"; - case GST_H265_PROFILE_SCALABLE_MAIN: - return "scalable-main"; - case GST_H265_PROFILE_SCALABLE_MAIN_10: - return "scalable-main-10"; - case GST_H265_PROFILE_SCALABLE_MONOCHROME: - return "scalable-monochrome"; - case GST_H265_PROFILE_SCALABLE_MONOCHROME_12: - return "scalable-monochrome-12"; - case GST_H265_PROFILE_SCALABLE_MONOCHROME_16: - return "scalable-monochrome-16"; - case GST_H265_PROFILE_SCALABLE_MAIN_444: - return "scalable-main-444"; - case GST_H265_PROFILE_3D_MAIN: - return "3d-main"; - default: - break; - } - - return NULL; -} - -static const gchar * get_tier_string (guint8 tier_flag) { const gchar *tier = NULL; @@ -1912,7 +1815,7 @@ get_compatible_profile_caps (GstH265SPS * sps, GstH265Profile profile) for (i = GST_H265_PROFILE_MAIN; i < GST_H265_PROFILE_MAX; i++) { if ((profiles & profile_to_flag (i)) == profile_to_flag (i)) { - profile_str = get_profile_string (i); + profile_str = gst_h265_profile_to_string (i); if (G_UNLIKELY (profile_str == NULL)) { GST_FIXME ("Unhandled profile index %d", i); @@ -2225,7 +2128,7 @@ gst_h265_parse_update_src_caps (GstH265Parse * h265parse, GstCaps * caps) GstH265Profile p; p = gst_h265_profile_tier_level_get_profile (&sps->profile_tier_level); - profile = get_profile_string (p); + profile = gst_h265_profile_to_string (p); if (profile != NULL) gst_caps_set_simple (caps, "profile", G_TYPE_STRING, profile, NULL); -- 2.7.4