3 * Copyright (C) <2010> Wim Taymans <wim.taymans@gmail.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
25 #include <gst/rtp/gstrtpbuffer.h>
29 #include "gstrtpg723depay.h"
31 GST_DEBUG_CATEGORY_STATIC (rtpg723depay_debug);
32 #define GST_CAT_DEFAULT (rtpg723depay_debug)
51 /* input is an RTP packet
54 static GstStaticPadTemplate gst_rtp_g723_depay_sink_template =
55 GST_STATIC_PAD_TEMPLATE ("sink",
58 GST_STATIC_CAPS ("application/x-rtp, "
59 "media = (string) \"audio\", "
60 "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
61 "clock-rate = (int) 8000, "
62 "encoding-name = (string) \"G723\"; "
64 "media = (string) \"audio\", "
65 "payload = (int) " GST_RTP_PAYLOAD_G723_STRING ", "
66 "clock-rate = (int) 8000")
69 static GstStaticPadTemplate gst_rtp_g723_depay_src_template =
70 GST_STATIC_PAD_TEMPLATE ("src",
73 GST_STATIC_CAPS ("audio/G723, " "channels = (int) 1," "rate = (int) 8000")
76 static gboolean gst_rtp_g723_depay_setcaps (GstBaseRTPDepayload * depayload,
78 static GstBuffer *gst_rtp_g723_depay_process (GstBaseRTPDepayload * depayload,
81 GST_BOILERPLATE (GstRtpG723Depay, gst_rtp_g723_depay, GstBaseRTPDepayload,
82 GST_TYPE_BASE_RTP_DEPAYLOAD);
85 gst_rtp_g723_depay_base_init (gpointer klass)
87 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
89 gst_element_class_add_static_pad_template (element_class,
90 &gst_rtp_g723_depay_src_template);
91 gst_element_class_add_static_pad_template (element_class,
92 &gst_rtp_g723_depay_sink_template);
94 gst_element_class_set_details_simple (element_class, "RTP G.723 depayloader",
95 "Codec/Depayloader/Network/RTP",
96 "Extracts G.723 audio from RTP packets (RFC 3551)",
97 "Wim Taymans <wim.taymans@gmail.com>");
99 GST_DEBUG_CATEGORY_INIT (rtpg723depay_debug, "rtpg723depay", 0,
100 "G.723 RTP Depayloader");
104 gst_rtp_g723_depay_class_init (GstRtpG723DepayClass * klass)
106 GstBaseRTPDepayloadClass *gstbasertpdepayload_class;
108 gstbasertpdepayload_class = (GstBaseRTPDepayloadClass *) klass;
110 gstbasertpdepayload_class->process = gst_rtp_g723_depay_process;
111 gstbasertpdepayload_class->set_caps = gst_rtp_g723_depay_setcaps;
115 gst_rtp_g723_depay_init (GstRtpG723Depay * rtpg723depay,
116 GstRtpG723DepayClass * klass)
118 GstBaseRTPDepayload *depayload;
120 depayload = GST_BASE_RTP_DEPAYLOAD (rtpg723depay);
122 gst_pad_use_fixed_caps (GST_BASE_RTP_DEPAYLOAD_SRCPAD (depayload));
126 gst_rtp_g723_depay_setcaps (GstBaseRTPDepayload * depayload, GstCaps * caps)
128 GstStructure *structure;
130 GstRtpG723Depay *rtpg723depay;
132 gint clock_rate, channels;
135 rtpg723depay = GST_RTP_G723_DEPAY (depayload);
137 structure = gst_caps_get_structure (caps, 0);
139 if (!(params = gst_structure_get_string (structure, "encoding-params")))
142 channels = atoi (params);
145 if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
151 if (clock_rate != 8000)
152 goto wrong_clock_rate;
154 depayload->clock_rate = clock_rate;
156 srccaps = gst_caps_new_simple ("audio/G723",
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);
166 GST_DEBUG_OBJECT (rtpg723depay, "expected 1 channel, got %d", channels);
171 GST_DEBUG_OBJECT (rtpg723depay, "expected 8000 clock-rate, got %d",
179 gst_rtp_g723_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
181 GstRtpG723Depay *rtpg723depay;
182 GstBuffer *outbuf = NULL;
186 rtpg723depay = GST_RTP_G723_DEPAY (depayload);
188 payload_len = gst_rtp_buffer_get_payload_len (buf);
190 /* At least 4 bytes */
194 GST_LOG_OBJECT (rtpg723depay, "payload len %d", payload_len);
196 outbuf = gst_rtp_buffer_get_payload_buffer (buf);
197 marker = gst_rtp_buffer_get_marker (buf);
200 /* marker bit starts talkspurt */
201 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
204 GST_LOG_OBJECT (depayload, "pushing buffer of size %d",
205 GST_BUFFER_SIZE (outbuf));
212 GST_ELEMENT_WARNING (rtpg723depay, STREAM, DECODE,
213 (NULL), ("G723 RTP payload too small (%d)", payload_len));
224 gst_rtp_g723_depay_plugin_init (GstPlugin * plugin)
226 return gst_element_register (plugin, "rtpg723depay",
227 GST_RANK_SECONDARY, GST_TYPE_RTP_G723_DEPAY);