Tizen 2.0 Release
[framework/multimedia/gst-plugins-good0.10.git] / gst / rtp / gstrtpsirendepay.c
1 /*
2  * Siren Depayloader Gst Element
3  *
4  *   @author: Youness Alaoui <kakaroto@kakaroto.homelinux.net>
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 <stdlib.h>
28 #include <gst/rtp/gstrtpbuffer.h>
29 #include "gstrtpsirendepay.h"
30
31 static GstStaticPadTemplate gst_rtp_siren_depay_sink_template =
32 GST_STATIC_PAD_TEMPLATE ("sink",
33     GST_PAD_SINK,
34     GST_PAD_ALWAYS,
35     GST_STATIC_CAPS ("application/x-rtp, "
36         "media = (string) \"audio\", "
37         "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
38         "clock-rate = (int) 16000, "
39         "encoding-name = (string) \"SIREN\", " "dct-length = (int) 320")
40     );
41
42 static GstStaticPadTemplate gst_rtp_siren_depay_src_template =
43 GST_STATIC_PAD_TEMPLATE ("src",
44     GST_PAD_SRC,
45     GST_PAD_ALWAYS,
46     GST_STATIC_CAPS ("audio/x-siren, " "dct-length = (int) 320")
47     );
48
49 static GstBuffer *gst_rtp_siren_depay_process (GstBaseRTPDepayload * depayload,
50     GstBuffer * buf);
51 static gboolean gst_rtp_siren_depay_setcaps (GstBaseRTPDepayload * depayload,
52     GstCaps * caps);
53
54 GST_BOILERPLATE (GstRTPSirenDepay, gst_rtp_siren_depay, GstBaseRTPDepayload,
55     GST_TYPE_BASE_RTP_DEPAYLOAD);
56
57 static void
58 gst_rtp_siren_depay_base_init (gpointer klass)
59 {
60   GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
61
62   gst_element_class_add_static_pad_template (element_class,
63       &gst_rtp_siren_depay_src_template);
64   gst_element_class_add_static_pad_template (element_class,
65       &gst_rtp_siren_depay_sink_template);
66   gst_element_class_set_details_simple (element_class,
67       "RTP Siren packet depayloader", "Codec/Depayloader/Network/RTP",
68       "Extracts Siren audio from RTP packets",
69       "Philippe Kalaf <philippe.kalaf@collabora.co.uk>");
70 }
71
72 static void
73 gst_rtp_siren_depay_class_init (GstRTPSirenDepayClass * klass)
74 {
75   GstBaseRTPDepayloadClass *gstbasertpdepayload_class;
76
77   gstbasertpdepayload_class = (GstBaseRTPDepayloadClass *) klass;
78
79   gstbasertpdepayload_class->process = gst_rtp_siren_depay_process;
80   gstbasertpdepayload_class->set_caps = gst_rtp_siren_depay_setcaps;
81 }
82
83 static void
84 gst_rtp_siren_depay_init (GstRTPSirenDepay * rtpsirendepay,
85     GstRTPSirenDepayClass * klass)
86 {
87
88 }
89
90 static gboolean
91 gst_rtp_siren_depay_setcaps (GstBaseRTPDepayload * depayload, GstCaps * caps)
92 {
93   GstCaps *srccaps;
94   gboolean ret;
95
96   srccaps = gst_caps_new_simple ("audio/x-siren",
97       "dct-length", G_TYPE_INT, 320, NULL);
98   ret = gst_pad_set_caps (GST_BASE_RTP_DEPAYLOAD_SRCPAD (depayload), srccaps);
99
100   GST_DEBUG ("set caps on source: %" GST_PTR_FORMAT " (ret=%d)", srccaps, ret);
101   gst_caps_unref (srccaps);
102
103   /* always fixed clock rate of 16000 */
104   depayload->clock_rate = 16000;
105
106   return ret;
107 }
108
109 static GstBuffer *
110 gst_rtp_siren_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
111 {
112   GstBuffer *outbuf;
113
114   outbuf = gst_rtp_buffer_get_payload_buffer (buf);
115
116   return outbuf;
117 }
118
119 gboolean
120 gst_rtp_siren_depay_plugin_init (GstPlugin * plugin)
121 {
122   return gst_element_register (plugin, "rtpsirendepay",
123       GST_RANK_SECONDARY, GST_TYPE_RTP_SIREN_DEPAY);
124 }