ext/faad/gstfaad.*: Fix negotiation (#310932) and miscellaneous other stuff. Probably still needs some more work.
Original commit message from CVS: * ext/faad/gstfaad.c: (gst_faad_base_init), (gst_faad_class_init), (gst_faad_init), (gst_faad_setcaps), (gst_faad_srcgetcaps), (gst_faad_event), (gst_faad_update_caps), (gst_faad_chain), (gst_faad_change_state): * ext/faad/gstfaad.h: Fix negotiation (#310932) and miscellaneous other stuff. Probably still needs some more work.
This commit is contained in:
parent
a649c14c8c
commit
76f3f25ecf
10
ChangeLog
10
ChangeLog
@ -1,3 +1,13 @@
|
|||||||
|
2005-08-08 Tim-Philipp Müller <tim at centricular dot net>
|
||||||
|
|
||||||
|
* ext/faad/gstfaad.c: (gst_faad_base_init), (gst_faad_class_init),
|
||||||
|
(gst_faad_init), (gst_faad_setcaps), (gst_faad_srcgetcaps),
|
||||||
|
(gst_faad_event), (gst_faad_update_caps), (gst_faad_chain),
|
||||||
|
(gst_faad_change_state):
|
||||||
|
* ext/faad/gstfaad.h:
|
||||||
|
Fix negotiation (#310932) and miscellaneous other stuff. Probably
|
||||||
|
still needs some more work.
|
||||||
|
|
||||||
2005-08-08 Tim-Philipp Müller <tim at centricular dot net>
|
2005-08-08 Tim-Philipp Müller <tim at centricular dot net>
|
||||||
|
|
||||||
* ext/jpeg/gstjpegdec.c: (gst_jpeg_dec_init),
|
* ext/jpeg/gstjpegdec.c: (gst_jpeg_dec_init),
|
||||||
|
@ -22,11 +22,16 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <gst/audio/multichannel.h>
|
#include <gst/audio/multichannel.h>
|
||||||
|
|
||||||
#include "gstfaad.h"
|
#include "gstfaad.h"
|
||||||
|
|
||||||
|
static GstElementDetails faad_details = {
|
||||||
|
"Free AAC Decoder (FAAD)",
|
||||||
|
"Codec/Decoder/Audio",
|
||||||
|
"Free MPEG-2/4 AAC decoder",
|
||||||
|
"Ronald Bultje <rbultje@ronald.bitfreak.net>"
|
||||||
|
};
|
||||||
|
|
||||||
static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
|
static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
|
||||||
GST_PAD_SINK,
|
GST_PAD_SINK,
|
||||||
GST_PAD_ALWAYS,
|
GST_PAD_ALWAYS,
|
||||||
@ -42,12 +47,14 @@ static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
|
|||||||
"rate = (int) [ 8000, 96000 ], " \
|
"rate = (int) [ 8000, 96000 ], " \
|
||||||
"channels = (int) [ 1, 8 ]"
|
"channels = (int) [ 1, 8 ]"
|
||||||
|
|
||||||
|
#if 0
|
||||||
#define STATIC_FLOAT_CAPS(bpp) \
|
#define STATIC_FLOAT_CAPS(bpp) \
|
||||||
"audio/x-raw-float, " \
|
"audio/x-raw-float, " \
|
||||||
"endianness = (int) BYTE_ORDER, " \
|
"endianness = (int) BYTE_ORDER, " \
|
||||||
"depth = (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 ]"
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* All except 16-bit integer are disabled until someone fixes FAAD.
|
* All except 16-bit integer are disabled until someone fixes FAAD.
|
||||||
@ -69,6 +76,7 @@ STATIC_FLOAT_CAPS (32) \
|
|||||||
"; " \
|
"; " \
|
||||||
STATIC_FLOAT_CAPS (64)
|
STATIC_FLOAT_CAPS (64)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
|
static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
|
||||||
GST_PAD_SRC,
|
GST_PAD_SRC,
|
||||||
GST_PAD_ALWAYS,
|
GST_PAD_ALWAYS,
|
||||||
@ -79,20 +87,13 @@ static void gst_faad_base_init (GstFaadClass * klass);
|
|||||||
static void gst_faad_class_init (GstFaadClass * klass);
|
static void gst_faad_class_init (GstFaadClass * klass);
|
||||||
static void gst_faad_init (GstFaad * faad);
|
static void gst_faad_init (GstFaad * faad);
|
||||||
|
|
||||||
/*
|
|
||||||
static GstPadLinkReturn
|
|
||||||
gst_faad_sinkconnect (GstPad * pad, const GstCaps * caps);
|
|
||||||
static GstPadLinkReturn
|
|
||||||
gst_faad_srcconnect (GstPad * pad, const GstCaps * caps);*/
|
|
||||||
static gboolean gst_faad_setcaps (GstPad * pad, GstCaps * caps);
|
static gboolean gst_faad_setcaps (GstPad * pad, GstCaps * caps);
|
||||||
static GstCaps *gst_faad_srcgetcaps (GstPad * pad);
|
static GstCaps *gst_faad_srcgetcaps (GstPad * pad);
|
||||||
static gboolean gst_faad_event (GstPad * pad, GstEvent * event);
|
static gboolean gst_faad_event (GstPad * pad, GstEvent * event);
|
||||||
static GstFlowReturn gst_faad_chain (GstPad * pad, GstBuffer * buffer);
|
static GstFlowReturn gst_faad_chain (GstPad * pad, GstBuffer * buffer);
|
||||||
static GstElementStateReturn gst_faad_change_state (GstElement * element);
|
static GstElementStateReturn gst_faad_change_state (GstElement * element);
|
||||||
|
|
||||||
static GstElementClass *parent_class = NULL;
|
static GstElementClass *parent_class; /* NULL */
|
||||||
|
|
||||||
/* static guint gst_faad_signals[LAST_SIGNAL] = { 0 }; */
|
|
||||||
|
|
||||||
GType
|
GType
|
||||||
gst_faad_get_type (void)
|
gst_faad_get_type (void)
|
||||||
@ -122,11 +123,6 @@ gst_faad_get_type (void)
|
|||||||
static void
|
static void
|
||||||
gst_faad_base_init (GstFaadClass * klass)
|
gst_faad_base_init (GstFaadClass * klass)
|
||||||
{
|
{
|
||||||
static GstElementDetails gst_faad_details =
|
|
||||||
GST_ELEMENT_DETAILS ("Free AAC Decoder (FAAD)",
|
|
||||||
"Codec/Decoder/Audio",
|
|
||||||
"Free MPEG-2/4 AAC decoder",
|
|
||||||
"Ronald Bultje <rbultje@ronald.bitfreak.net>");
|
|
||||||
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
||||||
|
|
||||||
gst_element_class_add_pad_template (element_class,
|
gst_element_class_add_pad_template (element_class,
|
||||||
@ -134,7 +130,7 @@ gst_faad_base_init (GstFaadClass * klass)
|
|||||||
gst_element_class_add_pad_template (element_class,
|
gst_element_class_add_pad_template (element_class,
|
||||||
gst_static_pad_template_get (&sink_template));
|
gst_static_pad_template_get (&sink_template));
|
||||||
|
|
||||||
gst_element_class_set_details (element_class, &gst_faad_details);
|
gst_element_class_set_details (element_class, &faad_details);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -142,7 +138,7 @@ gst_faad_class_init (GstFaadClass * klass)
|
|||||||
{
|
{
|
||||||
GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
|
GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
|
||||||
|
|
||||||
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
|
parent_class = g_type_class_peek_parent (klass);
|
||||||
|
|
||||||
gstelement_class->change_state = gst_faad_change_state;
|
gstelement_class->change_state = gst_faad_change_state;
|
||||||
}
|
}
|
||||||
@ -157,8 +153,10 @@ gst_faad_init (GstFaad * faad)
|
|||||||
faad->need_channel_setup = TRUE;
|
faad->need_channel_setup = TRUE;
|
||||||
faad->channel_positions = NULL;
|
faad->channel_positions = NULL;
|
||||||
faad->init = FALSE;
|
faad->init = FALSE;
|
||||||
|
faad->next_ts = 0;
|
||||||
/* GST_FLAG_SET (faad, GST_ELEMENT_EVENT_AWARE); */
|
faad->bytes_in = 0;
|
||||||
|
faad->sum_dur_out = 0;
|
||||||
|
faad->packetised = FALSE;
|
||||||
|
|
||||||
faad->sinkpad =
|
faad->sinkpad =
|
||||||
gst_pad_new_from_template (gst_static_pad_template_get (&sink_template),
|
gst_pad_new_from_template (gst_static_pad_template_get (&sink_template),
|
||||||
@ -167,41 +165,65 @@ gst_faad_init (GstFaad * faad)
|
|||||||
gst_pad_set_event_function (faad->sinkpad, gst_faad_event);
|
gst_pad_set_event_function (faad->sinkpad, gst_faad_event);
|
||||||
gst_pad_set_setcaps_function (faad->sinkpad, gst_faad_setcaps);
|
gst_pad_set_setcaps_function (faad->sinkpad, gst_faad_setcaps);
|
||||||
gst_pad_set_chain_function (faad->sinkpad, gst_faad_chain);
|
gst_pad_set_chain_function (faad->sinkpad, gst_faad_chain);
|
||||||
/*gst_pad_set_link_function (faad->sinkpad, gst_faad_sinkconnect); */
|
|
||||||
|
|
||||||
faad->srcpad =
|
faad->srcpad =
|
||||||
gst_pad_new_from_template (gst_static_pad_template_get (&src_template),
|
gst_pad_new_from_template (gst_static_pad_template_get (&src_template),
|
||||||
"src");
|
"src");
|
||||||
gst_element_add_pad (GST_ELEMENT (faad), faad->srcpad);
|
gst_element_add_pad (GST_ELEMENT (faad), faad->srcpad);
|
||||||
gst_pad_use_fixed_caps (faad->srcpad);
|
gst_pad_use_fixed_caps (faad->srcpad);
|
||||||
/*gst_pad_set_link_function (faad->srcpad, gst_faad_srcconnect); */
|
|
||||||
gst_pad_set_getcaps_function (faad->srcpad, gst_faad_srcgetcaps);
|
gst_pad_set_getcaps_function (faad->srcpad, gst_faad_srcgetcaps);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_faad_setcaps (GstPad * pad, GstCaps * caps)
|
gst_faad_setcaps (GstPad * pad, GstCaps * caps)
|
||||||
{
|
{
|
||||||
GstStructure *structure;
|
GstFaad *faad = GST_FAAD (gst_pad_get_parent (pad));
|
||||||
GstFaad *faad;
|
GstStructure *str = gst_caps_get_structure (caps, 0);
|
||||||
GstCaps *copy;
|
GstBuffer *buf;
|
||||||
|
const GValue *value;
|
||||||
|
|
||||||
faad = GST_FAAD (GST_PAD_PARENT (pad));
|
/* Assume raw stream */
|
||||||
|
faad->packetised = FALSE;
|
||||||
|
|
||||||
structure = gst_caps_get_structure (caps, 0);
|
if ((value = gst_structure_get_value (str, "codec_data"))) {
|
||||||
|
gulong samplerate;
|
||||||
|
guchar channels;
|
||||||
|
|
||||||
/* get channel count */
|
/* We have codec data, means packetised stream */
|
||||||
gst_structure_get_int (structure, "channels", &faad->channels);
|
faad->packetised = TRUE;
|
||||||
gst_structure_get_int (structure, "rate", &faad->samplerate);
|
buf = g_value_get_boxed (value);
|
||||||
|
|
||||||
/* create reverse caps */
|
if (faad->handle) {
|
||||||
copy = gst_caps_new_simple ("audio/x-raw-float",
|
GST_DEBUG ("faad handle already open; closing before re-initing");
|
||||||
"channels", G_TYPE_INT, faad->channels,
|
faacDecClose (faad->handle);
|
||||||
"depth", G_TYPE_INT, G_STRINGIFY (bpp),
|
}
|
||||||
"endianness", G_TYPE_INT, G_BYTE_ORDER,
|
|
||||||
"rate", G_TYPE_INT, faad->samplerate);
|
|
||||||
|
|
||||||
gst_pad_set_caps (faad->srcpad, copy);
|
/* someone forgot that char can be unsigned when writing the API */
|
||||||
gst_caps_unref (copy);
|
if ((gint8) faacDecInit2 (faad->handle, GST_BUFFER_DATA (buf),
|
||||||
|
GST_BUFFER_SIZE (buf), &samplerate, &channels) < 0) {
|
||||||
|
GST_DEBUG ("faacDecInit2() failed");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
#if 0
|
||||||
|
faad->samplerate = samplerate;
|
||||||
|
faad->channels = channels;
|
||||||
|
#endif
|
||||||
|
/* not updating these here, so they are updated in the
|
||||||
|
* chain function, and new caps are created etc. */
|
||||||
|
faad->samplerate = 0;
|
||||||
|
faad->channels = 0;
|
||||||
|
|
||||||
|
faad->init = TRUE;
|
||||||
|
|
||||||
|
if (faad->tempbuf) {
|
||||||
|
gst_buffer_unref (faad->tempbuf);
|
||||||
|
faad->tempbuf = NULL;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
faad->init = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
faad->need_channel_setup = TRUE;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@ -258,6 +280,7 @@ gst_faad_chanpos_from_gst (GstAudioChannelPosition * pos, guint num)
|
|||||||
return fpos;
|
return fpos;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static GstAudioChannelPosition *
|
static GstAudioChannelPosition *
|
||||||
gst_faad_chanpos_to_gst (guchar * fpos, guint num)
|
gst_faad_chanpos_to_gst (guchar * fpos, guint num)
|
||||||
{
|
{
|
||||||
@ -352,10 +375,11 @@ gst_faad_sinkconnect (GstPad * pad, const GstCaps * caps)
|
|||||||
return GST_PAD_LINK_OK;
|
return GST_PAD_LINK_OK;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static GstCaps *
|
static GstCaps *
|
||||||
gst_faad_srcgetcaps (GstPad * pad)
|
gst_faad_srcgetcaps (GstPad * pad)
|
||||||
{
|
{
|
||||||
GstFaad *faad = GST_FAAD (gst_pad_get_parent (pad));
|
GstFaad *faad = GST_FAAD (GST_OBJECT_PARENT (pad));
|
||||||
static GstAudioChannelPosition *supported_positions = NULL;
|
static GstAudioChannelPosition *supported_positions = NULL;
|
||||||
static gint num_supported_positions = LFE_CHANNEL - FRONT_CHANNEL_CENTER + 1;
|
static gint num_supported_positions = LFE_CHANNEL - FRONT_CHANNEL_CENTER + 1;
|
||||||
GstCaps *templ;
|
GstCaps *templ;
|
||||||
@ -430,7 +454,7 @@ gst_faad_srcgetcaps (GstPad * pad)
|
|||||||
if (faad->channels != -1) {
|
if (faad->channels != -1) {
|
||||||
gst_structure_set (str, "channels", G_TYPE_INT, faad->channels, NULL);
|
gst_structure_set (str, "channels", G_TYPE_INT, faad->channels, NULL);
|
||||||
|
|
||||||
// put channel information here */
|
/* put channel information here */
|
||||||
if (faad->channel_positions) {
|
if (faad->channel_positions) {
|
||||||
GstAudioChannelPosition *pos;
|
GstAudioChannelPosition *pos;
|
||||||
|
|
||||||
@ -578,31 +602,124 @@ gst_faad_srcconnect (GstPad * pad, const GstCaps * caps)
|
|||||||
return GST_PAD_LINK_REFUSED;
|
return GST_PAD_LINK_REFUSED;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
/*
|
|
||||||
* Data reading.
|
|
||||||
*/
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_faad_event (GstPad * pad, GstEvent * event)
|
gst_faad_event (GstPad * pad, GstEvent * event)
|
||||||
{
|
{
|
||||||
GstFaad *faad;
|
GstFaad *faad;
|
||||||
gboolean res;
|
gboolean res = TRUE;
|
||||||
|
|
||||||
faad = GST_FAAD (gst_pad_get_parent (pad));
|
faad = GST_FAAD (gst_pad_get_parent (pad));
|
||||||
|
|
||||||
GST_LOG ("handling event %d", GST_EVENT_TYPE (event));
|
GST_LOG ("handling event %d", GST_EVENT_TYPE (event));
|
||||||
|
|
||||||
|
/* FIXME: we should probably handle FLUSH and also
|
||||||
|
* SEEK in the case where we are not in a container
|
||||||
|
* (when our newsegment was in BYTES) */
|
||||||
switch (GST_EVENT_TYPE (event)) {
|
switch (GST_EVENT_TYPE (event)) {
|
||||||
case GST_EVENT_EOS:
|
case GST_EVENT_EOS:
|
||||||
|
if (faad->tempbuf != NULL) {
|
||||||
|
gst_buffer_unref (faad->tempbuf);
|
||||||
|
faad->tempbuf = NULL;
|
||||||
|
}
|
||||||
|
GST_STREAM_LOCK (pad);
|
||||||
|
res = gst_pad_push_event (faad->srcpad, event);
|
||||||
|
GST_STREAM_UNLOCK (pad);
|
||||||
|
break;
|
||||||
case GST_EVENT_NEWSEGMENT:
|
case GST_EVENT_NEWSEGMENT:
|
||||||
|
{
|
||||||
|
GstFormat fmt;
|
||||||
|
guint64 start, end, base;
|
||||||
|
gdouble rate;
|
||||||
|
|
||||||
|
gst_event_parse_newsegment (event, &rate, &fmt, &start, &end, &base);
|
||||||
|
if (fmt == GST_FORMAT_TIME) {
|
||||||
|
GST_DEBUG ("Got NEWSEGMENT event in GST_FORMAT_TIME, passing on ("
|
||||||
|
GST_TIME_FORMAT " - " GST_TIME_FORMAT ")", GST_TIME_ARGS (start),
|
||||||
|
GST_TIME_ARGS (end));
|
||||||
|
} else if (fmt == GST_FORMAT_BYTES) {
|
||||||
|
GstEvent *new_ev;
|
||||||
|
guint64 new_start = 0;
|
||||||
|
guint64 new_end = GST_CLOCK_TIME_NONE;
|
||||||
|
|
||||||
|
GST_DEBUG ("Got NEWSEGMENT event in GST_FORMAT_BYTES (%"
|
||||||
|
G_GUINT64_FORMAT " - %" G_GUINT64_FORMAT ")", start, end);
|
||||||
|
|
||||||
|
if (faad->bytes_in > 0 && faad->sum_dur_out > 0) {
|
||||||
|
/* try to convert based on the average bitrate so far */
|
||||||
|
new_start = (faad->sum_dur_out * start) / faad->bytes_in;
|
||||||
|
if (new_end != (guint64) - 1) {
|
||||||
|
new_end = (faad->sum_dur_out * end) / faad->bytes_in;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
GST_DEBUG
|
||||||
|
("no average bitrate yet, sending newsegment with start at 0");
|
||||||
|
}
|
||||||
|
new_ev =
|
||||||
|
gst_event_new_newsegment (rate, GST_FORMAT_TIME, new_start, new_end,
|
||||||
|
base);
|
||||||
|
gst_event_unref (event);
|
||||||
|
event = new_ev;
|
||||||
|
GST_DEBUG ("Sending new NEWSEGMENT event, time " GST_TIME_FORMAT " - "
|
||||||
|
GST_TIME_FORMAT, GST_TIME_ARGS (new_start),
|
||||||
|
GST_TIME_ARGS (new_end));
|
||||||
|
}
|
||||||
|
|
||||||
|
GST_STREAM_LOCK (pad);
|
||||||
|
res = gst_pad_push_event (faad->srcpad, event);
|
||||||
|
GST_STREAM_UNLOCK (pad);
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
|
GST_STREAM_LOCK (pad);
|
||||||
|
res = gst_pad_push_event (faad->srcpad, event);
|
||||||
|
GST_STREAM_UNLOCK (pad);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
res = gst_pad_event_default (faad->sinkpad, event);
|
/* res = gst_pad_event_default (faad->sinkpad, event); */
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_faad_update_caps (GstFaad * faad, faacDecFrameInfo * info,
|
||||||
|
GstCaps ** p_caps)
|
||||||
|
{
|
||||||
|
GstAudioChannelPosition *pos;
|
||||||
|
GstCaps *caps;
|
||||||
|
|
||||||
|
/* store new negotiation information */
|
||||||
|
faad->samplerate = info->samplerate;
|
||||||
|
faad->channels = info->channels;
|
||||||
|
g_free (faad->channel_positions);
|
||||||
|
faad->channel_positions = g_memdup (info->channel_position, faad->channels);
|
||||||
|
|
||||||
|
caps = gst_caps_new_simple ("audio/x-raw-int",
|
||||||
|
"endianness", G_TYPE_INT, G_BYTE_ORDER,
|
||||||
|
"signed", G_TYPE_BOOLEAN, TRUE,
|
||||||
|
"width", G_TYPE_INT, 16,
|
||||||
|
"depth", G_TYPE_INT, 16,
|
||||||
|
"rate", G_TYPE_INT, faad->samplerate,
|
||||||
|
"channels", G_TYPE_INT, faad->channels, NULL);
|
||||||
|
|
||||||
|
faad->bps = 16 / 8;
|
||||||
|
|
||||||
|
pos = gst_faad_chanpos_to_gst (faad->channel_positions, faad->channels);
|
||||||
|
gst_audio_set_channel_positions (gst_caps_get_structure (caps, 0), pos);
|
||||||
|
g_free (pos);
|
||||||
|
|
||||||
|
GST_DEBUG ("New output caps: %" GST_PTR_FORMAT, caps);
|
||||||
|
|
||||||
|
if (!gst_pad_set_caps (faad->srcpad, caps)) {
|
||||||
|
gst_caps_unref (caps);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
*p_caps = caps;
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
static GstFlowReturn
|
static GstFlowReturn
|
||||||
gst_faad_chain (GstPad * pad, GstBuffer * buffer)
|
gst_faad_chain (GstPad * pad, GstBuffer * buffer)
|
||||||
{
|
{
|
||||||
@ -610,37 +727,22 @@ gst_faad_chain (GstPad * pad, GstBuffer * buffer)
|
|||||||
guint input_size;
|
guint input_size;
|
||||||
guint skip_bytes = 0;
|
guint skip_bytes = 0;
|
||||||
guchar *input_data;
|
guchar *input_data;
|
||||||
GstFaad *faad = GST_FAAD (gst_pad_get_parent (pad));
|
GstFaad *faad;
|
||||||
GstBuffer *outbuf;
|
GstBuffer *outbuf;
|
||||||
faacDecFrameInfo *info;
|
GstCaps *caps = NULL;
|
||||||
guint64 next_ts;
|
faacDecFrameInfo info;
|
||||||
void *out;
|
void *out;
|
||||||
gboolean run_loop = TRUE;
|
gboolean run_loop = TRUE;
|
||||||
|
|
||||||
/*
|
faad = GST_FAAD (GST_OBJECT_PARENT (pad));
|
||||||
if (GST_IS_EVENT (data)) {
|
|
||||||
GstEvent *event = GST_EVENT (data);
|
|
||||||
|
|
||||||
switch (GST_EVENT_TYPE (event)) {
|
if (GST_BUFFER_TIMESTAMP (buffer) != GST_CLOCK_TIME_NONE) {
|
||||||
case GST_EVENT_EOS:
|
faad->next_ts = GST_BUFFER_TIMESTAMP (buffer);
|
||||||
if (faad->tempbuf != NULL) {
|
GST_DEBUG ("Timestamp on incoming buffer: %" GST_TIME_FORMAT,
|
||||||
gst_buffer_unref (faad->tempbuf);
|
GST_TIME_ARGS (faad->next_ts));
|
||||||
faad->tempbuf = NULL;
|
|
||||||
}
|
|
||||||
gst_element_set_eos (GST_ELEMENT (faad));
|
|
||||||
gst_pad_push (faad->srcpad, data);
|
|
||||||
return;
|
|
||||||
default:
|
|
||||||
gst_pad_event_default (pad, event);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
info = g_new0 (faacDecFrameInfo, 1);
|
|
||||||
|
|
||||||
/* buffer + remaining data */
|
/* buffer + remaining data */
|
||||||
/* buf = GST_BUFFER (data); */
|
|
||||||
next_ts = GST_BUFFER_TIMESTAMP (buffer);
|
|
||||||
if (faad->tempbuf) {
|
if (faad->tempbuf) {
|
||||||
buffer = gst_buffer_join (faad->tempbuf, buffer);
|
buffer = gst_buffer_join (faad->tempbuf, buffer);
|
||||||
faad->tempbuf = NULL;
|
faad->tempbuf = NULL;
|
||||||
@ -663,19 +765,15 @@ gst_faad_chain (GstPad * pad, GstBuffer * buffer)
|
|||||||
skip_bytes = init_res;
|
skip_bytes = init_res;
|
||||||
faad->init = TRUE;
|
faad->init = TRUE;
|
||||||
|
|
||||||
/* store for renegotiation later on */
|
/* make sure we create new caps below */
|
||||||
/* FIXME: that's moot, info will get zeroed in DecDecode() */
|
faad->samplerate = 0;
|
||||||
info->samplerate = samplerate;
|
faad->channels = 0;
|
||||||
info->channels = channels;
|
|
||||||
} else {
|
|
||||||
info->samplerate = 0;
|
|
||||||
info->channels = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* decode cycle */
|
/* decode cycle */
|
||||||
input_data = GST_BUFFER_DATA (buffer);
|
input_data = GST_BUFFER_DATA (buffer);
|
||||||
input_size = GST_BUFFER_SIZE (buffer);
|
input_size = GST_BUFFER_SIZE (buffer);
|
||||||
info->bytesconsumed = input_size - skip_bytes;
|
info.bytesconsumed = input_size - skip_bytes;
|
||||||
|
|
||||||
if (!faad->packetised) {
|
if (!faad->packetised) {
|
||||||
/* We must check that ourselves for raw stream */
|
/* We must check that ourselves for raw stream */
|
||||||
@ -688,72 +786,75 @@ gst_faad_chain (GstPad * pad, GstBuffer * buffer)
|
|||||||
/* Only one packet per buffer, no matter how much is really consumed */
|
/* Only one packet per buffer, no matter how much is really consumed */
|
||||||
run_loop = FALSE;
|
run_loop = FALSE;
|
||||||
} else {
|
} else {
|
||||||
if (input_size < FAAD_MIN_STREAMSIZE || info->bytesconsumed <= 0) {
|
if (input_size < FAAD_MIN_STREAMSIZE || info.bytesconsumed <= 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
out = faacDecDecode (faad->handle, info, input_data + skip_bytes,
|
out = faacDecDecode (faad->handle, &info, input_data + skip_bytes,
|
||||||
input_size - skip_bytes);
|
input_size - skip_bytes);
|
||||||
if (info->error) {
|
if (info.error) {
|
||||||
GST_ELEMENT_ERROR (faad, STREAM, DECODE, (NULL),
|
GST_ELEMENT_ERROR (faad, STREAM, DECODE, (NULL),
|
||||||
("Failed to decode buffer: %s",
|
("Failed to decode buffer: %s", faacDecGetErrorMessage (info.error)));
|
||||||
faacDecGetErrorMessage (info->error)));
|
ret = GST_FLOW_ERROR;
|
||||||
break;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info->bytesconsumed > input_size)
|
if (info.bytesconsumed > input_size)
|
||||||
info->bytesconsumed = input_size;
|
info.bytesconsumed = input_size;
|
||||||
input_size -= info->bytesconsumed;
|
input_size -= info.bytesconsumed;
|
||||||
input_data += info->bytesconsumed;
|
input_data += info.bytesconsumed;
|
||||||
|
|
||||||
if (out && info->samples > 0) {
|
if (out && info.samples > 0) {
|
||||||
gboolean fmt_change = FALSE;
|
gboolean fmt_change = FALSE;
|
||||||
|
|
||||||
/* see if we need to renegotiate */
|
/* see if we need to renegotiate */
|
||||||
if (info->samplerate != faad->samplerate ||
|
if (info.samplerate != faad->samplerate ||
|
||||||
info->channels != faad->channels || !faad->channel_positions) {
|
info.channels != faad->channels || !faad->channel_positions) {
|
||||||
fmt_change = TRUE;
|
fmt_change = TRUE;
|
||||||
} else {
|
} else {
|
||||||
gint i;
|
gint i;
|
||||||
|
|
||||||
for (i = 0; i < info->channels; i++) {
|
for (i = 0; i < info.channels; i++) {
|
||||||
if (info->channel_position[i] != faad->channel_positions[i])
|
if (info.channel_position[i] != faad->channel_positions[i])
|
||||||
fmt_change = TRUE;
|
fmt_change = TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fmt_change) {
|
if (fmt_change) {
|
||||||
/*GstPadLinkReturn ret; */
|
if (!gst_faad_update_caps (faad, &info, &caps)) {
|
||||||
|
GST_ELEMENT_ERROR (faad, CORE, NEGOTIATION, (NULL),
|
||||||
/* store new negotiation information */
|
("Setting caps on source pad failed"));
|
||||||
faad->samplerate = info->samplerate;
|
ret = GST_FLOW_ERROR;
|
||||||
faad->channels = info->channels;
|
goto out;
|
||||||
if (faad->channel_positions)
|
}
|
||||||
g_free (faad->channel_positions);
|
|
||||||
faad->channel_positions = g_new (guint8, faad->channels);
|
|
||||||
memcpy (faad->channel_positions, info->channel_position,
|
|
||||||
faad->channels);
|
|
||||||
|
|
||||||
/* and negotiate
|
|
||||||
ret = gst_pad_renegotiate (faad->srcpad);
|
|
||||||
if (GST_PAD_LINK_FAILED (ret)) {
|
|
||||||
GST_ELEMENT_ERROR (faad, CORE, NEGOTIATION, (NULL), (NULL));
|
|
||||||
break;
|
|
||||||
} */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* play decoded data */
|
/* play decoded data */
|
||||||
if (info->samples > 0) {
|
if (info.samples > 0 && GST_PAD_PEER (faad->srcpad)) {
|
||||||
outbuf = gst_buffer_new_and_alloc (info->samples * faad->bps);
|
GstFlowReturn r;
|
||||||
/* ugh */
|
guint bufsize = info.samples * faad->bps;
|
||||||
memcpy (GST_BUFFER_DATA (outbuf), out, GST_BUFFER_SIZE (outbuf));
|
|
||||||
GST_BUFFER_TIMESTAMP (outbuf) = next_ts;
|
/* note: info.samples is total samples, not per channel */
|
||||||
GST_BUFFER_DURATION (outbuf) =
|
r = gst_pad_alloc_buffer (faad->srcpad, 0, bufsize, caps, &outbuf);
|
||||||
(guint64) GST_SECOND *info->samples / faad->samplerate;
|
if (r != GST_FLOW_OK) {
|
||||||
if (GST_CLOCK_TIME_IS_VALID (next_ts)) {
|
GST_DEBUG ("Failed to allocate buffer");
|
||||||
next_ts += GST_BUFFER_DURATION (outbuf);
|
ret = GST_FLOW_OK; /* CHECK: or return something else? */
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
memcpy (GST_BUFFER_DATA (outbuf), out, GST_BUFFER_SIZE (outbuf));
|
||||||
|
GST_BUFFER_OFFSET (outbuf) =
|
||||||
|
(faad->next_ts * faad->samplerate) / GST_SECOND;
|
||||||
|
GST_BUFFER_TIMESTAMP (outbuf) = faad->next_ts;
|
||||||
|
GST_BUFFER_DURATION (outbuf) = (guint64) GST_SECOND *info.samples / (faad->samplerate * 2); ///////// over 2?
|
||||||
|
|
||||||
|
faad->next_ts += GST_BUFFER_DURATION (outbuf);
|
||||||
|
faad->sum_dur_out += GST_BUFFER_DURATION (outbuf);
|
||||||
|
|
||||||
|
GST_DEBUG ("pushing buffer, off=%" G_GUINT64_FORMAT ", ts=%"
|
||||||
|
GST_TIME_FORMAT, GST_BUFFER_OFFSET (outbuf),
|
||||||
|
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (outbuf)));
|
||||||
gst_pad_push (faad->srcpad, outbuf);
|
gst_pad_push (faad->srcpad, outbuf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -770,9 +871,14 @@ gst_faad_chain (GstPad * pad, GstBuffer * buffer)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gst_buffer_unref (buffer);
|
faad->bytes_in += input_size;
|
||||||
|
|
||||||
g_free (info);
|
out:
|
||||||
|
|
||||||
|
if (caps)
|
||||||
|
gst_caps_unref (caps);
|
||||||
|
|
||||||
|
gst_buffer_unref (buffer);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -784,6 +890,7 @@ gst_faad_change_state (GstElement * element)
|
|||||||
|
|
||||||
switch (GST_STATE_TRANSITION (element)) {
|
switch (GST_STATE_TRANSITION (element)) {
|
||||||
case GST_STATE_NULL_TO_READY:
|
case GST_STATE_NULL_TO_READY:
|
||||||
|
{
|
||||||
if (!(faad->handle = faacDecOpen ()))
|
if (!(faad->handle = faacDecOpen ()))
|
||||||
return GST_STATE_FAILURE;
|
return GST_STATE_FAILURE;
|
||||||
else {
|
else {
|
||||||
@ -791,10 +898,13 @@ gst_faad_change_state (GstElement * element)
|
|||||||
|
|
||||||
conf = faacDecGetCurrentConfiguration (faad->handle);
|
conf = faacDecGetCurrentConfiguration (faad->handle);
|
||||||
conf->defObjectType = LC;
|
conf->defObjectType = LC;
|
||||||
//conf->dontUpSampleImplicitSBR = 1;
|
/* conf->dontUpSampleImplicitSBR = 1; */
|
||||||
faacDecSetConfiguration (faad->handle, conf);
|
conf->outputFormat = FAAD_FMT_16BIT;
|
||||||
|
if (faacDecSetConfiguration (faad->handle, conf) == 0)
|
||||||
|
return GST_STATE_FAILURE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case GST_STATE_PAUSED_TO_READY:
|
case GST_STATE_PAUSED_TO_READY:
|
||||||
faad->samplerate = -1;
|
faad->samplerate = -1;
|
||||||
faad->channels = -1;
|
faad->channels = -1;
|
||||||
@ -802,6 +912,7 @@ gst_faad_change_state (GstElement * element)
|
|||||||
faad->init = FALSE;
|
faad->init = FALSE;
|
||||||
g_free (faad->channel_positions);
|
g_free (faad->channel_positions);
|
||||||
faad->channel_positions = NULL;
|
faad->channel_positions = NULL;
|
||||||
|
faad->next_ts = 0;
|
||||||
break;
|
break;
|
||||||
case GST_STATE_READY_TO_NULL:
|
case GST_STATE_READY_TO_NULL:
|
||||||
faacDecClose (faad->handle);
|
faacDecClose (faad->handle);
|
||||||
|
@ -39,16 +39,14 @@ G_BEGIN_DECLS
|
|||||||
typedef struct _GstFaad {
|
typedef struct _GstFaad {
|
||||||
GstElement element;
|
GstElement element;
|
||||||
|
|
||||||
/* pads */
|
GstPad *srcpad;
|
||||||
GstPad *srcpad, *sinkpad;
|
GstPad *sinkpad;
|
||||||
|
|
||||||
/* cache for latest MPEG-frame */
|
guint samplerate; /* sample rate of the last MPEG frame */
|
||||||
gint samplerate,
|
guint channels; /* number of channels of the last frame */
|
||||||
channels,
|
guint bps; /* bytes per sample */
|
||||||
bps;
|
|
||||||
|
|
||||||
/* used to keep input leftovers */
|
GstBuffer *tempbuf; /* used to keep input leftovers */
|
||||||
GstBuffer *tempbuf;
|
|
||||||
|
|
||||||
/* FAAD object */
|
/* FAAD object */
|
||||||
faacDecHandle handle;
|
faacDecHandle handle;
|
||||||
@ -58,6 +56,10 @@ typedef struct _GstFaad {
|
|||||||
guchar *channel_positions;
|
guchar *channel_positions;
|
||||||
gboolean need_channel_setup;
|
gboolean need_channel_setup;
|
||||||
gboolean packetised; /* We must differentiate between raw and packetised streams */
|
gboolean packetised; /* We must differentiate between raw and packetised streams */
|
||||||
|
|
||||||
|
guint64 next_ts; /* timestamp of next buffer */
|
||||||
|
guint64 bytes_in; /* bytes received */
|
||||||
|
guint64 sum_dur_out; /* sum of durations of decoded buffers we sent out */
|
||||||
} GstFaad;
|
} GstFaad;
|
||||||
|
|
||||||
typedef struct _GstFaadClass {
|
typedef struct _GstFaadClass {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user