From ceb70c3ca6d3ce85526a50b524ba6a01831f33ed Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=ADctor=20Manuel=20J=C3=A1quez=20Leal?= Date: Thu, 23 Jul 2015 20:07:59 +0200 Subject: [PATCH] surface pool config based on video info MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit First added the function gst_vaapi_video_format_get_best_native(), which returns the best native format that matches a particular chroma type: YUV 4:2:0 -> NV12, YUV 4:2:2 -> YUY2, YUV 4:0:0 -> Y800 RGB32 chroma and encoded format map to NV12 too. That format is used to configure, initially, the surface's pool for the allocator. Signed-off-by: Víctor Manuel Jáquez Leal https://bugzilla.gnome.org/show_bug.cgi?id=744042 --- gst-libs/gst/vaapi/video-format.c | 32 ++++++++++++++++++++++++++++++++ gst-libs/gst/vaapi/video-format.h | 3 +++ gst/vaapi/gstvaapivideomemory.c | 4 +++- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/gst-libs/gst/vaapi/video-format.c b/gst-libs/gst/vaapi/video-format.c index 34c70aa..9a6edd4 100644 --- a/gst-libs/gst/vaapi/video-format.c +++ b/gst-libs/gst/vaapi/video-format.c @@ -270,3 +270,35 @@ gst_vaapi_video_format_get_score (GstVideoFormat format) return m ? (m - &gst_vaapi_video_formats[0]) : G_MAXUINT; } + +/** + * gst_vaapi_video_format_get_best_native: + * @format: a #GstVideoFormat + * + * Returns the best "native" pixel format that matches a particular + * color-space. + * + * Returns: the #GstVideoFormat with the corresponding best native + * format for #GstVaapiSurface + **/ +GstVideoFormat +gst_vaapi_video_format_get_best_native (GstVideoFormat format) +{ + GstVaapiChromaType chroma_type; + + if (format == GST_VIDEO_FORMAT_ENCODED) + return GST_VIDEO_FORMAT_NV12; + + chroma_type = gst_vaapi_video_format_get_chroma_type (format); + switch (chroma_type) { + case GST_VAAPI_CHROMA_TYPE_YUV422: + return GST_VIDEO_FORMAT_YUY2; + case GST_VAAPI_CHROMA_TYPE_YUV400: + return GST_VIDEO_FORMAT_GRAY8; + case GST_VAAPI_CHROMA_TYPE_YUV420: + case GST_VAAPI_CHROMA_TYPE_RGB32: /* GstVideoGLTextureUploadMeta */ + return GST_VIDEO_FORMAT_NV12; + default: + return GST_VIDEO_FORMAT_UNKNOWN; + }; +} diff --git a/gst-libs/gst/vaapi/video-format.h b/gst-libs/gst/vaapi/video-format.h index 4830522..25e1161 100644 --- a/gst-libs/gst/vaapi/video-format.h +++ b/gst-libs/gst/vaapi/video-format.h @@ -53,6 +53,9 @@ gst_vaapi_video_format_get_chroma_type (GstVideoFormat format); guint gst_vaapi_video_format_get_score (GstVideoFormat format); +GstVideoFormat +gst_vaapi_video_format_get_best_native (GstVideoFormat format); + G_END_DECLS #endif /* GST_VAAPI_VIDEO_FORMAT_H */ diff --git a/gst/vaapi/gstvaapivideomemory.c b/gst/vaapi/gstvaapivideomemory.c index 4985672..21c0299 100644 --- a/gst/vaapi/gstvaapivideomemory.c +++ b/gst/vaapi/gstvaapivideomemory.c @@ -659,10 +659,12 @@ allocator_configure_surface_info (GstVaapiDisplay * display, GstVaapiSurface *surface = NULL; GstVaapiImage *image = NULL; gboolean updated; + GstVideoFormat fmt; vinfo = &allocator->video_info; - gst_video_info_set_format (&allocator->surface_info, GST_VIDEO_FORMAT_NV12, + fmt = gst_vaapi_video_format_get_best_native (GST_VIDEO_INFO_FORMAT (vinfo)); + gst_video_info_set_format (&allocator->surface_info, fmt, GST_VIDEO_INFO_WIDTH (vinfo), GST_VIDEO_INFO_HEIGHT (vinfo)); /* nothing to configure */ -- 2.7.4