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>
24 #include <gst/audio/audio.h>
28 #include "gstrtpelements.h"
29 #include "gstrtpg729depay.h"
30 #include "gstrtputils.h"
32 GST_DEBUG_CATEGORY_STATIC (rtpg729depay_debug);
33 #define GST_CAT_DEFAULT (rtpg729depay_debug)
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 "clock-rate = (int) 8000, "
62 "encoding-name = (string) \"G729\"; "
64 "media = (string) \"audio\", "
65 "payload = (int) " GST_RTP_PAYLOAD_G729_STRING ", "
66 "clock-rate = (int) 8000")
69 static GstStaticPadTemplate gst_rtp_g729_depay_src_template =
70 GST_STATIC_PAD_TEMPLATE ("src",
73 GST_STATIC_CAPS ("audio/G729, " "channels = (int) 1," "rate = (int) 8000")
76 static gboolean gst_rtp_g729_depay_setcaps (GstRTPBaseDepayload * depayload,
78 static GstBuffer *gst_rtp_g729_depay_process (GstRTPBaseDepayload * depayload,
81 #define gst_rtp_g729_depay_parent_class parent_class
82 G_DEFINE_TYPE (GstRtpG729Depay, gst_rtp_g729_depay,
83 GST_TYPE_RTP_BASE_DEPAYLOAD);
84 GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (rtpg729depay, "rtpg729depay",
85 GST_RANK_SECONDARY, GST_TYPE_RTP_G729_DEPAY, rtp_element_init (plugin));
88 gst_rtp_g729_depay_class_init (GstRtpG729DepayClass * klass)
90 GstElementClass *gstelement_class;
91 GstRTPBaseDepayloadClass *gstrtpbasedepayload_class;
93 GST_DEBUG_CATEGORY_INIT (rtpg729depay_debug, "rtpg729depay", 0,
94 "G.729 RTP Depayloader");
96 gstelement_class = (GstElementClass *) klass;
97 gstrtpbasedepayload_class = (GstRTPBaseDepayloadClass *) klass;
99 gst_element_class_add_static_pad_template (gstelement_class,
100 &gst_rtp_g729_depay_src_template);
101 gst_element_class_add_static_pad_template (gstelement_class,
102 &gst_rtp_g729_depay_sink_template);
104 gst_element_class_set_static_metadata (gstelement_class,
105 "RTP G.729 depayloader", "Codec/Depayloader/Network/RTP",
106 "Extracts G.729 audio from RTP packets (RFC 3551)",
107 "Laurent Glayal <spglegle@yahoo.fr>");
109 gstrtpbasedepayload_class->process_rtp_packet = gst_rtp_g729_depay_process;
110 gstrtpbasedepayload_class->set_caps = gst_rtp_g729_depay_setcaps;
114 gst_rtp_g729_depay_init (GstRtpG729Depay * rtpg729depay)
116 GstRTPBaseDepayload *depayload;
118 depayload = GST_RTP_BASE_DEPAYLOAD (rtpg729depay);
120 gst_pad_use_fixed_caps (GST_RTP_BASE_DEPAYLOAD_SRCPAD (depayload));
124 gst_rtp_g729_depay_setcaps (GstRTPBaseDepayload * depayload, GstCaps * caps)
126 GstStructure *structure;
128 GstRtpG729Depay *rtpg729depay;
130 gint clock_rate, channels;
133 rtpg729depay = GST_RTP_G729_DEPAY (depayload);
135 structure = gst_caps_get_structure (caps, 0);
137 if (!(params = gst_structure_get_string (structure, "encoding-params")))
140 channels = atoi (params);
143 if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
149 if (clock_rate != 8000)
150 goto wrong_clock_rate;
152 depayload->clock_rate = clock_rate;
154 srccaps = gst_caps_new_simple ("audio/G729",
155 "channels", G_TYPE_INT, channels, "rate", G_TYPE_INT, clock_rate, NULL);
156 ret = gst_pad_set_caps (GST_RTP_BASE_DEPAYLOAD_SRCPAD (depayload), srccaps);
157 gst_caps_unref (srccaps);
164 GST_DEBUG_OBJECT (rtpg729depay, "expected 1 channel, got %d", channels);
169 GST_DEBUG_OBJECT (rtpg729depay, "expected 8000 clock-rate, got %d",
176 gst_rtp_g729_depay_process (GstRTPBaseDepayload * depayload, GstRTPBuffer * rtp)
178 GstRtpG729Depay *rtpg729depay;
179 GstBuffer *outbuf = NULL;
183 rtpg729depay = GST_RTP_G729_DEPAY (depayload);
185 payload_len = gst_rtp_buffer_get_payload_len (rtp);
187 /* At least 2 bytes (CNG from G729 Annex B) */
188 if (payload_len < 2) {
189 GST_ELEMENT_WARNING (rtpg729depay, STREAM, DECODE,
190 (NULL), ("G729 RTP payload too small (%d)", payload_len));
194 GST_LOG_OBJECT (rtpg729depay, "payload len %d", payload_len);
196 if ((payload_len % 10) == 2) {
197 GST_LOG_OBJECT (rtpg729depay, "G729 payload contains CNG frame");
200 outbuf = gst_rtp_buffer_get_payload_buffer (rtp);
201 marker = gst_rtp_buffer_get_marker (rtp);
204 /* marker bit starts talkspurt */
205 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_RESYNC);
208 gst_rtp_drop_non_audio_meta (depayload, outbuf);
210 GST_LOG_OBJECT (depayload, "pushing buffer of size %" G_GSIZE_FORMAT,
211 gst_buffer_get_size (outbuf));