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., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
21 * SECTION:element-rtpL24depay
22 * @see_also: rtpL24pay
24 * Extract raw audio from RTP packets according to RFC 3190, section 4.
25 * For detailed information see: http://www.rfc-editor.org/rfc/rfc3190.txt
28 * <title>Example pipeline</title>
30 * gst-launch udpsrc caps='application/x-rtp, media=(string)audio, clock-rate=(int)44100, encoding-name=(string)L24, encoding-params=(string)1, channels=(int)1, payload=(int)96' ! rtpL24depay ! pulsesink
31 * ]| This example pipeline will depayload an RTP raw audio stream. Refer to
32 * the rtpL24pay example to create the RTP stream.
43 #include <gst/audio/audio.h>
45 #include "gstrtpL24depay.h"
46 #include "gstrtpchannels.h"
48 GST_DEBUG_CATEGORY_STATIC (rtpL24depay_debug);
49 #define GST_CAT_DEFAULT (rtpL24depay_debug)
51 static GstStaticPadTemplate gst_rtp_L24_depay_src_template =
52 GST_STATIC_PAD_TEMPLATE ("src",
55 GST_STATIC_CAPS ("audio/x-raw, "
56 "format = (string) S24BE, "
57 "layout = (string) interleaved, "
58 "rate = (int) [ 1, MAX ], " "channels = (int) [ 1, MAX ]")
61 static GstStaticPadTemplate gst_rtp_L24_depay_sink_template =
62 GST_STATIC_PAD_TEMPLATE ("sink",
65 GST_STATIC_CAPS ("application/x-rtp, "
66 "media = (string) \"audio\", " "clock-rate = (int) [ 1, MAX ], "
67 "encoding-name = (string) \"L24\"")
70 #define gst_rtp_L24_depay_parent_class parent_class
71 G_DEFINE_TYPE (GstRtpL24Depay, gst_rtp_L24_depay, GST_TYPE_RTP_BASE_DEPAYLOAD);
73 static gboolean gst_rtp_L24_depay_setcaps (GstRTPBaseDepayload * depayload,
75 static GstBuffer *gst_rtp_L24_depay_process (GstRTPBaseDepayload * depayload,
79 gst_rtp_L24_depay_class_init (GstRtpL24DepayClass * klass)
81 GstElementClass *gstelement_class;
82 GstRTPBaseDepayloadClass *gstrtpbasedepayload_class;
84 gstelement_class = (GstElementClass *) klass;
85 gstrtpbasedepayload_class = (GstRTPBaseDepayloadClass *) klass;
87 gstrtpbasedepayload_class->set_caps = gst_rtp_L24_depay_setcaps;
88 gstrtpbasedepayload_class->process = gst_rtp_L24_depay_process;
90 gst_element_class_add_pad_template (gstelement_class,
91 gst_static_pad_template_get (&gst_rtp_L24_depay_src_template));
92 gst_element_class_add_pad_template (gstelement_class,
93 gst_static_pad_template_get (&gst_rtp_L24_depay_sink_template));
95 gst_element_class_set_static_metadata (gstelement_class,
96 "RTP audio depayloader", "Codec/Depayloader/Network/RTP",
97 "Extracts raw 24-bit audio from RTP packets",
98 "Zeeshan Ali <zak147@yahoo.com>," "Wim Taymans <wim.taymans@gmail.com>,"
99 "David Holroyd <dave@badgers-in-foil.co.uk>");
101 GST_DEBUG_CATEGORY_INIT (rtpL24depay_debug, "rtpL24depay", 0,
102 "Raw Audio RTP Depayloader");
106 gst_rtp_L24_depay_init (GstRtpL24Depay * rtpL24depay)
111 gst_rtp_L24_depay_parse_int (GstStructure * structure, const gchar * field,
117 if ((str = gst_structure_get_string (structure, field)))
120 if (gst_structure_get_int (structure, field, &res))
127 gst_rtp_L24_depay_setcaps (GstRTPBaseDepayload * depayload, GstCaps * caps)
129 GstStructure *structure;
130 GstRtpL24Depay *rtpL24depay;
131 gint clock_rate, payload;
135 const gchar *channel_order;
136 const GstRTPChannelOrder *order;
139 rtpL24depay = GST_RTP_L24_DEPAY (depayload);
141 structure = gst_caps_get_structure (caps, 0);
144 gst_structure_get_int (structure, "payload", &payload);
145 /* no fixed mapping, we need clock-rate */
149 /* caps can overwrite defaults */
151 gst_rtp_L24_depay_parse_int (structure, "clock-rate", clock_rate);
156 gst_rtp_L24_depay_parse_int (structure, "encoding-params", channels);
158 channels = gst_rtp_L24_depay_parse_int (structure, "channels", channels);
160 /* channels defaults to 1 otherwise */
165 depayload->clock_rate = clock_rate;
167 info = &rtpL24depay->info;
168 gst_audio_info_init (info);
169 info->finfo = gst_audio_format_get_info (GST_AUDIO_FORMAT_S24BE);
170 info->rate = clock_rate;
171 info->channels = channels;
172 info->bpf = (info->finfo->width / 8) * channels;
174 /* add channel positions */
175 channel_order = gst_structure_get_string (structure, "channel-order");
177 order = gst_rtp_channels_get_by_order (channels, channel_order);
178 rtpL24depay->order = order;
180 memcpy (info->position, order->pos,
181 sizeof (GstAudioChannelPosition) * channels);
182 gst_audio_channel_positions_to_valid_order (info->position, info->channels);
184 GST_ELEMENT_WARNING (rtpL24depay, STREAM, DECODE,
185 (NULL), ("Unknown channel order '%s' for %d channels",
186 GST_STR_NULL (channel_order), channels));
187 /* create default NONE layout */
188 gst_rtp_channels_create_default (channels, info->position);
191 srccaps = gst_audio_info_to_caps (info);
192 res = gst_pad_set_caps (depayload->srcpad, srccaps);
193 gst_caps_unref (srccaps);
200 GST_ERROR_OBJECT (depayload, "no clock-rate specified");
206 gst_rtp_L24_depay_process (GstRTPBaseDepayload * depayload, GstBuffer * buf)
208 GstRtpL24Depay *rtpL24depay;
212 GstRTPBuffer rtp = { NULL };
214 rtpL24depay = GST_RTP_L24_DEPAY (depayload);
216 gst_rtp_buffer_map (buf, GST_MAP_READ, &rtp);
217 payload_len = gst_rtp_buffer_get_payload_len (&rtp);
219 if (payload_len <= 0)
222 GST_DEBUG_OBJECT (rtpL24depay, "got payload of %d bytes", payload_len);
224 outbuf = gst_rtp_buffer_get_payload_buffer (&rtp);
225 marker = gst_rtp_buffer_get_marker (&rtp);
228 /* mark talk spurt with RESYNC */
229 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_RESYNC);
232 outbuf = gst_buffer_make_writable (outbuf);
233 if (rtpL24depay->order &&
234 !gst_audio_buffer_reorder_channels (outbuf,
235 rtpL24depay->info.finfo->format, rtpL24depay->info.channels,
236 rtpL24depay->info.position, rtpL24depay->order->pos)) {
240 gst_rtp_buffer_unmap (&rtp);
247 GST_ELEMENT_WARNING (rtpL24depay, STREAM, DECODE,
248 ("Empty Payload."), (NULL));
249 gst_rtp_buffer_unmap (&rtp);
254 GST_ELEMENT_ERROR (rtpL24depay, STREAM, DECODE,
255 ("Channel reordering failed."), (NULL));
256 gst_rtp_buffer_unmap (&rtp);
262 gst_rtp_L24_depay_plugin_init (GstPlugin * plugin)
264 return gst_element_register (plugin, "rtpL24depay",
265 GST_RANK_SECONDARY, GST_TYPE_RTP_L24_DEPAY);