vaapisink: improve check for raw YUV format mode.
authorGwenole Beauchesne <gwenole.beauchesne@intel.com>
Wed, 3 Apr 2013 13:58:57 +0000 (15:58 +0200)
committerGwenole Beauchesne <gwenole.beauchesne@intel.com>
Wed, 3 Apr 2013 13:58:57 +0000 (15:58 +0200)
Improve check for raw YUV format modes by avoiding checks against strings
("video/x-raw-yuv") for each new GstBuffer allocation. In the usual case,
GstBaseSink::set_caps() is called first and if VA surface format mode is
used, then GstBaseSink::buffer_alloc() is not called. If the latter is
called before set_caps(), then we just make a full check. This one is
pretty rare though, e.g. it usually happens once for custom pipelines.

gst/vaapi/gstvaapisink.c

index fbf931cf7ff96ec2e9bf61af3e1ab13f671e5c23..1bf8026a0ed5157d48c241544107b6119f6f1d7e 100644 (file)
@@ -610,7 +610,6 @@ static gboolean
 gst_vaapisink_set_caps(GstBaseSink *base_sink, GstCaps *caps)
 {
     GstVaapiSink * const sink = GST_VAAPISINK(base_sink);
-    GstStructure * const structure = gst_caps_get_structure(caps, 0);
     GstVideoInfo vi;
     guint win_width, win_height;
 
@@ -621,16 +620,14 @@ gst_vaapisink_set_caps(GstBaseSink *base_sink, GstCaps *caps)
 
     if (!gst_video_info_from_caps(&vi, caps))
         return FALSE;
-    sink->video_width  = GST_VIDEO_INFO_WIDTH(&vi);
-    sink->video_height = GST_VIDEO_INFO_HEIGHT(&vi);
-    sink->video_par_n  = GST_VIDEO_INFO_PAR_N(&vi);
-    sink->video_par_d  = GST_VIDEO_INFO_PAR_D(&vi);
+    sink->use_video_raw = GST_VIDEO_INFO_IS_YUV(&vi);
+    sink->video_width   = GST_VIDEO_INFO_WIDTH(&vi);
+    sink->video_height  = GST_VIDEO_INFO_HEIGHT(&vi);
+    sink->video_par_n   = GST_VIDEO_INFO_PAR_N(&vi);
+    sink->video_par_d   = GST_VIDEO_INFO_PAR_D(&vi);
     GST_DEBUG("video pixel-aspect-ratio %d/%d",
               sink->video_par_n, sink->video_par_d);
 
-    if (gst_structure_has_name(structure, "video/x-raw-yuv"))
-        sink->use_video_raw = TRUE;
-
     gst_caps_replace(&sink->caps, caps);
 
     if (!gst_vaapisink_ensure_display(sink))
@@ -934,14 +931,21 @@ gst_vaapisink_buffer_alloc(
 )
 {
     GstVaapiSink * const sink = GST_VAAPISINK(base_sink);
-    GstStructure *structure;
+    GstVideoInfo vi;
     GstBuffer *buf;
 
     *pbuf = NULL;
 
-    structure = gst_caps_get_structure(caps, 0);
-    if (!gst_structure_has_name(structure, "video/x-raw-yuv"))
-        return GST_FLOW_OK;
+    if (!sink->use_video_raw) {
+        /* Note: this code path is rarely used but for raw YUV formats
+           from custom pipeline. Otherwise, GstBaseSink::set_caps() is
+           called first, and GstBaseSink::buffer_alloc() is not called
+           in VA surface format mode */
+        if (!gst_video_info_from_caps(&vi, caps))
+            return GST_FLOW_NOT_SUPPORTED;
+        if (!GST_VIDEO_INFO_IS_YUV(&vi))
+            return GST_FLOW_OK;
+    }
 
     if (!gst_vaapi_uploader_ensure_display(sink->uploader, sink->display))
         return GST_FLOW_NOT_SUPPORTED;