};
static void
-upload_image (guint8 *dst, const guint32 *src, guint size)
+upload_subpicture(GstBuffer *buffer, const VideoSubpictureInfo *subinfo)
{
- guint i;
-
- for (i = 0; i < size; i += 4) {
- dst[i ] = *src >> 24;
- dst[i + 1] = *src >> 16;
- dst[i + 2] = *src >> 8;
- dst[i + 3] = *src++;
+ guint32 * const dst = (guint32 *)GST_BUFFER_DATA(buffer);
+ const guint32 * const src = subinfo->data;
+ guint i, len = subinfo->data_size / 4;
+
+ /* Convert from RGBA source to ARGB */
+ for (i = 0; i < len; i++) {
+ const guint32 rgba = src[i];
+ dst[i] = (rgba >> 8) | (rgba << 24);
}
}
GstVaapiSurface *surface;
GstBuffer *buffer;
VideoSubpictureInfo subinfo;
- GstVaapiImage *subtitle_image;
- GstVaapiSubpicture *subpicture;
- GstCaps *argbcaps;
- GstVaapiRectangle sub_rect;
- guint surf_width, surf_height;
+ GstVaapiRectangle subrect;
+ GstVideoOverlayRectangle *overlay;
+ GstVideoOverlayComposition *compo;
+ guint flags = 0;
static const guint win_width = 640;
static const guint win_height = 480;
if (!surface)
g_error("could not get decoded surface");
- gst_vaapi_surface_get_size(surface, &surf_width, &surf_height);
- printf("surface size %dx%d\n", surf_width, surf_height);
-
- subpicture_get_info (&subinfo);
-
- /* Adding subpicture */
- argbcaps = gst_caps_new_simple ("video/x-raw-rgb",
- "endianness", G_TYPE_INT, G_BIG_ENDIAN,
- "bpp", G_TYPE_INT, 32,
- "red_mask", G_TYPE_INT, 0xff000000,
- "green_mask", G_TYPE_INT, 0x00ff0000,
- "blue_mask", G_TYPE_INT, 0x0000ff00,
- "alpha_mask", G_TYPE_INT, 0x000000ff,
- "width", G_TYPE_INT, subinfo.width,
- "height", G_TYPE_INT, subinfo.height,
- NULL);
-
- buffer = gst_buffer_new_and_alloc (subinfo.data_size);
- upload_image (GST_BUFFER_DATA (buffer), subinfo.data, subinfo.data_size);
- gst_buffer_set_caps (buffer, argbcaps);
-
- subtitle_image = gst_vaapi_image_new (display,
- GST_VAAPI_IMAGE_RGBA, subinfo.width, subinfo.height);
-
- if (!gst_vaapi_image_update_from_buffer (subtitle_image, buffer, NULL))
- g_error ("could not update VA image with subtitle data");
-
- subpicture = gst_vaapi_subpicture_new (subtitle_image, 0);
+ subpicture_get_info(&subinfo);
+ buffer = gst_buffer_new_and_alloc(subinfo.data_size);
+ upload_subpicture(buffer, &subinfo);
+
+ /* We position the subpicture at the bottom center */
+ subrect.x = (gst_vaapi_surface_get_width(surface) - subinfo.width) / 2;
+ subrect.y = gst_vaapi_surface_get_height(surface) - subinfo.height - 10;
+ subrect.height = subinfo.height;
+ subrect.width = subinfo.width;
+
+ overlay = gst_video_overlay_rectangle_new_argb(buffer,
+ subinfo.width, subinfo.height, subinfo.width * 4,
+ subrect.x, subrect.y, subrect.width, subrect.height, flags);
+ if (!overlay)
+ g_error("could not create video overlay");
+ gst_buffer_unref(buffer);
- /* We position it as a subtitle, centered at the bottom. */
- sub_rect.x = (surf_width - subinfo.width) / 2;
- sub_rect.y = surf_height - subinfo.height - 10;
- sub_rect.height = subinfo.height;
- sub_rect.width = subinfo.width;
+ compo = gst_video_overlay_composition_new(overlay);
+ if (!compo)
+ g_error("could not create video overlay composition");
+ gst_video_overlay_rectangle_unref(overlay);
- if (!gst_vaapi_surface_associate_subpicture (
- surface,
- subpicture,
- NULL,
- &sub_rect))
- g_error("could not associate subpicture");
+ if (!gst_vaapi_surface_set_subpictures_from_composition(surface, compo,
+ FALSE))
+ g_error("could not create subpictures from video overlay compoition");
gst_vaapi_window_show(window);
pause();
- gst_buffer_unref(buffer);
+ gst_video_overlay_composition_unref(compo);
g_object_unref(decoder);
g_object_unref(window);
g_object_unref(display);