plugins: remove gst_vaapi_plugin_base_get_allowed_srcpad_raw_caps()

Since nobody uses it, just remove it.

Thus extract_allowed_surface_formats() is refactored to attend only
gst_vaapi_plugin_base_get_allowed_sinkpad_raw_caps().

Now a surface is created when the image chorma is different from the
previous one. And if the driver has the quirk, it outputs all the
supported image formats without trying them.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-vaapi/-/merge_requests/381>
This commit is contained in:
Víctor Manuel Jáquez Leal 2020-08-12 18:48:59 +02:00
parent a50b466fc7
commit 089ef59c37
2 changed files with 21 additions and 61 deletions

View file

@ -1404,14 +1404,19 @@ no_valid_gl_display:
static GArray * static GArray *
extract_allowed_surface_formats (GstVaapiDisplay * display, extract_allowed_surface_formats (GstVaapiDisplay * display,
GArray * img_formats, GstVideoFormat specified_format, GArray * img_formats)
GstPadDirection direction)
{ {
guint i; guint i;
GArray *out_formats; GArray *out_formats;
guint surface_chroma = 0;
GstVaapiSurface *surface = NULL; GstVaapiSurface *surface = NULL;
g_assert (direction == GST_PAD_SRC || direction == GST_PAD_SINK); /* let's assume all the formats are possible to download */
if (gst_vaapi_display_has_driver_quirks (display,
GST_VAAPI_DRIVER_QUIRK_NO_CHECK_SURFACE_PUT_IMAGE)) {
out_formats = g_array_ref (img_formats);
goto bail;
}
out_formats = out_formats =
g_array_sized_new (FALSE, FALSE, sizeof (GstVideoFormat), g_array_sized_new (FALSE, FALSE, sizeof (GstVideoFormat),
@ -1424,54 +1429,34 @@ extract_allowed_surface_formats (GstVaapiDisplay * display,
g_array_index (img_formats, GstVideoFormat, i); g_array_index (img_formats, GstVideoFormat, i);
GstVaapiImage *image; GstVaapiImage *image;
GstVideoInfo vi; GstVideoInfo vi;
GstVideoFormat surface_format; guint img_chroma;
gboolean res;
if (img_format == GST_VIDEO_FORMAT_UNKNOWN) if (img_format == GST_VIDEO_FORMAT_UNKNOWN)
continue; continue;
surface_format = img_chroma = gst_vaapi_video_format_get_chroma_type (img_format);
(specified_format == GST_VIDEO_FORMAT_UNKNOWN) ? if (img_chroma != surface_chroma) {
img_format : specified_format; if (surface)
if (!surface) { gst_vaapi_surface_unref (surface);
gst_video_info_set_format (&vi, surface_format, 64, 64); gst_video_info_set_format (&vi, img_format, 64, 64);
surface = gst_vaapi_surface_new_full (display, &vi, 0); surface = gst_vaapi_surface_new_full (display, &vi, 0);
if (!surface) if (!surface)
continue; continue;
surface_chroma = img_chroma;
} }
image = gst_vaapi_image_new (display, img_format, 64, 64); image = gst_vaapi_image_new (display, img_format, 64, 64);
if (!image) { if (!image)
/* Just reuse the surface if the format is specified */
if (specified_format == GST_VIDEO_FORMAT_UNKNOWN)
gst_mini_object_replace ((GstMiniObject **) & surface, NULL);
continue; continue;
} if (gst_vaapi_surface_put_image (surface, image))
res = FALSE;
if (direction == GST_PAD_SRC) {
res = gst_vaapi_surface_get_image (surface, image);
} else {
if (!gst_vaapi_display_has_driver_quirks (display,
GST_VAAPI_DRIVER_QUIRK_NO_CHECK_SURFACE_PUT_IMAGE))
res = gst_vaapi_surface_put_image (surface, image);
else
res = TRUE; /* Let's say it's possible to upload
* all formats */
}
if (res)
g_array_append_val (out_formats, img_format); g_array_append_val (out_formats, img_format);
gst_vaapi_image_unref (image); gst_vaapi_image_unref (image);
/* Just reuse the surface if the format is specified */
if (specified_format == GST_VIDEO_FORMAT_UNKNOWN)
gst_mini_object_replace ((GstMiniObject **) & surface, NULL);
} }
if (surface) if (surface)
gst_vaapi_surface_unref (surface); gst_vaapi_surface_unref (surface);
bail:
if (out_formats->len == 0) { if (out_formats->len == 0) {
g_array_unref (out_formats); g_array_unref (out_formats);
return NULL; return NULL;
@ -1480,8 +1465,7 @@ extract_allowed_surface_formats (GstVaapiDisplay * display,
} }
static gboolean static gboolean
ensure_allowed_raw_caps (GstVaapiPluginBase * plugin, GstVideoFormat format, ensure_allowed_raw_caps (GstVaapiPluginBase * plugin)
GstPadDirection direction)
{ {
GArray *formats, *out_formats; GArray *formats, *out_formats;
GstVaapiDisplay *display; GstVaapiDisplay *display;
@ -1496,8 +1480,7 @@ ensure_allowed_raw_caps (GstVaapiPluginBase * plugin, GstVideoFormat format,
formats = gst_vaapi_display_get_image_formats (display); formats = gst_vaapi_display_get_image_formats (display);
if (!formats) if (!formats)
goto bail; goto bail;
out_formats = out_formats = extract_allowed_surface_formats (display, formats);
extract_allowed_surface_formats (display, formats, format, direction);
if (!out_formats) if (!out_formats)
goto bail; goto bail;
out_caps = gst_vaapi_video_format_new_template_caps_from_list (out_formats); out_caps = gst_vaapi_video_format_new_template_caps_from_list (out_formats);
@ -1529,25 +1512,7 @@ bail:
GstCaps * GstCaps *
gst_vaapi_plugin_base_get_allowed_sinkpad_raw_caps (GstVaapiPluginBase * plugin) gst_vaapi_plugin_base_get_allowed_sinkpad_raw_caps (GstVaapiPluginBase * plugin)
{ {
if (!ensure_allowed_raw_caps (plugin, GST_VIDEO_FORMAT_UNKNOWN, GST_PAD_SINK)) if (!ensure_allowed_raw_caps (plugin))
return NULL;
return plugin->allowed_raw_caps;
}
/**
* gst_vaapi_plugin_base_get_allowed_srcpad_raw_caps:
* @plugin: a #GstVaapiPluginBase
* @format: a #GstVideoFormat, the format we need to check
*
* Returns the raw #GstCaps allowed by the element.
*
* Returns: the allowed raw #GstCaps or %NULL
**/
GstCaps *
gst_vaapi_plugin_base_get_allowed_srcpad_raw_caps (GstVaapiPluginBase *
plugin, GstVideoFormat format)
{
if (!ensure_allowed_raw_caps (plugin, format, GST_PAD_SRC))
return NULL; return NULL;
return plugin->allowed_raw_caps; return plugin->allowed_raw_caps;
} }

View file

@ -301,11 +301,6 @@ G_GNUC_INTERNAL
GstCaps * GstCaps *
gst_vaapi_plugin_base_get_allowed_sinkpad_raw_caps (GstVaapiPluginBase * plugin); gst_vaapi_plugin_base_get_allowed_sinkpad_raw_caps (GstVaapiPluginBase * plugin);
G_GNUC_INTERNAL
GstCaps *
gst_vaapi_plugin_base_get_allowed_srcpad_raw_caps (
GstVaapiPluginBase * plugin, GstVideoFormat format);
G_GNUC_INTERNAL G_GNUC_INTERNAL
void void
gst_vaapi_plugin_base_set_srcpad_can_dmabuf (GstVaapiPluginBase * plugin, gst_vaapi_plugin_base_set_srcpad_can_dmabuf (GstVaapiPluginBase * plugin,