display: don't use GstCaps for image or subpicture formats list.

Replace gst_vaapi_display_get_{image,subpicture}_caps() APIs, that
returned GstCaps, with more convenient APIs that return an array of
GstVideoFormat: gst_vaapi_display_get_{image,subpicture}_formats().
This commit is contained in:
Gwenole Beauchesne 2013-12-20 15:15:05 +01:00
parent 446b060c7a
commit c4ca08a8d6
5 changed files with 80 additions and 68 deletions

View file

@ -394,24 +394,22 @@ find_format (GArray * formats, GstVideoFormat format)
} }
/* Convert formats array to GstCaps */ /* Convert formats array to GstCaps */
static GstCaps * static GArray *
get_format_caps (GArray * formats) get_formats (GArray * formats)
{ {
const GstVaapiFormatInfo *fip; const GstVaapiFormatInfo *fip;
GstCaps *out_caps, *caps; GArray *out_formats;
guint i; guint i;
out_caps = gst_caps_new_empty (); out_formats = g_array_new (FALSE, FALSE, sizeof (GstVideoFormat));
if (!out_caps) if (!out_formats)
return NULL; return NULL;
for (i = 0; i < formats->len; i++) { for (i = 0; i < formats->len; i++) {
fip = &g_array_index (formats, GstVaapiFormatInfo, i); fip = &g_array_index (formats, GstVaapiFormatInfo, i);
caps = gst_vaapi_video_format_to_caps (fip->format); g_array_append_val (out_formats, fip->format);
if (caps)
gst_caps_append (out_caps, caps);
} }
return out_caps; return out_formats;
} }
/* Find display attribute */ /* Find display attribute */
@ -1448,11 +1446,11 @@ gst_vaapi_display_has_encoder (GstVaapiDisplay * display,
} }
/** /**
* gst_vaapi_display_get_image_caps: * gst_vaapi_display_get_image_formats:
* @display: a #GstVaapiDisplay * @display: a #GstVaapiDisplay
* *
* Gets the supported image formats for gst_vaapi_surface_get_image() * Gets the supported image formats for gst_vaapi_surface_get_image()
* or gst_vaapi_surface_put_image() as #GstCaps capabilities. * or gst_vaapi_surface_put_image().
* *
* Note that this method does not necessarily map image formats * Note that this method does not necessarily map image formats
* returned by vaQueryImageFormats(). The set of capabilities can be * returned by vaQueryImageFormats(). The set of capabilities can be
@ -1461,17 +1459,21 @@ gst_vaapi_display_has_encoder (GstVaapiDisplay * display,
* driver. e.g. I420 can be supported even if the driver only exposes * driver. e.g. I420 can be supported even if the driver only exposes
* YV12. * YV12.
* *
* Return value: a newly allocated #GstCaps object, possibly empty * Note: the caller owns an extra reference to the resulting array of
* #GstVideoFormat elements, so it shall be released with
* g_array_unref() after usage.
*
* Return value: a newly allocated #GArray, or %NULL on error or if
* the set is empty
*/ */
GstCaps * GArray *
gst_vaapi_display_get_image_caps (GstVaapiDisplay * display) gst_vaapi_display_get_image_formats (GstVaapiDisplay * display)
{ {
g_return_val_if_fail (display != NULL, NULL); g_return_val_if_fail (display != NULL, NULL);
if (!ensure_image_formats (display)) if (!ensure_image_formats (display))
return NULL; return NULL;
return get_format_caps (GST_VAAPI_DISPLAY_GET_PRIVATE (display)-> return get_formats (GST_VAAPI_DISPLAY_GET_PRIVATE (display)->image_formats);
image_formats);
} }
/** /**
@ -1509,26 +1511,31 @@ gst_vaapi_display_has_image_format (GstVaapiDisplay * display,
} }
/** /**
* gst_vaapi_display_get_subpicture_caps: * gst_vaapi_display_get_subpicture_formats:
* @display: a #GstVaapiDisplay * @display: a #GstVaapiDisplay
* *
* Gets the supported subpicture formats as #GstCaps capabilities. * Gets the supported subpicture formats.
* *
* Note that this method does not necessarily map subpicture formats * Note that this method does not necessarily map subpicture formats
* returned by vaQuerySubpictureFormats(). The set of capabilities can * returned by vaQuerySubpictureFormats(). The set of capabilities can
* be stripped down if gstreamer-vaapi does not support the * be stripped down if gstreamer-vaapi does not support the
* format. e.g. this is the case for paletted formats like IA44. * format. e.g. this is the case for paletted formats like IA44.
* *
* Return value: a newly allocated #GstCaps object, possibly empty * Note: the caller owns an extra reference to the resulting array of
* #GstVideoFormat elements, so it shall be released with
* g_array_unref() after usage.
*
* Return value: a newly allocated #GArray, or %NULL on error of if
* the set is empty
*/ */
GstCaps * GArray *
gst_vaapi_display_get_subpicture_caps (GstVaapiDisplay * display) gst_vaapi_display_get_subpicture_formats (GstVaapiDisplay * display)
{ {
g_return_val_if_fail (display != NULL, NULL); g_return_val_if_fail (display != NULL, NULL);
if (!ensure_subpicture_formats (display)) if (!ensure_subpicture_formats (display))
return NULL; return NULL;
return get_format_caps (GST_VAAPI_DISPLAY_GET_PRIVATE (display)-> return get_formats (GST_VAAPI_DISPLAY_GET_PRIVATE (display)->
subpicture_formats); subpicture_formats);
} }

View file

@ -158,15 +158,15 @@ gboolean
gst_vaapi_display_has_encoder (GstVaapiDisplay * display, gst_vaapi_display_has_encoder (GstVaapiDisplay * display,
GstVaapiProfile profile, GstVaapiEntrypoint entrypoint); GstVaapiProfile profile, GstVaapiEntrypoint entrypoint);
GstCaps * GArray *
gst_vaapi_display_get_image_caps (GstVaapiDisplay * display); gst_vaapi_display_get_image_formats (GstVaapiDisplay * display);
gboolean gboolean
gst_vaapi_display_has_image_format (GstVaapiDisplay * display, gst_vaapi_display_has_image_format (GstVaapiDisplay * display,
GstVideoFormat format); GstVideoFormat format);
GstCaps * GArray *
gst_vaapi_display_get_subpicture_caps (GstVaapiDisplay * display); gst_vaapi_display_get_subpicture_formats (GstVaapiDisplay * display);
gboolean gboolean
gst_vaapi_display_has_subpicture_format (GstVaapiDisplay * display, gst_vaapi_display_has_subpicture_format (GstVaapiDisplay * display,

View file

@ -391,6 +391,8 @@ gst_vaapidownload_transform_caps(
GstPad *srcpad; GstPad *srcpad;
GstCaps *allowed_caps, *inter_caps, *out_caps = NULL; GstCaps *allowed_caps, *inter_caps, *out_caps = NULL;
GstStructure *structure; GstStructure *structure;
GArray *formats;
guint i;
g_return_val_if_fail(GST_IS_CAPS(caps), NULL); g_return_val_if_fail(GST_IS_CAPS(caps), NULL);
@ -409,10 +411,21 @@ gst_vaapidownload_transform_caps(
if (download->allowed_caps) if (download->allowed_caps)
allowed_caps = gst_caps_ref(download->allowed_caps); allowed_caps = gst_caps_ref(download->allowed_caps);
else { else {
allowed_caps = gst_vaapi_display_get_image_caps( allowed_caps = gst_caps_new_empty();
GST_VAAPI_PLUGIN_BASE_DISPLAY(download));
if (!allowed_caps) if (!allowed_caps)
return NULL; return NULL;
formats = gst_vaapi_display_get_image_formats(
GST_VAAPI_PLUGIN_BASE_DISPLAY(download));
if (formats) {
for (i = 0; i < formats->len; i++) {
const GstVideoFormat format =
g_array_index(formats, GstVideoFormat, i);
gst_caps_merge(allowed_caps,
gst_vaapi_video_format_to_caps(format));
}
g_array_unref(formats);
}
} }
inter_caps = gst_caps_intersect(out_caps, allowed_caps); inter_caps = gst_caps_intersect(out_caps, allowed_caps);
gst_caps_unref(allowed_caps); gst_caps_unref(allowed_caps);

View file

@ -112,8 +112,9 @@ ensure_allowed_caps(GstVaapiUploader *uploader)
{ {
GstVaapiUploaderPrivate * const priv = uploader->priv; GstVaapiUploaderPrivate * const priv = uploader->priv;
GstVaapiSurface *surface = NULL; GstVaapiSurface *surface = NULL;
GstCaps *out_caps, *image_caps = NULL; GArray *image_formats = NULL;
guint i, n_structures; GstCaps *out_caps;
guint i;
gboolean success = FALSE; gboolean success = FALSE;
enum { WIDTH = 64, HEIGHT = 64 }; enum { WIDTH = 64, HEIGHT = 64 };
@ -125,8 +126,8 @@ ensure_allowed_caps(GstVaapiUploader *uploader)
if (!out_caps) if (!out_caps)
return FALSE; return FALSE;
image_caps = gst_vaapi_display_get_image_caps(priv->display); image_formats = gst_vaapi_display_get_image_formats(priv->display);
if (!image_caps) if (!image_formats)
goto end; goto end;
surface = gst_vaapi_surface_new(priv->display, surface = gst_vaapi_surface_new(priv->display,
@ -134,20 +135,18 @@ ensure_allowed_caps(GstVaapiUploader *uploader)
if (!surface) if (!surface)
goto end; goto end;
n_structures = gst_caps_get_size(image_caps); for (i = 0; i < image_formats->len; i++) {
for (i = 0; i < n_structures; i++) { const GstVideoFormat format =
GstStructure * const structure = gst_caps_get_structure(image_caps, i); g_array_index(image_formats, GstVideoFormat, i);
GstVaapiImage *image; GstVaapiImage *image;
GstVideoFormat format;
format = gst_vaapi_video_format_from_structure(structure);
if (format == GST_VIDEO_FORMAT_UNKNOWN) if (format == GST_VIDEO_FORMAT_UNKNOWN)
continue; continue;
image = gst_vaapi_image_new(priv->display, format, WIDTH, HEIGHT); image = gst_vaapi_image_new(priv->display, format, WIDTH, HEIGHT);
if (!image) if (!image)
continue; continue;
if (ensure_image(image) && gst_vaapi_surface_put_image(surface, image)) if (ensure_image(image) && gst_vaapi_surface_put_image(surface, image))
gst_caps_append_structure(out_caps, gst_structure_copy(structure)); gst_caps_append(out_caps, gst_vaapi_video_format_to_caps(format));
gst_vaapi_object_unref(image); gst_vaapi_object_unref(image);
} }
@ -156,8 +155,8 @@ ensure_allowed_caps(GstVaapiUploader *uploader)
end: end:
gst_caps_unref(out_caps); gst_caps_unref(out_caps);
if (image_caps) if (image_formats)
gst_caps_unref(image_caps); g_array_unref(image_formats);
if (surface) if (surface)
gst_vaapi_object_unref(surface); gst_vaapi_object_unref(surface);
return success; return success;

View file

@ -94,7 +94,7 @@ print_profile_caps(GstCaps *caps, const gchar *name)
} }
static void static void
print_format_caps_yuv(const VAImageFormat *va_format) print_format_yuv(const VAImageFormat *va_format)
{ {
const guint32 fourcc = va_format->fourcc; const guint32 fourcc = va_format->fourcc;
@ -106,7 +106,7 @@ print_format_caps_yuv(const VAImageFormat *va_format)
} }
static void static void
print_format_caps_rgb(const VAImageFormat *va_format) print_format_rgb(const VAImageFormat *va_format)
{ {
g_print(" %d bits per pixel, %s endian,", g_print(" %d bits per pixel, %s endian,",
va_format->bits_per_pixel, va_format->bits_per_pixel,
@ -119,34 +119,26 @@ print_format_caps_rgb(const VAImageFormat *va_format)
} }
static void static void
print_format_caps(GstCaps *caps, const gchar *name) print_formats(GArray *formats, const gchar *name)
{ {
guint i, n_caps = gst_caps_get_size(caps); guint i;
g_print("%u %s caps\n", n_caps, name); g_print("%u %s caps\n", formats->len, name);
for (i = 0; i < gst_caps_get_size(caps); i++) { for (i = 0; i < formats->len; i++) {
GstStructure * const structure = gst_caps_get_structure(caps, i); const GstVideoFormat format = g_array_index(formats, GstVideoFormat, i);
const VAImageFormat *va_format; const VAImageFormat *va_format;
GstVideoFormat format;
if (!structure) g_print(" %s:", gst_vaapi_video_format_to_string(format));
g_error("could not get caps structure %d", i);
g_print(" %s:", gst_structure_get_name(structure));
format = gst_vaapi_video_format_from_structure(structure);
if (format == GST_VIDEO_FORMAT_UNKNOWN)
g_error("could not determine format");
va_format = gst_vaapi_video_format_to_va_format(format); va_format = gst_vaapi_video_format_to_va_format(format);
if (!va_format) if (!va_format)
g_error("could not determine VA format"); g_error("could not determine VA format");
if (gst_vaapi_video_format_is_yuv(format)) if (gst_vaapi_video_format_is_yuv(format))
print_format_caps_yuv(va_format); print_format_yuv(va_format);
else else
print_format_caps_rgb(va_format); print_format_rgb(va_format);
g_print("\n"); g_print("\n");
} }
} }
@ -240,6 +232,7 @@ end:
static void static void
dump_info(GstVaapiDisplay *display) dump_info(GstVaapiDisplay *display)
{ {
GArray *formats;
GstCaps *caps; GstCaps *caps;
caps = gst_vaapi_display_get_decode_caps(display); caps = gst_vaapi_display_get_decode_caps(display);
@ -256,19 +249,19 @@ dump_info(GstVaapiDisplay *display)
print_profile_caps(caps, "encoders"); print_profile_caps(caps, "encoders");
gst_caps_unref(caps); gst_caps_unref(caps);
caps = gst_vaapi_display_get_image_caps(display); formats = gst_vaapi_display_get_image_formats(display);
if (!caps) if (!formats)
g_error("could not get VA image caps"); g_error("could not get VA image formats");
print_format_caps(caps, "image"); print_formats(formats, "image");
gst_caps_unref(caps); g_array_unref(formats);
caps = gst_vaapi_display_get_subpicture_caps(display); formats = gst_vaapi_display_get_subpicture_formats(display);
if (!caps) if (!formats)
g_error("could not get VA subpicture caps"); g_error("could not get VA subpicture formats");
print_format_caps(caps, "subpicture"); print_formats(formats, "subpicture");
gst_caps_unref(caps); g_array_unref(formats);
dump_properties(display); dump_properties(display);
} }