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-rtpisacpay
24 * @short_description: iSAC RTP Payloader
34 #include <gst/rtp/gstrtpbuffer.h>
36 #include "gstrtpelements.h"
37 #include "gstrtpisacpay.h"
38 #include "gstrtputils.h"
40 GST_DEBUG_CATEGORY_STATIC (rtpisacpay_debug);
41 #define GST_CAT_DEFAULT (rtpisacpay_debug)
43 static GstStaticPadTemplate gst_rtp_isac_pay_sink_template =
44 GST_STATIC_PAD_TEMPLATE ("sink",
47 GST_STATIC_CAPS ("audio/isac, "
48 "rate = (int) { 16000, 32000 }, " "channels = (int) 1")
51 static GstStaticPadTemplate gst_rtp_isac_pay_src_template =
52 GST_STATIC_PAD_TEMPLATE ("src",
55 GST_STATIC_CAPS ("application/x-rtp, "
56 "media = (string) \"audio\", "
57 "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
58 "clock-rate = (int) { 16000, 32000 }, "
59 "encoding-name = (string) \"ISAC\", "
60 "encoding-params = (string) \"1\"")
66 GstRTPBasePayload parent;
69 #define gst_rtp_isac_pay_parent_class parent_class
70 G_DEFINE_TYPE (GstRtpIsacPay, gst_rtp_isac_pay, GST_TYPE_RTP_BASE_PAYLOAD);
71 GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (rtpisacpay, "rtpisacpay",
72 GST_RANK_SECONDARY, GST_TYPE_RTP_ISAC_PAY, rtp_element_init (plugin));
75 gst_rtp_isac_pay_getcaps (GstRTPBasePayload * payload, GstPad * pad,
78 GstCaps *otherpadcaps;
81 otherpadcaps = gst_pad_get_allowed_caps (payload->srcpad);
82 caps = gst_pad_get_pad_template_caps (pad);
85 if (!gst_caps_is_empty (otherpadcaps)) {
90 ps = gst_caps_get_structure (otherpadcaps, 0);
91 caps = gst_caps_make_writable (caps);
92 s = gst_caps_get_structure (caps, 0);
94 v = gst_structure_get_value (ps, "clock-rate");
96 gst_structure_set_value (s, "rate", v);
98 gst_caps_unref (otherpadcaps);
102 GstCaps *tcaps = caps;
104 caps = gst_caps_intersect_full (filter, tcaps, GST_CAPS_INTERSECT_FIRST);
105 gst_caps_unref (tcaps);
108 GST_DEBUG_OBJECT (payload, "%" GST_PTR_FORMAT, caps);
114 gst_rtp_isac_pay_setcaps (GstRTPBasePayload * payload, GstCaps * caps)
119 GST_DEBUG_OBJECT (payload, "%" GST_PTR_FORMAT, caps);
121 s = gst_caps_get_structure (caps, 0);
122 if (!gst_structure_get_int (s, "rate", &rate)) {
123 GST_ERROR_OBJECT (payload, "Missing 'rate' in caps");
127 gst_rtp_base_payload_set_options (payload, "audio", TRUE, "ISAC", rate);
129 return gst_rtp_base_payload_set_outcaps (payload, NULL);
133 gst_rtp_isac_pay_handle_buffer (GstRTPBasePayload * basepayload,
137 GstClockTime pts, dts, duration;
139 pts = GST_BUFFER_PTS (buffer);
140 dts = GST_BUFFER_DTS (buffer);
141 duration = GST_BUFFER_DURATION (buffer);
143 outbuf = gst_rtp_base_payload_allocate_output_buffer (basepayload, 0, 0, 0);
145 gst_rtp_copy_audio_meta (basepayload, outbuf, buffer);
147 outbuf = gst_buffer_append (outbuf, buffer);
149 GST_BUFFER_PTS (outbuf) = pts;
150 GST_BUFFER_DTS (outbuf) = dts;
151 GST_BUFFER_DURATION (outbuf) = duration;
153 return gst_rtp_base_payload_push (basepayload, outbuf);
157 gst_rtp_isac_pay_class_init (GstRtpIsacPayClass * klass)
159 GstElementClass *gstelement_class = (GstElementClass *) klass;
160 GstRTPBasePayloadClass *payload_class = (GstRTPBasePayloadClass *) klass;
162 payload_class->get_caps = gst_rtp_isac_pay_getcaps;
163 payload_class->set_caps = gst_rtp_isac_pay_setcaps;
164 payload_class->handle_buffer = gst_rtp_isac_pay_handle_buffer;
166 gst_element_class_add_static_pad_template (gstelement_class,
167 &gst_rtp_isac_pay_sink_template);
168 gst_element_class_add_static_pad_template (gstelement_class,
169 &gst_rtp_isac_pay_src_template);
171 gst_element_class_set_static_metadata (gstelement_class,
172 "RTP iSAC payloader", "Codec/Payloader/Network/RTP",
173 "Payload-encodes iSAC audio into a RTP packet",
174 "Guillaume Desmottes <guillaume.desmottes@collabora.com>");
176 GST_DEBUG_CATEGORY_INIT (rtpisacpay_debug, "rtpisacpay", 0,
177 "iSAC RTP Payloader");
181 gst_rtp_isac_pay_init (GstRtpIsacPay * rtpisacpay)