gst/rtp/: Use more efficient adapter and rtpbuffer methods when possible.
[platform/upstream/gst-plugins-good.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 /* elementfactory information */
30 static GstElementDetails gst_rtp_gsmdepay_details = {
31   "RTP packet depayloader",
32   "Codec/Depayloader/Network",
33   "Extracts GSM audio from RTP packets",
34   "Zeeshan Ali <zeenix@gmail.com>"
35 };
36
37 /* RTPGSMDepay signals and args */
38 enum
39 {
40   /* FILL ME */
41   LAST_SIGNAL
42 };
43
44 static GstStaticPadTemplate gst_rtp_gsm_depay_src_template =
45 GST_STATIC_PAD_TEMPLATE ("src",
46     GST_PAD_SRC,
47     GST_PAD_ALWAYS,
48     GST_STATIC_CAPS ("audio/x-gsm, " "rate = (int) 8000, " "channels = 1")
49     );
50
51 static GstStaticPadTemplate gst_rtp_gsm_depay_sink_template =
52     GST_STATIC_PAD_TEMPLATE ("sink",
53     GST_PAD_SINK,
54     GST_PAD_ALWAYS,
55     GST_STATIC_CAPS ("application/x-rtp, "
56         "media = (string) \"audio\", "
57         "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
58         "clock-rate = (int) 8000, " "encoding-name = (string) \"GSM\";"
59         "application/x-rtp, "
60         "media = (string) \"audio\", "
61         "payload = (int) " GST_RTP_PAYLOAD_GSM_STRING ", "
62         "clock-rate = (int) 8000")
63     );
64
65 static GstBuffer *gst_rtp_gsm_depay_process (GstBaseRTPDepayload * _depayload,
66     GstBuffer * buf);
67 static gboolean gst_rtp_gsm_depay_setcaps (GstBaseRTPDepayload * _depayload,
68     GstCaps * caps);
69
70 GST_BOILERPLATE (GstRTPGSMDepay, gst_rtp_gsm_depay, GstBaseRTPDepayload,
71     GST_TYPE_BASE_RTP_DEPAYLOAD);
72
73 static void
74 gst_rtp_gsm_depay_base_init (gpointer klass)
75 {
76   GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
77
78   gst_element_class_add_pad_template (element_class,
79       gst_static_pad_template_get (&gst_rtp_gsm_depay_src_template));
80   gst_element_class_add_pad_template (element_class,
81       gst_static_pad_template_get (&gst_rtp_gsm_depay_sink_template));
82   gst_element_class_set_details (element_class, &gst_rtp_gsmdepay_details);
83 }
84
85 static void
86 gst_rtp_gsm_depay_class_init (GstRTPGSMDepayClass * klass)
87 {
88   GObjectClass *gobject_class;
89   GstElementClass *gstelement_class;
90   GstBaseRTPDepayloadClass *gstbasertp_depayload_class;
91
92   gobject_class = (GObjectClass *) klass;
93   gstelement_class = (GstElementClass *) klass;
94   gstbasertp_depayload_class = (GstBaseRTPDepayloadClass *) klass;
95
96   parent_class = g_type_class_peek_parent (klass);
97
98   gstbasertp_depayload_class->process = gst_rtp_gsm_depay_process;
99   gstbasertp_depayload_class->set_caps = gst_rtp_gsm_depay_setcaps;
100 }
101
102 static void
103 gst_rtp_gsm_depay_init (GstRTPGSMDepay * rtpgsmdepay,
104     GstRTPGSMDepayClass * klass)
105 {
106   GST_BASE_RTP_DEPAYLOAD (rtpgsmdepay)->clock_rate = 8000;
107 }
108
109 static gboolean
110 gst_rtp_gsm_depay_setcaps (GstBaseRTPDepayload * _depayload, GstCaps * caps)
111 {
112   GstCaps *srccaps;
113   gboolean ret;
114
115   srccaps = gst_static_pad_template_get_caps (&gst_rtp_gsm_depay_src_template);
116   ret = gst_pad_set_caps (GST_BASE_RTP_DEPAYLOAD_SRCPAD (_depayload), srccaps);
117
118   gst_caps_unref (srccaps);
119   return ret;
120 }
121
122 static GstBuffer *
123 gst_rtp_gsm_depay_process (GstBaseRTPDepayload * _depayload, GstBuffer * buf)
124 {
125   GstBuffer *outbuf = NULL;
126
127   GST_DEBUG ("process : got %d bytes, mark %d ts %u seqn %d",
128       GST_BUFFER_SIZE (buf),
129       gst_rtp_buffer_get_marker (buf),
130       gst_rtp_buffer_get_timestamp (buf), gst_rtp_buffer_get_seq (buf));
131
132   outbuf = gst_rtp_buffer_get_payload_buffer (buf);
133
134   return outbuf;
135 }
136
137 gboolean
138 gst_rtp_gsm_depay_plugin_init (GstPlugin * plugin)
139 {
140   return gst_element_register (plugin, "rtpgsmdepay",
141       GST_RANK_MARGINAL, GST_TYPE_RTP_GSM_DEPAY);
142 }