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: <https://gitlab.freedesktop.org/gstreamer/gstreamer-vaapi/-/merge_requests/315>
This commit is contained in:
He Junyan 2020-04-10 21:21:43 +08:00 committed by Víctor Manuel Jáquez Leal
parent 5d56ce6927
commit 2b1809e9d3
2 changed files with 36 additions and 0 deletions

View file

@ -476,6 +476,39 @@ gst_vaapi_video_format_get_best_native (GstVideoFormat format)
return gst_vaapi_video_format_from_chroma (chroma_type); 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 struct ImageFormatsData
{ {
VAImageFormat *formats; VAImageFormat *formats;

View file

@ -64,6 +64,9 @@ gst_vaapi_video_format_from_chroma (guint chroma);
GstVideoFormat GstVideoFormat
gst_vaapi_video_format_get_best_native (GstVideoFormat format); gst_vaapi_video_format_get_best_native (GstVideoFormat format);
GArray *
gst_vaapi_video_format_get_formats_by_chroma (guint chroma);
gboolean gboolean
gst_vaapi_video_format_create_map (VAImageFormat * formats, guint n); gst_vaapi_video_format_create_map (VAImageFormat * formats, guint n);