2 * Copyright (C) <2009> Wim Taymans <wim.taymans@gmail.com>
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.
27 #include <gst/rtp/gstrtpbuffer.h>
28 #include "gstrtpbvdepay.h"
30 static GstStaticPadTemplate gst_rtp_bv_depay_sink_template =
31 GST_STATIC_PAD_TEMPLATE ("sink",
34 GST_STATIC_CAPS ("application/x-rtp, "
35 "media = (string) \"audio\", "
36 "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
37 "clock-rate = (int) 8000, "
38 "encoding-name = (string) \"BV16\"; "
40 "media = (string) \"audio\", "
41 "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
42 "clock-rate = (int) 16000, " "encoding-name = (string) \"BV32\"")
45 static GstStaticPadTemplate gst_rtp_bv_depay_src_template =
46 GST_STATIC_PAD_TEMPLATE ("src",
49 GST_STATIC_CAPS ("audio/x-bv, " "mode = (int) { 16, 32 }")
52 static GstBuffer *gst_rtp_bv_depay_process (GstBaseRTPDepayload * depayload,
54 static gboolean gst_rtp_bv_depay_setcaps (GstBaseRTPDepayload * depayload,
57 GST_BOILERPLATE (GstRTPBVDepay, gst_rtp_bv_depay, GstBaseRTPDepayload,
58 GST_TYPE_BASE_RTP_DEPAYLOAD);
61 gst_rtp_bv_depay_base_init (gpointer klass)
63 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
65 gst_element_class_add_static_pad_template (element_class,
66 &gst_rtp_bv_depay_src_template);
67 gst_element_class_add_static_pad_template (element_class,
68 &gst_rtp_bv_depay_sink_template);
69 gst_element_class_set_details_simple (element_class,
70 "RTP BroadcomVoice depayloader", "Codec/Depayloader/Network/RTP",
71 "Extracts BroadcomVoice audio from RTP packets (RFC 4298)",
72 "Wim Taymans <wim.taymans@collabora.co.uk>");
76 gst_rtp_bv_depay_class_init (GstRTPBVDepayClass * klass)
78 GstBaseRTPDepayloadClass *gstbasertpdepayload_class;
80 gstbasertpdepayload_class = (GstBaseRTPDepayloadClass *) klass;
82 gstbasertpdepayload_class->process = gst_rtp_bv_depay_process;
83 gstbasertpdepayload_class->set_caps = gst_rtp_bv_depay_setcaps;
87 gst_rtp_bv_depay_init (GstRTPBVDepay * rtpbvdepay, GstRTPBVDepayClass * klass)
89 rtpbvdepay->mode = -1;
93 gst_rtp_bv_depay_setcaps (GstBaseRTPDepayload * depayload, GstCaps * caps)
95 GstRTPBVDepay *rtpbvdepay = GST_RTP_BV_DEPAY (depayload);
97 GstStructure *structure;
98 const gchar *mode_str = NULL;
99 gint mode, clock_rate, expected_rate;
102 structure = gst_caps_get_structure (caps, 0);
104 mode_str = gst_structure_get_string (structure, "encoding-name");
108 if (!strcmp (mode_str, "BV16")) {
110 expected_rate = 8000;
111 } else if (!strcmp (mode_str, "BV32")) {
113 expected_rate = 16000;
117 if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
118 clock_rate = expected_rate;
119 else if (clock_rate != expected_rate)
122 depayload->clock_rate = clock_rate;
123 rtpbvdepay->mode = mode;
125 srccaps = gst_caps_new_simple ("audio/x-bv",
126 "mode", G_TYPE_INT, rtpbvdepay->mode, NULL);
127 ret = gst_pad_set_caps (GST_BASE_RTP_DEPAYLOAD_SRCPAD (depayload), srccaps);
129 GST_DEBUG ("set caps on source: %" GST_PTR_FORMAT " (ret=%d)", srccaps, ret);
130 gst_caps_unref (srccaps);
137 GST_ERROR_OBJECT (rtpbvdepay, "did not receive an encoding-name");
142 GST_ERROR_OBJECT (rtpbvdepay,
143 "invalid encoding-name, expected BV16 or BV32, got %s", mode_str);
148 GST_ERROR_OBJECT (rtpbvdepay, "invalid clock-rate, expected %d, got %d",
149 expected_rate, clock_rate);
155 gst_rtp_bv_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
160 marker = gst_rtp_buffer_get_marker (buf);
162 GST_DEBUG ("process : got %d bytes, mark %d ts %u seqn %d",
163 GST_BUFFER_SIZE (buf), marker,
164 gst_rtp_buffer_get_timestamp (buf), gst_rtp_buffer_get_seq (buf));
166 outbuf = gst_rtp_buffer_get_payload_buffer (buf);
168 if (marker && outbuf) {
169 /* mark start of talkspurt with DISCONT */
170 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
177 gst_rtp_bv_depay_plugin_init (GstPlugin * plugin)
179 return gst_element_register (plugin, "rtpbvdepay",
180 GST_RANK_SECONDARY, GST_TYPE_RTP_BV_DEPAY);