2 * Copyright (C) <2007> Wim Taymans <wim.taymans@gmail.com>
3 * Copyright (C) <2015> GE Intelligent Platforms Embedded Systems, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
22 * SECTION:element-rtpL8depay
25 * Extract raw audio from RTP packets according to RFC 3551.
26 * For detailed information see: http://www.rfc-editor.org/rfc/rfc3551.txt
29 * <title>Example pipeline</title>
31 * gst-launch udpsrc caps='application/x-rtp, media=(string)audio, clock-rate=(int)44100, encoding-name=(string)L8, encoding-params=(string)1, channels=(int)1, payload=(int)96' ! rtpL8depay ! pulsesink
32 * ]| This example pipeline will depayload an RTP raw audio stream. Refer to
33 * the rtpL8pay example to create the RTP stream.
44 #include <gst/audio/audio.h>
46 #include "gstrtpL8depay.h"
47 #include "gstrtpchannels.h"
49 GST_DEBUG_CATEGORY_STATIC (rtpL8depay_debug);
50 #define GST_CAT_DEFAULT (rtpL8depay_debug)
52 static GstStaticPadTemplate gst_rtp_L8_depay_src_template =
53 GST_STATIC_PAD_TEMPLATE ("src",
56 GST_STATIC_CAPS ("audio/x-raw, "
57 "format = (string) U8, "
58 "layout = (string) interleaved, "
59 "rate = (int) [ 1, MAX ], " "channels = (int) [ 1, MAX ]")
62 static GstStaticPadTemplate gst_rtp_L8_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 /* "channels = (int) [1, MAX]" */
69 /* "emphasis = (string) ANY" */
70 /* "channel-order = (string) ANY" */
71 "encoding-name = (string) L8;")
74 #define gst_rtp_L8_depay_parent_class parent_class
75 G_DEFINE_TYPE (GstRtpL8Depay, gst_rtp_L8_depay, GST_TYPE_RTP_BASE_DEPAYLOAD);
77 static gboolean gst_rtp_L8_depay_setcaps (GstRTPBaseDepayload * depayload,
79 static GstBuffer *gst_rtp_L8_depay_process (GstRTPBaseDepayload * depayload,
83 gst_rtp_L8_depay_class_init (GstRtpL8DepayClass * klass)
85 GstElementClass *gstelement_class;
86 GstRTPBaseDepayloadClass *gstrtpbasedepayload_class;
88 gstelement_class = (GstElementClass *) klass;
89 gstrtpbasedepayload_class = (GstRTPBaseDepayloadClass *) klass;
91 gstrtpbasedepayload_class->set_caps = gst_rtp_L8_depay_setcaps;
92 gstrtpbasedepayload_class->process = gst_rtp_L8_depay_process;
94 gst_element_class_add_pad_template (gstelement_class,
95 gst_static_pad_template_get (&gst_rtp_L8_depay_src_template));
96 gst_element_class_add_pad_template (gstelement_class,
97 gst_static_pad_template_get (&gst_rtp_L8_depay_sink_template));
99 gst_element_class_set_static_metadata (gstelement_class,
100 "RTP audio depayloader", "Codec/Depayloader/Network/RTP",
101 "Extracts raw audio from RTP packets",
102 "Zeeshan Ali <zak147@yahoo.com>," "Wim Taymans <wim.taymans@gmail.com>, "
103 "GE Intelligent Platforms Embedded Systems, Inc.");
105 GST_DEBUG_CATEGORY_INIT (rtpL8depay_debug, "rtpL8depay", 0,
106 "Raw Audio RTP Depayloader");
110 gst_rtp_L8_depay_init (GstRtpL8Depay * rtpL8depay)
115 gst_rtp_L8_depay_parse_int (GstStructure * structure, const gchar * field,
121 if ((str = gst_structure_get_string (structure, field)))
124 if (gst_structure_get_int (structure, field, &res))
131 gst_rtp_L8_depay_setcaps (GstRTPBaseDepayload * depayload, GstCaps * caps)
133 GstStructure *structure;
134 GstRtpL8Depay *rtpL8depay;
139 const gchar *channel_order;
140 const GstRTPChannelOrder *order;
143 rtpL8depay = GST_RTP_L8_DEPAY (depayload);
145 structure = gst_caps_get_structure (caps, 0);
147 /* no fixed mapping, we need clock-rate */
151 /* caps can overwrite defaults */
152 clock_rate = gst_rtp_L8_depay_parse_int (structure, "clock-rate", clock_rate);
157 gst_rtp_L8_depay_parse_int (structure, "encoding-params", channels);
159 channels = gst_rtp_L8_depay_parse_int (structure, "channels", channels);
161 /* channels defaults to 1 otherwise */
166 depayload->clock_rate = clock_rate;
168 info = &rtpL8depay->info;
169 gst_audio_info_init (info);
170 info->finfo = gst_audio_format_get_info (GST_AUDIO_FORMAT_U8);
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 rtpL8depay->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 (rtpL8depay, 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);
192 srccaps = gst_audio_info_to_caps (info);
193 res = gst_pad_set_caps (depayload->srcpad, srccaps);
194 gst_caps_unref (srccaps);
201 GST_ERROR_OBJECT (depayload, "no clock-rate specified");
207 gst_rtp_L8_depay_process (GstRTPBaseDepayload * depayload, GstBuffer * buf)
209 GstRtpL8Depay *rtpL8depay;
213 GstRTPBuffer rtp = { NULL };
215 rtpL8depay = GST_RTP_L8_DEPAY (depayload);
217 gst_rtp_buffer_map (buf, GST_MAP_READ, &rtp);
218 payload_len = gst_rtp_buffer_get_payload_len (&rtp);
220 if (payload_len <= 0)
223 GST_DEBUG_OBJECT (rtpL8depay, "got payload of %d bytes", payload_len);
225 outbuf = gst_rtp_buffer_get_payload_buffer (&rtp);
226 marker = gst_rtp_buffer_get_marker (&rtp);
229 /* mark talk spurt with RESYNC */
230 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_RESYNC);
233 outbuf = gst_buffer_make_writable (outbuf);
234 if (rtpL8depay->order &&
235 !gst_audio_buffer_reorder_channels (outbuf,
236 rtpL8depay->info.finfo->format, rtpL8depay->info.channels,
237 rtpL8depay->info.position, rtpL8depay->order->pos)) {
241 gst_rtp_buffer_unmap (&rtp);
248 GST_ELEMENT_WARNING (rtpL8depay, STREAM, DECODE,
249 ("Empty Payload."), (NULL));
250 gst_rtp_buffer_unmap (&rtp);
255 GST_ELEMENT_ERROR (rtpL8depay, STREAM, DECODE,
256 ("Channel reordering failed."), (NULL));
257 gst_rtp_buffer_unmap (&rtp);
263 gst_rtp_L8_depay_plugin_init (GstPlugin * plugin)
265 return gst_element_register (plugin, "rtpL8depay",
266 GST_RANK_SECONDARY, GST_TYPE_RTP_L8_DEPAY);