mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-10-21 09:53:47 +00:00
faad: port to 0.11
This commit is contained in:
parent
7f4cf50496
commit
f03b320c8d
1 changed files with 35 additions and 51 deletions
|
@ -95,24 +95,12 @@ static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
|
||||||
GST_STATIC_CAPS ("audio/mpeg, " "mpegversion = (int) { 2, 4 }")
|
GST_STATIC_CAPS ("audio/mpeg, " "mpegversion = (int) { 2, 4 }")
|
||||||
);
|
);
|
||||||
|
|
||||||
#define STATIC_INT_CAPS(bpp) \
|
#define STATIC_RAW_CAPS(format) \
|
||||||
"audio/x-raw-int, " \
|
"audio/x-raw, " \
|
||||||
"endianness = (int) BYTE_ORDER, " \
|
"format = (string) "GST_AUDIO_NE(format)", " \
|
||||||
"signed = (bool) TRUE, " \
|
|
||||||
"width = (int) " G_STRINGIFY (bpp) ", " \
|
|
||||||
"depth = (int) " G_STRINGIFY (bpp) ", " \
|
|
||||||
"rate = (int) [ 8000, 96000 ], " \
|
"rate = (int) [ 8000, 96000 ], " \
|
||||||
"channels = (int) [ 1, 8 ]"
|
"channels = (int) [ 1, 8 ]"
|
||||||
|
|
||||||
#if 0
|
|
||||||
#define STATIC_FLOAT_CAPS(bpp) \
|
|
||||||
"audio/x-raw-float, " \
|
|
||||||
"endianness = (int) BYTE_ORDER, " \
|
|
||||||
"depth = (int) " G_STRINGIFY (bpp) ", " \
|
|
||||||
"rate = (int) [ 8000, 96000 ], " \
|
|
||||||
"channels = (int) [ 1, 8 ]"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* All except 16-bit integer are disabled until someone fixes FAAD.
|
* All except 16-bit integer are disabled until someone fixes FAAD.
|
||||||
* FAAD allocates approximately 8*1024*2 bytes bytes, which is enough
|
* FAAD allocates approximately 8*1024*2 bytes bytes, which is enough
|
||||||
|
@ -122,16 +110,16 @@ static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define STATIC_CAPS \
|
#define STATIC_CAPS \
|
||||||
STATIC_INT_CAPS (16)
|
STATIC_RAW_CAPS (S16)
|
||||||
#if 0
|
#if 0
|
||||||
#define NOTUSED "; " \
|
#define NOTUSED "; " \
|
||||||
STATIC_INT_CAPS (24) \
|
STATIC_RAW_CAPS (S24) \
|
||||||
"; " \
|
"; " \
|
||||||
STATIC_INT_CAPS (32) \
|
STATIC_RAW_CAPS (S32) \
|
||||||
"; " \
|
"; " \
|
||||||
STATIC_FLOAT_CAPS (32) \
|
STATIC_RAW_CAPS (F32) \
|
||||||
"; " \
|
"; " \
|
||||||
STATIC_FLOAT_CAPS (64)
|
STATIC_RAW_CAPS (F64)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
|
static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
|
||||||
|
@ -154,12 +142,14 @@ static void gst_faad_flush (GstAudioDecoder * dec, gboolean hard);
|
||||||
static gboolean gst_faad_open_decoder (GstFaad * faad);
|
static gboolean gst_faad_open_decoder (GstFaad * faad);
|
||||||
static void gst_faad_close_decoder (GstFaad * faad);
|
static void gst_faad_close_decoder (GstFaad * faad);
|
||||||
|
|
||||||
GST_BOILERPLATE (GstFaad, gst_faad, GstAudioDecoder, GST_TYPE_AUDIO_DECODER);
|
#define gst_faad_parent_class parent_class
|
||||||
|
G_DEFINE_TYPE (GstFaad, gst_faad, GST_TYPE_AUDIO_DECODER);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_faad_base_init (gpointer klass)
|
gst_faad_class_init (GstFaadClass * klass)
|
||||||
{
|
{
|
||||||
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
||||||
|
GstAudioDecoderClass *base_class = GST_AUDIO_DECODER_CLASS (klass);
|
||||||
|
|
||||||
gst_element_class_add_pad_template (element_class,
|
gst_element_class_add_pad_template (element_class,
|
||||||
gst_static_pad_template_get (&src_template));
|
gst_static_pad_template_get (&src_template));
|
||||||
|
@ -171,26 +161,18 @@ gst_faad_base_init (gpointer klass)
|
||||||
"Free MPEG-2/4 AAC decoder",
|
"Free MPEG-2/4 AAC decoder",
|
||||||
"Ronald Bultje <rbultje@ronald.bitfreak.net>");
|
"Ronald Bultje <rbultje@ronald.bitfreak.net>");
|
||||||
|
|
||||||
GST_DEBUG_CATEGORY_INIT (faad_debug, "faad", 0, "AAC decoding");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_faad_class_init (GstFaadClass * klass)
|
|
||||||
{
|
|
||||||
GstAudioDecoderClass *base_class = GST_AUDIO_DECODER_CLASS (klass);
|
|
||||||
|
|
||||||
parent_class = g_type_class_peek_parent (klass);
|
|
||||||
|
|
||||||
base_class->start = GST_DEBUG_FUNCPTR (gst_faad_start);
|
base_class->start = GST_DEBUG_FUNCPTR (gst_faad_start);
|
||||||
base_class->stop = GST_DEBUG_FUNCPTR (gst_faad_stop);
|
base_class->stop = GST_DEBUG_FUNCPTR (gst_faad_stop);
|
||||||
base_class->set_format = GST_DEBUG_FUNCPTR (gst_faad_set_format);
|
base_class->set_format = GST_DEBUG_FUNCPTR (gst_faad_set_format);
|
||||||
base_class->parse = GST_DEBUG_FUNCPTR (gst_faad_parse);
|
base_class->parse = GST_DEBUG_FUNCPTR (gst_faad_parse);
|
||||||
base_class->handle_frame = GST_DEBUG_FUNCPTR (gst_faad_handle_frame);
|
base_class->handle_frame = GST_DEBUG_FUNCPTR (gst_faad_handle_frame);
|
||||||
base_class->flush = GST_DEBUG_FUNCPTR (gst_faad_flush);
|
base_class->flush = GST_DEBUG_FUNCPTR (gst_faad_flush);
|
||||||
|
|
||||||
|
GST_DEBUG_CATEGORY_INIT (faad_debug, "faad", 0, "AAC decoding");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_faad_init (GstFaad * faad, GstFaadClass * klass)
|
gst_faad_init (GstFaad * faad)
|
||||||
{
|
{
|
||||||
gst_faad_reset (faad);
|
gst_faad_reset (faad);
|
||||||
}
|
}
|
||||||
|
@ -280,6 +262,8 @@ gst_faad_set_format (GstAudioDecoder * dec, GstCaps * caps)
|
||||||
GstStructure *str = gst_caps_get_structure (caps, 0);
|
GstStructure *str = gst_caps_get_structure (caps, 0);
|
||||||
GstBuffer *buf;
|
GstBuffer *buf;
|
||||||
const GValue *value;
|
const GValue *value;
|
||||||
|
guint8 *cdata;
|
||||||
|
gsize csize;
|
||||||
|
|
||||||
/* clean up current decoder, rather than trying to reconfigure */
|
/* clean up current decoder, rather than trying to reconfigure */
|
||||||
gst_faad_close_decoder (faad);
|
gst_faad_close_decoder (faad);
|
||||||
|
@ -294,8 +278,6 @@ gst_faad_set_format (GstAudioDecoder * dec, GstCaps * caps)
|
||||||
guint32 samplerate;
|
guint32 samplerate;
|
||||||
#endif
|
#endif
|
||||||
guint8 channels;
|
guint8 channels;
|
||||||
guint8 *cdata;
|
|
||||||
guint csize;
|
|
||||||
|
|
||||||
/* We have codec data, means packetised stream */
|
/* We have codec data, means packetised stream */
|
||||||
faad->packetised = TRUE;
|
faad->packetised = TRUE;
|
||||||
|
@ -303,8 +285,7 @@ gst_faad_set_format (GstAudioDecoder * dec, GstCaps * caps)
|
||||||
buf = gst_value_get_buffer (value);
|
buf = gst_value_get_buffer (value);
|
||||||
g_return_val_if_fail (buf != NULL, FALSE);
|
g_return_val_if_fail (buf != NULL, FALSE);
|
||||||
|
|
||||||
cdata = GST_BUFFER_DATA (buf);
|
cdata = gst_buffer_map (buf, &csize, NULL, GST_MAP_READ);
|
||||||
csize = GST_BUFFER_SIZE (buf);
|
|
||||||
|
|
||||||
if (csize < 2)
|
if (csize < 2)
|
||||||
goto wrong_length;
|
goto wrong_length;
|
||||||
|
@ -375,18 +356,21 @@ wrong_length:
|
||||||
{
|
{
|
||||||
GST_DEBUG_OBJECT (faad, "codec_data less than 2 bytes long");
|
GST_DEBUG_OBJECT (faad, "codec_data less than 2 bytes long");
|
||||||
gst_object_unref (faad);
|
gst_object_unref (faad);
|
||||||
|
gst_buffer_unmap (buf, cdata, csize);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
open_failed:
|
open_failed:
|
||||||
{
|
{
|
||||||
GST_DEBUG_OBJECT (faad, "failed to create decoder");
|
GST_DEBUG_OBJECT (faad, "failed to create decoder");
|
||||||
gst_object_unref (faad);
|
gst_object_unref (faad);
|
||||||
|
gst_buffer_unmap (buf, cdata, csize);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
init_failed:
|
init_failed:
|
||||||
{
|
{
|
||||||
GST_DEBUG_OBJECT (faad, "faacDecInit2() failed");
|
GST_DEBUG_OBJECT (faad, "faacDecInit2() failed");
|
||||||
gst_object_unref (faad);
|
gst_object_unref (faad);
|
||||||
|
gst_buffer_unmap (buf, cdata, csize);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -662,9 +646,13 @@ gst_faad_parse (GstAudioDecoder * dec, GstAdapter * adapter,
|
||||||
*length = size;
|
*length = size;
|
||||||
return GST_FLOW_OK;
|
return GST_FLOW_OK;
|
||||||
} else {
|
} else {
|
||||||
data = gst_adapter_peek (adapter, size);
|
gboolean ret;
|
||||||
return gst_faad_sync (faad, data, size, !eos, offset, length) ?
|
|
||||||
GST_FLOW_OK : GST_FLOW_UNEXPECTED;
|
data = gst_adapter_map (adapter, size);
|
||||||
|
ret = gst_faad_sync (faad, data, size, !eos, offset, length);
|
||||||
|
gst_adapter_unmap (adapter, 0);
|
||||||
|
|
||||||
|
return (ret ? GST_FLOW_OK : GST_FLOW_UNEXPECTED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -673,7 +661,7 @@ gst_faad_handle_frame (GstAudioDecoder * dec, GstBuffer * buffer)
|
||||||
{
|
{
|
||||||
GstFaad *faad;
|
GstFaad *faad;
|
||||||
GstFlowReturn ret = GST_FLOW_OK;
|
GstFlowReturn ret = GST_FLOW_OK;
|
||||||
guint input_size;
|
gsize input_size;
|
||||||
guchar *input_data;
|
guchar *input_data;
|
||||||
GstBuffer *outbuf;
|
GstBuffer *outbuf;
|
||||||
faacDecFrameInfo info;
|
faacDecFrameInfo info;
|
||||||
|
@ -685,8 +673,7 @@ gst_faad_handle_frame (GstAudioDecoder * dec, GstBuffer * buffer)
|
||||||
if (G_UNLIKELY (!buffer))
|
if (G_UNLIKELY (!buffer))
|
||||||
return GST_FLOW_OK;
|
return GST_FLOW_OK;
|
||||||
|
|
||||||
input_data = GST_BUFFER_DATA (buffer);
|
input_data = gst_buffer_map (buffer, &input_size, NULL, GST_MAP_READ);
|
||||||
input_size = GST_BUFFER_SIZE (buffer);
|
|
||||||
|
|
||||||
init:
|
init:
|
||||||
/* init if not already done during capsnego */
|
/* init if not already done during capsnego */
|
||||||
|
@ -764,20 +751,17 @@ init:
|
||||||
goto sample_overflow;
|
goto sample_overflow;
|
||||||
|
|
||||||
/* note: info.samples is total samples, not per channel */
|
/* note: info.samples is total samples, not per channel */
|
||||||
ret =
|
/* FIXME, add bufferpool and allocator support to the base class */
|
||||||
gst_pad_alloc_buffer_and_set_caps (GST_AUDIO_DECODER_SRC_PAD
|
outbuf = gst_buffer_new_allocate (NULL, info.samples * faad->bps, 0);
|
||||||
(faad), 0, info.samples * faad->bps,
|
gst_buffer_fill (outbuf, 0, out, info.samples * faad->bps);
|
||||||
GST_PAD_CAPS (GST_AUDIO_DECODER_SRC_PAD (faad)), &outbuf);
|
|
||||||
if (ret != GST_FLOW_OK)
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
memcpy (GST_BUFFER_DATA (outbuf), out, GST_BUFFER_SIZE (outbuf));
|
|
||||||
|
|
||||||
ret = gst_audio_decoder_finish_frame (dec, outbuf, 1);
|
ret = gst_audio_decoder_finish_frame (dec, outbuf, 1);
|
||||||
}
|
}
|
||||||
} while (FALSE);
|
} while (FALSE);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
gst_buffer_unmap (buffer, input_data, input_size);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
/* ERRORS */
|
/* ERRORS */
|
||||||
|
|
Loading…
Reference in a new issue