Remove unused variables in _class_init
[platform/upstream/gstreamer.git] / gst / rtp / gstrtpgsmpay.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 <stdlib.h>
26 #include <string.h>
27 #include <gst/rtp/gstrtpbuffer.h>
28
29 #include "gstrtpgsmpay.h"
30
31 GST_DEBUG_CATEGORY_STATIC (rtpgsmpay_debug);
32 #define GST_CAT_DEFAULT (rtpgsmpay_debug)
33
34 /* elementfactory information */
35 static const GstElementDetails gst_rtp_gsm_pay_details =
36 GST_ELEMENT_DETAILS ("RTP GSM payloader",
37     "Codec/Payloader/Network",
38     "Payload-encodes GSM audio into a RTP packet",
39     "Zeeshan Ali <zeenix@gmail.com>");
40
41 static GstStaticPadTemplate gst_rtp_gsm_pay_sink_template =
42 GST_STATIC_PAD_TEMPLATE ("sink",
43     GST_PAD_SINK,
44     GST_PAD_ALWAYS,
45     GST_STATIC_CAPS ("audio/x-gsm, " "rate = (int) 8000, " "channels = (int) 1")
46     );
47
48 static GstStaticPadTemplate gst_rtp_gsm_pay_src_template =
49     GST_STATIC_PAD_TEMPLATE ("src",
50     GST_PAD_SRC,
51     GST_PAD_ALWAYS,
52     GST_STATIC_CAPS ("application/x-rtp, "
53         "media = (string) \"audio\", "
54         "payload = (int) " GST_RTP_PAYLOAD_GSM_STRING ", "
55         "clock-rate = (int) 8000, " "encoding-name = (string) \"GSM\"; "
56         "application/x-rtp, "
57         "media = (string) \"audio\", "
58         "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
59         "clock-rate = (int) 8000, " "encoding-name = (string) \"GSM\"")
60     );
61
62 static gboolean gst_rtp_gsm_pay_setcaps (GstBaseRTPPayload * payload,
63     GstCaps * caps);
64 static GstFlowReturn gst_rtp_gsm_pay_handle_buffer (GstBaseRTPPayload * payload,
65     GstBuffer * buffer);
66
67 GST_BOILERPLATE (GstRTPGSMPay, gst_rtp_gsm_pay, GstBaseRTPPayload,
68     GST_TYPE_BASE_RTP_PAYLOAD);
69
70 static void
71 gst_rtp_gsm_pay_base_init (gpointer klass)
72 {
73   GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
74
75   gst_element_class_add_pad_template (element_class,
76       gst_static_pad_template_get (&gst_rtp_gsm_pay_sink_template));
77   gst_element_class_add_pad_template (element_class,
78       gst_static_pad_template_get (&gst_rtp_gsm_pay_src_template));
79   gst_element_class_set_details (element_class, &gst_rtp_gsm_pay_details);
80 }
81
82 static void
83 gst_rtp_gsm_pay_class_init (GstRTPGSMPayClass * klass)
84 {
85   GstBaseRTPPayloadClass *gstbasertppayload_class;
86
87   gstbasertppayload_class = (GstBaseRTPPayloadClass *) klass;
88
89   parent_class = g_type_class_peek_parent (klass);
90
91   gstbasertppayload_class->set_caps = gst_rtp_gsm_pay_setcaps;
92   gstbasertppayload_class->handle_buffer = gst_rtp_gsm_pay_handle_buffer;
93
94   GST_DEBUG_CATEGORY_INIT (rtpgsmpay_debug, "rtpgsmpay", 0,
95       "GSM Audio RTP Payloader");
96 }
97
98 static void
99 gst_rtp_gsm_pay_init (GstRTPGSMPay * rtpgsmpay, GstRTPGSMPayClass * klass)
100 {
101   GST_BASE_RTP_PAYLOAD (rtpgsmpay)->clock_rate = 8000;
102   GST_BASE_RTP_PAYLOAD_PT (rtpgsmpay) = GST_RTP_PAYLOAD_GSM;
103 }
104
105 static gboolean
106 gst_rtp_gsm_pay_setcaps (GstBaseRTPPayload * payload, GstCaps * caps)
107 {
108   const char *stname;
109   GstStructure *structure;
110   gboolean res;
111
112   structure = gst_caps_get_structure (caps, 0);
113
114   stname = gst_structure_get_name (structure);
115
116   if (strcmp ("audio/x-gsm", stname))
117     goto invalid_type;
118
119   gst_basertppayload_set_options (payload, "audio", FALSE, "GSM", 8000);
120   res = gst_basertppayload_set_outcaps (payload, NULL);
121
122   return res;
123
124   /* ERRORS */
125 invalid_type:
126   {
127     GST_WARNING_OBJECT (payload, "invalid media type received");
128     return FALSE;
129   }
130 }
131
132 static GstFlowReturn
133 gst_rtp_gsm_pay_handle_buffer (GstBaseRTPPayload * basepayload,
134     GstBuffer * buffer)
135 {
136   GstRTPGSMPay *rtpgsmpay;
137   guint size, payload_len;
138   GstBuffer *outbuf;
139   guint8 *payload, *data;
140   GstClockTime timestamp, duration;
141   GstFlowReturn ret;
142
143   rtpgsmpay = GST_RTP_GSM_PAY (basepayload);
144
145   size = GST_BUFFER_SIZE (buffer);
146   timestamp = GST_BUFFER_TIMESTAMP (buffer);
147   duration = GST_BUFFER_DURATION (buffer);
148
149   /* FIXME, only one GSM frame per RTP packet for now */
150   payload_len = size;
151
152   outbuf = gst_rtp_buffer_new_allocate (payload_len, 0, 0);
153   /* FIXME, assert for now */
154   g_assert (payload_len <= GST_BASE_RTP_PAYLOAD_MTU (rtpgsmpay));
155
156   /* copy timestamp and duration */
157   GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
158   GST_BUFFER_DURATION (outbuf) = duration;
159
160   /* get payload */
161   payload = gst_rtp_buffer_get_payload (outbuf);
162
163   data = GST_BUFFER_DATA (buffer);
164
165   /* copy data in payload */
166   memcpy (&payload[0], data, size);
167
168   gst_buffer_unref (buffer);
169
170   GST_DEBUG ("gst_rtp_gsm_pay_chain: pushing buffer of size %d",
171       GST_BUFFER_SIZE (outbuf));
172
173   ret = gst_basertppayload_push (basepayload, outbuf);
174
175   return ret;
176 }
177
178 gboolean
179 gst_rtp_gsm_pay_plugin_init (GstPlugin * plugin)
180 {
181   return gst_element_register (plugin, "rtpgsmpay",
182       GST_RANK_NONE, GST_TYPE_RTP_GSM_PAY);
183 }