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., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, 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 "clock-rate = (int) [6000, 48000], "
49 "encoding-name = (string) \"SPEEX\", "
50 "encoding-params = (string) \"1\"")
53 static GstStaticPadTemplate gst_rtp_speex_depay_src_template =
54 GST_STATIC_PAD_TEMPLATE ("src",
57 GST_STATIC_CAPS ("audio/x-speex")
60 static GstBuffer *gst_rtp_speex_depay_process (GstRTPBaseDepayload * depayload,
62 static gboolean gst_rtp_speex_depay_setcaps (GstRTPBaseDepayload * depayload,
65 G_DEFINE_TYPE (GstRtpSPEEXDepay, gst_rtp_speex_depay,
66 GST_TYPE_RTP_BASE_DEPAYLOAD);
69 gst_rtp_speex_depay_class_init (GstRtpSPEEXDepayClass * klass)
71 GstElementClass *gstelement_class;
72 GstRTPBaseDepayloadClass *gstrtpbasedepayload_class;
74 gstelement_class = (GstElementClass *) klass;
75 gstrtpbasedepayload_class = (GstRTPBaseDepayloadClass *) klass;
77 gstrtpbasedepayload_class->process = gst_rtp_speex_depay_process;
78 gstrtpbasedepayload_class->set_caps = gst_rtp_speex_depay_setcaps;
80 gst_element_class_add_pad_template (gstelement_class,
81 gst_static_pad_template_get (&gst_rtp_speex_depay_src_template));
82 gst_element_class_add_pad_template (gstelement_class,
83 gst_static_pad_template_get (&gst_rtp_speex_depay_sink_template));
84 gst_element_class_set_static_metadata (gstelement_class,
85 "RTP Speex depayloader", "Codec/Depayloader/Network/RTP",
86 "Extracts Speex audio from RTP packets",
87 "Edgard Lima <edgard.lima@indt.org.br>");
91 gst_rtp_speex_depay_init (GstRtpSPEEXDepay * rtpspeexdepay)
96 gst_rtp_speex_depay_get_mode (gint rate)
100 else if (rate > 12500)
107 * vendor string (len bytes),
108 * user_len 4 (0) bytes LE
110 static const gchar gst_rtp_speex_comment[] =
111 "\045\0\0\0Depayloaded with GStreamer speexdepay\0\0\0\0";
114 gst_rtp_speex_depay_setcaps (GstRTPBaseDepayload * depayload, GstCaps * caps)
116 GstStructure *structure;
117 GstRtpSPEEXDepay *rtpspeexdepay;
118 gint clock_rate, nb_channels;
126 rtpspeexdepay = GST_RTP_SPEEX_DEPAY (depayload);
128 structure = gst_caps_get_structure (caps, 0);
130 if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
132 depayload->clock_rate = clock_rate;
134 if (!(params = gst_structure_get_string (structure, "encoding-params")))
137 nb_channels = atoi (params);
140 /* construct minimal header and comment packet for the decoder */
141 buf = gst_buffer_new_and_alloc (80);
142 gst_buffer_map (buf, &map, GST_MAP_WRITE);
144 memcpy (data, "Speex ", 8);
146 memcpy (data, "1.1.12", 7);
148 GST_WRITE_UINT32_LE (data, 1); /* version */
150 GST_WRITE_UINT32_LE (data, 80); /* header_size */
152 GST_WRITE_UINT32_LE (data, clock_rate); /* rate */
154 GST_WRITE_UINT32_LE (data, gst_rtp_speex_depay_get_mode (clock_rate)); /* mode */
156 GST_WRITE_UINT32_LE (data, 4); /* mode_bitstream_version */
158 GST_WRITE_UINT32_LE (data, nb_channels); /* nb_channels */
160 GST_WRITE_UINT32_LE (data, -1); /* bitrate */
162 GST_WRITE_UINT32_LE (data, 0xa0); /* frame_size */
164 GST_WRITE_UINT32_LE (data, 0); /* VBR */
166 GST_WRITE_UINT32_LE (data, 1); /* frames_per_packet */
168 GST_WRITE_UINT32_LE (data, 0); /* extra_headers */
170 GST_WRITE_UINT32_LE (data, 0); /* reserved1 */
172 GST_WRITE_UINT32_LE (data, 0); /* reserved2 */
173 gst_buffer_unmap (buf, &map);
175 srccaps = gst_caps_new_empty_simple ("audio/x-speex");
176 res = gst_pad_set_caps (depayload->srcpad, srccaps);
177 gst_caps_unref (srccaps);
179 gst_rtp_base_depayload_push (GST_RTP_BASE_DEPAYLOAD (rtpspeexdepay), buf);
181 buf = gst_buffer_new_and_alloc (sizeof (gst_rtp_speex_comment));
182 gst_buffer_fill (buf, 0, gst_rtp_speex_comment,
183 sizeof (gst_rtp_speex_comment));
185 gst_rtp_base_depayload_push (GST_RTP_BASE_DEPAYLOAD (rtpspeexdepay), buf);
192 GST_DEBUG_OBJECT (depayload, "no clock-rate specified");
198 gst_rtp_speex_depay_process (GstRTPBaseDepayload * depayload, GstBuffer * buf)
200 GstBuffer *outbuf = NULL;
201 GstRTPBuffer rtp = { NULL };
203 gst_rtp_buffer_map (buf, GST_MAP_READ, &rtp);
205 GST_DEBUG ("process : got %" G_GSIZE_FORMAT " bytes, mark %d ts %u seqn %d",
206 gst_buffer_get_size (buf),
207 gst_rtp_buffer_get_marker (&rtp),
208 gst_rtp_buffer_get_timestamp (&rtp), gst_rtp_buffer_get_seq (&rtp));
210 /* nothing special to be done */
211 outbuf = gst_rtp_buffer_get_payload_buffer (&rtp);
212 gst_rtp_buffer_unmap (&rtp);
215 GST_BUFFER_DURATION (outbuf) = 20 * GST_MSECOND;
221 gst_rtp_speex_depay_plugin_init (GstPlugin * plugin)
223 return gst_element_register (plugin, "rtpspeexdepay",
224 GST_RANK_SECONDARY, GST_TYPE_RTP_SPEEX_DEPAY);