Commit 992df181 authored by gb's avatar gb

Simplify upload process and fallback to subpictures.

parent e4d9e069
......@@ -258,15 +258,52 @@ static gboolean draw_rgb_rects(GstVaapiImage *image)
return TRUE;
}
static gboolean
upload_image(GstVaapiSurface *surface, GstVaapiImage *image)
{
GstVaapiDisplay *display;
GstVaapiImageFormat format;
GstVaapiSubpicture *subpicture;
display = gst_vaapi_object_get_display(GST_VAAPI_OBJECT(surface));
if (!display)
return FALSE;
format = gst_vaapi_image_get_format(image);
if (!format)
return FALSE;
if (gst_vaapi_surface_put_image(surface, image))
return TRUE;
g_print("could not upload %" GST_FOURCC_FORMAT" image to surface\n",
GST_FOURCC_ARGS(format));
if (!gst_vaapi_display_has_subpicture_format(display, format))
return FALSE;
g_print("trying as a subpicture\n");
subpicture = gst_vaapi_subpicture_new(image);
if (!subpicture)
g_error("could not create Gst/VA subpicture");
if (!gst_vaapi_surface_associate_subpicture(surface, subpicture,
NULL, NULL))
g_error("could not associate subpicture to surface");
/* The surface holds a reference to the subpicture. This is safe */
g_object_unref(subpicture);
return TRUE;
}
int
main(int argc, char *argv[])
{
GstVaapiDisplay *display;
GstVaapiWindow *window;
GstVaapiSurface *surface;
GstVaapiImage *image = NULL;
GstVaapiSubpicture *subpicture;
GstVaapiImageFormat format;
GstVaapiImage *image = NULL;
guint flags = GST_VAAPI_PICTURE_STRUCTURE_FRAME;
guint i;
......@@ -298,34 +335,20 @@ main(int argc, char *argv[])
g_error("could not create Gst/VA surface");
for (i = 0; image_formats[i]; i++) {
image = gst_vaapi_image_new(display, image_formats[i], width, height);
if (image) {
format = image_formats[i];
break;
}
}
if (!image)
g_error("could not create Gst/VA image");
const GstVaapiImageFormat format = image_formats[i];
if (!draw_rgb_rects(image))
g_error("could not draw RGB rectangles");
image = gst_vaapi_image_new(display, format, width, height);
if (!image)
continue;
if (gst_vaapi_image_format_is_rgb(format)) {
subpicture = gst_vaapi_subpicture_new(image);
if (!subpicture)
g_error("could not create Gst/VA subpicture");
if (!draw_rgb_rects(image))
g_error("could not draw RGB rectangles");
if (!gst_vaapi_surface_associate_subpicture(surface, subpicture,
NULL, NULL))
g_error("could not associate subpicture to surface");
/* The surface holds a reference to the subpicture. This is safe. */
g_object_unref(subpicture);
}
else {
if (!gst_vaapi_surface_put_image(surface, image))
g_error("could not upload image");
if (upload_image(surface, image))
break;
}
if (!image)
g_error("could not create Gst/VA image");
if (!gst_vaapi_surface_sync(surface))
g_error("could not complete image upload");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment