Blame gst-libs/gst/video/video-overlay-composition.c

Packit 0652a1
/* GStreamer Video Overlay Composition
Packit 0652a1
 * Copyright (C) 2011 Intel Corporation
Packit 0652a1
 * Copyright (C) 2011 Collabora Ltd.
Packit 0652a1
 * Copyright (C) 2011 Tim-Philipp Müller <tim centricular net>
Packit 0652a1
 *
Packit 0652a1
 * This library is free software; you can redistribute it and/or
Packit 0652a1
 * modify it under the terms of the GNU Library General Public
Packit 0652a1
 * License as published by the Free Software Foundation; either
Packit 0652a1
 * version 2 of the License, or (at your option) any later version.
Packit 0652a1
 *
Packit 0652a1
 * This library is distributed in the hope that it will be useful,
Packit 0652a1
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 0652a1
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 0652a1
 * Library General Public License for more details.
Packit 0652a1
 *
Packit 0652a1
 * You should have received a copy of the GNU Library General Public
Packit 0652a1
 * License along with this library; if not, write to the
Packit 0652a1
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Packit 0652a1
 * Boston, MA 02110-1301, USA.
Packit 0652a1
 */
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * SECTION:gstvideooverlaycomposition
Packit 0652a1
 * @title: GstVideoOverlayRectangle
Packit 0652a1
 * @short_description: Video Buffer Overlay Compositions (Subtitles, Logos)
Packit 0652a1
 *
Packit 0652a1
 * Functions to create and handle overlay compositions on video buffers.
Packit 0652a1
 *
Packit 0652a1
 * An overlay composition describes one or more overlay rectangles to be
Packit 0652a1
 * blended on top of a video buffer.
Packit 0652a1
 *
Packit 0652a1
 * This API serves two main purposes:
Packit 0652a1
 *
Packit 0652a1
 * * it can be used to attach overlay information (subtitles or logos)
Packit 0652a1
 *   to non-raw video buffers such as GL/VAAPI/VDPAU surfaces. The actual
Packit 0652a1
 *   blending of the overlay can then be done by e.g. the video sink that
Packit 0652a1
 *   processes these non-raw buffers.
Packit 0652a1
 *
Packit 0652a1
 * * it can also be used to blend overlay rectangles on top of raw video
Packit 0652a1
 *   buffers, thus consolidating blending functionality for raw video in
Packit 0652a1
 *   one place.
Packit 0652a1
 *
Packit 0652a1
 * Together, this allows existing overlay elements to easily handle raw
Packit 0652a1
 * and non-raw video as input in without major changes (once the overlays
Packit 0652a1
 * have been put into a #GstVideoOverlayComposition object anyway) - for raw
Packit 0652a1
 * video the overlay can just use the blending function to blend the data
Packit 0652a1
 * on top of the video, and for surface buffers it can just attach them to
Packit 0652a1
 * the buffer and let the sink render the overlays.
Packit 0652a1
 *
Packit 0652a1
 */
Packit 0652a1
Packit 0652a1
/* TODO:
Packit 0652a1
 *  - provide accessors for seq_num and other fields (as needed)
Packit 0652a1
 *  - allow overlay to set/get original pango markup string on/from rectangle
Packit 0652a1
 */
Packit 0652a1
Packit 0652a1
#ifdef HAVE_CONFIG_H
Packit 0652a1
#include "config.h"
Packit 0652a1
#endif
Packit 0652a1
Packit 0652a1
#include "video-overlay-composition.h"
Packit 0652a1
#include "video-blend.h"
Packit 0652a1
#include "gstvideometa.h"
Packit 0652a1
#include <string.h>
Packit 0652a1
Packit 0652a1
struct _GstVideoOverlayComposition
Packit 0652a1
{
Packit 0652a1
  GstMiniObject parent;
Packit 0652a1
Packit 0652a1
  guint num_rectangles;
Packit 0652a1
  GstVideoOverlayRectangle **rectangles;
Packit 0652a1
Packit 0652a1
  /* lowest rectangle sequence number still used by the upstream
Packit 0652a1
   * overlay element. This way a renderer maintaining some kind of
Packit 0652a1
   * rectangles <-> surface cache can know when to free cached
Packit 0652a1
   * surfaces/rectangles. */
Packit 0652a1
  guint min_seq_num_used;
Packit 0652a1
Packit 0652a1
  /* sequence number for the composition (same series as rectangles) */
Packit 0652a1
  guint seq_num;
Packit 0652a1
};
Packit 0652a1
Packit 0652a1
struct _GstVideoOverlayRectangle
Packit 0652a1
{
Packit 0652a1
  GstMiniObject parent;
Packit 0652a1
Packit 0652a1
  /* Position on video frame and dimension of output rectangle in
Packit 0652a1
   * output frame terms (already adjusted for the PAR of the output
Packit 0652a1
   * frame). x/y can be negative (overlay will be clipped then) */
Packit 0652a1
  gint x, y;
Packit 0652a1
  guint render_width, render_height;
Packit 0652a1
Packit 0652a1
  /* Info on overlay pixels (format, width, height) */
Packit 0652a1
  GstVideoInfo info;
Packit 0652a1
Packit 0652a1
  /* The flags associated to this rectangle */
Packit 0652a1
  GstVideoOverlayFormatFlags flags;
Packit 0652a1
Packit 0652a1
  /* Refcounted blob of memory, no caps or timestamps */
Packit 0652a1
  GstBuffer *pixels;
Packit 0652a1
Packit 0652a1
  /* FIXME: how to express source like text or pango markup?
Packit 0652a1
   *        (just add source type enum + source buffer with data)
Packit 0652a1
   *
Packit 0652a1
   * FOR 0.10: always send pixel blobs, but attach source data in
Packit 0652a1
   * addition (reason: if downstream changes, we can't renegotiate
Packit 0652a1
   * that properly, if we just do a query of supported formats from
Packit 0652a1
   * the start). Sink will just ignore pixels and use pango markup
Packit 0652a1
   * from source data if it supports that.
Packit 0652a1
   *
Packit 0652a1
   * FOR 0.11: overlay should query formats (pango markup, pixels)
Packit 0652a1
   * supported by downstream and then only send that. We can
Packit 0652a1
   * renegotiate via the reconfigure event.
Packit 0652a1
   */
Packit 0652a1
Packit 0652a1
  /* sequence number: useful for backends/renderers/sinks that want
Packit 0652a1
   * to maintain a cache of rectangles <-> surfaces. The value of
Packit 0652a1
   * the min_seq_num_used in the composition tells the renderer which
Packit 0652a1
   * rectangles have expired. */
Packit 0652a1
  guint seq_num;
Packit 0652a1
Packit 0652a1
  /* global alpha: global alpha value of the rectangle. Each each per-pixel
Packit 0652a1
   * alpha value of image-data will be multiplied with the global alpha value
Packit 0652a1
   * during blending.
Packit 0652a1
   * Can be used for efficient fading in/out of overlay rectangles.
Packit 0652a1
   * GstElements that render OverlayCompositions and don't support global alpha
Packit 0652a1
   * should simply ignore it.*/
Packit 0652a1
  gfloat global_alpha;
Packit 0652a1
Packit 0652a1
  /* track alpha-values already applied: */
Packit 0652a1
  gfloat applied_global_alpha;
Packit 0652a1
  /* store initial per-pixel alpha values: */
Packit 0652a1
  guint8 *initial_alpha;
Packit 0652a1
Packit 0652a1
  /* FIXME: we may also need a (private) way to cache converted/scaled
Packit 0652a1
   * pixel blobs */
Packit 0652a1
  GMutex lock;
Packit 0652a1
Packit 0652a1
  GList *scaled_rectangles;
Packit 0652a1
};
Packit 0652a1
Packit 0652a1
#define GST_RECTANGLE_LOCK(rect)   g_mutex_lock(&rect->lock)
Packit 0652a1
#define GST_RECTANGLE_UNLOCK(rect) g_mutex_unlock(&rect->lock)
Packit 0652a1
Packit 0652a1
/* --------------------------- utility functions --------------------------- */
Packit 0652a1
Packit 0652a1
#ifndef GST_DISABLE_GST_DEBUG
Packit 0652a1
Packit 0652a1
#define GST_CAT_DEFAULT ensure_debug_category()
Packit 0652a1
Packit 0652a1
static GstDebugCategory *
Packit 0652a1
ensure_debug_category (void)
Packit 0652a1
{
Packit 0652a1
  static gsize cat_gonce = 0;
Packit 0652a1
Packit 0652a1
  if (g_once_init_enter (&cat_gonce)) {
Packit 0652a1
    gsize cat_done;
Packit 0652a1
Packit 0652a1
    cat_done = (gsize) _gst_debug_category_new ("video-composition", 0,
Packit 0652a1
        "video overlay composition");
Packit 0652a1
Packit 0652a1
    g_once_init_leave (&cat_gonce, cat_done);
Packit 0652a1
  }
Packit 0652a1
Packit 0652a1
  return (GstDebugCategory *) cat_gonce;
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
#else
Packit 0652a1
Packit 0652a1
#define ensure_debug_category() /* NOOP */
Packit 0652a1
Packit 0652a1
#endif /* GST_DISABLE_GST_DEBUG */
Packit 0652a1
Packit 0652a1
static guint
Packit 0652a1
gst_video_overlay_get_seqnum (void)
Packit 0652a1
{
Packit 0652a1
  static gint seqnum;           /* 0 */
Packit 0652a1
Packit 0652a1
  return (guint) g_atomic_int_add (&seqnum, 1);
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
static gboolean
Packit 0652a1
gst_video_overlay_composition_meta_init (GstMeta * meta, gpointer params,
Packit 0652a1
    GstBuffer * buf)
Packit 0652a1
{
Packit 0652a1
  GstVideoOverlayCompositionMeta *ometa;
Packit 0652a1
Packit 0652a1
  ometa = (GstVideoOverlayCompositionMeta *) meta;
Packit 0652a1
Packit 0652a1
  ometa->overlay = NULL;
Packit 0652a1
Packit 0652a1
  return TRUE;
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
static void
Packit 0652a1
gst_video_overlay_composition_meta_free (GstMeta * meta, GstBuffer * buf)
Packit 0652a1
{
Packit 0652a1
  GstVideoOverlayCompositionMeta *ometa;
Packit 0652a1
Packit 0652a1
  ometa = (GstVideoOverlayCompositionMeta *) meta;
Packit 0652a1
Packit 0652a1
  if (ometa->overlay)
Packit 0652a1
    gst_video_overlay_composition_unref (ometa->overlay);
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
static gboolean
Packit 0652a1
gst_video_overlay_composition_meta_transform (GstBuffer * dest, GstMeta * meta,
Packit 0652a1
    GstBuffer * buffer, GQuark type, gpointer data)
Packit 0652a1
{
Packit 0652a1
  GstVideoOverlayCompositionMeta *dmeta, *smeta;
Packit 0652a1
Packit 0652a1
  smeta = (GstVideoOverlayCompositionMeta *) meta;
Packit 0652a1
Packit 0652a1
  if (GST_META_TRANSFORM_IS_COPY (type)) {
Packit 0652a1
    GstMetaTransformCopy *copy = data;
Packit 0652a1
Packit 0652a1
    if (!copy->region) {
Packit 0652a1
      GST_DEBUG ("copy video overlay composition metadata");
Packit 0652a1
Packit 0652a1
      /* only copy if the complete data is copied as well */
Packit 0652a1
      dmeta =
Packit 0652a1
          (GstVideoOverlayCompositionMeta *) gst_buffer_add_meta (dest,
Packit 0652a1
          GST_VIDEO_OVERLAY_COMPOSITION_META_INFO, NULL);
Packit 0652a1
      if (!dmeta)
Packit 0652a1
        return FALSE;
Packit 0652a1
Packit 0652a1
      dmeta->overlay = gst_video_overlay_composition_ref (smeta->overlay);
Packit 0652a1
    }
Packit 0652a1
  } else {
Packit 0652a1
    /* return FALSE, if transform type is not supported */
Packit 0652a1
    return FALSE;
Packit 0652a1
  }
Packit 0652a1
  return TRUE;
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
GType
Packit 0652a1
gst_video_overlay_composition_meta_api_get_type (void)
Packit 0652a1
{
Packit 0652a1
  static volatile GType type = 0;
Packit 0652a1
  static const gchar *tags[] = { NULL };
Packit 0652a1
Packit 0652a1
  if (g_once_init_enter (&type)) {
Packit 0652a1
    GType _type =
Packit 0652a1
        gst_meta_api_type_register ("GstVideoOverlayCompositionMetaAPI", tags);
Packit 0652a1
    g_once_init_leave (&type, _type);
Packit 0652a1
  }
Packit 0652a1
  return type;
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/* video overlay composition metadata */
Packit 0652a1
const GstMetaInfo *
Packit 0652a1
gst_video_overlay_composition_meta_get_info (void)
Packit 0652a1
{
Packit 0652a1
  static const GstMetaInfo *video_overlay_composition_meta_info = NULL;
Packit 0652a1
Packit 0652a1
  if (g_once_init_enter ((GstMetaInfo **) &
Packit 0652a1
          video_overlay_composition_meta_info)) {
Packit 0652a1
    const GstMetaInfo *meta =
Packit 0652a1
        gst_meta_register (GST_VIDEO_OVERLAY_COMPOSITION_META_API_TYPE,
Packit 0652a1
        "GstVideoOverlayCompositionMeta",
Packit 0652a1
        sizeof (GstVideoOverlayCompositionMeta),
Packit 0652a1
        (GstMetaInitFunction) gst_video_overlay_composition_meta_init,
Packit 0652a1
        (GstMetaFreeFunction) gst_video_overlay_composition_meta_free,
Packit 0652a1
        (GstMetaTransformFunction)
Packit 0652a1
        gst_video_overlay_composition_meta_transform);
Packit 0652a1
    g_once_init_leave ((GstMetaInfo **) & video_overlay_composition_meta_info,
Packit 0652a1
        (GstMetaInfo *) meta);
Packit 0652a1
  }
Packit 0652a1
  return video_overlay_composition_meta_info;
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * gst_buffer_add_video_overlay_composition_meta:
Packit 0652a1
 * @buf: a #GstBuffer
Packit 0652a1
 * @comp: (allow-none): a #GstVideoOverlayComposition
Packit 0652a1
 *
Packit 0652a1
 * Sets an overlay composition on a buffer. The buffer will obtain its own
Packit 0652a1
 * reference to the composition, meaning this function does not take ownership
Packit 0652a1
 * of @comp.
Packit 0652a1
 *
Packit 0652a1
 * Returns: (transfer none): a #GstVideoOverlayCompositionMeta
Packit 0652a1
 */
Packit 0652a1
GstVideoOverlayCompositionMeta *
Packit 0652a1
gst_buffer_add_video_overlay_composition_meta (GstBuffer * buf,
Packit 0652a1
    GstVideoOverlayComposition * comp)
Packit 0652a1
{
Packit 0652a1
  GstVideoOverlayCompositionMeta *ometa;
Packit 0652a1
Packit 0652a1
  g_return_val_if_fail (gst_buffer_is_writable (buf), NULL);
Packit 0652a1
Packit 0652a1
  ometa = (GstVideoOverlayCompositionMeta *)
Packit 0652a1
      gst_buffer_add_meta (buf, GST_VIDEO_OVERLAY_COMPOSITION_META_INFO, NULL);
Packit 0652a1
Packit 0652a1
  ometa->overlay = gst_video_overlay_composition_ref (comp);
Packit 0652a1
Packit 0652a1
  return ometa;
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/* ------------------------------ composition ------------------------------ */
Packit 0652a1
Packit 0652a1
#define RECTANGLE_ARRAY_STEP 4  /* premature optimization */
Packit 0652a1
Packit 0652a1
GST_DEFINE_MINI_OBJECT_TYPE (GstVideoOverlayComposition,
Packit 0652a1
    gst_video_overlay_composition);
Packit 0652a1
Packit 0652a1
static void
Packit 0652a1
gst_video_overlay_composition_free (GstMiniObject * mini_obj)
Packit 0652a1
{
Packit 0652a1
  GstVideoOverlayComposition *comp = (GstVideoOverlayComposition *) mini_obj;
Packit 0652a1
  guint num;
Packit 0652a1
Packit 0652a1
  num = comp->num_rectangles;
Packit 0652a1
Packit 0652a1
  while (num > 0) {
Packit 0652a1
    gst_mini_object_remove_parent (GST_MINI_OBJECT_CAST (comp->rectangles[num -
Packit 0652a1
                1]), GST_MINI_OBJECT_CAST (comp));
Packit 0652a1
    gst_video_overlay_rectangle_unref (comp->rectangles[num - 1]);
Packit 0652a1
    --num;
Packit 0652a1
  }
Packit 0652a1
Packit 0652a1
  g_free (comp->rectangles);
Packit 0652a1
  comp->rectangles = NULL;
Packit 0652a1
  comp->num_rectangles = 0;
Packit 0652a1
Packit 0652a1
  g_slice_free (GstVideoOverlayComposition, comp);
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * gst_video_overlay_composition_new:
Packit 0652a1
 * @rectangle: (transfer none): a #GstVideoOverlayRectangle to add to the
Packit 0652a1
 *     composition
Packit 0652a1
 *
Packit 0652a1
 * Creates a new video overlay composition object to hold one or more
Packit 0652a1
 * overlay rectangles.
Packit 0652a1
 *
Packit 0652a1
 * Returns: (transfer full): a new #GstVideoOverlayComposition. Unref with
Packit 0652a1
 *     gst_video_overlay_composition_unref() when no longer needed.
Packit 0652a1
 */
Packit 0652a1
GstVideoOverlayComposition *
Packit 0652a1
gst_video_overlay_composition_new (GstVideoOverlayRectangle * rectangle)
Packit 0652a1
{
Packit 0652a1
  GstVideoOverlayComposition *comp;
Packit 0652a1
Packit 0652a1
Packit 0652a1
  /* FIXME: should we allow empty compositions? Could also be expressed as
Packit 0652a1
   * buffer without a composition on it. Maybe there are cases where doing
Packit 0652a1
   * an empty new + _add() in a loop is easier? */
Packit 0652a1
  g_return_val_if_fail (GST_IS_VIDEO_OVERLAY_RECTANGLE (rectangle), NULL);
Packit 0652a1
Packit 0652a1
  comp = g_slice_new0 (GstVideoOverlayComposition);
Packit 0652a1
Packit 0652a1
  gst_mini_object_init (GST_MINI_OBJECT_CAST (comp), 0,
Packit 0652a1
      GST_TYPE_VIDEO_OVERLAY_COMPOSITION,
Packit 0652a1
      (GstMiniObjectCopyFunction) gst_video_overlay_composition_copy,
Packit 0652a1
      NULL, (GstMiniObjectFreeFunction) gst_video_overlay_composition_free);
Packit 0652a1
Packit 0652a1
  comp->rectangles = g_new0 (GstVideoOverlayRectangle *, RECTANGLE_ARRAY_STEP);
Packit 0652a1
  comp->rectangles[0] = gst_video_overlay_rectangle_ref (rectangle);
Packit 0652a1
  gst_mini_object_add_parent (GST_MINI_OBJECT_CAST (rectangle),
Packit 0652a1
      GST_MINI_OBJECT_CAST (comp));
Packit 0652a1
  comp->num_rectangles = 1;
Packit 0652a1
Packit 0652a1
  comp->seq_num = gst_video_overlay_get_seqnum ();
Packit 0652a1
Packit 0652a1
  /* since the rectangle was created earlier, its seqnum is smaller than ours */
Packit 0652a1
  comp->min_seq_num_used = rectangle->seq_num;
Packit 0652a1
Packit 0652a1
  GST_LOG ("new composition %p: seq_num %u with rectangle %p", comp,
Packit 0652a1
      comp->seq_num, rectangle);
Packit 0652a1
Packit 0652a1
  return comp;
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * gst_video_overlay_composition_add_rectangle:
Packit 0652a1
 * @comp: a #GstVideoOverlayComposition
Packit 0652a1
 * @rectangle: (transfer none): a #GstVideoOverlayRectangle to add to the
Packit 0652a1
 *     composition
Packit 0652a1
 *
Packit 0652a1
 * Adds an overlay rectangle to an existing overlay composition object. This
Packit 0652a1
 * must be done right after creating the overlay composition.
Packit 0652a1
 */
Packit 0652a1
void
Packit 0652a1
gst_video_overlay_composition_add_rectangle (GstVideoOverlayComposition * comp,
Packit 0652a1
    GstVideoOverlayRectangle * rectangle)
Packit 0652a1
{
Packit 0652a1
  g_return_if_fail (GST_IS_VIDEO_OVERLAY_COMPOSITION (comp));
Packit 0652a1
  g_return_if_fail (GST_IS_VIDEO_OVERLAY_RECTANGLE (rectangle));
Packit 0652a1
  g_return_if_fail (gst_mini_object_is_writable (GST_MINI_OBJECT_CAST (comp)));
Packit 0652a1
Packit 0652a1
  if (comp->num_rectangles % RECTANGLE_ARRAY_STEP == 0) {
Packit 0652a1
    comp->rectangles =
Packit 0652a1
        g_renew (GstVideoOverlayRectangle *, comp->rectangles,
Packit 0652a1
        comp->num_rectangles + RECTANGLE_ARRAY_STEP);
Packit 0652a1
  }
Packit 0652a1
Packit 0652a1
  comp->rectangles[comp->num_rectangles] =
Packit 0652a1
      gst_video_overlay_rectangle_ref (rectangle);
Packit 0652a1
  gst_mini_object_add_parent (GST_MINI_OBJECT_CAST (rectangle),
Packit 0652a1
      GST_MINI_OBJECT_CAST (comp));
Packit 0652a1
  comp->num_rectangles += 1;
Packit 0652a1
Packit 0652a1
  comp->min_seq_num_used = MIN (comp->min_seq_num_used, rectangle->seq_num);
Packit 0652a1
Packit 0652a1
  GST_LOG ("composition %p: added rectangle %p", comp, rectangle);
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * gst_video_overlay_composition_n_rectangles:
Packit 0652a1
 * @comp: a #GstVideoOverlayComposition
Packit 0652a1
 *
Packit 0652a1
 * Returns the number of #GstVideoOverlayRectangles contained in @comp.
Packit 0652a1
 *
Packit 0652a1
 * Returns: the number of rectangles
Packit 0652a1
 */
Packit 0652a1
guint
Packit 0652a1
gst_video_overlay_composition_n_rectangles (GstVideoOverlayComposition * comp)
Packit 0652a1
{
Packit 0652a1
  g_return_val_if_fail (GST_IS_VIDEO_OVERLAY_COMPOSITION (comp), 0);
Packit 0652a1
Packit 0652a1
  return comp->num_rectangles;
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * gst_video_overlay_composition_get_rectangle:
Packit 0652a1
 * @comp: a #GstVideoOverlayComposition
Packit 0652a1
 * @n: number of the rectangle to get
Packit 0652a1
 *
Packit 0652a1
 * Returns the @n-th #GstVideoOverlayRectangle contained in @comp.
Packit 0652a1
 *
Packit 0652a1
 * Returns: (transfer none): the @n-th rectangle, or NULL if @n is out of
Packit 0652a1
 *     bounds. Will not return a new reference, the caller will need to
Packit 0652a1
 *     obtain her own reference using gst_video_overlay_rectangle_ref()
Packit 0652a1
 *     if needed.
Packit 0652a1
 */
Packit 0652a1
GstVideoOverlayRectangle *
Packit 0652a1
gst_video_overlay_composition_get_rectangle (GstVideoOverlayComposition * comp,
Packit 0652a1
    guint n)
Packit 0652a1
{
Packit 0652a1
  g_return_val_if_fail (GST_IS_VIDEO_OVERLAY_COMPOSITION (comp), NULL);
Packit 0652a1
Packit 0652a1
  if (n >= comp->num_rectangles)
Packit 0652a1
    return NULL;
Packit 0652a1
Packit 0652a1
  return comp->rectangles[n];
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
static gboolean
Packit 0652a1
gst_video_overlay_rectangle_needs_scaling (GstVideoOverlayRectangle * r)
Packit 0652a1
{
Packit 0652a1
  return (GST_VIDEO_INFO_WIDTH (&r->info) != r->render_width ||
Packit 0652a1
      GST_VIDEO_INFO_HEIGHT (&r->info) != r->render_height);
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * gst_video_overlay_composition_blend:
Packit 0652a1
 * @comp: a #GstVideoOverlayComposition
Packit 0652a1
 * @video_buf: a #GstVideoFrame containing raw video data in a
Packit 0652a1
 *             supported format. It should be mapped using GST_MAP_READWRITE
Packit 0652a1
 *
Packit 0652a1
 * Blends the overlay rectangles in @comp on top of the raw video data
Packit 0652a1
 * contained in @video_buf. The data in @video_buf must be writable and
Packit 0652a1
 * mapped appropriately.
Packit 0652a1
 *
Packit 0652a1
 * Since @video_buf data is read and will be modified, it ought be
Packit 0652a1
 * mapped with flag GST_MAP_READWRITE.
Packit 0652a1
 */
Packit 0652a1
/* FIXME: formats with more than 8 bit per component which get unpacked into
Packit 0652a1
 * ARGB64 or AYUV64 (such as v210, v216, UYVP, GRAY16_LE and GRAY16_BE)
Packit 0652a1
 * are not supported yet by the code in video-blend.c.
Packit 0652a1
 */
Packit 0652a1
gboolean
Packit 0652a1
gst_video_overlay_composition_blend (GstVideoOverlayComposition * comp,
Packit 0652a1
    GstVideoFrame * video_buf)
Packit 0652a1
{
Packit 0652a1
  GstVideoInfo scaled_info;
Packit 0652a1
  GstVideoInfo *vinfo;
Packit 0652a1
  GstVideoFrame rectangle_frame;
Packit 0652a1
  GstVideoFormat fmt;
Packit 0652a1
  GstBuffer *pixels = NULL;
Packit 0652a1
  gboolean ret = TRUE;
Packit 0652a1
  guint n, num;
Packit 0652a1
  int w, h;
Packit 0652a1
Packit 0652a1
  g_return_val_if_fail (GST_IS_VIDEO_OVERLAY_COMPOSITION (comp), FALSE);
Packit 0652a1
  g_return_val_if_fail (video_buf != NULL, FALSE);
Packit 0652a1
Packit 0652a1
  w = GST_VIDEO_FRAME_WIDTH (video_buf);
Packit 0652a1
  h = GST_VIDEO_FRAME_HEIGHT (video_buf);
Packit 0652a1
  fmt = GST_VIDEO_FRAME_FORMAT (video_buf);
Packit 0652a1
Packit 0652a1
  num = comp->num_rectangles;
Packit 0652a1
  GST_LOG ("Blending composition %p with %u rectangles onto video buffer %p "
Packit 0652a1
      "(%ux%u, format %u)", comp, num, video_buf, w, h, fmt);
Packit 0652a1
Packit 0652a1
  for (n = 0; n < num; ++n) {
Packit 0652a1
    GstVideoOverlayRectangle *rect;
Packit 0652a1
    gboolean needs_scaling;
Packit 0652a1
Packit 0652a1
    rect = comp->rectangles[n];
Packit 0652a1
Packit 0652a1
    GST_LOG (" rectangle %u %p: %ux%u, format %u", n, rect,
Packit 0652a1
        GST_VIDEO_INFO_WIDTH (&rect->info), GST_VIDEO_INFO_HEIGHT (&rect->info),
Packit 0652a1
        GST_VIDEO_INFO_FORMAT (&rect->info));
Packit 0652a1
Packit 0652a1
    needs_scaling = gst_video_overlay_rectangle_needs_scaling (rect);
Packit 0652a1
    if (needs_scaling) {
Packit 0652a1
      gst_video_blend_scale_linear_RGBA (&rect->info, rect->pixels,
Packit 0652a1
          rect->render_height, rect->render_width, &scaled_info, &pixels);
Packit 0652a1
      vinfo = &scaled_info;
Packit 0652a1
    } else {
Packit 0652a1
      pixels = gst_buffer_ref (rect->pixels);
Packit 0652a1
      vinfo = &rect->info;
Packit 0652a1
    }
Packit 0652a1
Packit 0652a1
    gst_video_frame_map (&rectangle_frame, vinfo, pixels, GST_MAP_READ);
Packit 0652a1
Packit 0652a1
    ret = gst_video_blend (video_buf, &rectangle_frame, rect->x, rect->y,
Packit 0652a1
        rect->global_alpha);
Packit 0652a1
    gst_video_frame_unmap (&rectangle_frame);
Packit 0652a1
    if (!ret) {
Packit 0652a1
      GST_WARNING ("Could not blend overlay rectangle onto video buffer");
Packit 0652a1
    }
Packit 0652a1
Packit 0652a1
    /* FIXME: should cache scaled pixels in the rectangle struct */
Packit 0652a1
    gst_buffer_unref (pixels);
Packit 0652a1
  }
Packit 0652a1
Packit 0652a1
  return ret;
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * gst_video_overlay_composition_copy:
Packit 0652a1
 * @comp: (transfer none): a #GstVideoOverlayComposition to copy
Packit 0652a1
 *
Packit 0652a1
 * Makes a copy of @comp and all contained rectangles, so that it is possible
Packit 0652a1
 * to modify the composition and contained rectangles (e.g. add additional
Packit 0652a1
 * rectangles or change the render co-ordinates or render dimension). The
Packit 0652a1
 * actual overlay pixel data buffers contained in the rectangles are not
Packit 0652a1
 * copied.
Packit 0652a1
 *
Packit 0652a1
 * Returns: (transfer full): a new #GstVideoOverlayComposition equivalent
Packit 0652a1
 *     to @comp.
Packit 0652a1
 */
Packit 0652a1
GstVideoOverlayComposition *
Packit 0652a1
gst_video_overlay_composition_copy (GstVideoOverlayComposition * comp)
Packit 0652a1
{
Packit 0652a1
  GstVideoOverlayComposition *copy;
Packit 0652a1
  GstVideoOverlayRectangle *rect;
Packit 0652a1
  guint n;
Packit 0652a1
Packit 0652a1
  g_return_val_if_fail (GST_IS_VIDEO_OVERLAY_COMPOSITION (comp), NULL);
Packit 0652a1
Packit 0652a1
  if (G_LIKELY (comp->num_rectangles == 0))
Packit 0652a1
    return gst_video_overlay_composition_new (NULL);
Packit 0652a1
Packit 0652a1
  rect = gst_video_overlay_rectangle_copy (comp->rectangles[0]);
Packit 0652a1
  copy = gst_video_overlay_composition_new (rect);
Packit 0652a1
  gst_video_overlay_rectangle_unref (rect);
Packit 0652a1
Packit 0652a1
  for (n = 1; n < comp->num_rectangles; ++n) {
Packit 0652a1
    rect = gst_video_overlay_rectangle_copy (comp->rectangles[n]);
Packit 0652a1
    gst_video_overlay_composition_add_rectangle (copy, rect);
Packit 0652a1
    gst_video_overlay_rectangle_unref (rect);
Packit 0652a1
  }
Packit 0652a1
Packit 0652a1
  return copy;
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * gst_video_overlay_composition_make_writable:
Packit 0652a1
 * @comp: (transfer full): a #GstVideoOverlayComposition to copy
Packit 0652a1
 *
Packit 0652a1
 * Takes ownership of @comp and returns a version of @comp that is writable
Packit 0652a1
 * (i.e. can be modified). Will either return @comp right away, or create a
Packit 0652a1
 * new writable copy of @comp and unref @comp itself. All the contained
Packit 0652a1
 * rectangles will also be copied, but the actual overlay pixel data buffers
Packit 0652a1
 * contained in the rectangles are not copied.
Packit 0652a1
 *
Packit 0652a1
 * Returns: (transfer full): a writable #GstVideoOverlayComposition
Packit 0652a1
 *     equivalent to @comp.
Packit 0652a1
 */
Packit 0652a1
GstVideoOverlayComposition *
Packit 0652a1
gst_video_overlay_composition_make_writable (GstVideoOverlayComposition * comp)
Packit 0652a1
{
Packit 0652a1
  GstVideoOverlayComposition *writable_comp;
Packit 0652a1
Packit 0652a1
  g_return_val_if_fail (GST_IS_VIDEO_OVERLAY_COMPOSITION (comp), NULL);
Packit 0652a1
Packit 0652a1
  if (gst_mini_object_is_writable (GST_MINI_OBJECT_CAST (comp))) {
Packit 0652a1
    guint n;
Packit 0652a1
Packit 0652a1
    for (n = 0; n < comp->num_rectangles; ++n) {
Packit 0652a1
      if (!gst_mini_object_is_writable (GST_MINI_OBJECT_CAST (comp->rectangles
Packit 0652a1
                  [n])))
Packit 0652a1
        goto copy;
Packit 0652a1
    }
Packit 0652a1
    return comp;
Packit 0652a1
  }
Packit 0652a1
Packit 0652a1
copy:
Packit 0652a1
Packit 0652a1
  writable_comp = gst_video_overlay_composition_copy (comp);
Packit 0652a1
  gst_video_overlay_composition_unref (comp);
Packit 0652a1
Packit 0652a1
  return writable_comp;
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * gst_video_overlay_composition_get_seqnum:
Packit 0652a1
 * @comp: a #GstVideoOverlayComposition
Packit 0652a1
 *
Packit 0652a1
 * Returns the sequence number of this composition. Sequence numbers are
Packit 0652a1
 * monotonically increasing and unique for overlay compositions and rectangles
Packit 0652a1
 * (meaning there will never be a rectangle with the same sequence number as
Packit 0652a1
 * a composition).
Packit 0652a1
 *
Packit 0652a1
 * Returns: the sequence number of @comp
Packit 0652a1
 */
Packit 0652a1
guint
Packit 0652a1
gst_video_overlay_composition_get_seqnum (GstVideoOverlayComposition * comp)
Packit 0652a1
{
Packit 0652a1
  g_return_val_if_fail (GST_IS_VIDEO_OVERLAY_COMPOSITION (comp), 0);
Packit 0652a1
Packit 0652a1
  return comp->seq_num;
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/* ------------------------------ rectangles ------------------------------ -*/
Packit 0652a1
Packit 0652a1
GST_DEFINE_MINI_OBJECT_TYPE (GstVideoOverlayRectangle,
Packit 0652a1
    gst_video_overlay_rectangle);
Packit 0652a1
Packit 0652a1
static void
Packit 0652a1
gst_video_overlay_rectangle_free (GstMiniObject * mini_obj)
Packit 0652a1
{
Packit 0652a1
  GstVideoOverlayRectangle *rect = (GstVideoOverlayRectangle *) mini_obj;
Packit 0652a1
Packit 0652a1
  gst_mini_object_remove_parent (GST_MINI_OBJECT_CAST (rect->pixels),
Packit 0652a1
      GST_MINI_OBJECT_CAST (rect));
Packit 0652a1
  gst_buffer_replace (&rect->pixels, NULL);
Packit 0652a1
Packit 0652a1
  while (rect->scaled_rectangles != NULL) {
Packit 0652a1
    GstVideoOverlayRectangle *scaled_rect = rect->scaled_rectangles->data;
Packit 0652a1
Packit 0652a1
    gst_video_overlay_rectangle_unref (scaled_rect);
Packit 0652a1
Packit 0652a1
    rect->scaled_rectangles =
Packit 0652a1
        g_list_delete_link (rect->scaled_rectangles, rect->scaled_rectangles);
Packit 0652a1
  }
Packit 0652a1
Packit 0652a1
  g_free (rect->initial_alpha);
Packit 0652a1
  g_mutex_clear (&rect->lock);
Packit 0652a1
Packit 0652a1
  g_slice_free (GstVideoOverlayRectangle, rect);
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
static inline gboolean
Packit 0652a1
gst_video_overlay_rectangle_check_flags (GstVideoOverlayFormatFlags flags)
Packit 0652a1
{
Packit 0652a1
  /* Check flags only contains flags we know about */
Packit 0652a1
  return (flags & ~(GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA |
Packit 0652a1
          GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA)) == 0;
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
static gboolean
Packit 0652a1
gst_video_overlay_rectangle_is_same_alpha_type (GstVideoOverlayFormatFlags
Packit 0652a1
    flags1, GstVideoOverlayFormatFlags flags2)
Packit 0652a1
{
Packit 0652a1
  return ((flags1 ^ flags2) & GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA)
Packit 0652a1
      == 0;
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * gst_video_overlay_rectangle_new_raw:
Packit 0652a1
 * @pixels: (transfer none): a #GstBuffer pointing to the pixel memory
Packit 0652a1
 * @render_x: the X co-ordinate on the video where the top-left corner of this
Packit 0652a1
 *     overlay rectangle should be rendered to
Packit 0652a1
 * @render_y: the Y co-ordinate on the video where the top-left corner of this
Packit 0652a1
 *     overlay rectangle should be rendered to
Packit 0652a1
 * @render_width: the render width of this rectangle on the video
Packit 0652a1
 * @render_height: the render height of this rectangle on the video
Packit 0652a1
 * @flags: flags
Packit 0652a1
 *
Packit 0652a1
 * Creates a new video overlay rectangle with ARGB or AYUV pixel data.
Packit 0652a1
 * The layout in case of ARGB of the components in memory is B-G-R-A
Packit 0652a1
 * on little-endian platforms
Packit 0652a1
 * (corresponding to #GST_VIDEO_FORMAT_BGRA) and A-R-G-B on big-endian
Packit 0652a1
 * platforms (corresponding to #GST_VIDEO_FORMAT_ARGB). In other words,
Packit 0652a1
 * pixels are treated as 32-bit words and the lowest 8 bits then contain
Packit 0652a1
 * the blue component value and the highest 8 bits contain the alpha
Packit 0652a1
 * component value. Unless specified in the flags, the RGB values are
Packit 0652a1
 * non-premultiplied. This is the format that is used by most hardware,
Packit 0652a1
 * and also many rendering libraries such as Cairo, for example.
Packit 0652a1
 * The pixel data buffer must have #GstVideoMeta set.
Packit 0652a1
 *
Packit 0652a1
 * Returns: (transfer full): a new #GstVideoOverlayRectangle. Unref with
Packit 0652a1
 *     gst_video_overlay_rectangle_unref() when no longer needed.
Packit 0652a1
 */
Packit 0652a1
GstVideoOverlayRectangle *
Packit 0652a1
gst_video_overlay_rectangle_new_raw (GstBuffer * pixels,
Packit 0652a1
    gint render_x, gint render_y, guint render_width, guint render_height,
Packit 0652a1
    GstVideoOverlayFormatFlags flags)
Packit 0652a1
{
Packit 0652a1
  GstVideoOverlayRectangle *rect;
Packit 0652a1
  GstVideoMeta *vmeta;
Packit 0652a1
  GstVideoFormat format;
Packit 0652a1
  guint width, height;
Packit 0652a1
Packit 0652a1
  g_return_val_if_fail (GST_IS_BUFFER (pixels), NULL);
Packit 0652a1
  g_return_val_if_fail (render_height > 0 && render_width > 0, NULL);
Packit 0652a1
  g_return_val_if_fail (gst_video_overlay_rectangle_check_flags (flags), NULL);
Packit 0652a1
Packit 0652a1
  /* buffer must have video meta with some expected settings */
Packit 0652a1
  vmeta = gst_buffer_get_video_meta (pixels);
Packit 0652a1
  g_return_val_if_fail (vmeta, NULL);
Packit 0652a1
  g_return_val_if_fail (vmeta->format ==
Packit 0652a1
      GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB ||
Packit 0652a1
      vmeta->format == GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_YUV, NULL);
Packit 0652a1
  g_return_val_if_fail (vmeta->flags == GST_VIDEO_FRAME_FLAG_NONE, NULL);
Packit 0652a1
Packit 0652a1
  format = vmeta->format;
Packit 0652a1
  width = vmeta->width;
Packit 0652a1
  height = vmeta->height;
Packit 0652a1
Packit 0652a1
  /* technically ((height-1)*stride)+width might be okay too */
Packit 0652a1
  g_return_val_if_fail (gst_buffer_get_size (pixels) >= height * width * 4,
Packit 0652a1
      NULL);
Packit 0652a1
  g_return_val_if_fail (height > 0 && width > 0, NULL);
Packit 0652a1
Packit 0652a1
  rect = g_slice_new0 (GstVideoOverlayRectangle);
Packit 0652a1
Packit 0652a1
  gst_mini_object_init (GST_MINI_OBJECT_CAST (rect), 0,
Packit 0652a1
      GST_TYPE_VIDEO_OVERLAY_RECTANGLE,
Packit 0652a1
      (GstMiniObjectCopyFunction) gst_video_overlay_rectangle_copy,
Packit 0652a1
      NULL, (GstMiniObjectFreeFunction) gst_video_overlay_rectangle_free);
Packit 0652a1
Packit 0652a1
  g_mutex_init (&rect->lock);
Packit 0652a1
Packit 0652a1
  rect->pixels = gst_buffer_ref (pixels);
Packit 0652a1
  gst_mini_object_add_parent (GST_MINI_OBJECT_CAST (pixels),
Packit 0652a1
      GST_MINI_OBJECT_CAST (rect));
Packit 0652a1
  rect->scaled_rectangles = NULL;
Packit 0652a1
Packit 0652a1
  gst_video_info_init (&rect->info);
Packit 0652a1
  if (!gst_video_info_set_format (&rect->info, format, width, height)) {
Packit 0652a1
    gst_mini_object_unref (GST_MINI_OBJECT_CAST (rect));
Packit 0652a1
    return NULL;
Packit 0652a1
  }
Packit 0652a1
  if (flags & GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA)
Packit 0652a1
    rect->info.flags |= GST_VIDEO_FLAG_PREMULTIPLIED_ALPHA;
Packit 0652a1
Packit 0652a1
  rect->x = render_x;
Packit 0652a1
  rect->y = render_y;
Packit 0652a1
  rect->render_width = render_width;
Packit 0652a1
  rect->render_height = render_height;
Packit 0652a1
Packit 0652a1
  rect->global_alpha = 1.0;
Packit 0652a1
  rect->applied_global_alpha = 1.0;
Packit 0652a1
  rect->initial_alpha = NULL;
Packit 0652a1
Packit 0652a1
  rect->flags = flags;
Packit 0652a1
Packit 0652a1
  rect->seq_num = gst_video_overlay_get_seqnum ();
Packit 0652a1
Packit 0652a1
  GST_LOG ("new rectangle %p: %ux%u => %ux%u @ %u,%u, seq_num %u, format %u, "
Packit 0652a1
      "flags %x, pixels %p, global_alpha=%f", rect, width, height, render_width,
Packit 0652a1
      render_height, render_x, render_y, rect->seq_num, format,
Packit 0652a1
      rect->flags, pixels, rect->global_alpha);
Packit 0652a1
Packit 0652a1
  return rect;
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * gst_video_overlay_rectangle_get_render_rectangle:
Packit 0652a1
 * @rectangle: a #GstVideoOverlayRectangle
Packit 0652a1
 * @render_x: (out) (allow-none): address where to store the X render offset
Packit 0652a1
 * @render_y: (out) (allow-none): address where to store the Y render offset
Packit 0652a1
 * @render_width: (out) (allow-none): address where to store the render width
Packit 0652a1
 * @render_height: (out) (allow-none): address where to store the render height
Packit 0652a1
 *
Packit 0652a1
 * Retrieves the render position and render dimension of the overlay
Packit 0652a1
 * rectangle on the video.
Packit 0652a1
 *
Packit 0652a1
 * Returns: TRUE if valid render dimensions were retrieved.
Packit 0652a1
 */
Packit 0652a1
gboolean
Packit 0652a1
gst_video_overlay_rectangle_get_render_rectangle (GstVideoOverlayRectangle *
Packit 0652a1
    rectangle, gint * render_x, gint * render_y, guint * render_width,
Packit 0652a1
    guint * render_height)
Packit 0652a1
{
Packit 0652a1
  g_return_val_if_fail (GST_IS_VIDEO_OVERLAY_RECTANGLE (rectangle), FALSE);
Packit 0652a1
Packit 0652a1
  if (render_x)
Packit 0652a1
    *render_x = rectangle->x;
Packit 0652a1
  if (render_y)
Packit 0652a1
    *render_y = rectangle->y;
Packit 0652a1
  if (render_width)
Packit 0652a1
    *render_width = rectangle->render_width;
Packit 0652a1
  if (render_height)
Packit 0652a1
    *render_height = rectangle->render_height;
Packit 0652a1
Packit 0652a1
  return TRUE;
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * gst_video_overlay_rectangle_set_render_rectangle:
Packit 0652a1
 * @rectangle: a #GstVideoOverlayRectangle
Packit 0652a1
 * @render_x: render X position of rectangle on video
Packit 0652a1
 * @render_y: render Y position of rectangle on video
Packit 0652a1
 * @render_width: render width of rectangle
Packit 0652a1
 * @render_height: render height of rectangle
Packit 0652a1
 *
Packit 0652a1
 * Sets the render position and dimensions of the rectangle on the video.
Packit 0652a1
 * This function is mainly for elements that modify the size of the video
Packit 0652a1
 * in some way (e.g. through scaling or cropping) and need to adjust the
Packit 0652a1
 * details of any overlays to match the operation that changed the size.
Packit 0652a1
 *
Packit 0652a1
 * @rectangle must be writable, meaning its refcount must be 1. You can
Packit 0652a1
 * make the rectangles inside a #GstVideoOverlayComposition writable using
Packit 0652a1
 * gst_video_overlay_composition_make_writable() or
Packit 0652a1
 * gst_video_overlay_composition_copy().
Packit 0652a1
 */
Packit 0652a1
void
Packit 0652a1
gst_video_overlay_rectangle_set_render_rectangle (GstVideoOverlayRectangle *
Packit 0652a1
    rectangle, gint render_x, gint render_y, guint render_width,
Packit 0652a1
    guint render_height)
Packit 0652a1
{
Packit 0652a1
  g_return_if_fail (GST_IS_VIDEO_OVERLAY_RECTANGLE (rectangle));
Packit 0652a1
  g_return_if_fail (gst_mini_object_is_writable (GST_MINI_OBJECT_CAST
Packit 0652a1
          (rectangle)));
Packit 0652a1
Packit 0652a1
  rectangle->x = render_x;
Packit 0652a1
  rectangle->y = render_y;
Packit 0652a1
  rectangle->render_width = render_width;
Packit 0652a1
  rectangle->render_height = render_height;
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/* FIXME: orc-ify */
Packit 0652a1
static void
Packit 0652a1
gst_video_overlay_rectangle_premultiply_0 (GstVideoFrame * frame)
Packit 0652a1
{
Packit 0652a1
  int i, j;
Packit 0652a1
  int width = GST_VIDEO_FRAME_WIDTH (frame);
Packit 0652a1
  int height = GST_VIDEO_FRAME_HEIGHT (frame);
Packit 0652a1
  int stride = GST_VIDEO_FRAME_PLANE_STRIDE (frame, 0);
Packit 0652a1
  guint8 *data = GST_VIDEO_FRAME_PLANE_DATA (frame, 0);
Packit 0652a1
Packit 0652a1
  for (j = 0; j < height; ++j) {
Packit 0652a1
    guint8 *line;
Packit 0652a1
Packit 0652a1
    line = data;
Packit 0652a1
    line += stride * j;
Packit 0652a1
    for (i = 0; i < width; ++i) {
Packit 0652a1
      int a = line[0];
Packit 0652a1
      line[1] = line[1] * a / 255;
Packit 0652a1
      line[2] = line[2] * a / 255;
Packit 0652a1
      line[3] = line[3] * a / 255;
Packit 0652a1
      line += 4;
Packit 0652a1
    }
Packit 0652a1
  }
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
static void
Packit 0652a1
gst_video_overlay_rectangle_premultiply_3 (GstVideoFrame * frame)
Packit 0652a1
{
Packit 0652a1
  int i, j;
Packit 0652a1
  int width = GST_VIDEO_FRAME_WIDTH (frame);
Packit 0652a1
  int height = GST_VIDEO_FRAME_HEIGHT (frame);
Packit 0652a1
  int stride = GST_VIDEO_FRAME_PLANE_STRIDE (frame, 0);
Packit 0652a1
  guint8 *data = GST_VIDEO_FRAME_PLANE_DATA (frame, 0);
Packit 0652a1
Packit 0652a1
  for (j = 0; j < height; ++j) {
Packit 0652a1
    guint8 *line;
Packit 0652a1
Packit 0652a1
    line = data;
Packit 0652a1
    line += stride * j;
Packit 0652a1
    for (i = 0; i < width; ++i) {
Packit 0652a1
      int a = line[3];
Packit 0652a1
      line[0] = line[0] * a / 255;
Packit 0652a1
      line[1] = line[1] * a / 255;
Packit 0652a1
      line[2] = line[2] * a / 255;
Packit 0652a1
      line += 4;
Packit 0652a1
    }
Packit 0652a1
  }
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
static void
Packit 0652a1
gst_video_overlay_rectangle_premultiply (GstVideoFrame * frame)
Packit 0652a1
{
Packit 0652a1
  gint alpha_offset;
Packit 0652a1
Packit 0652a1
  alpha_offset = GST_VIDEO_FRAME_COMP_POFFSET (frame, 3);
Packit 0652a1
  switch (alpha_offset) {
Packit 0652a1
    case 0:
Packit 0652a1
      gst_video_overlay_rectangle_premultiply_0 (frame);
Packit 0652a1
      break;
Packit 0652a1
    case 3:
Packit 0652a1
      gst_video_overlay_rectangle_premultiply_3 (frame);
Packit 0652a1
      break;
Packit 0652a1
    default:
Packit 0652a1
      g_assert_not_reached ();
Packit 0652a1
      break;
Packit 0652a1
  }
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/* FIXME: orc-ify */
Packit 0652a1
static void
Packit 0652a1
gst_video_overlay_rectangle_unpremultiply_0 (GstVideoFrame * frame)
Packit 0652a1
{
Packit 0652a1
  int i, j;
Packit 0652a1
  int width = GST_VIDEO_FRAME_WIDTH (frame);
Packit 0652a1
  int height = GST_VIDEO_FRAME_HEIGHT (frame);
Packit 0652a1
  int stride = GST_VIDEO_FRAME_PLANE_STRIDE (frame, 0);
Packit 0652a1
  guint8 *data = GST_VIDEO_FRAME_PLANE_DATA (frame, 0);
Packit 0652a1
Packit 0652a1
  for (j = 0; j < height; ++j) {
Packit 0652a1
    guint8 *line;
Packit 0652a1
Packit 0652a1
    line = data;
Packit 0652a1
    line += stride * j;
Packit 0652a1
    for (i = 0; i < width; ++i) {
Packit 0652a1
      int a = line[0];
Packit 0652a1
      if (a) {
Packit 0652a1
        line[1] = MIN ((line[1] * 255 + a / 2) / a, 255);
Packit 0652a1
        line[2] = MIN ((line[2] * 255 + a / 2) / a, 255);
Packit 0652a1
        line[3] = MIN ((line[3] * 255 + a / 2) / a, 255);
Packit 0652a1
      }
Packit 0652a1
      line += 4;
Packit 0652a1
    }
Packit 0652a1
  }
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
static void
Packit 0652a1
gst_video_overlay_rectangle_unpremultiply_3 (GstVideoFrame * frame)
Packit 0652a1
{
Packit 0652a1
  int i, j;
Packit 0652a1
  int width = GST_VIDEO_FRAME_WIDTH (frame);
Packit 0652a1
  int height = GST_VIDEO_FRAME_HEIGHT (frame);
Packit 0652a1
  int stride = GST_VIDEO_FRAME_PLANE_STRIDE (frame, 0);
Packit 0652a1
  guint8 *data = GST_VIDEO_FRAME_PLANE_DATA (frame, 0);
Packit 0652a1
Packit 0652a1
  for (j = 0; j < height; ++j) {
Packit 0652a1
    guint8 *line;
Packit 0652a1
Packit 0652a1
    line = data;
Packit 0652a1
    line += stride * j;
Packit 0652a1
    for (i = 0; i < width; ++i) {
Packit 0652a1
      int a = line[3];
Packit 0652a1
      if (a) {
Packit 0652a1
        line[0] = MIN ((line[0] * 255 + a / 2) / a, 255);
Packit 0652a1
        line[1] = MIN ((line[1] * 255 + a / 2) / a, 255);
Packit 0652a1
        line[2] = MIN ((line[2] * 255 + a / 2) / a, 255);
Packit 0652a1
      }
Packit 0652a1
      line += 4;
Packit 0652a1
    }
Packit 0652a1
  }
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
static void
Packit 0652a1
gst_video_overlay_rectangle_unpremultiply (GstVideoFrame * frame)
Packit 0652a1
{
Packit 0652a1
  gint alpha_offset;
Packit 0652a1
Packit 0652a1
  alpha_offset = GST_VIDEO_FRAME_COMP_POFFSET (frame, 3);
Packit 0652a1
  switch (alpha_offset) {
Packit 0652a1
    case 0:
Packit 0652a1
      gst_video_overlay_rectangle_unpremultiply_0 (frame);
Packit 0652a1
      break;
Packit 0652a1
    case 3:
Packit 0652a1
      gst_video_overlay_rectangle_unpremultiply_3 (frame);
Packit 0652a1
      break;
Packit 0652a1
    default:
Packit 0652a1
      g_assert_not_reached ();
Packit 0652a1
      break;
Packit 0652a1
  }
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
Packit 0652a1
static void
Packit 0652a1
gst_video_overlay_rectangle_extract_alpha (GstVideoOverlayRectangle * rect)
Packit 0652a1
{
Packit 0652a1
  guint8 *src, *dst;
Packit 0652a1
  GstVideoFrame frame;
Packit 0652a1
  gint i, j, w, h, stride, alpha_offset;
Packit 0652a1
Packit 0652a1
  alpha_offset = GST_VIDEO_INFO_COMP_POFFSET (&rect->info, 3);
Packit 0652a1
  g_return_if_fail (alpha_offset == 0 || alpha_offset == 3);
Packit 0652a1
Packit 0652a1
  gst_video_frame_map (&frame, &rect->info, rect->pixels, GST_MAP_READ);
Packit 0652a1
  src = GST_VIDEO_FRAME_PLANE_DATA (&frame, 0);
Packit 0652a1
  w = GST_VIDEO_INFO_WIDTH (&rect->info);
Packit 0652a1
  h = GST_VIDEO_INFO_HEIGHT (&rect->info);
Packit 0652a1
  stride = GST_VIDEO_INFO_PLANE_STRIDE (&rect->info, 0);
Packit 0652a1
Packit 0652a1
  g_free (rect->initial_alpha);
Packit 0652a1
  rect->initial_alpha = g_malloc (w * h);
Packit 0652a1
  dst = rect->initial_alpha;
Packit 0652a1
Packit 0652a1
  for (i = 0; i < h; i++) {
Packit 0652a1
    for (j = 0; j < w; j++) {
Packit 0652a1
      *dst = src[alpha_offset];
Packit 0652a1
      dst++;
Packit 0652a1
      src += 4;
Packit 0652a1
    }
Packit 0652a1
    src += stride - 4 * w;
Packit 0652a1
  }
Packit 0652a1
  gst_video_frame_unmap (&frame);
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
Packit 0652a1
static void
Packit 0652a1
gst_video_overlay_rectangle_apply_global_alpha (GstVideoOverlayRectangle * rect,
Packit 0652a1
    float global_alpha)
Packit 0652a1
{
Packit 0652a1
  guint8 *src, *dst;
Packit 0652a1
  GstVideoFrame frame;
Packit 0652a1
  gint i, j, w, h, stride;
Packit 0652a1
  gint argb_a, argb_r, argb_g, argb_b;
Packit 0652a1
  gint alpha_offset;
Packit 0652a1
Packit 0652a1
  g_assert (!(rect->applied_global_alpha != 1.0
Packit 0652a1
          && rect->initial_alpha == NULL));
Packit 0652a1
Packit 0652a1
  alpha_offset = GST_VIDEO_INFO_COMP_POFFSET (&rect->info, 3);
Packit 0652a1
  g_return_if_fail (alpha_offset == 0 || alpha_offset == 3);
Packit 0652a1
Packit 0652a1
  if (global_alpha == rect->applied_global_alpha)
Packit 0652a1
    return;
Packit 0652a1
Packit 0652a1
  if (rect->initial_alpha == NULL)
Packit 0652a1
    gst_video_overlay_rectangle_extract_alpha (rect);
Packit 0652a1
Packit 0652a1
  src = rect->initial_alpha;
Packit 0652a1
  if (!gst_buffer_is_writable (rect->pixels)) {
Packit 0652a1
    gst_mini_object_remove_parent (GST_MINI_OBJECT_CAST (rect->pixels),
Packit 0652a1
        GST_MINI_OBJECT_CAST (rect));
Packit 0652a1
    rect->pixels = gst_buffer_copy (rect->pixels);
Packit 0652a1
    gst_mini_object_add_parent (GST_MINI_OBJECT_CAST (rect->pixels),
Packit 0652a1
        GST_MINI_OBJECT_CAST (rect));
Packit 0652a1
  }
Packit 0652a1
Packit 0652a1
  gst_video_frame_map (&frame, &rect->info, rect->pixels, GST_MAP_READ);
Packit 0652a1
  dst = GST_VIDEO_FRAME_PLANE_DATA (&frame, 0);
Packit 0652a1
  w = GST_VIDEO_INFO_WIDTH (&rect->info);
Packit 0652a1
  h = GST_VIDEO_INFO_HEIGHT (&rect->info);
Packit 0652a1
  stride = GST_VIDEO_INFO_PLANE_STRIDE (&rect->info, 0);
Packit 0652a1
Packit 0652a1
  argb_a = GST_VIDEO_INFO_COMP_POFFSET (&rect->info, 3);
Packit 0652a1
  argb_r = (argb_a + 1) % 4;
Packit 0652a1
  argb_g = (argb_a + 2) % 4;
Packit 0652a1
  argb_b = (argb_a + 3) % 4;
Packit 0652a1
Packit 0652a1
  for (i = 0; i < h; i++) {
Packit 0652a1
    for (j = 0; j < w; j++) {
Packit 0652a1
      guint8 na = (guint8) (*src * global_alpha);
Packit 0652a1
Packit 0652a1
      if (! !(rect->flags & GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA)) {
Packit 0652a1
        dst[argb_r] =
Packit 0652a1
            (guint8) ((double) (dst[argb_r] * 255) / (double) dst[argb_a]) *
Packit 0652a1
            na / 255;
Packit 0652a1
        dst[argb_g] =
Packit 0652a1
            (guint8) ((double) (dst[argb_g] * 255) / (double) dst[argb_a]) *
Packit 0652a1
            na / 255;
Packit 0652a1
        dst[argb_b] =
Packit 0652a1
            (guint8) ((double) (dst[argb_b] * 255) / (double) dst[argb_a]) *
Packit 0652a1
            na / 255;
Packit 0652a1
      }
Packit 0652a1
      dst[argb_a] = na;
Packit 0652a1
      src++;
Packit 0652a1
      dst += 4;
Packit 0652a1
    }
Packit 0652a1
    dst += stride - 4 * w;
Packit 0652a1
  }
Packit 0652a1
  gst_video_frame_unmap (&frame);
Packit 0652a1
Packit 0652a1
  rect->applied_global_alpha = global_alpha;
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
static void
Packit 0652a1
gst_video_overlay_rectangle_convert (GstVideoInfo * src, GstBuffer * src_buffer,
Packit 0652a1
    GstVideoFormat dest_format, GstVideoInfo * dest, GstBuffer ** dest_buffer)
Packit 0652a1
{
Packit 0652a1
  gint width, height, stride;
Packit 0652a1
  GstVideoFrame src_frame, dest_frame;
Packit 0652a1
  GstVideoFormat format;
Packit 0652a1
  gint k, l;
Packit 0652a1
  guint8 *sdata, *ddata;
Packit 0652a1
Packit 0652a1
  format = GST_VIDEO_INFO_FORMAT (src);
Packit 0652a1
Packit 0652a1
  width = GST_VIDEO_INFO_WIDTH (src);
Packit 0652a1
  height = GST_VIDEO_INFO_HEIGHT (src);
Packit 0652a1
Packit 0652a1
  gst_video_info_init (dest);
Packit 0652a1
  if (!gst_video_info_set_format (dest, dest_format, width, height)) {
Packit 0652a1
    g_warn_if_reached ();
Packit 0652a1
    return;
Packit 0652a1
  }
Packit 0652a1
Packit 0652a1
  *dest_buffer = gst_buffer_new_and_alloc (GST_VIDEO_INFO_SIZE (dest));
Packit 0652a1
Packit 0652a1
  gst_video_frame_map (&src_frame, src, src_buffer, GST_MAP_READ);
Packit 0652a1
  gst_video_frame_map (&dest_frame, dest, *dest_buffer, GST_MAP_WRITE);
Packit 0652a1
Packit 0652a1
  sdata = GST_VIDEO_FRAME_PLANE_DATA (&src_frame, 0);
Packit 0652a1
  ddata = GST_VIDEO_FRAME_PLANE_DATA (&dest_frame, 0);
Packit 0652a1
  stride = GST_VIDEO_FRAME_PLANE_STRIDE (&src_frame, 0);
Packit 0652a1
Packit 0652a1
  if (format == GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_YUV &&
Packit 0652a1
      dest_format == GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB) {
Packit 0652a1
    gint ayuv;
Packit 0652a1
    gint a, y, u, v, r, g, b;
Packit 0652a1
Packit 0652a1
    for (k = 0; k < height; k++) {
Packit 0652a1
      for (l = 0; l < width; l++) {
Packit 0652a1
        ayuv = GST_READ_UINT32_BE (sdata);
Packit 0652a1
        a = ayuv >> 24;
Packit 0652a1
        y = (ayuv >> 16) & 0xff;
Packit 0652a1
        u = (ayuv >> 8) & 0xff;
Packit 0652a1
        v = (ayuv & 0xff);
Packit 0652a1
Packit 0652a1
        r = (298 * y + 459 * v - 63514) >> 8;
Packit 0652a1
        g = (298 * y - 55 * u - 136 * v + 19681) >> 8;
Packit 0652a1
        b = (298 * y + 541 * u - 73988) >> 8;
Packit 0652a1
Packit 0652a1
        r = CLAMP (r, 0, 255);
Packit 0652a1
        g = CLAMP (g, 0, 255);
Packit 0652a1
        b = CLAMP (b, 0, 255);
Packit 0652a1
Packit 0652a1
        /* native endian ARGB */
Packit 0652a1
        *(guint32 *) ddata = ((a << 24) | (r << 16) | (g << 8) | b);
Packit 0652a1
Packit 0652a1
        sdata += 4;
Packit 0652a1
        ddata += 4;
Packit 0652a1
      }
Packit 0652a1
      sdata += stride - 4 * width;
Packit 0652a1
    }
Packit 0652a1
  } else if (format == GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB &&
Packit 0652a1
      dest_format == GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_YUV) {
Packit 0652a1
    gint argb;
Packit 0652a1
    gint a, y, u, v, r, g, b;
Packit 0652a1
Packit 0652a1
    for (k = 0; k < height; k++) {
Packit 0652a1
      for (l = 0; l < width; l++) {
Packit 0652a1
        /* native endian ARGB */
Packit 0652a1
        argb = *(guint32 *) sdata;
Packit 0652a1
        a = argb >> 24;
Packit 0652a1
        r = (argb >> 16) & 0xff;
Packit 0652a1
        g = (argb >> 8) & 0xff;
Packit 0652a1
        b = (argb & 0xff);
Packit 0652a1
Packit 0652a1
        y = (47 * r + 157 * g + 16 * b + 4096) >> 8;
Packit 0652a1
        u = (-26 * r - 87 * g + 112 * b + 32768) >> 8;
Packit 0652a1
        v = (112 * r - 102 * g - 10 * b + 32768) >> 8;
Packit 0652a1
Packit 0652a1
        y = CLAMP (y, 0, 255);
Packit 0652a1
        u = CLAMP (u, 0, 255);
Packit 0652a1
        v = CLAMP (v, 0, 255);
Packit 0652a1
Packit 0652a1
        GST_WRITE_UINT32_BE (ddata, ((a << 24) | (y << 16) | (u << 8) | v));
Packit 0652a1
Packit 0652a1
        sdata += 4;
Packit 0652a1
        ddata += 4;
Packit 0652a1
      }
Packit 0652a1
      sdata += stride - 4 * width;
Packit 0652a1
    }
Packit 0652a1
  } else {
Packit 0652a1
    GST_ERROR ("unsupported conversion");
Packit 0652a1
    g_assert_not_reached ();
Packit 0652a1
  }
Packit 0652a1
Packit 0652a1
  gst_video_frame_unmap (&src_frame);
Packit 0652a1
  gst_video_frame_unmap (&dest_frame);
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
static GstBuffer *
Packit 0652a1
gst_video_overlay_rectangle_get_pixels_raw_internal (GstVideoOverlayRectangle *
Packit 0652a1
    rectangle, GstVideoOverlayFormatFlags flags, gboolean unscaled,
Packit 0652a1
    GstVideoFormat wanted_format)
Packit 0652a1
{
Packit 0652a1
  GstVideoOverlayFormatFlags new_flags;
Packit 0652a1
  GstVideoOverlayRectangle *scaled_rect = NULL, *conv_rect = NULL;
Packit 0652a1
  GstVideoInfo info;
Packit 0652a1
  GstVideoFrame frame;
Packit 0652a1
  GstBuffer *buf;
Packit 0652a1
  GList *l;
Packit 0652a1
  guint width, height;
Packit 0652a1
  guint wanted_width;
Packit 0652a1
  guint wanted_height;
Packit 0652a1
  gboolean apply_global_alpha;
Packit 0652a1
  gboolean revert_global_alpha;
Packit 0652a1
  GstVideoFormat format;
Packit 0652a1
Packit 0652a1
  g_return_val_if_fail (GST_IS_VIDEO_OVERLAY_RECTANGLE (rectangle), NULL);
Packit 0652a1
  g_return_val_if_fail (gst_video_overlay_rectangle_check_flags (flags), NULL);
Packit 0652a1
Packit 0652a1
  width = GST_VIDEO_INFO_WIDTH (&rectangle->info);
Packit 0652a1
  height = GST_VIDEO_INFO_HEIGHT (&rectangle->info);
Packit 0652a1
  wanted_width = unscaled ? width : rectangle->render_width;
Packit 0652a1
  wanted_height = unscaled ? height : rectangle->render_height;
Packit 0652a1
  format = GST_VIDEO_INFO_FORMAT (&rectangle->info);
Packit 0652a1
Packit 0652a1
  apply_global_alpha =
Packit 0652a1
      (! !(rectangle->flags & GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA)
Packit 0652a1
      && !(flags & GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA));
Packit 0652a1
  revert_global_alpha =
Packit 0652a1
      (! !(rectangle->flags & GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA)
Packit 0652a1
      && ! !(flags & GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA));
Packit 0652a1
Packit 0652a1
  /* This assumes we don't need to adjust the format */
Packit 0652a1
  if (wanted_width == width &&
Packit 0652a1
      wanted_height == height &&
Packit 0652a1
      wanted_format == format &&
Packit 0652a1
      gst_video_overlay_rectangle_is_same_alpha_type (rectangle->flags,
Packit 0652a1
          flags)) {
Packit 0652a1
    /* don't need to apply/revert global-alpha either: */
Packit 0652a1
    if ((!apply_global_alpha
Packit 0652a1
            || rectangle->applied_global_alpha == rectangle->global_alpha)
Packit 0652a1
        && (!revert_global_alpha || rectangle->applied_global_alpha == 1.0)) {
Packit 0652a1
      return rectangle->pixels;
Packit 0652a1
    } else {
Packit 0652a1
      /* only apply/revert global-alpha */
Packit 0652a1
      scaled_rect = rectangle;
Packit 0652a1
      goto done;
Packit 0652a1
    }
Packit 0652a1
  }
Packit 0652a1
Packit 0652a1
  /* see if we've got one cached already */
Packit 0652a1
  GST_RECTANGLE_LOCK (rectangle);
Packit 0652a1
  for (l = rectangle->scaled_rectangles; l != NULL; l = l->next) {
Packit 0652a1
    GstVideoOverlayRectangle *r = l->data;
Packit 0652a1
Packit 0652a1
    if (GST_VIDEO_INFO_WIDTH (&r->info) == wanted_width &&
Packit 0652a1
        GST_VIDEO_INFO_HEIGHT (&r->info) == wanted_height &&
Packit 0652a1
        GST_VIDEO_INFO_FORMAT (&r->info) == wanted_format &&
Packit 0652a1
        gst_video_overlay_rectangle_is_same_alpha_type (r->flags, flags)) {
Packit 0652a1
      /* we'll keep these rectangles around until finalize, so it's ok not
Packit 0652a1
       * to take our own ref here */
Packit 0652a1
      scaled_rect = r;
Packit 0652a1
      break;
Packit 0652a1
    }
Packit 0652a1
  }
Packit 0652a1
  GST_RECTANGLE_UNLOCK (rectangle);
Packit 0652a1
Packit 0652a1
  if (scaled_rect != NULL)
Packit 0652a1
    goto done;
Packit 0652a1
Packit 0652a1
  /* maybe have one in the right format though */
Packit 0652a1
  if (format != wanted_format) {
Packit 0652a1
    GST_RECTANGLE_LOCK (rectangle);
Packit 0652a1
    for (l = rectangle->scaled_rectangles; l != NULL; l = l->next) {
Packit 0652a1
      GstVideoOverlayRectangle *r = l->data;
Packit 0652a1
Packit 0652a1
      if (GST_VIDEO_INFO_FORMAT (&r->info) == wanted_format &&
Packit 0652a1
          gst_video_overlay_rectangle_is_same_alpha_type (r->flags, flags)) {
Packit 0652a1
        /* we'll keep these rectangles around until finalize, so it's ok not
Packit 0652a1
         * to take our own ref here */
Packit 0652a1
        conv_rect = r;
Packit 0652a1
        break;
Packit 0652a1
      }
Packit 0652a1
    }
Packit 0652a1
    GST_RECTANGLE_UNLOCK (rectangle);
Packit 0652a1
  } else {
Packit 0652a1
    conv_rect = rectangle;
Packit 0652a1
  }
Packit 0652a1
Packit 0652a1
  if (conv_rect == NULL) {
Packit 0652a1
    GstVideoInfo conv_info;
Packit 0652a1
Packit 0652a1
    gst_video_overlay_rectangle_convert (&rectangle->info, rectangle->pixels,
Packit 0652a1
        wanted_format, &conv_info, &buf;;
Packit 0652a1
    gst_buffer_add_video_meta (buf, GST_VIDEO_FRAME_FLAG_NONE,
Packit 0652a1
        GST_VIDEO_INFO_FORMAT (&conv_info), width, height);
Packit 0652a1
    conv_rect = gst_video_overlay_rectangle_new_raw (buf,
Packit 0652a1
        0, 0, width, height, rectangle->flags);
Packit 0652a1
    if (rectangle->global_alpha != 1.0)
Packit 0652a1
      gst_video_overlay_rectangle_set_global_alpha (scaled_rect,
Packit 0652a1
          rectangle->global_alpha);
Packit 0652a1
    gst_buffer_unref (buf);
Packit 0652a1
    /* keep this converted one around as well in any case */
Packit 0652a1
    GST_RECTANGLE_LOCK (rectangle);
Packit 0652a1
    rectangle->scaled_rectangles =
Packit 0652a1
        g_list_prepend (rectangle->scaled_rectangles, conv_rect);
Packit 0652a1
    GST_RECTANGLE_UNLOCK (rectangle);
Packit 0652a1
  }
Packit 0652a1
Packit 0652a1
  /* now we continue from conv_rect */
Packit 0652a1
  width = GST_VIDEO_INFO_WIDTH (&conv_rect->info);
Packit 0652a1
  height = GST_VIDEO_INFO_HEIGHT (&conv_rect->info);
Packit 0652a1
  format = GST_VIDEO_INFO_FORMAT (&conv_rect->info);
Packit 0652a1
Packit 0652a1
  /* not cached yet, do the preprocessing and put the result into our cache */
Packit 0652a1
  if (wanted_width != width || wanted_height != height) {
Packit 0652a1
    GstVideoInfo scaled_info;
Packit 0652a1
Packit 0652a1
    /* we could check the cache for a scaled rect with global_alpha == 1 here */
Packit 0652a1
    gst_video_blend_scale_linear_RGBA (&conv_rect->info, conv_rect->pixels,
Packit 0652a1
        wanted_height, wanted_width, &scaled_info, &buf;;
Packit 0652a1
    info = scaled_info;
Packit 0652a1
    gst_buffer_add_video_meta (buf, GST_VIDEO_FRAME_FLAG_NONE,
Packit 0652a1
        GST_VIDEO_INFO_FORMAT (&conv_rect->info), wanted_width, wanted_height);
Packit 0652a1
  } else if (!gst_video_overlay_rectangle_is_same_alpha_type (conv_rect->flags,
Packit 0652a1
          flags)) {
Packit 0652a1
    /* if we don't have to scale, we have to modify the alpha values, so we
Packit 0652a1
     * need to make a copy of the pixel memory (and we take ownership below) */
Packit 0652a1
    buf = gst_buffer_copy (conv_rect->pixels);
Packit 0652a1
    info = conv_rect->info;
Packit 0652a1
  } else {
Packit 0652a1
    /* do not need to scale or modify alpha values, almost done then */
Packit 0652a1
    scaled_rect = conv_rect;
Packit 0652a1
    goto done;
Packit 0652a1
  }
Packit 0652a1
Packit 0652a1
  new_flags = conv_rect->flags;
Packit 0652a1
  gst_video_frame_map (&frame, &info, buf, GST_MAP_READWRITE);
Packit 0652a1
  if (!gst_video_overlay_rectangle_is_same_alpha_type (conv_rect->flags, flags)) {
Packit 0652a1
    if (rectangle->flags & GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA) {
Packit 0652a1
      gst_video_overlay_rectangle_unpremultiply (&frame);
Packit 0652a1
      new_flags &= ~GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA;
Packit 0652a1
    } else {
Packit 0652a1
      gst_video_overlay_rectangle_premultiply (&frame);
Packit 0652a1
      new_flags |= GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA;
Packit 0652a1
    }
Packit 0652a1
  }
Packit 0652a1
  gst_video_frame_unmap (&frame);
Packit 0652a1
Packit 0652a1
  scaled_rect = gst_video_overlay_rectangle_new_raw (buf,
Packit 0652a1
      0, 0, wanted_width, wanted_height, new_flags);
Packit 0652a1
  if (conv_rect->global_alpha != 1.0)
Packit 0652a1
    gst_video_overlay_rectangle_set_global_alpha (scaled_rect,
Packit 0652a1
        conv_rect->global_alpha);
Packit 0652a1
  gst_buffer_unref (buf);
Packit 0652a1
Packit 0652a1
  GST_RECTANGLE_LOCK (rectangle);
Packit 0652a1
  rectangle->scaled_rectangles =
Packit 0652a1
      g_list_prepend (rectangle->scaled_rectangles, scaled_rect);
Packit 0652a1
  GST_RECTANGLE_UNLOCK (rectangle);
Packit 0652a1
Packit 0652a1
done:
Packit 0652a1
Packit 0652a1
  GST_RECTANGLE_LOCK (rectangle);
Packit 0652a1
  if (apply_global_alpha
Packit 0652a1
      && scaled_rect->applied_global_alpha != rectangle->global_alpha) {
Packit 0652a1
    gst_video_overlay_rectangle_apply_global_alpha (scaled_rect,
Packit 0652a1
        rectangle->global_alpha);
Packit 0652a1
    gst_video_overlay_rectangle_set_global_alpha (scaled_rect,
Packit 0652a1
        rectangle->global_alpha);
Packit 0652a1
  } else if (revert_global_alpha && scaled_rect->applied_global_alpha != 1.0) {
Packit 0652a1
    gst_video_overlay_rectangle_apply_global_alpha (scaled_rect, 1.0);
Packit 0652a1
  }
Packit 0652a1
  GST_RECTANGLE_UNLOCK (rectangle);
Packit 0652a1
Packit 0652a1
  return scaled_rect->pixels;
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * gst_video_overlay_rectangle_get_pixels_raw:
Packit 0652a1
 * @rectangle: a #GstVideoOverlayRectangle
Packit 0652a1
 * @flags: flags
Packit 0652a1
 *    If a global_alpha value != 1 is set for the rectangle, the caller
Packit 0652a1
 *    should set the #GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA flag
Packit 0652a1
 *    if he wants to apply global-alpha himself. If the flag is not set
Packit 0652a1
 *    global_alpha is applied internally before returning the pixel-data.
Packit 0652a1
 *
Packit 0652a1
 * Returns: (transfer none): a #GstBuffer holding the pixel data with
Packit 0652a1
 *    format as originally provided and specified in video meta with
Packit 0652a1
 *    width and height of the render dimensions as per
Packit 0652a1
 *    gst_video_overlay_rectangle_get_render_rectangle(). This function does
Packit 0652a1
 *    not return a reference, the caller should obtain a reference of her own
Packit 0652a1
 *    with gst_buffer_ref() if needed.
Packit 0652a1
 */
Packit 0652a1
GstBuffer *
Packit 0652a1
gst_video_overlay_rectangle_get_pixels_raw (GstVideoOverlayRectangle *
Packit 0652a1
    rectangle, GstVideoOverlayFormatFlags flags)
Packit 0652a1
{
Packit 0652a1
  return gst_video_overlay_rectangle_get_pixels_raw_internal (rectangle,
Packit 0652a1
      flags, FALSE, GST_VIDEO_INFO_FORMAT (&rectangle->info));
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * gst_video_overlay_rectangle_get_pixels_argb:
Packit 0652a1
 * @rectangle: a #GstVideoOverlayRectangle
Packit 0652a1
 * @flags: flags
Packit 0652a1
 *    If a global_alpha value != 1 is set for the rectangle, the caller
Packit 0652a1
 *    should set the #GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA flag
Packit 0652a1
 *    if he wants to apply global-alpha himself. If the flag is not set
Packit 0652a1
 *    global_alpha is applied internally before returning the pixel-data.
Packit 0652a1
 *
Packit 0652a1
 * Returns: (transfer none): a #GstBuffer holding the ARGB pixel data with
Packit 0652a1
 *    width and height of the render dimensions as per
Packit 0652a1
 *    gst_video_overlay_rectangle_get_render_rectangle(). This function does
Packit 0652a1
 *    not return a reference, the caller should obtain a reference of her own
Packit 0652a1
 *    with gst_buffer_ref() if needed.
Packit 0652a1
 */
Packit 0652a1
GstBuffer *
Packit 0652a1
gst_video_overlay_rectangle_get_pixels_argb (GstVideoOverlayRectangle *
Packit 0652a1
    rectangle, GstVideoOverlayFormatFlags flags)
Packit 0652a1
{
Packit 0652a1
  return gst_video_overlay_rectangle_get_pixels_raw_internal (rectangle,
Packit 0652a1
      flags, FALSE, GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB);
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * gst_video_overlay_rectangle_get_pixels_ayuv:
Packit 0652a1
 * @rectangle: a #GstVideoOverlayRectangle
Packit 0652a1
 * @flags: flags
Packit 0652a1
 *    If a global_alpha value != 1 is set for the rectangle, the caller
Packit 0652a1
 *    should set the #GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA flag
Packit 0652a1
 *    if he wants to apply global-alpha himself. If the flag is not set
Packit 0652a1
 *    global_alpha is applied internally before returning the pixel-data.
Packit 0652a1
 *
Packit 0652a1
 * Returns: (transfer none): a #GstBuffer holding the AYUV pixel data with
Packit 0652a1
 *    width and height of the render dimensions as per
Packit 0652a1
 *    gst_video_overlay_rectangle_get_render_rectangle(). This function does
Packit 0652a1
 *    not return a reference, the caller should obtain a reference of her own
Packit 0652a1
 *    with gst_buffer_ref() if needed.
Packit 0652a1
 */
Packit 0652a1
GstBuffer *
Packit 0652a1
gst_video_overlay_rectangle_get_pixels_ayuv (GstVideoOverlayRectangle *
Packit 0652a1
    rectangle, GstVideoOverlayFormatFlags flags)
Packit 0652a1
{
Packit 0652a1
  return gst_video_overlay_rectangle_get_pixels_raw_internal (rectangle,
Packit 0652a1
      flags, FALSE, GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_YUV);
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * gst_video_overlay_rectangle_get_pixels_unscaled_raw:
Packit 0652a1
 * @rectangle: a #GstVideoOverlayRectangle
Packit 0652a1
 * @flags: flags.
Packit 0652a1
 *    If a global_alpha value != 1 is set for the rectangle, the caller
Packit 0652a1
 *    should set the #GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA flag
Packit 0652a1
 *    if he wants to apply global-alpha himself. If the flag is not set
Packit 0652a1
 *    global_alpha is applied internally before returning the pixel-data.
Packit 0652a1
 *
Packit 0652a1
 * Retrieves the pixel data as it is. This is useful if the caller can
Packit 0652a1
 * do the scaling itself when handling the overlaying. The rectangle will
Packit 0652a1
 * need to be scaled to the render dimensions, which can be retrieved using
Packit 0652a1
 * gst_video_overlay_rectangle_get_render_rectangle().
Packit 0652a1
 *
Packit 0652a1
 * Returns: (transfer none): a #GstBuffer holding the pixel data with
Packit 0652a1
 *    #GstVideoMeta set. This function does not return a reference, the caller
Packit 0652a1
 *    should obtain a reference of her own with gst_buffer_ref() if needed.
Packit 0652a1
 */
Packit 0652a1
GstBuffer *
Packit 0652a1
gst_video_overlay_rectangle_get_pixels_unscaled_raw (GstVideoOverlayRectangle *
Packit 0652a1
    rectangle, GstVideoOverlayFormatFlags flags)
Packit 0652a1
{
Packit 0652a1
  g_return_val_if_fail (GST_IS_VIDEO_OVERLAY_RECTANGLE (rectangle), NULL);
Packit 0652a1
Packit 0652a1
  return gst_video_overlay_rectangle_get_pixels_raw_internal (rectangle,
Packit 0652a1
      flags, TRUE, GST_VIDEO_INFO_FORMAT (&rectangle->info));
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * gst_video_overlay_rectangle_get_pixels_unscaled_argb:
Packit 0652a1
 * @rectangle: a #GstVideoOverlayRectangle
Packit 0652a1
 * @flags: flags.
Packit 0652a1
 *    If a global_alpha value != 1 is set for the rectangle, the caller
Packit 0652a1
 *    should set the #GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA flag
Packit 0652a1
 *    if he wants to apply global-alpha himself. If the flag is not set
Packit 0652a1
 *    global_alpha is applied internally before returning the pixel-data.
Packit 0652a1
 *
Packit 0652a1
 * Retrieves the pixel data as it is. This is useful if the caller can
Packit 0652a1
 * do the scaling itself when handling the overlaying. The rectangle will
Packit 0652a1
 * need to be scaled to the render dimensions, which can be retrieved using
Packit 0652a1
 * gst_video_overlay_rectangle_get_render_rectangle().
Packit 0652a1
 *
Packit 0652a1
 * Returns: (transfer none): a #GstBuffer holding the ARGB pixel data with
Packit 0652a1
 *    #GstVideoMeta set. This function does not return a reference, the caller
Packit 0652a1
 *    should obtain a reference of her own with gst_buffer_ref() if needed.
Packit 0652a1
 */
Packit 0652a1
GstBuffer *
Packit 0652a1
gst_video_overlay_rectangle_get_pixels_unscaled_argb (GstVideoOverlayRectangle *
Packit 0652a1
    rectangle, GstVideoOverlayFormatFlags flags)
Packit 0652a1
{
Packit 0652a1
  g_return_val_if_fail (GST_IS_VIDEO_OVERLAY_RECTANGLE (rectangle), NULL);
Packit 0652a1
Packit 0652a1
  return gst_video_overlay_rectangle_get_pixels_raw_internal (rectangle,
Packit 0652a1
      flags, TRUE, GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB);
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * gst_video_overlay_rectangle_get_pixels_unscaled_ayuv:
Packit 0652a1
 * @rectangle: a #GstVideoOverlayRectangle
Packit 0652a1
 * @flags: flags.
Packit 0652a1
 *    If a global_alpha value != 1 is set for the rectangle, the caller
Packit 0652a1
 *    should set the #GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA flag
Packit 0652a1
 *    if he wants to apply global-alpha himself. If the flag is not set
Packit 0652a1
 *    global_alpha is applied internally before returning the pixel-data.
Packit 0652a1
 *
Packit 0652a1
 * Retrieves the pixel data as it is. This is useful if the caller can
Packit 0652a1
 * do the scaling itself when handling the overlaying. The rectangle will
Packit 0652a1
 * need to be scaled to the render dimensions, which can be retrieved using
Packit 0652a1
 * gst_video_overlay_rectangle_get_render_rectangle().
Packit 0652a1
 *
Packit 0652a1
 * Returns: (transfer none): a #GstBuffer holding the AYUV pixel data with
Packit 0652a1
 *    #GstVideoMeta set. This function does not return a reference, the caller
Packit 0652a1
 *    should obtain a reference of her own with gst_buffer_ref() if needed.
Packit 0652a1
 */
Packit 0652a1
GstBuffer *
Packit 0652a1
gst_video_overlay_rectangle_get_pixels_unscaled_ayuv (GstVideoOverlayRectangle *
Packit 0652a1
    rectangle, GstVideoOverlayFormatFlags flags)
Packit 0652a1
{
Packit 0652a1
  g_return_val_if_fail (GST_IS_VIDEO_OVERLAY_RECTANGLE (rectangle), NULL);
Packit 0652a1
Packit 0652a1
  return gst_video_overlay_rectangle_get_pixels_raw_internal (rectangle,
Packit 0652a1
      flags, TRUE, GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_YUV);
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * gst_video_overlay_rectangle_get_flags:
Packit 0652a1
 * @rectangle: a #GstVideoOverlayRectangle
Packit 0652a1
 *
Packit 0652a1
 * Retrieves the flags associated with a #GstVideoOverlayRectangle.
Packit 0652a1
 * This is useful if the caller can handle both premultiplied alpha and
Packit 0652a1
 * non premultiplied alpha, for example. By knowing whether the rectangle
Packit 0652a1
 * uses premultiplied or not, it can request the pixel data in the format
Packit 0652a1
 * it is stored in, to avoid unnecessary conversion.
Packit 0652a1
 *
Packit 0652a1
 * Returns: the #GstVideoOverlayFormatFlags associated with the rectangle.
Packit 0652a1
 */
Packit 0652a1
GstVideoOverlayFormatFlags
Packit 0652a1
gst_video_overlay_rectangle_get_flags (GstVideoOverlayRectangle * rectangle)
Packit 0652a1
{
Packit 0652a1
  g_return_val_if_fail (GST_IS_VIDEO_OVERLAY_RECTANGLE (rectangle),
Packit 0652a1
      GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
Packit 0652a1
Packit 0652a1
  return rectangle->flags;
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * gst_video_overlay_rectangle_get_global_alpha:
Packit 0652a1
 * @rectangle: a #GstVideoOverlayRectangle
Packit 0652a1
 *
Packit 0652a1
 * Retrieves the global-alpha value associated with a #GstVideoOverlayRectangle.
Packit 0652a1
 *
Packit 0652a1
 * Returns: the global-alpha value associated with the rectangle.
Packit 0652a1
 */
Packit 0652a1
gfloat
Packit 0652a1
gst_video_overlay_rectangle_get_global_alpha (GstVideoOverlayRectangle *
Packit 0652a1
    rectangle)
Packit 0652a1
{
Packit 0652a1
  g_return_val_if_fail (GST_IS_VIDEO_OVERLAY_RECTANGLE (rectangle), -1);
Packit 0652a1
Packit 0652a1
  return rectangle->global_alpha;
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * gst_video_overlay_rectangle_set_global_alpha:
Packit 0652a1
 * @rectangle: a #GstVideoOverlayRectangle
Packit 0652a1
 * @global_alpha: Global alpha value (0 to 1.0)
Packit 0652a1
 *
Packit 0652a1
 * Sets the global alpha value associated with a #GstVideoOverlayRectangle. Per-
Packit 0652a1
 * pixel alpha values are multiplied with this value. Valid
Packit 0652a1
 * values: 0 <= global_alpha <= 1; 1 to deactivate.
Packit 0652a1
 *
Packit 0652a1
 * @rectangle must be writable, meaning its refcount must be 1. You can
Packit 0652a1
 * make the rectangles inside a #GstVideoOverlayComposition writable using
Packit 0652a1
 * gst_video_overlay_composition_make_writable() or
Packit 0652a1
 * gst_video_overlay_composition_copy().
Packit 0652a1
 */
Packit 0652a1
void
Packit 0652a1
gst_video_overlay_rectangle_set_global_alpha (GstVideoOverlayRectangle *
Packit 0652a1
    rectangle, gfloat global_alpha)
Packit 0652a1
{
Packit 0652a1
  g_return_if_fail (GST_IS_VIDEO_OVERLAY_RECTANGLE (rectangle));
Packit 0652a1
  g_return_if_fail (gst_mini_object_is_writable (GST_MINI_OBJECT_CAST
Packit 0652a1
          (rectangle)));
Packit 0652a1
  g_return_if_fail (global_alpha >= 0 && global_alpha <= 1);
Packit 0652a1
Packit 0652a1
  if (rectangle->global_alpha != global_alpha) {
Packit 0652a1
    rectangle->global_alpha = global_alpha;
Packit 0652a1
    if (global_alpha != 1)
Packit 0652a1
      rectangle->flags |= GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA;
Packit 0652a1
    else
Packit 0652a1
      rectangle->flags &= ~GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA;
Packit 0652a1
    /* update seq_num automatically to signal the consumer, that data has changed
Packit 0652a1
     * note, that this might mislead renderers, that can handle global-alpha
Packit 0652a1
     * themselves, because what they want to know is whether the actual pixel data
Packit 0652a1
     * has changed. */
Packit 0652a1
    rectangle->seq_num = gst_video_overlay_get_seqnum ();
Packit 0652a1
  }
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * gst_video_overlay_rectangle_copy:
Packit 0652a1
 * @rectangle: (transfer none): a #GstVideoOverlayRectangle to copy
Packit 0652a1
 *
Packit 0652a1
 * Makes a copy of @rectangle, so that it is possible to modify it
Packit 0652a1
 * (e.g. to change the render co-ordinates or render dimension). The
Packit 0652a1
 * actual overlay pixel data buffers contained in the rectangle are not
Packit 0652a1
 * copied.
Packit 0652a1
 *
Packit 0652a1
 * Returns: (transfer full): a new #GstVideoOverlayRectangle equivalent
Packit 0652a1
 *     to @rectangle.
Packit 0652a1
 */
Packit 0652a1
GstVideoOverlayRectangle *
Packit 0652a1
gst_video_overlay_rectangle_copy (GstVideoOverlayRectangle * rectangle)
Packit 0652a1
{
Packit 0652a1
  GstVideoOverlayRectangle *copy;
Packit 0652a1
Packit 0652a1
  g_return_val_if_fail (GST_IS_VIDEO_OVERLAY_RECTANGLE (rectangle), NULL);
Packit 0652a1
Packit 0652a1
  copy = gst_video_overlay_rectangle_new_raw (rectangle->pixels,
Packit 0652a1
      rectangle->x, rectangle->y,
Packit 0652a1
      rectangle->render_width, rectangle->render_height, rectangle->flags);
Packit 0652a1
  if (rectangle->global_alpha != 1)
Packit 0652a1
    gst_video_overlay_rectangle_set_global_alpha (copy,
Packit 0652a1
        rectangle->global_alpha);
Packit 0652a1
Packit 0652a1
  return copy;
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * gst_video_overlay_rectangle_get_seqnum:
Packit 0652a1
 * @rectangle: a #GstVideoOverlayRectangle
Packit 0652a1
 *
Packit 0652a1
 * Returns the sequence number of this rectangle. Sequence numbers are
Packit 0652a1
 * monotonically increasing and unique for overlay compositions and rectangles
Packit 0652a1
 * (meaning there will never be a rectangle with the same sequence number as
Packit 0652a1
 * a composition).
Packit 0652a1
 *
Packit 0652a1
 * Using the sequence number of a rectangle as an indicator for changed
Packit 0652a1
 * pixel-data of a rectangle is dangereous. Some API calls, like e.g.
Packit 0652a1
 * gst_video_overlay_rectangle_set_global_alpha(), automatically update
Packit 0652a1
 * the per rectangle sequence number, which is misleading for renderers/
Packit 0652a1
 * consumers, that handle global-alpha themselves. For them  the
Packit 0652a1
 * pixel-data returned by gst_video_overlay_rectangle_get_pixels_*()
Packit 0652a1
 * wont be different for different global-alpha values. In this case a
Packit 0652a1
 * renderer could also use the GstBuffer pointers as a hint for changed
Packit 0652a1
 * pixel-data.
Packit 0652a1
 *
Packit 0652a1
 * Returns: the sequence number of @rectangle
Packit 0652a1
 */
Packit 0652a1
guint
Packit 0652a1
gst_video_overlay_rectangle_get_seqnum (GstVideoOverlayRectangle * rectangle)
Packit 0652a1
{
Packit 0652a1
  g_return_val_if_fail (GST_IS_VIDEO_OVERLAY_RECTANGLE (rectangle), 0);
Packit 0652a1
Packit 0652a1
  return rectangle->seq_num;
Packit 0652a1
}