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"
24 #ifndef GST_DISABLE_GST_DEBUG
25 #define GST_CAT_DEFAULT ensure_debug_category()
26 static GstDebugCategory *
27 ensure_debug_category (void)
29 static gsize cat_gonce = 0;
31 if (g_once_init_enter (&cat_gonce)) {
34 cat_done = (gsize) _gst_debug_category_new ("videometa", 0, "videometa");
36 g_once_init_leave (&cat_gonce, cat_done);
39 return (GstDebugCategory *) cat_gonce;
42 #define ensure_debug_category() /* NOOP */
43 #endif /* GST_DISABLE_GST_DEBUG */
46 gst_video_meta_init (GstMeta * meta, gpointer params, GstBuffer * buffer)
48 GstVideoMeta *emeta = (GstVideoMeta *) meta;
51 emeta->flags = GST_VIDEO_FRAME_FLAG_NONE;
52 emeta->format = GST_VIDEO_FORMAT_UNKNOWN;
54 emeta->width = emeta->height = emeta->n_planes = 0;
55 memset (emeta->offset, 0, sizeof (emeta->offset));
56 memset (emeta->stride, 0, sizeof (emeta->stride));
64 gst_video_meta_transform (GstBuffer * dest, GstMeta * meta,
65 GstBuffer * buffer, GQuark type, gpointer data)
67 GstVideoMeta *dmeta, *smeta;
70 smeta = (GstVideoMeta *) meta;
72 if (GST_META_TRANSFORM_IS_COPY (type)) {
73 GstMetaTransformCopy *copy = data;
76 /* only copy if the complete data is copied as well */
78 (GstVideoMeta *) gst_buffer_add_meta (dest, GST_VIDEO_META_INFO,
86 GST_DEBUG ("copy video metadata");
87 dmeta->flags = smeta->flags;
88 dmeta->format = smeta->format;
89 dmeta->id = smeta->id;
90 dmeta->width = smeta->width;
91 dmeta->height = smeta->height;
93 dmeta->n_planes = smeta->n_planes;
94 for (i = 0; i < dmeta->n_planes; i++) {
95 dmeta->offset[i] = smeta->offset[i];
96 dmeta->stride[i] = smeta->stride[i];
98 dmeta->map = smeta->map;
99 dmeta->unmap = smeta->unmap;
102 /* return FALSE, if transform type is not supported */
109 gst_video_meta_api_get_type (void)
111 static volatile GType type = 0;
112 static const gchar *tags[] =
113 { GST_META_TAG_VIDEO_STR, GST_META_TAG_MEMORY_STR,
114 GST_META_TAG_VIDEO_COLORSPACE_STR,
115 GST_META_TAG_VIDEO_SIZE_STR, NULL
118 if (g_once_init_enter (&type)) {
119 GType _type = gst_meta_api_type_register ("GstVideoMetaAPI", tags);
120 g_once_init_leave (&type, _type);
127 gst_video_meta_get_info (void)
129 static const GstMetaInfo *video_meta_info = NULL;
131 if (g_once_init_enter ((GstMetaInfo **) & video_meta_info)) {
132 const GstMetaInfo *meta =
133 gst_meta_register (GST_VIDEO_META_API_TYPE, "GstVideoMeta",
134 sizeof (GstVideoMeta), (GstMetaInitFunction) gst_video_meta_init,
135 (GstMetaFreeFunction) NULL, gst_video_meta_transform);
136 g_once_init_leave ((GstMetaInfo **) & video_meta_info,
137 (GstMetaInfo *) meta);
139 return video_meta_info;
143 * gst_buffer_get_video_meta:
144 * @buffer: a #GstBuffer
146 * Find the #GstVideoMeta on @buffer with the lowest @id.
148 * Buffers can contain multiple #GstVideoMeta metadata items when dealing with
151 * Returns: (transfer none): the #GstVideoMeta with lowest id (usually 0) or %NULL when there
152 * is no such metadata on @buffer.
155 gst_buffer_get_video_meta (GstBuffer * buffer)
157 gpointer state = NULL;
158 GstVideoMeta *out = NULL;
160 const GstMetaInfo *info = GST_VIDEO_META_INFO;
162 while ((meta = gst_buffer_iterate_meta (buffer, &state))) {
163 if (meta->info->api == info->api) {
164 GstVideoMeta *vmeta = (GstVideoMeta *) meta;
166 return vmeta; /* Early out for id 0 */
167 if (out == NULL || vmeta->id < out->id)
175 * gst_buffer_get_video_meta_id:
176 * @buffer: a #GstBuffer
179 * Find the #GstVideoMeta on @buffer with the given @id.
181 * Buffers can contain multiple #GstVideoMeta metadata items when dealing with
184 * Returns: (transfer none): the #GstVideoMeta with @id or %NULL when there is no such metadata
188 gst_buffer_get_video_meta_id (GstBuffer * buffer, gint id)
190 gpointer state = NULL;
192 const GstMetaInfo *info = GST_VIDEO_META_INFO;
194 while ((meta = gst_buffer_iterate_meta (buffer, &state))) {
195 if (meta->info->api == info->api) {
196 GstVideoMeta *vmeta = (GstVideoMeta *) meta;
205 default_map (GstVideoMeta * meta, guint plane, GstMapInfo * info,
206 gpointer * data, gint * stride, GstMapFlags flags)
210 GstBuffer *buffer = meta->buffer;
212 offset = meta->offset[plane];
214 /* find the memory block for this plane, this is the memory block containing
215 * the plane offset. FIXME use plane size */
216 if (!gst_buffer_find_memory (buffer, offset, 1, &idx, &length, &skip))
219 if (!gst_buffer_map_range (buffer, idx, length, info, flags))
222 *stride = meta->stride[plane];
223 *data = (guint8 *) info->data + skip;
230 GST_DEBUG ("plane %u, no memory at offset %" G_GSIZE_FORMAT, plane, offset);
235 GST_DEBUG ("cannot map memory range %u-%u", idx, length);
241 default_unmap (GstVideoMeta * meta, guint plane, GstMapInfo * info)
243 GstBuffer *buffer = meta->buffer;
245 gst_buffer_unmap (buffer, info);
251 * gst_buffer_add_video_meta:
252 * @buffer: a #GstBuffer
253 * @flags: #GstVideoFrameFlags
254 * @format: a #GstVideoFormat
256 * @height: the height
258 * Attaches GstVideoMeta metadata to @buffer with the given parameters and the
259 * default offsets and strides for @format and @width x @height.
261 * This function calculates the default offsets and strides and then calls
262 * gst_buffer_add_video_meta_full() with them.
264 * Returns: (transfer none): the #GstVideoMeta on @buffer.
267 gst_buffer_add_video_meta (GstBuffer * buffer,
268 GstVideoFrameFlags flags, GstVideoFormat format, guint width, guint height)
273 if (!gst_video_info_set_format (&info, format, width, height))
277 gst_buffer_add_video_meta_full (buffer, flags, format, width,
278 height, info.finfo->n_planes, info.offset, info.stride);
284 * gst_buffer_add_video_meta_full:
285 * @buffer: a #GstBuffer
286 * @flags: #GstVideoFrameFlags
287 * @format: a #GstVideoFormat
289 * @height: the height
290 * @n_planes: number of planes
291 * @offset: offset of each plane
292 * @stride: stride of each plane
294 * Attaches GstVideoMeta metadata to @buffer with the given parameters.
296 * Returns: (transfer none): the #GstVideoMeta on @buffer.
299 gst_buffer_add_video_meta_full (GstBuffer * buffer,
300 GstVideoFrameFlags flags, GstVideoFormat format, guint width,
301 guint height, guint n_planes, gsize offset[GST_VIDEO_MAX_PLANES],
302 gint stride[GST_VIDEO_MAX_PLANES])
308 (GstVideoMeta *) gst_buffer_add_meta (buffer, GST_VIDEO_META_INFO, NULL);
314 meta->format = format;
317 meta->height = height;
318 meta->buffer = buffer;
320 meta->n_planes = n_planes;
321 for (i = 0; i < n_planes; i++) {
322 meta->offset[i] = offset[i];
323 meta->stride[i] = stride[i];
324 GST_LOG ("plane %d, offset %" G_GSIZE_FORMAT ", stride %d", i, offset[i],
327 meta->map = default_map;
328 meta->unmap = default_unmap;
334 * gst_video_meta_map:
335 * @meta: a #GstVideoMeta
337 * @info: a #GstMapInfo
338 * @data: the data of @plane
339 * @stride: the stride of @plane
340 * @flags: @GstMapFlags
342 * Map the video plane with index @plane in @meta and return a pointer to the
343 * first byte of the plane and the stride of the plane.
345 * Returns: TRUE if the map operation was successful.
348 gst_video_meta_map (GstVideoMeta * meta, guint plane, GstMapInfo * info,
349 gpointer * data, gint * stride, GstMapFlags flags)
351 g_return_val_if_fail (meta != NULL, FALSE);
352 g_return_val_if_fail (meta->map != NULL, FALSE);
353 g_return_val_if_fail (plane < meta->n_planes, FALSE);
354 g_return_val_if_fail (info != NULL, FALSE);
355 g_return_val_if_fail (data != NULL, FALSE);
356 g_return_val_if_fail (stride != NULL, FALSE);
357 g_return_val_if_fail (meta->buffer != NULL, FALSE);
358 g_return_val_if_fail (!(flags & GST_MAP_WRITE)
359 || gst_buffer_is_writable (meta->buffer), FALSE);
361 return meta->map (meta, plane, info, data, stride, flags);
365 * gst_video_meta_unmap:
366 * @meta: a #GstVideoMeta
368 * @info: a #GstMapInfo
370 * Unmap a previously mapped plane with gst_video_meta_map().
372 * Returns: TRUE if the memory was successfully unmapped.
375 gst_video_meta_unmap (GstVideoMeta * meta, guint plane, GstMapInfo * info)
377 g_return_val_if_fail (meta != NULL, FALSE);
378 g_return_val_if_fail (meta->unmap != NULL, FALSE);
379 g_return_val_if_fail (plane < meta->n_planes, FALSE);
380 g_return_val_if_fail (info != NULL, FALSE);
382 return meta->unmap (meta, plane, info);
386 gst_video_crop_meta_transform (GstBuffer * dest, GstMeta * meta,
387 GstBuffer * buffer, GQuark type, gpointer data)
389 GstVideoCropMeta *dmeta, *smeta;
391 if (GST_META_TRANSFORM_IS_COPY (type)) {
392 smeta = (GstVideoCropMeta *) meta;
393 dmeta = gst_buffer_add_video_crop_meta (dest);
397 GST_DEBUG ("copy crop metadata");
400 dmeta->width = smeta->width;
401 dmeta->height = smeta->height;
402 } else if (GST_VIDEO_META_TRANSFORM_IS_SCALE (type)) {
403 GstVideoMetaTransform *trans = data;
406 smeta = (GstVideoCropMeta *) meta;
407 dmeta = gst_buffer_add_video_crop_meta (dest);
411 ow = GST_VIDEO_INFO_WIDTH (trans->in_info);
412 nw = GST_VIDEO_INFO_WIDTH (trans->out_info);
413 oh = GST_VIDEO_INFO_HEIGHT (trans->in_info);
414 nh = GST_VIDEO_INFO_HEIGHT (trans->out_info);
416 GST_DEBUG ("scaling crop metadata %dx%d -> %dx%d", ow, oh, nw, nh);
417 dmeta->x = (smeta->x * nw) / ow;
418 dmeta->y = (smeta->y * nh) / oh;
419 dmeta->width = (smeta->width * nw) / ow;
420 dmeta->height = (smeta->height * nh) / oh;
421 GST_DEBUG ("crop offset %dx%d -> %dx%d", smeta->x, smeta->y, dmeta->x,
423 GST_DEBUG ("crop size %dx%d -> %dx%d", smeta->width, smeta->height,
424 dmeta->width, dmeta->height);
426 /* return FALSE, if transform type is not supported */
433 gst_video_crop_meta_api_get_type (void)
435 static volatile GType type = 0;
436 static const gchar *tags[] =
437 { GST_META_TAG_VIDEO_STR, GST_META_TAG_VIDEO_SIZE_STR,
438 GST_META_TAG_VIDEO_ORIENTATION_STR, NULL
441 if (g_once_init_enter (&type)) {
442 GType _type = gst_meta_api_type_register ("GstVideoCropMetaAPI", tags);
443 g_once_init_leave (&type, _type);
449 gst_video_crop_meta_init (GstMeta * meta, gpointer params, GstBuffer * buffer)
451 GstVideoCropMeta *emeta = (GstVideoCropMeta *) meta;
452 emeta->x = emeta->y = emeta->width = emeta->height = 0;
458 gst_video_crop_meta_get_info (void)
460 static const GstMetaInfo *video_crop_meta_info = NULL;
462 if (g_once_init_enter ((GstMetaInfo **) & video_crop_meta_info)) {
463 const GstMetaInfo *meta =
464 gst_meta_register (GST_VIDEO_CROP_META_API_TYPE, "GstVideoCropMeta",
465 sizeof (GstVideoCropMeta),
466 (GstMetaInitFunction) gst_video_crop_meta_init,
467 (GstMetaFreeFunction) NULL, gst_video_crop_meta_transform);
468 g_once_init_leave ((GstMetaInfo **) & video_crop_meta_info,
469 (GstMetaInfo *) meta);
471 return video_crop_meta_info;
475 * gst_video_meta_transform_scale_get_quark:
477 * Get the #GQuark for the "gst-video-scale" metadata transform operation.
482 gst_video_meta_transform_scale_get_quark (void)
484 static GQuark _value = 0;
487 _value = g_quark_from_static_string ("gst-video-scale");
494 gst_video_gl_texture_upload_meta_api_get_type (void)
496 static volatile GType type = 0;
497 static const gchar *tags[] =
498 { GST_META_TAG_VIDEO_STR, GST_META_TAG_MEMORY_STR, NULL };
500 if (g_once_init_enter (&type)) {
502 gst_meta_api_type_register ("GstVideoGLTextureUploadMetaAPI", tags);
503 g_once_init_leave (&type, _type);
509 gst_video_gl_texture_upload_meta_init (GstMeta * meta, gpointer params,
512 GstVideoGLTextureUploadMeta *vmeta = (GstVideoGLTextureUploadMeta *) meta;
514 vmeta->texture_orientation =
515 GST_VIDEO_GL_TEXTURE_ORIENTATION_X_NORMAL_Y_NORMAL;
516 vmeta->n_textures = 0;
517 memset (vmeta->texture_type, 0, sizeof (vmeta->texture_type));
518 vmeta->buffer = NULL;
519 vmeta->upload = NULL;
520 vmeta->user_data = NULL;
521 vmeta->user_data_copy = NULL;
522 vmeta->user_data_free = NULL;
528 gst_video_gl_texture_upload_meta_free (GstMeta * meta, GstBuffer * buffer)
530 GstVideoGLTextureUploadMeta *vmeta = (GstVideoGLTextureUploadMeta *) meta;
532 if (vmeta->user_data_free)
533 vmeta->user_data_free (vmeta->user_data);
537 gst_video_gl_texture_upload_meta_transform (GstBuffer * dest, GstMeta * meta,
538 GstBuffer * buffer, GQuark type, gpointer data)
540 GstVideoGLTextureUploadMeta *dmeta, *smeta;
542 smeta = (GstVideoGLTextureUploadMeta *) meta;
544 if (GST_META_TRANSFORM_IS_COPY (type)) {
545 GstMetaTransformCopy *copy = data;
548 /* only copy if the complete data is copied as well */
550 (GstVideoGLTextureUploadMeta *) gst_buffer_add_meta (dest,
551 GST_VIDEO_GL_TEXTURE_UPLOAD_META_INFO, NULL);
556 dmeta->texture_orientation = smeta->texture_orientation;
557 dmeta->n_textures = smeta->n_textures;
558 memcpy (dmeta->texture_type, smeta->texture_type,
559 sizeof (smeta->texture_type[0]) * 4);
560 dmeta->buffer = dest;
561 dmeta->upload = smeta->upload;
562 dmeta->user_data = smeta->user_data;
563 dmeta->user_data_copy = smeta->user_data_copy;
564 dmeta->user_data_free = smeta->user_data_free;
565 if (dmeta->user_data_copy)
566 dmeta->user_data = dmeta->user_data_copy (dmeta->user_data);
569 /* return FALSE, if transform type is not supported */
576 gst_video_gl_texture_upload_meta_get_info (void)
578 static const GstMetaInfo *info = NULL;
580 if (g_once_init_enter ((GstMetaInfo **) & info)) {
581 const GstMetaInfo *meta =
582 gst_meta_register (GST_VIDEO_GL_TEXTURE_UPLOAD_META_API_TYPE,
583 "GstVideoGLTextureUploadMeta",
584 sizeof (GstVideoGLTextureUploadMeta),
585 gst_video_gl_texture_upload_meta_init,
586 gst_video_gl_texture_upload_meta_free,
587 gst_video_gl_texture_upload_meta_transform);
588 g_once_init_leave ((GstMetaInfo **) & info, (GstMetaInfo *) meta);
594 * gst_buffer_add_video_gl_texture_upload_meta:
595 * @buffer: a #GstBuffer
596 * @texture_orientation: the #GstVideoGLTextureOrientation
597 * @n_textures: the number of textures
598 * @texture_type: array of #GstVideoGLTextureType
599 * @upload: (scope call): the function to upload the buffer to a specific texture ID
600 * @user_data: user data for the implementor of @upload
601 * @user_data_copy: (scope call): function to copy @user_data
602 * @user_data_free: (scope call): function to free @user_data
604 * Attaches GstVideoGLTextureUploadMeta metadata to @buffer with the given
607 * Returns: (transfer none): the #GstVideoGLTextureUploadMeta on @buffer.
609 GstVideoGLTextureUploadMeta *
610 gst_buffer_add_video_gl_texture_upload_meta (GstBuffer * buffer,
611 GstVideoGLTextureOrientation texture_orientation, guint n_textures,
612 GstVideoGLTextureType texture_type[4], GstVideoGLTextureUpload upload,
613 gpointer user_data, GBoxedCopyFunc user_data_copy,
614 GBoxedFreeFunc user_data_free)
616 GstVideoGLTextureUploadMeta *meta;
618 g_return_val_if_fail (buffer != NULL, NULL);
619 g_return_val_if_fail (upload != NULL, NULL);
620 g_return_val_if_fail (n_textures > 0 && n_textures < 5, NULL);
623 (GstVideoGLTextureUploadMeta *) gst_buffer_add_meta (buffer,
624 GST_VIDEO_GL_TEXTURE_UPLOAD_META_INFO, NULL);
629 meta->texture_orientation = texture_orientation;
630 meta->n_textures = n_textures;
631 memcpy (meta->texture_type, texture_type, sizeof (texture_type[0]) * 4);
632 meta->buffer = buffer;
633 meta->upload = upload;
634 meta->user_data = user_data;
635 meta->user_data_copy = user_data_copy;
636 meta->user_data_free = user_data_free;
642 * gst_video_gl_texture_upload_meta_upload:
643 * @meta: a #GstVideoGLTextureUploadMeta
644 * @texture_id: the texture IDs to upload to
646 * Uploads the buffer which owns the meta to a specific texture ID.
648 * Returns: %TRUE if uploading succeeded, %FALSE otherwise.
651 gst_video_gl_texture_upload_meta_upload (GstVideoGLTextureUploadMeta * meta,
654 g_return_val_if_fail (meta != NULL, FALSE);
656 return meta->upload (meta, texture_id);
659 /* Region of Interest Meta implementation *******************************************/
662 gst_video_region_of_interest_meta_api_get_type (void)
664 static volatile GType type;
665 static const gchar *tags[] =
666 { GST_META_TAG_VIDEO_STR, GST_META_TAG_VIDEO_ORIENTATION_STR,
667 GST_META_TAG_VIDEO_SIZE_STR, NULL
670 if (g_once_init_enter (&type)) {
672 gst_meta_api_type_register ("GstVideoRegionOfInterestMetaAPI", tags);
673 GST_INFO ("registering");
674 g_once_init_leave (&type, _type);
681 gst_video_region_of_interest_meta_transform (GstBuffer * dest, GstMeta * meta,
682 GstBuffer * buffer, GQuark type, gpointer data)
684 GstVideoRegionOfInterestMeta *dmeta, *smeta;
686 if (GST_META_TRANSFORM_IS_COPY (type)) {
687 smeta = (GstVideoRegionOfInterestMeta *) meta;
689 GST_DEBUG ("copy region of interest metadata");
691 gst_buffer_add_video_region_of_interest_meta_id (dest,
692 smeta->roi_type, smeta->x, smeta->y, smeta->w, smeta->h);
696 dmeta->id = smeta->id;
697 dmeta->parent_id = smeta->parent_id;
698 dmeta->params = g_list_copy_deep (smeta->params,
699 (GCopyFunc) gst_structure_copy, NULL);
700 } else if (GST_VIDEO_META_TRANSFORM_IS_SCALE (type)) {
701 GstVideoMetaTransform *trans = data;
703 ow = GST_VIDEO_INFO_WIDTH (trans->in_info);
704 nw = GST_VIDEO_INFO_WIDTH (trans->out_info);
705 oh = GST_VIDEO_INFO_HEIGHT (trans->in_info);
706 nh = GST_VIDEO_INFO_HEIGHT (trans->out_info);
707 GST_DEBUG ("scaling region of interest metadata %dx%d -> %dx%d", ow, oh, nw,
710 smeta = (GstVideoRegionOfInterestMeta *) meta;
712 gst_buffer_add_video_region_of_interest_meta_id (dest,
713 smeta->roi_type, (smeta->x * nw) / ow, (smeta->y * nh) / oh,
714 (smeta->w * nw) / ow, (smeta->h * nh) / oh);
718 dmeta->id = smeta->id;
719 dmeta->parent_id = smeta->parent_id;
721 GST_DEBUG ("region of interest (id:%d, parent id:%d) offset %dx%d -> %dx%d",
722 smeta->id, smeta->parent_id, smeta->x, smeta->y, dmeta->x, dmeta->y);
723 GST_DEBUG ("region of interest size %dx%d -> %dx%d", smeta->w, smeta->h,
726 /* return FALSE, if transform type is not supported */
733 gst_video_region_of_interest_meta_init (GstMeta * meta, gpointer params,
736 GstVideoRegionOfInterestMeta *emeta = (GstVideoRegionOfInterestMeta *) meta;
739 emeta->parent_id = 0;
740 emeta->x = emeta->y = emeta->w = emeta->h = 0;
741 emeta->params = NULL;
747 gst_video_region_of_interest_meta_free (GstMeta * meta, GstBuffer * buffer)
749 GstVideoRegionOfInterestMeta *emeta = (GstVideoRegionOfInterestMeta *) meta;
751 g_list_free_full (emeta->params, (GDestroyNotify) gst_structure_free);
755 gst_video_region_of_interest_meta_get_info (void)
757 static const GstMetaInfo *meta_info = NULL;
759 if (g_once_init_enter ((GstMetaInfo **) & meta_info)) {
760 const GstMetaInfo *mi =
761 gst_meta_register (GST_VIDEO_REGION_OF_INTEREST_META_API_TYPE,
762 "GstVideoRegionOfInterestMeta",
763 sizeof (GstVideoRegionOfInterestMeta),
764 gst_video_region_of_interest_meta_init,
765 gst_video_region_of_interest_meta_free,
766 gst_video_region_of_interest_meta_transform);
767 g_once_init_leave ((GstMetaInfo **) & meta_info, (GstMetaInfo *) mi);
773 * gst_buffer_get_video_region_of_interest_meta_id:
774 * @buffer: a #GstBuffer
777 * Find the #GstVideoRegionOfInterestMeta on @buffer with the given @id.
779 * Buffers can contain multiple #GstVideoRegionOfInterestMeta metadata items if
780 * multiple regions of interests are marked on a frame.
782 * Returns: (transfer none): the #GstVideoRegionOfInterestMeta with @id or %NULL when there is
783 * no such metadata on @buffer.
785 GstVideoRegionOfInterestMeta *
786 gst_buffer_get_video_region_of_interest_meta_id (GstBuffer * buffer, gint id)
788 gpointer state = NULL;
790 const GstMetaInfo *info = GST_VIDEO_REGION_OF_INTEREST_META_INFO;
792 while ((meta = gst_buffer_iterate_meta (buffer, &state))) {
793 if (meta->info->api == info->api) {
794 GstVideoRegionOfInterestMeta *vmeta =
795 (GstVideoRegionOfInterestMeta *) meta;
804 * gst_buffer_add_video_region_of_interest_meta:
805 * @buffer: a #GstBuffer
806 * @roi_type: Type of the region of interest (e.g. "face")
812 * Attaches #GstVideoRegionOfInterestMeta metadata to @buffer with the given
815 * Returns: (transfer none): the #GstVideoRegionOfInterestMeta on @buffer.
817 GstVideoRegionOfInterestMeta *
818 gst_buffer_add_video_region_of_interest_meta (GstBuffer * buffer,
819 const gchar * roi_type, guint x, guint y, guint w, guint h)
821 return gst_buffer_add_video_region_of_interest_meta_id (buffer,
822 g_quark_from_string (roi_type), x, y, w, h);
826 * gst_buffer_add_video_region_of_interest_meta_id:
827 * @buffer: a #GstBuffer
828 * @roi_type: Type of the region of interest (e.g. "face")
834 * Attaches #GstVideoRegionOfInterestMeta metadata to @buffer with the given
837 * Returns: (transfer none): the #GstVideoRegionOfInterestMeta on @buffer.
839 GstVideoRegionOfInterestMeta *
840 gst_buffer_add_video_region_of_interest_meta_id (GstBuffer * buffer,
841 GQuark roi_type, guint x, guint y, guint w, guint h)
843 GstVideoRegionOfInterestMeta *meta;
845 g_return_val_if_fail (GST_IS_BUFFER (buffer), NULL);
847 meta = (GstVideoRegionOfInterestMeta *) gst_buffer_add_meta (buffer,
848 GST_VIDEO_REGION_OF_INTEREST_META_INFO, NULL);
849 meta->roi_type = roi_type;
859 * gst_video_region_of_interest_meta_add_param:
860 * @meta: a #GstVideoRegionOfInterestMeta
861 * @s: (transfer full): a #GstStructure
863 * Attach element-specific parameters to @meta meant to be used by downstream
864 * elements which may handle this ROI.
865 * The name of @s is used to identify the element these parameters are meant for.
867 * This is typically used to tell encoders how they should encode this specific region.
868 * For example, a structure named "roi/x264enc" could be used to give the
869 * QP offsets this encoder should use when encoding the region described in @meta.
870 * Multiple parameters can be defined for the same meta so different encoders
871 * can be supported by cross platform applications).
876 gst_video_region_of_interest_meta_add_param (GstVideoRegionOfInterestMeta *
877 meta, GstStructure * s)
879 g_return_if_fail (meta);
880 g_return_if_fail (s);
882 meta->params = g_list_append (meta->params, s);
886 * gst_video_region_of_interest_meta_get_param:
887 * @meta: a #GstVideoRegionOfInterestMeta
889 * Retrieve the parameter for @meta having @name as structure name,
890 * or %NULL if there is none.
892 * Returns: (transfer none) (nullable): a #GstStructure
895 * See also: gst_video_region_of_interest_meta_add_param()
898 gst_video_region_of_interest_meta_get_param (GstVideoRegionOfInterestMeta *
899 meta, const gchar * name)
903 g_return_val_if_fail (meta, NULL);
904 g_return_val_if_fail (name, NULL);
906 for (l = meta->params; l; l = g_list_next (l)) {
907 GstStructure *s = l->data;
909 if (gst_structure_has_name (s, name))
916 /* Time Code Meta implementation *******************************************/
919 gst_video_time_code_meta_api_get_type (void)
921 static volatile GType type;
923 if (g_once_init_enter (&type)) {
924 static const gchar *tags[] = { NULL };
925 GType _type = gst_meta_api_type_register ("GstVideoTimeCodeMetaAPI", tags);
926 GST_INFO ("registering");
927 g_once_init_leave (&type, _type);
934 gst_video_time_code_meta_transform (GstBuffer * dest, GstMeta * meta,
935 GstBuffer * buffer, GQuark type, gpointer data)
937 GstVideoTimeCodeMeta *dmeta, *smeta;
939 if (GST_META_TRANSFORM_IS_COPY (type)) {
940 smeta = (GstVideoTimeCodeMeta *) meta;
942 GST_DEBUG ("copy time code metadata");
944 gst_buffer_add_video_time_code_meta_full (dest, smeta->tc.config.fps_n,
945 smeta->tc.config.fps_d, smeta->tc.config.latest_daily_jam,
946 smeta->tc.config.flags, smeta->tc.hours, smeta->tc.minutes,
947 smeta->tc.seconds, smeta->tc.frames, smeta->tc.field_count);
951 /* return FALSE, if transform type is not supported */
958 gst_video_time_code_meta_init (GstMeta * meta, gpointer params,
961 GstVideoTimeCodeMeta *emeta = (GstVideoTimeCodeMeta *) meta;
962 memset (&emeta->tc, 0, sizeof (emeta->tc));
963 gst_video_time_code_clear (&emeta->tc);
969 gst_video_time_code_meta_free (GstMeta * meta, GstBuffer * buffer)
971 GstVideoTimeCodeMeta *emeta = (GstVideoTimeCodeMeta *) meta;
973 gst_video_time_code_clear (&emeta->tc);
977 gst_video_time_code_meta_get_info (void)
979 static const GstMetaInfo *meta_info = NULL;
981 if (g_once_init_enter ((GstMetaInfo **) & meta_info)) {
982 const GstMetaInfo *mi =
983 gst_meta_register (GST_VIDEO_TIME_CODE_META_API_TYPE,
984 "GstVideoTimeCodeMeta",
985 sizeof (GstVideoTimeCodeMeta),
986 gst_video_time_code_meta_init,
987 gst_video_time_code_meta_free,
988 gst_video_time_code_meta_transform);
989 g_once_init_leave ((GstMetaInfo **) & meta_info, (GstMetaInfo *) mi);
995 * gst_buffer_add_video_time_code_meta:
996 * @buffer: a #GstBuffer
997 * @tc: a #GstVideoTimeCode
999 * Attaches #GstVideoTimeCodeMeta metadata to @buffer with the given
1002 * Returns: (transfer none): the #GstVideoTimeCodeMeta on @buffer.
1006 GstVideoTimeCodeMeta *
1007 gst_buffer_add_video_time_code_meta (GstBuffer * buffer, GstVideoTimeCode * tc)
1009 g_return_val_if_fail (gst_video_time_code_is_valid (tc), NULL);
1010 return gst_buffer_add_video_time_code_meta_full (buffer, tc->config.fps_n,
1011 tc->config.fps_d, tc->config.latest_daily_jam, tc->config.flags,
1012 tc->hours, tc->minutes, tc->seconds, tc->frames, tc->field_count);
1016 * gst_buffer_add_video_time_code_meta_full:
1017 * @buffer: a #GstBuffer
1018 * @fps_n: framerate numerator
1019 * @fps_d: framerate denominator
1020 * @latest_daily_jam: a #GDateTime for the latest daily jam
1021 * @flags: a #GstVideoTimeCodeFlags
1022 * @hours: hours since the daily jam
1023 * @minutes: minutes since the daily jam
1024 * @seconds: seconds since the daily jam
1025 * @frames: frames since the daily jam
1026 * @field_count: fields since the daily jam
1028 * Attaches #GstVideoTimeCodeMeta metadata to @buffer with the given
1031 * Returns: (transfer none): the #GstVideoTimeCodeMeta on @buffer.
1035 GstVideoTimeCodeMeta *
1036 gst_buffer_add_video_time_code_meta_full (GstBuffer * buffer, guint fps_n,
1037 guint fps_d, GDateTime * latest_daily_jam, GstVideoTimeCodeFlags flags,
1038 guint hours, guint minutes, guint seconds, guint frames, guint field_count)
1040 GstVideoTimeCodeMeta *meta;
1042 g_return_val_if_fail (GST_IS_BUFFER (buffer), NULL);
1044 meta = (GstVideoTimeCodeMeta *) gst_buffer_add_meta (buffer,
1045 GST_VIDEO_TIME_CODE_META_INFO, NULL);
1046 g_return_val_if_fail (meta != NULL, NULL);
1048 gst_video_time_code_init (&meta->tc, fps_n, fps_d, latest_daily_jam, flags,
1049 hours, minutes, seconds, frames, field_count);
1051 g_return_val_if_fail (gst_video_time_code_is_valid (&meta->tc), NULL);