From e88f349c6fd41b8e7f62d94a3fa5233f78972483 Mon Sep 17 00:00:00 2001 From: Wangfei Date: Thu, 11 Apr 2019 15:05:02 +0800 Subject: [PATCH] plugins: find the preferred format from right caps. When the downstream has any caps, then raw video feature will be used. At this situation, the preferred format should be chose from caps which contains "vide/x-raw" feature instead of from the fist allowed caps. Fixes #142 --- gst/vaapi/gstvaapipluginutil.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/gst/vaapi/gstvaapipluginutil.c b/gst/vaapi/gstvaapipluginutil.c index 51fdf12..3599b6a 100644 --- a/gst/vaapi/gstvaapipluginutil.c +++ b/gst/vaapi/gstvaapipluginutil.c @@ -698,17 +698,28 @@ gst_vaapi_find_preferred_caps_feature (GstPad * pad, GstCaps * allowed_caps, find_format: if (out_format_ptr) { GstVideoFormat out_format; - GstStructure *structure; + GstStructure *structure = NULL; const GValue *format_list; + GstCapsFeatures *features; - /* if the best feature is SystemMemory, we should use the first - * caps in the filtered peer caps set, which is the preferred by - * downstream. */ - if (feature == GST_VAAPI_CAPS_FEATURE_SYSTEM_MEMORY) + /* if the best feature is SystemMemory, we should choose the + * vidoe/x-raw caps in the filtered peer caps set. If not, use + * the first caps, which is the preferred by downstream. */ + if (feature == GST_VAAPI_CAPS_FEATURE_SYSTEM_MEMORY) { gst_caps_replace (&caps, out_caps); - - /* use the first caps, which is the preferred by downstream. */ - structure = gst_caps_get_structure (caps, 0); + num_structures = gst_caps_get_size (caps); + for (i = 0; i < num_structures; i++) { + structure = gst_caps_get_structure (caps, i); + features = gst_caps_get_features (caps, i); + if (!gst_caps_features_is_any (features) + && gst_caps_features_contains (features, + gst_vaapi_caps_feature_to_string + (GST_VAAPI_CAPS_FEATURE_SYSTEM_MEMORY))) + break; + } + } else { + structure = gst_caps_get_structure (caps, 0); + } if (!structure) goto cleanup; format_list = gst_structure_get_value (structure, "format"); -- 2.7.4