diff --git a/gst-libs/gst/video/video-overlay-composition.c b/gst-libs/gst/video/video-overlay-composition.c index f712d9d503..af43ff894c 100644 --- a/gst-libs/gst/video/video-overlay-composition.c +++ b/gst-libs/gst/video/video-overlay-composition.c @@ -190,32 +190,6 @@ gst_video_overlay_get_seqnum (void) 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 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; } -static GType +GType gst_video_overlay_composition_meta_api_get_type (void) { static volatile GType type = 0; @@ -266,7 +240,7 @@ gst_video_overlay_composition_meta_api_get_type (void) } /* video overlay composition metadata */ -static const GstMetaInfo * +const GstMetaInfo * gst_video_overlay_composition_meta_get_info (void) { 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; } -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 - * @comp: (allow-none): a #GstVideoOverlayComposition, or NULL to clear a - * previously-set composition + * @comp: (allow-none): a #GstVideoOverlayComposition * * Sets an overlay composition on a buffer. The buffer will obtain its own * 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 */ -void -gst_video_buffer_set_overlay_composition (GstBuffer * buf, +GstVideoOverlayCompositionMeta * +gst_buffer_add_video_overlay_composition_meta (GstBuffer * buf, GstVideoOverlayComposition * comp) { - /* FIXME MT safety ? */ - GstVideoOverlayCompositionMeta *ometa; - ometa = gst_video_buffer_get_overlay_composition_meta (buf); - if (ometa) { - gst_mini_object_replace ((GstMiniObject **) & ometa->overlay, - (GstMiniObject *) comp); - } else { - ometa = (GstVideoOverlayCompositionMeta *) - gst_buffer_add_meta (buf, GST_VIDEO_OVERLAY_COMPOSITION_META_INFO, - NULL); - /* buffer might not be writable or so */ - if (ometa) - ometa->overlay = gst_video_overlay_composition_ref (comp); - } -} + g_return_val_if_fail (gst_buffer_is_writable (buf), NULL); -/** - * 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 = (GstVideoOverlayCompositionMeta *) + gst_buffer_add_meta (buf, GST_VIDEO_OVERLAY_COMPOSITION_META_INFO, NULL); - ometa = gst_video_buffer_get_overlay_composition_meta (buf); - if (ometa) - return ometa->overlay; - return NULL; + ometa->overlay = gst_video_overlay_composition_ref (comp); + + return ometa; } /* ------------------------------ composition ------------------------------ */ diff --git a/gst-libs/gst/video/video-overlay-composition.h b/gst-libs/gst/video/video-overlay-composition.h index 8238b718b9..676c8f1282 100644 --- a/gst-libs/gst/video/video-overlay-composition.h +++ b/gst-libs/gst/video/video-overlay-composition.h @@ -237,10 +237,37 @@ gboolean gst_video_overlay_composition_blend (GstVid /* attach/retrieve composition from buffers */ -void gst_video_buffer_set_overlay_composition (GstBuffer * buf, - GstVideoOverlayComposition * comp); +#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()) -GstVideoOverlayComposition * gst_video_buffer_get_overlay_composition (GstBuffer * buf); +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); + +#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 diff --git a/tests/check/libs/video.c b/tests/check/libs/video.c index b0434b59bf..7bbc3e3b18 100644 --- a/tests/check/libs/video.c +++ b/tests/check/libs/video.c @@ -869,6 +869,7 @@ GST_START_TEST (test_overlay_composition) { GstVideoOverlayComposition *comp1, *comp2; GstVideoOverlayRectangle *rect1, *rect2; + GstVideoOverlayCompositionMeta *ometa; GstBuffer *pix1, *pix2, *buf; guint seq1, seq2; guint w, h, stride; @@ -986,26 +987,31 @@ GST_START_TEST (test_overlay_composition) /* test attaching and retrieving of compositions to/from buffers */ 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); /* 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 */ #ifdef HAVE_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 gst_buffer_unref (buf); - gst_video_buffer_set_overlay_composition (buf, comp1); - fail_unless (gst_video_buffer_get_overlay_composition (buf) == comp1); - gst_video_buffer_set_overlay_composition (buf, comp2); - fail_unless (gst_video_buffer_get_overlay_composition (buf) == comp2); - gst_video_buffer_set_overlay_composition (buf, NULL); - fail_unless (gst_video_buffer_get_overlay_composition (buf) == NULL); + gst_buffer_add_video_overlay_composition_meta (buf, comp1); + ometa = gst_buffer_get_video_overlay_composition_meta (buf); + fail_unless (ometa != NULL); + fail_unless (ometa->overlay == comp1); + fail_unless (gst_buffer_remove_video_overlay_composition_meta (buf, ometa)); + 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 */ - gst_video_buffer_set_overlay_composition (buf, comp2); + gst_buffer_add_video_overlay_composition_meta (buf, comp2); gst_buffer_unref (buf); gst_video_overlay_composition_unref (comp2);