Add -Wmissing-declarations -Wmissing-prototypes warning flags
[platform/upstream/gstreamer.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 /* elementfactory information */
30 static GstElementDetails gst_rtp_siren_pay_details = {
31   "RTP Payloader for Siren Audio",
32   "Codec/Payloader/Network",
33   "Packetize Siren audio streams into RTP packets",
34   "Youness Alaoui <kakaroto@kakaroto.homelinux.net>"
35 };
36
37 GST_DEBUG_CATEGORY_STATIC (rtpsirenpay_debug);
38 #define GST_CAT_DEFAULT (rtpsirenpay_debug)
39
40 static GstStaticPadTemplate gst_rtp_siren_pay_sink_template =
41 GST_STATIC_PAD_TEMPLATE ("sink",
42     GST_PAD_SINK,
43     GST_PAD_ALWAYS,
44     GST_STATIC_CAPS ("audio/x-siren, " "dct-length = (int) 320")
45     );
46
47 static GstStaticPadTemplate gst_rtp_siren_pay_src_template =
48 GST_STATIC_PAD_TEMPLATE ("src",
49     GST_PAD_SRC,
50     GST_PAD_ALWAYS,
51     GST_STATIC_CAPS ("application/x-rtp, "
52         "media = (string) \"audio\", "
53         "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
54         "clock-rate = (int) 16000, "
55         "encoding-name = (string) \"SIREN\", "
56         "bitrate = (string) \"16000\", " "dct-length = (int) 320")
57     );
58
59 static gboolean gst_rtp_siren_pay_setcaps (GstBaseRTPPayload * payload,
60     GstCaps * caps);
61
62 GST_BOILERPLATE (GstRTPSirenPay, gst_rtp_siren_pay, GstBaseRTPAudioPayload,
63     GST_TYPE_BASE_RTP_AUDIO_PAYLOAD);
64
65 static void
66 gst_rtp_siren_pay_base_init (gpointer klass)
67 {
68   GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
69
70   gst_element_class_add_pad_template (element_class,
71       gst_static_pad_template_get (&gst_rtp_siren_pay_sink_template));
72   gst_element_class_add_pad_template (element_class,
73       gst_static_pad_template_get (&gst_rtp_siren_pay_src_template));
74   gst_element_class_set_details (element_class, &gst_rtp_siren_pay_details);
75 }
76
77 static void
78 gst_rtp_siren_pay_class_init (GstRTPSirenPayClass * klass)
79 {
80   GstBaseRTPPayloadClass *gstbasertppayload_class;
81
82   gstbasertppayload_class = (GstBaseRTPPayloadClass *) klass;
83
84   gstbasertppayload_class->set_caps = gst_rtp_siren_pay_setcaps;
85
86   GST_DEBUG_CATEGORY_INIT (rtpsirenpay_debug, "rtpsirenpay", 0,
87       "siren audio RTP payloader");
88 }
89
90 static void
91 gst_rtp_siren_pay_init (GstRTPSirenPay * rtpsirenpay,
92     GstRTPSirenPayClass * klass)
93 {
94   GstBaseRTPPayload *basertppayload;
95   GstBaseRTPAudioPayload *basertpaudiopayload;
96
97   basertppayload = GST_BASE_RTP_PAYLOAD (rtpsirenpay);
98   basertpaudiopayload = GST_BASE_RTP_AUDIO_PAYLOAD (rtpsirenpay);
99
100   /* we don't set the payload type, it should be set by the application using
101    * the pt property or the default 96 will be used */
102   basertppayload->clock_rate = 16000;
103
104   /* tell basertpaudiopayload that this is a frame based codec */
105   gst_base_rtp_audio_payload_set_frame_based (basertpaudiopayload);
106 }
107
108 static gboolean
109 gst_rtp_siren_pay_setcaps (GstBaseRTPPayload * basertppayload, GstCaps * caps)
110 {
111   GstRTPSirenPay *rtpsirenpay;
112   GstBaseRTPAudioPayload *basertpaudiopayload;
113   gint dct_length;
114   GstStructure *structure;
115   const char *payload_name;
116
117   rtpsirenpay = GST_RTP_SIREN_PAY (basertppayload);
118   basertpaudiopayload = GST_BASE_RTP_AUDIO_PAYLOAD (basertppayload);
119
120   structure = gst_caps_get_structure (caps, 0);
121
122   gst_structure_get_int (structure, "dct-length", &dct_length);
123   if (dct_length != 320)
124     goto wrong_dct;
125
126   payload_name = gst_structure_get_name (structure);
127   if (g_ascii_strcasecmp ("audio/x-siren", payload_name))
128     goto wrong_caps;
129
130   gst_basertppayload_set_options (basertppayload, "audio", TRUE, "SIREN",
131       16000);
132   /* set options for this frame based audio codec */
133   gst_base_rtp_audio_payload_set_frame_options (basertpaudiopayload, 20, 40);
134
135   return gst_basertppayload_set_outcaps (basertppayload, NULL);
136
137   /* ERRORS */
138 wrong_dct:
139   {
140     GST_ERROR_OBJECT (rtpsirenpay, "dct-length must be 320, received %d",
141         dct_length);
142     return FALSE;
143   }
144 wrong_caps:
145   {
146     GST_ERROR_OBJECT (rtpsirenpay, "expected audio/x-siren, received %s",
147         payload_name);
148     return FALSE;
149   }
150 }
151
152 gboolean
153 gst_rtp_siren_pay_plugin_init (GstPlugin * plugin)
154 {
155   return gst_element_register (plugin, "rtpsirenpay",
156       GST_RANK_NONE, GST_TYPE_RTP_SIREN_PAY);
157 }