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 /* RtpSPEEXDepay signals and args */
42 static GstStaticPadTemplate gst_rtp_speex_depay_sink_template =
43 GST_STATIC_PAD_TEMPLATE ("sink",
46 GST_STATIC_CAPS ("application/x-rtp, "
47 "media = (string) \"audio\", "
48 "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
49 "clock-rate = (int) [6000, 48000], "
50 "encoding-name = (string) \"SPEEX\", "
51 "encoding-params = (string) \"1\"")
54 static GstStaticPadTemplate gst_rtp_speex_depay_src_template =
55 GST_STATIC_PAD_TEMPLATE ("src",
58 GST_STATIC_CAPS ("audio/x-speex")
61 static GstBuffer *gst_rtp_speex_depay_process (GstBaseRTPDepayload * depayload,
63 static gboolean gst_rtp_speex_depay_setcaps (GstBaseRTPDepayload * depayload,
66 GST_BOILERPLATE (GstRtpSPEEXDepay, gst_rtp_speex_depay, GstBaseRTPDepayload,
67 GST_TYPE_BASE_RTP_DEPAYLOAD);
70 gst_rtp_speex_depay_base_init (gpointer klass)
72 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
74 gst_element_class_add_static_pad_template (element_class,
75 &gst_rtp_speex_depay_src_template);
76 gst_element_class_add_static_pad_template (element_class,
77 &gst_rtp_speex_depay_sink_template);
78 gst_element_class_set_details_simple (element_class, "RTP Speex depayloader",
79 "Codec/Depayloader/Network/RTP",
80 "Extracts Speex audio from RTP packets",
81 "Edgard Lima <edgard.lima@indt.org.br>");
85 gst_rtp_speex_depay_class_init (GstRtpSPEEXDepayClass * klass)
87 GstBaseRTPDepayloadClass *gstbasertpdepayload_class;
89 gstbasertpdepayload_class = (GstBaseRTPDepayloadClass *) klass;
91 gstbasertpdepayload_class->process = gst_rtp_speex_depay_process;
92 gstbasertpdepayload_class->set_caps = gst_rtp_speex_depay_setcaps;
96 gst_rtp_speex_depay_init (GstRtpSPEEXDepay * rtpspeexdepay,
97 GstRtpSPEEXDepayClass * klass)
102 gst_rtp_speex_depay_get_mode (gint rate)
106 else if (rate > 12500)
113 * vendor string (len bytes),
114 * user_len 4 (0) bytes LE
116 static const gchar gst_rtp_speex_comment[] =
117 "\045\0\0\0Depayloaded with GStreamer speexdepay\0\0\0\0";
120 gst_rtp_speex_depay_setcaps (GstBaseRTPDepayload * depayload, GstCaps * caps)
122 GstStructure *structure;
123 GstRtpSPEEXDepay *rtpspeexdepay;
124 gint clock_rate, nb_channels;
131 rtpspeexdepay = GST_RTP_SPEEX_DEPAY (depayload);
133 structure = gst_caps_get_structure (caps, 0);
135 if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
137 depayload->clock_rate = clock_rate;
139 if (!(params = gst_structure_get_string (structure, "encoding-params")))
142 nb_channels = atoi (params);
145 /* construct minimal header and comment packet for the decoder */
146 buf = gst_buffer_new_and_alloc (80);
147 data = GST_BUFFER_DATA (buf);
148 memcpy (data, "Speex ", 8);
150 memcpy (data, "1.1.12", 7);
152 GST_WRITE_UINT32_LE (data, 1); /* version */
154 GST_WRITE_UINT32_LE (data, 80); /* header_size */
156 GST_WRITE_UINT32_LE (data, clock_rate); /* rate */
158 GST_WRITE_UINT32_LE (data, gst_rtp_speex_depay_get_mode (clock_rate)); /* mode */
160 GST_WRITE_UINT32_LE (data, 4); /* mode_bitstream_version */
162 GST_WRITE_UINT32_LE (data, nb_channels); /* nb_channels */
164 GST_WRITE_UINT32_LE (data, -1); /* bitrate */
166 GST_WRITE_UINT32_LE (data, 0xa0); /* frame_size */
168 GST_WRITE_UINT32_LE (data, 0); /* VBR */
170 GST_WRITE_UINT32_LE (data, 1); /* frames_per_packet */
172 GST_WRITE_UINT32_LE (data, 0); /* extra_headers */
174 GST_WRITE_UINT32_LE (data, 0); /* reserved1 */
176 GST_WRITE_UINT32_LE (data, 0); /* reserved2 */
178 srccaps = gst_caps_new_simple ("audio/x-speex", NULL);
179 res = gst_pad_set_caps (depayload->srcpad, srccaps);
180 gst_caps_unref (srccaps);
182 gst_buffer_set_caps (buf, GST_PAD_CAPS (depayload->srcpad));
183 gst_base_rtp_depayload_push (GST_BASE_RTP_DEPAYLOAD (rtpspeexdepay), buf);
185 buf = gst_buffer_new_and_alloc (sizeof (gst_rtp_speex_comment));
186 memcpy (GST_BUFFER_DATA (buf), gst_rtp_speex_comment,
187 sizeof (gst_rtp_speex_comment));
189 gst_buffer_set_caps (buf, GST_PAD_CAPS (depayload->srcpad));
190 gst_base_rtp_depayload_push (GST_BASE_RTP_DEPAYLOAD (rtpspeexdepay), buf);
197 GST_DEBUG_OBJECT (depayload, "no clock-rate specified");
203 gst_rtp_speex_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
205 GstBuffer *outbuf = NULL;
207 GST_DEBUG ("process : got %d bytes, mark %d ts %u seqn %d",
208 GST_BUFFER_SIZE (buf),
209 gst_rtp_buffer_get_marker (buf),
210 gst_rtp_buffer_get_timestamp (buf), gst_rtp_buffer_get_seq (buf));
212 /* nothing special to be done */
213 outbuf = gst_rtp_buffer_get_payload_buffer (buf);
216 GST_BUFFER_DURATION (outbuf) = 20 * GST_MSECOND;
222 gst_rtp_speex_depay_plugin_init (GstPlugin * plugin)
224 return gst_element_register (plugin, "rtpspeexdepay",
225 GST_RANK_SECONDARY, GST_TYPE_RTP_SPEEX_DEPAY);