e1c77d46608e80355452d26071e1a974a2b9a748
[platform/upstream/gstreamer.git] / gst-libs / gst / sctp / sctpreceivemeta.c
1 /*
2  * Copyright (c) 2015, Collabora Ltd.
3  *
4  * Redistribution and use in source and binary forms, with or without modification,
5  * are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice, this
8  * list of conditions and the following disclaimer.
9  *
10  * 2. Redistributions in binary form must reproduce the above copyright notice, this
11  * list of conditions and the following disclaimer in the documentation and/or other
12  * materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17  * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
18  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
23  * OF SUCH DAMAGE.
24  */
25 #ifdef HAVE_CONFIG_H
26 #include "config.h"
27 #endif
28
29 #include "sctpreceivemeta.h"
30
31 static gboolean gst_sctp_receive_meta_init (GstMeta * meta, gpointer params,
32     GstBuffer * buffer);
33 static gboolean gst_sctp_receive_meta_transform (GstBuffer * transbuf,
34     GstMeta * meta, GstBuffer * buffer, GQuark type, gpointer data);
35
36 GType
37 gst_sctp_receive_meta_api_get_type (void)
38 {
39   static const gchar *tags[] = { NULL };
40   static volatile GType type;
41   if (g_once_init_enter (&type)) {
42     GType _type = gst_meta_api_type_register ("GstSctpReceiveMetaAPI", tags);
43     g_once_init_leave (&type, _type);
44   }
45   return type;
46 }
47
48 const GstMetaInfo *
49 gst_sctp_receive_meta_get_info (void)
50 {
51   static const GstMetaInfo *gst_sctp_receive_meta_info = NULL;
52
53   if (g_once_init_enter (&gst_sctp_receive_meta_info)) {
54     const GstMetaInfo *meta = gst_meta_register (GST_SCTP_RECEIVE_META_API_TYPE,
55         "GstSctpReceiveMeta",
56         sizeof (GstSctpReceiveMeta),
57         gst_sctp_receive_meta_init,
58         (GstMetaFreeFunction) NULL,
59         gst_sctp_receive_meta_transform);
60     g_once_init_leave (&gst_sctp_receive_meta_info, meta);
61   }
62   return gst_sctp_receive_meta_info;
63 }
64
65 static gboolean
66 gst_sctp_receive_meta_init (GstMeta * meta, gpointer params, GstBuffer * buffer)
67 {
68   GstSctpReceiveMeta *gst_sctp_receive_meta = (GstSctpReceiveMeta *) meta;
69   gst_sctp_receive_meta->ppid = 0;
70   return TRUE;
71 }
72
73 static gboolean
74 gst_sctp_receive_meta_transform (GstBuffer * transbuf, GstMeta * meta,
75     GstBuffer * buffer, GQuark type, gpointer data)
76 {
77   GstSctpReceiveMeta *gst_sctp_receive_meta = (GstSctpReceiveMeta *) meta;
78   gst_sctp_buffer_add_receive_meta (transbuf, gst_sctp_receive_meta->ppid);
79   return TRUE;
80 }
81
82 GstSctpReceiveMeta *
83 gst_sctp_buffer_add_receive_meta (GstBuffer * buffer, guint32 ppid)
84 {
85   GstSctpReceiveMeta *gst_sctp_receive_meta = NULL;
86
87   g_return_val_if_fail (GST_IS_BUFFER (buffer), NULL);
88   gst_sctp_receive_meta =
89       (GstSctpReceiveMeta *) gst_buffer_add_meta (buffer,
90       GST_SCTP_RECEIVE_META_INFO, NULL);
91   gst_sctp_receive_meta->ppid = ppid;
92   return gst_sctp_receive_meta;
93 }