From 2b1809e9d384c143487ef6065af0cf0112669b06 Mon Sep 17 00:00:00 2001 From: He Junyan Date: Fri, 10 Apr 2020 21:21:43 +0800 Subject: [PATCH] libs: video-format: add a helper function of get_formats_by_chroma. The function iterates all supported video formats and returns the formats belong to the specified chroma type. Part-of: --- gst-libs/gst/vaapi/video-format.c | 33 +++++++++++++++++++++++++++++++ gst-libs/gst/vaapi/video-format.h | 3 +++ 2 files changed, 36 insertions(+) diff --git a/gst-libs/gst/vaapi/video-format.c b/gst-libs/gst/vaapi/video-format.c index 5ebb211ccb..6c1e8e7f5d 100644 --- a/gst-libs/gst/vaapi/video-format.c +++ b/gst-libs/gst/vaapi/video-format.c @@ -476,6 +476,39 @@ gst_vaapi_video_format_get_best_native (GstVideoFormat format) return gst_vaapi_video_format_from_chroma (chroma_type); } +/** + * gst_vaapi_video_format_get_formats_by_chroma: + * @chroma: a #GstVaapiChromaType + * + * Get all #GstVideoFormat which belong to #GstVaapiChromaType. + * + * Returns: an array of #GstVideoFormat. + **/ +GArray * +gst_vaapi_video_format_get_formats_by_chroma (guint chroma) +{ + const GstVideoFormatMap *entry; + GArray *formats; + guint i; + + formats = g_array_new (FALSE, FALSE, sizeof (GstVideoFormat)); + if (!formats) + return NULL; + + for (i = 0; i < gst_vaapi_video_formats_map->len; i++) { + entry = &g_array_index (gst_vaapi_video_formats_map, GstVideoFormatMap, i); + if (entry->chroma_type == chroma) + g_array_append_val (formats, entry->format); + } + + if (formats->len == 0) { + g_array_unref (formats); + return NULL; + } + + return formats; +} + struct ImageFormatsData { VAImageFormat *formats; diff --git a/gst-libs/gst/vaapi/video-format.h b/gst-libs/gst/vaapi/video-format.h index 466e115a2d..953194e559 100644 --- a/gst-libs/gst/vaapi/video-format.h +++ b/gst-libs/gst/vaapi/video-format.h @@ -64,6 +64,9 @@ gst_vaapi_video_format_from_chroma (guint chroma); GstVideoFormat gst_vaapi_video_format_get_best_native (GstVideoFormat format); +GArray * +gst_vaapi_video_format_get_formats_by_chroma (guint chroma); + gboolean gst_vaapi_video_format_create_map (VAImageFormat * formats, guint n);