summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRonald S. Bultje <rbultje@ronald.bitfreak.net>2005-02-05 16:28:31 +0000
committerRonald S. Bultje <rbultje@ronald.bitfreak.net>2005-02-05 16:28:31 +0000
commit4a1a8872625b855d6bf909e1c493625c1ee78c00 (patch)
tree82aff574c9ad35a106d582ad43a6e4de0580169a
parent204e36d8724047fe9f87a5041c7c50fd1e5027d3 (diff)
downloadgstreamer-plugins-bad-4a1a8872625b855d6bf909e1c493625c1ee78c00.tar.gz
examples/seeking/seek.c: Add AVI pipeline.
Original commit message from CVS: * examples/seeking/seek.c: (make_avi_msmpeg4v3_mp3_pipeline): Add AVI pipeline. * gst-libs/gst/riff/riff-media.c: (gst_riff_create_video_caps), (gst_riff_create_audio_caps), (gst_riff_create_iavs_caps), (gst_riff_create_video_template_caps), (gst_riff_create_audio_template_caps), (gst_riff_create_iavs_template_caps): * gst-libs/gst/riff/riff-media.h: Remove obsolete non-data functions, make data functions the default. * gst-libs/gst/riff/riff-read.c: (gst_riff_read_chunk), (gst_riff_parse_chunk), (gst_riff_parse_file_header), (gst_riff_parse_strh), (gst_riff_parse_strf_vids), (gst_riff_parse_strf_auds), (gst_riff_parse_strf_iavs), (gst_riff_parse_info): * gst-libs/gst/riff/riff-read.h: * gst-libs/gst/riff/riff.c: (plugin_init): Change from bytestream-wrapping to pure RIFF parsing (can be used chain-based if someone would want that). Add gtk-doc comments. * gst/avi/Makefile.am: * gst/avi/gstavi.c: (plugin_init): Disable mux for now. * gst/avi/gstavidemux.c: (gst_avi_demux_get_type), (gst_avi_demux_class_init), (gst_avi_demux_init), (gst_avi_demux_reset), (gst_avi_demux_src_convert), (gst_avi_demux_handle_src_query), (gst_avi_demux_handle_src_event), (gst_avi_demux_parse_file_header), (gst_avi_demux_stream_init), (gst_avi_demux_parse_avih), (gst_avi_demux_parse_superindex), (gst_avi_demux_parse_subindex), (gst_avi_demux_read_subindexes), (gst_avi_demux_parse_stream), (gst_avi_demux_parse_odml), (gst_avi_demux_parse_index), (gst_avi_demux_stream_index), (gst_avi_demux_stream_scan), (gst_avi_demux_massage_index), (gst_avi_demux_stream_header), (gst_avi_demux_handle_seek), (gst_avi_demux_process_next_entry), (gst_avi_demux_stream_data), (gst_avi_demux_loop), (gst_avi_demux_sink_activate): * gst/avi/gstavidemux.h: Port to changed RIFF API, port to 0.9, add locking. Add gtk-doc comments to some relevant functions. Seeking is weird, works otherwise. Some parts are still disabled.
-rw-r--r--ChangeLog42
-rw-r--r--examples/seeking/seek.c68
-rw-r--r--gst-libs/gst/riff/riff-media.c29
-rw-r--r--gst-libs/gst/riff/riff-media.h38
-rw-r--r--gst-libs/gst/riff/riff-read.c992
-rw-r--r--gst-libs/gst/riff/riff-read.h113
-rw-r--r--gst-libs/gst/riff/riff.c6
7 files changed, 492 insertions, 796 deletions
diff --git a/ChangeLog b/ChangeLog
index 3de8b2409..888c46e65 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,45 @@
+2005-02-05 Ronald S. Bultje <rbultje@ronald.bitfreak.net>
+
+ * examples/seeking/seek.c: (make_avi_msmpeg4v3_mp3_pipeline):
+ Add AVI pipeline.
+ * gst-libs/gst/riff/riff-media.c: (gst_riff_create_video_caps),
+ (gst_riff_create_audio_caps), (gst_riff_create_iavs_caps),
+ (gst_riff_create_video_template_caps),
+ (gst_riff_create_audio_template_caps),
+ (gst_riff_create_iavs_template_caps):
+ * gst-libs/gst/riff/riff-media.h:
+ Remove obsolete non-data functions, make data functions the
+ default.
+ * gst-libs/gst/riff/riff-read.c: (gst_riff_read_chunk),
+ (gst_riff_parse_chunk), (gst_riff_parse_file_header),
+ (gst_riff_parse_strh), (gst_riff_parse_strf_vids),
+ (gst_riff_parse_strf_auds), (gst_riff_parse_strf_iavs),
+ (gst_riff_parse_info):
+ * gst-libs/gst/riff/riff-read.h:
+ * gst-libs/gst/riff/riff.c: (plugin_init):
+ Change from bytestream-wrapping to pure RIFF parsing (can be used
+ chain-based if someone would want that). Add gtk-doc comments.
+ * gst/avi/Makefile.am:
+ * gst/avi/gstavi.c: (plugin_init):
+ Disable mux for now.
+ * gst/avi/gstavidemux.c: (gst_avi_demux_get_type),
+ (gst_avi_demux_class_init), (gst_avi_demux_init),
+ (gst_avi_demux_reset), (gst_avi_demux_src_convert),
+ (gst_avi_demux_handle_src_query), (gst_avi_demux_handle_src_event),
+ (gst_avi_demux_parse_file_header), (gst_avi_demux_stream_init),
+ (gst_avi_demux_parse_avih), (gst_avi_demux_parse_superindex),
+ (gst_avi_demux_parse_subindex), (gst_avi_demux_read_subindexes),
+ (gst_avi_demux_parse_stream), (gst_avi_demux_parse_odml),
+ (gst_avi_demux_parse_index), (gst_avi_demux_stream_index),
+ (gst_avi_demux_stream_scan), (gst_avi_demux_massage_index),
+ (gst_avi_demux_stream_header), (gst_avi_demux_handle_seek),
+ (gst_avi_demux_process_next_entry), (gst_avi_demux_stream_data),
+ (gst_avi_demux_loop), (gst_avi_demux_sink_activate):
+ * gst/avi/gstavidemux.h:
+ Port to changed RIFF API, port to 0.9, add locking. Add gtk-doc
+ comments to some relevant functions. Seeking is weird, works
+ otherwise. Some parts are still disabled.
+
2005-02-01 Ronald S. Bultje <rbultje@ronald.bitfreak.net>
* ext/gnomevfs/Makefile.am:
diff --git a/examples/seeking/seek.c b/examples/seeking/seek.c
index f171d0c1a..4ba2f34c6 100644
--- a/examples/seeking/seek.c
+++ b/examples/seeking/seek.c
@@ -20,7 +20,7 @@ static guint update_id;
static gulong changed_id;
//#define SOURCE "gnomevfssrc"
-#define SOURCE "filesrc"
+#define SOURCE "gnomevfssrc"
#define UPDATE_INTERVAL 500
@@ -422,6 +422,71 @@ make_vorbis_theora_pipeline (const gchar * location)
}
static GstElement *
+make_avi_msmpeg4v3_mp3_pipeline (const gchar * location)
+{
+ GstElement *pipeline, *audio_bin, *video_bin;
+ GstElement *src, *demux, *a_decoder, *a_convert, *v_decoder, *v_convert;
+ GstElement *audiosink, *videosink;
+ GstElement *a_queue, *v_queue;
+ GstPad *seekable;
+
+ pipeline = gst_pipeline_new ("app");
+
+ src = gst_element_factory_make_or_warn (SOURCE, "src");
+ g_object_set (G_OBJECT (src), "location", location, NULL);
+
+ demux = gst_element_factory_make_or_warn ("avidemux", "demux");
+
+ gst_bin_add (GST_BIN (pipeline), src);
+ gst_bin_add (GST_BIN (pipeline), demux);
+ gst_element_link (src, demux);
+
+ audio_bin = gst_bin_new ("a_decoder_bin");
+ a_queue = gst_element_factory_make_or_warn ("queue", "a_queue");
+ a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec");
+ a_convert = gst_element_factory_make_or_warn ("audioconvert", "a_convert");
+ audiosink = gst_element_factory_make_or_warn ("osssink", "a_sink");
+
+ gst_element_link (a_queue, a_decoder);
+ gst_element_link (a_decoder, a_convert);
+ gst_element_link (a_convert, audiosink);
+
+ gst_bin_add (GST_BIN (audio_bin), a_queue);
+ gst_bin_add (GST_BIN (audio_bin), a_decoder);
+ gst_bin_add (GST_BIN (audio_bin), a_convert);
+ gst_bin_add (GST_BIN (audio_bin), audiosink);
+
+ gst_bin_add (GST_BIN (pipeline), audio_bin);
+
+ setup_dynamic_link (demux, NULL, gst_element_get_pad (a_queue, "sink"), NULL);
+
+ video_bin = gst_bin_new ("v_decoder_bin");
+ v_queue = gst_element_factory_make_or_warn ("queue", "v_queue");
+ v_decoder = gst_element_factory_make_or_warn ("ffdec_msmpeg4", "v_dec");
+ v_convert =
+ gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_convert");
+ videosink = gst_element_factory_make_or_warn ("xvimagesink", "v_sink");
+ gst_element_link_many (v_queue, v_decoder, v_convert, videosink, NULL);
+
+ gst_bin_add (GST_BIN (video_bin), v_queue);
+ gst_bin_add (GST_BIN (video_bin), v_decoder);
+ gst_bin_add (GST_BIN (video_bin), v_convert);
+ gst_bin_add (GST_BIN (video_bin), videosink);
+
+ gst_bin_add (GST_BIN (pipeline), video_bin);
+
+ setup_dynamic_link (demux, NULL, gst_element_get_pad (v_queue, "sink"), NULL);
+
+ seekable = gst_element_get_pad (a_decoder, "src");
+ seekable_pads = g_list_prepend (seekable_pads, seekable);
+ rate_pads = g_list_prepend (rate_pads, seekable);
+ rate_pads =
+ g_list_prepend (rate_pads, gst_element_get_pad (a_decoder, "sink"));
+
+ return pipeline;
+}
+
+static GstElement *
make_mp3_pipeline (const gchar * location)
{
GstElement *pipeline;
@@ -1043,6 +1108,7 @@ static Pipeline pipelines[] = {
{"vorbis", make_vorbis_pipeline},
{"theora", make_theora_pipeline},
{"ogg/v/t", make_vorbis_theora_pipeline},
+ {"avi/msmpeg4v3/mp3", make_avi_msmpeg4v3_mp3_pipeline},
{"sid", make_sid_pipeline},
{"flac", make_flac_pipeline},
{"wav", make_wav_pipeline},
diff --git a/gst-libs/gst/riff/riff-media.c b/gst-libs/gst/riff/riff-media.c
index 4e4e22d3c..07513e88b 100644
--- a/gst-libs/gst/riff/riff-media.c
+++ b/gst-libs/gst/riff/riff-media.c
@@ -41,7 +41,7 @@
*/
GstCaps *
-gst_riff_create_video_caps_with_data (guint32 codec_fcc,
+gst_riff_create_video_caps (guint32 codec_fcc,
gst_riff_strh * strh, gst_riff_strf_vids * strf,
GstBuffer * strf_data, GstBuffer * strd_data, char **codec_name)
{
@@ -355,15 +355,7 @@ gst_riff_create_video_caps_with_data (guint32 codec_fcc,
}
GstCaps *
-gst_riff_create_video_caps (guint32 codec_fcc,
- gst_riff_strh * strh, gst_riff_strf_vids * strf, char **codec_name)
-{
- return gst_riff_create_video_caps_with_data (codec_fcc,
- strh, strf, NULL, NULL, codec_name);
-}
-
-GstCaps *
-gst_riff_create_audio_caps_with_data (guint16 codec_id,
+gst_riff_create_audio_caps (guint16 codec_id,
gst_riff_strh * strh, gst_riff_strf_auds * strf,
GstBuffer * strf_data, GstBuffer * strd_data, char **codec_name)
{
@@ -528,16 +520,9 @@ gst_riff_create_audio_caps_with_data (guint16 codec_id,
}
GstCaps *
-gst_riff_create_audio_caps (guint16 codec_id,
- gst_riff_strh * strh, gst_riff_strf_auds * strf, char **codec_name)
-{
- return gst_riff_create_audio_caps_with_data (codec_id,
- strh, strf, NULL, NULL, codec_name);
-}
-
-GstCaps *
gst_riff_create_iavs_caps (guint32 codec_fcc,
- gst_riff_strh * strh, gst_riff_strf_iavs * strf, char **codec_name)
+ gst_riff_strh * strh, gst_riff_strf_iavs * strf,
+ GstBuffer * init_data, GstBuffer * extra_data, char **codec_name)
{
GstCaps *caps = NULL;
@@ -600,7 +585,7 @@ gst_riff_create_video_template_caps (void)
caps = gst_caps_new_empty ();
for (i = 0; tags[i] != 0; i++) {
- one = gst_riff_create_video_caps (tags[i], NULL, NULL, NULL);
+ one = gst_riff_create_video_caps (tags[i], NULL, NULL, NULL, NULL, NULL);
if (one)
gst_caps_append (caps, one);
}
@@ -632,7 +617,7 @@ gst_riff_create_audio_template_caps (void)
caps = gst_caps_new_empty ();
for (i = 0; tags[i] != 0; i++) {
- one = gst_riff_create_audio_caps (tags[i], NULL, NULL, NULL);
+ one = gst_riff_create_audio_caps (tags[i], NULL, NULL, NULL, NULL, NULL);
if (one)
gst_caps_append (caps, one);
}
@@ -653,7 +638,7 @@ gst_riff_create_iavs_template_caps (void)
caps = gst_caps_new_empty ();
for (i = 0; tags[i] != 0; i++) {
- one = gst_riff_create_iavs_caps (tags[i], NULL, NULL, NULL);
+ one = gst_riff_create_iavs_caps (tags[i], NULL, NULL, NULL, NULL, NULL);
if (one)
gst_caps_append (caps, one);
}
diff --git a/gst-libs/gst/riff/riff-media.h b/gst-libs/gst/riff/riff-media.h
index 6ff3ea1be..3dea55f63 100644
--- a/gst-libs/gst/riff/riff-media.h
+++ b/gst-libs/gst/riff/riff-media.h
@@ -29,48 +29,36 @@
G_BEGIN_DECLS
/*
- * Create one caps. strh/strf can be NULL (for non-fixed caps).
+ * Create caos. strh/strf, strf/strd_data and codec_name can be NULL.
*/
-GstCaps *gst_riff_create_video_caps (guint32 codec_fcc,
- gst_riff_strh *strh,
- gst_riff_strf_vids *strf,
- char **codec_name);
-GstCaps *gst_riff_create_audio_caps (guint16 codec_id,
- gst_riff_strh *strh,
- gst_riff_strf_auds *strf,
- char **codec_name);
-GstCaps *gst_riff_create_iavs_caps (guint32 codec_fcc,
- gst_riff_strh *strh,
- gst_riff_strf_iavs *strf,
- char **codec_name);
-
-/*
- * Extended...
- */
-
-GstCaps *
-gst_riff_create_video_caps_with_data (guint32 codec_fcc,
+GstCaps * gst_riff_create_video_caps (guint32 codec_fcc,
gst_riff_strh * strh,
gst_riff_strf_vids * strf,
GstBuffer * strf_data,
GstBuffer * strd_data,
char ** codec_name);
-GstCaps *
-gst_riff_create_audio_caps_with_data (guint16 codec_id,
+GstCaps * gst_riff_create_audio_caps (guint16 codec_id,
gst_riff_strh * strh,
gst_riff_strf_auds * strf,
GstBuffer * strf_data,
GstBuffer * strd_data,
char ** codec_name);
+
+GstCaps * gst_riff_create_iavs_caps (guint32 codec_fcc,
+ gst_riff_strh * strh,
+ gst_riff_strf_iavs * strf,
+ GstBuffer * strf_data,
+ GstBuffer * strd_data,
+ char ** codec_name);
/*
* Create template caps (includes all known types).
*/
-GstCaps *gst_riff_create_video_template_caps (void);
-GstCaps *gst_riff_create_audio_template_caps (void);
-GstCaps *gst_riff_create_iavs_template_caps (void);
+GstCaps * gst_riff_create_video_template_caps (void);
+GstCaps * gst_riff_create_audio_template_caps (void);
+GstCaps * gst_riff_create_iavs_template_caps (void);
G_END_DECLS
diff --git a/gst-libs/gst/riff/riff-read.c b/gst-libs/gst/riff/riff-read.c
index 7c7e1d09d..f9c895764 100644
--- a/gst-libs/gst/riff/riff-read.c
+++ b/gst-libs/gst/riff/riff-read.c
@@ -26,462 +26,190 @@
#include <string.h>
#include <gst/gstutils.h>
-#include "riff-ids.h"
#include "riff-read.h"
-GST_DEBUG_CATEGORY_STATIC (riffread_debug);
-#define GST_CAT_DEFAULT riffread_debug
+GST_DEBUG_CATEGORY_EXTERN (riff_debug);
+#define GST_CAT_DEFAULT riff_debug
-enum
-{
- ARG_0,
- ARG_METADATA
- /* FILL ME */
-};
-
-static void gst_riff_read_class_init (GstRiffReadClass * klass);
-static void gst_riff_read_init (GstRiffRead * riff);
-
-static GstElementStateReturn gst_riff_read_change_state (GstElement * element);
-
-static GstElementClass *parent_class = NULL;
-
-GType
-gst_riff_read_get_type (void)
-{
- static GType gst_riff_read_type = 0;
-
- if (!gst_riff_read_type) {
- static const GTypeInfo gst_riff_read_info = {
- sizeof (GstRiffReadClass),
- NULL,
- NULL,
- (GClassInitFunc) gst_riff_read_class_init,
- NULL,
- NULL,
- sizeof (GstRiffRead),
- 0,
- (GInstanceInitFunc) gst_riff_read_init,
- };
-
- gst_riff_read_type =
- g_type_register_static (GST_TYPE_ELEMENT, "GstRiffRead",
- &gst_riff_read_info, 0);
- }
-
- return gst_riff_read_type;
-}
-
-static void
-gst_riff_read_class_init (GstRiffReadClass * klass)
-{
- GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
-
- parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
-
- GST_DEBUG_CATEGORY_INIT (riffread_debug, "riffread",
- 0, "RIFF stream helper class");
-
- gstelement_class->change_state = gst_riff_read_change_state;
-}
-
-static void
-gst_riff_read_init (GstRiffRead * riff)
-{
- riff->sinkpad = NULL;
- riff->bs = NULL;
- riff->level = NULL;
-}
-
-static GstElementStateReturn
-gst_riff_read_change_state (GstElement * element)
-{
- GstRiffRead *riff = GST_RIFF_READ (element);
-
- switch (GST_STATE_TRANSITION (element)) {
- case GST_STATE_READY_TO_PAUSED:
- if (!riff->sinkpad)
- return GST_STATE_FAILURE;
- riff->bs = gst_bytestream_new (riff->sinkpad);
- break;
- case GST_STATE_PAUSED_TO_READY:
- gst_bytestream_destroy (riff->bs);
- while (riff->level) {
- GstRiffLevel *level = riff->level->data;
-
- riff->level = g_list_remove (riff->level, level);
- g_free (level);
- }
- break;
- default:
- break;
- }
-
- if (GST_ELEMENT_CLASS (parent_class)->change_state)
- return GST_ELEMENT_CLASS (parent_class)->change_state (element);
-
- return GST_STATE_SUCCESS;
-}
-
-/*
- * Return: the amount of levels in the hierarchy that the
- * current element lies higher than the previous one.
- * The opposite isn't done - that's auto-done using list
- * element reading.
- */
-
-static guint
-gst_riff_read_element_level_up (GstRiffRead * riff)
-{
- guint num = 0;
- guint64 pos = gst_bytestream_tell (riff->bs);
-
- while (riff->level != NULL) {
- GList *last = g_list_last (riff->level);
- GstRiffLevel *level = last->data;
-
- if (pos >= level->start + level->length) {
- riff->level = g_list_remove (riff->level, level);
- g_free (level);
- num++;
- } else
- break;
- }
-
- return num;
-}
-
-/*
- * Event handler. Basic:
- * - EOS: end-of-file, stop processing, forward EOS.
- * - Interrupt: stop processing.
- * - Discont: shouldn't be handled here but in the seek handler. Error.
- * - Flush: ignore, since we check for flush flags manually. Don't forward.
- * - Others: warn, ignore.
- * Return value indicates whether to continue processing.
- */
-
-static gboolean
-gst_riff_read_use_event (GstRiffRead * riff, GstEvent * event)
-{
- if (!event) {
- GST_ELEMENT_ERROR (riff, RESOURCE, READ, (NULL), (NULL));
- return FALSE;
- }
-
- switch (GST_EVENT_TYPE (event)) {
- case GST_EVENT_EOS:
- gst_pad_event_default (riff->sinkpad, event);
- return FALSE;
-
- case GST_EVENT_DISCONTINUOUS:
- GST_WARNING_OBJECT (riff, "Unexpected discont - might lose sync");
- gst_event_unref (event);
- return TRUE;
-
- case GST_EVENT_FLUSH:
- gst_event_unref (event);
- return TRUE;
-
- default:
- GST_WARNING ("don't know how to handle event %d", GST_EVENT_TYPE (event));
- gst_pad_event_default (riff->sinkpad, event);
- return FALSE;
- }
-
- /* happy */
- g_assert_not_reached ();
- return FALSE;
-}
-
-static gboolean
-gst_riff_read_handle_event (GstRiffRead * riff)
-{
- GstEvent *event = NULL;
- guint32 remaining;
-
- gst_bytestream_get_status (riff->bs, &remaining, &event);
-
- return gst_riff_read_use_event (riff, event);
-}
-
-/*
- * Read the next tag plus length (may be NULL). Return
- * TRUE on success or FALSE on failure.
- */
-
-gboolean
-gst_riff_peek_head (GstRiffRead * riff,
- guint32 * tag, guint32 * length, guint * level_up)
-{
- GList *last;
- guint8 *data;
-
- /* if we're at the end of a chunk, but unaligned, then re-align.
- * Those are essentially broken files, but unfortunately they
- * exist. */
- if ((last = g_list_last (riff->level)) != NULL) {
- GstRiffLevel *level = last->data;
- guint64 pos = gst_bytestream_tell (riff->bs);
-
- if (level->start + level->length - pos < 8) {
- if (!gst_bytestream_flush (riff->bs, level->start + level->length - pos)) {
- GST_ELEMENT_ERROR (riff, RESOURCE, READ, (NULL), (NULL));
- return FALSE;
- }
- }
- }
-
- /* read */
- while (gst_bytestream_peek_bytes (riff->bs, &data, 8) != 8) {
- if (!gst_riff_read_handle_event (riff))
- return FALSE;
- }
-
- /* parse tag + length (if wanted) */
- *tag = GST_READ_UINT32_LE (data);
- if (length)
- *length = GST_READ_UINT32_LE (((guint32 *) data) + 1);
-
- /* level */
- if (level_up)
- *level_up = gst_riff_read_element_level_up (riff);
-
- return TRUE;
-}
-
-/*
- * Read: the actual data (plus alignment and flush).
- * Return: the data, as a GstBuffer.
+/**
+ * gst_riff_read_chunk:
+ * @element: caller element (used for debugging).
+ * @pad: pad to pull data from.
+ * @offset: offset to pull from, incremented by this function.
+ * @tag: fourcc of the chunk (returned by this function).
+ * @chunk_data: buffer (returned by this function).
+ *
+ * Reads a single chunk of data.
+ *
+ * Returns: flow status.
*/
-GstBuffer *
-gst_riff_read_element_data (GstRiffRead * riff, guint length, guint * got_bytes)
+GstFlowReturn
+gst_riff_read_chunk (GstElement * element,
+ GstPad * pad, guint64 * _offset, guint32 * tag, GstBuffer ** _chunk_data)
{
- GstBuffer *buf = NULL;
- guint32 got;
+ GstBuffer *buf;
+ GstFlowReturn res;
+ guint size;
+ guint64 offset = *_offset;
- while ((got = gst_bytestream_peek (riff->bs, &buf, length)) != length) {
+ if ((res = gst_pad_pull_range (pad, offset, 8, &buf)) != GST_FLOW_OK)
+ return res;
+ else if (!buf || GST_BUFFER_SIZE (buf) < 8) {
if (buf)
gst_buffer_unref (buf);
- if (!gst_riff_read_handle_event (riff))
- return NULL;
- }
-
- /* we need 16-bit alignment */
- if (length & 1)
- length++;
-
- gst_bytestream_flush (riff->bs, length);
-
- if (got_bytes)
- *got_bytes = got;
-
- return buf;
-}
-
-/*
- * Seek.
- */
-
-GstEvent *
-gst_riff_read_seek (GstRiffRead * riff, guint64 offset)
-{
- guint64 length = gst_bytestream_length (riff->bs);
- guint32 remaining;
- GstEvent *event = NULL;
- guchar *data;
-
- /* hack for AVI files with broken idx1 size chunk markers */
- if (offset > length)
- offset = length;
-
- /* first, flush remaining buffers */
- gst_bytestream_get_status (riff->bs, &remaining, &event);
- if (event) {
- GST_WARNING ("Unexpected event before seek");
- if (!gst_riff_read_use_event (riff, event))
- return NULL;
- event = NULL;
- }
-
- if (remaining)
- gst_bytestream_flush_fast (riff->bs, remaining);
-
- /* now seek */
- if (!gst_bytestream_seek (riff->bs, offset, GST_SEEK_METHOD_SET)) {
- GST_ELEMENT_ERROR (riff, RESOURCE, SEEK, (NULL), (NULL));
- return NULL;
+ return GST_FLOW_ERROR;
}
- /* and now, peek a new byte. This will fail because there's a
- * pending event. Then, take the event and return it. */
- while (!event) {
- if (gst_bytestream_peek_bytes (riff->bs, &data, 1)) {
- GST_WARNING ("Unexpected data after seek - this means seek failed");
- break;
- }
+ *tag = GST_READ_UINT32_LE (GST_BUFFER_DATA (buf));
+ size = GST_READ_UINT32_LE (GST_BUFFER_DATA (buf) + 4);
+ gst_buffer_unref (buf);
- /* get the discont event and return */
- gst_bytestream_get_status (riff->bs, &remaining, &event);
- if (!event) {
- GST_WARNING ("No discontinuity event after seek - seek failed");
- break;
- } else if (GST_EVENT_TYPE (event) != GST_EVENT_DISCONTINUOUS) {
- if (!gst_riff_read_use_event (riff, event))
- return NULL;
- event = NULL;
- }
+ if ((res = gst_pad_pull_range (pad, offset + 8, size, &buf)) != GST_FLOW_OK)
+ return res;
+ else if (!buf || GST_BUFFER_SIZE (buf) < size) {
+ if (buf)
+ gst_buffer_unref (buf);
+ return GST_FLOW_ERROR;
}
- return event;
-}
-
-/*
- * Gives the tag of the next RIFF element.
- */
-
-guint32
-gst_riff_peek_tag (GstRiffRead * riff, guint * level_up)
-{
- guint32 tag;
+ *_chunk_data = buf;
+ *_offset += 8 + ((size + 1) & ~1);
- if (!gst_riff_peek_head (riff, &tag, NULL, level_up))
- return 0;
-
- return tag;
+ return GST_FLOW_OK;
}
-/*
- * Gives the tag of the next LIST/RIFF element.
+/**
+ * gst_riff_parse_chunk:
+ * @element: caller element (used for debugging).
+ * @buf: input buffer.
+ * @offset: offset in the buffer in the caller. Is incremented
+ * by the read size by this function.
+ * @fourcc: fourcc (returned by this function0 of the chunk.
+ * @chunk_data: buffer (returned by the function) containing the
+ * chunk data.
+ *
+ * Reads a single chunk.
+ *
+ * Returns: the fourcc tag of this chunk, or 0 on error.
*/
-guint32
-gst_riff_peek_list (GstRiffRead * riff)
+gboolean
+gst_riff_parse_chunk (GstElement * element, GstBuffer * buf,
+ guint * _offset, guint32 * _fourcc, GstBuffer ** chunk_data)
{
- guint32 lst;
+ guint size;
+ guint32 fourcc;
guint8 *data;
+ guint offset = *_offset;
- if (!gst_riff_peek_head (riff, &lst, NULL, NULL))
- return FALSE;
- if (lst != GST_RIFF_TAG_LIST) {
- g_warning ("Not a LIST object");
- return 0;
- }
-
- if (gst_bytestream_peek_bytes (riff->bs, &data, 12) != 12) {
- GST_ELEMENT_ERROR (riff, RESOURCE, READ, (NULL), (NULL));
- return 0;
- }
-
- return GST_READ_UINT32_LE (((guint32 *) data) + 2);
-}
-
-/*
- * Don't read data.
- */
-
-gboolean
-gst_riff_read_skip (GstRiffRead * riff)
-{
- guint32 tag, length;
- GstEvent *event = NULL;
- guint32 remaining;
+ *chunk_data = NULL;
+ *_fourcc = 0;
- if (!gst_riff_peek_head (riff, &tag, &length, NULL))
+ if (!buf || GST_BUFFER_SIZE (buf) < offset + 8) {
+ GST_DEBUG_OBJECT (element,
+ "Failed to parse chunk header (offset %d, %d available, %d needed)",
+ offset, buf ? GST_BUFFER_DATA (buf) : 0, 8);
return FALSE;
-
- /* 16-bit alignment */
- if (length & 1)
- length++;
-
- /* header itself */
- length += 8;
-
- /* see if we have that much data available */
- gst_bytestream_get_status (riff->bs, &remaining, &event);
- if (event) {
- GST_WARNING ("Unexpected event in skip");
- if (!gst_riff_read_use_event (riff, event))
- return FALSE;
}
- /* yes */
- if (remaining >= length) {
- gst_bytestream_flush_fast (riff->bs, length);
- return TRUE;
- }
+ /* read header */
+ data = GST_BUFFER_DATA (buf) + offset;
+ fourcc = GST_READ_UINT32_LE (data);
+ size = GST_READ_UINT32_LE (data + 4);
- /* no */
- if (!(event = gst_riff_read_seek (riff,
- gst_bytestream_tell (riff->bs) + length)))
- return FALSE;
+ if (GST_BUFFER_SIZE (buf) < size + 8 + offset) {
+ GST_DEBUG_OBJECT (element,
+ "Needed chunk data (%d) is more than available (%d), shortcutting",
+ size, GST_BUFFER_SIZE (buf) - 8 - offset);
+ size = GST_BUFFER_SIZE (buf) - 8 - offset;
+ }
- gst_event_unref (event);
+ if (size)
+ *chunk_data = gst_buffer_create_sub (buf, offset + 8, size);
+ else
+ *chunk_data = NULL;
+ *_fourcc = fourcc;
+ *_offset += 8 + ((size + 1) & ~1);
return TRUE;
}
-/*
- * Read any type of data.
+/**
+ * gst_riff_parse_file_header:
+ * @element: caller element (used for debugging/error).
+ * @buf: input buffer from which the file header will be parsed,
+ * should be at least 12 bytes long.
+ * @doctype: a fourcc (returned by this function) to indicate the
+ * type of document (according to the header).
+ *
+ * Reads the first few bytes from the provided buffer, checks
+ * if this stream is a RIFF stream, and determines document type.
+ * The input data is discarded after use.
+ *
+ * Returns: FALSE if this is not a RIFF stream (in which case the
+ * caller should error out; we already throw an error), or TRUE
+ * if it is.
*/
gboolean
-gst_riff_read_data (GstRiffRead * riff, guint32 * tag, GstBuffer ** buf)
+gst_riff_parse_file_header (GstElement * element,
+ GstBuffer * buf, guint32 * doctype)
{
- guint32 length;
+ guint8 *data = GST_BUFFER_DATA (buf);
+ guint32 tag;
- if (!gst_riff_peek_head (riff, tag, &length, NULL))
+ if (!buf || GST_BUFFER_SIZE (buf) < 12) {
+ GST_ELEMENT_ERROR (element, STREAM, WRONG_TYPE, (NULL),
+ ("Not enough data to parse RIFF header (%d available, %d needed)",
+ buf ? GST_BUFFER_SIZE (buf) : 0, 12));
+ if (buf)
+ gst_buffer_unref (buf);
return FALSE;
- gst_bytestream_flush_fast (riff->bs, 8);
-
- return ((*buf = gst_riff_read_element_data (riff, length, NULL)) != NULL);
-}
-
-/*
- * Read a string.
- */
-
-gboolean
-gst_riff_read_ascii (GstRiffRead * riff, guint32 * tag, gchar ** str)
-{
- GstBuffer *buf;
+ }
- if (!gst_riff_read_data (riff, tag, &buf))
+ tag = GST_READ_UINT32_LE (data);
+ if (tag != GST_RIFF_TAG_RIFF) {
+ GST_ELEMENT_ERROR (element, STREAM, WRONG_TYPE, (NULL),
+ ("Stream is no RIFF stream: " GST_FOURCC_FORMAT,
+ GST_FOURCC_ARGS (tag)));
+ gst_buffer_unref (buf);
return FALSE;
+ }
- *str = g_malloc (GST_BUFFER_SIZE (buf) + 1);
- memcpy (*str, GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));
- (*str)[GST_BUFFER_SIZE (buf)] = '\0';
+ *doctype = GST_READ_UINT32_LE (data + 8);
gst_buffer_unref (buf);
return TRUE;
}
-/*
- * Read media structs.
+/**
+ * gst_riff_parse_strh:
+ * @element: caller element (used for debugging/error).
+ * @buf: input data to be used for parsing, stripped from header.
+ * @strh: a pointer (returned by this function) to a filled-in
+ * strh structure. Caller should free it.
+ *
+ * Parses a strh structure from input data. The input data is
+ * discarded after use.
+ *
+ * Returns: TRUE if parsing succeeded, otherwise FALSE. The stream
+ * should be skipped on error, but it is not fatal.
*/
gboolean
-gst_riff_read_strh (GstRiffRead * riff, gst_riff_strh ** header)
+gst_riff_parse_strh (GstElement * element,
+ GstBuffer * buf, gst_riff_strh ** _strh)
{
- guint32 tag;
- GstBuffer *buf;
gst_riff_strh *strh;
- if (!gst_riff_read_data (riff, &tag, &buf))
- return FALSE;
-
- if (tag != GST_RIFF_TAG_strh) {
- g_warning ("Not a strh chunk");
- gst_buffer_unref (buf);
- return FALSE;
- }
- if (GST_BUFFER_SIZE (buf) < sizeof (gst_riff_strh)) {
- GST_WARNING ("Too small strh (%d available, %d needed)",
- GST_BUFFER_SIZE (buf), (int) sizeof (gst_riff_strh));
- gst_buffer_unref (buf);
+ if (!buf || GST_BUFFER_SIZE (buf) < sizeof (gst_riff_strh)) {
+ GST_ERROR_OBJECT (element,
+ "Too small strh (%d available, %d needed)",
+ buf ? GST_BUFFER_SIZE (buf) : 0, (int) sizeof (gst_riff_strh));
+ if (buf)
+ gst_buffer_unref (buf);
return FALSE;
}
@@ -510,46 +238,57 @@ gst_riff_read_strh (GstRiffRead * riff, gst_riff_strh ** header)
strh->rate = 1;
/* debug */
- GST_INFO ("strh tag found");
- GST_INFO (" type " GST_FOURCC_FORMAT, GST_FOURCC_ARGS (strh->type));
- GST_INFO (" fcc_handler " GST_FOURCC_FORMAT,
+ GST_INFO_OBJECT (element, "strh tag found:");
+ GST_INFO_OBJECT (element, " type " GST_FOURCC_FORMAT,
+ GST_FOURCC_ARGS (strh->type));
+ GST_INFO_OBJECT (element, " fcc_handler " GST_FOURCC_FORMAT,
GST_FOURCC_ARGS (strh->fcc_handler));
- GST_INFO (" flags 0x%08x", strh->flags);
- GST_INFO (" priority %d", strh->priority);
- GST_INFO (" init_frames %d", strh->init_frames);
- GST_INFO (" scale %d", strh->scale);
- GST_INFO (" rate %d", strh->rate);
- GST_INFO (" start %d", strh->start);
- GST_INFO (" length %d", strh->length);
- GST_INFO (" bufsize %d", strh->bufsize);
- GST_INFO (" quality %d", strh->quality);
- GST_INFO (" samplesize %d", strh->samplesize);
-
- *header = strh;
+ GST_INFO_OBJECT (element, " flags 0x%08x", strh->flags);
+ GST_INFO_OBJECT (element, " priority %d", strh->priority);
+ GST_INFO_OBJECT (element, " init_frames %d", strh->init_frames);
+ GST_INFO_OBJECT (element, " scale %d", strh->scale);
+ GST_INFO_OBJECT (element, " rate %d", strh->rate);
+ GST_INFO_OBJECT (element, " start %d", strh->start);
+ GST_INFO_OBJECT (element, " length %d", strh->length);
+ GST_INFO_OBJECT (element, " bufsize %d", strh->bufsize);
+ GST_INFO_OBJECT (element, " quality %d", strh->quality);
+ GST_INFO_OBJECT (element, " samplesize %d", strh->samplesize);
+
+ *_strh = strh;
return TRUE;
}
+/**
+ * gst_riff_parse_strf_vids:
+ * @element: caller element (used for debugging/error).
+ * @buf: input data to be used for parsing, stripped from header.
+ * @strf: a pointer (returned by this function) to a filled-in
+ * strf/vids structure. Caller should free it.
+ * @data: a pointer (returned by this function) to a buffer
+ * containing extradata for this particular stream (e.g.
+ * palette, codec initialization data).
+ *
+ * Parses a video stream´s strf structure plus optionally some
+ * extradata from input data. The input data is discarded after
+ * use.
+ *
+ * Returns: TRUE if parsing succeeded, otherwise FALSE. The stream
+ * should be skipped on error, but it is not fatal.
+ */
+
gboolean
-gst_riff_read_strf_vids_with_data (GstRiffRead * riff,
- gst_riff_strf_vids ** header, GstBuffer ** extradata)
+gst_riff_parse_strf_vids (GstElement * element,
+ GstBuffer * buf, gst_riff_strf_vids ** _strf, GstBuffer ** data)
{
- guint32 tag;
- GstBuffer *buf;
gst_riff_strf_vids *strf;
- if (!gst_riff_read_data (riff, &tag, &buf))
- return FALSE;
-
- if (tag != GST_RIFF_TAG_strf) {
- g_warning ("Not a strf chunk");
- gst_buffer_unref (buf);
- return FALSE;
- }
- if (GST_BUFFER_SIZE (buf) < sizeof (gst_riff_strf_vids)) {
- GST_WARNING ("Too small strf_vids (%d available, %d needed)",
- GST_BUFFER_SIZE (buf), (int) sizeof (gst_riff_strf_vids));
- gst_buffer_unref (buf);
+ if (!buf || GST_BUFFER_SIZE (buf) < sizeof (gst_riff_strf_vids)) {
+ GST_ERROR_OBJECT (element,
+ "Too small strf_vids (%d available, %d needed)",
+ buf ? GST_BUFFER_SIZE (buf) : 0, (int) sizeof (gst_riff_strf_vids));
+ if (buf)
+ gst_buffer_unref (buf);
return FALSE;
}
@@ -570,80 +309,71 @@ gst_riff_read_strf_vids_with_data (GstRiffRead * riff,
#endif
/* size checking */
- *extradata = NULL;
+ *data = NULL;
if (strf->size > GST_BUFFER_SIZE (buf)) {
- g_warning ("strf_vids header gave %d bytes data, only %d available",
+ GST_WARNING_OBJECT (element,
+ "strf_vids header gave %d bytes data, only %d available",
strf->size, GST_BUFFER_SIZE (buf));
strf->size = GST_BUFFER_SIZE (buf);
} else if (strf->size < GST_BUFFER_SIZE (buf)) {
- gint len;
-
- len = GST_BUFFER_SIZE (buf) - strf->size;
- if (len > 0) {
- *extradata = gst_buffer_create_sub (buf, strf->size, len);
- }
+ *data = gst_buffer_create_sub (buf, strf->size,
+ GST_BUFFER_SIZE (buf) - strf->size);
}
/* debug */
- GST_INFO ("strf tag found in context vids:");
- GST_INFO (" size %d", strf->size);
- GST_INFO (" width %d", strf->width);
- GST_INFO (" height %d", strf->height);
- GST_INFO (" planes %d", strf->planes);
- GST_INFO (" bit_cnt %d", strf->bit_cnt);
- GST_INFO (" compression " GST_FOURCC_FORMAT,
+ GST_INFO_OBJECT (element, "strf tag found in context vids:");
+ GST_INFO_OBJECT (element, " size %d", strf->size);
+ GST_INFO_OBJECT (element, " width %d", strf->width);
+ GST_INFO_OBJECT (element, " height %d", strf->height);
+ GST_INFO_OBJECT (element, " planes %d", strf->planes);
+ GST_INFO_OBJECT (element, " bit_cnt %d", strf->bit_cnt);
+ GST_INFO_OBJECT (element, " compression " GST_FOURCC_FORMAT,
GST_FOURCC_ARGS (strf->compression));
- GST_INFO (" image_size %d", strf->image_size);
- GST_INFO (" xpels_meter %d", strf->xpels_meter);
- GST_INFO (" ypels_meter %d", strf->ypels_meter);
- GST_INFO (" num_colors %d", strf->num_colors);
- GST_INFO (" imp_colors %d", strf->imp_colors);
- if (*extradata)
- GST_INFO (" %d bytes extra_data", GST_BUFFER_SIZE (*extradata));
+ GST_INFO_OBJECT (element, " image_size %d", strf->image_size);
+ GST_INFO_OBJECT (element, " xpels_meter %d", strf->xpels_meter);
+ GST_INFO_OBJECT (element, " ypels_meter %d", strf->ypels_meter);
+ GST_INFO_OBJECT (element, " num_colors %d", strf->num_colors);
+ GST_INFO_OBJECT (element, " imp_colors %d", strf->imp_colors);
+ if (*data)
+ GST_INFO_OBJECT (element, " %d bytes extradata", GST_BUFFER_SIZE (*data));
gst_buffer_unref (buf);
- *header = strf;
+ *_strf = strf;
return TRUE;
}
-/*
- * Obsolete, use gst_riff_read_strf_vids_with_data ().
+/**
+ * gst_riff_parse_strf_auds:
+ * @element: caller element (used for debugging/error).
+ * @buf: input data to be used for parsing, stripped from header.
+ * @strf: a pointer (returned by this function) to a filled-in
+ * strf/auds structure. Caller should free it.
+ * @data: a pointer (returned by this function) to a buffer
+ * containing extradata for this particular stream (e.g.
+ * codec initialization data).
+ *
+ * Parses an audio stream´s strf structure plus optionally some
+ * extradata from input data. The input data is discarded after
+ * use.
+ *
+ * Returns: TRUE if parsing succeeded, otherwise FALSE. The stream
+ * should be skipped on error, but it is not fatal.
*/
-gboolean
-gst_riff_read_strf_vids (GstRiffRead * riff, gst_riff_strf_vids ** header)
-{
- GstBuffer *data = NULL;
- gboolean ret;
-
- ret = gst_riff_read_strf_vids_with_data (riff, header, &data);
- if (data)
- gst_buffer_unref (data);
-
- return ret;
-}
gboolean
-gst_riff_read_strf_auds_with_data (GstRiffRead * riff,
- gst_riff_strf_auds ** header, GstBuffer ** extradata)
+gst_riff_parse_strf_auds (GstElement * element,
+ GstBuffer * buf, gst_riff_strf_auds ** _strf, GstBuffer ** data)
{
- guint32 tag;
- GstBuffer *buf;
gst_riff_strf_auds *strf;
- if (!gst_riff_read_data (riff, &tag, &buf))
- return FALSE;
-
- if (tag != GST_RIFF_TAG_strf && tag != GST_RIFF_TAG_fmt) {
- g_warning ("Not a strf chunk");
- gst_buffer_unref (buf);
- return FALSE;
- }
- if (GST_BUFFER_SIZE (buf) < sizeof (gst_riff_strf_auds)) {
- GST_WARNING ("Too small strf_auds (%d available, %d needed)",
- GST_BUFFER_SIZE (buf), (int) sizeof (gst_riff_strf_auds));
- gst_buffer_unref (buf);
+ if (!buf || GST_BUFFER_SIZE (buf) < sizeof (gst_riff_strf_auds)) {
+ GST_ERROR_OBJECT (element,
+ "Too small strf_auds (%d available, %d needed)",
+ buf ? GST_BUFFER_SIZE (buf) : 0, (int) sizeof (gst_riff_strf_auds));
+ if (buf)
+ gst_buffer_unref (buf);
return FALSE;
}
@@ -659,72 +389,65 @@ gst_riff_read_strf_auds_with_data (GstRiffRead * riff,
#endif
/* size checking */
- *extradata = NULL;
- if (strf->size > GST_BUFFER_SIZE (buf)) {
- g_warning ("strf_auds header gave %d bytes data, only %d available",
- strf->size, GST_BUFFER_SIZE (buf));
- strf->size = GST_BUFFER_SIZE (buf);
- } else if (strf->size < GST_BUFFER_SIZE (buf)) {
+ *data = NULL;
+ if (GST_BUFFER_SIZE (buf) > sizeof (gst_riff_strf_auds) + 2) {
gint len;
- len = GST_BUFFER_SIZE (buf) - strf->size - 2;
- if (len > 0) {
- *extradata = gst_buffer_create_sub (buf, strf->size + 2, len);
+ len = GST_READ_UINT16_LE (&GST_BUFFER_DATA (buf)[16]);
+ if (len + 2 + sizeof (gst_riff_strf_auds) > GST_BUFFER_SIZE (buf)) {
+ GST_WARNING_OBJECT (element,
+ "Extradata indicated %d bytes, but only %d available",
+ len, GST_BUFFER_SIZE (buf) - 2 - sizeof (gst_riff_strf_auds));
+ len = GST_BUFFER_SIZE (buf) - 2 - sizeof (gst_riff_strf_auds);
}
+ *data = gst_buffer_create_sub (buf, sizeof (gst_riff_strf_auds) + 2, len);
}
/* debug */
- GST_INFO ("strf tag found in context auds:");
- GST_INFO (" format %d", strf->format);
- GST_INFO (" channels %d", strf->channels);
- GST_INFO (" rate %d", strf->rate);
- GST_INFO (" av_bps %d", strf->av_bps);
- GST_INFO (" blockalign %d", strf->blockalign);
- GST_INFO (" size %d", strf->size); /* wordsize, not extrasize! */
- if (*extradata)
- GST_INFO (" %d bytes extra_data", GST_BUFFER_SIZE (*extradata));
+ GST_INFO_OBJECT (element, "strf tag found in context auds:");
+ GST_INFO_OBJECT (element, " format %d", strf->format);
+ GST_INFO_OBJECT (element, " channels %d", strf->channels);
+ GST_INFO_OBJECT (element, " rate %d", strf->rate);
+ GST_INFO_OBJECT (element, " av_bps %d", strf->av_bps);
+ GST_INFO_OBJECT (element, " blockalign %d", strf->blockalign);
+ GST_INFO_OBJECT (element, " size %d", strf->size);
+ if (*data)
+ GST_INFO_OBJECT (element, " %d bytes extradata", GST_BUFFER_SIZE (*data));
gst_buffer_unref (buf);
- *header = strf;
+ *_strf = strf;
return TRUE;
}
-/*
- * Obsolete, use gst_riff_read_strf_auds_with_data ().
+/**
+ * gst_riff_parse_strf_iavs:
+ * @element: caller element (used for debugging/error).
+ * @buf: input data to be used for parsing, stripped from header.
+ * @strf: a pointer (returned by this function) to a filled-in
+ * strf/iavs structure. Caller should free it.
+ * @data: a pointer (returned by this function) to a buffer
+ * containing extradata for this particular stream (e.g.
+ * codec initialization data).
+ *
+ * Parses a interleaved (also known as "complex") stream´s strf
+ * structure plus optionally some extradata from input data. The
+ * input data is discarded after use.
+ *
+ * Returns: TRUE if parsing succeeded, otherwise FALSE.
*/
-gboolean
-gst_riff_read_strf_auds (GstRiffRead * riff, gst_riff_strf_auds ** header)
-{
- GstBuffer *data = NULL;
- gboolean ret;
-
- ret = gst_riff_read_strf_auds_with_data (riff, header, &data);
- if (data)
- gst_buffer_unref (data);
-
- return ret;
-}
gboolean
-gst_riff_read_strf_iavs (GstRiffRead * riff, gst_riff_strf_iavs ** header)
+gst_riff_parse_strf_iavs (GstElement * element,
+ GstBuffer * buf, gst_riff_strf_iavs ** _strf, GstBuffer ** data)
{
- guint32 tag;
- GstBuffer *buf;
gst_riff_strf_iavs *strf;
- if (!gst_riff_read_data (riff, &tag, &buf))
- return FALSE;
-
- if (tag != GST_RIFF_TAG_strf) {
- g_warning ("Not a strf chunk");
- gst_buffer_unref (buf);
- return FALSE;
- }
- if (GST_BUFFER_SIZE (buf) < sizeof (gst_riff_strf_iavs)) {
- GST_WARNING ("Too small strf_iavs (%d available, %d needed)",
- GST_BUFFER_SIZE (buf), (int) sizeof (gst_riff_strf_iavs));
+ if (!buf || GST_BUFFER_SIZE (buf) < sizeof (gst_riff_strf_iavs)) {
+ GST_ERROR_OBJECT (element,
+ "Too small strf_iavs (%d available, %d needed)",
+ buf ? GST_BUFFER_SIZE (buf) : 0, (int) sizeof (gst_riff_strf_iavs));
gst_buffer_unref (buf);
return FALSE;
}
@@ -744,85 +467,63 @@ gst_riff_read_strf_iavs (GstRiffRead * riff, gst_riff_strf_iavs ** header)
#endif
/* debug */
- GST_INFO ("strf tag found in context iavs");
- GST_INFO (" DVAAuxSrc %08x", strf->DVAAuxSrc);
- GST_INFO (" DVAAuxCtl %08x", strf->DVAAuxCtl);
- GST_INFO (" DVAAuxSrc1 %08x", strf->DVAAuxSrc1);
- GST_INFO (" DVAAuxCtl1 %08x", strf->DVAAuxCtl1);
- GST_INFO (" DVVAuxSrc %08x", strf->DVVAuxSrc);
- GST_INFO (" DVVAuxCtl %08x", strf->DVVAuxCtl);
- GST_INFO (" DVReserved1 %08x", strf->DVReserved1);
- GST_INFO (" DVReserved2 %08x", strf->DVReserved2);
-
- *header = strf;
+ GST_INFO_OBJECT (element, "strf tag found in context iavs:");
+ GST_INFO_OBJECT (element, " DVAAuxSrc %08x", strf->DVAAuxSrc);
+ GST_INFO_OBJECT (element, " DVAAuxCtl %08x", strf->DVAAuxCtl);
+ GST_INFO_OBJECT (element, " DVAAuxSrc1 %08x", strf->DVAAuxSrc1);
+ GST_INFO_OBJECT (element, " DVAAuxCtl1 %08x", strf->DVAAuxCtl1);
+ GST_INFO_OBJECT (element, " DVVAuxSrc %08x", strf->DVVAuxSrc);
+ GST_INFO_OBJECT (element, " DVVAuxCtl %08x", strf->DVVAuxCtl);
+ GST_INFO_OBJECT (element, " DVReserved1 %08x", strf->DVReserved1);
+ GST_INFO_OBJECT (element, " DVReserved2 %08x", strf->DVReserved2);
+
+ *_strf = strf;
+ *data = NULL;
return TRUE;
}
-/*
- * Read a list.
+/**
+ * gst_riff_parse_info:
+ * @element: caller element (used for debugging/error).
+ * @buf: input data to be used for parsing, stripped from header.
+ * @taglist: a pointer to a taglist (returned by this function)
+ * containing information about this stream. May be
+ * NULL if no supported tags were found.
+ *
+ * Parses stream metadata from input data. The input data is
+ * discarded after use.
*/
-gboolean
-gst_riff_read_list (GstRiffRead * riff, guint32 * tag)
+void
+gst_riff_parse_info (GstElement * element,
+ GstBuffer * buf, GstTagList ** _taglist)
{
- guint32 length, lst;
- GstRiffLevel *level;
guint8 *data;
-
- if (!gst_riff_peek_head (riff, &lst, &length, NULL))
- return FALSE;
- if (lst != GST_RIFF_TAG_LIST) {
- g_warning ("Not a LIST object");
- return FALSE;
- }
- gst_bytestream_flush_fast (riff->bs, 8);
- if (gst_bytestream_peek_bytes (riff->bs, &data, 4) != 4) {
- GST_ELEMENT_ERROR (riff, RESOURCE, READ, (NULL), (NULL));
- return FALSE;
- }
- gst_bytestream_flush_fast (riff->bs, 4);
- *tag = GST_READ_UINT32_LE (data);
-
- /* remember level */
- level = g_new (GstRiffLevel, 1);
- level->start = gst_bytestream_tell (riff->bs);
- level->length = length - 4;
- riff->level = g_list_append (riff->level, level);
-
- return TRUE;
-}
-
-/*
- * Utility function for reading metadata in a RIFF file.
- */
-
-gboolean
-gst_riff_read_info (GstRiffRead * riff)
-{
+ guint size, tsize;
guint32 tag;
- guint64 end;
- GstRiffLevel *level;
- GList *last;
- gchar *name, *type;
+ const gchar *type;
+ gchar *name;
GstTagList *taglist;
gboolean have_tags = FALSE;
- /* What we're doing here is ugly (oh no!); we look
- * at our LIST tag size and assure that we do not
- * cross boundaries. This is to maintain the level
- * counter for the client app. */
- last = g_list_last (riff->level);
- level = last->data;
- riff->level = g_list_remove (riff->level, level);
- end = level->start + level->length;
- g_free (level);
-
+ if (!buf) {
+ *_taglist = NULL;
+ return;
+ }
+ data = GST_BUFFER_DATA (buf);
+ size = GST_BUFFER_SIZE (buf);
taglist = gst_tag_list_new ();
- while (gst_bytestream_tell (riff->bs) < end) {
- if (!gst_riff_peek_head (riff, &tag, NULL, NULL)) {
- return FALSE;
+ while (size > 8) {
+ tag = GST_READ_UINT32_LE (data);
+ tsize = GST_READ_UINT32_LE (data + 4);
+ size -= 8;
+ data += 8;
+ if (tsize > size) {
+ GST_WARNING_OBJECT (element,
+ "Tagsize %d is larger than available data %d", tsize, size);
+ tsize = size;
}
/* find out the type of metadata */
@@ -898,97 +599,36 @@ gst_riff_read_info (GstRiffRead * riff)
break;
default:
type = NULL;
- GST_WARNING ("Unknown INFO (metadata) tag entry " GST_FOURCC_FORMAT,
+ GST_WARNING_OBJECT (element,
+ "Unknown INFO (metadata) tag entry " GST_FOURCC_FORMAT,
GST_FOURCC_ARGS (tag));
break;
}
if (type) {
- name = NULL;
- if (!gst_riff_read_ascii (riff, &tag, &name)) {
- return FALSE;
- }
-
- if (name && name[0] != '\0') {
- GValue src = { 0 }
- , dest = {
- 0};
- GType dest_type = gst_tag_get_type (type);
+ if (data[0] != '\0') {
+ /* read, NULL-terminate */
+ name = g_new (gchar, tsize + 1);
+ name[tsize] = '\0';
+ memcpy (name, data, tsize);
+ /* add to list */
have_tags = TRUE;
- g_value_init (&src, G_TYPE_STRING);
- g_value_set_string (&src, name);
- g_value_init (&dest, dest_type);
- g_value_transform (&src, &dest);
- g_value_unset (&src);
- gst_tag_list_add_values (taglist, GST_TAG_MERGE_APPEND,
- type, &dest, NULL);
- g_value_unset (&dest);
+ gst_tag_list_add (taglist, GST_TAG_MERGE_APPEND, type, name, NULL);
+ g_free (name);
}
- g_free (name);
- } else {
- gst_riff_read_skip (riff);
}
+
+ data += tsize;
+ size -= tsize;
}
if (have_tags) {
- GstElement *element = GST_ELEMENT (riff);
- GstEvent *event = gst_event_new_tag (taglist);
- const GList *padlist;
-
- /* let the world know about this wonderful thing */
- /* FIXME, MT unsafe */
- for (padlist = element->pads; padlist != NULL; padlist = padlist->next) {
- if (GST_PAD_IS_SRC (padlist->data) && GST_PAD_IS_USABLE (padlist->data)) {
- gst_event_ref (event);
- gst_pad_push_event (GST_PAD (padlist->data), event);
- }
- }
-
- gst_element_post_message (GST_ELEMENT (element),
- gst_message_new_tag (GST_OBJECT (element), taglist));
-
- gst_event_unref (event);
+ *_taglist = taglist;
} else {
+ *_taglist = NULL;
gst_tag_list_free (taglist);
}
- return TRUE;
-}
-
-/*
- * Read RIFF header and document type.
- */
-
-gboolean
-gst_riff_read_header (GstRiffRead * riff, guint32 * doctype)
-{
- GstRiffLevel *level;
- guint32 tag, length;
- guint8 *data;
-
- /* We ignore size for openDML-2.0 support */
- if (!gst_riff_peek_head (riff, &tag, &length, NULL))
- return FALSE;
- if (tag != GST_RIFF_TAG_RIFF) {
- GST_ELEMENT_ERROR (riff, STREAM, WRONG_TYPE, (NULL), (NULL));
- return FALSE;
- }
- gst_bytestream_flush_fast (riff->bs, 8);
-
- /* doctype */
- if (gst_bytestream_peek_bytes (riff->bs, &data, 4) != 4) {
- GST_ELEMENT_ERROR (riff, RESOURCE, READ, (NULL), (NULL));
- return FALSE;
- }
- gst_bytestream_flush_fast (riff->bs, 4);
- *doctype = GST_READ_UINT32_LE (data);
-
- /* remember level */
- level = g_new (GstRiffLevel, 1);
- level->start = gst_bytestream_tell (riff->bs);
- level->length = length - 4;
- riff->level = g_list_append (riff->level, level);
-
- return TRUE;
+ return;
}
diff --git a/gst-libs/gst/riff/riff-read.h b/gst-libs/gst/riff/riff-read.h
index d44c4ed7e..aadd0a629 100644
--- a/gst-libs/gst/riff/riff-read.h
+++ b/gst-libs/gst/riff/riff-read.h
@@ -24,87 +24,58 @@
#include <glib.h>
#include <gst/gst.h>
-#include <gst/bytestream/bytestream.h>
-G_BEGIN_DECLS
+#include "riff-ids.h"
-#define GST_TYPE_RIFF_READ \
- (gst_riff_read_get_type ())
-#define GST_RIFF_READ(obj) \
- (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_RIFF_READ, GstRiffRead))
-#define GST_RIFF_READ_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_RIFF_READ, GstRiffReadClass))
-#define GST_IS_RIFF_READ(obj) \
- (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_RIFF_READ))
-#define GST_IS_RIFF_READ_CLASS(obj) \
- (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_RIFF_READ))
-#define GST_RIFF_READ_GET_CLASS(obj) \
- (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_RIFF_READ, GstRiffReadClass))
+G_BEGIN_DECLS
-typedef struct _GstRiffLevel {
- guint64 start,
- length;
-} GstRiffLevel;
+/*
+ * Operate using pull_range().
+ */
-typedef struct _GstRiffRead {
- GstElement parent;
+GstFlowReturn gst_riff_read_chunk (GstElement * element,
+ GstPad * pad,
+ guint64 * offset,
+ guint32 * fourcc,
+ GstBuffer ** chunk_data);
- GstPad *sinkpad;
- GstByteStream *bs;
+/*
+ * These functions operate on provided data (the caller is
+ * supposed to strip the chunk headers). The buffer is
+ * provided by the caller, the strf/strh/data are filled in
+ * by the function.
+ */
- GList *level;
-} GstRiffRead;
+gboolean gst_riff_parse_chunk (GstElement * element,
+ GstBuffer * buf,
+ guint * offset,
+ guint32 * fourcc,
+ GstBuffer ** chunk_data);
-typedef struct _GstRiffReadClass {
- GstElementClass parent;
-} GstRiffReadClass;
+gboolean gst_riff_parse_file_header (GstElement * element,
+ GstBuffer * buf,
+ guint32 * doctype);
-GType gst_riff_read_get_type (void);
+gboolean gst_riff_parse_strh (GstElement * element,
+ GstBuffer * buf,
+ gst_riff_strh ** strh);
-guint32 gst_riff_peek_tag (GstRiffRead *riff,
- guint *level_up);
-guint32 gst_riff_peek_list (GstRiffRead *riff);
-gboolean gst_riff_peek_head (GstRiffRead *riff,
- guint32 *tag,
- guint32 *length,
- guint *level_up);
+gboolean gst_riff_parse_strf_vids (GstElement * element,
+ GstBuffer * buf,
+ gst_riff_strf_vids ** strf,
+ GstBuffer ** data);
+gboolean gst_riff_parse_strf_auds (GstElement * element,
+ GstBuffer * buf,
+ gst_riff_strf_auds ** strf,
+ GstBuffer ** data);
+gboolean gst_riff_parse_strf_iavs (GstElement * element,
+ GstBuffer * buf,
+ gst_riff_strf_iavs ** strf,
+ GstBuffer ** data);
-GstEvent *gst_riff_read_seek (GstRiffRead *riff,
- guint64 offset);
-gboolean gst_riff_read_skip (GstRiffRead *riff);
-gboolean gst_riff_read_data (GstRiffRead *riff,
- guint32 *tag,
- GstBuffer **buf);
-gboolean gst_riff_read_ascii (GstRiffRead *riff,
- guint32 *tag,
- gchar **str);
-gboolean gst_riff_read_list (GstRiffRead *riff,
- guint32 *tag);
-gboolean gst_riff_read_header (GstRiffRead *read,
- guint32 *doctype);
-GstBuffer *gst_riff_read_element_data (GstRiffRead *riff,
- guint length,
- guint *got_bytes);
-/*
- * Utility functions (including byteswapping).
- */
-gboolean gst_riff_read_strh (GstRiffRead *riff,
- gst_riff_strh **header);
-gboolean gst_riff_read_strf_vids (GstRiffRead *riff,
- gst_riff_strf_vids **header);
-gboolean gst_riff_read_strf_vids_with_data
- (GstRiffRead *riff,
- gst_riff_strf_vids **header,
- GstBuffer **extradata);
-gboolean gst_riff_read_strf_auds (GstRiffRead *riff,
- gst_riff_strf_auds **header);
-gboolean gst_riff_read_strf_auds_with_data
- (GstRiffRead *riff,
- gst_riff_strf_auds **header,
- GstBuffer **extradata);
-gboolean gst_riff_read_strf_iavs (GstRiffRead *riff,
- gst_riff_strf_iavs **header);
-gboolean gst_riff_read_info (GstRiffRead *riff);
+void gst_riff_parse_info (GstElement * element,
+ GstBuffer * buf,
+ GstTagList ** taglist);
G_END_DECLS
diff --git a/gst-libs/gst/riff/riff.c b/gst-libs/gst/riff/riff.c
index ab8d47b57..433cac766 100644
--- a/gst-libs/gst/riff/riff.c
+++ b/gst-libs/gst/riff/riff.c
@@ -25,10 +25,14 @@
#include <gst/gst.h>
+GST_DEBUG_CATEGORY (riff_debug);
+
static gboolean
plugin_init (GstPlugin * plugin)
{
- return gst_library_load ("gstbytestream");
+ GST_DEBUG_CATEGORY_INIT (riff_debug, "riff", 0, "RIFF I/O");
+
+ return TRUE;
}
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,