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