gst/rtp/gstrtpg726pay.c: Remove unused variable so that we can compile again.
[platform/upstream/gst-plugins-good.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 packet 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   GObjectClass *gobject_class;
83   GstElementClass *gstelement_class;
84   GstBaseRTPPayloadClass *gstbasertppayload_class;
85
86   gobject_class = (GObjectClass *) klass;
87   gstelement_class = (GstElementClass *) klass;
88   gstbasertppayload_class = (GstBaseRTPPayloadClass *) klass;
89
90   parent_class = g_type_class_peek_parent (klass);
91
92   gstbasertppayload_class->set_caps = gst_rtp_g726_pay_setcaps;
93 }
94
95 static void
96 gst_rtp_g726_pay_init (GstRtpG726Pay * rtpg726pay, GstRtpG726PayClass * klass)
97 {
98   GstBaseRTPAudioPayload *basertpaudiopayload;
99
100   basertpaudiopayload = GST_BASE_RTP_AUDIO_PAYLOAD (rtpg726pay);
101
102   GST_BASE_RTP_PAYLOAD (rtpg726pay)->clock_rate = 8000;
103
104   /* sample based codec */
105   gst_base_rtp_audio_payload_set_sample_based (basertpaudiopayload);
106 }
107
108 static gboolean
109 gst_rtp_g726_pay_setcaps (GstBaseRTPPayload * payload, GstCaps * caps)
110 {
111   gchar *encoding_name;
112   GstStructure *structure = gst_caps_get_structure (caps, 0);
113   GstBaseRTPAudioPayload *basertpaudiopayload;
114   gint bitrate;
115
116   basertpaudiopayload = GST_BASE_RTP_AUDIO_PAYLOAD (payload);
117
118   if (!gst_structure_get_int (structure, "bitrate", &bitrate))
119     bitrate = 32000;
120
121   switch (bitrate) {
122     case 16000:
123       encoding_name = g_strdup ("G726-16");
124       gst_base_rtp_audio_payload_set_samplebits_options (basertpaudiopayload,
125           2);
126       break;
127     case 24000:
128       encoding_name = g_strdup ("G726-24");
129       gst_base_rtp_audio_payload_set_samplebits_options (basertpaudiopayload,
130           3);
131       break;
132     case 32000:
133       encoding_name = g_strdup ("G726-32");
134       gst_base_rtp_audio_payload_set_samplebits_options (basertpaudiopayload,
135           4);
136       break;
137     case 40000:
138       encoding_name = g_strdup ("G726-40");
139       gst_base_rtp_audio_payload_set_samplebits_options (basertpaudiopayload,
140           5);
141       break;
142     default:
143       goto invalid_bitrate;
144   }
145
146   gst_basertppayload_set_options (payload, "audio", TRUE, encoding_name, 8000);
147   gst_basertppayload_set_outcaps (payload, NULL);
148
149   g_free (encoding_name);
150
151   return TRUE;
152
153   /* ERRORS */
154 invalid_bitrate:
155   {
156     GST_ERROR_OBJECT (payload, "invalid bitrate %d specified", bitrate);
157     return FALSE;
158   }
159 }
160
161 gboolean
162 gst_rtp_g726_pay_plugin_init (GstPlugin * plugin)
163 {
164   return gst_element_register (plugin, "rtpg726pay",
165       GST_RANK_NONE, GST_TYPE_RTP_G726_PAY);
166 }