Port gtk-doc comments to their equivalent markdown syntax
[platform/upstream/gstreamer.git] / libs / gst / net / gstnetcontrolmessagemeta.c
1 /* GStreamer
2  * Copyright (C) <2014> William Manley <will@williammanley.net>
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 /**
21  * SECTION:gstnetcontrolmessagemeta
22  * @title: GstNetControlMessageMeta
23  * @short_description: Network Control Message Meta
24  *
25  * #GstNetControlMessageMeta can be used to store control messages (ancillary
26  * data) which was received with or is to be sent alongside the buffer data.
27  * When used with socket sinks and sources which understand this meta it allows
28  * sending and receiving ancillary data such as unix credentials (See
29  * #GUnixCredentialsMessage) and Unix file descriptions (See #GUnixFDMessage).
30  */
31
32 #include <string.h>
33
34 #include "gstnetcontrolmessagemeta.h"
35
36 static gboolean
37 net_control_message_meta_init (GstMeta * meta, gpointer params,
38     GstBuffer * buffer)
39 {
40   GstNetControlMessageMeta *nmeta = (GstNetControlMessageMeta *) meta;
41
42   nmeta->message = NULL;
43
44   return TRUE;
45 }
46
47 static gboolean
48 net_control_message_meta_transform (GstBuffer * transbuf, GstMeta * meta,
49     GstBuffer * buffer, GQuark type, gpointer data)
50 {
51   GstNetControlMessageMeta *smeta, *dmeta;
52   smeta = (GstNetControlMessageMeta *) meta;
53
54   /* we always copy no matter what transform */
55   dmeta = gst_buffer_add_net_control_message_meta (transbuf, smeta->message);
56   if (!dmeta)
57     return FALSE;
58
59   return TRUE;
60 }
61
62 static void
63 net_control_message_meta_free (GstMeta * meta, GstBuffer * buffer)
64 {
65   GstNetControlMessageMeta *nmeta = (GstNetControlMessageMeta *) meta;
66
67   if (nmeta->message)
68     g_object_unref (nmeta->message);
69   nmeta->message = NULL;
70 }
71
72 GType
73 gst_net_control_message_meta_api_get_type (void)
74 {
75   static volatile GType type;
76   static const gchar *tags[] = { "origin", NULL };
77
78   if (g_once_init_enter (&type)) {
79     GType _type =
80         gst_meta_api_type_register ("GstNetControlMessageMetaAPI", tags);
81     g_once_init_leave (&type, _type);
82   }
83   return type;
84 }
85
86 const GstMetaInfo *
87 gst_net_control_message_meta_get_info (void)
88 {
89   static const GstMetaInfo *meta_info = NULL;
90
91   if (g_once_init_enter ((GstMetaInfo **) & meta_info)) {
92     const GstMetaInfo *mi =
93         gst_meta_register (GST_NET_CONTROL_MESSAGE_META_API_TYPE,
94         "GstNetControlMessageMeta",
95         sizeof (GstNetControlMessageMeta),
96         net_control_message_meta_init,
97         net_control_message_meta_free,
98         net_control_message_meta_transform);
99     g_once_init_leave ((GstMetaInfo **) & meta_info, (GstMetaInfo *) mi);
100   }
101   return meta_info;
102 }
103
104 /**
105  * gst_buffer_add_net_control_message_meta:
106  * @buffer: a #GstBuffer
107  * @message: a @GSocketControlMessage to attach to @buffer
108  *
109  * Attaches @message as metadata in a #GstNetControlMessageMeta to @buffer.
110  *
111  * Returns: (transfer none): a #GstNetControlMessageMeta connected to @buffer
112  */
113 GstNetControlMessageMeta *
114 gst_buffer_add_net_control_message_meta (GstBuffer * buffer,
115     GSocketControlMessage * message)
116 {
117   GstNetControlMessageMeta *meta;
118
119   g_return_val_if_fail (GST_IS_BUFFER (buffer), NULL);
120   g_return_val_if_fail (G_IS_SOCKET_CONTROL_MESSAGE (message), NULL);
121
122   meta =
123       (GstNetControlMessageMeta *) gst_buffer_add_meta (buffer,
124       GST_NET_CONTROL_MESSAGE_META_INFO, NULL);
125
126   meta->message = g_object_ref (message);
127
128   return meta;
129 }