2 * Copyright (C) <2005> Edgard Lima <edgard.lima@indt.org.br>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
26 #include <gst/rtp/gstrtpbuffer.h>
28 #include "gstrtpspeexdepay.h"
30 /* elementfactory information */
31 static const GstElementDetails gst_rtp_speexdepay_details =
32 GST_ELEMENT_DETAILS ("RTP Speex depayloader",
33 "Codec/Depayloader/Network",
34 "Extracts Speex audio from RTP packets",
35 "Edgard Lima <edgard.lima@indt.org.br>");
37 /* RtpSPEEXDepay signals and args */
49 static GstStaticPadTemplate gst_rtp_speex_depay_sink_template =
50 GST_STATIC_PAD_TEMPLATE ("sink",
53 GST_STATIC_CAPS ("application/x-rtp, "
54 "media = (string) \"audio\", "
55 "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
56 "clock-rate = (int) [6000, 48000], "
57 "encoding-name = (string) \"SPEEX\", "
58 "encoding-params = (string) \"1\"")
61 static GstStaticPadTemplate gst_rtp_speex_depay_src_template =
62 GST_STATIC_PAD_TEMPLATE ("src",
65 GST_STATIC_CAPS ("audio/x-speex")
68 static GstBuffer *gst_rtp_speex_depay_process (GstBaseRTPDepayload * depayload,
70 static gboolean gst_rtp_speex_depay_setcaps (GstBaseRTPDepayload * depayload,
73 GST_BOILERPLATE (GstRtpSPEEXDepay, gst_rtp_speex_depay, GstBaseRTPDepayload,
74 GST_TYPE_BASE_RTP_DEPAYLOAD);
77 gst_rtp_speex_depay_base_init (gpointer klass)
79 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
81 gst_element_class_add_pad_template (element_class,
82 gst_static_pad_template_get (&gst_rtp_speex_depay_src_template));
83 gst_element_class_add_pad_template (element_class,
84 gst_static_pad_template_get (&gst_rtp_speex_depay_sink_template));
85 gst_element_class_set_details (element_class, &gst_rtp_speexdepay_details);
89 gst_rtp_speex_depay_class_init (GstRtpSPEEXDepayClass * klass)
91 GstBaseRTPDepayloadClass *gstbasertpdepayload_class;
93 gstbasertpdepayload_class = (GstBaseRTPDepayloadClass *) klass;
95 gstbasertpdepayload_class->process = gst_rtp_speex_depay_process;
96 gstbasertpdepayload_class->set_caps = gst_rtp_speex_depay_setcaps;
100 gst_rtp_speex_depay_init (GstRtpSPEEXDepay * rtpspeexdepay,
101 GstRtpSPEEXDepayClass * klass)
106 gst_rtp_speex_depay_get_mode (gint rate)
110 else if (rate > 12500)
117 * vendor string (len bytes),
118 * user_len 4 (0) bytes LE
120 static const gchar gst_rtp_speex_comment[] =
121 "\045\0\0\0Depayloaded with GStreamer speexdepay\0\0\0\0";
124 gst_rtp_speex_depay_setcaps (GstBaseRTPDepayload * depayload, GstCaps * caps)
126 GstStructure *structure;
127 GstRtpSPEEXDepay *rtpspeexdepay;
128 gint clock_rate, nb_channels;
135 rtpspeexdepay = GST_RTP_SPEEX_DEPAY (depayload);
137 structure = gst_caps_get_structure (caps, 0);
139 if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
141 depayload->clock_rate = clock_rate;
143 if (!(params = gst_structure_get_string (structure, "encoding-params")))
146 nb_channels = atoi (params);
149 /* construct minimal header and comment packet for the decoder */
150 buf = gst_buffer_new_and_alloc (80);
151 data = GST_BUFFER_DATA (buf);
152 memcpy (data, "Speex ", 8);
154 memcpy (data, "1.1.12", 7);
156 GST_WRITE_UINT32_LE (data, 1); /* version */
158 GST_WRITE_UINT32_LE (data, 80); /* header_size */
160 GST_WRITE_UINT32_LE (data, clock_rate); /* rate */
162 GST_WRITE_UINT32_LE (data, gst_rtp_speex_depay_get_mode (clock_rate)); /* mode */
164 GST_WRITE_UINT32_LE (data, 4); /* mode_bitstream_version */
166 GST_WRITE_UINT32_LE (data, nb_channels); /* nb_channels */
168 GST_WRITE_UINT32_LE (data, -1); /* bitrate */
170 GST_WRITE_UINT32_LE (data, 0xa0); /* frame_size */
172 GST_WRITE_UINT32_LE (data, 0); /* VBR */
174 GST_WRITE_UINT32_LE (data, 1); /* frames_per_packet */
176 GST_WRITE_UINT32_LE (data, 0); /* extra_headers */
178 GST_WRITE_UINT32_LE (data, 0); /* reserved1 */
180 GST_WRITE_UINT32_LE (data, 0); /* reserved2 */
182 srccaps = gst_caps_new_simple ("audio/x-speex", NULL);
183 res = gst_pad_set_caps (depayload->srcpad, srccaps);
184 gst_caps_unref (srccaps);
186 gst_buffer_set_caps (buf, GST_PAD_CAPS (depayload->srcpad));
187 gst_base_rtp_depayload_push (GST_BASE_RTP_DEPAYLOAD (rtpspeexdepay), buf);
189 buf = gst_buffer_new_and_alloc (sizeof (gst_rtp_speex_comment));
190 memcpy (GST_BUFFER_DATA (buf), gst_rtp_speex_comment,
191 sizeof (gst_rtp_speex_comment));
193 gst_buffer_set_caps (buf, GST_PAD_CAPS (depayload->srcpad));
194 gst_base_rtp_depayload_push (GST_BASE_RTP_DEPAYLOAD (rtpspeexdepay), buf);
201 GST_DEBUG_OBJECT (depayload, "no clock-rate specified");
207 gst_rtp_speex_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
209 GstBuffer *outbuf = NULL;
211 GST_DEBUG ("process : got %d bytes, mark %d ts %u seqn %d",
212 GST_BUFFER_SIZE (buf),
213 gst_rtp_buffer_get_marker (buf),
214 gst_rtp_buffer_get_timestamp (buf), gst_rtp_buffer_get_seq (buf));
216 /* nothing special to be done */
217 outbuf = gst_rtp_buffer_get_payload_buffer (buf);
219 GST_BUFFER_DURATION (outbuf) = 20 * GST_MSECOND;
225 gst_rtp_speex_depay_plugin_init (GstPlugin * plugin)
227 return gst_element_register (plugin, "rtpspeexdepay",
228 GST_RANK_MARGINAL, GST_TYPE_RTP_SPEEX_DEPAY);