Tizen 2.0 Release
[framework/multimedia/gst-plugins-good0.10.git] / gst / rtp / gstrtpdepay.c
1 /* GStreamer
2  * Copyright (C) <2005> Wim Taymans <wim.taymans@gmail.com>
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., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19 /* Element-Checklist-Version: 5 */
20
21 #include "gstrtpdepay.h"
22
23 GST_DEBUG_CATEGORY_STATIC (rtpdepay_debug);
24 #define GST_CAT_DEFAULT (rtpdepay_debug)
25
26 static GstStaticPadTemplate gst_rtp_depay_src_rtp_template =
27 GST_STATIC_PAD_TEMPLATE ("srcrtp",
28     GST_PAD_SRC,
29     GST_PAD_ALWAYS,
30     GST_STATIC_CAPS ("application/x-rtp")
31     );
32
33 static GstStaticPadTemplate gst_rtp_depay_src_rtcp_template =
34 GST_STATIC_PAD_TEMPLATE ("srcrtcp",
35     GST_PAD_SRC,
36     GST_PAD_ALWAYS,
37     GST_STATIC_CAPS ("application/x-rtcp")
38     );
39
40 static GstStaticPadTemplate gst_rtp_depay_sink_rtp_template =
41 GST_STATIC_PAD_TEMPLATE ("sinkrtp",
42     GST_PAD_SINK,
43     GST_PAD_ALWAYS,
44     GST_STATIC_CAPS ("application/x-rtp")
45     );
46
47 static GstStaticPadTemplate gst_rtp_depay_sink_rtcp_template =
48 GST_STATIC_PAD_TEMPLATE ("sinkrtcp",
49     GST_PAD_SINK,
50     GST_PAD_ALWAYS,
51     GST_STATIC_CAPS ("application/x-rtcp")
52     );
53
54 static GstCaps *gst_rtp_depay_getcaps (GstPad * pad);
55 static GstFlowReturn gst_rtp_depay_chain_rtp (GstPad * pad, GstBuffer * buffer);
56 static GstFlowReturn gst_rtp_depay_chain_rtcp (GstPad * pad,
57     GstBuffer * buffer);
58
59 GST_BOILERPLATE (GstRTPDepay, gst_rtp_depay, GstElement, GST_TYPE_ELEMENT);
60
61 static void
62 gst_rtp_depay_base_init (gpointer klass)
63 {
64   GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
65
66   gst_element_class_add_static_pad_template (gstelement_class,
67       &gst_rtp_depay_src_rtp_template);
68   gst_element_class_add_static_pad_template (gstelement_class,
69       &gst_rtp_depay_src_rtcp_template);
70   gst_element_class_add_static_pad_template (gstelement_class,
71       &gst_rtp_depay_sink_rtp_template);
72   gst_element_class_add_static_pad_template (gstelement_class,
73       &gst_rtp_depay_sink_rtcp_template);
74   gst_element_class_set_details_simple (gstelement_class,
75       "Dummy RTP session manager", "Codec/Depayloader/Network/RTP",
76       "Accepts raw RTP and RTCP packets and sends them forward",
77       "Wim Taymans <wim.taymans@gmail.com>");
78 }
79
80 static void
81 gst_rtp_depay_class_init (GstRTPDepayClass * klass)
82 {
83   GST_DEBUG_CATEGORY_INIT (rtpdepay_debug, "rtpdepay", 0, "RTP decoder");
84 }
85
86 static void
87 gst_rtp_depay_init (GstRTPDepay * rtpdepay, GstRTPDepayClass * klass)
88 {
89   /* the input rtp pad */
90   rtpdepay->sink_rtp =
91       gst_pad_new_from_static_template (&gst_rtp_depay_sink_rtp_template,
92       "sinkrtp");
93   gst_element_add_pad (GST_ELEMENT (rtpdepay), rtpdepay->sink_rtp);
94   gst_pad_set_getcaps_function (rtpdepay->sink_rtp, gst_rtp_depay_getcaps);
95   gst_pad_set_chain_function (rtpdepay->sink_rtp, gst_rtp_depay_chain_rtp);
96
97   /* the input rtcp pad */
98   rtpdepay->sink_rtcp =
99       gst_pad_new_from_static_template (&gst_rtp_depay_sink_rtcp_template,
100       "sinkrtcp");
101   gst_element_add_pad (GST_ELEMENT (rtpdepay), rtpdepay->sink_rtcp);
102   gst_pad_set_chain_function (rtpdepay->sink_rtcp, gst_rtp_depay_chain_rtcp);
103
104   /* the output rtp pad */
105   rtpdepay->src_rtp =
106       gst_pad_new_from_static_template (&gst_rtp_depay_src_rtp_template,
107       "srcrtp");
108   gst_pad_set_getcaps_function (rtpdepay->src_rtp, gst_rtp_depay_getcaps);
109   gst_element_add_pad (GST_ELEMENT (rtpdepay), rtpdepay->src_rtp);
110
111   /* the output rtcp pad */
112   rtpdepay->src_rtcp =
113       gst_pad_new_from_static_template (&gst_rtp_depay_src_rtcp_template,
114       "srcrtcp");
115   gst_element_add_pad (GST_ELEMENT (rtpdepay), rtpdepay->src_rtcp);
116 }
117
118 static GstCaps *
119 gst_rtp_depay_getcaps (GstPad * pad)
120 {
121   GstRTPDepay *src;
122   GstPad *other;
123   GstCaps *caps;
124
125   src = GST_RTP_DEPAY (GST_PAD_PARENT (pad));
126
127   other = pad == src->src_rtp ? src->sink_rtp : src->src_rtp;
128
129   caps = gst_pad_peer_get_caps (other);
130
131   if (caps == NULL)
132     caps = gst_caps_copy (gst_pad_get_pad_template_caps (pad));
133
134   return caps;
135 }
136
137 static GstFlowReturn
138 gst_rtp_depay_chain_rtp (GstPad * pad, GstBuffer * buffer)
139 {
140   GstRTPDepay *src;
141
142   src = GST_RTP_DEPAY (GST_PAD_PARENT (pad));
143
144   GST_DEBUG ("got rtp packet");
145   return gst_pad_push (src->src_rtp, buffer);
146 }
147
148 static GstFlowReturn
149 gst_rtp_depay_chain_rtcp (GstPad * pad, GstBuffer * buffer)
150 {
151   GST_DEBUG ("got rtcp packet");
152
153   gst_buffer_unref (buffer);
154   return GST_FLOW_OK;
155 }
156
157 gboolean
158 gst_rtp_depay_plugin_init (GstPlugin * plugin)
159 {
160   return gst_element_register (plugin, "rtpdepay",
161       GST_RANK_MARGINAL, GST_TYPE_RTP_DEPAY);
162 }