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-int, "
41 "endianness = (int) BIG_ENDIAN, "
42 "signed = (boolean) true, "
45 "rate = (int) [ 1, MAX ], " "channels = (int) [ 1, MAX ]")
48 static GstStaticPadTemplate gst_rtp_L16_depay_sink_template =
49 GST_STATIC_PAD_TEMPLATE ("sink",
52 GST_STATIC_CAPS ("application/x-rtp, "
53 "media = (string) \"audio\", "
54 "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
55 "clock-rate = (int) [ 1, MAX ], "
56 /* "channels = (int) [1, MAX]" */
57 /* "emphasis = (string) ANY" */
58 /* "channel-order = (string) ANY" */
59 "encoding-name = (string) \"L16\";"
61 "media = (string) \"audio\", "
62 "payload = (int) { " GST_RTP_PAYLOAD_L16_STEREO_STRING ", "
63 GST_RTP_PAYLOAD_L16_MONO_STRING " }," "clock-rate = (int) [ 1, MAX ]"
64 /* "channels = (int) [1, MAX]" */
65 /* "emphasis = (string) ANY" */
66 /* "channel-order = (string) ANY" */
70 GST_BOILERPLATE (GstRtpL16Depay, gst_rtp_L16_depay, GstBaseRTPDepayload,
71 GST_TYPE_BASE_RTP_DEPAYLOAD);
73 static gboolean gst_rtp_L16_depay_setcaps (GstBaseRTPDepayload * depayload,
75 static GstBuffer *gst_rtp_L16_depay_process (GstBaseRTPDepayload * depayload,
79 gst_rtp_L16_depay_base_init (gpointer klass)
81 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
83 gst_element_class_add_static_pad_template (element_class,
84 &gst_rtp_L16_depay_src_template);
85 gst_element_class_add_static_pad_template (element_class,
86 &gst_rtp_L16_depay_sink_template);
88 gst_element_class_set_details_simple (element_class, "RTP audio depayloader",
89 "Codec/Depayloader/Network/RTP",
90 "Extracts raw audio from RTP packets",
91 "Zeeshan Ali <zak147@yahoo.com>," "Wim Taymans <wim.taymans@gmail.com>");
95 gst_rtp_L16_depay_class_init (GstRtpL16DepayClass * klass)
97 GstBaseRTPDepayloadClass *gstbasertpdepayload_class;
99 gstbasertpdepayload_class = (GstBaseRTPDepayloadClass *) klass;
101 gstbasertpdepayload_class->set_caps = gst_rtp_L16_depay_setcaps;
102 gstbasertpdepayload_class->process = gst_rtp_L16_depay_process;
104 GST_DEBUG_CATEGORY_INIT (rtpL16depay_debug, "rtpL16depay", 0,
105 "Raw Audio RTP Depayloader");
109 gst_rtp_L16_depay_init (GstRtpL16Depay * rtpL16depay,
110 GstRtpL16DepayClass * klass)
112 /* needed because of GST_BOILERPLATE */
116 gst_rtp_L16_depay_parse_int (GstStructure * structure, const gchar * field,
122 if ((str = gst_structure_get_string (structure, field)))
125 if (gst_structure_get_int (structure, field, &res))
132 gst_rtp_L16_depay_setcaps (GstBaseRTPDepayload * depayload, GstCaps * caps)
134 GstStructure *structure;
135 GstRtpL16Depay *rtpL16depay;
136 gint clock_rate, payload;
140 const gchar *channel_order;
141 const GstRTPChannelOrder *order;
143 rtpL16depay = GST_RTP_L16_DEPAY (depayload);
145 structure = gst_caps_get_structure (caps, 0);
148 gst_structure_get_int (structure, "payload", &payload);
150 case GST_RTP_PAYLOAD_L16_STEREO:
154 case GST_RTP_PAYLOAD_L16_MONO:
159 /* no fixed mapping, we need clock-rate */
165 /* caps can overwrite defaults */
167 gst_rtp_L16_depay_parse_int (structure, "clock-rate", clock_rate);
172 gst_rtp_L16_depay_parse_int (structure, "encoding-params", channels);
174 channels = gst_rtp_L16_depay_parse_int (structure, "channels", channels);
176 /* channels defaults to 1 otherwise */
181 depayload->clock_rate = clock_rate;
182 rtpL16depay->rate = clock_rate;
183 rtpL16depay->channels = channels;
185 srccaps = gst_caps_new_simple ("audio/x-raw-int",
186 "endianness", G_TYPE_INT, G_BIG_ENDIAN,
187 "signed", G_TYPE_BOOLEAN, TRUE,
188 "width", G_TYPE_INT, 16,
189 "depth", G_TYPE_INT, 16,
190 "rate", G_TYPE_INT, clock_rate, "channels", G_TYPE_INT, channels, NULL);
192 /* add channel positions */
193 channel_order = gst_structure_get_string (structure, "channel-order");
195 order = gst_rtp_channels_get_by_order (channels, channel_order);
197 gst_audio_set_channel_positions (gst_caps_get_structure (srccaps, 0),
200 GstAudioChannelPosition *pos;
202 GST_ELEMENT_WARNING (rtpL16depay, STREAM, DECODE,
203 (NULL), ("Unknown channel order '%s' for %d channels",
204 GST_STR_NULL (channel_order), channels));
205 /* create default NONE layout */
206 pos = gst_rtp_channels_create_default (channels);
207 gst_audio_set_channel_positions (gst_caps_get_structure (srccaps, 0), pos);
211 res = gst_pad_set_caps (depayload->srcpad, srccaps);
212 gst_caps_unref (srccaps);
219 GST_ERROR_OBJECT (depayload, "no clock-rate specified");
225 gst_rtp_L16_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
227 GstRtpL16Depay *rtpL16depay;
232 rtpL16depay = GST_RTP_L16_DEPAY (depayload);
234 payload_len = gst_rtp_buffer_get_payload_len (buf);
236 if (payload_len <= 0)
239 GST_DEBUG_OBJECT (rtpL16depay, "got payload of %d bytes", payload_len);
241 outbuf = gst_rtp_buffer_get_payload_buffer (buf);
242 marker = gst_rtp_buffer_get_marker (buf);
245 /* mark talk spurt with DISCONT */
246 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
254 GST_ELEMENT_WARNING (rtpL16depay, STREAM, DECODE,
255 ("Empty Payload."), (NULL));
261 gst_rtp_L16_depay_plugin_init (GstPlugin * plugin)
263 return gst_element_register (plugin, "rtpL16depay",
264 GST_RANK_SECONDARY, GST_TYPE_RTP_L16_DEPAY);