mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-23 16:50:47 +00:00
Simplify upload process and fallback to subpictures.
This commit is contained in:
parent
e4d9e06945
commit
992df1819e
1 changed files with 50 additions and 27 deletions
|
@ -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,35 +335,21 @@ 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];
|
||||
const GstVaapiImageFormat 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;
|
||||
}
|
||||
}
|
||||
if (!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))
|
||||
g_error("could not complete image upload");
|
||||
|
||||
|
|
Loading…
Reference in a new issue