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., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, 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 <gst/audio/audio.h>
30 #include "gstrtpsirendepay.h"
31 #include "gstrtputils.h"
32
33 static GstStaticPadTemplate gst_rtp_siren_depay_sink_template =
34 GST_STATIC_PAD_TEMPLATE ("sink",
35 GST_PAD_SINK,
36 GST_PAD_ALWAYS,
37 GST_STATIC_CAPS ("application/x-rtp, "
38 "media = (string) \"audio\", "
39 "clock-rate = (int) 16000, " "encoding-name = (string) \"SIREN\"")
40 /* This is the default, so the peer doesn't have to specify it */
41 /* " "dct-length = (int) 320") */
42 );
43
44 static GstStaticPadTemplate gst_rtp_siren_depay_src_template =
45 GST_STATIC_PAD_TEMPLATE ("src",
46 GST_PAD_SRC,
47 GST_PAD_ALWAYS,
48 GST_STATIC_CAPS ("audio/x-siren, " "dct-length = (int) 320")
49 );
50
51 static GstBuffer *gst_rtp_siren_depay_process (GstRTPBaseDepayload *
52 depayload, GstRTPBuffer * rtp);
53 static gboolean gst_rtp_siren_depay_setcaps (GstRTPBaseDepayload *
54 depayload, GstCaps * caps);
55
56 G_DEFINE_TYPE (GstRTPSirenDepay, gst_rtp_siren_depay,
57 GST_TYPE_RTP_BASE_DEPAYLOAD);
58
gst_rtp_siren_depay_class_init(GstRTPSirenDepayClass * klass)59 static void gst_rtp_siren_depay_class_init (GstRTPSirenDepayClass * klass)
60 {
61 GstElementClass *gstelement_class;
62 GstRTPBaseDepayloadClass *gstrtpbasedepayload_class;
63
64 gstelement_class = (GstElementClass *) klass;
65 gstrtpbasedepayload_class = (GstRTPBaseDepayloadClass *) klass;
66
67 gstrtpbasedepayload_class->process_rtp_packet = gst_rtp_siren_depay_process;
68 gstrtpbasedepayload_class->set_caps = gst_rtp_siren_depay_setcaps;
69
70 gst_element_class_add_static_pad_template (gstelement_class,
71 &gst_rtp_siren_depay_src_template);
72 gst_element_class_add_static_pad_template (gstelement_class,
73 &gst_rtp_siren_depay_sink_template);
74 gst_element_class_set_static_metadata (gstelement_class,
75 "RTP Siren packet depayloader", "Codec/Depayloader/Network/RTP",
76 "Extracts Siren audio from RTP packets",
77 "Philippe Kalaf <philippe.kalaf@collabora.co.uk>");
78 }
79
80 static void
gst_rtp_siren_depay_init(GstRTPSirenDepay * rtpsirendepay)81 gst_rtp_siren_depay_init (GstRTPSirenDepay * rtpsirendepay)
82 {
83
84 }
85
86 static gboolean
gst_rtp_siren_depay_setcaps(GstRTPBaseDepayload * depayload,GstCaps * caps)87 gst_rtp_siren_depay_setcaps (GstRTPBaseDepayload * depayload, GstCaps * caps)
88 {
89 GstCaps *srccaps;
90 gboolean ret;
91
92 srccaps = gst_caps_new_simple ("audio/x-siren",
93 "dct-length", G_TYPE_INT, 320, NULL);
94 ret = gst_pad_set_caps (GST_RTP_BASE_DEPAYLOAD_SRCPAD (depayload), srccaps);
95
96 GST_DEBUG ("set caps on source: %" GST_PTR_FORMAT " (ret=%d)", srccaps, ret);
97 gst_caps_unref (srccaps);
98
99 /* always fixed clock rate of 16000 */
100 depayload->clock_rate = 16000;
101
102 return ret;
103 }
104
105 static GstBuffer *
gst_rtp_siren_depay_process(GstRTPBaseDepayload * depayload,GstRTPBuffer * rtp)106 gst_rtp_siren_depay_process (GstRTPBaseDepayload * depayload,
107 GstRTPBuffer * rtp)
108 {
109 GstBuffer *outbuf;
110
111 outbuf = gst_rtp_buffer_get_payload_buffer (rtp);
112
113 if (outbuf) {
114 gst_rtp_drop_non_audio_meta (depayload, outbuf);
115 }
116
117 return outbuf;
118 }
119
120 gboolean
gst_rtp_siren_depay_plugin_init(GstPlugin * plugin)121 gst_rtp_siren_depay_plugin_init (GstPlugin * plugin)
122 {
123 return gst_element_register (plugin, "rtpsirendepay",
124 GST_RANK_SECONDARY, GST_TYPE_RTP_SIREN_DEPAY);
125 }
126