rtp: add rtpisacpay

Payload for the iSAC audio codec.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/530>
This commit is contained in:
Guillaume Desmottes 2020-03-20 13:15:33 +01:00
parent aa264e6b07
commit a1e7b1fd61
4 changed files with 225 additions and 0 deletions

View file

@ -70,6 +70,7 @@
#include "gstrtph264pay.h"
#include "gstrtph265depay.h"
#include "gstrtph265pay.h"
#include "gstrtpisacpay.h"
#include "gstrtpj2kdepay.h"
#include "gstrtpj2kpay.h"
#include "gstrtpjpegdepay.h"
@ -393,6 +394,9 @@ plugin_init (GstPlugin * plugin)
if (!gst_rtp_stream_depay_plugin_init (plugin))
return FALSE;
if (!gst_rtp_isac_pay_plugin_init (plugin))
return FALSE;
if (!gst_element_register (plugin, "rtpredenc", GST_RANK_NONE,
GST_TYPE_RTP_RED_ENC))
return FALSE;

187
gst/rtp/gstrtpisacpay.c Normal file
View file

@ -0,0 +1,187 @@
/* GStreamer
* Copyright (C) 2020 Collabora Ltd.
* Author: Guillaume Desmottes <guillaume.desmottes@collabora.com>, Collabora Ltd.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
/**
* SECTION:element-isacpay
* @title: isacpay
* @short_description: iSAC RTP Payloader
*
* Since: 1.20
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gst/rtp/gstrtpbuffer.h>
#include "gstrtpisacpay.h"
#include "gstrtputils.h"
GST_DEBUG_CATEGORY_STATIC (rtpisacpay_debug);
#define GST_CAT_DEFAULT (rtpisacpay_debug)
static GstStaticPadTemplate gst_rtp_isac_pay_sink_template =
GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("audio/isac, "
"rate = (int) { 16000, 32000 }, " "channels = (int) 1")
);
static GstStaticPadTemplate gst_rtp_isac_pay_src_template =
GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("application/x-rtp, "
"media = (string) \"audio\", "
"payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
"clock-rate = (int) { 16000, 32000 }, "
"encoding-name = (string) \"ISAC\", "
"encoding-params = (string) \"1\"")
);
struct _GstRtpIsacPay
{
/*< private > */
GstRTPBasePayload parent;
};
#define gst_rtp_isac_pay_parent_class parent_class
G_DEFINE_TYPE (GstRtpIsacPay, gst_rtp_isac_pay, GST_TYPE_RTP_BASE_PAYLOAD);
static GstCaps *
gst_rtp_isac_pay_getcaps (GstRTPBasePayload * payload, GstPad * pad,
GstCaps * filter)
{
GstCaps *otherpadcaps;
GstCaps *caps;
otherpadcaps = gst_pad_get_allowed_caps (payload->srcpad);
caps = gst_pad_get_pad_template_caps (pad);
if (otherpadcaps) {
if (!gst_caps_is_empty (otherpadcaps)) {
GstStructure *ps;
GstStructure *s;
const GValue *v;
ps = gst_caps_get_structure (otherpadcaps, 0);
caps = gst_caps_make_writable (caps);
s = gst_caps_get_structure (caps, 0);
v = gst_structure_get_value (ps, "clock-rate");
if (v)
gst_structure_set_value (s, "rate", v);
}
gst_caps_unref (otherpadcaps);
}
if (filter) {
GstCaps *tcaps = caps;
caps = gst_caps_intersect_full (filter, tcaps, GST_CAPS_INTERSECT_FIRST);
gst_caps_unref (tcaps);
}
GST_DEBUG_OBJECT (payload, "%" GST_PTR_FORMAT, caps);
return caps;
}
static gboolean
gst_rtp_isac_pay_setcaps (GstRTPBasePayload * payload, GstCaps * caps)
{
GstStructure *s;
gint rate;
GST_DEBUG_OBJECT (payload, "%" GST_PTR_FORMAT, caps);
s = gst_caps_get_structure (caps, 0);
if (!gst_structure_get_int (s, "rate", &rate)) {
GST_ERROR_OBJECT (payload, "Missing 'rate' in caps");
return FALSE;
}
gst_rtp_base_payload_set_options (payload, "audio", TRUE, "ISAC", rate);
return gst_rtp_base_payload_set_outcaps (payload, NULL);
}
static GstFlowReturn
gst_rtp_isac_pay_handle_buffer (GstRTPBasePayload * basepayload,
GstBuffer * buffer)
{
GstBuffer *outbuf;
GstClockTime pts, dts, duration;
pts = GST_BUFFER_PTS (buffer);
dts = GST_BUFFER_DTS (buffer);
duration = GST_BUFFER_DURATION (buffer);
outbuf = gst_rtp_base_payload_allocate_output_buffer (basepayload, 0, 0, 0);
gst_rtp_copy_audio_meta (basepayload, outbuf, buffer);
outbuf = gst_buffer_append (outbuf, buffer);
GST_BUFFER_PTS (outbuf) = pts;
GST_BUFFER_DTS (outbuf) = dts;
GST_BUFFER_DURATION (outbuf) = duration;
return gst_rtp_base_payload_push (basepayload, outbuf);
}
static void
gst_rtp_isac_pay_class_init (GstRtpIsacPayClass * klass)
{
GstElementClass *gstelement_class = (GstElementClass *) klass;
GstRTPBasePayloadClass *payload_class = (GstRTPBasePayloadClass *) klass;
payload_class->get_caps = gst_rtp_isac_pay_getcaps;
payload_class->set_caps = gst_rtp_isac_pay_setcaps;
payload_class->handle_buffer = gst_rtp_isac_pay_handle_buffer;
gst_element_class_add_static_pad_template (gstelement_class,
&gst_rtp_isac_pay_sink_template);
gst_element_class_add_static_pad_template (gstelement_class,
&gst_rtp_isac_pay_src_template);
gst_element_class_set_static_metadata (gstelement_class,
"RTP iSAC payloader", "Codec/Payloader/Network/RTP",
"Payload-encodes iSAC audio into a RTP packet",
"Guillaume Desmottes <guillaume.desmottes@collabora.com>");
GST_DEBUG_CATEGORY_INIT (rtpisacpay_debug, "rtpisacpay", 0,
"iSAC RTP Payloader");
}
static void
gst_rtp_isac_pay_init (GstRtpIsacPay * rtpisacpay)
{
}
gboolean
gst_rtp_isac_pay_plugin_init (GstPlugin * plugin)
{
return gst_element_register (plugin, "rtpisacpay",
GST_RANK_SECONDARY, GST_TYPE_RTP_ISAC_PAY);
}

33
gst/rtp/gstrtpisacpay.h Normal file
View file

@ -0,0 +1,33 @@
/* GStreamer
* Copyright (C) 2020 Collabora Ltd.
* Author: Guillaume Desmottes <guillaume.desmottes@collabora.com>, Collabora Ltd.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more
*/
#ifndef __GST_RTP_ISAC_PAY_H__
#define __GST_RTP_ISAC_PAY_H__
#include <gst/gst.h>
#include <gst/rtp/gstrtpbasepayload.h>
G_BEGIN_DECLS
#define GST_TYPE_RTP_ISAC_PAY gst_rtp_isac_pay_get_type ()
G_DECLARE_FINAL_TYPE(GstRtpIsacPay, gst_rtp_isac_pay, GST, RTP_ISAC_PAY, GstRTPBasePayload);
gboolean gst_rtp_isac_pay_plugin_init (GstPlugin * plugin);
G_END_DECLS
#endif /* __GST_RTP_ISAC_PAY_H__ */

View file

@ -102,6 +102,7 @@ rtp_sources = [
'rtpstorage.c',
'rtpstoragestream.c',
'gstrtpstorage.c',
'gstrtpisacpay.c',
]
rtp_args = [