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 (GstRTPBaseDepayload * depayload,
54 static gboolean gst_rtp_bv_depay_setcaps (GstRTPBaseDepayload * depayload,
57 #define gst_rtp_bv_depay_parent_class parent_class
58 G_DEFINE_TYPE (GstRTPBVDepay, gst_rtp_bv_depay, GST_TYPE_RTP_BASE_DEPAYLOAD);
61 gst_rtp_bv_depay_class_init (GstRTPBVDepayClass * klass)
63 GstElementClass *gstelement_class;
64 GstRTPBaseDepayloadClass *gstrtpbasedepayload_class;
66 gstelement_class = (GstElementClass *) klass;
67 gstrtpbasedepayload_class = (GstRTPBaseDepayloadClass *) klass;
69 gst_element_class_add_pad_template (gstelement_class,
70 gst_static_pad_template_get (&gst_rtp_bv_depay_src_template));
71 gst_element_class_add_pad_template (gstelement_class,
72 gst_static_pad_template_get (&gst_rtp_bv_depay_sink_template));
74 gst_element_class_set_details_simple (gstelement_class,
75 "RTP BroadcomVoice depayloader", "Codec/Depayloader/Network/RTP",
76 "Extracts BroadcomVoice audio from RTP packets (RFC 4298)",
77 "Wim Taymans <wim.taymans@collabora.co.uk>");
79 gstrtpbasedepayload_class->process = gst_rtp_bv_depay_process;
80 gstrtpbasedepayload_class->set_caps = gst_rtp_bv_depay_setcaps;
84 gst_rtp_bv_depay_init (GstRTPBVDepay * rtpbvdepay)
86 rtpbvdepay->mode = -1;
90 gst_rtp_bv_depay_setcaps (GstRTPBaseDepayload * depayload, GstCaps * caps)
92 GstRTPBVDepay *rtpbvdepay = GST_RTP_BV_DEPAY (depayload);
94 GstStructure *structure;
95 const gchar *mode_str = NULL;
96 gint mode, clock_rate, expected_rate;
99 structure = gst_caps_get_structure (caps, 0);
101 mode_str = gst_structure_get_string (structure, "encoding-name");
105 if (!strcmp (mode_str, "BV16")) {
107 expected_rate = 8000;
108 } else if (!strcmp (mode_str, "BV32")) {
110 expected_rate = 16000;
114 if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
115 clock_rate = expected_rate;
116 else if (clock_rate != expected_rate)
119 depayload->clock_rate = clock_rate;
120 rtpbvdepay->mode = mode;
122 srccaps = gst_caps_new_simple ("audio/x-bv",
123 "mode", G_TYPE_INT, rtpbvdepay->mode, NULL);
124 ret = gst_pad_set_caps (GST_RTP_BASE_DEPAYLOAD_SRCPAD (depayload), srccaps);
126 GST_DEBUG ("set caps on source: %" GST_PTR_FORMAT " (ret=%d)", srccaps, ret);
127 gst_caps_unref (srccaps);
134 GST_ERROR_OBJECT (rtpbvdepay, "did not receive an encoding-name");
139 GST_ERROR_OBJECT (rtpbvdepay,
140 "invalid encoding-name, expected BV16 or BV32, got %s", mode_str);
145 GST_ERROR_OBJECT (rtpbvdepay, "invalid clock-rate, expected %d, got %d",
146 expected_rate, clock_rate);
152 gst_rtp_bv_depay_process (GstRTPBaseDepayload * depayload, GstBuffer * buf)
156 GstRTPBuffer rtp = { NULL, };
158 gst_rtp_buffer_map (buf, GST_MAP_READ, &rtp);
160 marker = gst_rtp_buffer_get_marker (&rtp);
162 GST_DEBUG ("process : got %" G_GSIZE_FORMAT " bytes, mark %d ts %u seqn %d",
163 gst_buffer_get_size (buf), marker,
164 gst_rtp_buffer_get_timestamp (&rtp), gst_rtp_buffer_get_seq (&rtp));
166 outbuf = gst_rtp_buffer_get_payload_buffer (&rtp);
167 gst_rtp_buffer_unmap (&rtp);
169 if (marker && outbuf) {
170 /* mark start of talkspurt with DISCONT */
171 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
178 gst_rtp_bv_depay_plugin_init (GstPlugin * plugin)
180 return gst_element_register (plugin, "rtpbvdepay",
181 GST_RANK_SECONDARY, GST_TYPE_RTP_BV_DEPAY);