2 * gstvaapisurface.c - VA surface abstraction
4 * Copyright (C) 2010-2011 Splitted-Desktop Systems
5 * Copyright (C) 2011 Intel Corporation
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public License
9 * as published by the Free Software Foundation; either version 2.1
10 * of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301 USA
24 * SECTION:gstvaapisurface
25 * @short_description: VA surface abstraction
29 #include "gstvaapicompat.h"
30 #include "gstvaapiutils.h"
31 #include "gstvaapisurface.h"
32 #include "gstvaapisurface_priv.h"
33 #include "gstvaapicontext.h"
34 #include "gstvaapiimage.h"
35 #include "gstvaapi_priv.h"
38 #include "gstvaapidebug.h"
40 G_DEFINE_TYPE(GstVaapiSurface, gst_vaapi_surface, GST_VAAPI_TYPE_OBJECT)
42 #define GST_VAAPI_SURFACE_GET_PRIVATE(obj) \
43 (G_TYPE_INSTANCE_GET_PRIVATE((obj), \
44 GST_VAAPI_TYPE_SURFACE, \
45 GstVaapiSurfacePrivate))
47 struct _GstVaapiSurfacePrivate {
50 GstVaapiChromaType chroma_type;
51 GPtrArray *subpictures;
52 GstVaapiContext *parent_context;
65 _gst_vaapi_surface_associate_subpicture(
66 GstVaapiSurface *surface,
67 GstVaapiSubpicture *subpicture,
68 const GstVaapiRectangle *src_rect,
69 const GstVaapiRectangle *dst_rect
73 _gst_vaapi_surface_deassociate_subpicture(
74 GstVaapiSurface *surface,
75 GstVaapiSubpicture *subpicture
79 destroy_subpicture_cb(gpointer subpicture, gpointer surface)
81 _gst_vaapi_surface_deassociate_subpicture(surface, subpicture);
82 g_object_unref(subpicture);
86 gst_vaapi_surface_destroy_subpictures(GstVaapiSurface *surface)
88 GstVaapiSurfacePrivate * const priv = surface->priv;
90 if (priv->subpictures) {
91 g_ptr_array_foreach(priv->subpictures, destroy_subpicture_cb, surface);
92 g_ptr_array_free(priv->subpictures, TRUE);
93 priv->subpictures = NULL;
98 gst_vaapi_surface_destroy(GstVaapiSurface *surface)
100 GstVaapiDisplay * const display = GST_VAAPI_OBJECT_DISPLAY(surface);
101 VASurfaceID surface_id;
104 surface_id = GST_VAAPI_OBJECT_ID(surface);
105 GST_DEBUG("surface %" GST_VAAPI_ID_FORMAT, GST_VAAPI_ID_ARGS(surface_id));
107 gst_vaapi_surface_destroy_subpictures(surface);
108 gst_vaapi_surface_set_parent_context(surface, NULL);
110 if (surface_id != VA_INVALID_SURFACE) {
111 GST_VAAPI_DISPLAY_LOCK(display);
112 status = vaDestroySurfaces(
113 GST_VAAPI_DISPLAY_VADISPLAY(display),
116 GST_VAAPI_DISPLAY_UNLOCK(display);
117 if (!vaapi_check_status(status, "vaDestroySurfaces()"))
118 g_warning("failed to destroy surface %" GST_VAAPI_ID_FORMAT,
119 GST_VAAPI_ID_ARGS(surface_id));
120 GST_VAAPI_OBJECT_ID(surface) = VA_INVALID_SURFACE;
125 gst_vaapi_surface_create(GstVaapiSurface *surface)
127 GstVaapiDisplay * const display = GST_VAAPI_OBJECT_DISPLAY(surface);
128 GstVaapiSurfacePrivate * const priv = surface->priv;
129 VASurfaceID surface_id;
133 switch (priv->chroma_type) {
134 case GST_VAAPI_CHROMA_TYPE_YUV420:
135 format = VA_RT_FORMAT_YUV420;
137 case GST_VAAPI_CHROMA_TYPE_YUV422:
138 format = VA_RT_FORMAT_YUV422;
140 case GST_VAAPI_CHROMA_TYPE_YUV444:
141 format = VA_RT_FORMAT_YUV444;
144 GST_DEBUG("unsupported chroma-type %u\n", priv->chroma_type);
148 GST_VAAPI_DISPLAY_LOCK(display);
149 status = vaCreateSurfaces(
150 GST_VAAPI_DISPLAY_VADISPLAY(display),
156 GST_VAAPI_DISPLAY_UNLOCK(display);
157 if (!vaapi_check_status(status, "vaCreateSurfaces()"))
160 GST_DEBUG("surface %" GST_VAAPI_ID_FORMAT, GST_VAAPI_ID_ARGS(surface_id));
161 GST_VAAPI_OBJECT_ID(surface) = surface_id;
166 gst_vaapi_surface_finalize(GObject *object)
168 gst_vaapi_surface_destroy(GST_VAAPI_SURFACE(object));
170 G_OBJECT_CLASS(gst_vaapi_surface_parent_class)->finalize(object);
174 gst_vaapi_surface_set_property(
181 GstVaapiSurface * const surface = GST_VAAPI_SURFACE(object);
182 GstVaapiSurfacePrivate * const priv = surface->priv;
186 priv->width = g_value_get_uint(value);
189 priv->height = g_value_get_uint(value);
191 case PROP_CHROMA_TYPE:
192 priv->chroma_type = g_value_get_uint(value);
194 case PROP_PARENT_CONTEXT:
195 gst_vaapi_surface_set_parent_context(surface, g_value_get_object(value));
198 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
204 gst_vaapi_surface_get_property(
211 GstVaapiSurface * const surface = GST_VAAPI_SURFACE(object);
215 g_value_set_uint(value, gst_vaapi_surface_get_width(surface));
218 g_value_set_uint(value, gst_vaapi_surface_get_height(surface));
220 case PROP_CHROMA_TYPE:
221 g_value_set_uint(value, gst_vaapi_surface_get_chroma_type(surface));
223 case PROP_PARENT_CONTEXT:
224 g_value_set_object(value, gst_vaapi_surface_get_parent_context(surface));
227 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
233 gst_vaapi_surface_constructed(GObject *object)
235 GstVaapiSurface * const surface = GST_VAAPI_SURFACE(object);
236 GObjectClass *parent_class;
238 gst_vaapi_surface_create(surface);
240 parent_class = G_OBJECT_CLASS(gst_vaapi_surface_parent_class);
241 if (parent_class->constructed)
242 parent_class->constructed(object);
246 gst_vaapi_surface_class_init(GstVaapiSurfaceClass *klass)
248 GObjectClass * const object_class = G_OBJECT_CLASS(klass);
250 g_type_class_add_private(klass, sizeof(GstVaapiSurfacePrivate));
252 object_class->finalize = gst_vaapi_surface_finalize;
253 object_class->set_property = gst_vaapi_surface_set_property;
254 object_class->get_property = gst_vaapi_surface_get_property;
255 object_class->constructed = gst_vaapi_surface_constructed;
257 g_object_class_install_property
260 g_param_spec_uint("width",
262 "The width of the surface",
264 G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
266 g_object_class_install_property
269 g_param_spec_uint("height",
271 "The height of the surface",
273 G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
275 g_object_class_install_property
278 g_param_spec_uint("chroma-type",
280 "The chroma type of the surface",
282 G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
284 g_object_class_install_property
287 g_param_spec_object("parent-context",
289 "The parent context, if any",
290 GST_VAAPI_TYPE_CONTEXT,
291 G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
295 gst_vaapi_surface_init(GstVaapiSurface *surface)
297 GstVaapiSurfacePrivate *priv = GST_VAAPI_SURFACE_GET_PRIVATE(surface);
299 surface->priv = priv;
302 priv->chroma_type = 0;
303 priv->subpictures = NULL;
304 priv->parent_context = NULL;
308 * gst_vaapi_surface_new:
309 * @display: a #GstVaapiDisplay
310 * @chroma_type: the surface chroma format
311 * @width: the requested surface width
312 * @height: the requested surface height
314 * Creates a new #GstVaapiSurface with the specified chroma format and
317 * Return value: the newly allocated #GstVaapiSurface object
320 gst_vaapi_surface_new(
321 GstVaapiDisplay *display,
322 GstVaapiChromaType chroma_type,
327 GST_DEBUG("size %ux%u, chroma type 0x%x", width, height, chroma_type);
329 return g_object_new(GST_VAAPI_TYPE_SURFACE,
331 "id", GST_VAAPI_ID(VA_INVALID_ID),
334 "chroma-type", chroma_type,
339 * gst_vaapi_surface_get_id:
340 * @surface: a #GstVaapiSurface
342 * Returns the underlying VASurfaceID of the @surface.
344 * Return value: the underlying VA surface id
347 gst_vaapi_surface_get_id(GstVaapiSurface *surface)
349 g_return_val_if_fail(GST_VAAPI_IS_SURFACE(surface), VA_INVALID_SURFACE);
351 return GST_VAAPI_OBJECT_ID(surface);
355 * gst_vaapi_surface_get_chroma_type:
356 * @surface: a #GstVaapiSurface
358 * Returns the #GstVaapiChromaType the @surface was created with.
360 * Return value: the #GstVaapiChromaType
363 gst_vaapi_surface_get_chroma_type(GstVaapiSurface *surface)
365 g_return_val_if_fail(GST_VAAPI_IS_SURFACE(surface), 0);
367 return surface->priv->chroma_type;
371 * gst_vaapi_surface_get_width:
372 * @surface: a #GstVaapiSurface
374 * Returns the @surface width.
376 * Return value: the surface width, in pixels
379 gst_vaapi_surface_get_width(GstVaapiSurface *surface)
381 g_return_val_if_fail(GST_VAAPI_IS_SURFACE(surface), 0);
383 return surface->priv->width;
387 * gst_vaapi_surface_get_height:
388 * @surface: a #GstVaapiSurface
390 * Returns the @surface height.
392 * Return value: the surface height, in pixels.
395 gst_vaapi_surface_get_height(GstVaapiSurface *surface)
397 g_return_val_if_fail(GST_VAAPI_IS_SURFACE(surface), 0);
399 return surface->priv->height;
403 * gst_vaapi_surface_get_size:
404 * @surface: a #GstVaapiSurface
405 * @pwidth: return location for the width, or %NULL
406 * @pheight: return location for the height, or %NULL
408 * Retrieves the dimensions of a #GstVaapiSurface.
411 gst_vaapi_surface_get_size(
412 GstVaapiSurface *surface,
417 g_return_if_fail(GST_VAAPI_IS_SURFACE(surface));
420 *pwidth = gst_vaapi_surface_get_width(surface);
423 *pheight = gst_vaapi_surface_get_height(surface);
427 * gst_vaapi_surface_set_parent_context:
428 * @surface: a #GstVaapiSurface
429 * @context: a #GstVaapiContext
431 * Sets new parent context, or clears any parent context if @context
432 * is %NULL. This function owns an extra reference to the context,
433 * which will be released when the surface is destroyed.
436 gst_vaapi_surface_set_parent_context(
437 GstVaapiSurface *surface,
438 GstVaapiContext *context
441 GstVaapiSurfacePrivate *priv;
443 g_return_if_fail(GST_VAAPI_IS_SURFACE(surface));
445 priv = surface->priv;
447 g_clear_object(&priv->parent_context);
450 priv->parent_context = g_object_ref(context);
454 * gst_vaapi_surface_get_parent_context:
455 * @surface: a #GstVaapiSurface
457 * Retrieves the parent #GstVaapiContext, or %NULL if there is
458 * none. The surface shall still own a reference to the context.
459 * i.e. the caller shall not unreference the returned context object.
461 * Return value: the parent context, if any.
464 gst_vaapi_surface_get_parent_context(GstVaapiSurface *surface)
466 g_return_val_if_fail(GST_VAAPI_IS_SURFACE(surface), NULL);
468 return surface->priv->parent_context;
472 * gst_vaapi_surface_derive_image:
473 * @surface: a #GstVaapiSurface
475 * Derives a #GstVaapiImage from the @surface. This image buffer can
476 * then be mapped/unmapped for direct CPU access. This operation is
477 * only possible if the underlying implementation supports direct
478 * rendering capabilities and internal surface formats that can be
479 * represented with a #GstVaapiImage.
481 * When the operation is not possible, the function returns %NULL and
482 * the user should then fallback to using gst_vaapi_surface_get_image()
483 * or gst_vaapi_surface_put_image() to accomplish the same task in an
484 * indirect manner (additional copy).
486 * An image created with gst_vaapi_surface_derive_image() should be
487 * unreferenced when it's no longer needed. The image and image buffer
488 * data structures will be destroyed. However, the surface contents
489 * will remain unchanged until destroyed through the last call to
492 * Return value: the newly allocated #GstVaapiImage object, or %NULL
496 gst_vaapi_surface_derive_image(GstVaapiSurface *surface)
498 GstVaapiDisplay *display;
502 g_return_val_if_fail(GST_VAAPI_IS_SURFACE(surface), NULL);
504 display = GST_VAAPI_OBJECT_DISPLAY(surface);
505 va_image.image_id = VA_INVALID_ID;
506 va_image.buf = VA_INVALID_ID;
508 GST_VAAPI_DISPLAY_LOCK(display);
509 status = vaDeriveImage(
510 GST_VAAPI_DISPLAY_VADISPLAY(display),
511 GST_VAAPI_OBJECT_ID(surface),
514 GST_VAAPI_DISPLAY_UNLOCK(display);
515 if (!vaapi_check_status(status, "vaDeriveImage()"))
517 if (va_image.image_id == VA_INVALID_ID || va_image.buf == VA_INVALID_ID)
520 return gst_vaapi_image_new_with_image(display, &va_image);
524 * gst_vaapi_surface_get_image
525 * @surface: a #GstVaapiSurface
526 * @image: a #GstVaapiImage
528 * Retrieves surface data into a #GstVaapiImage. The @image must have
529 * a format supported by the @surface.
531 * Return value: %TRUE on success
534 gst_vaapi_surface_get_image(GstVaapiSurface *surface, GstVaapiImage *image)
536 GstVaapiDisplay *display;
541 g_return_val_if_fail(GST_VAAPI_IS_SURFACE(surface), FALSE);
542 g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), FALSE);
544 display = GST_VAAPI_OBJECT_DISPLAY(surface);
548 gst_vaapi_image_get_size(image, &width, &height);
549 if (width != surface->priv->width || height != surface->priv->height)
552 image_id = GST_VAAPI_OBJECT_ID(image);
553 if (image_id == VA_INVALID_ID)
556 GST_VAAPI_DISPLAY_LOCK(display);
558 GST_VAAPI_DISPLAY_VADISPLAY(display),
559 GST_VAAPI_OBJECT_ID(surface),
563 GST_VAAPI_DISPLAY_UNLOCK(display);
564 if (!vaapi_check_status(status, "vaGetImage()"))
571 * gst_vaapi_surface_put_image:
572 * @surface: a #GstVaapiSurface
573 * @image: a #GstVaapiImage
575 * Copies data from a #GstVaapiImage into a @surface. The @image must
576 * have a format supported by the @surface.
578 * Return value: %TRUE on success
581 gst_vaapi_surface_put_image(GstVaapiSurface *surface, GstVaapiImage *image)
583 GstVaapiDisplay *display;
588 g_return_val_if_fail(GST_VAAPI_IS_SURFACE(surface), FALSE);
589 g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), FALSE);
591 display = GST_VAAPI_OBJECT_DISPLAY(surface);
595 gst_vaapi_image_get_size(image, &width, &height);
596 if (width != surface->priv->width || height != surface->priv->height)
599 image_id = GST_VAAPI_OBJECT_ID(image);
600 if (image_id == VA_INVALID_ID)
603 GST_VAAPI_DISPLAY_LOCK(display);
605 GST_VAAPI_DISPLAY_VADISPLAY(display),
606 GST_VAAPI_OBJECT_ID(surface),
611 GST_VAAPI_DISPLAY_UNLOCK(display);
612 if (!vaapi_check_status(status, "vaPutImage()"))
619 * gst_vaapi_surface_associate_subpicture:
620 * @surface: a #GstVaapiSurface
621 * @subpicture: a #GstVaapiSubpicture
622 * @src_rect: the sub-rectangle of the source subpicture
623 * image to extract and process. If %NULL, the entire image will be used.
624 * @dst_rect: the sub-rectangle of the destination
625 * surface into which the image is rendered. If %NULL, the entire
626 * surface will be used.
628 * Associates the @subpicture with the @surface. The @src_rect
629 * coordinates and size are relative to the source image bound to
630 * @subpicture. The @dst_rect coordinates and size are relative to the
631 * target @surface. Note that the @surface holds an additional
632 * reference to the @subpicture.
634 * Return value: %TRUE on success
637 gst_vaapi_surface_associate_subpicture(
638 GstVaapiSurface *surface,
639 GstVaapiSubpicture *subpicture,
640 const GstVaapiRectangle *src_rect,
641 const GstVaapiRectangle *dst_rect
646 g_return_val_if_fail(GST_VAAPI_IS_SURFACE(surface), FALSE);
647 g_return_val_if_fail(GST_VAAPI_IS_SUBPICTURE(subpicture), FALSE);
649 if (!surface->priv->subpictures) {
650 surface->priv->subpictures = g_ptr_array_new();
651 if (!surface->priv->subpictures)
655 if (g_ptr_array_remove_fast(surface->priv->subpictures, subpicture)) {
656 success = _gst_vaapi_surface_deassociate_subpicture(surface, subpicture);
657 g_object_unref(subpicture);
662 success = _gst_vaapi_surface_associate_subpicture(
671 g_ptr_array_add(surface->priv->subpictures, g_object_ref(subpicture));
676 _gst_vaapi_surface_associate_subpicture(
677 GstVaapiSurface *surface,
678 GstVaapiSubpicture *subpicture,
679 const GstVaapiRectangle *src_rect,
680 const GstVaapiRectangle *dst_rect
683 GstVaapiDisplay *display;
684 GstVaapiRectangle src_rect_default, dst_rect_default;
685 GstVaapiImage *image;
686 VASurfaceID surface_id;
689 display = GST_VAAPI_OBJECT_DISPLAY(surface);
693 surface_id = GST_VAAPI_OBJECT_ID(surface);
694 if (surface_id == VA_INVALID_SURFACE)
698 image = gst_vaapi_subpicture_get_image(subpicture);
701 src_rect = &src_rect_default;
702 src_rect_default.x = 0;
703 src_rect_default.y = 0;
704 gst_vaapi_image_get_size(
706 &src_rect_default.width,
707 &src_rect_default.height
712 dst_rect = &dst_rect_default;
713 dst_rect_default.x = 0;
714 dst_rect_default.y = 0;
715 dst_rect_default.width = surface->priv->width;
716 dst_rect_default.height = surface->priv->height;
719 GST_VAAPI_DISPLAY_LOCK(display);
720 status = vaAssociateSubpicture(
721 GST_VAAPI_DISPLAY_VADISPLAY(display),
722 GST_VAAPI_OBJECT_ID(subpicture),
724 src_rect->x, src_rect->y, src_rect->width, src_rect->height,
725 dst_rect->x, dst_rect->y, dst_rect->width, dst_rect->height,
728 GST_VAAPI_DISPLAY_UNLOCK(display);
729 if (!vaapi_check_status(status, "vaAssociateSubpicture()"))
736 * gst_vaapi_surface_deassociate_subpicture:
737 * @surface: a #GstVaapiSurface
738 * @subpicture: a #GstVaapiSubpicture
740 * Deassociates @subpicture from @surface. Other associations are kept.
742 * Return value: %TRUE on success
745 gst_vaapi_surface_deassociate_subpicture(
746 GstVaapiSurface *surface,
747 GstVaapiSubpicture *subpicture
752 g_return_val_if_fail(GST_VAAPI_IS_SURFACE(surface), FALSE);
753 g_return_val_if_fail(GST_VAAPI_IS_SUBPICTURE(subpicture), FALSE);
755 if (!surface->priv->subpictures)
758 /* First, check subpicture was really associated with this surface */
759 if (!g_ptr_array_remove_fast(surface->priv->subpictures, subpicture)) {
760 GST_DEBUG("subpicture %" GST_VAAPI_ID_FORMAT " was not bound to "
761 "surface %" GST_VAAPI_ID_FORMAT,
762 GST_VAAPI_ID_ARGS(GST_VAAPI_OBJECT_ID(subpicture)),
763 GST_VAAPI_ID_ARGS(GST_VAAPI_OBJECT_ID(surface)));
767 success = _gst_vaapi_surface_deassociate_subpicture(surface, subpicture);
768 g_object_unref(subpicture);
773 _gst_vaapi_surface_deassociate_subpicture(
774 GstVaapiSurface *surface,
775 GstVaapiSubpicture *subpicture
778 GstVaapiDisplay *display;
779 VASurfaceID surface_id;
782 display = GST_VAAPI_OBJECT_DISPLAY(surface);
786 surface_id = GST_VAAPI_OBJECT_ID(surface);
787 if (surface_id == VA_INVALID_SURFACE)
790 GST_VAAPI_DISPLAY_LOCK(display);
791 status = vaDeassociateSubpicture(
792 GST_VAAPI_DISPLAY_VADISPLAY(display),
793 GST_VAAPI_OBJECT_ID(subpicture),
796 GST_VAAPI_DISPLAY_UNLOCK(display);
797 if (!vaapi_check_status(status, "vaDeassociateSubpicture()"))
804 * gst_vaapi_surface_sync:
805 * @surface: a #GstVaapiSurface
807 * Blocks until all pending operations on the @surface have been
810 * Return value: %TRUE on success
813 gst_vaapi_surface_sync(GstVaapiSurface *surface)
815 GstVaapiDisplay *display;
818 g_return_val_if_fail(GST_VAAPI_IS_SURFACE(surface), FALSE);
820 display = GST_VAAPI_OBJECT_DISPLAY(surface);
824 GST_VAAPI_DISPLAY_LOCK(display);
825 status = vaSyncSurface(
826 GST_VAAPI_DISPLAY_VADISPLAY(display),
827 GST_VAAPI_OBJECT_ID(surface)
829 GST_VAAPI_DISPLAY_UNLOCK(display);
830 if (!vaapi_check_status(status, "vaSyncSurface()"))
837 * gst_vaapi_surface_query_status:
838 * @surface: a #GstVaapiSurface
839 * @pstatus: return location for the #GstVaapiSurfaceStatus
841 * Finds out any pending operations on the @surface. The
842 * #GstVaapiSurfaceStatus flags are returned into @pstatus.
844 * Return value: %TRUE on success
847 gst_vaapi_surface_query_status(
848 GstVaapiSurface *surface,
849 GstVaapiSurfaceStatus *pstatus
852 VASurfaceStatus surface_status;
855 g_return_val_if_fail(GST_VAAPI_IS_SURFACE(surface), FALSE);
857 GST_VAAPI_OBJECT_LOCK_DISPLAY(surface);
858 status = vaQuerySurfaceStatus(
859 GST_VAAPI_OBJECT_VADISPLAY(surface),
860 GST_VAAPI_OBJECT_ID(surface),
863 GST_VAAPI_OBJECT_UNLOCK_DISPLAY(surface);
864 if (!vaapi_check_status(status, "vaQuerySurfaceStatus()"))
868 *pstatus = to_GstVaapiSurfaceStatus(surface_status);
873 * gst_vaapi_surface_set_subpictures_from_composition:
874 * @surface: a #GstVaapiSurface
875 * @compostion: a #GstVideoOverlayCompositon
876 * @propagate_context: a flag specifying whether to apply composition
877 * to the parent context, if any
879 * Helper to update the subpictures from #GstVideoOverlayCompositon. Sending
880 * a NULL composition will clear all the current subpictures. Note that this
881 * method will clear existing subpictures.
883 * Return value: %TRUE on success
886 gst_vaapi_surface_set_subpictures_from_composition(
887 GstVaapiSurface *surface,
888 GstVideoOverlayComposition *composition,
889 gboolean propagate_context
892 GstVaapiDisplay *display;
893 guint n, nb_rectangles;
895 g_return_val_if_fail(GST_VAAPI_IS_SURFACE(surface), FALSE);
897 if (propagate_context) {
898 GstVaapiContext * const context = surface->priv->parent_context;
900 return gst_vaapi_context_apply_composition(context, composition);
903 display = GST_VAAPI_OBJECT_DISPLAY(surface);
907 /* Clear current subpictures */
908 gst_vaapi_surface_destroy_subpictures(surface);
913 nb_rectangles = gst_video_overlay_composition_n_rectangles (composition);
915 /* Overlay all the rectangles cantained in the overlay composition */
916 for (n = 0; n < nb_rectangles; ++n) {
917 GstVideoOverlayRectangle *rect;
918 GstVaapiRectangle sub_rect;
919 GstVaapiSubpicture *subpicture;
921 rect = gst_video_overlay_composition_get_rectangle (composition, n);
922 subpicture = gst_vaapi_subpicture_new_from_overlay_rectangle (display,
925 gst_video_overlay_rectangle_get_render_rectangle (rect,
926 (gint *)&sub_rect.x, (gint *)&sub_rect.y,
927 &sub_rect.width, &sub_rect.height);
929 if (!gst_vaapi_surface_associate_subpicture (surface, subpicture,
931 GST_WARNING ("could not render overlay rectangle %p", rect);
932 g_object_unref (subpicture);
935 g_object_unref (subpicture);