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 "gstrtpbvpay.h"
30 GST_DEBUG_CATEGORY_STATIC (rtpbvpay_debug);
31 #define GST_CAT_DEFAULT (rtpbvpay_debug)
33 static GstStaticPadTemplate gst_rtp_bv_pay_sink_template =
34 GST_STATIC_PAD_TEMPLATE ("sink",
37 GST_STATIC_CAPS ("audio/x-bv, " "mode = (int) {16, 32}")
40 static GstStaticPadTemplate gst_rtp_bv_pay_src_template =
41 GST_STATIC_PAD_TEMPLATE ("src",
44 GST_STATIC_CAPS ("application/x-rtp, "
45 "media = (string) \"audio\", "
46 "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
47 "clock-rate = (int) 8000, "
48 "encoding-name = (string) \"BV16\";"
50 "media = (string) \"audio\", "
51 "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
52 "clock-rate = (int) 16000, " "encoding-name = (string) \"BV32\"")
56 static GstCaps *gst_rtp_bv_pay_sink_getcaps (GstBaseRTPPayload * payload,
58 static gboolean gst_rtp_bv_pay_sink_setcaps (GstBaseRTPPayload * payload,
61 GST_BOILERPLATE (GstRTPBVPay, gst_rtp_bv_pay, GstBaseRTPAudioPayload,
62 GST_TYPE_BASE_RTP_AUDIO_PAYLOAD);
65 gst_rtp_bv_pay_base_init (gpointer klass)
67 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
69 gst_element_class_add_pad_template (element_class,
70 gst_static_pad_template_get (&gst_rtp_bv_pay_sink_template));
71 gst_element_class_add_pad_template (element_class,
72 gst_static_pad_template_get (&gst_rtp_bv_pay_src_template));
73 gst_element_class_set_details_simple (element_class, "RTP BV Payloader",
74 "Codec/Payloader/Network",
75 "Packetize BroadcomVoice audio streams into RTP packets (RFC 4298)",
76 "Wim Taymans <wim.taymans@collabora.co.uk>");
80 gst_rtp_bv_pay_class_init (GstRTPBVPayClass * klass)
82 GstBaseRTPPayloadClass *gstbasertppayload_class;
84 gstbasertppayload_class = (GstBaseRTPPayloadClass *) klass;
86 gstbasertppayload_class->set_caps = gst_rtp_bv_pay_sink_setcaps;
87 gstbasertppayload_class->get_caps = gst_rtp_bv_pay_sink_getcaps;
89 GST_DEBUG_CATEGORY_INIT (rtpbvpay_debug, "rtpbvpay", 0,
90 "BroadcomVoice audio RTP payloader");
94 gst_rtp_bv_pay_init (GstRTPBVPay * rtpbvpay, GstRTPBVPayClass * klass)
96 GstBaseRTPPayload *basertppayload;
97 GstBaseRTPAudioPayload *basertpaudiopayload;
99 basertppayload = GST_BASE_RTP_PAYLOAD (rtpbvpay);
100 basertpaudiopayload = GST_BASE_RTP_AUDIO_PAYLOAD (rtpbvpay);
104 /* tell basertpaudiopayload that this is a frame based codec */
105 gst_base_rtp_audio_payload_set_frame_based (basertpaudiopayload);
109 gst_rtp_bv_pay_sink_setcaps (GstBaseRTPPayload * basertppayload, GstCaps * caps)
111 GstRTPBVPay *rtpbvpay;
112 GstBaseRTPAudioPayload *basertpaudiopayload;
114 GstStructure *structure;
115 const char *payload_name;
117 rtpbvpay = GST_RTP_BV_PAY (basertppayload);
118 basertpaudiopayload = GST_BASE_RTP_AUDIO_PAYLOAD (basertppayload);
120 structure = gst_caps_get_structure (caps, 0);
122 payload_name = gst_structure_get_name (structure);
123 if (g_ascii_strcasecmp ("audio/x-bv", payload_name))
126 if (!gst_structure_get_int (structure, "mode", &mode))
129 if (mode != 16 && mode != 32)
133 gst_basertppayload_set_options (basertppayload, "audio", TRUE, "BV16",
135 basertppayload->clock_rate = 8000;
137 gst_basertppayload_set_options (basertppayload, "audio", TRUE, "BV32",
139 basertppayload->clock_rate = 16000;
142 /* set options for this frame based audio codec */
143 gst_base_rtp_audio_payload_set_frame_options (basertpaudiopayload,
144 mode, mode == 16 ? 10 : 20);
146 if (mode != rtpbvpay->mode && rtpbvpay->mode != -1)
149 rtpbvpay->mode = mode;
156 GST_ERROR_OBJECT (rtpbvpay, "expected audio/x-bv, received %s",
162 GST_ERROR_OBJECT (rtpbvpay, "did not receive a mode");
167 GST_ERROR_OBJECT (rtpbvpay, "mode must be 16 or 32, received %d", mode);
172 GST_ERROR_OBJECT (rtpbvpay, "Mode has changed from %d to %d! "
173 "Mode cannot change while streaming", rtpbvpay->mode, mode);
178 /* we return the padtemplate caps with the mode field fixated to a value if we
181 gst_rtp_bv_pay_sink_getcaps (GstBaseRTPPayload * rtppayload, GstPad * pad)
183 GstCaps *otherpadcaps;
186 otherpadcaps = gst_pad_get_allowed_caps (rtppayload->srcpad);
187 caps = gst_caps_copy (gst_pad_get_pad_template_caps (pad));
190 if (!gst_caps_is_empty (otherpadcaps)) {
191 GstStructure *structure;
192 const gchar *mode_str;
195 structure = gst_caps_get_structure (otherpadcaps, 0);
197 /* construct mode, if we can */
198 mode_str = gst_structure_get_string (structure, "encoding-name");
200 if (!strcmp (mode_str, "BV16"))
202 else if (!strcmp (mode_str, "BV32"))
207 if (mode == 16 || mode == 32) {
208 structure = gst_caps_get_structure (caps, 0);
209 gst_structure_set (structure, "mode", G_TYPE_INT, mode, NULL);
213 gst_caps_unref (otherpadcaps);
219 gst_rtp_bv_pay_plugin_init (GstPlugin * plugin)
221 return gst_element_register (plugin, "rtpbvpay",
222 GST_RANK_SECONDARY, GST_TYPE_RTP_BV_PAY);