2 * Copyright (C) <2007> 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., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
27 #include <gst/audio/audio.h>
28 #include <gst/audio/multichannel.h>
30 #include "gstrtpL16depay.h"
31 #include "gstrtpchannels.h"
33 GST_DEBUG_CATEGORY_STATIC (rtpL16depay_debug);
34 #define GST_CAT_DEFAULT (rtpL16depay_debug)
36 static GstStaticPadTemplate gst_rtp_L16_depay_src_template =
37 GST_STATIC_PAD_TEMPLATE ("src",
40 GST_STATIC_CAPS ("audio/x-raw, "
41 "format = (string) S16_BE, "
42 "rate = (int) [ 1, MAX ], " "channels = (int) [ 1, MAX ]")
45 static GstStaticPadTemplate gst_rtp_L16_depay_sink_template =
46 GST_STATIC_PAD_TEMPLATE ("sink",
49 GST_STATIC_CAPS ("application/x-rtp, "
50 "media = (string) \"audio\", "
51 "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
52 "clock-rate = (int) [ 1, MAX ], "
53 /* "channels = (int) [1, MAX]" */
54 /* "emphasis = (string) ANY" */
55 /* "channel-order = (string) ANY" */
56 "encoding-name = (string) \"L16\";"
58 "media = (string) \"audio\", "
59 "payload = (int) { " GST_RTP_PAYLOAD_L16_STEREO_STRING ", "
60 GST_RTP_PAYLOAD_L16_MONO_STRING " }," "clock-rate = (int) [ 1, MAX ]"
61 /* "channels = (int) [1, MAX]" */
62 /* "emphasis = (string) ANY" */
63 /* "channel-order = (string) ANY" */
67 #define gst_rtp_L16_depay_parent_class parent_class
68 G_DEFINE_TYPE (GstRtpL16Depay, gst_rtp_L16_depay, GST_TYPE_RTP_BASE_DEPAYLOAD);
70 static gboolean gst_rtp_L16_depay_setcaps (GstRTPBaseDepayload * depayload,
72 static GstBuffer *gst_rtp_L16_depay_process (GstRTPBaseDepayload * depayload,
76 gst_rtp_L16_depay_class_init (GstRtpL16DepayClass * klass)
78 GstElementClass *gstelement_class;
79 GstRTPBaseDepayloadClass *gstrtpbasedepayload_class;
81 gstelement_class = (GstElementClass *) klass;
82 gstrtpbasedepayload_class = (GstRTPBaseDepayloadClass *) klass;
84 gstrtpbasedepayload_class->set_caps = gst_rtp_L16_depay_setcaps;
85 gstrtpbasedepayload_class->process = gst_rtp_L16_depay_process;
87 gst_element_class_add_pad_template (gstelement_class,
88 gst_static_pad_template_get (&gst_rtp_L16_depay_src_template));
89 gst_element_class_add_pad_template (gstelement_class,
90 gst_static_pad_template_get (&gst_rtp_L16_depay_sink_template));
92 gst_element_class_set_details_simple (gstelement_class,
93 "RTP audio depayloader", "Codec/Depayloader/Network/RTP",
94 "Extracts raw audio from RTP packets",
95 "Zeeshan Ali <zak147@yahoo.com>," "Wim Taymans <wim.taymans@gmail.com>");
97 GST_DEBUG_CATEGORY_INIT (rtpL16depay_debug, "rtpL16depay", 0,
98 "Raw Audio RTP Depayloader");
102 gst_rtp_L16_depay_init (GstRtpL16Depay * rtpL16depay)
104 /* needed because of GST_BOILERPLATE */
108 gst_rtp_L16_depay_parse_int (GstStructure * structure, const gchar * field,
114 if ((str = gst_structure_get_string (structure, field)))
117 if (gst_structure_get_int (structure, field, &res))
124 gst_rtp_L16_depay_setcaps (GstRTPBaseDepayload * depayload, GstCaps * caps)
126 GstStructure *structure;
127 GstRtpL16Depay *rtpL16depay;
128 gint clock_rate, payload;
132 const gchar *channel_order;
133 const GstRTPChannelOrder *order;
135 rtpL16depay = GST_RTP_L16_DEPAY (depayload);
137 structure = gst_caps_get_structure (caps, 0);
140 gst_structure_get_int (structure, "payload", &payload);
142 case GST_RTP_PAYLOAD_L16_STEREO:
146 case GST_RTP_PAYLOAD_L16_MONO:
151 /* no fixed mapping, we need clock-rate */
157 /* caps can overwrite defaults */
159 gst_rtp_L16_depay_parse_int (structure, "clock-rate", clock_rate);
164 gst_rtp_L16_depay_parse_int (structure, "encoding-params", channels);
166 channels = gst_rtp_L16_depay_parse_int (structure, "channels", channels);
168 /* channels defaults to 1 otherwise */
173 depayload->clock_rate = clock_rate;
174 rtpL16depay->rate = clock_rate;
175 rtpL16depay->channels = channels;
177 srccaps = gst_caps_new_simple ("audio/x-raw",
178 "format", G_TYPE_STRING, "S16_BE",
179 "rate", G_TYPE_INT, clock_rate, "channels", G_TYPE_INT, channels, NULL);
181 /* add channel positions */
182 channel_order = gst_structure_get_string (structure, "channel-order");
184 order = gst_rtp_channels_get_by_order (channels, channel_order);
186 gst_audio_set_channel_positions (gst_caps_get_structure (srccaps, 0),
189 GstAudioChannelPosition *pos;
191 GST_ELEMENT_WARNING (rtpL16depay, STREAM, DECODE,
192 (NULL), ("Unknown channel order '%s' for %d channels",
193 GST_STR_NULL (channel_order), channels));
194 /* create default NONE layout */
195 pos = gst_rtp_channels_create_default (channels);
196 gst_audio_set_channel_positions (gst_caps_get_structure (srccaps, 0), pos);
200 res = gst_pad_set_caps (depayload->srcpad, srccaps);
201 gst_caps_unref (srccaps);
208 GST_ERROR_OBJECT (depayload, "no clock-rate specified");
214 gst_rtp_L16_depay_process (GstRTPBaseDepayload * depayload, GstBuffer * buf)
216 GstRtpL16Depay *rtpL16depay;
222 rtpL16depay = GST_RTP_L16_DEPAY (depayload);
224 gst_rtp_buffer_map (buf, GST_MAP_READ, &rtp);
225 payload_len = gst_rtp_buffer_get_payload_len (&rtp);
227 if (payload_len <= 0)
230 GST_DEBUG_OBJECT (rtpL16depay, "got payload of %d bytes", payload_len);
232 outbuf = gst_rtp_buffer_get_payload_buffer (&rtp);
233 marker = gst_rtp_buffer_get_marker (&rtp);
236 /* mark talk spurt with DISCONT */
237 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
240 gst_rtp_buffer_unmap (&rtp);
247 GST_ELEMENT_WARNING (rtpL16depay, STREAM, DECODE,
248 ("Empty Payload."), (NULL));
249 gst_rtp_buffer_unmap (&rtp);
255 gst_rtp_L16_depay_plugin_init (GstPlugin * plugin)
257 return gst_element_register (plugin, "rtpL16depay",
258 GST_RANK_SECONDARY, GST_TYPE_RTP_L16_DEPAY);