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 (GstRTPBaseDepayload * depayload,
63 static gboolean gst_rtp_speex_depay_setcaps (GstRTPBaseDepayload * depayload,
66 G_DEFINE_TYPE (GstRtpSPEEXDepay, gst_rtp_speex_depay,
67 GST_TYPE_RTP_BASE_DEPAYLOAD);
70 gst_rtp_speex_depay_class_init (GstRtpSPEEXDepayClass * klass)
72 GstElementClass *gstelement_class;
73 GstRTPBaseDepayloadClass *gstrtpbasedepayload_class;
75 gstelement_class = (GstElementClass *) klass;
76 gstrtpbasedepayload_class = (GstRTPBaseDepayloadClass *) klass;
78 gstrtpbasedepayload_class->process = gst_rtp_speex_depay_process;
79 gstrtpbasedepayload_class->set_caps = gst_rtp_speex_depay_setcaps;
81 gst_element_class_add_pad_template (gstelement_class,
82 gst_static_pad_template_get (&gst_rtp_speex_depay_src_template));
83 gst_element_class_add_pad_template (gstelement_class,
84 gst_static_pad_template_get (&gst_rtp_speex_depay_sink_template));
85 gst_element_class_set_static_metadata (gstelement_class,
86 "RTP Speex depayloader", "Codec/Depayloader/Network/RTP",
87 "Extracts Speex audio from RTP packets",
88 "Edgard Lima <edgard.lima@indt.org.br>");
92 gst_rtp_speex_depay_init (GstRtpSPEEXDepay * rtpspeexdepay)
97 gst_rtp_speex_depay_get_mode (gint rate)
101 else if (rate > 12500)
108 * vendor string (len bytes),
109 * user_len 4 (0) bytes LE
111 static const gchar gst_rtp_speex_comment[] =
112 "\045\0\0\0Depayloaded with GStreamer speexdepay\0\0\0\0";
115 gst_rtp_speex_depay_setcaps (GstRTPBaseDepayload * depayload, GstCaps * caps)
117 GstStructure *structure;
118 GstRtpSPEEXDepay *rtpspeexdepay;
119 gint clock_rate, nb_channels;
127 rtpspeexdepay = GST_RTP_SPEEX_DEPAY (depayload);
129 structure = gst_caps_get_structure (caps, 0);
131 if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
133 depayload->clock_rate = clock_rate;
135 if (!(params = gst_structure_get_string (structure, "encoding-params")))
138 nb_channels = atoi (params);
141 /* construct minimal header and comment packet for the decoder */
142 buf = gst_buffer_new_and_alloc (80);
143 gst_buffer_map (buf, &map, GST_MAP_WRITE);
145 memcpy (data, "Speex ", 8);
147 memcpy (data, "1.1.12", 7);
149 GST_WRITE_UINT32_LE (data, 1); /* version */
151 GST_WRITE_UINT32_LE (data, 80); /* header_size */
153 GST_WRITE_UINT32_LE (data, clock_rate); /* rate */
155 GST_WRITE_UINT32_LE (data, gst_rtp_speex_depay_get_mode (clock_rate)); /* mode */
157 GST_WRITE_UINT32_LE (data, 4); /* mode_bitstream_version */
159 GST_WRITE_UINT32_LE (data, nb_channels); /* nb_channels */
161 GST_WRITE_UINT32_LE (data, -1); /* bitrate */
163 GST_WRITE_UINT32_LE (data, 0xa0); /* frame_size */
165 GST_WRITE_UINT32_LE (data, 0); /* VBR */
167 GST_WRITE_UINT32_LE (data, 1); /* frames_per_packet */
169 GST_WRITE_UINT32_LE (data, 0); /* extra_headers */
171 GST_WRITE_UINT32_LE (data, 0); /* reserved1 */
173 GST_WRITE_UINT32_LE (data, 0); /* reserved2 */
174 gst_buffer_unmap (buf, &map);
176 srccaps = gst_caps_new_empty_simple ("audio/x-speex");
177 res = gst_pad_set_caps (depayload->srcpad, srccaps);
178 gst_caps_unref (srccaps);
180 gst_rtp_base_depayload_push (GST_RTP_BASE_DEPAYLOAD (rtpspeexdepay), buf);
182 buf = gst_buffer_new_and_alloc (sizeof (gst_rtp_speex_comment));
183 gst_buffer_fill (buf, 0, gst_rtp_speex_comment,
184 sizeof (gst_rtp_speex_comment));
186 gst_rtp_base_depayload_push (GST_RTP_BASE_DEPAYLOAD (rtpspeexdepay), buf);
193 GST_DEBUG_OBJECT (depayload, "no clock-rate specified");
199 gst_rtp_speex_depay_process (GstRTPBaseDepayload * depayload, GstBuffer * buf)
201 GstBuffer *outbuf = NULL;
202 GstRTPBuffer rtp = { NULL };
204 gst_rtp_buffer_map (buf, GST_MAP_READ, &rtp);
206 GST_DEBUG ("process : got %" G_GSIZE_FORMAT " bytes, mark %d ts %u seqn %d",
207 gst_buffer_get_size (buf),
208 gst_rtp_buffer_get_marker (&rtp),
209 gst_rtp_buffer_get_timestamp (&rtp), gst_rtp_buffer_get_seq (&rtp));
211 /* nothing special to be done */
212 outbuf = gst_rtp_buffer_get_payload_buffer (&rtp);
213 gst_rtp_buffer_unmap (&rtp);
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);