2 * Copyright (C) 2020 Collabora Ltd.
3 * Author: Guillaume Desmottes <guillaume.desmottes@collabora.com>, Collabora Ltd.
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.
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.
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.
22 * SECTION:element-rtpisacdepay
23 * @title: rtpisacdepay
24 * @short_description: iSAC RTP Depayloader
36 #include <gst/rtp/gstrtpbuffer.h>
37 #include <gst/audio/audio.h>
39 #include "gstrtpelements.h"
40 #include "gstrtpisacdepay.h"
41 #include "gstrtputils.h"
43 GST_DEBUG_CATEGORY_STATIC (rtpisacdepay_debug);
44 #define GST_CAT_DEFAULT (rtpisacdepay_debug)
46 static GstStaticPadTemplate gst_rtp_isac_depay_sink_template =
47 GST_STATIC_PAD_TEMPLATE ("sink",
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\"")
57 static GstStaticPadTemplate gst_rtp_isac_depay_src_template =
58 GST_STATIC_PAD_TEMPLATE ("src",
61 GST_STATIC_CAPS ("audio/isac, "
62 "rate = (int) { 16000, 32000 }, " "channels = (int) 1")
65 struct _GstRtpIsacDepay
68 GstRTPBaseDepayload parent;
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));
80 gst_rtp_isac_depay_setcaps (GstRTPBaseDepayload * depayload, GstCaps * caps)
87 GST_DEBUG_OBJECT (depayload, "sink caps: %" GST_PTR_FORMAT, caps);
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");
95 src_caps = gst_caps_new_simple ("audio/isac",
96 "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, rate, NULL);
98 ret = gst_pad_set_caps (GST_RTP_BASE_DEPAYLOAD_SRCPAD (depayload), src_caps);
100 GST_DEBUG_OBJECT (depayload,
101 "set caps on source: %" GST_PTR_FORMAT " (ret=%d)", src_caps, ret);
102 gst_caps_unref (src_caps);
108 gst_rtp_isac_depay_process (GstRTPBaseDepayload * depayload,
109 GstRTPBuffer * rtp_buffer)
113 outbuf = gst_rtp_buffer_get_payload_buffer (rtp_buffer);
115 gst_rtp_drop_non_audio_meta (depayload, outbuf);
121 gst_rtp_isac_depay_class_init (GstRtpIsacDepayClass * klass)
123 GstElementClass *gstelement_class = (GstElementClass *) klass;
124 GstRTPBaseDepayloadClass *depayload_class =
125 (GstRTPBaseDepayloadClass *) klass;
127 depayload_class->set_caps = gst_rtp_isac_depay_setcaps;
128 depayload_class->process_rtp_packet = gst_rtp_isac_depay_process;
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);
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>");
140 GST_DEBUG_CATEGORY_INIT (rtpisacdepay_debug, "rtpisacdepay", 0,
141 "iSAC RTP Depayloader");
145 gst_rtp_isac_depay_init (GstRtpIsacDepay * rtpisacdepay)