upload tizen1.0 source
[framework/multimedia/gst-plugins-good0.10.git] / gst / rtp / gstrtpsirenpay.c
1 /*
2  * Siren Payloader Gst Element
3  *
4  *   @author: Youness Alaoui <kakaroto@kakaroto.homelinux.net>
5  *
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.
10  *
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.
15  *
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.
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25
26 #include "gstrtpsirenpay.h"
27 #include <gst/rtp/gstrtpbuffer.h>
28
29 GST_DEBUG_CATEGORY_STATIC (rtpsirenpay_debug);
30 #define GST_CAT_DEFAULT (rtpsirenpay_debug)
31
32 static GstStaticPadTemplate gst_rtp_siren_pay_sink_template =
33 GST_STATIC_PAD_TEMPLATE ("sink",
34     GST_PAD_SINK,
35     GST_PAD_ALWAYS,
36     GST_STATIC_CAPS ("audio/x-siren, " "dct-length = (int) 320")
37     );
38
39 static GstStaticPadTemplate gst_rtp_siren_pay_src_template =
40 GST_STATIC_PAD_TEMPLATE ("src",
41     GST_PAD_SRC,
42     GST_PAD_ALWAYS,
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")
49     );
50
51 static gboolean gst_rtp_siren_pay_setcaps (GstBaseRTPPayload * payload,
52     GstCaps * caps);
53
54 GST_BOILERPLATE (GstRTPSirenPay, gst_rtp_siren_pay, GstBaseRTPAudioPayload,
55     GST_TYPE_BASE_RTP_AUDIO_PAYLOAD);
56
57 static void
58 gst_rtp_siren_pay_base_init (gpointer klass)
59 {
60   GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
61
62   gst_element_class_add_pad_template (element_class,
63       gst_static_pad_template_get (&gst_rtp_siren_pay_sink_template));
64   gst_element_class_add_pad_template (element_class,
65       gst_static_pad_template_get (&gst_rtp_siren_pay_src_template));
66   gst_element_class_set_details_simple (element_class,
67       "RTP Payloader for Siren Audio", "Codec/Payloader/Network/RTP",
68       "Packetize Siren audio streams into RTP packets",
69       "Youness Alaoui <kakaroto@kakaroto.homelinux.net>");
70 }
71
72 static void
73 gst_rtp_siren_pay_class_init (GstRTPSirenPayClass * klass)
74 {
75   GstBaseRTPPayloadClass *gstbasertppayload_class;
76
77   gstbasertppayload_class = (GstBaseRTPPayloadClass *) klass;
78
79   gstbasertppayload_class->set_caps = gst_rtp_siren_pay_setcaps;
80
81   GST_DEBUG_CATEGORY_INIT (rtpsirenpay_debug, "rtpsirenpay", 0,
82       "siren audio RTP payloader");
83 }
84
85 static void
86 gst_rtp_siren_pay_init (GstRTPSirenPay * rtpsirenpay,
87     GstRTPSirenPayClass * klass)
88 {
89   GstBaseRTPPayload *basertppayload;
90   GstBaseRTPAudioPayload *basertpaudiopayload;
91
92   basertppayload = GST_BASE_RTP_PAYLOAD (rtpsirenpay);
93   basertpaudiopayload = GST_BASE_RTP_AUDIO_PAYLOAD (rtpsirenpay);
94
95   /* we don't set the payload type, it should be set by the application using
96    * the pt property or the default 96 will be used */
97   basertppayload->clock_rate = 16000;
98
99   /* tell basertpaudiopayload that this is a frame based codec */
100   gst_base_rtp_audio_payload_set_frame_based (basertpaudiopayload);
101 }
102
103 static gboolean
104 gst_rtp_siren_pay_setcaps (GstBaseRTPPayload * basertppayload, GstCaps * caps)
105 {
106   GstRTPSirenPay *rtpsirenpay;
107   GstBaseRTPAudioPayload *basertpaudiopayload;
108   gint dct_length;
109   GstStructure *structure;
110   const char *payload_name;
111
112   rtpsirenpay = GST_RTP_SIREN_PAY (basertppayload);
113   basertpaudiopayload = GST_BASE_RTP_AUDIO_PAYLOAD (basertppayload);
114
115   structure = gst_caps_get_structure (caps, 0);
116
117   gst_structure_get_int (structure, "dct-length", &dct_length);
118   if (dct_length != 320)
119     goto wrong_dct;
120
121   payload_name = gst_structure_get_name (structure);
122   if (g_ascii_strcasecmp ("audio/x-siren", payload_name))
123     goto wrong_caps;
124
125   gst_basertppayload_set_options (basertppayload, "audio", TRUE, "SIREN",
126       16000);
127   /* set options for this frame based audio codec */
128   gst_base_rtp_audio_payload_set_frame_options (basertpaudiopayload, 20, 40);
129
130   return gst_basertppayload_set_outcaps (basertppayload, NULL);
131
132   /* ERRORS */
133 wrong_dct:
134   {
135     GST_ERROR_OBJECT (rtpsirenpay, "dct-length must be 320, received %d",
136         dct_length);
137     return FALSE;
138   }
139 wrong_caps:
140   {
141     GST_ERROR_OBJECT (rtpsirenpay, "expected audio/x-siren, received %s",
142         payload_name);
143     return FALSE;
144   }
145 }
146
147 gboolean
148 gst_rtp_siren_pay_plugin_init (GstPlugin * plugin)
149 {
150   return gst_element_register (plugin, "rtpsirenpay",
151       GST_RANK_SECONDARY, GST_TYPE_RTP_SIREN_PAY);
152 }