Remove unused variables in _class_init
[platform/upstream/gstreamer.git] / gst / rtp / gstrtpg726pay.c
1 /* GStreamer
2  * Copyright (C) 1999 Erik Walthinsen <omega@cse.ogi.edu>
3  * Copyright (C) 2005 Edgard Lima <edgard.lima@indt.org.br>
4  * Copyright (C) 2005 Nokia Corporation <kai.vehmanen@nokia.com>
5  * Copyright (C) 2007,2008 Axis Communications <dev-gstreamer@axis.com>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 #ifdef HAVE_CONFIG_H
24 #  include "config.h"
25 #endif
26
27 #include <stdlib.h>
28 #include <string.h>
29 #include <gst/rtp/gstrtpbuffer.h>
30
31 #include "gstrtpg726pay.h"
32
33 static const GstElementDetails gst_rtp_g726_pay_details =
34 GST_ELEMENT_DETAILS ("RTP G.726 payloader",
35     "Codec/Payloader/Network",
36     "Payload-encodes G.726 audio into a RTP packet",
37     "Axis Communications <dev-gstreamer@axis.com>");
38
39 static GstStaticPadTemplate gst_rtp_g726_pay_sink_template =
40 GST_STATIC_PAD_TEMPLATE ("sink",
41     GST_PAD_SINK,
42     GST_PAD_ALWAYS,
43     GST_STATIC_CAPS ("audio/x-adpcm, "
44         "channels = (int) 1, "
45         "rate = (int) 8000, "
46         "bitrate = (int) { 16000, 24000, 32000, 40000 }, "
47         "layout = (string) \"g726\"")
48     );
49
50 static GstStaticPadTemplate gst_rtp_g726_pay_src_template =
51 GST_STATIC_PAD_TEMPLATE ("src",
52     GST_PAD_SRC,
53     GST_PAD_ALWAYS,
54     GST_STATIC_CAPS ("application/x-rtp, "
55         "media = (string) \"audio\", "
56         "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
57         "clock-rate = (int) 8000, "
58         "encoding-name = (string) { \"G726-16\", \"G726-24\", \"G726-32\", \"G726-40\" } ")
59     );
60
61 static gboolean gst_rtp_g726_pay_setcaps (GstBaseRTPPayload * payload,
62     GstCaps * caps);
63
64 GST_BOILERPLATE (GstRtpG726Pay, gst_rtp_g726_pay, GstBaseRTPAudioPayload,
65     GST_TYPE_BASE_RTP_AUDIO_PAYLOAD);
66
67 static void
68 gst_rtp_g726_pay_base_init (gpointer klass)
69 {
70   GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
71
72   gst_element_class_add_pad_template (element_class,
73       gst_static_pad_template_get (&gst_rtp_g726_pay_sink_template));
74   gst_element_class_add_pad_template (element_class,
75       gst_static_pad_template_get (&gst_rtp_g726_pay_src_template));
76   gst_element_class_set_details (element_class, &gst_rtp_g726_pay_details);
77 }
78
79 static void
80 gst_rtp_g726_pay_class_init (GstRtpG726PayClass * klass)
81 {
82   GstBaseRTPPayloadClass *gstbasertppayload_class;
83
84   gstbasertppayload_class = (GstBaseRTPPayloadClass *) klass;
85
86   parent_class = g_type_class_peek_parent (klass);
87
88   gstbasertppayload_class->set_caps = gst_rtp_g726_pay_setcaps;
89 }
90
91 static void
92 gst_rtp_g726_pay_init (GstRtpG726Pay * rtpg726pay, GstRtpG726PayClass * klass)
93 {
94   GstBaseRTPAudioPayload *basertpaudiopayload;
95
96   basertpaudiopayload = GST_BASE_RTP_AUDIO_PAYLOAD (rtpg726pay);
97
98   GST_BASE_RTP_PAYLOAD (rtpg726pay)->clock_rate = 8000;
99
100   /* sample based codec */
101   gst_base_rtp_audio_payload_set_sample_based (basertpaudiopayload);
102 }
103
104 static gboolean
105 gst_rtp_g726_pay_setcaps (GstBaseRTPPayload * payload, GstCaps * caps)
106 {
107   gchar *encoding_name;
108   GstStructure *structure = gst_caps_get_structure (caps, 0);
109   GstBaseRTPAudioPayload *basertpaudiopayload;
110   gint bitrate;
111
112   basertpaudiopayload = GST_BASE_RTP_AUDIO_PAYLOAD (payload);
113
114   if (!gst_structure_get_int (structure, "bitrate", &bitrate))
115     bitrate = 32000;
116
117   switch (bitrate) {
118     case 16000:
119       encoding_name = g_strdup ("G726-16");
120       gst_base_rtp_audio_payload_set_samplebits_options (basertpaudiopayload,
121           2);
122       break;
123     case 24000:
124       encoding_name = g_strdup ("G726-24");
125       gst_base_rtp_audio_payload_set_samplebits_options (basertpaudiopayload,
126           3);
127       break;
128     case 32000:
129       encoding_name = g_strdup ("G726-32");
130       gst_base_rtp_audio_payload_set_samplebits_options (basertpaudiopayload,
131           4);
132       break;
133     case 40000:
134       encoding_name = g_strdup ("G726-40");
135       gst_base_rtp_audio_payload_set_samplebits_options (basertpaudiopayload,
136           5);
137       break;
138     default:
139       goto invalid_bitrate;
140   }
141
142   gst_basertppayload_set_options (payload, "audio", TRUE, encoding_name, 8000);
143   gst_basertppayload_set_outcaps (payload, NULL);
144
145   g_free (encoding_name);
146
147   return TRUE;
148
149   /* ERRORS */
150 invalid_bitrate:
151   {
152     GST_ERROR_OBJECT (payload, "invalid bitrate %d specified", bitrate);
153     return FALSE;
154   }
155 }
156
157 gboolean
158 gst_rtp_g726_pay_plugin_init (GstPlugin * plugin)
159 {
160   return gst_element_register (plugin, "rtpg726pay",
161       GST_RANK_NONE, GST_TYPE_RTP_G726_PAY);
162 }