Use a chain function instead of a loop monkeyenc needs audio raw caps now

Original commit message from CVS:
Use a chain function instead of a loop
monkeyenc needs audio raw caps now
This commit is contained in:
Jeremy Simon 2003-03-13 21:37:11 +00:00
parent 5f837b2017
commit af42d059d6
4 changed files with 53 additions and 74 deletions

View file

@ -18,8 +18,5 @@ noinst_HEADERS = gstmonkeyaudio.h gstmonkeydec.h monkey_io.h gstmonkeyenc.h
# I appreciate any help into fixing this mess definitively # I appreciate any help into fixing this mess definitively
# I suspect a libtool bug, because in the end it doesn't even *use* the .c # I suspect a libtool bug, because in the end it doesn't even *use* the .c
# file; my libtool version when seeing this bug was 1.4.2 # file; my libtool version when seeing this bug was 1.4.2
#gstmonkeyaudio.c: gstmonkeyaudio.cc gstmonkeyaudio.c: gstmonkeyaudio.cc
# cp $(srcdir)/gstmonkeyaudio.cc gstmonkeyaudio.c cp $(srcdir)/gstmonkeyaudio.cc gstmonkeyaudio.c
#monkeyaudio_types.c: monkeyaudio_types.cc
# cp $(srcdir)/monkeyaudio_types.cc monkeyaudio_types.c

View file

@ -122,7 +122,7 @@ plugin_init (GModule * module, GstPlugin * plugin)
/* register sink pads */ /* register sink pads */
monkeyenc_sink_template = gst_pad_template_new ("sink", GST_PAD_SINK, monkeyenc_sink_template = gst_pad_template_new ("sink", GST_PAD_SINK,
GST_PAD_ALWAYS, GST_PAD_ALWAYS,
wav_caps, NULL); raw_caps, NULL);
gst_element_factory_add_pad_template (monkey_enc, monkeyenc_sink_template); gst_element_factory_add_pad_template (monkey_enc, monkeyenc_sink_template);

View file

@ -45,12 +45,15 @@ enum
}; };
static void gst_monkeyenc_class_init (GstMonkeyEncClass *klass); static void gst_monkeyenc_class_init (GstMonkeyEncClass *klass);
static void gst_monkeyenc_init (GstMonkeyEnc *monkeyenc); static void gst_monkeyenc_init (GstMonkeyEnc *monkeyenc);
static void gst_monkeyenc_loop (GstElement *element); static void gst_monkeyenc_chain (GstPad *pad, GstBuffer *buffer);
static void gst_monkeyenc_handle_event (GstPad *pad, GstBuffer *buffer);
static GstPadLinkReturn
gst_monkeyenc_sinklink (GstPad *pad, GstCaps *caps);
static GstElementStateReturn static GstElementStateReturn
gst_monkeyenc_change_state (GstElement *element); gst_monkeyenc_change_state (GstElement *element);
static GstElementClass *parent_class = NULL; static GstElementClass *parent_class = NULL;
@ -90,7 +93,7 @@ gst_monkeyenc_class_init (GstMonkeyEncClass *klass)
parent_class = GST_ELEMENT_CLASS( g_type_class_ref(GST_TYPE_ELEMENT)); parent_class = GST_ELEMENT_CLASS( g_type_class_ref(GST_TYPE_ELEMENT));
} }
/*
static GstPadLinkReturn static GstPadLinkReturn
gst_monkeyenc_sinklink (GstPad *pad, GstCaps *caps) gst_monkeyenc_sinklink (GstPad *pad, GstCaps *caps)
{ {
@ -105,10 +108,9 @@ gst_monkeyenc_sinklink (GstPad *pad, GstCaps *caps)
gst_caps_get_int (caps, "rate", &monkeyenc->rate); gst_caps_get_int (caps, "rate", &monkeyenc->rate);
gst_caps_get_int (caps, "depth", &monkeyenc->depth); gst_caps_get_int (caps, "depth", &monkeyenc->depth);
monkeyenc->linked = TRUE;
return GST_PAD_LINK_OK; return GST_PAD_LINK_OK;
}*/ }
static void static void
gst_monkeyenc_init (GstMonkeyEnc * monkeyenc) gst_monkeyenc_init (GstMonkeyEnc * monkeyenc)
@ -119,54 +121,55 @@ gst_monkeyenc_init (GstMonkeyEnc * monkeyenc)
monkeyenc->srcpad = gst_pad_new_from_template (monkeyenc_src_template, "src"); monkeyenc->srcpad = gst_pad_new_from_template (monkeyenc_src_template, "src");
gst_element_add_pad (GST_ELEMENT (monkeyenc), monkeyenc->srcpad); gst_element_add_pad (GST_ELEMENT (monkeyenc), monkeyenc->srcpad);
/*gst_pad_set_link_function (monkeyenc->sinkpad, gst_monkeyenc_sinklink);*/ gst_pad_set_link_function (monkeyenc->sinkpad, gst_monkeyenc_sinklink);
gst_element_set_loop_function (GST_ELEMENT (monkeyenc), gst_monkeyenc_loop); gst_pad_set_chain_function (monkeyenc->sinkpad, gst_monkeyenc_chain);
monkeyenc->linked = FALSE;
} }
static void static void
gst_monkeyenc_loop (GstElement *element) gst_monkeyenc_handle_event (GstPad *pad, GstBuffer *buffer)
{
GstEvent *event = GST_EVENT (buffer);
switch (GST_EVENT_TYPE (event))
{
default:
gst_pad_event_default (pad, event);
break;
}
return;
}
static void
gst_monkeyenc_chain (GstPad *pad, GstBuffer *buffer)
{ {
GstMonkeyEnc *monkeyenc; GstMonkeyEnc *monkeyenc;
gint retval, size; gint retval;
g_return_if_fail (element != NULL); monkeyenc = GST_MONKEYENC (gst_pad_get_parent (pad));
g_return_if_fail (GST_IS_MONKEYENC (element)); g_return_if_fail (GST_IS_MONKEYENC (monkeyenc));
monkeyenc = GST_MONKEYENC (element); /* handle events */
if (GST_IS_EVENT (buffer))
{
gst_monkeyenc_handle_event (pad, buffer);
return;
}
if (!GST_PAD_IS_USABLE (monkeyenc->srcpad)) if (!GST_PAD_IS_USABLE (monkeyenc->srcpad))
return; return;
if (monkeyenc->init) if (monkeyenc->init)
{ {
unsigned char *wav_header;
monkeyenc->src_io = new srcpad_CIO; monkeyenc->src_io = new srcpad_CIO;
monkeyenc->src_io->Open(""); monkeyenc->src_io->Open("");
monkeyenc->src_io->srcpad = monkeyenc->srcpad; monkeyenc->src_io->srcpad = monkeyenc->srcpad;
monkeyenc->sink_io = new sinkpad_CIO; FillWaveFormatEx(&monkeyenc->waveformatex, monkeyenc->rate, monkeyenc->depth, monkeyenc->channels);
monkeyenc->sink_io->sinkpad = monkeyenc->sinkpad;
monkeyenc->sink_io->bs = gst_bytestream_new (monkeyenc->sinkpad);
if (monkeyenc->sink_io->bs == NULL)
{
gst_element_error(element, "Failed to initiliaze bytestream from sinkpad");
return;
}
monkeyenc->inputsrc = new CWAVInputSource (monkeyenc->sink_io, &(monkeyenc->waveformatex), &(monkeyenc->total_blocks),
&(monkeyenc->header_size), &(monkeyenc->terminating), &retval);
monkeyenc->audiobytes = monkeyenc->total_blocks * monkeyenc->waveformatex.nBlockAlign;
monkeyenc->audiobytesleft = monkeyenc->audiobytes;
wav_header = (unsigned char*) g_malloc0 (monkeyenc->header_size);
retval = monkeyenc->inputsrc->GetHeaderData (wav_header);
monkeyenc->compress_engine = CreateIAPECompress (&retval); monkeyenc->compress_engine = CreateIAPECompress (&retval);
if (monkeyenc->compress_engine == NULL) if (monkeyenc->compress_engine == NULL)
@ -175,30 +178,15 @@ gst_monkeyenc_loop (GstElement *element)
return; return;
} }
retval = monkeyenc->compress_engine->StartEx (monkeyenc->src_io, &(monkeyenc->waveformatex), monkeyenc->audiobytes, retval = monkeyenc->compress_engine->StartEx (monkeyenc->src_io, &(monkeyenc->waveformatex), MAX_AUDIO_BYTES_UNKNOWN,
COMPRESSION_LEVEL_NORMAL, wav_header, monkeyenc->header_size); COMPRESSION_LEVEL_NORMAL, NULL, CREATE_WAV_HEADER_ON_DECOMPRESSION);
monkeyenc->init = FALSE; monkeyenc->init = FALSE;
} }
retval = monkeyenc->compress_engine->AddDataFromInputSource (monkeyenc->inputsrc, monkeyenc->audiobytesleft, &size); retval = monkeyenc->compress_engine->AddData ((unsigned char *)GST_BUFFER_DATA (buffer), GST_BUFFER_SIZE (buffer));
monkeyenc->audiobytesleft -= size; monkeyenc->audiobytesleft -= GST_BUFFER_SIZE (buffer);
}
if (monkeyenc->audiobytesleft <= 0)
{
unsigned char *terminating_data;
terminating_data = (unsigned char *) g_malloc0 (monkeyenc->terminating);
retval = monkeyenc->inputsrc->GetTerminatingData (terminating_data);
retval = monkeyenc->compress_engine->Finish (terminating_data, monkeyenc->terminating, monkeyenc->terminating);
monkeyenc->sink_io->SetEOF();
monkeyenc->src_io->SetEOF();
monkeyenc->sink_io->Close();
gst_element_set_eos (element);
}
}
static GstElementStateReturn static GstElementStateReturn
@ -218,6 +206,7 @@ gst_monkeyenc_change_state (GstElement *element)
/* do something to get out of the chain function faster */ /* do something to get out of the chain function faster */
break; break;
case GST_STATE_PLAYING_TO_PAUSED: case GST_STATE_PLAYING_TO_PAUSED:
monkeyenc->compress_engine->Finish (NULL, 0, 0);
break; break;
case GST_STATE_PAUSED_TO_READY: case GST_STATE_PAUSED_TO_READY:
break; break;

View file

@ -58,20 +58,13 @@ struct _GstMonkeyEnc
gint channels; gint channels;
gint rate; gint rate;
gint depth; gint depth;
gboolean linked;
gint total_blocks; gint total_blocks;
gint header_size;
gint terminating;
guint64 audiobytes; guint64 audiobytes;
guint64 audiobytesleft; guint64 audiobytesleft;
IAPECompress *compress_engine; IAPECompress *compress_engine;
WAVEFORMATEX waveformatex; WAVEFORMATEX waveformatex;
WAVE_HEADER pWAVHeader;
srcpad_CIO *src_io; srcpad_CIO *src_io;
sinkpad_CIO *sink_io;
CWAVInputSource *inputsrc;
}; };
struct _GstMonkeyEncClass struct _GstMonkeyEncClass