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
25 * Extract BroadcomVoice audio from RTP packets according to RFC 4298.
26 * For detailed information see: http://www.rfc-editor.org/rfc/rfc4298.txt
36 #include <gst/rtp/gstrtpbuffer.h>
37 #include <gst/audio/audio.h>
38 #include "gstrtpbvdepay.h"
39 #include "gstrtputils.h"
41 static GstStaticPadTemplate gst_rtp_bv_depay_sink_template =
42 GST_STATIC_PAD_TEMPLATE ("sink",
45 GST_STATIC_CAPS ("application/x-rtp, "
46 "media = (string) \"audio\", "
47 "clock-rate = (int) 8000, "
48 "encoding-name = (string) \"BV16\"; "
50 "media = (string) \"audio\", "
51 "clock-rate = (int) 16000, " "encoding-name = (string) \"BV32\"")
54 static GstStaticPadTemplate gst_rtp_bv_depay_src_template =
55 GST_STATIC_PAD_TEMPLATE ("src",
58 GST_STATIC_CAPS ("audio/x-bv, " "mode = (int) { 16, 32 }")
61 static GstBuffer *gst_rtp_bv_depay_process (GstRTPBaseDepayload * depayload,
63 static gboolean gst_rtp_bv_depay_setcaps (GstRTPBaseDepayload * depayload,
66 #define gst_rtp_bv_depay_parent_class parent_class
67 G_DEFINE_TYPE (GstRTPBVDepay, gst_rtp_bv_depay, GST_TYPE_RTP_BASE_DEPAYLOAD);
70 gst_rtp_bv_depay_class_init (GstRTPBVDepayClass * klass)
72 GstElementClass *gstelement_class;
73 GstRTPBaseDepayloadClass *gstrtpbasedepayload_class;
75 gstelement_class = (GstElementClass *) klass;
76 gstrtpbasedepayload_class = (GstRTPBaseDepayloadClass *) klass;
78 gst_element_class_add_static_pad_template (gstelement_class,
79 &gst_rtp_bv_depay_src_template);
80 gst_element_class_add_static_pad_template (gstelement_class,
81 &gst_rtp_bv_depay_sink_template);
83 gst_element_class_set_static_metadata (gstelement_class,
84 "RTP BroadcomVoice depayloader", "Codec/Depayloader/Network/RTP",
85 "Extracts BroadcomVoice audio from RTP packets (RFC 4298)",
86 "Wim Taymans <wim.taymans@collabora.co.uk>");
88 gstrtpbasedepayload_class->process_rtp_packet = gst_rtp_bv_depay_process;
89 gstrtpbasedepayload_class->set_caps = gst_rtp_bv_depay_setcaps;
93 gst_rtp_bv_depay_init (GstRTPBVDepay * rtpbvdepay)
95 rtpbvdepay->mode = -1;
99 gst_rtp_bv_depay_setcaps (GstRTPBaseDepayload * depayload, GstCaps * caps)
101 GstRTPBVDepay *rtpbvdepay = GST_RTP_BV_DEPAY (depayload);
103 GstStructure *structure;
104 const gchar *mode_str = NULL;
105 gint mode, clock_rate, expected_rate;
108 structure = gst_caps_get_structure (caps, 0);
110 mode_str = gst_structure_get_string (structure, "encoding-name");
114 if (!strcmp (mode_str, "BV16")) {
116 expected_rate = 8000;
117 } else if (!strcmp (mode_str, "BV32")) {
119 expected_rate = 16000;
123 if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
124 clock_rate = expected_rate;
125 else if (clock_rate != expected_rate)
128 depayload->clock_rate = clock_rate;
129 rtpbvdepay->mode = mode;
131 srccaps = gst_caps_new_simple ("audio/x-bv",
132 "mode", G_TYPE_INT, rtpbvdepay->mode, NULL);
133 ret = gst_pad_set_caps (GST_RTP_BASE_DEPAYLOAD_SRCPAD (depayload), srccaps);
135 GST_DEBUG ("set caps on source: %" GST_PTR_FORMAT " (ret=%d)", srccaps, ret);
136 gst_caps_unref (srccaps);
143 GST_ERROR_OBJECT (rtpbvdepay, "did not receive an encoding-name");
148 GST_ERROR_OBJECT (rtpbvdepay,
149 "invalid encoding-name, expected BV16 or BV32, got %s", mode_str);
154 GST_ERROR_OBJECT (rtpbvdepay, "invalid clock-rate, expected %d, got %d",
155 expected_rate, clock_rate);
161 gst_rtp_bv_depay_process (GstRTPBaseDepayload * depayload, GstRTPBuffer * rtp)
166 marker = gst_rtp_buffer_get_marker (rtp);
168 GST_DEBUG ("process : got %" G_GSIZE_FORMAT " bytes, mark %d ts %u seqn %d",
169 gst_buffer_get_size (rtp->buffer), marker,
170 gst_rtp_buffer_get_timestamp (rtp), gst_rtp_buffer_get_seq (rtp));
172 outbuf = gst_rtp_buffer_get_payload_buffer (rtp);
174 if (marker && outbuf) {
175 /* mark start of talkspurt with RESYNC */
176 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_RESYNC);
180 gst_rtp_drop_non_audio_meta (depayload, outbuf);
187 gst_rtp_bv_depay_plugin_init (GstPlugin * plugin)
189 return gst_element_register (plugin, "rtpbvdepay",
190 GST_RANK_SECONDARY, GST_TYPE_RTP_BV_DEPAY);