2008-04-10 07:01:16 +00:00
|
|
|
/*
|
|
|
|
* Siren Decoder Gst Element
|
|
|
|
*
|
|
|
|
* @author: Youness Alaoui <kakaroto@kakaroto.homelinux.net>
|
|
|
|
*
|
|
|
|
* 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., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
*/
|
2009-02-10 19:20:26 +00:00
|
|
|
/**
|
|
|
|
* SECTION:element-sirendec
|
|
|
|
*
|
|
|
|
* This decodes audio buffers from the Siren 16 codec (a 16khz extension of
|
|
|
|
* G.722.1) that is meant to be compatible with the Microsoft Windows Live
|
|
|
|
* Messenger(tm) implementation.
|
|
|
|
*
|
|
|
|
* Ref: http://www.polycom.com/company/about_us/technology/siren_g7221/index.html
|
|
|
|
*/
|
2008-04-10 07:01:16 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "gstsirendec.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY (sirendec_debug);
|
|
|
|
#define GST_CAT_DEFAULT (sirendec_debug)
|
|
|
|
|
|
|
|
/* elementfactory information */
|
|
|
|
static const GstElementDetails gst_siren_dec_details =
|
2009-02-10 19:20:19 +00:00
|
|
|
GST_ELEMENT_DETAILS ("Siren Decoder element",
|
|
|
|
"Codec/Decoder/Audio ",
|
|
|
|
"Decode streams encoded with the Siren7 codec into 16bit PCM",
|
|
|
|
"Youness Alaoui <kakaroto@kakaroto.homelinux.net>");
|
2008-04-10 07:01:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
2009-02-10 19:20:19 +00:00
|
|
|
GST_STATIC_CAPS ("audio/x-siren, " "dct-length = (int) 320"));
|
2008-04-10 07:01:16 +00:00
|
|
|
|
|
|
|
static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("audio/x-raw-int, "
|
|
|
|
"width = (int) 16, "
|
|
|
|
"depth = (int) 16, "
|
|
|
|
"endianness = (int) 1234, "
|
|
|
|
"signed = (boolean) true, "
|
2009-02-10 19:20:19 +00:00
|
|
|
"rate = (int) 16000, " "channels = (int) 1"));
|
2008-04-10 07:01:16 +00:00
|
|
|
|
|
|
|
/* signals and args */
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
ARG_0,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-02-10 19:20:19 +00:00
|
|
|
static GstFlowReturn gst_siren_dec_chain (GstPad * pad, GstBuffer * buf);
|
2008-04-10 07:01:16 +00:00
|
|
|
|
2009-02-10 19:20:19 +00:00
|
|
|
static void gst_siren_dec_dispose (GObject * object);
|
2008-04-10 07:01:16 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
_do_init (GType type)
|
|
|
|
{
|
2009-02-10 19:20:19 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (sirendec_debug, "sirendec", 0, "sirendec");
|
2008-04-10 07:01:16 +00:00
|
|
|
}
|
|
|
|
|
2008-07-04 20:17:44 +00:00
|
|
|
GST_BOILERPLATE_FULL (GstSirenDec, gst_siren_dec, GstElement,
|
|
|
|
GST_TYPE_ELEMENT, _do_init);
|
2008-04-10 07:01:16 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gst_siren_dec_base_init (gpointer klass)
|
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
|
|
|
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&srctemplate));
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&sinktemplate));
|
|
|
|
|
|
|
|
gst_element_class_set_details (element_class, &gst_siren_dec_details);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-02-10 19:20:19 +00:00
|
|
|
gst_siren_dec_class_init (GstSirenDecClass * klass)
|
2008-04-10 07:01:16 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
2008-07-04 20:17:44 +00:00
|
|
|
GstElementClass *gstelement_class;
|
2008-04-10 07:01:16 +00:00
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
2008-07-04 20:17:44 +00:00
|
|
|
gstelement_class = (GstElementClass *) klass;
|
2008-04-10 07:01:16 +00:00
|
|
|
|
|
|
|
GST_DEBUG ("Initializing Class");
|
|
|
|
|
|
|
|
gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_siren_dec_dispose);
|
|
|
|
|
|
|
|
GST_DEBUG ("Class Init done");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-02-10 19:20:19 +00:00
|
|
|
gst_siren_dec_init (GstSirenDec * dec, GstSirenDecClass * klass)
|
2008-04-10 07:01:16 +00:00
|
|
|
{
|
|
|
|
|
2008-07-04 20:00:29 +00:00
|
|
|
GST_DEBUG_OBJECT (dec, "Initializing");
|
2008-07-04 20:17:44 +00:00
|
|
|
dec->decoder = Siren7_NewDecoder (16000);;
|
|
|
|
|
|
|
|
dec->sinkpad = gst_pad_new_from_static_template (&sinktemplate, "sink");
|
|
|
|
dec->srcpad = gst_pad_new_from_static_template (&srctemplate, "src");
|
|
|
|
|
|
|
|
gst_pad_set_chain_function (dec->sinkpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_siren_dec_chain));
|
|
|
|
|
|
|
|
gst_element_add_pad (GST_ELEMENT (dec), dec->sinkpad);
|
|
|
|
gst_element_add_pad (GST_ELEMENT (dec), dec->srcpad);
|
|
|
|
|
|
|
|
dec->srccaps = gst_static_pad_template_get_caps (&srctemplate);
|
2008-04-10 07:01:16 +00:00
|
|
|
|
2008-07-04 20:00:29 +00:00
|
|
|
GST_DEBUG_OBJECT (dec, "Init done");
|
2008-04-10 07:01:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-02-10 19:20:19 +00:00
|
|
|
gst_siren_dec_dispose (GObject * object)
|
2008-04-10 07:01:16 +00:00
|
|
|
{
|
|
|
|
GstSirenDec *dec = GST_SIREN_DEC (object);
|
|
|
|
|
2008-07-04 20:00:29 +00:00
|
|
|
GST_DEBUG_OBJECT (dec, "Disposing");
|
2008-04-10 07:01:16 +00:00
|
|
|
|
|
|
|
if (dec->decoder) {
|
|
|
|
Siren7_CloseDecoder (dec->decoder);
|
|
|
|
dec->decoder = NULL;
|
|
|
|
}
|
|
|
|
|
2009-02-10 19:20:19 +00:00
|
|
|
if (dec->srccaps) {
|
2008-07-04 20:17:44 +00:00
|
|
|
gst_caps_unref (dec->srccaps);
|
|
|
|
dec->srccaps = NULL;
|
2008-04-10 07:01:16 +00:00
|
|
|
}
|
|
|
|
|
2008-07-04 20:17:44 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
2008-04-10 07:01:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2009-02-10 19:20:19 +00:00
|
|
|
gst_siren_dec_chain (GstPad * pad, GstBuffer * buf)
|
2008-04-10 07:01:16 +00:00
|
|
|
{
|
2008-07-04 20:17:44 +00:00
|
|
|
GstSirenDec *dec = GST_SIREN_DEC (gst_pad_get_parent_element (pad));
|
2008-04-10 07:01:16 +00:00
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
2008-07-04 20:17:44 +00:00
|
|
|
GstBuffer *decoded = NULL;
|
2008-10-06 02:03:05 +00:00
|
|
|
guint in_offset = 0;
|
|
|
|
guint out_offset = 0;
|
2008-04-10 07:01:16 +00:00
|
|
|
gint decode_ret = 0;
|
2008-07-04 20:17:44 +00:00
|
|
|
guint size = 0;
|
2008-04-10 07:01:16 +00:00
|
|
|
|
2008-07-04 22:21:03 +00:00
|
|
|
GST_LOG_OBJECT (dec, "Decoding buffer of size %d", GST_BUFFER_SIZE (buf));
|
2008-07-04 20:17:44 +00:00
|
|
|
|
|
|
|
size = GST_BUFFER_SIZE (buf) * 16;
|
|
|
|
size -= size % 640;
|
|
|
|
|
2009-02-10 19:20:19 +00:00
|
|
|
if (size == 0) {
|
2008-07-04 20:17:44 +00:00
|
|
|
GST_LOG_OBJECT (dec, "Got buffer smaller than framesize: %u < 40",
|
|
|
|
GST_BUFFER_SIZE (buf));
|
|
|
|
return GST_FLOW_OK;
|
2008-04-10 07:01:16 +00:00
|
|
|
}
|
|
|
|
|
2008-10-06 02:00:27 +00:00
|
|
|
if (GST_BUFFER_SIZE (buf) % 40 != 0)
|
2008-07-04 20:17:44 +00:00
|
|
|
GST_LOG_OBJECT (dec, "Got buffer with size not a multiple for frame size,"
|
|
|
|
" ignoring last %u bytes", GST_BUFFER_SIZE (buf) % 40);
|
2008-04-10 07:01:16 +00:00
|
|
|
|
2008-07-04 20:17:44 +00:00
|
|
|
ret = gst_pad_alloc_buffer_and_set_caps (dec->srcpad,
|
|
|
|
GST_BUFFER_OFFSET (buf) * 16, size, dec->srccaps, &decoded);
|
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
return ret;
|
2008-04-10 07:01:16 +00:00
|
|
|
|
2008-09-16 19:40:04 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (decoded) = GST_BUFFER_TIMESTAMP (buf);
|
|
|
|
|
2009-02-10 19:20:19 +00:00
|
|
|
while ((in_offset + 40 <= GST_BUFFER_SIZE (buf)) && ret == GST_FLOW_OK) {
|
2008-04-10 07:01:16 +00:00
|
|
|
|
2008-07-04 20:18:30 +00:00
|
|
|
GST_LOG_OBJECT (dec, "Decoding frame");
|
2008-04-10 07:01:16 +00:00
|
|
|
|
|
|
|
decode_ret = Siren7_DecodeFrame (dec->decoder,
|
2008-10-06 02:03:05 +00:00
|
|
|
GST_BUFFER_DATA (buf) + in_offset,
|
|
|
|
GST_BUFFER_DATA (decoded) + out_offset);
|
2008-04-10 07:01:16 +00:00
|
|
|
if (decode_ret != 0) {
|
2008-07-04 20:00:29 +00:00
|
|
|
GST_ERROR_OBJECT (dec, "Siren7_DecodeFrame returned %d", decode_ret);
|
2008-04-10 07:01:16 +00:00
|
|
|
ret = GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
|
2008-10-06 02:03:05 +00:00
|
|
|
in_offset += 40;
|
|
|
|
out_offset += 640;
|
2008-04-10 07:01:16 +00:00
|
|
|
}
|
|
|
|
|
2008-10-06 02:03:05 +00:00
|
|
|
GST_LOG_OBJECT (dec, "Finished decoding : %d", out_offset);
|
|
|
|
if (out_offset != GST_BUFFER_SIZE (decoded)) {
|
2008-07-04 20:00:29 +00:00
|
|
|
GST_ERROR_OBJECT (dec,
|
|
|
|
"didn't decode enough : offfset (%d) != BUFFER_SIZE (%d)",
|
2008-10-06 02:03:05 +00:00
|
|
|
out_offset, GST_BUFFER_SIZE (decoded));
|
2008-04-10 07:01:16 +00:00
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
|
2008-07-04 20:17:44 +00:00
|
|
|
ret = gst_pad_push (dec->srcpad, decoded);
|
|
|
|
|
|
|
|
gst_object_unref (dec);
|
|
|
|
|
2008-04-10 07:01:16 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gboolean
|
2009-02-10 19:20:19 +00:00
|
|
|
gst_siren_dec_plugin_init (GstPlugin * plugin)
|
2008-04-10 07:01:16 +00:00
|
|
|
{
|
|
|
|
return gst_element_register (plugin, "sirendec",
|
|
|
|
GST_RANK_MARGINAL, GST_TYPE_SIREN_DEC);
|
|
|
|
}
|