Fix regressions from using gstriff library

Original commit message from CVS:
Fix regressions from using gstriff library
This commit is contained in:
David Schleef 2003-08-13 06:41:09 +00:00
parent b3a95010c1
commit b957481334
3 changed files with 105 additions and 92 deletions

View file

@ -6,4 +6,4 @@ libgstwavparse_la_CFLAGS = $(GST_CFLAGS)
libgstwavparse_la_LIBADD =
libgstwavparse_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
noinst_HEADERS = gstwavparse.h gstriff.h
noinst_HEADERS = gstwavparse.h

View file

@ -224,142 +224,20 @@ wav_type_find (GstBuffer *buf, gpointer private)
return gst_caps_new ("wav_type_find", "audio/x-wav", NULL);
}
static void
gst_wavparse_chain (GstPad *pad, GstBuffer *buf)
static void wav_new_chunk_callback(GstRiffChunk *chunk, gpointer data)
{
GstWavParse *wavparse;
gboolean buffer_riffed = FALSE; /* so we don't parse twice */
gulong size;
g_return_if_fail (pad != NULL);
g_return_if_fail (GST_IS_PAD (pad));
g_return_if_fail (buf != NULL);
g_return_if_fail (GST_BUFFER_DATA (buf) != NULL);
wavparse = GST_WAVPARSE (data);
wavparse = GST_WAVPARSE (gst_pad_get_parent (pad));
GST_DEBUG ("gst_wavparse_chain: got buffer in '%s'",
gst_object_get_name (GST_OBJECT (wavparse)));
GST_DEBUG("new tag " GST_FOURCC_FORMAT "\n", GST_FOURCC_ARGS(chunk->id));
size = GST_BUFFER_SIZE (buf);
/* walk through the states in priority order */
/* we're in the data region */
if (wavparse->state == GST_WAVPARSE_DATA) {
GstFormat format;
guint64 maxsize;
/* we can't go beyond the max length */
maxsize = wavparse->riff_nextlikely - GST_BUFFER_OFFSET (buf);
if (maxsize == 0) {
return;
} else if (maxsize < size) {
/* if we're expected to see a new chunk in this buffer */
GstBuffer *newbuf;
newbuf = gst_buffer_create_sub (buf, 0, maxsize);
gst_buffer_unref (buf);
buf = newbuf;
size = maxsize;
wavparse->state = GST_WAVPARSE_OTHER;
/* I suppose we could signal an EOF at this point, but that may be
premature. We've stopped data flow, that's the main thing. */
}
if (GST_PAD_IS_USABLE (wavparse->srcpad)) {
format = GST_FORMAT_TIME;
gst_pad_convert (wavparse->srcpad,
GST_FORMAT_BYTES,
wavparse->offset,
&format,
&GST_BUFFER_TIMESTAMP (buf));
if (wavparse->need_discont) {
if (buf && GST_BUFFER_TIMESTAMP_IS_VALID (buf)) {
gst_pad_push (wavparse->srcpad,
GST_BUFFER (gst_event_new_discontinuous (FALSE,
GST_FORMAT_BYTES, wavparse->offset,
GST_FORMAT_TIME, GST_BUFFER_TIMESTAMP (buf),
NULL)));
} else {
gst_pad_push (wavparse->srcpad,
GST_BUFFER (gst_event_new_discontinuous (FALSE,
GST_FORMAT_BYTES, wavparse->offset,
NULL)));
}
wavparse->need_discont = FALSE;
}
gst_pad_push (wavparse->srcpad, buf);
} else {
gst_buffer_unref (buf);
}
wavparse->offset += size;
return;
}
if (wavparse->state == GST_WAVPARSE_OTHER) {
GST_DEBUG ("we're in unknown territory here, not passing on");
return;
}
/* here we deal with parsing out the primary state */
/* these are sequenced such that in the normal case each (RIFF/WAVE,
fmt, data) will fire in sequence, as they should */
/* we're in null state now, look for the RIFF header, start parsing */
if (wavparse->state == GST_WAVPARSE_UNKNOWN) {
gint retval;
GST_DEBUG ("GstWavParse: checking for RIFF format");
/* create a new RIFF parser */
wavparse->riff = gst_riff_parser_new (NULL, NULL);
/* give it the current buffer to start parsing */
retval = gst_riff_parser_next_buffer (wavparse->riff, buf, 0);
buffer_riffed = TRUE;
if (retval < 0) {
GST_DEBUG ("sorry, isn't RIFF");
return;
}
/* this has to be a file of form WAVE for us to deal with it */
if (wavparse->riff->form != gst_riff_fourcc_to_id ("WAVE")) {
GST_DEBUG ("sorry, isn't WAVE");
return;
}
/* at this point we're waiting for the 'fmt ' chunk */
wavparse->state = GST_WAVPARSE_CHUNK_FMT;
}
/* we're now looking for the 'fmt ' chunk to get the audio info */
if (wavparse->state == GST_WAVPARSE_CHUNK_FMT) {
GstRiffChunk *fmt;
if(chunk->id == GST_RIFF_TAG_fmt){
GstWavParseFormat *format;
GST_DEBUG ("GstWavParse: looking for fmt chunk");
/* there's a good possibility we may not have parsed this buffer */
if (buffer_riffed == FALSE) {
gst_riff_parser_next_buffer (wavparse->riff, buf, GST_BUFFER_OFFSET (buf));
buffer_riffed = TRUE;
}
/* see if the fmt chunk is available yet */
fmt = gst_riff_parser_get_chunk (wavparse->riff, GST_RIFF_TAG_fmt);
/* if we've got something, deal with it */
if (fmt != NULL) {
GstCaps *caps = NULL;
/* we can gather format information now */
format = (GstWavParseFormat *)((guchar *) GST_BUFFER_DATA (buf) + fmt->offset);
format = (GstWavParseFormat *)((guchar *) GST_BUFFER_DATA (wavparse->buf) + chunk->offset);
wavparse->bps = GUINT16_FROM_LE(format->wBlockAlign);
wavparse->rate = GUINT32_FROM_LE(format->dwSamplesPerSec);
@ -428,16 +306,148 @@ gst_wavparse_chain (GstPad *pad, GstBuffer *buf)
/* we're now looking for the data chunk */
wavparse->state = GST_WAVPARSE_CHUNK_DATA;
} else {
/* otherwise we just sort of give up for this buffer */
}
}
static void
gst_wavparse_chain (GstPad *pad, GstBuffer *buf)
{
GstWavParse *wavparse;
gboolean buffer_riffed = FALSE; /* so we don't parse twice */
gulong size;
g_return_if_fail (pad != NULL);
g_return_if_fail (GST_IS_PAD (pad));
g_return_if_fail (buf != NULL);
g_return_if_fail (GST_BUFFER_DATA (buf) != NULL);
wavparse = GST_WAVPARSE (gst_pad_get_parent (pad));
GST_DEBUG ("gst_wavparse_chain: got buffer in '%s'",
gst_object_get_name (GST_OBJECT (wavparse)));
size = GST_BUFFER_SIZE (buf);
wavparse->buf = buf;
/* walk through the states in priority order */
/* we're in the data region */
if (wavparse->state == GST_WAVPARSE_DATA) {
GstFormat format;
guint64 maxsize;
/* we can't go beyond the max length */
maxsize = wavparse->riff_nextlikely - GST_BUFFER_OFFSET (buf);
if (maxsize == 0) {
return;
} else if (maxsize < size) {
/* if we're expected to see a new chunk in this buffer */
GstBuffer *newbuf;
newbuf = gst_buffer_create_sub (buf, 0, maxsize);
gst_buffer_unref (buf);
buf = newbuf;
size = maxsize;
wavparse->state = GST_WAVPARSE_OTHER;
/* I suppose we could signal an EOF at this point, but that may be
premature. We've stopped data flow, that's the main thing. */
}
if (GST_PAD_IS_USABLE (wavparse->srcpad)) {
format = GST_FORMAT_TIME;
gst_pad_convert (wavparse->srcpad,
GST_FORMAT_BYTES,
wavparse->offset,
&format,
&GST_BUFFER_TIMESTAMP (buf));
if (wavparse->need_discont) {
if (buf && GST_BUFFER_TIMESTAMP_IS_VALID (buf)) {
gst_pad_push (wavparse->srcpad,
GST_BUFFER (gst_event_new_discontinuous (FALSE,
GST_FORMAT_BYTES, wavparse->offset,
GST_FORMAT_TIME, GST_BUFFER_TIMESTAMP (buf),
NULL)));
} else {
gst_pad_push (wavparse->srcpad,
GST_BUFFER (gst_event_new_discontinuous (FALSE,
GST_FORMAT_BYTES, wavparse->offset,
NULL)));
}
wavparse->need_discont = FALSE;
}
gst_pad_push (wavparse->srcpad, buf);
} else {
gst_buffer_unref (buf);
}
wavparse->offset += size;
return;
}
if (wavparse->state == GST_WAVPARSE_OTHER) {
GST_DEBUG ("we're in unknown territory here, not passing on");
gst_buffer_unref(buf);
return;
}
/* here we deal with parsing out the primary state */
/* these are sequenced such that in the normal case each (RIFF/WAVE,
fmt, data) will fire in sequence, as they should */
/* we're in null state now, look for the RIFF header, start parsing */
if (wavparse->state == GST_WAVPARSE_UNKNOWN) {
gint retval;
GST_DEBUG ("GstWavParse: checking for RIFF format");
/* create a new RIFF parser */
wavparse->riff = gst_riff_parser_new (wav_new_chunk_callback, wavparse);
/* give it the current buffer to start parsing */
retval = gst_riff_parser_next_buffer (wavparse->riff, buf, 0);
buffer_riffed = TRUE;
if (retval < 0) {
GST_DEBUG ("sorry, isn't RIFF");
gst_buffer_unref(buf);
return;
}
/* this has to be a file of form WAVE for us to deal with it */
if (wavparse->riff->form != gst_riff_fourcc_to_id ("WAVE")) {
GST_DEBUG ("sorry, isn't WAVE");
gst_buffer_unref(buf);
return;
}
/* at this point we're waiting for the 'fmt ' chunk */
/* careful, the state may have changed in the callback */
if (wavparse->state == GST_WAVPARSE_UNKNOWN){
wavparse->state = GST_WAVPARSE_CHUNK_FMT;
}
}
/* we're now looking for the 'fmt ' chunk to get the audio info */
if (wavparse->state == GST_WAVPARSE_CHUNK_FMT) {
GST_DEBUG ("GstWavParse: looking for fmt chunk");
/* there's a good possibility we may not have parsed this buffer */
if (buffer_riffed == FALSE) {
gst_riff_parser_next_buffer (wavparse->riff, buf, GST_BUFFER_OFFSET (buf));
buffer_riffed = TRUE;
}
return;
}
/* now we look for the data chunk */
if (wavparse->state == GST_WAVPARSE_CHUNK_DATA) {
GstBuffer *newbuf;
GstRiffChunk *datachunk;
GST_DEBUG ("GstWavParse: looking for data chunk");
@ -452,6 +462,7 @@ gst_wavparse_chain (GstPad *pad, GstBuffer *buf)
if (datachunk != NULL) {
gulong subsize;
GstBuffer *newbuf;
GST_DEBUG ("data begins at %ld", datachunk->offset);
@ -481,12 +492,12 @@ gst_wavparse_chain (GstPad *pad, GstBuffer *buf)
/* however, we may be expecting another chunk at some point */
wavparse->riff_nextlikely = gst_riff_parser_get_nextlikely (wavparse->riff);
} else {
/* otherwise we just sort of give up for this buffer */
gst_buffer_unref (buf);
return;
}
}
gst_buffer_unref (buf);
}
/* convert and query stuff */
@ -705,7 +716,7 @@ plugin_init (GModule *module, GstPlugin *plugin)
GstElementFactory *factory;
GstTypeFactory *type;
if(gst_library_load("gstriff") == FALSE){
if(!gst_library_load("gstriff")){
return FALSE;
}

View file

@ -81,6 +81,8 @@ struct _GstWavParse {
gint64 offset;
gint64 datastart;
gboolean need_discont;
GstBuffer *buf;
};
struct _GstWavParseClass {