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.
21 * SECTION:element-rtpbvdepay
24 * Extract BroadcomVoice audio from RTP packets according to RFC 4298.
25 * For detailed information see: http://www.rfc-editor.org/rfc/rfc4298.txt
27 * Last reviewed on 2013-04-25 (1.1.0)
37 #include <gst/rtp/gstrtpbuffer.h>
38 #include "gstrtpbvdepay.h"
40 static GstStaticPadTemplate gst_rtp_bv_depay_sink_template =
41 GST_STATIC_PAD_TEMPLATE ("sink",
44 GST_STATIC_CAPS ("application/x-rtp, "
45 "media = (string) \"audio\", "
46 "clock-rate = (int) 8000, "
47 "encoding-name = (string) \"BV16\"; "
49 "media = (string) \"audio\", "
50 "clock-rate = (int) 16000, " "encoding-name = (string) \"BV32\"")
53 static GstStaticPadTemplate gst_rtp_bv_depay_src_template =
54 GST_STATIC_PAD_TEMPLATE ("src",
57 GST_STATIC_CAPS ("audio/x-bv, " "mode = (int) { 16, 32 }")
60 static GstBuffer *gst_rtp_bv_depay_process (GstRTPBaseDepayload * depayload,
62 static gboolean gst_rtp_bv_depay_setcaps (GstRTPBaseDepayload * depayload,
65 #define gst_rtp_bv_depay_parent_class parent_class
66 G_DEFINE_TYPE (GstRTPBVDepay, gst_rtp_bv_depay, GST_TYPE_RTP_BASE_DEPAYLOAD);
69 gst_rtp_bv_depay_class_init (GstRTPBVDepayClass * klass)
71 GstElementClass *gstelement_class;
72 GstRTPBaseDepayloadClass *gstrtpbasedepayload_class;
74 gstelement_class = (GstElementClass *) klass;
75 gstrtpbasedepayload_class = (GstRTPBaseDepayloadClass *) klass;
77 gst_element_class_add_pad_template (gstelement_class,
78 gst_static_pad_template_get (&gst_rtp_bv_depay_src_template));
79 gst_element_class_add_pad_template (gstelement_class,
80 gst_static_pad_template_get (&gst_rtp_bv_depay_sink_template));
82 gst_element_class_set_static_metadata (gstelement_class,
83 "RTP BroadcomVoice depayloader", "Codec/Depayloader/Network/RTP",
84 "Extracts BroadcomVoice audio from RTP packets (RFC 4298)",
85 "Wim Taymans <wim.taymans@collabora.co.uk>");
87 gstrtpbasedepayload_class->process = gst_rtp_bv_depay_process;
88 gstrtpbasedepayload_class->set_caps = gst_rtp_bv_depay_setcaps;
92 gst_rtp_bv_depay_init (GstRTPBVDepay * rtpbvdepay)
94 rtpbvdepay->mode = -1;
98 gst_rtp_bv_depay_setcaps (GstRTPBaseDepayload * depayload, GstCaps * caps)
100 GstRTPBVDepay *rtpbvdepay = GST_RTP_BV_DEPAY (depayload);
102 GstStructure *structure;
103 const gchar *mode_str = NULL;
104 gint mode, clock_rate, expected_rate;
107 structure = gst_caps_get_structure (caps, 0);
109 mode_str = gst_structure_get_string (structure, "encoding-name");
113 if (!strcmp (mode_str, "BV16")) {
115 expected_rate = 8000;
116 } else if (!strcmp (mode_str, "BV32")) {
118 expected_rate = 16000;
122 if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
123 clock_rate = expected_rate;
124 else if (clock_rate != expected_rate)
127 depayload->clock_rate = clock_rate;
128 rtpbvdepay->mode = mode;
130 srccaps = gst_caps_new_simple ("audio/x-bv",
131 "mode", G_TYPE_INT, rtpbvdepay->mode, NULL);
132 ret = gst_pad_set_caps (GST_RTP_BASE_DEPAYLOAD_SRCPAD (depayload), srccaps);
134 GST_DEBUG ("set caps on source: %" GST_PTR_FORMAT " (ret=%d)", srccaps, ret);
135 gst_caps_unref (srccaps);
142 GST_ERROR_OBJECT (rtpbvdepay, "did not receive an encoding-name");
147 GST_ERROR_OBJECT (rtpbvdepay,
148 "invalid encoding-name, expected BV16 or BV32, got %s", mode_str);
153 GST_ERROR_OBJECT (rtpbvdepay, "invalid clock-rate, expected %d, got %d",
154 expected_rate, clock_rate);
160 gst_rtp_bv_depay_process (GstRTPBaseDepayload * depayload, GstBuffer * buf)
164 GstRTPBuffer rtp = { NULL, };
166 gst_rtp_buffer_map (buf, GST_MAP_READ, &rtp);
168 marker = gst_rtp_buffer_get_marker (&rtp);
170 GST_DEBUG ("process : got %" G_GSIZE_FORMAT " bytes, mark %d ts %u seqn %d",
171 gst_buffer_get_size (buf), marker,
172 gst_rtp_buffer_get_timestamp (&rtp), gst_rtp_buffer_get_seq (&rtp));
174 outbuf = gst_rtp_buffer_get_payload_buffer (&rtp);
175 gst_rtp_buffer_unmap (&rtp);
177 if (marker && outbuf) {
178 /* mark start of talkspurt with RESYNC */
179 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_RESYNC);
186 gst_rtp_bv_depay_plugin_init (GstPlugin * plugin)
188 return gst_element_register (plugin, "rtpbvdepay",
189 GST_RANK_SECONDARY, GST_TYPE_RTP_BV_DEPAY);