initial import
[platform/adaptation/nexell/nx-gst-meta.git] / src / gstmmvideobuffermeta.c
1 /* GStreamer
2  * Copyright (C) 2016 Biela.Jo <doriya@nexell.co.kr>
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 #include "gstmmvideobuffermeta.h"
21
22 GType
23 gst_mmvideobuffer_meta_api_get_type (void)
24 {
25   static volatile GType type;
26   static const gchar *tags[] = { "MMVideoBuffer", NULL };
27
28   if (g_once_init_enter (&type)) {
29     GType _type = gst_meta_api_type_register ("GstMMVideoBufferMetaAPI", tags);
30     g_once_init_leave (&type, _type);
31   }
32
33   return type;
34 }
35
36 static gboolean
37 gst_mmvideobuffer_meta_init (GstMeta * meta, gpointer params,
38     GstBuffer * buffer)
39 {
40   GstMMVideoBufferMeta *emeta = (GstMMVideoBufferMeta *) meta;
41
42   emeta->memory_index = -1;
43
44   return TRUE;
45 }
46
47 static gboolean
48 gst_mmvideobuffer_meta_transform (GstBuffer * transbuf, GstMeta * meta,
49     GstBuffer * buffer, GQuark type, gpointer data)
50 {
51   GstMMVideoBufferMeta *emeta = (GstMMVideoBufferMeta *) meta;
52
53   /* we always copy no matter what transform */
54   gst_buffer_add_mmvideobuffer_meta (transbuf, emeta->memory_index);
55
56   return TRUE;
57 }
58
59 static void
60 gst_mmvideobuffer_meta_free (GstMeta * meta, GstBuffer * buffer)
61 {
62   GstMMVideoBufferMeta *emeta = (GstMMVideoBufferMeta *) meta;
63
64   emeta->memory_index = -1;
65 }
66
67 const GstMetaInfo *
68 gst_mmvideobuffer_meta_get_info (void)
69 {
70   static const GstMetaInfo *meta_info = NULL;
71
72   if (g_once_init_enter (&meta_info)) {
73     const GstMetaInfo *mi = gst_meta_register (GST_MMVIDEOBUFFER_META_API_TYPE,
74         "GstMMVideoBufferMeta",
75         sizeof (GstMMVideoBufferMeta),
76         gst_mmvideobuffer_meta_init,
77         gst_mmvideobuffer_meta_free,
78         gst_mmvideobuffer_meta_transform);
79
80     g_once_init_leave (&meta_info, mi);
81   }
82   return meta_info;
83 }
84
85 GstMMVideoBufferMeta *
86 gst_buffer_add_mmvideobuffer_meta (GstBuffer * buffer, gint memory_index)
87 {
88   GstMMVideoBufferMeta *meta;
89
90   g_return_val_if_fail (GST_IS_BUFFER (buffer), NULL);
91
92   meta =
93       (GstMMVideoBufferMeta *) gst_buffer_add_meta (buffer,
94       GST_MMVIDEOBUFFER_META_INFO, NULL);
95   meta->memory_index = memory_index;
96
97   return meta;
98 }