Tizen 2.0 Release
[framework/multimedia/gst-plugins-good0.10.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 /* RTPGSMDepay signals and args */
33 enum
34 {
35   /* FILL ME */
36   LAST_SIGNAL
37 };
38
39 static GstStaticPadTemplate gst_rtp_gsm_depay_src_template =
40 GST_STATIC_PAD_TEMPLATE ("src",
41     GST_PAD_SRC,
42     GST_PAD_ALWAYS,
43     GST_STATIC_CAPS ("audio/x-gsm, " "rate = (int) 8000, " "channels = 1")
44     );
45
46 static GstStaticPadTemplate gst_rtp_gsm_depay_sink_template =
47     GST_STATIC_PAD_TEMPLATE ("sink",
48     GST_PAD_SINK,
49     GST_PAD_ALWAYS,
50     GST_STATIC_CAPS ("application/x-rtp, "
51         "media = (string) \"audio\", "
52         "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
53         "clock-rate = (int) 8000, " "encoding-name = (string) \"GSM\";"
54         "application/x-rtp, "
55         "media = (string) \"audio\", "
56         "payload = (int) " GST_RTP_PAYLOAD_GSM_STRING ", "
57         "clock-rate = (int) 8000")
58     );
59
60 static GstBuffer *gst_rtp_gsm_depay_process (GstBaseRTPDepayload * _depayload,
61     GstBuffer * buf);
62 static gboolean gst_rtp_gsm_depay_setcaps (GstBaseRTPDepayload * _depayload,
63     GstCaps * caps);
64
65 GST_BOILERPLATE (GstRTPGSMDepay, gst_rtp_gsm_depay, GstBaseRTPDepayload,
66     GST_TYPE_BASE_RTP_DEPAYLOAD);
67
68 static void
69 gst_rtp_gsm_depay_base_init (gpointer klass)
70 {
71   GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
72
73   gst_element_class_add_static_pad_template (element_class,
74       &gst_rtp_gsm_depay_src_template);
75   gst_element_class_add_static_pad_template (element_class,
76       &gst_rtp_gsm_depay_sink_template);
77   gst_element_class_set_details_simple (element_class, "RTP GSM depayloader",
78       "Codec/Depayloader/Network/RTP",
79       "Extracts GSM audio from RTP packets", "Zeeshan Ali <zeenix@gmail.com>");
80 }
81
82 static void
83 gst_rtp_gsm_depay_class_init (GstRTPGSMDepayClass * klass)
84 {
85   GstBaseRTPDepayloadClass *gstbasertp_depayload_class;
86
87   gstbasertp_depayload_class = (GstBaseRTPDepayloadClass *) klass;
88
89   gstbasertp_depayload_class->process = gst_rtp_gsm_depay_process;
90   gstbasertp_depayload_class->set_caps = gst_rtp_gsm_depay_setcaps;
91
92   GST_DEBUG_CATEGORY_INIT (rtpgsmdepay_debug, "rtpgsmdepay", 0,
93       "GSM Audio RTP Depayloader");
94 }
95
96 static void
97 gst_rtp_gsm_depay_init (GstRTPGSMDepay * rtpgsmdepay,
98     GstRTPGSMDepayClass * klass)
99 {
100   /* needed because of GST_BOILERPLATE */
101 }
102
103 static gboolean
104 gst_rtp_gsm_depay_setcaps (GstBaseRTPDepayload * depayload, GstCaps * caps)
105 {
106   GstCaps *srccaps;
107   gboolean ret;
108   GstStructure *structure;
109   gint clock_rate;
110
111   structure = gst_caps_get_structure (caps, 0);
112
113   if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
114     clock_rate = 8000;          /* default */
115   depayload->clock_rate = clock_rate;
116
117   srccaps = gst_caps_new_simple ("audio/x-gsm",
118       "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, clock_rate, NULL);
119   ret = gst_pad_set_caps (GST_BASE_RTP_DEPAYLOAD_SRCPAD (depayload), srccaps);
120   gst_caps_unref (srccaps);
121
122   return ret;
123 }
124
125 static GstBuffer *
126 gst_rtp_gsm_depay_process (GstBaseRTPDepayload * _depayload, GstBuffer * buf)
127 {
128   GstBuffer *outbuf = NULL;
129   gboolean marker;
130
131   marker = gst_rtp_buffer_get_marker (buf);
132
133   GST_DEBUG ("process : got %d bytes, mark %d ts %u seqn %d",
134       GST_BUFFER_SIZE (buf), marker,
135       gst_rtp_buffer_get_timestamp (buf), gst_rtp_buffer_get_seq (buf));
136
137   outbuf = gst_rtp_buffer_get_payload_buffer (buf);
138
139   if (marker && outbuf) {
140     /* mark start of talkspurt with DISCONT */
141     GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
142   }
143
144   return outbuf;
145 }
146
147 gboolean
148 gst_rtp_gsm_depay_plugin_init (GstPlugin * plugin)
149 {
150   return gst_element_register (plugin, "rtpgsmdepay",
151       GST_RANK_SECONDARY, GST_TYPE_RTP_GSM_DEPAY);
152 }