+2004-12-03 Ronald S. Bultje <rbultje@ronald.bitfreak.net>
+
+ * gst/matroska/ebml-read.c: (gst_ebml_read_class_init),
+ (gst_ebml_read_init), (gst_ebml_read_use_event),
+ (gst_ebml_read_element_id), (gst_ebml_peek_id),
+ (gst_ebml_read_seek), (gst_ebml_read_skip),
+ (gst_ebml_read_reserve), (gst_ebml_read_buffer),
+ (gst_ebml_read_master):
+ * gst/matroska/ebml-read.h:
+ * gst/matroska/matroska-demux.c:
+ (gst_matroska_demux_parse_contents),
+ (gst_matroska_demux_loop_stream), (gst_matroska_demux_audio_caps):
+ Disgustingly evil hack for working around INTERRUPT events and
+ their extremely annoying habit of being a pain in the ass. We
+ simply peek a cluster before reading any of it.
+
2004-12-03 Ronald S. Bultje <rbultje@ronald.bitfreak.net>
* ext/musepack/gstmusepackdec.cpp:
#include "ebml-read.h"
#include "ebml-ids.h"
+GST_DEBUG_CATEGORY_STATIC (ebmlread_debug);
+#define GST_CAT_DEFAULT ebmlread_debug
+
enum
{
/* FILL ME */
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
+ GST_DEBUG_CATEGORY_INIT (ebmlread_debug, "ebmlread",
+ 0, "EBML stream helper class");
+
gstelement_class->change_state = gst_ebml_read_change_state;
}
ebml->sinkpad = NULL;
ebml->bs = NULL;
ebml->level = NULL;
+ ebml->id_cache = 0;
}
static GstElementStateReturn
return FALSE;
}
+ GST_LOG ("Received event of type %d", GST_EVENT_TYPE (event));
+
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_EOS:
gst_pad_event_default (ebml->sinkpad, event);
case GST_EVENT_DISCONTINUOUS:
GST_WARNING_OBJECT (ebml, "Unexpected discont - might lose sync");
- gst_pad_event_default (ebml->sinkpad, event);
+ gst_event_unref (event);
return TRUE;
case GST_EVENT_FLUSH:
gint len_mask = 0x80, read = 1, n = 1;
guint32 total;
+ if (ebml->id_cache) {
+ *id = ebml->id_cache;
+ if (level_up)
+ *level_up = 0;
+
+ return 0;
+ }
+
while (gst_bytestream_peek_bytes (ebml->bs, &data, 1) != 1) {
if (!gst_ebml_read_handle_event (ebml))
return -1;
while (n < read)
total = (total << 8) | data[n++];
- *id = total;
+ *id = ebml->id_cache = total;
/* level */
if (level_up)
*level_up = gst_ebml_read_element_level_up (ebml);
- return read;
+ gst_bytestream_flush_fast (ebml->bs, read);
+
+ return 0;
}
/*
g_assert (level_up);
- if (gst_ebml_read_element_id (ebml, &id, level_up) <= 0)
+ if (gst_ebml_read_element_id (ebml, &id, level_up) < 0)
return 0;
return id;
}
}
+ /* at the end of a seek, we have no cached ID anymore */
+ ebml->id_cache = 0;
+
return event;
}
return FALSE;
}
- if (remaining >= length)
- return gst_bytestream_flush (ebml->bs, length);
+ if (remaining >= length) {
+ ebml->id_cache = 0;
+ gst_bytestream_flush_fast (ebml->bs, length);
+
+ return TRUE;
+ }
if (!(event = gst_ebml_read_seek (ebml,
gst_bytestream_tell (ebml->bs) + length))) {
}
gst_event_unref (event);
+ ebml->id_cache = 0;
+
+ return TRUE;
+}
+
+/*
+ * Make sure there's one whole next chunk available
+ * for uninterrupted reading.
+ */
+
+gboolean
+gst_ebml_read_reserve (GstEbmlRead * ebml)
+{
+ guint64 length;
+ gint bytes;
+ guint8 *data;
+ guint32 id;
+
+ /* make sure the ID is cached */
+ if (gst_ebml_read_element_id (ebml, &id, NULL) < 0)
+ return FALSE;
+
+ /* now we can peek the length */
+ if ((bytes = gst_ebml_read_element_length (ebml, &length)) < 0)
+ return FALSE;
+ length += bytes;
+
+ /* now check if we have that amount available */
+ while (gst_bytestream_peek_bytes (ebml->bs, &data, length) != length) {
+ if (!gst_ebml_read_handle_event (ebml))
+ return FALSE;
+ }
+ /* yes, available */
return TRUE;
}
if ((bytes = gst_ebml_read_element_length (ebml, &length)) < 0)
return FALSE;
gst_bytestream_flush_fast (ebml->bs, bytes);
+ ebml->id_cache = 0;
return ((*buf = gst_ebml_read_element_data (ebml, length)) != NULL);
}
level->start = gst_bytestream_tell (ebml->bs);
level->length = length;
ebml->level = g_list_append (ebml->level, level);
+ ebml->id_cache = 0;
return TRUE;
}
case GST_MATROSKA_ID_TAGS:{
guint level_up = demux->level_up;
guint64 before_pos, length;
+ guint32 id_cache = ebml->id_cache;
GstEbmlLevel *level;
GstEvent *event;
return FALSE;
gst_event_unref (event);
demux->level_up = level_up;
+ ebml->id_cache = id_cache;
break;
}
demux->state = GST_MATROSKA_DEMUX_STATE_DATA;
gst_element_no_more_pads (GST_ELEMENT (demux));
} else {
+ if (!gst_ebml_read_reserve (ebml)) {
+ res = FALSE;
+ break;
+ }
if (!gst_ebml_read_master (ebml, &id)) {
res = FALSE;
break;
}
} else {
GST_WARNING ("Unknown codec '%s', cannot build Caps", codec_id);
- g_print ("Codec=%s\n", codec_id);
return NULL;
}