3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Library General Public
5 * License as published by the Free Software Foundation; either
6 * version 2 of the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Library General Public License for more details.
13 * You should have received a copy of the GNU Library General Public
14 * License along with this library; if not, write to the
15 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
16 * Boston, MA 02110-1301, USA.
23 #include <gst/rtp/gstrtpbuffer.h>
27 #include "gstrtpg729depay.h"
29 GST_DEBUG_CATEGORY_STATIC (rtpg729depay_debug);
30 #define GST_CAT_DEFAULT (rtpg729depay_debug)
49 /* input is an RTP packet
52 static GstStaticPadTemplate gst_rtp_g729_depay_sink_template =
53 GST_STATIC_PAD_TEMPLATE ("sink",
56 GST_STATIC_CAPS ("application/x-rtp, "
57 "media = (string) \"audio\", "
58 "clock-rate = (int) 8000, "
59 "encoding-name = (string) \"G729\"; "
61 "media = (string) \"audio\", "
62 "payload = (int) " GST_RTP_PAYLOAD_G729_STRING ", "
63 "clock-rate = (int) 8000")
66 static GstStaticPadTemplate gst_rtp_g729_depay_src_template =
67 GST_STATIC_PAD_TEMPLATE ("src",
70 GST_STATIC_CAPS ("audio/G729, " "channels = (int) 1," "rate = (int) 8000")
73 static gboolean gst_rtp_g729_depay_setcaps (GstRTPBaseDepayload * depayload,
75 static GstBuffer *gst_rtp_g729_depay_process (GstRTPBaseDepayload * depayload,
78 #define gst_rtp_g729_depay_parent_class parent_class
79 G_DEFINE_TYPE (GstRtpG729Depay, gst_rtp_g729_depay,
80 GST_TYPE_RTP_BASE_DEPAYLOAD);
83 gst_rtp_g729_depay_class_init (GstRtpG729DepayClass * klass)
85 GstElementClass *gstelement_class;
86 GstRTPBaseDepayloadClass *gstrtpbasedepayload_class;
88 GST_DEBUG_CATEGORY_INIT (rtpg729depay_debug, "rtpg729depay", 0,
89 "G.729 RTP Depayloader");
91 gstelement_class = (GstElementClass *) klass;
92 gstrtpbasedepayload_class = (GstRTPBaseDepayloadClass *) klass;
94 gst_element_class_add_pad_template (gstelement_class,
95 gst_static_pad_template_get (&gst_rtp_g729_depay_src_template));
96 gst_element_class_add_pad_template (gstelement_class,
97 gst_static_pad_template_get (&gst_rtp_g729_depay_sink_template));
99 gst_element_class_set_static_metadata (gstelement_class,
100 "RTP G.729 depayloader", "Codec/Depayloader/Network/RTP",
101 "Extracts G.729 audio from RTP packets (RFC 3551)",
102 "Laurent Glayal <spglegle@yahoo.fr>");
104 gstrtpbasedepayload_class->process = gst_rtp_g729_depay_process;
105 gstrtpbasedepayload_class->set_caps = gst_rtp_g729_depay_setcaps;
109 gst_rtp_g729_depay_init (GstRtpG729Depay * rtpg729depay)
111 GstRTPBaseDepayload *depayload;
113 depayload = GST_RTP_BASE_DEPAYLOAD (rtpg729depay);
115 gst_pad_use_fixed_caps (GST_RTP_BASE_DEPAYLOAD_SRCPAD (depayload));
119 gst_rtp_g729_depay_setcaps (GstRTPBaseDepayload * depayload, GstCaps * caps)
121 GstStructure *structure;
123 GstRtpG729Depay *rtpg729depay;
125 gint clock_rate, channels;
128 rtpg729depay = GST_RTP_G729_DEPAY (depayload);
130 structure = gst_caps_get_structure (caps, 0);
132 if (!(params = gst_structure_get_string (structure, "encoding-params")))
135 channels = atoi (params);
138 if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
144 if (clock_rate != 8000)
145 goto wrong_clock_rate;
147 depayload->clock_rate = clock_rate;
149 srccaps = gst_caps_new_simple ("audio/G729",
150 "channels", G_TYPE_INT, channels, "rate", G_TYPE_INT, clock_rate, NULL);
151 ret = gst_pad_set_caps (GST_RTP_BASE_DEPAYLOAD_SRCPAD (depayload), srccaps);
152 gst_caps_unref (srccaps);
159 GST_DEBUG_OBJECT (rtpg729depay, "expected 1 channel, got %d", channels);
164 GST_DEBUG_OBJECT (rtpg729depay, "expected 8000 clock-rate, got %d",
171 gst_rtp_g729_depay_process (GstRTPBaseDepayload * depayload, GstBuffer * buf)
173 GstRtpG729Depay *rtpg729depay;
174 GstBuffer *outbuf = NULL;
177 GstRTPBuffer rtp = { NULL };
179 rtpg729depay = GST_RTP_G729_DEPAY (depayload);
181 gst_rtp_buffer_map (buf, GST_MAP_READ, &rtp);
183 payload_len = gst_rtp_buffer_get_payload_len (&rtp);
185 /* At least 2 bytes (CNG from G729 Annex B) */
186 if (payload_len < 2) {
187 GST_ELEMENT_WARNING (rtpg729depay, STREAM, DECODE,
188 (NULL), ("G729 RTP payload too small (%d)", payload_len));
192 GST_LOG_OBJECT (rtpg729depay, "payload len %d", payload_len);
194 if ((payload_len % 10) == 2) {
195 GST_LOG_OBJECT (rtpg729depay, "G729 payload contains CNG frame");
198 outbuf = gst_rtp_buffer_get_payload_buffer (&rtp);
199 marker = gst_rtp_buffer_get_marker (&rtp);
201 gst_rtp_buffer_unmap (&rtp);
204 /* marker bit starts talkspurt */
205 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_RESYNC);
208 GST_LOG_OBJECT (depayload, "pushing buffer of size %" G_GSIZE_FORMAT,
209 gst_buffer_get_size (outbuf));
222 gst_rtp_g729_depay_plugin_init (GstPlugin * plugin)
224 return gst_element_register (plugin, "rtpg729depay",
225 GST_RANK_SECONDARY, GST_TYPE_RTP_G729_DEPAY);