Remove unused variables in _class_init
[platform/upstream/gstreamer.git] / gst / rtp / gstrtppcmadepay.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> Zeeshan Ali <zeenix@gmail.com>
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 <string.h>
27 #include <gst/rtp/gstrtpbuffer.h>
28 #include "gstrtppcmadepay.h"
29
30 /* elementfactory information */
31 static const GstElementDetails gst_rtp_pcmadepay_details =
32 GST_ELEMENT_DETAILS ("RTP PCMA depayloader",
33     "Codec/Depayloader/Network",
34     "Extracts PCMA audio from RTP packets",
35     "Edgard Lima <edgard.lima@indt.org.br>, Zeeshan Ali <zeenix@gmail.com>");
36
37 /* RtpPcmaDepay signals and args */
38 enum
39 {
40   /* FILL ME */
41   LAST_SIGNAL
42 };
43
44 enum
45 {
46   ARG_0
47 };
48
49 static GstStaticPadTemplate gst_rtp_pcma_depay_sink_template =
50     GST_STATIC_PAD_TEMPLATE ("sink",
51     GST_PAD_SINK,
52     GST_PAD_ALWAYS,
53     GST_STATIC_CAPS ("application/x-rtp, "
54         "media = (string) \"audio\", "
55         "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
56         "clock-rate = (int) 8000, " "encoding-name = (string) \"PCMA\";"
57         "application/x-rtp, "
58         "media = (string) \"audio\", "
59         "payload = (int) " GST_RTP_PAYLOAD_PCMA_STRING ", "
60         "clock-rate = (int) 8000")
61     );
62
63 static GstStaticPadTemplate gst_rtp_pcma_depay_src_template =
64 GST_STATIC_PAD_TEMPLATE ("src",
65     GST_PAD_SRC,
66     GST_PAD_ALWAYS,
67     GST_STATIC_CAPS ("audio/x-alaw, channels = (int) 1, rate = (int) 8000")
68     );
69
70 static GstBuffer *gst_rtp_pcma_depay_process (GstBaseRTPDepayload * depayload,
71     GstBuffer * buf);
72 static gboolean gst_rtp_pcma_depay_setcaps (GstBaseRTPDepayload * depayload,
73     GstCaps * caps);
74
75 GST_BOILERPLATE (GstRtpPcmaDepay, gst_rtp_pcma_depay, GstBaseRTPDepayload,
76     GST_TYPE_BASE_RTP_DEPAYLOAD);
77
78 static void
79 gst_rtp_pcma_depay_base_init (gpointer klass)
80 {
81   GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
82
83   gst_element_class_add_pad_template (element_class,
84       gst_static_pad_template_get (&gst_rtp_pcma_depay_src_template));
85   gst_element_class_add_pad_template (element_class,
86       gst_static_pad_template_get (&gst_rtp_pcma_depay_sink_template));
87   gst_element_class_set_details (element_class, &gst_rtp_pcmadepay_details);
88 }
89
90 static void
91 gst_rtp_pcma_depay_class_init (GstRtpPcmaDepayClass * klass)
92 {
93   GstBaseRTPDepayloadClass *gstbasertpdepayload_class;
94
95   gstbasertpdepayload_class = (GstBaseRTPDepayloadClass *) klass;
96
97   parent_class = g_type_class_peek_parent (klass);
98
99   gstbasertpdepayload_class->process = gst_rtp_pcma_depay_process;
100   gstbasertpdepayload_class->set_caps = gst_rtp_pcma_depay_setcaps;
101 }
102
103 static void
104 gst_rtp_pcma_depay_init (GstRtpPcmaDepay * rtppcmadepay,
105     GstRtpPcmaDepayClass * klass)
106 {
107   GstBaseRTPDepayload *depayload;
108
109   depayload = GST_BASE_RTP_DEPAYLOAD (rtppcmadepay);
110
111   gst_pad_use_fixed_caps (GST_BASE_RTP_DEPAYLOAD_SRCPAD (depayload));
112 }
113
114 static gboolean
115 gst_rtp_pcma_depay_setcaps (GstBaseRTPDepayload * depayload, GstCaps * caps)
116 {
117   GstCaps *srccaps;
118   GstStructure *structure;
119   gboolean ret;
120   gint clock_rate;
121
122   structure = gst_caps_get_structure (caps, 0);
123
124   if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
125     clock_rate = 8000;          /* default */
126   depayload->clock_rate = clock_rate;
127
128   srccaps = gst_caps_new_simple ("audio/x-alaw",
129       "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, clock_rate, NULL);
130   ret = gst_pad_set_caps (GST_BASE_RTP_DEPAYLOAD_SRCPAD (depayload), srccaps);
131   gst_caps_unref (srccaps);
132
133   return ret;
134 }
135
136 static GstBuffer *
137 gst_rtp_pcma_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
138 {
139   GstBuffer *outbuf = NULL;
140   gboolean marker;
141   guint len;
142
143   marker = gst_rtp_buffer_get_marker (buf);
144
145   GST_DEBUG ("process : got %d bytes, mark %d ts %u seqn %d",
146       GST_BUFFER_SIZE (buf), marker,
147       gst_rtp_buffer_get_timestamp (buf), gst_rtp_buffer_get_seq (buf));
148
149   len = gst_rtp_buffer_get_payload_len (buf);
150   outbuf = gst_rtp_buffer_get_payload_buffer (buf);
151
152   GST_BUFFER_DURATION (outbuf) =
153       gst_util_uint64_scale_int (len, GST_SECOND, depayload->clock_rate);
154
155   if (marker) {
156     /* mark start of talkspurt with DISCONT */
157     GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
158   }
159
160   return outbuf;
161 }
162
163 gboolean
164 gst_rtp_pcma_depay_plugin_init (GstPlugin * plugin)
165 {
166   return gst_element_register (plugin, "rtppcmadepay",
167       GST_RANK_MARGINAL, GST_TYPE_RTP_PCMA_DEPAY);
168 }