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"
34 /* elementfactory information */
35 static const GstElementDetails gst_rtp_g729depay_details =
36 GST_ELEMENT_DETAILS ("RTP packet depayloader",
37 "Codec/Depayloader/Network",
38 "Extracts G729 audio from RTP packets (RFC 3551)",
39 "Laurent Glayal <spglegle@yahoo.fr>");
52 /* input is an RTP packet
55 static GstStaticPadTemplate gst_rtp_g729_depay_sink_template =
56 GST_STATIC_PAD_TEMPLATE ("sink",
59 GST_STATIC_CAPS ("application/x-rtp, "
60 "media = (string) \"audio\", "
61 "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
62 "clock-rate = (int) 8000, "
63 "encoding-name = (string) \"G729\"; "
65 "media = (string) \"audio\", "
66 "payload = (int) " GST_RTP_PAYLOAD_G729_STRING ", "
67 "clock-rate = (int) 8000")
70 static GstStaticPadTemplate gst_rtp_g729_depay_src_template =
71 GST_STATIC_PAD_TEMPLATE ("src",
74 GST_STATIC_CAPS ("audio/G729, " "channels = (int) 1," "rate = (int) 8000")
77 static gboolean gst_rtp_g729_depay_setcaps (GstBaseRTPDepayload * depayload,
79 static GstBuffer *gst_rtp_g729_depay_process (GstBaseRTPDepayload * depayload,
82 GST_BOILERPLATE (GstRtpG729Depay, gst_rtp_g729_depay, GstBaseRTPDepayload,
83 GST_TYPE_BASE_RTP_DEPAYLOAD);
86 gst_rtp_g729_depay_base_init (gpointer klass)
88 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
90 gst_element_class_add_pad_template (element_class,
91 gst_static_pad_template_get (&gst_rtp_g729_depay_src_template));
92 gst_element_class_add_pad_template (element_class,
93 gst_static_pad_template_get (&gst_rtp_g729_depay_sink_template));
95 gst_element_class_set_details (element_class, &gst_rtp_g729depay_details);
99 gst_rtp_g729_depay_class_init (GstRtpG729DepayClass * klass)
101 GObjectClass *gobject_class;
102 GstElementClass *gstelement_class;
103 GstBaseRTPDepayloadClass *gstbasertpdepayload_class;
105 gobject_class = (GObjectClass *) klass;
106 gstelement_class = (GstElementClass *) klass;
107 gstbasertpdepayload_class = (GstBaseRTPDepayloadClass *) klass;
109 parent_class = g_type_class_peek_parent (klass);
111 gstbasertpdepayload_class->process = gst_rtp_g729_depay_process;
112 gstbasertpdepayload_class->set_caps = gst_rtp_g729_depay_setcaps;
116 gst_rtp_g729_depay_init (GstRtpG729Depay * rtpg729depay,
117 GstRtpG729DepayClass * klass)
119 GstBaseRTPDepayload *depayload;
121 depayload = GST_BASE_RTP_DEPAYLOAD (rtpg729depay);
123 depayload->clock_rate = 8000;
124 gst_pad_use_fixed_caps (GST_BASE_RTP_DEPAYLOAD_SRCPAD (depayload));
128 gst_rtp_g729_depay_setcaps (GstBaseRTPDepayload * depayload, GstCaps * caps)
130 GstStructure *structure;
132 GstRtpG729Depay *rtpg729depay;
134 gint clock_rate, channels;
137 rtpg729depay = GST_RTP_G729_DEPAY (depayload);
139 structure = gst_caps_get_structure (caps, 0);
141 if (!(params = gst_structure_get_string (structure, "encoding-params")))
144 channels = atoi (params);
147 if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
153 if (clock_rate != 8000)
154 goto wrong_clock_rate;
156 srccaps = gst_caps_new_simple ("audio/G729",
157 "channels", G_TYPE_INT, channels, "rate", G_TYPE_INT, clock_rate, NULL);
158 ret = gst_pad_set_caps (GST_BASE_RTP_DEPAYLOAD_SRCPAD (depayload), srccaps);
159 gst_caps_unref (srccaps);
161 rtpg729depay->negotiated = ret;
168 GST_DEBUG_OBJECT (rtpg729depay, "expected 1 channel, got %d",
169 rtpg729depay->channels);
174 GST_DEBUG_OBJECT (rtpg729depay, "expected 8000 clock-rate, got %d",
182 gst_rtp_g729_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
184 GstRtpG729Depay *rtpg729depay;
185 GstBuffer *outbuf = NULL;
188 rtpg729depay = GST_RTP_G729_DEPAY (depayload);
190 if (!rtpg729depay->negotiated)
193 if (!gst_rtp_buffer_validate (buf)) {
194 GST_ELEMENT_WARNING (rtpg729depay, STREAM, DECODE,
195 (NULL), ("G729 RTP packet did not validate"));
199 payload_len = gst_rtp_buffer_get_payload_len (buf);
201 /* At least 2 bytes (CNG from G729 Annex B) */
202 if (payload_len < 2) {
203 GST_ELEMENT_WARNING (rtpg729depay, STREAM, DECODE,
204 (NULL), ("G729 RTP payload too small (%d)", payload_len));
208 GST_DEBUG_OBJECT (rtpg729depay, "payload len %d", payload_len);
210 if ((payload_len % 10) == 2) {
211 GST_DEBUG_OBJECT (rtpg729depay, "G729 payload contains CNG frame");
214 outbuf = gst_rtp_buffer_get_payload_buffer (buf);
216 GST_DEBUG ("gst_rtp_g729_depay_chain: pushing buffer of size %d",
217 GST_BUFFER_SIZE (outbuf));
224 GST_ELEMENT_ERROR (rtpg729depay, STREAM, NOT_IMPLEMENTED,
225 (NULL), ("not negotiated"));
236 gst_rtp_g729_depay_plugin_init (GstPlugin * plugin)
238 return gst_element_register (plugin, "rtpg729depay",
239 GST_RANK_MARGINAL, GST_TYPE_RTP_G729_DEPAY);