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., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
26 #include "gstrtpsirenpay.h"
27 #include <gst/rtp/gstrtpbuffer.h>
29 GST_DEBUG_CATEGORY_STATIC (rtpsirenpay_debug);
30 #define GST_CAT_DEFAULT (rtpsirenpay_debug)
32 static GstStaticPadTemplate gst_rtp_siren_pay_sink_template =
33 GST_STATIC_PAD_TEMPLATE ("sink",
36 GST_STATIC_CAPS ("audio/x-siren, " "dct-length = (int) 320")
39 static GstStaticPadTemplate gst_rtp_siren_pay_src_template =
40 GST_STATIC_PAD_TEMPLATE ("src",
43 GST_STATIC_CAPS ("application/x-rtp, "
44 "media = (string) \"audio\", "
45 "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
46 "clock-rate = (int) 16000, "
47 "encoding-name = (string) \"SIREN\", "
48 "bitrate = (string) \"16000\", " "dct-length = (int) 320")
51 static gboolean gst_rtp_siren_pay_setcaps (GstRTPBasePayload * payload,
54 G_DEFINE_TYPE (GstRTPSirenPay, gst_rtp_siren_pay,
55 GST_TYPE_RTP_BASE_AUDIO_PAYLOAD);
58 gst_rtp_siren_pay_class_init (GstRTPSirenPayClass * klass)
60 GstElementClass *gstelement_class;
61 GstRTPBasePayloadClass *gstrtpbasepayload_class;
63 gstelement_class = (GstElementClass *) klass;
64 gstrtpbasepayload_class = (GstRTPBasePayloadClass *) klass;
66 gstrtpbasepayload_class->set_caps = gst_rtp_siren_pay_setcaps;
68 gst_element_class_add_pad_template (gstelement_class,
69 gst_static_pad_template_get (&gst_rtp_siren_pay_sink_template));
70 gst_element_class_add_pad_template (gstelement_class,
71 gst_static_pad_template_get (&gst_rtp_siren_pay_src_template));
72 gst_element_class_set_details_simple (gstelement_class,
73 "RTP Payloader for Siren Audio", "Codec/Payloader/Network/RTP",
74 "Packetize Siren audio streams into RTP packets",
75 "Youness Alaoui <kakaroto@kakaroto.homelinux.net>");
77 GST_DEBUG_CATEGORY_INIT (rtpsirenpay_debug, "rtpsirenpay", 0,
78 "siren audio RTP payloader");
82 gst_rtp_siren_pay_init (GstRTPSirenPay * rtpsirenpay)
84 GstRTPBasePayload *rtpbasepayload;
85 GstRTPBaseAudioPayload *rtpbaseaudiopayload;
87 rtpbasepayload = GST_RTP_BASE_PAYLOAD (rtpsirenpay);
88 rtpbaseaudiopayload = GST_RTP_BASE_AUDIO_PAYLOAD (rtpsirenpay);
90 /* we don't set the payload type, it should be set by the application using
91 * the pt property or the default 96 will be used */
92 rtpbasepayload->clock_rate = 16000;
94 /* tell rtpbaseaudiopayload that this is a frame based codec */
95 gst_rtp_base_audio_payload_set_frame_based (rtpbaseaudiopayload);
99 gst_rtp_siren_pay_setcaps (GstRTPBasePayload * rtpbasepayload, GstCaps * caps)
101 GstRTPSirenPay *rtpsirenpay;
102 GstRTPBaseAudioPayload *rtpbaseaudiopayload;
104 GstStructure *structure;
105 const char *payload_name;
107 rtpsirenpay = GST_RTP_SIREN_PAY (rtpbasepayload);
108 rtpbaseaudiopayload = GST_RTP_BASE_AUDIO_PAYLOAD (rtpbasepayload);
110 structure = gst_caps_get_structure (caps, 0);
112 gst_structure_get_int (structure, "dct-length", &dct_length);
113 if (dct_length != 320)
116 payload_name = gst_structure_get_name (structure);
117 if (g_ascii_strcasecmp ("audio/x-siren", payload_name))
120 gst_rtp_base_payload_set_options (rtpbasepayload, "audio", TRUE, "SIREN",
122 /* set options for this frame based audio codec */
123 gst_rtp_base_audio_payload_set_frame_options (rtpbaseaudiopayload, 20, 40);
125 return gst_rtp_base_payload_set_outcaps (rtpbasepayload, NULL);
130 GST_ERROR_OBJECT (rtpsirenpay, "dct-length must be 320, received %d",
136 GST_ERROR_OBJECT (rtpsirenpay, "expected audio/x-siren, received %s",
143 gst_rtp_siren_pay_plugin_init (GstPlugin * plugin)
145 return gst_element_register (plugin, "rtpsirenpay",
146 GST_RANK_SECONDARY, GST_TYPE_RTP_SIREN_PAY);