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., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, 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 "clock-rate = (int) 8000, "
37 "encoding-name = (string) \"BV16\"; "
39 "media = (string) \"audio\", "
40 "clock-rate = (int) 16000, " "encoding-name = (string) \"BV32\"")
43 static GstStaticPadTemplate gst_rtp_bv_depay_src_template =
44 GST_STATIC_PAD_TEMPLATE ("src",
47 GST_STATIC_CAPS ("audio/x-bv, " "mode = (int) { 16, 32 }")
50 static GstBuffer *gst_rtp_bv_depay_process (GstRTPBaseDepayload * depayload,
52 static gboolean gst_rtp_bv_depay_setcaps (GstRTPBaseDepayload * depayload,
55 #define gst_rtp_bv_depay_parent_class parent_class
56 G_DEFINE_TYPE (GstRTPBVDepay, gst_rtp_bv_depay, GST_TYPE_RTP_BASE_DEPAYLOAD);
59 gst_rtp_bv_depay_class_init (GstRTPBVDepayClass * klass)
61 GstElementClass *gstelement_class;
62 GstRTPBaseDepayloadClass *gstrtpbasedepayload_class;
64 gstelement_class = (GstElementClass *) klass;
65 gstrtpbasedepayload_class = (GstRTPBaseDepayloadClass *) klass;
67 gst_element_class_add_pad_template (gstelement_class,
68 gst_static_pad_template_get (&gst_rtp_bv_depay_src_template));
69 gst_element_class_add_pad_template (gstelement_class,
70 gst_static_pad_template_get (&gst_rtp_bv_depay_sink_template));
72 gst_element_class_set_static_metadata (gstelement_class,
73 "RTP BroadcomVoice depayloader", "Codec/Depayloader/Network/RTP",
74 "Extracts BroadcomVoice audio from RTP packets (RFC 4298)",
75 "Wim Taymans <wim.taymans@collabora.co.uk>");
77 gstrtpbasedepayload_class->process = gst_rtp_bv_depay_process;
78 gstrtpbasedepayload_class->set_caps = gst_rtp_bv_depay_setcaps;
82 gst_rtp_bv_depay_init (GstRTPBVDepay * rtpbvdepay)
84 rtpbvdepay->mode = -1;
88 gst_rtp_bv_depay_setcaps (GstRTPBaseDepayload * depayload, GstCaps * caps)
90 GstRTPBVDepay *rtpbvdepay = GST_RTP_BV_DEPAY (depayload);
92 GstStructure *structure;
93 const gchar *mode_str = NULL;
94 gint mode, clock_rate, expected_rate;
97 structure = gst_caps_get_structure (caps, 0);
99 mode_str = gst_structure_get_string (structure, "encoding-name");
103 if (!strcmp (mode_str, "BV16")) {
105 expected_rate = 8000;
106 } else if (!strcmp (mode_str, "BV32")) {
108 expected_rate = 16000;
112 if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
113 clock_rate = expected_rate;
114 else if (clock_rate != expected_rate)
117 depayload->clock_rate = clock_rate;
118 rtpbvdepay->mode = mode;
120 srccaps = gst_caps_new_simple ("audio/x-bv",
121 "mode", G_TYPE_INT, rtpbvdepay->mode, NULL);
122 ret = gst_pad_set_caps (GST_RTP_BASE_DEPAYLOAD_SRCPAD (depayload), srccaps);
124 GST_DEBUG ("set caps on source: %" GST_PTR_FORMAT " (ret=%d)", srccaps, ret);
125 gst_caps_unref (srccaps);
132 GST_ERROR_OBJECT (rtpbvdepay, "did not receive an encoding-name");
137 GST_ERROR_OBJECT (rtpbvdepay,
138 "invalid encoding-name, expected BV16 or BV32, got %s", mode_str);
143 GST_ERROR_OBJECT (rtpbvdepay, "invalid clock-rate, expected %d, got %d",
144 expected_rate, clock_rate);
150 gst_rtp_bv_depay_process (GstRTPBaseDepayload * depayload, GstBuffer * buf)
154 GstRTPBuffer rtp = { NULL, };
156 gst_rtp_buffer_map (buf, GST_MAP_READ, &rtp);
158 marker = gst_rtp_buffer_get_marker (&rtp);
160 GST_DEBUG ("process : got %" G_GSIZE_FORMAT " bytes, mark %d ts %u seqn %d",
161 gst_buffer_get_size (buf), marker,
162 gst_rtp_buffer_get_timestamp (&rtp), gst_rtp_buffer_get_seq (&rtp));
164 outbuf = gst_rtp_buffer_get_payload_buffer (&rtp);
165 gst_rtp_buffer_unmap (&rtp);
167 if (marker && outbuf) {
168 /* mark start of talkspurt with DISCONT */
169 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
176 gst_rtp_bv_depay_plugin_init (GstPlugin * plugin)
178 return gst_element_register (plugin, "rtpbvdepay",
179 GST_RANK_SECONDARY, GST_TYPE_RTP_BV_DEPAY);