Simplify upload process and fallback to subpictures.

This commit is contained in:
gb 2010-03-24 14:36:39 +00:00
parent e4d9e06945
commit 992df1819e

View file

@ -258,15 +258,52 @@ static gboolean draw_rgb_rects(GstVaapiImage *image)
return TRUE; 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 int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
GstVaapiDisplay *display; GstVaapiDisplay *display;
GstVaapiWindow *window; GstVaapiWindow *window;
GstVaapiSurface *surface; GstVaapiSurface *surface;
GstVaapiImage *image = NULL; GstVaapiImage *image = NULL;
GstVaapiSubpicture *subpicture;
GstVaapiImageFormat format;
guint flags = GST_VAAPI_PICTURE_STRUCTURE_FRAME; guint flags = GST_VAAPI_PICTURE_STRUCTURE_FRAME;
guint i; guint i;
@ -298,35 +335,21 @@ main(int argc, char *argv[])
g_error("could not create Gst/VA surface"); g_error("could not create Gst/VA surface");
for (i = 0; image_formats[i]; i++) { for (i = 0; image_formats[i]; i++) {
image = gst_vaapi_image_new(display, image_formats[i], width, height); const GstVaapiImageFormat format = image_formats[i];
if (image) {
format = image_formats[i]; image = gst_vaapi_image_new(display, format, width, height);
if (!image)
continue;
if (!draw_rgb_rects(image))
g_error("could not draw RGB rectangles");
if (upload_image(surface, image))
break; break;
}
} }
if (!image) if (!image)
g_error("could not create Gst/VA image"); g_error("could not create Gst/VA image");
if (!draw_rgb_rects(image))
g_error("could not draw RGB rectangles");
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 (!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 (!gst_vaapi_surface_sync(surface)) if (!gst_vaapi_surface_sync(surface))
g_error("could not complete image upload"); g_error("could not complete image upload");