2 * Copyright (C) <2011> Wim Taymans <wim.taymans@gmail.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 #include "gstvideometa.h"
25 * SECTION:gstvideometa
26 * @title: GstMeta for video
27 * @short_description: Video related GstMeta
31 #ifndef GST_DISABLE_GST_DEBUG
32 #define GST_CAT_DEFAULT ensure_debug_category()
33 static GstDebugCategory *
34 ensure_debug_category (void)
36 static gsize cat_gonce = 0;
38 if (g_once_init_enter (&cat_gonce)) {
41 cat_done = (gsize) _gst_debug_category_new ("videometa", 0, "videometa");
43 g_once_init_leave (&cat_gonce, cat_done);
46 return (GstDebugCategory *) cat_gonce;
49 #define ensure_debug_category() /* NOOP */
50 #endif /* GST_DISABLE_GST_DEBUG */
53 gst_video_meta_init (GstMeta * meta, gpointer params, GstBuffer * buffer)
55 GstVideoMeta *emeta = (GstVideoMeta *) meta;
58 emeta->flags = GST_VIDEO_FRAME_FLAG_NONE;
59 emeta->format = GST_VIDEO_FORMAT_UNKNOWN;
61 emeta->width = emeta->height = emeta->n_planes = 0;
62 memset (emeta->offset, 0, sizeof (emeta->offset));
63 memset (emeta->stride, 0, sizeof (emeta->stride));
71 gst_video_meta_transform (GstBuffer * dest, GstMeta * meta,
72 GstBuffer * buffer, GQuark type, gpointer data)
74 GstVideoMeta *dmeta, *smeta;
77 smeta = (GstVideoMeta *) meta;
79 if (GST_META_TRANSFORM_IS_COPY (type)) {
80 GstMetaTransformCopy *copy = data;
83 /* only copy if the complete data is copied as well */
85 (GstVideoMeta *) gst_buffer_add_meta (dest, GST_VIDEO_META_INFO,
93 GST_DEBUG ("copy video metadata");
94 dmeta->flags = smeta->flags;
95 dmeta->format = smeta->format;
96 dmeta->id = smeta->id;
97 dmeta->width = smeta->width;
98 dmeta->height = smeta->height;
100 dmeta->n_planes = smeta->n_planes;
101 for (i = 0; i < dmeta->n_planes; i++) {
102 dmeta->offset[i] = smeta->offset[i];
103 dmeta->stride[i] = smeta->stride[i];
105 dmeta->map = smeta->map;
106 dmeta->unmap = smeta->unmap;
109 /* return FALSE, if transform type is not supported */
116 gst_video_meta_api_get_type (void)
118 static volatile GType type = 0;
119 static const gchar *tags[] =
120 { GST_META_TAG_VIDEO_STR, GST_META_TAG_MEMORY_STR,
121 GST_META_TAG_VIDEO_COLORSPACE_STR,
122 GST_META_TAG_VIDEO_SIZE_STR, NULL
125 if (g_once_init_enter (&type)) {
126 GType _type = gst_meta_api_type_register ("GstVideoMetaAPI", tags);
127 g_once_init_leave (&type, _type);
134 gst_video_meta_get_info (void)
136 static const GstMetaInfo *video_meta_info = NULL;
138 if (g_once_init_enter ((GstMetaInfo **) & video_meta_info)) {
139 const GstMetaInfo *meta =
140 gst_meta_register (GST_VIDEO_META_API_TYPE, "GstVideoMeta",
141 sizeof (GstVideoMeta), (GstMetaInitFunction) gst_video_meta_init,
142 (GstMetaFreeFunction) NULL, gst_video_meta_transform);
143 g_once_init_leave ((GstMetaInfo **) & video_meta_info,
144 (GstMetaInfo *) meta);
146 return video_meta_info;
150 * gst_buffer_get_video_meta:
151 * @buffer: a #GstBuffer
153 * Find the #GstVideoMeta on @buffer with the lowest @id.
155 * Buffers can contain multiple #GstVideoMeta metadata items when dealing with
158 * Returns: (transfer none): the #GstVideoMeta with lowest id (usually 0) or %NULL when there
159 * is no such metadata on @buffer.
162 gst_buffer_get_video_meta (GstBuffer * buffer)
164 gpointer state = NULL;
165 GstVideoMeta *out = NULL;
167 const GstMetaInfo *info = GST_VIDEO_META_INFO;
169 while ((meta = gst_buffer_iterate_meta (buffer, &state))) {
170 if (meta->info->api == info->api) {
171 GstVideoMeta *vmeta = (GstVideoMeta *) meta;
173 return vmeta; /* Early out for id 0 */
174 if (out == NULL || vmeta->id < out->id)
182 * gst_buffer_get_video_meta_id:
183 * @buffer: a #GstBuffer
186 * Find the #GstVideoMeta on @buffer with the given @id.
188 * Buffers can contain multiple #GstVideoMeta metadata items when dealing with
191 * Returns: (transfer none): the #GstVideoMeta with @id or %NULL when there is no such metadata
195 gst_buffer_get_video_meta_id (GstBuffer * buffer, gint id)
197 gpointer state = NULL;
199 const GstMetaInfo *info = GST_VIDEO_META_INFO;
201 while ((meta = gst_buffer_iterate_meta (buffer, &state))) {
202 if (meta->info->api == info->api) {
203 GstVideoMeta *vmeta = (GstVideoMeta *) meta;
212 default_map (GstVideoMeta * meta, guint plane, GstMapInfo * info,
213 gpointer * data, gint * stride, GstMapFlags flags)
217 GstBuffer *buffer = meta->buffer;
219 offset = meta->offset[plane];
221 /* find the memory block for this plane, this is the memory block containing
222 * the plane offset. FIXME use plane size */
223 if (!gst_buffer_find_memory (buffer, offset, 1, &idx, &length, &skip))
226 if (!gst_buffer_map_range (buffer, idx, length, info, flags))
229 *stride = meta->stride[plane];
230 *data = (guint8 *) info->data + skip;
237 GST_DEBUG ("plane %u, no memory at offset %" G_GSIZE_FORMAT, plane, offset);
242 GST_DEBUG ("cannot map memory range %u-%u", idx, length);
248 default_unmap (GstVideoMeta * meta, guint plane, GstMapInfo * info)
250 GstBuffer *buffer = meta->buffer;
252 gst_buffer_unmap (buffer, info);
258 * gst_buffer_add_video_meta:
259 * @buffer: a #GstBuffer
260 * @flags: #GstVideoFrameFlags
261 * @format: a #GstVideoFormat
263 * @height: the height
265 * Attaches GstVideoMeta metadata to @buffer with the given parameters and the
266 * default offsets and strides for @format and @width x @height.
268 * This function calculates the default offsets and strides and then calls
269 * gst_buffer_add_video_meta_full() with them.
271 * Returns: (transfer none): the #GstVideoMeta on @buffer.
274 gst_buffer_add_video_meta (GstBuffer * buffer,
275 GstVideoFrameFlags flags, GstVideoFormat format, guint width, guint height)
280 if (!gst_video_info_set_format (&info, format, width, height))
284 gst_buffer_add_video_meta_full (buffer, flags, format, width,
285 height, info.finfo->n_planes, info.offset, info.stride);
291 * gst_buffer_add_video_meta_full:
292 * @buffer: a #GstBuffer
293 * @flags: #GstVideoFrameFlags
294 * @format: a #GstVideoFormat
296 * @height: the height
297 * @n_planes: number of planes
298 * @offset: offset of each plane
299 * @stride: stride of each plane
301 * Attaches GstVideoMeta metadata to @buffer with the given parameters.
303 * Returns: (transfer none): the #GstVideoMeta on @buffer.
306 gst_buffer_add_video_meta_full (GstBuffer * buffer,
307 GstVideoFrameFlags flags, GstVideoFormat format, guint width,
308 guint height, guint n_planes, gsize offset[GST_VIDEO_MAX_PLANES],
309 gint stride[GST_VIDEO_MAX_PLANES])
315 (GstVideoMeta *) gst_buffer_add_meta (buffer, GST_VIDEO_META_INFO, NULL);
321 meta->format = format;
324 meta->height = height;
325 meta->buffer = buffer;
327 meta->n_planes = n_planes;
328 for (i = 0; i < n_planes; i++) {
329 meta->offset[i] = offset[i];
330 meta->stride[i] = stride[i];
331 GST_LOG ("plane %d, offset %" G_GSIZE_FORMAT ", stride %d", i, offset[i],
334 meta->map = default_map;
335 meta->unmap = default_unmap;
341 * gst_video_meta_map:
342 * @meta: a #GstVideoMeta
344 * @info: a #GstMapInfo
345 * @data: (out): the data of @plane
346 * @stride: (out): the stride of @plane
347 * @flags: @GstMapFlags
349 * Map the video plane with index @plane in @meta and return a pointer to the
350 * first byte of the plane and the stride of the plane.
352 * Returns: TRUE if the map operation was successful.
355 gst_video_meta_map (GstVideoMeta * meta, guint plane, GstMapInfo * info,
356 gpointer * data, gint * stride, GstMapFlags flags)
358 g_return_val_if_fail (meta != NULL, FALSE);
359 g_return_val_if_fail (meta->map != NULL, FALSE);
360 g_return_val_if_fail (plane < meta->n_planes, FALSE);
361 g_return_val_if_fail (info != NULL, FALSE);
362 g_return_val_if_fail (data != NULL, FALSE);
363 g_return_val_if_fail (stride != NULL, FALSE);
364 g_return_val_if_fail (meta->buffer != NULL, FALSE);
365 g_return_val_if_fail (!(flags & GST_MAP_WRITE)
366 || gst_buffer_is_writable (meta->buffer), FALSE);
368 return meta->map (meta, plane, info, data, stride, flags);
372 * gst_video_meta_unmap:
373 * @meta: a #GstVideoMeta
375 * @info: a #GstMapInfo
377 * Unmap a previously mapped plane with gst_video_meta_map().
379 * Returns: TRUE if the memory was successfully unmapped.
382 gst_video_meta_unmap (GstVideoMeta * meta, guint plane, GstMapInfo * info)
384 g_return_val_if_fail (meta != NULL, FALSE);
385 g_return_val_if_fail (meta->unmap != NULL, FALSE);
386 g_return_val_if_fail (plane < meta->n_planes, FALSE);
387 g_return_val_if_fail (info != NULL, FALSE);
389 return meta->unmap (meta, plane, info);
393 gst_video_crop_meta_transform (GstBuffer * dest, GstMeta * meta,
394 GstBuffer * buffer, GQuark type, gpointer data)
396 GstVideoCropMeta *dmeta, *smeta;
398 if (GST_META_TRANSFORM_IS_COPY (type)) {
399 smeta = (GstVideoCropMeta *) meta;
400 dmeta = gst_buffer_add_video_crop_meta (dest);
404 GST_DEBUG ("copy crop metadata");
407 dmeta->width = smeta->width;
408 dmeta->height = smeta->height;
409 } else if (GST_VIDEO_META_TRANSFORM_IS_SCALE (type)) {
410 GstVideoMetaTransform *trans = data;
413 smeta = (GstVideoCropMeta *) meta;
414 dmeta = gst_buffer_add_video_crop_meta (dest);
418 ow = GST_VIDEO_INFO_WIDTH (trans->in_info);
419 nw = GST_VIDEO_INFO_WIDTH (trans->out_info);
420 oh = GST_VIDEO_INFO_HEIGHT (trans->in_info);
421 nh = GST_VIDEO_INFO_HEIGHT (trans->out_info);
423 GST_DEBUG ("scaling crop metadata %dx%d -> %dx%d", ow, oh, nw, nh);
424 dmeta->x = (smeta->x * nw) / ow;
425 dmeta->y = (smeta->y * nh) / oh;
426 dmeta->width = (smeta->width * nw) / ow;
427 dmeta->height = (smeta->height * nh) / oh;
428 GST_DEBUG ("crop offset %dx%d -> %dx%d", smeta->x, smeta->y, dmeta->x,
430 GST_DEBUG ("crop size %dx%d -> %dx%d", smeta->width, smeta->height,
431 dmeta->width, dmeta->height);
433 /* return FALSE, if transform type is not supported */
440 gst_video_crop_meta_api_get_type (void)
442 static volatile GType type = 0;
443 static const gchar *tags[] =
444 { GST_META_TAG_VIDEO_STR, GST_META_TAG_VIDEO_SIZE_STR,
445 GST_META_TAG_VIDEO_ORIENTATION_STR, NULL
448 if (g_once_init_enter (&type)) {
449 GType _type = gst_meta_api_type_register ("GstVideoCropMetaAPI", tags);
450 g_once_init_leave (&type, _type);
456 gst_video_crop_meta_init (GstMeta * meta, gpointer params, GstBuffer * buffer)
458 GstVideoCropMeta *emeta = (GstVideoCropMeta *) meta;
459 emeta->x = emeta->y = emeta->width = emeta->height = 0;
465 gst_video_crop_meta_get_info (void)
467 static const GstMetaInfo *video_crop_meta_info = NULL;
469 if (g_once_init_enter ((GstMetaInfo **) & video_crop_meta_info)) {
470 const GstMetaInfo *meta =
471 gst_meta_register (GST_VIDEO_CROP_META_API_TYPE, "GstVideoCropMeta",
472 sizeof (GstVideoCropMeta),
473 (GstMetaInitFunction) gst_video_crop_meta_init,
474 (GstMetaFreeFunction) NULL, gst_video_crop_meta_transform);
475 g_once_init_leave ((GstMetaInfo **) & video_crop_meta_info,
476 (GstMetaInfo *) meta);
478 return video_crop_meta_info;
482 * gst_video_meta_transform_scale_get_quark:
484 * Get the #GQuark for the "gst-video-scale" metadata transform operation.
489 gst_video_meta_transform_scale_get_quark (void)
491 static GQuark _value = 0;
494 _value = g_quark_from_static_string ("gst-video-scale");
501 gst_video_gl_texture_upload_meta_api_get_type (void)
503 static volatile GType type = 0;
504 static const gchar *tags[] =
505 { GST_META_TAG_VIDEO_STR, GST_META_TAG_MEMORY_STR, NULL };
507 if (g_once_init_enter (&type)) {
509 gst_meta_api_type_register ("GstVideoGLTextureUploadMetaAPI", tags);
510 g_once_init_leave (&type, _type);
516 gst_video_gl_texture_upload_meta_init (GstMeta * meta, gpointer params,
519 GstVideoGLTextureUploadMeta *vmeta = (GstVideoGLTextureUploadMeta *) meta;
521 vmeta->texture_orientation =
522 GST_VIDEO_GL_TEXTURE_ORIENTATION_X_NORMAL_Y_NORMAL;
523 vmeta->n_textures = 0;
524 memset (vmeta->texture_type, 0, sizeof (vmeta->texture_type));
525 vmeta->buffer = NULL;
526 vmeta->upload = NULL;
527 vmeta->user_data = NULL;
528 vmeta->user_data_copy = NULL;
529 vmeta->user_data_free = NULL;
535 gst_video_gl_texture_upload_meta_free (GstMeta * meta, GstBuffer * buffer)
537 GstVideoGLTextureUploadMeta *vmeta = (GstVideoGLTextureUploadMeta *) meta;
539 if (vmeta->user_data_free)
540 vmeta->user_data_free (vmeta->user_data);
544 gst_video_gl_texture_upload_meta_transform (GstBuffer * dest, GstMeta * meta,
545 GstBuffer * buffer, GQuark type, gpointer data)
547 GstVideoGLTextureUploadMeta *dmeta, *smeta;
549 smeta = (GstVideoGLTextureUploadMeta *) meta;
551 if (GST_META_TRANSFORM_IS_COPY (type)) {
552 GstMetaTransformCopy *copy = data;
555 /* only copy if the complete data is copied as well */
557 (GstVideoGLTextureUploadMeta *) gst_buffer_add_meta (dest,
558 GST_VIDEO_GL_TEXTURE_UPLOAD_META_INFO, NULL);
563 dmeta->texture_orientation = smeta->texture_orientation;
564 dmeta->n_textures = smeta->n_textures;
565 memcpy (dmeta->texture_type, smeta->texture_type,
566 sizeof (smeta->texture_type[0]) * 4);
567 dmeta->buffer = dest;
568 dmeta->upload = smeta->upload;
569 dmeta->user_data = smeta->user_data;
570 dmeta->user_data_copy = smeta->user_data_copy;
571 dmeta->user_data_free = smeta->user_data_free;
572 if (dmeta->user_data_copy)
573 dmeta->user_data = dmeta->user_data_copy (dmeta->user_data);
576 /* return FALSE, if transform type is not supported */
583 gst_video_gl_texture_upload_meta_get_info (void)
585 static const GstMetaInfo *info = NULL;
587 if (g_once_init_enter ((GstMetaInfo **) & info)) {
588 const GstMetaInfo *meta =
589 gst_meta_register (GST_VIDEO_GL_TEXTURE_UPLOAD_META_API_TYPE,
590 "GstVideoGLTextureUploadMeta",
591 sizeof (GstVideoGLTextureUploadMeta),
592 gst_video_gl_texture_upload_meta_init,
593 gst_video_gl_texture_upload_meta_free,
594 gst_video_gl_texture_upload_meta_transform);
595 g_once_init_leave ((GstMetaInfo **) & info, (GstMetaInfo *) meta);
601 * gst_buffer_add_video_gl_texture_upload_meta:
602 * @buffer: a #GstBuffer
603 * @texture_orientation: the #GstVideoGLTextureOrientation
604 * @n_textures: the number of textures
605 * @texture_type: array of #GstVideoGLTextureType
606 * @upload: (scope call): the function to upload the buffer to a specific texture ID
607 * @user_data: user data for the implementor of @upload
608 * @user_data_copy: (scope call): function to copy @user_data
609 * @user_data_free: (scope call): function to free @user_data
611 * Attaches GstVideoGLTextureUploadMeta metadata to @buffer with the given
614 * Returns: (transfer none): the #GstVideoGLTextureUploadMeta on @buffer.
616 GstVideoGLTextureUploadMeta *
617 gst_buffer_add_video_gl_texture_upload_meta (GstBuffer * buffer,
618 GstVideoGLTextureOrientation texture_orientation, guint n_textures,
619 GstVideoGLTextureType texture_type[4], GstVideoGLTextureUpload upload,
620 gpointer user_data, GBoxedCopyFunc user_data_copy,
621 GBoxedFreeFunc user_data_free)
623 GstVideoGLTextureUploadMeta *meta;
625 g_return_val_if_fail (buffer != NULL, NULL);
626 g_return_val_if_fail (upload != NULL, NULL);
627 g_return_val_if_fail (n_textures > 0 && n_textures < 5, NULL);
630 (GstVideoGLTextureUploadMeta *) gst_buffer_add_meta (buffer,
631 GST_VIDEO_GL_TEXTURE_UPLOAD_META_INFO, NULL);
636 meta->texture_orientation = texture_orientation;
637 meta->n_textures = n_textures;
638 memcpy (meta->texture_type, texture_type, sizeof (texture_type[0]) * 4);
639 meta->buffer = buffer;
640 meta->upload = upload;
641 meta->user_data = user_data;
642 meta->user_data_copy = user_data_copy;
643 meta->user_data_free = user_data_free;
649 * gst_video_gl_texture_upload_meta_upload:
650 * @meta: a #GstVideoGLTextureUploadMeta
651 * @texture_id: the texture IDs to upload to
653 * Uploads the buffer which owns the meta to a specific texture ID.
655 * Returns: %TRUE if uploading succeeded, %FALSE otherwise.
658 gst_video_gl_texture_upload_meta_upload (GstVideoGLTextureUploadMeta * meta,
661 g_return_val_if_fail (meta != NULL, FALSE);
663 return meta->upload (meta, texture_id);
666 /* Region of Interest Meta implementation *******************************************/
669 gst_video_region_of_interest_meta_api_get_type (void)
671 static volatile GType type;
672 static const gchar *tags[] =
673 { GST_META_TAG_VIDEO_STR, GST_META_TAG_VIDEO_ORIENTATION_STR,
674 GST_META_TAG_VIDEO_SIZE_STR, NULL
677 if (g_once_init_enter (&type)) {
679 gst_meta_api_type_register ("GstVideoRegionOfInterestMetaAPI", tags);
680 GST_INFO ("registering");
681 g_once_init_leave (&type, _type);
688 gst_video_region_of_interest_meta_transform (GstBuffer * dest, GstMeta * meta,
689 GstBuffer * buffer, GQuark type, gpointer data)
691 GstVideoRegionOfInterestMeta *dmeta, *smeta;
693 if (GST_META_TRANSFORM_IS_COPY (type)) {
694 smeta = (GstVideoRegionOfInterestMeta *) meta;
696 GST_DEBUG ("copy region of interest metadata");
698 gst_buffer_add_video_region_of_interest_meta_id (dest,
699 smeta->roi_type, smeta->x, smeta->y, smeta->w, smeta->h);
703 dmeta->id = smeta->id;
704 dmeta->parent_id = smeta->parent_id;
705 dmeta->params = g_list_copy_deep (smeta->params,
706 (GCopyFunc) gst_structure_copy, NULL);
707 } else if (GST_VIDEO_META_TRANSFORM_IS_SCALE (type)) {
708 GstVideoMetaTransform *trans = data;
710 ow = GST_VIDEO_INFO_WIDTH (trans->in_info);
711 nw = GST_VIDEO_INFO_WIDTH (trans->out_info);
712 oh = GST_VIDEO_INFO_HEIGHT (trans->in_info);
713 nh = GST_VIDEO_INFO_HEIGHT (trans->out_info);
714 GST_DEBUG ("scaling region of interest metadata %dx%d -> %dx%d", ow, oh, nw,
717 smeta = (GstVideoRegionOfInterestMeta *) meta;
719 gst_buffer_add_video_region_of_interest_meta_id (dest,
720 smeta->roi_type, (smeta->x * nw) / ow, (smeta->y * nh) / oh,
721 (smeta->w * nw) / ow, (smeta->h * nh) / oh);
725 dmeta->id = smeta->id;
726 dmeta->parent_id = smeta->parent_id;
728 GST_DEBUG ("region of interest (id:%d, parent id:%d) offset %dx%d -> %dx%d",
729 smeta->id, smeta->parent_id, smeta->x, smeta->y, dmeta->x, dmeta->y);
730 GST_DEBUG ("region of interest size %dx%d -> %dx%d", smeta->w, smeta->h,
733 /* return FALSE, if transform type is not supported */
740 gst_video_region_of_interest_meta_init (GstMeta * meta, gpointer params,
743 GstVideoRegionOfInterestMeta *emeta = (GstVideoRegionOfInterestMeta *) meta;
746 emeta->parent_id = 0;
747 emeta->x = emeta->y = emeta->w = emeta->h = 0;
748 emeta->params = NULL;
754 gst_video_region_of_interest_meta_free (GstMeta * meta, GstBuffer * buffer)
756 GstVideoRegionOfInterestMeta *emeta = (GstVideoRegionOfInterestMeta *) meta;
758 g_list_free_full (emeta->params, (GDestroyNotify) gst_structure_free);
762 gst_video_region_of_interest_meta_get_info (void)
764 static const GstMetaInfo *meta_info = NULL;
766 if (g_once_init_enter ((GstMetaInfo **) & meta_info)) {
767 const GstMetaInfo *mi =
768 gst_meta_register (GST_VIDEO_REGION_OF_INTEREST_META_API_TYPE,
769 "GstVideoRegionOfInterestMeta",
770 sizeof (GstVideoRegionOfInterestMeta),
771 gst_video_region_of_interest_meta_init,
772 gst_video_region_of_interest_meta_free,
773 gst_video_region_of_interest_meta_transform);
774 g_once_init_leave ((GstMetaInfo **) & meta_info, (GstMetaInfo *) mi);
780 * gst_buffer_get_video_region_of_interest_meta_id:
781 * @buffer: a #GstBuffer
784 * Find the #GstVideoRegionOfInterestMeta on @buffer with the given @id.
786 * Buffers can contain multiple #GstVideoRegionOfInterestMeta metadata items if
787 * multiple regions of interests are marked on a frame.
789 * Returns: (transfer none): the #GstVideoRegionOfInterestMeta with @id or %NULL when there is
790 * no such metadata on @buffer.
792 GstVideoRegionOfInterestMeta *
793 gst_buffer_get_video_region_of_interest_meta_id (GstBuffer * buffer, gint id)
795 gpointer state = NULL;
797 const GstMetaInfo *info = GST_VIDEO_REGION_OF_INTEREST_META_INFO;
799 while ((meta = gst_buffer_iterate_meta (buffer, &state))) {
800 if (meta->info->api == info->api) {
801 GstVideoRegionOfInterestMeta *vmeta =
802 (GstVideoRegionOfInterestMeta *) meta;
811 * gst_buffer_add_video_region_of_interest_meta:
812 * @buffer: a #GstBuffer
813 * @roi_type: Type of the region of interest (e.g. "face")
819 * Attaches #GstVideoRegionOfInterestMeta metadata to @buffer with the given
822 * Returns: (transfer none): the #GstVideoRegionOfInterestMeta on @buffer.
824 GstVideoRegionOfInterestMeta *
825 gst_buffer_add_video_region_of_interest_meta (GstBuffer * buffer,
826 const gchar * roi_type, guint x, guint y, guint w, guint h)
828 return gst_buffer_add_video_region_of_interest_meta_id (buffer,
829 g_quark_from_string (roi_type), x, y, w, h);
833 * gst_buffer_add_video_region_of_interest_meta_id:
834 * @buffer: a #GstBuffer
835 * @roi_type: Type of the region of interest (e.g. "face")
841 * Attaches #GstVideoRegionOfInterestMeta metadata to @buffer with the given
844 * Returns: (transfer none): the #GstVideoRegionOfInterestMeta on @buffer.
846 GstVideoRegionOfInterestMeta *
847 gst_buffer_add_video_region_of_interest_meta_id (GstBuffer * buffer,
848 GQuark roi_type, guint x, guint y, guint w, guint h)
850 GstVideoRegionOfInterestMeta *meta;
852 g_return_val_if_fail (GST_IS_BUFFER (buffer), NULL);
854 meta = (GstVideoRegionOfInterestMeta *) gst_buffer_add_meta (buffer,
855 GST_VIDEO_REGION_OF_INTEREST_META_INFO, NULL);
856 meta->roi_type = roi_type;
866 * gst_video_region_of_interest_meta_add_param:
867 * @meta: a #GstVideoRegionOfInterestMeta
868 * @s: (transfer full): a #GstStructure
870 * Attach element-specific parameters to @meta meant to be used by downstream
871 * elements which may handle this ROI.
872 * The name of @s is used to identify the element these parameters are meant for.
874 * This is typically used to tell encoders how they should encode this specific region.
875 * For example, a structure named "roi/x264enc" could be used to give the
876 * QP offsets this encoder should use when encoding the region described in @meta.
877 * Multiple parameters can be defined for the same meta so different encoders
878 * can be supported by cross platform applications).
883 gst_video_region_of_interest_meta_add_param (GstVideoRegionOfInterestMeta *
884 meta, GstStructure * s)
886 g_return_if_fail (meta);
887 g_return_if_fail (s);
889 meta->params = g_list_append (meta->params, s);
893 * gst_video_region_of_interest_meta_get_param:
894 * @meta: a #GstVideoRegionOfInterestMeta
897 * Retrieve the parameter for @meta having @name as structure name,
898 * or %NULL if there is none.
900 * Returns: (transfer none) (nullable): a #GstStructure
903 * See also: gst_video_region_of_interest_meta_add_param()
906 gst_video_region_of_interest_meta_get_param (GstVideoRegionOfInterestMeta *
907 meta, const gchar * name)
911 g_return_val_if_fail (meta, NULL);
912 g_return_val_if_fail (name, NULL);
914 for (l = meta->params; l; l = g_list_next (l)) {
915 GstStructure *s = l->data;
917 if (gst_structure_has_name (s, name))
924 /* Time Code Meta implementation *******************************************/
927 gst_video_time_code_meta_api_get_type (void)
929 static volatile GType type;
931 if (g_once_init_enter (&type)) {
932 static const gchar *tags[] = { NULL };
933 GType _type = gst_meta_api_type_register ("GstVideoTimeCodeMetaAPI", tags);
934 GST_INFO ("registering");
935 g_once_init_leave (&type, _type);
942 gst_video_time_code_meta_transform (GstBuffer * dest, GstMeta * meta,
943 GstBuffer * buffer, GQuark type, gpointer data)
945 GstVideoTimeCodeMeta *dmeta, *smeta;
947 if (GST_META_TRANSFORM_IS_COPY (type)) {
948 smeta = (GstVideoTimeCodeMeta *) meta;
950 GST_DEBUG ("copy time code metadata");
952 gst_buffer_add_video_time_code_meta_full (dest, smeta->tc.config.fps_n,
953 smeta->tc.config.fps_d, smeta->tc.config.latest_daily_jam,
954 smeta->tc.config.flags, smeta->tc.hours, smeta->tc.minutes,
955 smeta->tc.seconds, smeta->tc.frames, smeta->tc.field_count);
959 /* return FALSE, if transform type is not supported */
966 gst_video_time_code_meta_init (GstMeta * meta, gpointer params,
969 GstVideoTimeCodeMeta *emeta = (GstVideoTimeCodeMeta *) meta;
970 memset (&emeta->tc, 0, sizeof (emeta->tc));
971 gst_video_time_code_clear (&emeta->tc);
977 gst_video_time_code_meta_free (GstMeta * meta, GstBuffer * buffer)
979 GstVideoTimeCodeMeta *emeta = (GstVideoTimeCodeMeta *) meta;
981 gst_video_time_code_clear (&emeta->tc);
985 gst_video_time_code_meta_get_info (void)
987 static const GstMetaInfo *meta_info = NULL;
989 if (g_once_init_enter ((GstMetaInfo **) & meta_info)) {
990 const GstMetaInfo *mi =
991 gst_meta_register (GST_VIDEO_TIME_CODE_META_API_TYPE,
992 "GstVideoTimeCodeMeta",
993 sizeof (GstVideoTimeCodeMeta),
994 gst_video_time_code_meta_init,
995 gst_video_time_code_meta_free,
996 gst_video_time_code_meta_transform);
997 g_once_init_leave ((GstMetaInfo **) & meta_info, (GstMetaInfo *) mi);
1003 * gst_buffer_add_video_time_code_meta:
1004 * @buffer: a #GstBuffer
1005 * @tc: a #GstVideoTimeCode
1007 * Attaches #GstVideoTimeCodeMeta metadata to @buffer with the given
1010 * Returns: (transfer none): the #GstVideoTimeCodeMeta on @buffer.
1014 GstVideoTimeCodeMeta *
1015 gst_buffer_add_video_time_code_meta (GstBuffer * buffer, GstVideoTimeCode * tc)
1017 g_return_val_if_fail (gst_video_time_code_is_valid (tc), NULL);
1018 return gst_buffer_add_video_time_code_meta_full (buffer, tc->config.fps_n,
1019 tc->config.fps_d, tc->config.latest_daily_jam, tc->config.flags,
1020 tc->hours, tc->minutes, tc->seconds, tc->frames, tc->field_count);
1024 * gst_buffer_add_video_time_code_meta_full:
1025 * @buffer: a #GstBuffer
1026 * @fps_n: framerate numerator
1027 * @fps_d: framerate denominator
1028 * @latest_daily_jam: a #GDateTime for the latest daily jam
1029 * @flags: a #GstVideoTimeCodeFlags
1030 * @hours: hours since the daily jam
1031 * @minutes: minutes since the daily jam
1032 * @seconds: seconds since the daily jam
1033 * @frames: frames since the daily jam
1034 * @field_count: fields since the daily jam
1036 * Attaches #GstVideoTimeCodeMeta metadata to @buffer with the given
1039 * Returns: (transfer none): the #GstVideoTimeCodeMeta on @buffer.
1043 GstVideoTimeCodeMeta *
1044 gst_buffer_add_video_time_code_meta_full (GstBuffer * buffer, guint fps_n,
1045 guint fps_d, GDateTime * latest_daily_jam, GstVideoTimeCodeFlags flags,
1046 guint hours, guint minutes, guint seconds, guint frames, guint field_count)
1048 GstVideoTimeCodeMeta *meta;
1050 g_return_val_if_fail (GST_IS_BUFFER (buffer), NULL);
1052 meta = (GstVideoTimeCodeMeta *) gst_buffer_add_meta (buffer,
1053 GST_VIDEO_TIME_CODE_META_INFO, NULL);
1054 g_return_val_if_fail (meta != NULL, NULL);
1056 gst_video_time_code_init (&meta->tc, fps_n, fps_d, latest_daily_jam, flags,
1057 hours, minutes, seconds, frames, field_count);
1059 g_return_val_if_fail (gst_video_time_code_is_valid (&meta->tc), NULL);