Remove unused variables in _class_init
[platform/upstream/gstreamer.git] / gst / rtp / gstrtpgsmdepay.c
1 /* GStreamer
2  * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3  * Copyright (C) <2005> Zeeshan Ali <zeenix@gmail.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #  include "config.h"
23 #endif
24
25 #include <string.h>
26 #include <gst/rtp/gstrtpbuffer.h>
27 #include "gstrtpgsmdepay.h"
28
29 GST_DEBUG_CATEGORY_STATIC (rtpgsmdepay_debug);
30 #define GST_CAT_DEFAULT (rtpgsmdepay_debug)
31
32 /* elementfactory information */
33 static GstElementDetails gst_rtp_gsmdepay_details = {
34   "RTP GSM depayloader",
35   "Codec/Depayloader/Network",
36   "Extracts GSM audio from RTP packets",
37   "Zeeshan Ali <zeenix@gmail.com>"
38 };
39
40 /* RTPGSMDepay signals and args */
41 enum
42 {
43   /* FILL ME */
44   LAST_SIGNAL
45 };
46
47 static GstStaticPadTemplate gst_rtp_gsm_depay_src_template =
48 GST_STATIC_PAD_TEMPLATE ("src",
49     GST_PAD_SRC,
50     GST_PAD_ALWAYS,
51     GST_STATIC_CAPS ("audio/x-gsm, " "rate = (int) 8000, " "channels = 1")
52     );
53
54 static GstStaticPadTemplate gst_rtp_gsm_depay_sink_template =
55     GST_STATIC_PAD_TEMPLATE ("sink",
56     GST_PAD_SINK,
57     GST_PAD_ALWAYS,
58     GST_STATIC_CAPS ("application/x-rtp, "
59         "media = (string) \"audio\", "
60         "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
61         "clock-rate = (int) 8000, " "encoding-name = (string) \"GSM\";"
62         "application/x-rtp, "
63         "media = (string) \"audio\", "
64         "payload = (int) " GST_RTP_PAYLOAD_GSM_STRING ", "
65         "clock-rate = (int) 8000")
66     );
67
68 static GstBuffer *gst_rtp_gsm_depay_process (GstBaseRTPDepayload * _depayload,
69     GstBuffer * buf);
70 static gboolean gst_rtp_gsm_depay_setcaps (GstBaseRTPDepayload * _depayload,
71     GstCaps * caps);
72
73 GST_BOILERPLATE (GstRTPGSMDepay, gst_rtp_gsm_depay, GstBaseRTPDepayload,
74     GST_TYPE_BASE_RTP_DEPAYLOAD);
75
76 static void
77 gst_rtp_gsm_depay_base_init (gpointer klass)
78 {
79   GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
80
81   gst_element_class_add_pad_template (element_class,
82       gst_static_pad_template_get (&gst_rtp_gsm_depay_src_template));
83   gst_element_class_add_pad_template (element_class,
84       gst_static_pad_template_get (&gst_rtp_gsm_depay_sink_template));
85   gst_element_class_set_details (element_class, &gst_rtp_gsmdepay_details);
86 }
87
88 static void
89 gst_rtp_gsm_depay_class_init (GstRTPGSMDepayClass * klass)
90 {
91   GstBaseRTPDepayloadClass *gstbasertp_depayload_class;
92
93   gstbasertp_depayload_class = (GstBaseRTPDepayloadClass *) klass;
94
95   parent_class = g_type_class_peek_parent (klass);
96
97   gstbasertp_depayload_class->process = gst_rtp_gsm_depay_process;
98   gstbasertp_depayload_class->set_caps = gst_rtp_gsm_depay_setcaps;
99
100   GST_DEBUG_CATEGORY_INIT (rtpgsmdepay_debug, "rtpgsmdepay", 0,
101       "GSM Audio RTP Depayloader");
102 }
103
104 static void
105 gst_rtp_gsm_depay_init (GstRTPGSMDepay * rtpgsmdepay,
106     GstRTPGSMDepayClass * klass)
107 {
108   /* needed because of GST_BOILERPLATE */
109 }
110
111 static gboolean
112 gst_rtp_gsm_depay_setcaps (GstBaseRTPDepayload * depayload, GstCaps * caps)
113 {
114   GstCaps *srccaps;
115   gboolean ret;
116   GstStructure *structure;
117   gint clock_rate;
118
119   structure = gst_caps_get_structure (caps, 0);
120
121   if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
122     clock_rate = 8000;          /* default */
123   depayload->clock_rate = clock_rate;
124
125   srccaps = gst_caps_new_simple ("audio/x-gsm",
126       "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, clock_rate, NULL);
127   ret = gst_pad_set_caps (GST_BASE_RTP_DEPAYLOAD_SRCPAD (depayload), srccaps);
128   gst_caps_unref (srccaps);
129
130   return ret;
131 }
132
133 static GstBuffer *
134 gst_rtp_gsm_depay_process (GstBaseRTPDepayload * _depayload, GstBuffer * buf)
135 {
136   GstBuffer *outbuf = NULL;
137   gboolean marker;
138
139   marker = gst_rtp_buffer_get_marker (buf);
140
141   GST_DEBUG ("process : got %d bytes, mark %d ts %u seqn %d",
142       GST_BUFFER_SIZE (buf), marker,
143       gst_rtp_buffer_get_timestamp (buf), gst_rtp_buffer_get_seq (buf));
144
145   outbuf = gst_rtp_buffer_get_payload_buffer (buf);
146
147   if (marker) {
148     /* mark start of talkspurt with DISCONT */
149     GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
150   }
151
152   return outbuf;
153 }
154
155 gboolean
156 gst_rtp_gsm_depay_plugin_init (GstPlugin * plugin)
157 {
158   return gst_element_register (plugin, "rtpgsmdepay",
159       GST_RANK_MARGINAL, GST_TYPE_RTP_GSM_DEPAY);
160 }