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
23 * @see_also: rtpL24pay
25 * Extract raw audio from RTP packets according to RFC 3190, section 4.
26 * For detailed information see: http://www.rfc-editor.org/rfc/rfc3190.txt
30 * gst-launch-1.0 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"
47 #include "gstrtputils.h"
49 GST_DEBUG_CATEGORY_STATIC (rtpL24depay_debug);
50 #define GST_CAT_DEFAULT (rtpL24depay_debug)
52 static GstStaticPadTemplate gst_rtp_L24_depay_src_template =
53 GST_STATIC_PAD_TEMPLATE ("src",
56 GST_STATIC_CAPS ("audio/x-raw, "
57 "format = (string) S24BE, "
58 "layout = (string) interleaved, "
59 "rate = (int) [ 1, MAX ], " "channels = (int) [ 1, MAX ]")
62 static GstStaticPadTemplate gst_rtp_L24_depay_sink_template =
63 GST_STATIC_PAD_TEMPLATE ("sink",
66 GST_STATIC_CAPS ("application/x-rtp, "
67 "media = (string) \"audio\", " "clock-rate = (int) [ 1, MAX ], "
68 "encoding-name = (string) \"L24\"")
71 #define gst_rtp_L24_depay_parent_class parent_class
72 G_DEFINE_TYPE (GstRtpL24Depay, gst_rtp_L24_depay, GST_TYPE_RTP_BASE_DEPAYLOAD);
74 static gboolean gst_rtp_L24_depay_setcaps (GstRTPBaseDepayload * depayload,
76 static GstBuffer *gst_rtp_L24_depay_process (GstRTPBaseDepayload * depayload,
80 gst_rtp_L24_depay_class_init (GstRtpL24DepayClass * klass)
82 GstElementClass *gstelement_class;
83 GstRTPBaseDepayloadClass *gstrtpbasedepayload_class;
85 gstelement_class = (GstElementClass *) klass;
86 gstrtpbasedepayload_class = (GstRTPBaseDepayloadClass *) klass;
88 gstrtpbasedepayload_class->set_caps = gst_rtp_L24_depay_setcaps;
89 gstrtpbasedepayload_class->process_rtp_packet = gst_rtp_L24_depay_process;
91 gst_element_class_add_static_pad_template (gstelement_class,
92 &gst_rtp_L24_depay_src_template);
93 gst_element_class_add_static_pad_template (gstelement_class,
94 &gst_rtp_L24_depay_sink_template);
96 gst_element_class_set_static_metadata (gstelement_class,
97 "RTP audio depayloader", "Codec/Depayloader/Network/RTP",
98 "Extracts raw 24-bit audio from RTP packets",
99 "Zeeshan Ali <zak147@yahoo.com>," "Wim Taymans <wim.taymans@gmail.com>,"
100 "David Holroyd <dave@badgers-in-foil.co.uk>");
102 GST_DEBUG_CATEGORY_INIT (rtpL24depay_debug, "rtpL24depay", 0,
103 "Raw Audio RTP Depayloader");
107 gst_rtp_L24_depay_init (GstRtpL24Depay * rtpL24depay)
112 gst_rtp_L24_depay_parse_int (GstStructure * structure, const gchar * field,
118 if ((str = gst_structure_get_string (structure, field)))
121 if (gst_structure_get_int (structure, field, &res))
128 gst_rtp_L24_depay_setcaps (GstRTPBaseDepayload * depayload, GstCaps * caps)
130 GstStructure *structure;
131 GstRtpL24Depay *rtpL24depay;
132 gint clock_rate, payload;
136 const gchar *channel_order;
137 const GstRTPChannelOrder *order;
140 rtpL24depay = GST_RTP_L24_DEPAY (depayload);
142 structure = gst_caps_get_structure (caps, 0);
145 gst_structure_get_int (structure, "payload", &payload);
146 /* no fixed mapping, we need clock-rate */
150 /* caps can overwrite defaults */
152 gst_rtp_L24_depay_parse_int (structure, "clock-rate", clock_rate);
157 gst_rtp_L24_depay_parse_int (structure, "encoding-params", channels);
159 channels = gst_rtp_L24_depay_parse_int (structure, "channels", channels);
161 /* channels defaults to 1 otherwise */
166 depayload->clock_rate = clock_rate;
168 info = &rtpL24depay->info;
169 gst_audio_info_init (info);
170 info->finfo = gst_audio_format_get_info (GST_AUDIO_FORMAT_S24BE);
171 info->rate = clock_rate;
172 info->channels = channels;
173 info->bpf = (info->finfo->width / 8) * channels;
175 /* add channel positions */
176 channel_order = gst_structure_get_string (structure, "channel-order");
178 order = gst_rtp_channels_get_by_order (channels, channel_order);
179 rtpL24depay->order = order;
181 memcpy (info->position, order->pos,
182 sizeof (GstAudioChannelPosition) * channels);
183 gst_audio_channel_positions_to_valid_order (info->position, info->channels);
185 GST_ELEMENT_WARNING (rtpL24depay, STREAM, DECODE,
186 (NULL), ("Unknown channel order '%s' for %d channels",
187 GST_STR_NULL (channel_order), channels));
188 /* create default NONE layout */
189 gst_rtp_channels_create_default (channels, info->position);
190 info->flags |= GST_AUDIO_FLAG_UNPOSITIONED;
193 srccaps = gst_audio_info_to_caps (info);
194 res = gst_pad_set_caps (depayload->srcpad, srccaps);
195 gst_caps_unref (srccaps);
202 GST_ERROR_OBJECT (depayload, "no clock-rate specified");
208 gst_rtp_L24_depay_process (GstRTPBaseDepayload * depayload, GstRTPBuffer * rtp)
210 GstRtpL24Depay *rtpL24depay;
215 rtpL24depay = GST_RTP_L24_DEPAY (depayload);
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);
234 gst_rtp_drop_non_audio_meta (rtpL24depay, outbuf);
236 if (rtpL24depay->order &&
237 !gst_audio_buffer_reorder_channels (outbuf,
238 rtpL24depay->info.finfo->format, rtpL24depay->info.channels,
239 rtpL24depay->info.position, rtpL24depay->order->pos)) {
248 GST_ELEMENT_WARNING (rtpL24depay, STREAM, DECODE,
249 ("Empty Payload."), (NULL));
254 GST_ELEMENT_ERROR (rtpL24depay, STREAM, DECODE,
255 ("Channel reordering failed."), (NULL));
261 gst_rtp_L24_depay_plugin_init (GstPlugin * plugin)
263 return gst_element_register (plugin, "rtpL24depay",
264 GST_RANK_SECONDARY, GST_TYPE_RTP_L24_DEPAY);