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 #define gst_rtp_bv_pay_parent_class parent_class
62 G_DEFINE_TYPE (GstRTPBVPay, gst_rtp_bv_pay, GST_TYPE_BASE_RTP_AUDIO_PAYLOAD);
65 gst_rtp_bv_pay_class_init (GstRTPBVPayClass * klass)
67 GstElementClass *gstelement_class;
68 GstBaseRTPPayloadClass *gstbasertppayload_class;
70 GST_DEBUG_CATEGORY_INIT (rtpbvpay_debug, "rtpbvpay", 0,
71 "BroadcomVoice audio RTP payloader");
73 gstelement_class = (GstElementClass *) klass;
74 gstbasertppayload_class = (GstBaseRTPPayloadClass *) klass;
76 gst_element_class_add_pad_template (gstelement_class,
77 gst_static_pad_template_get (&gst_rtp_bv_pay_sink_template));
78 gst_element_class_add_pad_template (gstelement_class,
79 gst_static_pad_template_get (&gst_rtp_bv_pay_src_template));
81 gst_element_class_set_details_simple (gstelement_class, "RTP BV Payloader",
82 "Codec/Payloader/Network/RTP",
83 "Packetize BroadcomVoice audio streams into RTP packets (RFC 4298)",
84 "Wim Taymans <wim.taymans@collabora.co.uk>");
86 gstbasertppayload_class->set_caps = gst_rtp_bv_pay_sink_setcaps;
87 gstbasertppayload_class->get_caps = gst_rtp_bv_pay_sink_getcaps;
91 gst_rtp_bv_pay_init (GstRTPBVPay * rtpbvpay)
93 GstBaseRTPAudioPayload *basertpaudiopayload;
95 basertpaudiopayload = GST_BASE_RTP_AUDIO_PAYLOAD (rtpbvpay);
99 /* tell basertpaudiopayload that this is a frame based codec */
100 gst_base_rtp_audio_payload_set_frame_based (basertpaudiopayload);
104 gst_rtp_bv_pay_sink_setcaps (GstBaseRTPPayload * basertppayload, GstCaps * caps)
106 GstRTPBVPay *rtpbvpay;
107 GstBaseRTPAudioPayload *basertpaudiopayload;
109 GstStructure *structure;
110 const char *payload_name;
112 rtpbvpay = GST_RTP_BV_PAY (basertppayload);
113 basertpaudiopayload = GST_BASE_RTP_AUDIO_PAYLOAD (basertppayload);
115 structure = gst_caps_get_structure (caps, 0);
117 payload_name = gst_structure_get_name (structure);
118 if (g_ascii_strcasecmp ("audio/x-bv", payload_name))
121 if (!gst_structure_get_int (structure, "mode", &mode))
124 if (mode != 16 && mode != 32)
128 gst_basertppayload_set_options (basertppayload, "audio", TRUE, "BV16",
130 basertppayload->clock_rate = 8000;
132 gst_basertppayload_set_options (basertppayload, "audio", TRUE, "BV32",
134 basertppayload->clock_rate = 16000;
137 /* set options for this frame based audio codec */
138 gst_base_rtp_audio_payload_set_frame_options (basertpaudiopayload,
139 mode, mode == 16 ? 10 : 20);
141 if (mode != rtpbvpay->mode && rtpbvpay->mode != -1)
144 rtpbvpay->mode = mode;
151 GST_ERROR_OBJECT (rtpbvpay, "expected audio/x-bv, received %s",
157 GST_ERROR_OBJECT (rtpbvpay, "did not receive a mode");
162 GST_ERROR_OBJECT (rtpbvpay, "mode must be 16 or 32, received %d", mode);
167 GST_ERROR_OBJECT (rtpbvpay, "Mode has changed from %d to %d! "
168 "Mode cannot change while streaming", rtpbvpay->mode, mode);
173 /* we return the padtemplate caps with the mode field fixated to a value if we
176 gst_rtp_bv_pay_sink_getcaps (GstBaseRTPPayload * rtppayload, GstPad * pad)
178 GstCaps *otherpadcaps;
181 otherpadcaps = gst_pad_get_allowed_caps (rtppayload->srcpad);
182 caps = gst_caps_copy (gst_pad_get_pad_template_caps (pad));
185 if (!gst_caps_is_empty (otherpadcaps)) {
186 GstStructure *structure;
187 const gchar *mode_str;
190 structure = gst_caps_get_structure (otherpadcaps, 0);
192 /* construct mode, if we can */
193 mode_str = gst_structure_get_string (structure, "encoding-name");
195 if (!strcmp (mode_str, "BV16"))
197 else if (!strcmp (mode_str, "BV32"))
202 if (mode == 16 || mode == 32) {
203 structure = gst_caps_get_structure (caps, 0);
204 gst_structure_set (structure, "mode", G_TYPE_INT, mode, NULL);
208 gst_caps_unref (otherpadcaps);
214 gst_rtp_bv_pay_plugin_init (GstPlugin * plugin)
216 return gst_element_register (plugin, "rtpbvpay",
217 GST_RANK_SECONDARY, GST_TYPE_RTP_BV_PAY);