2 * Siren Payloader Gst Element
4 * @author: Youness Alaoui <kakaroto@kakaroto.homelinux.net>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
26 #include "gstrtpelements.h"
27 #include "gstrtpsirenpay.h"
28 #include <gst/rtp/gstrtpbuffer.h>
30 GST_DEBUG_CATEGORY_STATIC (rtpsirenpay_debug);
31 #define GST_CAT_DEFAULT (rtpsirenpay_debug)
33 static GstStaticPadTemplate gst_rtp_siren_pay_sink_template =
34 GST_STATIC_PAD_TEMPLATE ("sink",
37 GST_STATIC_CAPS ("audio/x-siren, " "dct-length = (int) 320")
40 static GstStaticPadTemplate gst_rtp_siren_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) 16000, "
48 "encoding-name = (string) \"SIREN\", "
49 "bitrate = (string) \"16000\", " "dct-length = (int) 320")
52 static gboolean gst_rtp_siren_pay_setcaps (GstRTPBasePayload * payload,
55 G_DEFINE_TYPE (GstRTPSirenPay, gst_rtp_siren_pay,
56 GST_TYPE_RTP_BASE_AUDIO_PAYLOAD);
57 GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (rtpsirenpay, "rtpsirenpay",
58 GST_RANK_SECONDARY, GST_TYPE_RTP_SIREN_PAY, rtp_element_init (plugin));
61 gst_rtp_siren_pay_class_init (GstRTPSirenPayClass * klass)
63 GstElementClass *gstelement_class;
64 GstRTPBasePayloadClass *gstrtpbasepayload_class;
66 gstelement_class = (GstElementClass *) klass;
67 gstrtpbasepayload_class = (GstRTPBasePayloadClass *) klass;
69 gstrtpbasepayload_class->set_caps = gst_rtp_siren_pay_setcaps;
71 gst_element_class_add_static_pad_template (gstelement_class,
72 &gst_rtp_siren_pay_sink_template);
73 gst_element_class_add_static_pad_template (gstelement_class,
74 &gst_rtp_siren_pay_src_template);
75 gst_element_class_set_static_metadata (gstelement_class,
76 "RTP Payloader for Siren Audio", "Codec/Payloader/Network/RTP",
77 "Packetize Siren audio streams into RTP packets",
78 "Youness Alaoui <kakaroto@kakaroto.homelinux.net>");
80 GST_DEBUG_CATEGORY_INIT (rtpsirenpay_debug, "rtpsirenpay", 0,
81 "siren audio RTP payloader");
85 gst_rtp_siren_pay_init (GstRTPSirenPay * rtpsirenpay)
87 GstRTPBasePayload *rtpbasepayload;
88 GstRTPBaseAudioPayload *rtpbaseaudiopayload;
90 rtpbasepayload = GST_RTP_BASE_PAYLOAD (rtpsirenpay);
91 rtpbaseaudiopayload = GST_RTP_BASE_AUDIO_PAYLOAD (rtpsirenpay);
93 /* we don't set the payload type, it should be set by the application using
94 * the pt property or the default 96 will be used */
95 rtpbasepayload->clock_rate = 16000;
97 /* tell rtpbaseaudiopayload that this is a frame based codec */
98 gst_rtp_base_audio_payload_set_frame_based (rtpbaseaudiopayload);
102 gst_rtp_siren_pay_setcaps (GstRTPBasePayload * rtpbasepayload, GstCaps * caps)
104 GstRTPSirenPay *rtpsirenpay;
105 GstRTPBaseAudioPayload *rtpbaseaudiopayload;
107 GstStructure *structure;
108 const char *payload_name;
110 rtpsirenpay = GST_RTP_SIREN_PAY (rtpbasepayload);
111 rtpbaseaudiopayload = GST_RTP_BASE_AUDIO_PAYLOAD (rtpbasepayload);
113 structure = gst_caps_get_structure (caps, 0);
115 gst_structure_get_int (structure, "dct-length", &dct_length);
116 if (dct_length != 320)
119 payload_name = gst_structure_get_name (structure);
120 if (g_ascii_strcasecmp ("audio/x-siren", payload_name))
123 gst_rtp_base_payload_set_options (rtpbasepayload, "audio", TRUE, "SIREN",
125 /* set options for this frame based audio codec */
126 gst_rtp_base_audio_payload_set_frame_options (rtpbaseaudiopayload, 20, 40);
128 return gst_rtp_base_payload_set_outcaps (rtpbasepayload, NULL);
133 GST_ERROR_OBJECT (rtpsirenpay, "dct-length must be 320, received %d",
139 GST_ERROR_OBJECT (rtpsirenpay, "expected audio/x-siren, received %s",