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 "gstrtpg722depay.h"
31 #include "gstrtpchannels.h"
33 GST_DEBUG_CATEGORY_STATIC (rtpg722depay_debug);
34 #define GST_CAT_DEFAULT (rtpg722depay_debug)
36 static GstStaticPadTemplate gst_rtp_g722_depay_src_template =
37 GST_STATIC_PAD_TEMPLATE ("src",
40 GST_STATIC_CAPS ("audio/G722, "
41 "rate = (int) [ 1, MAX ], " "channels = (int) [ 1, MAX ]")
44 static GstStaticPadTemplate gst_rtp_g722_depay_sink_template =
45 GST_STATIC_PAD_TEMPLATE ("sink",
48 GST_STATIC_CAPS ("application/x-rtp, "
49 "media = (string) \"audio\", "
50 "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
51 "clock-rate = (int) 8000, "
52 /* "channels = (int) [1, MAX]" */
53 /* "channel-order = (string) ANY" */
54 "encoding-name = (string) \"G722\";"
56 "media = (string) \"audio\", "
57 "payload = (int) " GST_RTP_PAYLOAD_G722_STRING ", "
58 "clock-rate = (int) [ 1, MAX ]"
59 /* "channels = (int) [1, MAX]" */
60 /* "emphasis = (string) ANY" */
61 /* "channel-order = (string) ANY" */
65 GST_BOILERPLATE (GstRtpG722Depay, gst_rtp_g722_depay, GstBaseRTPDepayload,
66 GST_TYPE_BASE_RTP_DEPAYLOAD);
68 static gboolean gst_rtp_g722_depay_setcaps (GstBaseRTPDepayload * depayload,
70 static GstBuffer *gst_rtp_g722_depay_process (GstBaseRTPDepayload * depayload,
74 gst_rtp_g722_depay_base_init (gpointer klass)
76 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
78 gst_element_class_add_pad_template (element_class,
79 gst_static_pad_template_get (&gst_rtp_g722_depay_src_template));
80 gst_element_class_add_pad_template (element_class,
81 gst_static_pad_template_get (&gst_rtp_g722_depay_sink_template));
83 gst_element_class_set_details_simple (element_class, "RTP audio depayloader",
84 "Codec/Depayloader/Network/RTP",
85 "Extracts G722 audio from RTP packets",
86 "Wim Taymans <wim.taymans@gmail.com>");
90 gst_rtp_g722_depay_class_init (GstRtpG722DepayClass * klass)
92 GstBaseRTPDepayloadClass *gstbasertpdepayload_class;
94 gstbasertpdepayload_class = (GstBaseRTPDepayloadClass *) klass;
96 gstbasertpdepayload_class->set_caps = gst_rtp_g722_depay_setcaps;
97 gstbasertpdepayload_class->process = gst_rtp_g722_depay_process;
99 GST_DEBUG_CATEGORY_INIT (rtpg722depay_debug, "rtpg722depay", 0,
100 "G722 RTP Depayloader");
104 gst_rtp_g722_depay_init (GstRtpG722Depay * rtpg722depay,
105 GstRtpG722DepayClass * klass)
107 /* needed because of GST_BOILERPLATE */
111 gst_rtp_g722_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_g722_depay_setcaps (GstBaseRTPDepayload * depayload, GstCaps * caps)
129 GstStructure *structure;
130 GstRtpG722Depay *rtpg722depay;
131 gint clock_rate, payload, samplerate;
135 const gchar *channel_order;
136 const GstRTPChannelOrder *order;
138 rtpg722depay = GST_RTP_G722_DEPAY (depayload);
140 structure = gst_caps_get_structure (caps, 0);
143 gst_structure_get_int (structure, "payload", &payload);
145 case GST_RTP_PAYLOAD_G722:
151 /* no fixed mapping, we need clock-rate */
158 /* caps can overwrite defaults */
160 gst_rtp_g722_depay_parse_int (structure, "clock-rate", clock_rate);
164 if (clock_rate == 8000)
168 samplerate = clock_rate;
171 gst_rtp_g722_depay_parse_int (structure, "encoding-params", channels);
173 channels = gst_rtp_g722_depay_parse_int (structure, "channels", channels);
175 /* channels defaults to 1 otherwise */
180 depayload->clock_rate = clock_rate;
181 rtpg722depay->rate = samplerate;
182 rtpg722depay->channels = channels;
184 srccaps = gst_caps_new_simple ("audio/G722",
185 "rate", G_TYPE_INT, samplerate, "channels", G_TYPE_INT, channels, NULL);
187 /* add channel positions */
188 channel_order = gst_structure_get_string (structure, "channel-order");
190 order = gst_rtp_channels_get_by_order (channels, channel_order);
192 gst_audio_set_channel_positions (gst_caps_get_structure (srccaps, 0),
195 GstAudioChannelPosition *pos;
197 GST_ELEMENT_WARNING (rtpg722depay, STREAM, DECODE,
198 (NULL), ("Unknown channel order '%s' for %d channels",
199 GST_STR_NULL (channel_order), channels));
200 /* create default NONE layout */
201 pos = gst_rtp_channels_create_default (channels);
202 gst_audio_set_channel_positions (gst_caps_get_structure (srccaps, 0), pos);
206 res = gst_pad_set_caps (depayload->srcpad, srccaps);
207 gst_caps_unref (srccaps);
214 GST_ERROR_OBJECT (depayload, "no clock-rate specified");
220 gst_rtp_g722_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
222 GstRtpG722Depay *rtpg722depay;
227 rtpg722depay = GST_RTP_G722_DEPAY (depayload);
229 payload_len = gst_rtp_buffer_get_payload_len (buf);
231 if (payload_len <= 0)
234 GST_DEBUG_OBJECT (rtpg722depay, "got payload of %d bytes", payload_len);
236 outbuf = gst_rtp_buffer_get_payload_buffer (buf);
237 marker = gst_rtp_buffer_get_marker (buf);
240 /* mark talk spurt with DISCONT */
241 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
249 GST_ELEMENT_WARNING (rtpg722depay, STREAM, DECODE,
250 ("Empty Payload."), (NULL));
256 gst_rtp_g722_depay_plugin_init (GstPlugin * plugin)
258 return gst_element_register (plugin, "rtpg722depay",
259 GST_RANK_SECONDARY, GST_TYPE_RTP_G722_DEPAY);