From 992df1819e1b3a27b336e002a49928e065dc0e66 Mon Sep 17 00:00:00 2001 From: gb Date: Wed, 24 Mar 2010 14:36:39 +0000 Subject: [PATCH] Simplify upload process and fallback to subpictures. --- tests/test-windows.c | 77 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 50 insertions(+), 27 deletions(-) diff --git a/tests/test-windows.c b/tests/test-windows.c index bca4afc..b3ecd23 100644 --- a/tests/test-windows.c +++ b/tests/test-windows.c @@ -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"); -- 2.7.4