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 (GstRTPBasePayload * payload,
57 GstPad * pad, GstCaps * filter);
58 static gboolean gst_rtp_bv_pay_sink_setcaps (GstRTPBasePayload * payload,
61 #define gst_rtp_bv_pay_parent_class parent_class
62 G_DEFINE_TYPE (GstRTPBVPay, gst_rtp_bv_pay, GST_TYPE_RTP_BASE_AUDIO_PAYLOAD);
65 gst_rtp_bv_pay_class_init (GstRTPBVPayClass * klass)
67 GstElementClass *gstelement_class;
68 GstRTPBasePayloadClass *gstrtpbasepayload_class;
70 GST_DEBUG_CATEGORY_INIT (rtpbvpay_debug, "rtpbvpay", 0,
71 "BroadcomVoice audio RTP payloader");
73 gstelement_class = (GstElementClass *) klass;
74 gstrtpbasepayload_class = (GstRTPBasePayloadClass *) 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 gstrtpbasepayload_class->set_caps = gst_rtp_bv_pay_sink_setcaps;
87 gstrtpbasepayload_class->get_caps = gst_rtp_bv_pay_sink_getcaps;
91 gst_rtp_bv_pay_init (GstRTPBVPay * rtpbvpay)
93 GstRTPBaseAudioPayload *rtpbaseaudiopayload;
95 rtpbaseaudiopayload = GST_RTP_BASE_AUDIO_PAYLOAD (rtpbvpay);
99 /* tell rtpbaseaudiopayload that this is a frame based codec */
100 gst_rtp_base_audio_payload_set_frame_based (rtpbaseaudiopayload);
104 gst_rtp_bv_pay_sink_setcaps (GstRTPBasePayload * rtpbasepayload, GstCaps * caps)
106 GstRTPBVPay *rtpbvpay;
107 GstRTPBaseAudioPayload *rtpbaseaudiopayload;
109 GstStructure *structure;
110 const char *payload_name;
112 rtpbvpay = GST_RTP_BV_PAY (rtpbasepayload);
113 rtpbaseaudiopayload = GST_RTP_BASE_AUDIO_PAYLOAD (rtpbasepayload);
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_rtp_base_payload_set_options (rtpbasepayload, "audio", TRUE, "BV16",
130 rtpbasepayload->clock_rate = 8000;
132 gst_rtp_base_payload_set_options (rtpbasepayload, "audio", TRUE, "BV32",
134 rtpbasepayload->clock_rate = 16000;
137 /* set options for this frame based audio codec */
138 gst_rtp_base_audio_payload_set_frame_options (rtpbaseaudiopayload,
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 (GstRTPBasePayload * rtppayload, GstPad * pad,
179 GstCaps *otherpadcaps;
182 otherpadcaps = gst_pad_get_allowed_caps (rtppayload->srcpad);
183 caps = gst_caps_copy (gst_pad_get_pad_template_caps (pad));
186 if (!gst_caps_is_empty (otherpadcaps)) {
187 GstStructure *structure;
188 const gchar *mode_str;
191 structure = gst_caps_get_structure (otherpadcaps, 0);
193 /* construct mode, if we can */
194 mode_str = gst_structure_get_string (structure, "encoding-name");
196 if (!strcmp (mode_str, "BV16"))
198 else if (!strcmp (mode_str, "BV32"))
203 if (mode == 16 || mode == 32) {
204 structure = gst_caps_get_structure (caps, 0);
205 gst_structure_set (structure, "mode", G_TYPE_INT, mode, NULL);
209 gst_caps_unref (otherpadcaps);
215 gst_rtp_bv_pay_plugin_init (GstPlugin * plugin)
217 return gst_element_register (plugin, "rtpbvpay",
218 GST_RANK_SECONDARY, GST_TYPE_RTP_BV_PAY);