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-rtpbvpay
22 * @see_also: rtpbvdepay
24 * Payload BroadcomVoice audio into 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 "gstrtpbvpay.h"
40 GST_DEBUG_CATEGORY_STATIC (rtpbvpay_debug);
41 #define GST_CAT_DEFAULT (rtpbvpay_debug)
43 static GstStaticPadTemplate gst_rtp_bv_pay_sink_template =
44 GST_STATIC_PAD_TEMPLATE ("sink",
47 GST_STATIC_CAPS ("audio/x-bv, " "mode = (int) {16, 32}")
50 static GstStaticPadTemplate gst_rtp_bv_pay_src_template =
51 GST_STATIC_PAD_TEMPLATE ("src",
54 GST_STATIC_CAPS ("application/x-rtp, "
55 "media = (string) \"audio\", "
56 "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
57 "clock-rate = (int) 8000, "
58 "encoding-name = (string) \"BV16\";"
60 "media = (string) \"audio\", "
61 "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
62 "clock-rate = (int) 16000, " "encoding-name = (string) \"BV32\"")
66 static GstCaps *gst_rtp_bv_pay_sink_getcaps (GstRTPBasePayload * payload,
67 GstPad * pad, GstCaps * filter);
68 static gboolean gst_rtp_bv_pay_sink_setcaps (GstRTPBasePayload * payload,
71 #define gst_rtp_bv_pay_parent_class parent_class
72 G_DEFINE_TYPE (GstRTPBVPay, gst_rtp_bv_pay, GST_TYPE_RTP_BASE_AUDIO_PAYLOAD);
75 gst_rtp_bv_pay_class_init (GstRTPBVPayClass * klass)
77 GstElementClass *gstelement_class;
78 GstRTPBasePayloadClass *gstrtpbasepayload_class;
80 GST_DEBUG_CATEGORY_INIT (rtpbvpay_debug, "rtpbvpay", 0,
81 "BroadcomVoice audio RTP payloader");
83 gstelement_class = (GstElementClass *) klass;
84 gstrtpbasepayload_class = (GstRTPBasePayloadClass *) klass;
86 gst_element_class_add_pad_template (gstelement_class,
87 gst_static_pad_template_get (&gst_rtp_bv_pay_sink_template));
88 gst_element_class_add_pad_template (gstelement_class,
89 gst_static_pad_template_get (&gst_rtp_bv_pay_src_template));
91 gst_element_class_set_static_metadata (gstelement_class, "RTP BV Payloader",
92 "Codec/Payloader/Network/RTP",
93 "Packetize BroadcomVoice audio streams into RTP packets (RFC 4298)",
94 "Wim Taymans <wim.taymans@collabora.co.uk>");
96 gstrtpbasepayload_class->set_caps = gst_rtp_bv_pay_sink_setcaps;
97 gstrtpbasepayload_class->get_caps = gst_rtp_bv_pay_sink_getcaps;
101 gst_rtp_bv_pay_init (GstRTPBVPay * rtpbvpay)
103 GstRTPBaseAudioPayload *rtpbaseaudiopayload;
105 rtpbaseaudiopayload = GST_RTP_BASE_AUDIO_PAYLOAD (rtpbvpay);
109 /* tell rtpbaseaudiopayload that this is a frame based codec */
110 gst_rtp_base_audio_payload_set_frame_based (rtpbaseaudiopayload);
114 gst_rtp_bv_pay_sink_setcaps (GstRTPBasePayload * rtpbasepayload, GstCaps * caps)
116 GstRTPBVPay *rtpbvpay;
117 GstRTPBaseAudioPayload *rtpbaseaudiopayload;
119 GstStructure *structure;
120 const char *payload_name;
122 rtpbvpay = GST_RTP_BV_PAY (rtpbasepayload);
123 rtpbaseaudiopayload = GST_RTP_BASE_AUDIO_PAYLOAD (rtpbasepayload);
125 structure = gst_caps_get_structure (caps, 0);
127 payload_name = gst_structure_get_name (structure);
128 if (g_ascii_strcasecmp ("audio/x-bv", payload_name))
131 if (!gst_structure_get_int (structure, "mode", &mode))
134 if (mode != 16 && mode != 32)
138 gst_rtp_base_payload_set_options (rtpbasepayload, "audio", TRUE, "BV16",
140 rtpbasepayload->clock_rate = 8000;
142 gst_rtp_base_payload_set_options (rtpbasepayload, "audio", TRUE, "BV32",
144 rtpbasepayload->clock_rate = 16000;
147 /* set options for this frame based audio codec */
148 gst_rtp_base_audio_payload_set_frame_options (rtpbaseaudiopayload,
149 mode, mode == 16 ? 10 : 20);
151 if (mode != rtpbvpay->mode && rtpbvpay->mode != -1)
154 rtpbvpay->mode = mode;
161 GST_ERROR_OBJECT (rtpbvpay, "expected audio/x-bv, received %s",
167 GST_ERROR_OBJECT (rtpbvpay, "did not receive a mode");
172 GST_ERROR_OBJECT (rtpbvpay, "mode must be 16 or 32, received %d", mode);
177 GST_ERROR_OBJECT (rtpbvpay, "Mode has changed from %d to %d! "
178 "Mode cannot change while streaming", rtpbvpay->mode, mode);
183 /* we return the padtemplate caps with the mode field fixated to a value if we
186 gst_rtp_bv_pay_sink_getcaps (GstRTPBasePayload * rtppayload, GstPad * pad,
189 GstCaps *otherpadcaps;
192 caps = gst_pad_get_pad_template_caps (pad);
194 otherpadcaps = gst_pad_get_allowed_caps (rtppayload->srcpad);
196 if (!gst_caps_is_empty (otherpadcaps)) {
197 GstStructure *structure;
198 const gchar *mode_str;
201 structure = gst_caps_get_structure (otherpadcaps, 0);
203 /* construct mode, if we can */
204 mode_str = gst_structure_get_string (structure, "encoding-name");
206 if (!strcmp (mode_str, "BV16"))
208 else if (!strcmp (mode_str, "BV32"))
213 if (mode == 16 || mode == 32) {
214 caps = gst_caps_make_writable (caps);
215 structure = gst_caps_get_structure (caps, 0);
216 gst_structure_set (structure, "mode", G_TYPE_INT, mode, NULL);
220 gst_caps_unref (otherpadcaps);
226 gst_rtp_bv_pay_plugin_init (GstPlugin * plugin)
228 return gst_element_register (plugin, "rtpbvpay",
229 GST_RANK_SECONDARY, GST_TYPE_RTP_BV_PAY);