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., 59 Temple Place - Suite 330,
16 * Boston, MA 02111-1307, 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 "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
59 "clock-rate = (int) 8000, "
60 "encoding-name = (string) \"G729\"; "
62 "media = (string) \"audio\", "
63 "payload = (int) " GST_RTP_PAYLOAD_G729_STRING ", "
64 "clock-rate = (int) 8000")
67 static GstStaticPadTemplate gst_rtp_g729_depay_src_template =
68 GST_STATIC_PAD_TEMPLATE ("src",
71 GST_STATIC_CAPS ("audio/G729, " "channels = (int) 1," "rate = (int) 8000")
74 static gboolean gst_rtp_g729_depay_setcaps (GstBaseRTPDepayload * depayload,
76 static GstBuffer *gst_rtp_g729_depay_process (GstBaseRTPDepayload * depayload,
79 #define gst_rtp_g729_depay_parent_class parent_class
80 G_DEFINE_TYPE (GstRtpG729Depay, gst_rtp_g729_depay,
81 GST_TYPE_BASE_RTP_DEPAYLOAD);
84 gst_rtp_g729_depay_class_init (GstRtpG729DepayClass * klass)
86 GstElementClass *gstelement_class;
87 GstBaseRTPDepayloadClass *gstbasertpdepayload_class;
89 GST_DEBUG_CATEGORY_INIT (rtpg729depay_debug, "rtpg729depay", 0,
90 "G.729 RTP Depayloader");
92 gstelement_class = (GstElementClass *) klass;
93 gstbasertpdepayload_class = (GstBaseRTPDepayloadClass *) klass;
95 gst_element_class_add_pad_template (gstelement_class,
96 gst_static_pad_template_get (&gst_rtp_g729_depay_src_template));
97 gst_element_class_add_pad_template (gstelement_class,
98 gst_static_pad_template_get (&gst_rtp_g729_depay_sink_template));
100 gst_element_class_set_details_simple (gstelement_class,
101 "RTP G.729 depayloader", "Codec/Depayloader/Network/RTP",
102 "Extracts G.729 audio from RTP packets (RFC 3551)",
103 "Laurent Glayal <spglegle@yahoo.fr>");
105 gstbasertpdepayload_class->process = gst_rtp_g729_depay_process;
106 gstbasertpdepayload_class->set_caps = gst_rtp_g729_depay_setcaps;
110 gst_rtp_g729_depay_init (GstRtpG729Depay * rtpg729depay)
112 GstBaseRTPDepayload *depayload;
114 depayload = GST_BASE_RTP_DEPAYLOAD (rtpg729depay);
116 gst_pad_use_fixed_caps (GST_BASE_RTP_DEPAYLOAD_SRCPAD (depayload));
120 gst_rtp_g729_depay_setcaps (GstBaseRTPDepayload * depayload, GstCaps * caps)
122 GstStructure *structure;
124 GstRtpG729Depay *rtpg729depay;
126 gint clock_rate, channels;
129 rtpg729depay = GST_RTP_G729_DEPAY (depayload);
131 structure = gst_caps_get_structure (caps, 0);
133 if (!(params = gst_structure_get_string (structure, "encoding-params")))
136 channels = atoi (params);
139 if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
145 if (clock_rate != 8000)
146 goto wrong_clock_rate;
148 depayload->clock_rate = clock_rate;
150 srccaps = gst_caps_new_simple ("audio/G729",
151 "channels", G_TYPE_INT, channels, "rate", G_TYPE_INT, clock_rate, NULL);
152 ret = gst_pad_set_caps (GST_BASE_RTP_DEPAYLOAD_SRCPAD (depayload), srccaps);
153 gst_caps_unref (srccaps);
160 GST_DEBUG_OBJECT (rtpg729depay, "expected 1 channel, got %d", channels);
165 GST_DEBUG_OBJECT (rtpg729depay, "expected 8000 clock-rate, got %d",
172 gst_rtp_g729_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
174 GstRtpG729Depay *rtpg729depay;
175 GstBuffer *outbuf = NULL;
178 GstRTPBuffer rtp = { NULL };
180 rtpg729depay = GST_RTP_G729_DEPAY (depayload);
182 gst_rtp_buffer_map (buf, GST_MAP_READ, &rtp);
184 payload_len = gst_rtp_buffer_get_payload_len (&rtp);
186 /* At least 2 bytes (CNG from G729 Annex B) */
187 if (payload_len < 2) {
188 GST_ELEMENT_WARNING (rtpg729depay, STREAM, DECODE,
189 (NULL), ("G729 RTP payload too small (%d)", payload_len));
193 GST_LOG_OBJECT (rtpg729depay, "payload len %d", payload_len);
195 if ((payload_len % 10) == 2) {
196 GST_LOG_OBJECT (rtpg729depay, "G729 payload contains CNG frame");
199 outbuf = gst_rtp_buffer_get_payload_buffer (&rtp);
200 marker = gst_rtp_buffer_get_marker (&rtp);
202 gst_rtp_buffer_unmap (&rtp);
205 /* marker bit starts talkspurt */
206 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
209 GST_LOG_OBJECT (depayload, "pushing buffer of size %d",
210 gst_buffer_get_size (outbuf));
223 gst_rtp_g729_depay_plugin_init (GstPlugin * plugin)
225 return gst_element_register (plugin, "rtpg729depay",
226 GST_RANK_SECONDARY, GST_TYPE_RTP_G729_DEPAY);