mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 04:01:08 +00:00
[MOVED FROM GST-P-FARSIGHT] Port sirendec to Gstelement
20080704201744-3e2dc-99bf7b86e42da363d8c826449d84b43751572d5e.gz
This commit is contained in:
parent
84a188ff73
commit
bda906038d
3 changed files with 66 additions and 171 deletions
|
@ -70,20 +70,11 @@ enum
|
|||
};
|
||||
|
||||
|
||||
static GstFlowReturn
|
||||
gst_siren_dec_chain (GstPad *pad, GstBuffer *buf);
|
||||
|
||||
static void gst_siren_dec_dispose (GObject *object);
|
||||
|
||||
static GstFlowReturn gst_siren_dec_transform (GstBaseTransform *trans,
|
||||
GstBuffer *inbuf, GstBuffer *outbuf);
|
||||
static gboolean gst_siren_dec_transform_size (GstBaseTransform *trans,
|
||||
GstPadDirection direction, GstCaps *caps, guint size,
|
||||
GstCaps *othercaps, guint *othersize);
|
||||
static GstCaps * gst_siren_dec_transform_caps (GstBaseTransform * base,
|
||||
GstPadDirection direction, GstCaps * caps);
|
||||
static gboolean gst_siren_dec_start (GstBaseTransform *trans);
|
||||
static gboolean gst_siren_dec_stop (GstBaseTransform *trans);
|
||||
|
||||
|
||||
static void
|
||||
_do_init (GType type)
|
||||
{
|
||||
|
@ -91,8 +82,8 @@ _do_init (GType type)
|
|||
(sirendec_debug, "sirendec", 0, "sirendec");
|
||||
}
|
||||
|
||||
GST_BOILERPLATE_FULL (GstSirenDec, gst_siren_dec, GstBaseTransform,
|
||||
GST_TYPE_BASE_TRANSFORM, _do_init);
|
||||
GST_BOILERPLATE_FULL (GstSirenDec, gst_siren_dec, GstElement,
|
||||
GST_TYPE_ELEMENT, _do_init);
|
||||
|
||||
static void
|
||||
gst_siren_dec_base_init (gpointer klass)
|
||||
|
@ -111,28 +102,15 @@ static void
|
|||
gst_siren_dec_class_init (GstSirenDecClass *klass)
|
||||
{
|
||||
GObjectClass *gobject_class;
|
||||
GstBaseTransformClass *gstbasetransform_class;
|
||||
GstElementClass *gstelement_class;
|
||||
|
||||
gobject_class = (GObjectClass *) klass;
|
||||
gstbasetransform_class = (GstBaseTransformClass *) klass;
|
||||
gstelement_class = (GstElementClass *) klass;
|
||||
|
||||
GST_DEBUG ("Initializing Class");
|
||||
|
||||
gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_siren_dec_dispose);
|
||||
|
||||
gstbasetransform_class->transform =
|
||||
GST_DEBUG_FUNCPTR (gst_siren_dec_transform);
|
||||
gstbasetransform_class->transform_caps =
|
||||
GST_DEBUG_FUNCPTR (gst_siren_dec_transform_caps);
|
||||
gstbasetransform_class->transform_size =
|
||||
GST_DEBUG_FUNCPTR (gst_siren_dec_transform_size);
|
||||
gstbasetransform_class->start =
|
||||
GST_DEBUG_FUNCPTR (gst_siren_dec_start);
|
||||
gstbasetransform_class->stop =
|
||||
GST_DEBUG_FUNCPTR (gst_siren_dec_stop);
|
||||
|
||||
parent_class = g_type_class_peek_parent (klass);
|
||||
|
||||
GST_DEBUG ("Class Init done");
|
||||
}
|
||||
|
||||
|
@ -141,8 +119,18 @@ gst_siren_dec_init (GstSirenDec *dec, GstSirenDecClass *klass)
|
|||
{
|
||||
|
||||
GST_DEBUG_OBJECT (dec, "Initializing");
|
||||
dec->decoder = NULL;
|
||||
dec->adapter = gst_adapter_new ();
|
||||
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);
|
||||
|
||||
GST_DEBUG_OBJECT (dec, "Init done");
|
||||
}
|
||||
|
@ -158,128 +146,26 @@ gst_siren_dec_dispose (GObject *object)
|
|||
Siren7_CloseDecoder (dec->decoder);
|
||||
dec->decoder = NULL;
|
||||
}
|
||||
if (dec->adapter) {
|
||||
g_object_unref (dec->adapter);
|
||||
dec->adapter = NULL;
|
||||
|
||||
if (dec->srccaps)
|
||||
{
|
||||
gst_caps_unref (dec->srccaps);
|
||||
dec->srccaps = NULL;
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_siren_dec_start (GstBaseTransform *trans)
|
||||
{
|
||||
GstSirenDec *dec = GST_SIREN_DEC (trans);
|
||||
|
||||
GST_DEBUG ("Start");
|
||||
|
||||
if (dec->decoder) {
|
||||
Siren7_CloseDecoder (dec->decoder);
|
||||
dec->decoder = NULL;
|
||||
}
|
||||
dec->decoder = Siren7_NewDecoder (16000);
|
||||
gst_adapter_clear (dec->adapter);
|
||||
|
||||
return dec->decoder != NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static gboolean
|
||||
gst_siren_dec_stop (GstBaseTransform *trans)
|
||||
{
|
||||
GstSirenDec *dec = GST_SIREN_DEC (trans);
|
||||
|
||||
GST_DEBUG ("Stop");
|
||||
|
||||
if (dec->decoder) {
|
||||
Siren7_CloseDecoder (dec->decoder);
|
||||
dec->decoder = NULL;
|
||||
}
|
||||
gst_adapter_clear (dec->adapter);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
static gboolean gst_siren_dec_transform_size (GstBaseTransform *trans,
|
||||
GstPadDirection direction, GstCaps *caps, guint size,
|
||||
GstCaps *othercaps, guint *othersize)
|
||||
{
|
||||
GstSirenDec *dec = GST_SIREN_DEC (trans);
|
||||
GstStructure *structure = NULL;
|
||||
const gchar *in_name = NULL;
|
||||
const gchar *out_name = NULL;
|
||||
gboolean decoding;
|
||||
|
||||
if (caps != NULL && othercaps != NULL) {
|
||||
structure = gst_caps_get_structure (caps, 0);
|
||||
in_name = gst_structure_get_name (structure);
|
||||
structure = gst_caps_get_structure (othercaps, 0);
|
||||
out_name = gst_structure_get_name (structure);
|
||||
}
|
||||
|
||||
GST_DEBUG ("Transform size from caps '%s' to '%s'", in_name, out_name);
|
||||
|
||||
if (in_name == NULL || out_name == NULL) {
|
||||
if (direction == GST_PAD_SINK)
|
||||
decoding = TRUE;
|
||||
else
|
||||
decoding = FALSE;
|
||||
} else if (strcmp (in_name, "audio/x-raw-int") == 0 &&
|
||||
strcmp (out_name, "audio/x-siren") == 0 ) {
|
||||
decoding = FALSE;
|
||||
} else if (strcmp (in_name, "audio/x-siren") == 0 &&
|
||||
strcmp (out_name, "audio/x-raw-int") == 0 ) {
|
||||
decoding = TRUE;
|
||||
} else {
|
||||
GST_DEBUG ("Unknown in/out caps");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (decoding) {
|
||||
size += gst_adapter_available (dec->adapter);
|
||||
*othersize = size * 16;
|
||||
*othersize -= *othersize % 640;
|
||||
if ((size * 16) % 640 > 0)
|
||||
*othersize+= 640;
|
||||
} else {
|
||||
*othersize = size / 16;
|
||||
*othersize -= *othersize % 40;
|
||||
if ((size / 16) % 40 > 0)
|
||||
*othersize+= 40;
|
||||
}
|
||||
GST_DEBUG ("Transform size %d to %d", size, *othersize);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static GstCaps * gst_siren_dec_transform_caps (GstBaseTransform * base,
|
||||
GstPadDirection direction, GstCaps * caps)
|
||||
{
|
||||
GstCaps *othercaps = NULL;
|
||||
GST_DEBUG ("Transforming caps");
|
||||
|
||||
if (direction == GST_PAD_SINK) {
|
||||
return gst_static_pad_template_get_caps (&srctemplate);
|
||||
} else if (direction == GST_PAD_SRC) {
|
||||
return gst_static_pad_template_get_caps (&sinktemplate);
|
||||
}
|
||||
|
||||
GST_DEBUG ("Transform caps");
|
||||
|
||||
return othercaps;
|
||||
}
|
||||
|
||||
static GstFlowReturn
|
||||
gst_siren_dec_transform (GstBaseTransform *trans, GstBuffer *inbuf,
|
||||
GstBuffer *outbuf)
|
||||
gst_siren_dec_chain (GstPad *pad, GstBuffer *buf)
|
||||
{
|
||||
|
||||
GstSirenDec *dec = GST_SIREN_DEC (trans);
|
||||
GstSirenDec *dec = GST_SIREN_DEC (gst_pad_get_parent_element (pad));
|
||||
GstFlowReturn ret = GST_FLOW_OK;
|
||||
guint8 *data = NULL;
|
||||
gint offset = 0;
|
||||
GstBuffer *decoded = NULL;
|
||||
guint inoffset = 0;
|
||||
guint outoffset = 0;
|
||||
gint decode_ret = 0;
|
||||
guint size = 0;
|
||||
|
||||
GST_LOG_OBJECT (dec, "Transform");
|
||||
|
||||
|
@ -287,45 +173,57 @@ gst_siren_dec_transform (GstBaseTransform *trans, GstBuffer *inbuf,
|
|||
GST_DEBUG ("Siren decoder not set");
|
||||
return GST_FLOW_WRONG_STATE;
|
||||
}
|
||||
if (dec->adapter == NULL) {
|
||||
GST_DEBUG ("Adapter not set");
|
||||
return GST_FLOW_UNEXPECTED;
|
||||
|
||||
GST_LOG_OBJECT (dec,"Received buffer of size %d", GST_BUFFER_SIZE (buf));
|
||||
|
||||
size = GST_BUFFER_SIZE (buf) * 16;
|
||||
size -= size % 640;
|
||||
|
||||
if (size == 0)
|
||||
{
|
||||
GST_LOG_OBJECT (dec, "Got buffer smaller than framesize: %u < 40",
|
||||
GST_BUFFER_SIZE (buf));
|
||||
return GST_FLOW_OK;
|
||||
}
|
||||
|
||||
gst_buffer_ref (inbuf);
|
||||
gst_adapter_push (dec->adapter, inbuf);
|
||||
if (size % 40 != 0)
|
||||
GST_LOG_OBJECT (dec, "Got buffer with size not a multiple for frame size,"
|
||||
" ignoring last %u bytes", GST_BUFFER_SIZE (buf) % 40);
|
||||
|
||||
GST_LOG_OBJECT (dec,"Received buffer of size %d with adapter of size : %d",
|
||||
GST_BUFFER_SIZE (inbuf), gst_adapter_available (dec->adapter));
|
||||
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;
|
||||
|
||||
data = GST_BUFFER_DATA (outbuf);
|
||||
offset = 0;
|
||||
while((gst_adapter_available (dec->adapter) >= 40) &&
|
||||
(offset + 640 <= GST_BUFFER_SIZE (outbuf)) &&
|
||||
while((inoffset + 40 <= GST_BUFFER_SIZE (buf)) &&
|
||||
ret == GST_FLOW_OK) {
|
||||
|
||||
GST_DEBUG ("Decoding frame");
|
||||
|
||||
decode_ret = Siren7_DecodeFrame (dec->decoder,
|
||||
(guint8 *) gst_adapter_peek (dec->adapter, 40),
|
||||
data + offset);
|
||||
GST_BUFFER_DATA (buf) + inoffset,
|
||||
GST_BUFFER_DATA (decoded) + outoffset);
|
||||
if (decode_ret != 0) {
|
||||
GST_ERROR_OBJECT (dec, "Siren7_DecodeFrame returned %d", decode_ret);
|
||||
ret = GST_FLOW_ERROR;
|
||||
}
|
||||
|
||||
gst_adapter_flush (dec->adapter, 40);
|
||||
offset += 640;
|
||||
inoffset += 40;
|
||||
outoffset += 640;
|
||||
}
|
||||
|
||||
GST_LOG_OBJECT (dec, "Finished decoding : %d", offset);
|
||||
if (offset != GST_BUFFER_SIZE (outbuf)) {
|
||||
GST_LOG_OBJECT (dec, "Finished decoding : %d", outoffset);
|
||||
if (outoffset != GST_BUFFER_SIZE (decoded)) {
|
||||
GST_ERROR_OBJECT (dec,
|
||||
"didn't decode enough : offfset (%d) != BUFFER_SIZE (%d)",
|
||||
offset, GST_BUFFER_SIZE (outbuf));
|
||||
outoffset, GST_BUFFER_SIZE (decoded));
|
||||
return GST_FLOW_ERROR;
|
||||
}
|
||||
|
||||
ret = gst_pad_push (dec->srcpad, decoded);
|
||||
|
||||
gst_object_unref (dec);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
#define __GST_SIREN_DEC_H__
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <gst/base/gstbasetransform.h>
|
||||
#include <gst/base/gstadapter.h>
|
||||
|
||||
#include "siren7.h"
|
||||
|
@ -51,22 +50,19 @@ typedef struct _GstSirenDecPrivate GstSirenDecPrivate;
|
|||
|
||||
struct _GstSirenDec
|
||||
{
|
||||
GstBaseTransform parent;
|
||||
GstElement parent;
|
||||
|
||||
SirenDecoder decoder;
|
||||
GstAdapter *adapter;
|
||||
|
||||
/*< private > */
|
||||
gpointer _gst_reserved[GST_PADDING];
|
||||
GstPad *sinkpad;
|
||||
GstPad *srcpad;
|
||||
|
||||
GstCaps *srccaps;
|
||||
};
|
||||
|
||||
struct _GstSirenDecClass
|
||||
{
|
||||
GstBaseTransformClass parent_class;
|
||||
|
||||
|
||||
/*< private > */
|
||||
gpointer _gst_reserved[GST_PADDING];
|
||||
GstElementClass parent_class;
|
||||
};
|
||||
|
||||
GType gst_siren_dec_get_type (void);
|
||||
|
|
|
@ -153,6 +153,7 @@ gst_siren_enc_dispose (GObject *object)
|
|||
Siren7_CloseEncoder (enc->encoder);
|
||||
enc->encoder = NULL;
|
||||
}
|
||||
|
||||
if (enc->adapter) {
|
||||
g_object_unref (enc->adapter);
|
||||
enc->adapter = NULL;
|
||||
|
|
Loading…
Reference in a new issue