1 /* GStreamer
2 * Copyright (C) 2020 Collabora Ltd.
3 * Author: Guillaume Desmottes <guillaume.desmottes@collabora.com>, Collabora Ltd.
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., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21 /**
22 * SECTION:element-rtpisacdepay
23 * @title: rtpisacdepay
24 * @short_description: iSAC RTP Depayloader
25 *
26 * Since: 1.20
27 *
28 */
29
30 #ifdef HAVE_CONFIG_H
31 # include "config.h"
32 #endif
33
34 #include <stdlib.h>
35 #include <string.h>
36 #include <gst/rtp/gstrtpbuffer.h>
37 #include <gst/audio/audio.h>
38
39 #include "gstrtpelements.h"
40 #include "gstrtpisacdepay.h"
41 #include "gstrtputils.h"
42
43 GST_DEBUG_CATEGORY_STATIC (rtpisacdepay_debug);
44 #define GST_CAT_DEFAULT (rtpisacdepay_debug)
45
46 static GstStaticPadTemplate gst_rtp_isac_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) { 16000, 32000 }, "
54 "encoding-name = (string) \"ISAC\"")
55 );
56
57 static GstStaticPadTemplate gst_rtp_isac_depay_src_template =
58 GST_STATIC_PAD_TEMPLATE ("src",
59 GST_PAD_SRC,
60 GST_PAD_ALWAYS,
61 GST_STATIC_CAPS ("audio/isac, "
62 "rate = (int) { 16000, 32000 }, " "channels = (int) 1")
63 );
64
65 struct _GstRtpIsacDepay
66 {
67 /*< private > */
68 GstRTPBaseDepayload parent;
69
70 guint64 packet;
71 };
72
73 #define gst_rtp_isac_depay_parent_class parent_class
74 G_DEFINE_TYPE (GstRtpIsacDepay, gst_rtp_isac_depay,
75 GST_TYPE_RTP_BASE_DEPAYLOAD);
76 GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (rtpisacdepay, "rtpisacdepay",
77 GST_RANK_SECONDARY, GST_TYPE_RTP_ISAC_DEPAY, rtp_element_init (plugin));
78
79 static gboolean
gst_rtp_isac_depay_setcaps(GstRTPBaseDepayload * depayload,GstCaps * caps)80 gst_rtp_isac_depay_setcaps (GstRTPBaseDepayload * depayload, GstCaps * caps)
81 {
82 GstCaps *src_caps;
83 GstStructure *s;
84 gint rate;
85 gboolean ret;
86
87 GST_DEBUG_OBJECT (depayload, "sink caps: %" GST_PTR_FORMAT, caps);
88
89 s = gst_caps_get_structure (caps, 0);
90 if (!gst_structure_get_int (s, "clock-rate", &rate)) {
91 GST_ERROR_OBJECT (depayload, "Missing 'clock-rate' in caps");
92 return FALSE;
93 }
94
95 src_caps = gst_caps_new_simple ("audio/isac",
96 "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, rate, NULL);
97
98 ret = gst_pad_set_caps (GST_RTP_BASE_DEPAYLOAD_SRCPAD (depayload), src_caps);
99
100 GST_DEBUG_OBJECT (depayload,
101 "set caps on source: %" GST_PTR_FORMAT " (ret=%d)", src_caps, ret);
102 gst_caps_unref (src_caps);
103
104 return ret;
105 }
106
107 static GstBuffer *
gst_rtp_isac_depay_process(GstRTPBaseDepayload * depayload,GstRTPBuffer * rtp_buffer)108 gst_rtp_isac_depay_process (GstRTPBaseDepayload * depayload,
109 GstRTPBuffer * rtp_buffer)
110 {
111 GstBuffer *outbuf;
112
113 outbuf = gst_rtp_buffer_get_payload_buffer (rtp_buffer);
114
115 gst_rtp_drop_non_audio_meta (depayload, outbuf);
116
117 return outbuf;
118 }
119
120 static void
gst_rtp_isac_depay_class_init(GstRtpIsacDepayClass * klass)121 gst_rtp_isac_depay_class_init (GstRtpIsacDepayClass * klass)
122 {
123 GstElementClass *gstelement_class = (GstElementClass *) klass;
124 GstRTPBaseDepayloadClass *depayload_class =
125 (GstRTPBaseDepayloadClass *) klass;
126
127 depayload_class->set_caps = gst_rtp_isac_depay_setcaps;
128 depayload_class->process_rtp_packet = gst_rtp_isac_depay_process;
129
130 gst_element_class_add_static_pad_template (gstelement_class,
131 &gst_rtp_isac_depay_sink_template);
132 gst_element_class_add_static_pad_template (gstelement_class,
133 &gst_rtp_isac_depay_src_template);
134
135 gst_element_class_set_static_metadata (gstelement_class,
136 "RTP iSAC depayloader", "Codec/Depayloader/Network/RTP",
137 "Extracts iSAC audio from RTP packets",
138 "Guillaume Desmottes <guillaume.desmottes@collabora.com>");
139
140 GST_DEBUG_CATEGORY_INIT (rtpisacdepay_debug, "rtpisacdepay", 0,
141 "iSAC RTP Depayloader");
142 }
143
144 static void
gst_rtp_isac_depay_init(GstRtpIsacDepay * rtpisacdepay)145 gst_rtp_isac_depay_init (GstRtpIsacDepay * rtpisacdepay)
146 {
147 }
148