mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-01 22:21:13 +00:00
isac: add iSAC plugin
Wrapper on the iSAC reference encoder and decoder from webrtc, see https://en.wikipedia.org/wiki/Internet_Speech_Audio_Codec Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1124>
This commit is contained in:
parent
d1945de102
commit
bfb9071081
10 changed files with 1001 additions and 0 deletions
56
ext/isac/gstisac.c
Normal file
56
ext/isac/gstisac.c
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
/* iSAC plugin
|
||||||
|
*
|
||||||
|
* 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 Street, Fifth Floor,
|
||||||
|
* Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* plugin-isac:
|
||||||
|
*
|
||||||
|
* Since: 1.20
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <gst/gst.h>
|
||||||
|
|
||||||
|
#include "gstisacenc.h"
|
||||||
|
#include "gstisacdec.h"
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
plugin_init (GstPlugin * plugin)
|
||||||
|
{
|
||||||
|
if (!gst_element_register (plugin, "isacenc", GST_RANK_PRIMARY,
|
||||||
|
GST_TYPE_ISACENC))
|
||||||
|
return FALSE;
|
||||||
|
if (!gst_element_register (plugin, "isacdec", GST_RANK_PRIMARY,
|
||||||
|
GST_TYPE_ISACDEC))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
||||||
|
GST_VERSION_MINOR,
|
||||||
|
isac,
|
||||||
|
"iSAC plugin", plugin_init, VERSION, "LGPL", PACKAGE_NAME,
|
||||||
|
GST_PACKAGE_ORIGIN)
|
295
ext/isac/gstisacdec.c
Normal file
295
ext/isac/gstisacdec.c
Normal file
|
@ -0,0 +1,295 @@
|
||||||
|
/* iSAC decoder
|
||||||
|
*
|
||||||
|
* 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 Street, Fifth Floor,
|
||||||
|
* Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SECTION:element-isacdec
|
||||||
|
* @title: isacdec
|
||||||
|
* @short_description: iSAC audio decoder
|
||||||
|
*
|
||||||
|
* Since: 1.20
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "gstisacdec.h"
|
||||||
|
#include "gstisacutils.h"
|
||||||
|
|
||||||
|
#include <modules/audio_coding/codecs/isac/main/include/isac.h>
|
||||||
|
|
||||||
|
GST_DEBUG_CATEGORY_STATIC (isacdec_debug);
|
||||||
|
#define GST_CAT_DEFAULT isacdec_debug
|
||||||
|
|
||||||
|
#define SAMPLE_SIZE 2 /* 16-bits samples */
|
||||||
|
#define MAX_OUTPUT_SAMPLES 960 /* decoder produces max 960 samples */
|
||||||
|
#define MAX_OUTPUT_SIZE (SAMPLE_SIZE * MAX_OUTPUT_SAMPLES)
|
||||||
|
|
||||||
|
static GstStaticPadTemplate 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 src_template = GST_STATIC_PAD_TEMPLATE ("src",
|
||||||
|
GST_PAD_SRC,
|
||||||
|
GST_PAD_ALWAYS,
|
||||||
|
GST_STATIC_CAPS ("audio/x-raw, "
|
||||||
|
"format = (string) " GST_AUDIO_NE (S16) ", "
|
||||||
|
"rate = (int) { 16000, 32000 }, "
|
||||||
|
"layout = (string) interleaved, " "channels = (int) 1")
|
||||||
|
);
|
||||||
|
|
||||||
|
struct _GstIsacDec
|
||||||
|
{
|
||||||
|
/*< private > */
|
||||||
|
GstAudioDecoder parent;
|
||||||
|
|
||||||
|
ISACStruct *isac;
|
||||||
|
|
||||||
|
/* properties */
|
||||||
|
};
|
||||||
|
|
||||||
|
#define gst_isacdec_parent_class parent_class
|
||||||
|
G_DEFINE_TYPE_WITH_CODE (GstIsacDec, gst_isacdec,
|
||||||
|
GST_TYPE_AUDIO_DECODER,
|
||||||
|
GST_DEBUG_CATEGORY_INIT (isacdec_debug, "isacdec", 0,
|
||||||
|
"debug category for isacdec element"));
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_isacdec_start (GstAudioDecoder * dec)
|
||||||
|
{
|
||||||
|
GstIsacDec *self = GST_ISACDEC (dec);
|
||||||
|
gint16 ret;
|
||||||
|
|
||||||
|
g_assert (!self->isac);
|
||||||
|
ret = WebRtcIsac_Create (&self->isac);
|
||||||
|
CHECK_ISAC_RET (ret, Create);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_isacdec_stop (GstAudioDecoder * dec)
|
||||||
|
{
|
||||||
|
GstIsacDec *self = GST_ISACDEC (dec);
|
||||||
|
|
||||||
|
if (self->isac) {
|
||||||
|
gint16 ret;
|
||||||
|
|
||||||
|
ret = WebRtcIsac_Free (self->isac);
|
||||||
|
CHECK_ISAC_RET (ret, Free);
|
||||||
|
self->isac = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_isacdec_set_format (GstAudioDecoder * dec, GstCaps * input_caps)
|
||||||
|
{
|
||||||
|
GstIsacDec *self = GST_ISACDEC (dec);
|
||||||
|
GstAudioInfo output_format;
|
||||||
|
gint16 ret;
|
||||||
|
gboolean result;
|
||||||
|
GstStructure *s;
|
||||||
|
gint rate, channels;
|
||||||
|
GstCaps *output_caps;
|
||||||
|
|
||||||
|
GST_DEBUG_OBJECT (self, "input caps: %" GST_PTR_FORMAT, input_caps);
|
||||||
|
|
||||||
|
s = gst_caps_get_structure (input_caps, 0);
|
||||||
|
if (!s)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
if (!gst_structure_get_int (s, "rate", &rate)) {
|
||||||
|
GST_ERROR_OBJECT (self, "'rate' missing in input caps: %" GST_PTR_FORMAT,
|
||||||
|
input_caps);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!gst_structure_get_int (s, "channels", &channels)) {
|
||||||
|
GST_ERROR_OBJECT (self,
|
||||||
|
"'channels' missing in input caps: %" GST_PTR_FORMAT, input_caps);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
gst_audio_info_set_format (&output_format, GST_AUDIO_FORMAT_S16LE, rate,
|
||||||
|
channels, NULL);
|
||||||
|
|
||||||
|
output_caps = gst_audio_info_to_caps (&output_format);
|
||||||
|
GST_DEBUG_OBJECT (self, "output caps: %" GST_PTR_FORMAT, output_caps);
|
||||||
|
gst_caps_unref (output_caps);
|
||||||
|
|
||||||
|
ret = WebRtcIsac_SetDecSampRate (self->isac, rate);
|
||||||
|
CHECK_ISAC_RET (ret, SetDecSampleRate);
|
||||||
|
|
||||||
|
WebRtcIsac_DecoderInit (self->isac);
|
||||||
|
|
||||||
|
result = gst_audio_decoder_set_output_format (dec, &output_format);
|
||||||
|
|
||||||
|
gst_audio_decoder_set_plc_aware (dec, TRUE);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static GstFlowReturn
|
||||||
|
gst_isacdec_plc (GstIsacDec * self, GstClockTime duration)
|
||||||
|
{
|
||||||
|
GstAudioDecoder *dec = GST_AUDIO_DECODER (self);
|
||||||
|
guint nb_plc_frames;
|
||||||
|
GstBuffer *output;
|
||||||
|
GstMapInfo map_write;
|
||||||
|
size_t ret;
|
||||||
|
|
||||||
|
/* Decoder produces 30 ms PLC frames */
|
||||||
|
nb_plc_frames = duration / (30 * GST_MSECOND);
|
||||||
|
|
||||||
|
GST_DEBUG_OBJECT (self,
|
||||||
|
"GAP of %" GST_TIME_FORMAT " detected, request PLC for %d frames",
|
||||||
|
GST_TIME_ARGS (duration), nb_plc_frames);
|
||||||
|
|
||||||
|
output =
|
||||||
|
gst_audio_decoder_allocate_output_buffer (dec,
|
||||||
|
nb_plc_frames * MAX_OUTPUT_SIZE);
|
||||||
|
|
||||||
|
if (!gst_buffer_map (output, &map_write, GST_MAP_WRITE)) {
|
||||||
|
GST_ERROR_OBJECT (self, "Failed to map output buffer");
|
||||||
|
gst_buffer_unref (output);
|
||||||
|
return GST_FLOW_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret =
|
||||||
|
WebRtcIsac_DecodePlc (self->isac, (gint16 *) map_write.data,
|
||||||
|
nb_plc_frames);
|
||||||
|
|
||||||
|
gst_buffer_unmap (output, &map_write);
|
||||||
|
|
||||||
|
if (ret < 0) {
|
||||||
|
/* error */
|
||||||
|
gint16 code = WebRtcIsac_GetErrorCode (self->isac);
|
||||||
|
GST_WARNING_OBJECT (self, "Failed to produce PLC: %s (%d)",
|
||||||
|
isac_error_code_to_str (code), code);
|
||||||
|
gst_buffer_unref (output);
|
||||||
|
return GST_FLOW_ERROR;
|
||||||
|
} else if (ret == 0) {
|
||||||
|
GST_DEBUG_OBJECT (self, "Decoder didn't produce any PLC frame");
|
||||||
|
gst_buffer_unref (output);
|
||||||
|
return GST_FLOW_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
gst_buffer_set_size (output, ret * SAMPLE_SIZE);
|
||||||
|
|
||||||
|
GST_LOG_OBJECT (self, "Produced %" G_GSIZE_FORMAT " PLC samples", ret);
|
||||||
|
|
||||||
|
return gst_audio_decoder_finish_frame (dec, output, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static GstFlowReturn
|
||||||
|
gst_isacdec_handle_frame (GstAudioDecoder * dec, GstBuffer * input)
|
||||||
|
{
|
||||||
|
GstIsacDec *self = GST_ISACDEC (dec);
|
||||||
|
GstMapInfo map_read, map_write;
|
||||||
|
GstBuffer *output;
|
||||||
|
gint16 ret, speech_type[1];
|
||||||
|
gsize input_size;
|
||||||
|
|
||||||
|
/* Can't drain the decoder */
|
||||||
|
if (!input)
|
||||||
|
return GST_FLOW_OK;
|
||||||
|
|
||||||
|
if (!gst_buffer_get_size (input)) {
|
||||||
|
/* Base class detected a gap in the stream, try to do PLC */
|
||||||
|
return gst_isacdec_plc (self, GST_BUFFER_DURATION (input));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!gst_buffer_map (input, &map_read, GST_MAP_READ)) {
|
||||||
|
GST_ELEMENT_ERROR (self, RESOURCE, READ, ("Failed to map input buffer"),
|
||||||
|
(NULL));
|
||||||
|
return GST_FLOW_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
input_size = map_read.size;
|
||||||
|
|
||||||
|
output = gst_audio_decoder_allocate_output_buffer (dec, MAX_OUTPUT_SIZE);
|
||||||
|
if (!gst_buffer_map (output, &map_write, GST_MAP_WRITE)) {
|
||||||
|
GST_ELEMENT_ERROR (self, RESOURCE, WRITE, ("Failed to map output buffer"),
|
||||||
|
(NULL));
|
||||||
|
gst_buffer_unref (output);
|
||||||
|
gst_buffer_unmap (input, &map_read);
|
||||||
|
return GST_FLOW_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = WebRtcIsac_Decode (self->isac, map_read.data, map_read.size,
|
||||||
|
(gint16 *) map_write.data, speech_type);
|
||||||
|
|
||||||
|
gst_buffer_unmap (input, &map_read);
|
||||||
|
gst_buffer_unmap (output, &map_write);
|
||||||
|
|
||||||
|
if (ret < 0) {
|
||||||
|
/* error */
|
||||||
|
gint16 code = WebRtcIsac_GetErrorCode (self->isac);
|
||||||
|
GST_WARNING_OBJECT (self, "Failed to decode: %s (%d)",
|
||||||
|
isac_error_code_to_str (code), code);
|
||||||
|
gst_buffer_unref (output);
|
||||||
|
/* Give a chance to decode next frames */
|
||||||
|
return GST_FLOW_OK;
|
||||||
|
} else if (ret == 0) {
|
||||||
|
GST_DEBUG_OBJECT (self, "Decoder didn't produce any frame");
|
||||||
|
gst_buffer_unref (output);
|
||||||
|
output = NULL;
|
||||||
|
} else {
|
||||||
|
gst_buffer_set_size (output, ret * SAMPLE_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
GST_LOG_OBJECT (self, "Decoded %d samples from %" G_GSIZE_FORMAT " bytes",
|
||||||
|
ret, input_size);
|
||||||
|
|
||||||
|
return gst_audio_decoder_finish_frame (dec, output, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_isacdec_class_init (GstIsacDecClass * klass)
|
||||||
|
{
|
||||||
|
GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
|
||||||
|
GstAudioDecoderClass *base_class = GST_AUDIO_DECODER_CLASS (klass);
|
||||||
|
|
||||||
|
base_class->start = GST_DEBUG_FUNCPTR (gst_isacdec_start);
|
||||||
|
base_class->stop = GST_DEBUG_FUNCPTR (gst_isacdec_stop);
|
||||||
|
base_class->set_format = GST_DEBUG_FUNCPTR (gst_isacdec_set_format);
|
||||||
|
base_class->handle_frame = GST_DEBUG_FUNCPTR (gst_isacdec_handle_frame);
|
||||||
|
|
||||||
|
gst_element_class_set_static_metadata (gstelement_class, "iSAC decoder",
|
||||||
|
"Codec/Decoder/Audio",
|
||||||
|
"iSAC audio decoder",
|
||||||
|
"Guillaume Desmottes <guillaume.desmottes@collabora.com>");
|
||||||
|
|
||||||
|
gst_element_class_add_static_pad_template (gstelement_class, &sink_template);
|
||||||
|
gst_element_class_add_static_pad_template (gstelement_class, &src_template);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_isacdec_init (GstIsacDec * self)
|
||||||
|
{
|
||||||
|
self->isac = NULL;
|
||||||
|
}
|
34
ext/isac/gstisacdec.h
Normal file
34
ext/isac/gstisacdec.h
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
/* iSAC decoder
|
||||||
|
*
|
||||||
|
* 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 Street, Fifth Floor,
|
||||||
|
* Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __GST_ISAC_DEC_H__
|
||||||
|
#define __GST_ISAC_DEC_H__
|
||||||
|
|
||||||
|
#include <gst/audio/audio.h>
|
||||||
|
|
||||||
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
#define GST_TYPE_ISACDEC gst_isacdec_get_type ()
|
||||||
|
G_DECLARE_FINAL_TYPE(GstIsacDec, gst_isacdec, GST, ISACDEC, GstAudioDecoder)
|
||||||
|
|
||||||
|
G_END_DECLS
|
||||||
|
|
||||||
|
#endif /* __GST_ISAC_DEC_H__ */
|
435
ext/isac/gstisacenc.c
Normal file
435
ext/isac/gstisacenc.c
Normal file
|
@ -0,0 +1,435 @@
|
||||||
|
/* iSAC encoder
|
||||||
|
*
|
||||||
|
* 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 Street, Fifth Floor,
|
||||||
|
* Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SECTION:element-isacenc
|
||||||
|
* @title: isacenc
|
||||||
|
* @short_description: iSAC audio encoder
|
||||||
|
*
|
||||||
|
* Since: 1.20
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "gstisacenc.h"
|
||||||
|
#include "gstisacutils.h"
|
||||||
|
|
||||||
|
#include <modules/audio_coding/codecs/isac/main/include/isac.h>
|
||||||
|
|
||||||
|
GST_DEBUG_CATEGORY_STATIC (isacenc_debug);
|
||||||
|
#define GST_CAT_DEFAULT isacenc_debug
|
||||||
|
|
||||||
|
/* Buffer size used in the simpleKenny.c test app from webrtc */
|
||||||
|
#define OUTPUT_BUFFER_SIZE 1200
|
||||||
|
|
||||||
|
#define GST_TYPE_ISACENC_OUTPUT_FRAME_LEN (gst_isacenc_output_frame_len_get_type ())
|
||||||
|
static GType
|
||||||
|
gst_isacenc_output_frame_len_get_type (void)
|
||||||
|
{
|
||||||
|
static GType qtype = 0;
|
||||||
|
|
||||||
|
if (qtype == 0) {
|
||||||
|
static const GEnumValue values[] = {
|
||||||
|
{30, "30 ms", "30 ms"},
|
||||||
|
{60, "60 ms", "60 ms, only usable in wideband mode (16 kHz)"},
|
||||||
|
{0, NULL, NULL}
|
||||||
|
};
|
||||||
|
|
||||||
|
qtype = g_enum_register_static ("GstIsacEncOutputFrameLen", values);
|
||||||
|
}
|
||||||
|
return qtype;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
PROP_0,
|
||||||
|
PROP_OUTPUT_FRAME_LEN,
|
||||||
|
PROP_BITRATE,
|
||||||
|
PROP_MAX_PAYLOAD_SIZE,
|
||||||
|
PROP_MAX_RATE,
|
||||||
|
};
|
||||||
|
|
||||||
|
#define GST_ISACENC_OUTPUT_FRAME_LEN_DEFAULT (30)
|
||||||
|
#define GST_ISACENC_BITRATE_DEFAULT (32000)
|
||||||
|
#define GST_ISACENC_MAX_PAYLOAD_SIZE_DEFAULT (-1)
|
||||||
|
#define GST_ISACENC_MAX_RATE_DEFAULT (-1)
|
||||||
|
|
||||||
|
static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
|
||||||
|
GST_PAD_SINK,
|
||||||
|
GST_PAD_ALWAYS,
|
||||||
|
GST_STATIC_CAPS ("audio/x-raw, "
|
||||||
|
"format = (string) " GST_AUDIO_NE (S16) ", "
|
||||||
|
"rate = (int) { 16000, 32000 }, "
|
||||||
|
"layout = (string) interleaved, " "channels = (int) 1")
|
||||||
|
);
|
||||||
|
|
||||||
|
static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
|
||||||
|
GST_PAD_SRC,
|
||||||
|
GST_PAD_ALWAYS,
|
||||||
|
GST_STATIC_CAPS ("audio/isac, "
|
||||||
|
"rate = (int) { 16000, 32000 }, " "channels = (int) 1")
|
||||||
|
);
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
ENCODER_MODE_WIDEBAND, /* 16 kHz */
|
||||||
|
ENCODER_MODE_SUPER_WIDEBAND, /* 32 kHz */
|
||||||
|
} EncoderMode;
|
||||||
|
|
||||||
|
struct _GstIsacEnc
|
||||||
|
{
|
||||||
|
/*< private > */
|
||||||
|
GstAudioEncoder parent;
|
||||||
|
|
||||||
|
ISACStruct *isac;
|
||||||
|
EncoderMode mode;
|
||||||
|
gint samples_per_frame; /* number of samples in one input frame */
|
||||||
|
gsize frame_size; /* size, in bytes, of one input frame */
|
||||||
|
guint nb_processed_input_frames; /* number of input frames processed by the encoder since the last produced encoded data */
|
||||||
|
|
||||||
|
/* properties */
|
||||||
|
gint output_frame_len;
|
||||||
|
gint bitrate;
|
||||||
|
gint max_payload_size;
|
||||||
|
gint max_rate;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define gst_isacenc_parent_class parent_class
|
||||||
|
G_DEFINE_TYPE_WITH_CODE (GstIsacEnc, gst_isacenc,
|
||||||
|
GST_TYPE_AUDIO_ENCODER,
|
||||||
|
GST_DEBUG_CATEGORY_INIT (isacenc_debug, "isacenc", 0,
|
||||||
|
"debug category for isacenc element"));
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_isacenc_start (GstAudioEncoder * enc)
|
||||||
|
{
|
||||||
|
GstIsacEnc *self = GST_ISACENC (enc);
|
||||||
|
gint16 ret;
|
||||||
|
|
||||||
|
g_assert (!self->isac);
|
||||||
|
ret = WebRtcIsac_Create (&self->isac);
|
||||||
|
CHECK_ISAC_RET (ret, Create);
|
||||||
|
|
||||||
|
self->nb_processed_input_frames = 0;
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_isacenc_stop (GstAudioEncoder * enc)
|
||||||
|
{
|
||||||
|
GstIsacEnc *self = GST_ISACENC (enc);
|
||||||
|
|
||||||
|
if (self->isac) {
|
||||||
|
gint16 ret;
|
||||||
|
|
||||||
|
ret = WebRtcIsac_Free (self->isac);
|
||||||
|
CHECK_ISAC_RET (ret, Free);
|
||||||
|
self->isac = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_isacenc_set_format (GstAudioEncoder * enc, GstAudioInfo * info)
|
||||||
|
{
|
||||||
|
GstIsacEnc *self = GST_ISACENC (enc);
|
||||||
|
GstCaps *input_caps, *output_caps;
|
||||||
|
gint16 ret;
|
||||||
|
gboolean result;
|
||||||
|
|
||||||
|
switch (GST_AUDIO_INFO_RATE (info)) {
|
||||||
|
case 16000:
|
||||||
|
self->mode = ENCODER_MODE_WIDEBAND;
|
||||||
|
break;
|
||||||
|
case 32000:
|
||||||
|
self->mode = ENCODER_MODE_SUPER_WIDEBAND;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
g_assert_not_reached ();
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
input_caps = gst_audio_info_to_caps (info);
|
||||||
|
output_caps = gst_caps_new_simple ("audio/isac",
|
||||||
|
"channels", G_TYPE_INT, GST_AUDIO_INFO_CHANNELS (info),
|
||||||
|
"rate", G_TYPE_INT, GST_AUDIO_INFO_RATE (info), NULL);
|
||||||
|
|
||||||
|
GST_DEBUG_OBJECT (self, "input caps: %" GST_PTR_FORMAT, input_caps);
|
||||||
|
GST_DEBUG_OBJECT (self, "output caps: %" GST_PTR_FORMAT, output_caps);
|
||||||
|
|
||||||
|
ret = WebRtcIsac_SetEncSampRate (self->isac, GST_AUDIO_INFO_RATE (info));
|
||||||
|
CHECK_ISAC_RET (ret, SetEncSampleRate);
|
||||||
|
|
||||||
|
/* TODO: add support for automatically adjusted bit rate and frame
|
||||||
|
* length (codingMode = 0). */
|
||||||
|
ret = WebRtcIsac_EncoderInit (self->isac, 1);
|
||||||
|
CHECK_ISAC_RET (ret, EncoderInit);
|
||||||
|
|
||||||
|
if (self->mode == ENCODER_MODE_SUPER_WIDEBAND && self->output_frame_len != 30) {
|
||||||
|
GST_ERROR_OBJECT (self,
|
||||||
|
"Only output-frame-len=30 is supported in super-wideband mode (32 kHz)");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (self->mode == ENCODER_MODE_WIDEBAND && (self->bitrate < 10000
|
||||||
|
|| self->bitrate > 32000)) {
|
||||||
|
GST_ERROR_OBJECT (self,
|
||||||
|
"bitrate range is 10000 to 32000 bps in wideband mode (16 kHz)");
|
||||||
|
return FALSE;
|
||||||
|
} else if (self->mode == ENCODER_MODE_SUPER_WIDEBAND && (self->bitrate < 10000
|
||||||
|
|| self->bitrate > 56000)) {
|
||||||
|
GST_ERROR_OBJECT (self,
|
||||||
|
"bitrate range is 10000 to 56000 bps in super-wideband mode (32 kHz)");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = WebRtcIsac_Control (self->isac, self->bitrate, self->output_frame_len);
|
||||||
|
CHECK_ISAC_RET (ret, Control);
|
||||||
|
|
||||||
|
if (self->max_payload_size != GST_ISACENC_MAX_PAYLOAD_SIZE_DEFAULT) {
|
||||||
|
GST_DEBUG_OBJECT (self, "set max payload size to %d bytes",
|
||||||
|
self->max_payload_size);
|
||||||
|
ret = WebRtcIsac_SetMaxPayloadSize (self->isac, self->max_payload_size);
|
||||||
|
CHECK_ISAC_RET (ret, SetMaxPayloadSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (self->max_rate != GST_ISACENC_MAX_RATE_DEFAULT) {
|
||||||
|
GST_DEBUG_OBJECT (self, "set max rate to %d bits/sec", self->max_rate);
|
||||||
|
ret = WebRtcIsac_SetMaxRate (self->isac, self->max_rate);
|
||||||
|
CHECK_ISAC_RET (ret, SetMaxRate);
|
||||||
|
}
|
||||||
|
|
||||||
|
result = gst_audio_encoder_set_output_format (enc, output_caps);
|
||||||
|
|
||||||
|
/* input size is 10ms */
|
||||||
|
self->samples_per_frame = GST_AUDIO_INFO_RATE (info) / 100;
|
||||||
|
self->frame_size = self->samples_per_frame * GST_AUDIO_INFO_BPS (info);
|
||||||
|
|
||||||
|
GST_DEBUG_OBJECT (self, "input frame: %d samples, %" G_GSIZE_FORMAT " bytes",
|
||||||
|
self->samples_per_frame, self->frame_size);
|
||||||
|
|
||||||
|
gst_audio_encoder_set_frame_samples_min (enc, self->samples_per_frame);
|
||||||
|
gst_audio_encoder_set_frame_samples_max (enc, self->samples_per_frame);
|
||||||
|
gst_audio_encoder_set_hard_min (enc, TRUE);
|
||||||
|
|
||||||
|
gst_caps_unref (input_caps);
|
||||||
|
gst_caps_unref (output_caps);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static GstFlowReturn
|
||||||
|
gst_isacenc_handle_frame (GstAudioEncoder * enc, GstBuffer * input)
|
||||||
|
{
|
||||||
|
GstIsacEnc *self = GST_ISACENC (enc);
|
||||||
|
GstMapInfo map_read;
|
||||||
|
gint16 ret;
|
||||||
|
GstFlowReturn flow_ret = GST_FLOW_ERROR;
|
||||||
|
gsize offset = 0;
|
||||||
|
|
||||||
|
/* Can't drain the encoder */
|
||||||
|
if (!input)
|
||||||
|
return GST_FLOW_OK;
|
||||||
|
|
||||||
|
if (!gst_buffer_map (input, &map_read, GST_MAP_READ)) {
|
||||||
|
GST_ELEMENT_ERROR (self, RESOURCE, READ, ("Failed to map input buffer"),
|
||||||
|
(NULL));
|
||||||
|
return GST_FLOW_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
GST_LOG_OBJECT (self, "Received %" G_GSIZE_FORMAT " bytes", map_read.size);
|
||||||
|
|
||||||
|
while (offset + self->frame_size <= map_read.size) {
|
||||||
|
GstBuffer *output;
|
||||||
|
GstMapInfo map_write;
|
||||||
|
|
||||||
|
output = gst_audio_encoder_allocate_output_buffer (enc, OUTPUT_BUFFER_SIZE);
|
||||||
|
if (!gst_buffer_map (output, &map_write, GST_MAP_WRITE)) {
|
||||||
|
GST_ELEMENT_ERROR (self, RESOURCE, WRITE, ("Failed to map output buffer"),
|
||||||
|
(NULL));
|
||||||
|
gst_buffer_unref (output);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret =
|
||||||
|
WebRtcIsac_Encode (self->isac,
|
||||||
|
(const gint16 *) (map_read.data + offset), map_write.data);
|
||||||
|
|
||||||
|
gst_buffer_unmap (output, &map_write);
|
||||||
|
self->nb_processed_input_frames++;
|
||||||
|
offset += self->frame_size;
|
||||||
|
|
||||||
|
if (ret == 0) {
|
||||||
|
/* buffering */
|
||||||
|
gst_buffer_unref (output);
|
||||||
|
continue;
|
||||||
|
} else if (ret < 0) {
|
||||||
|
/* error */
|
||||||
|
gint16 code = WebRtcIsac_GetErrorCode (self->isac);
|
||||||
|
GST_ELEMENT_ERROR (self, LIBRARY, ENCODE, ("Failed to encode frame"),
|
||||||
|
("Failed to encode: %s (%d)", isac_error_code_to_str (code), code));
|
||||||
|
gst_buffer_unref (output);
|
||||||
|
goto out;
|
||||||
|
} else {
|
||||||
|
/* encoded */
|
||||||
|
GST_LOG_OBJECT (self, "Encoded %d input frames to %d bytes",
|
||||||
|
self->nb_processed_input_frames, ret);
|
||||||
|
|
||||||
|
gst_buffer_set_size (output, ret);
|
||||||
|
|
||||||
|
flow_ret =
|
||||||
|
gst_audio_encoder_finish_frame (enc, output,
|
||||||
|
self->nb_processed_input_frames * self->samples_per_frame);
|
||||||
|
|
||||||
|
if (flow_ret != GST_FLOW_OK)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
self->nb_processed_input_frames = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
flow_ret = GST_FLOW_OK;
|
||||||
|
out:
|
||||||
|
gst_buffer_unmap (input, &map_read);
|
||||||
|
return flow_ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_isacenc_set_property (GObject * object, guint prop_id,
|
||||||
|
const GValue * value, GParamSpec * pspec)
|
||||||
|
{
|
||||||
|
GstIsacEnc *self = GST_ISACENC (object);
|
||||||
|
|
||||||
|
switch (prop_id) {
|
||||||
|
case PROP_OUTPUT_FRAME_LEN:
|
||||||
|
self->output_frame_len = g_value_get_enum (value);
|
||||||
|
break;
|
||||||
|
case PROP_BITRATE:
|
||||||
|
self->bitrate = g_value_get_int (value);
|
||||||
|
break;
|
||||||
|
case PROP_MAX_PAYLOAD_SIZE:
|
||||||
|
self->max_payload_size = g_value_get_int (value);
|
||||||
|
break;
|
||||||
|
case PROP_MAX_RATE:
|
||||||
|
self->max_rate = g_value_get_int (value);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_isacenc_get_property (GObject * object, guint prop_id,
|
||||||
|
GValue * value, GParamSpec * pspec)
|
||||||
|
{
|
||||||
|
GstIsacEnc *self = GST_ISACENC (object);
|
||||||
|
|
||||||
|
switch (prop_id) {
|
||||||
|
case PROP_OUTPUT_FRAME_LEN:
|
||||||
|
g_value_set_enum (value, self->output_frame_len);
|
||||||
|
break;
|
||||||
|
case PROP_BITRATE:
|
||||||
|
g_value_set_int (value, self->bitrate);
|
||||||
|
break;
|
||||||
|
case PROP_MAX_PAYLOAD_SIZE:
|
||||||
|
g_value_set_int (value, self->max_payload_size);
|
||||||
|
break;
|
||||||
|
case PROP_MAX_RATE:
|
||||||
|
g_value_set_int (value, self->max_rate);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_isacenc_class_init (GstIsacEncClass * klass)
|
||||||
|
{
|
||||||
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||||
|
GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
|
||||||
|
GstAudioEncoderClass *base_class = GST_AUDIO_ENCODER_CLASS (klass);
|
||||||
|
|
||||||
|
gobject_class->set_property = gst_isacenc_set_property;
|
||||||
|
gobject_class->get_property = gst_isacenc_get_property;
|
||||||
|
|
||||||
|
base_class->start = GST_DEBUG_FUNCPTR (gst_isacenc_start);
|
||||||
|
base_class->stop = GST_DEBUG_FUNCPTR (gst_isacenc_stop);
|
||||||
|
base_class->set_format = GST_DEBUG_FUNCPTR (gst_isacenc_set_format);
|
||||||
|
base_class->handle_frame = GST_DEBUG_FUNCPTR (gst_isacenc_handle_frame);
|
||||||
|
|
||||||
|
g_object_class_install_property (gobject_class, PROP_OUTPUT_FRAME_LEN,
|
||||||
|
g_param_spec_enum ("output-frame-len", "Output Frame Length",
|
||||||
|
"Length, in ms, of output frames",
|
||||||
|
GST_TYPE_ISACENC_OUTPUT_FRAME_LEN,
|
||||||
|
GST_ISACENC_OUTPUT_FRAME_LEN_DEFAULT,
|
||||||
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
|
||||||
|
GST_PARAM_MUTABLE_READY));
|
||||||
|
|
||||||
|
g_object_class_install_property (gobject_class, PROP_BITRATE,
|
||||||
|
g_param_spec_int ("bitrate", "Bitrate",
|
||||||
|
"Average Bitrate (ABR) in bits/sec",
|
||||||
|
10000, 56000,
|
||||||
|
GST_ISACENC_BITRATE_DEFAULT,
|
||||||
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
|
||||||
|
GST_PARAM_MUTABLE_READY));
|
||||||
|
|
||||||
|
g_object_class_install_property (gobject_class, PROP_MAX_PAYLOAD_SIZE,
|
||||||
|
g_param_spec_int ("max-payload-size", "Max Payload Size",
|
||||||
|
"Maximum payload size, in bytes. Range is 120 to 400 at 16 kHz "
|
||||||
|
"and 120 to 600 at 32 kHz (-1 = encoder default)",
|
||||||
|
-1, 600,
|
||||||
|
GST_ISACENC_MAX_PAYLOAD_SIZE_DEFAULT,
|
||||||
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
|
||||||
|
GST_PARAM_MUTABLE_READY));
|
||||||
|
|
||||||
|
g_object_class_install_property (gobject_class, PROP_MAX_RATE,
|
||||||
|
g_param_spec_int ("max-rate", "Max Rate",
|
||||||
|
"Maximum rate, in bits/sec, which the codec may not exceed for any "
|
||||||
|
"signal packet. Range is 32000 to 53400 at 16 kHz "
|
||||||
|
"and 32000 to 160000 at 32 kHz (-1 = encoder default)",
|
||||||
|
-1, 160000,
|
||||||
|
GST_ISACENC_MAX_PAYLOAD_SIZE_DEFAULT,
|
||||||
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
|
||||||
|
GST_PARAM_MUTABLE_READY));
|
||||||
|
|
||||||
|
gst_element_class_set_static_metadata (gstelement_class, "iSAC encoder",
|
||||||
|
"Codec/Encoder/Audio",
|
||||||
|
"iSAC audio encoder",
|
||||||
|
"Guillaume Desmottes <guillaume.desmottes@collabora.com>");
|
||||||
|
|
||||||
|
gst_element_class_add_static_pad_template (gstelement_class, &sink_template);
|
||||||
|
gst_element_class_add_static_pad_template (gstelement_class, &src_template);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_isacenc_init (GstIsacEnc * self)
|
||||||
|
{
|
||||||
|
self->output_frame_len = GST_ISACENC_OUTPUT_FRAME_LEN_DEFAULT;
|
||||||
|
self->bitrate = GST_ISACENC_BITRATE_DEFAULT;
|
||||||
|
self->max_payload_size = GST_ISACENC_MAX_PAYLOAD_SIZE_DEFAULT;
|
||||||
|
self->max_rate = GST_ISACENC_MAX_RATE_DEFAULT;
|
||||||
|
}
|
34
ext/isac/gstisacenc.h
Normal file
34
ext/isac/gstisacenc.h
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
/* iSAC encoder
|
||||||
|
*
|
||||||
|
* 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 Street, Fifth Floor,
|
||||||
|
* Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __GST_ISAC_ENC_H__
|
||||||
|
#define __GST_ISAC_ENC_H__
|
||||||
|
|
||||||
|
#include <gst/audio/audio.h>
|
||||||
|
|
||||||
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
#define GST_TYPE_ISACENC gst_isacenc_get_type ()
|
||||||
|
G_DECLARE_FINAL_TYPE(GstIsacEnc, gst_isacenc, GST, ISACENC, GstAudioEncoder)
|
||||||
|
|
||||||
|
G_END_DECLS
|
||||||
|
|
||||||
|
#endif /* __GST_ISAC_ENC_H__ */
|
85
ext/isac/gstisacutils.c
Normal file
85
ext/isac/gstisacutils.c
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
/* iSAC plugin utils
|
||||||
|
*
|
||||||
|
* 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 Street, Fifth Floor,
|
||||||
|
* Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "gstisacutils.h"
|
||||||
|
|
||||||
|
#include <modules/audio_coding/codecs/isac/main/source/settings.h>
|
||||||
|
|
||||||
|
const gchar *
|
||||||
|
isac_error_code_to_str (gint code)
|
||||||
|
{
|
||||||
|
switch (code) {
|
||||||
|
case ISAC_MEMORY_ALLOCATION_FAILED:
|
||||||
|
return "allocation failed";
|
||||||
|
case ISAC_MODE_MISMATCH:
|
||||||
|
return "mode mismatch";
|
||||||
|
case ISAC_DISALLOWED_BOTTLENECK:
|
||||||
|
return "disallowed bottleneck";
|
||||||
|
case ISAC_DISALLOWED_FRAME_LENGTH:
|
||||||
|
return "disallowed frame length";
|
||||||
|
case ISAC_UNSUPPORTED_SAMPLING_FREQUENCY:
|
||||||
|
return "unsupported sampling frequency";
|
||||||
|
case ISAC_RANGE_ERROR_BW_ESTIMATOR:
|
||||||
|
return "range error bandwitch estimator";
|
||||||
|
case ISAC_ENCODER_NOT_INITIATED:
|
||||||
|
return "encoder not initiated";
|
||||||
|
case ISAC_DISALLOWED_CODING_MODE:
|
||||||
|
return "disallowed coding mode";
|
||||||
|
case ISAC_DISALLOWED_FRAME_MODE_ENCODER:
|
||||||
|
return "disallowed frame mode encoder";
|
||||||
|
case ISAC_DISALLOWED_BITSTREAM_LENGTH:
|
||||||
|
return "disallowed bitstream length";
|
||||||
|
case ISAC_PAYLOAD_LARGER_THAN_LIMIT:
|
||||||
|
return "payload larger than limit";
|
||||||
|
case ISAC_DISALLOWED_ENCODER_BANDWIDTH:
|
||||||
|
return "disallowed encoder bandwith";
|
||||||
|
case ISAC_DECODER_NOT_INITIATED:
|
||||||
|
return "decoder not initiated";
|
||||||
|
case ISAC_EMPTY_PACKET:
|
||||||
|
return "empty packet";
|
||||||
|
case ISAC_DISALLOWED_FRAME_MODE_DECODER:
|
||||||
|
return "disallowed frame mode decoder";
|
||||||
|
case ISAC_RANGE_ERROR_DECODE_FRAME_LENGTH:
|
||||||
|
return "range error decode frame length";
|
||||||
|
case ISAC_RANGE_ERROR_DECODE_BANDWIDTH:
|
||||||
|
return "range error decode bandwith";
|
||||||
|
case ISAC_RANGE_ERROR_DECODE_PITCH_GAIN:
|
||||||
|
return "range error decode pitch gain";
|
||||||
|
case ISAC_RANGE_ERROR_DECODE_PITCH_LAG:
|
||||||
|
return "range error decode pitch lag";
|
||||||
|
case ISAC_RANGE_ERROR_DECODE_LPC:
|
||||||
|
return "range error decode lpc";
|
||||||
|
case ISAC_RANGE_ERROR_DECODE_SPECTRUM:
|
||||||
|
return "range error decode spectrum";
|
||||||
|
case ISAC_LENGTH_MISMATCH:
|
||||||
|
return "length mismatch";
|
||||||
|
case ISAC_RANGE_ERROR_DECODE_BANDWITH:
|
||||||
|
return "range error decode bandwith";
|
||||||
|
case ISAC_DISALLOWED_BANDWIDTH_MODE_DECODER:
|
||||||
|
return "disallowed bandwitch mode decoder";
|
||||||
|
case ISAC_DISALLOWED_LPC_MODEL:
|
||||||
|
return "disallowed lpc model";
|
||||||
|
case ISAC_INCOMPATIBLE_FORMATS:
|
||||||
|
return "incompatible formats";
|
||||||
|
}
|
||||||
|
|
||||||
|
return "<unknown>";
|
||||||
|
}
|
40
ext/isac/gstisacutils.h
Normal file
40
ext/isac/gstisacutils.h
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
/* iSAC plugin utils
|
||||||
|
*
|
||||||
|
* 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 Street, Fifth Floor,
|
||||||
|
* Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __GST_ISAC_UTILS_H__
|
||||||
|
#define __GST_ISAC_UTILS_H__
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
const gchar * isac_error_code_to_str (gint code);
|
||||||
|
|
||||||
|
#define CHECK_ISAC_RET(ret, function) \
|
||||||
|
if (ret == -1) {\
|
||||||
|
gint16 code = WebRtcIsac_GetErrorCode (self->isac);\
|
||||||
|
GST_WARNING_OBJECT (self, "WebRtcIsac_"#function " call failed: %s (%d)", isac_error_code_to_str (code), code);\
|
||||||
|
return FALSE;\
|
||||||
|
}
|
||||||
|
|
||||||
|
G_END_DECLS
|
||||||
|
|
||||||
|
#endif /* __GST_ISAC_UTILS_H__ */
|
20
ext/isac/meson.build
Normal file
20
ext/isac/meson.build
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
webrtc_audio_coding_dep = dependency('webrtc-audio-coding-1', required: get_option('isac'))
|
||||||
|
|
||||||
|
if webrtc_audio_coding_dep.found()
|
||||||
|
isac_sources = [
|
||||||
|
'gstisac.c',
|
||||||
|
'gstisacenc.c',
|
||||||
|
'gstisacdec.c',
|
||||||
|
'gstisacutils.c',
|
||||||
|
]
|
||||||
|
|
||||||
|
gstisac = library('gstisac', isac_sources,
|
||||||
|
c_args : gst_plugins_bad_args,
|
||||||
|
include_directories : [configinc],
|
||||||
|
dependencies : [gstaudio_dep, webrtc_audio_coding_dep],
|
||||||
|
install : true,
|
||||||
|
install_dir : plugins_install_dir,
|
||||||
|
)
|
||||||
|
pkgconfig.generate(gstisac, install_dir : plugins_pkgconfig_install_dir)
|
||||||
|
plugins += [gstisac]
|
||||||
|
endif
|
|
@ -21,6 +21,7 @@ subdir('gme')
|
||||||
subdir('gsm')
|
subdir('gsm')
|
||||||
subdir('hls')
|
subdir('hls')
|
||||||
subdir('iqa')
|
subdir('iqa')
|
||||||
|
subdir('isac')
|
||||||
subdir('kate')
|
subdir('kate')
|
||||||
subdir('ladspa')
|
subdir('ladspa')
|
||||||
subdir('libde265')
|
subdir('libde265')
|
||||||
|
|
|
@ -169,6 +169,7 @@ option('zxing', type : 'feature', value : 'auto', description : 'Barcode image s
|
||||||
option('wpe', type : 'feature', value : 'auto', description : 'WPE Web browser plugin')
|
option('wpe', type : 'feature', value : 'auto', description : 'WPE Web browser plugin')
|
||||||
option('magicleap', type : 'feature', value : 'auto', description : 'Magic Leap platform support')
|
option('magicleap', type : 'feature', value : 'auto', description : 'Magic Leap platform support')
|
||||||
option('v4l2codecs', type : 'feature', value : 'auto', description : 'Video4Linux Stateless CODECs support')
|
option('v4l2codecs', type : 'feature', value : 'auto', description : 'Video4Linux Stateless CODECs support')
|
||||||
|
option('isac', type : 'feature', value : 'auto', description : 'iSAC plugin')
|
||||||
|
|
||||||
# HLS plugin options
|
# HLS plugin options
|
||||||
option('hls', type : 'feature', value : 'auto', description : 'HTTP Live Streaming plugin')
|
option('hls', type : 'feature', value : 'auto', description : 'HTTP Live Streaming plugin')
|
||||||
|
|
Loading…
Reference in a new issue