videooverlaycomposition: make API meta oriented
... and as such more consistent with other buffer meta components.
This commit is contained in:
parent
fa72c94a53
commit
bcc5a89a98
@ -190,32 +190,6 @@ gst_video_overlay_get_seqnum (void)
|
|||||||
return (guint) g_atomic_int_add (&seqnum, 1);
|
return (guint) g_atomic_int_add (&seqnum, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO ??
|
|
||||||
* maybe this should be in public header and expose a more meta oriented API,
|
|
||||||
* rather than hiding it here internally ? */
|
|
||||||
|
|
||||||
#define GST_VIDEO_OVERLAY_COMPOSITION_META_API_TYPE \
|
|
||||||
(gst_video_overlay_composition_meta_api_get_type())
|
|
||||||
#define GST_VIDEO_OVERLAY_COMPOSITION_META_INFO \
|
|
||||||
(gst_video_overlay_composition_meta_get_info())
|
|
||||||
typedef struct _GstVideoOverlayCompositionMeta GstVideoOverlayCompositionMeta;
|
|
||||||
|
|
||||||
static const GstMetaInfo *gst_video_overlay_composition_meta_get_info (void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* GstVideoOverlayCompositionMeta:
|
|
||||||
* @meta: parent #GstMeta
|
|
||||||
* @overlay: the attached #GstVideoOverlayComposition
|
|
||||||
*
|
|
||||||
* Extra buffer metadata describing image overlay data.
|
|
||||||
*/
|
|
||||||
struct _GstVideoOverlayCompositionMeta
|
|
||||||
{
|
|
||||||
GstMeta meta;
|
|
||||||
|
|
||||||
GstVideoOverlayComposition *overlay;
|
|
||||||
};
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_video_overlay_composition_meta_free (GstMeta * meta, GstBuffer * buf)
|
gst_video_overlay_composition_meta_free (GstMeta * meta, GstBuffer * buf)
|
||||||
{
|
{
|
||||||
@ -251,7 +225,7 @@ gst_video_overlay_composition_meta_transform (GstBuffer * dest, GstMeta * meta,
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static GType
|
GType
|
||||||
gst_video_overlay_composition_meta_api_get_type (void)
|
gst_video_overlay_composition_meta_api_get_type (void)
|
||||||
{
|
{
|
||||||
static volatile GType type = 0;
|
static volatile GType type = 0;
|
||||||
@ -266,7 +240,7 @@ gst_video_overlay_composition_meta_api_get_type (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* video overlay composition metadata */
|
/* video overlay composition metadata */
|
||||||
static const GstMetaInfo *
|
const GstMetaInfo *
|
||||||
gst_video_overlay_composition_meta_get_info (void)
|
gst_video_overlay_composition_meta_get_info (void)
|
||||||
{
|
{
|
||||||
static const GstMetaInfo *video_overlay_composition_meta_info = NULL;
|
static const GstMetaInfo *video_overlay_composition_meta_info = NULL;
|
||||||
@ -283,28 +257,10 @@ gst_video_overlay_composition_meta_get_info (void)
|
|||||||
return video_overlay_composition_meta_info;
|
return video_overlay_composition_meta_info;
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstVideoOverlayCompositionMeta *
|
|
||||||
gst_video_buffer_get_overlay_composition_meta (GstBuffer * buf)
|
|
||||||
{
|
|
||||||
gpointer state = NULL;
|
|
||||||
GstMeta *meta;
|
|
||||||
const GstMetaInfo *info = GST_VIDEO_OVERLAY_COMPOSITION_META_INFO;
|
|
||||||
|
|
||||||
while ((meta = gst_buffer_iterate_meta (buf, &state))) {
|
|
||||||
if (meta->info->api == info->api) {
|
|
||||||
GstVideoOverlayCompositionMeta *ometa =
|
|
||||||
(GstVideoOverlayCompositionMeta *) meta;
|
|
||||||
return ometa;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gst_video_buffer_set_overlay_composition:
|
* gst_buffer_add_video_overlay_composition_meta:
|
||||||
* @buf: a #GstBuffer
|
* @buf: a #GstBuffer
|
||||||
* @comp: (allow-none): a #GstVideoOverlayComposition, or NULL to clear a
|
* @comp: (allow-none): a #GstVideoOverlayComposition
|
||||||
* previously-set composition
|
|
||||||
*
|
*
|
||||||
* Sets an overlay composition on a buffer. The buffer will obtain its own
|
* Sets an overlay composition on a buffer. The buffer will obtain its own
|
||||||
* reference to the composition, meaning this function does not take ownership
|
* reference to the composition, meaning this function does not take ownership
|
||||||
@ -312,52 +268,20 @@ gst_video_buffer_get_overlay_composition_meta (GstBuffer * buf)
|
|||||||
*
|
*
|
||||||
* Since: 0.11.x
|
* Since: 0.11.x
|
||||||
*/
|
*/
|
||||||
void
|
GstVideoOverlayCompositionMeta *
|
||||||
gst_video_buffer_set_overlay_composition (GstBuffer * buf,
|
gst_buffer_add_video_overlay_composition_meta (GstBuffer * buf,
|
||||||
GstVideoOverlayComposition * comp)
|
GstVideoOverlayComposition * comp)
|
||||||
{
|
{
|
||||||
/* FIXME MT safety ? */
|
|
||||||
|
|
||||||
GstVideoOverlayCompositionMeta *ometa;
|
GstVideoOverlayCompositionMeta *ometa;
|
||||||
|
|
||||||
ometa = gst_video_buffer_get_overlay_composition_meta (buf);
|
g_return_val_if_fail (gst_buffer_is_writable (buf), NULL);
|
||||||
if (ometa) {
|
|
||||||
gst_mini_object_replace ((GstMiniObject **) & ometa->overlay,
|
|
||||||
(GstMiniObject *) comp);
|
|
||||||
} else {
|
|
||||||
ometa = (GstVideoOverlayCompositionMeta *)
|
ometa = (GstVideoOverlayCompositionMeta *)
|
||||||
gst_buffer_add_meta (buf, GST_VIDEO_OVERLAY_COMPOSITION_META_INFO,
|
gst_buffer_add_meta (buf, GST_VIDEO_OVERLAY_COMPOSITION_META_INFO, NULL);
|
||||||
NULL);
|
|
||||||
/* buffer might not be writable or so */
|
|
||||||
if (ometa)
|
|
||||||
ometa->overlay = gst_video_overlay_composition_ref (comp);
|
ometa->overlay = gst_video_overlay_composition_ref (comp);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
return ometa;
|
||||||
* gst_video_buffer_get_overlay_composition:
|
|
||||||
* @buf: a #GstBuffer
|
|
||||||
*
|
|
||||||
* Get the overlay composition that has previously been attached to a buffer
|
|
||||||
* with gst_video_buffer_get_overlay_composition(), usually by another element
|
|
||||||
* upstream.
|
|
||||||
*
|
|
||||||
* Returns: (transfer none): the #GstVideoOverlayComposition attached to
|
|
||||||
* this buffer, or NULL. Does not return a reference to the composition,
|
|
||||||
* caller must obtain her own ref via gst_video_overlay_composition_ref()
|
|
||||||
* if needed.
|
|
||||||
*
|
|
||||||
* Since: 0.11.x
|
|
||||||
*/
|
|
||||||
GstVideoOverlayComposition *
|
|
||||||
gst_video_buffer_get_overlay_composition (GstBuffer * buf)
|
|
||||||
{
|
|
||||||
GstVideoOverlayCompositionMeta *ometa;
|
|
||||||
|
|
||||||
ometa = gst_video_buffer_get_overlay_composition_meta (buf);
|
|
||||||
if (ometa)
|
|
||||||
return ometa->overlay;
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------ composition ------------------------------ */
|
/* ------------------------------ composition ------------------------------ */
|
||||||
|
@ -237,10 +237,37 @@ gboolean gst_video_overlay_composition_blend (GstVid
|
|||||||
|
|
||||||
/* attach/retrieve composition from buffers */
|
/* attach/retrieve composition from buffers */
|
||||||
|
|
||||||
void gst_video_buffer_set_overlay_composition (GstBuffer * buf,
|
#define GST_VIDEO_OVERLAY_COMPOSITION_META_API_TYPE \
|
||||||
|
(gst_video_overlay_composition_meta_api_get_type())
|
||||||
|
#define GST_VIDEO_OVERLAY_COMPOSITION_META_INFO \
|
||||||
|
(gst_video_overlay_composition_meta_get_info())
|
||||||
|
|
||||||
|
typedef struct _GstVideoOverlayCompositionMeta GstVideoOverlayCompositionMeta;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GstVideoOverlayCompositionMeta:
|
||||||
|
* @meta: parent #GstMeta
|
||||||
|
* @overlay: the attached #GstVideoOverlayComposition
|
||||||
|
*
|
||||||
|
* Extra buffer metadata describing image overlay data.
|
||||||
|
*/
|
||||||
|
struct _GstVideoOverlayCompositionMeta
|
||||||
|
{
|
||||||
|
GstMeta meta;
|
||||||
|
|
||||||
|
GstVideoOverlayComposition *overlay;
|
||||||
|
};
|
||||||
|
|
||||||
|
GType gst_video_overlay_composition_meta_api_get_type (void);
|
||||||
|
const GstMetaInfo *gst_video_overlay_composition_meta_get_info (void);
|
||||||
|
|
||||||
|
GstVideoOverlayCompositionMeta * gst_buffer_add_video_overlay_composition_meta (GstBuffer * buf,
|
||||||
GstVideoOverlayComposition * comp);
|
GstVideoOverlayComposition * comp);
|
||||||
|
|
||||||
GstVideoOverlayComposition * gst_video_buffer_get_overlay_composition (GstBuffer * buf);
|
#define gst_buffer_get_video_overlay_composition_meta(b) \
|
||||||
|
((GstVideoOverlayCompositionMeta*)gst_buffer_get_meta((b),GST_VIDEO_OVERLAY_COMPOSITION_META_API_TYPE))
|
||||||
|
#define gst_buffer_remove_video_overlay_composition_meta(b,m) \
|
||||||
|
gst_buffer_remove_meta((b),((GstMeta *) m))
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
@ -869,6 +869,7 @@ GST_START_TEST (test_overlay_composition)
|
|||||||
{
|
{
|
||||||
GstVideoOverlayComposition *comp1, *comp2;
|
GstVideoOverlayComposition *comp1, *comp2;
|
||||||
GstVideoOverlayRectangle *rect1, *rect2;
|
GstVideoOverlayRectangle *rect1, *rect2;
|
||||||
|
GstVideoOverlayCompositionMeta *ometa;
|
||||||
GstBuffer *pix1, *pix2, *buf;
|
GstBuffer *pix1, *pix2, *buf;
|
||||||
guint seq1, seq2;
|
guint seq1, seq2;
|
||||||
guint w, h, stride;
|
guint w, h, stride;
|
||||||
@ -986,26 +987,31 @@ GST_START_TEST (test_overlay_composition)
|
|||||||
|
|
||||||
/* test attaching and retrieving of compositions to/from buffers */
|
/* test attaching and retrieving of compositions to/from buffers */
|
||||||
buf = gst_buffer_new ();
|
buf = gst_buffer_new ();
|
||||||
fail_unless (gst_video_buffer_get_overlay_composition (buf) == NULL);
|
fail_unless (gst_buffer_get_video_overlay_composition_meta (buf) == NULL);
|
||||||
|
|
||||||
gst_buffer_ref (buf);
|
gst_buffer_ref (buf);
|
||||||
/* buffer now has refcount of 2, so its metadata is not writable.
|
/* buffer now has refcount of 2, so its metadata is not writable.
|
||||||
* only check this if we are not running in valgrind, as it leaks */
|
* only check this if we are not running in valgrind, as it leaks */
|
||||||
#ifdef HAVE_VALGRIND
|
#ifdef HAVE_VALGRIND
|
||||||
if (!RUNNING_ON_VALGRIND) {
|
if (!RUNNING_ON_VALGRIND) {
|
||||||
ASSERT_CRITICAL (gst_video_buffer_set_overlay_composition (buf, comp1));
|
ASSERT_CRITICAL (gst_buffer_add_video_overlay_composition_meta (buf,
|
||||||
|
comp1));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
gst_buffer_unref (buf);
|
gst_buffer_unref (buf);
|
||||||
gst_video_buffer_set_overlay_composition (buf, comp1);
|
gst_buffer_add_video_overlay_composition_meta (buf, comp1);
|
||||||
fail_unless (gst_video_buffer_get_overlay_composition (buf) == comp1);
|
ometa = gst_buffer_get_video_overlay_composition_meta (buf);
|
||||||
gst_video_buffer_set_overlay_composition (buf, comp2);
|
fail_unless (ometa != NULL);
|
||||||
fail_unless (gst_video_buffer_get_overlay_composition (buf) == comp2);
|
fail_unless (ometa->overlay == comp1);
|
||||||
gst_video_buffer_set_overlay_composition (buf, NULL);
|
fail_unless (gst_buffer_remove_video_overlay_composition_meta (buf, ometa));
|
||||||
fail_unless (gst_video_buffer_get_overlay_composition (buf) == NULL);
|
gst_buffer_add_video_overlay_composition_meta (buf, comp2);
|
||||||
|
ometa = gst_buffer_get_video_overlay_composition_meta (buf);
|
||||||
|
fail_unless (ometa->overlay == comp2);
|
||||||
|
fail_unless (gst_buffer_remove_video_overlay_composition_meta (buf, ometa));
|
||||||
|
fail_unless (gst_buffer_get_video_overlay_composition_meta (buf) == NULL);
|
||||||
|
|
||||||
/* make sure the buffer cleans up its composition ref when unreffed */
|
/* make sure the buffer cleans up its composition ref when unreffed */
|
||||||
gst_video_buffer_set_overlay_composition (buf, comp2);
|
gst_buffer_add_video_overlay_composition_meta (buf, comp2);
|
||||||
gst_buffer_unref (buf);
|
gst_buffer_unref (buf);
|
||||||
|
|
||||||
gst_video_overlay_composition_unref (comp2);
|
gst_video_overlay_composition_unref (comp2);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user