From ba9e0cc8d5801a9d6d82fc6e6dfbe235ff028372 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Sun, 6 Jan 2008 16:36:32 +0000 Subject: [PATCH] Update to GMemoryInputStream API changes in GLib SVN and require gio-2.0 >= 2.15.1 for this. Fixes bug #507584. Original commit message from CVS: * configure.ac: * ext/gio/gstgiobasesrc.c: (gst_gio_base_src_get_size): * tests/check/pipelines/gio.c: (free_input), (GST_START_TEST): Update to GMemoryInputStream API changes in GLib SVN and require gio-2.0 >= 2.15.1 for this. Fixes bug #507584. We can also report the duration for every GSeekable, not only GFileInputStream and GMemoryInputStream. --- ext/gio/gstgiobasesrc.c | 51 ++++++++++++++++++++++++++++++++----- tests/check/pipelines/gio.c | 17 +++++++++++-- 2 files changed, 59 insertions(+), 9 deletions(-) diff --git a/ext/gio/gstgiobasesrc.c b/ext/gio/gstgiobasesrc.c index eaf6b954d0..019f8ee4d0 100644 --- a/ext/gio/gstgiobasesrc.c +++ b/ext/gio/gstgiobasesrc.c @@ -185,15 +185,52 @@ gst_gio_base_src_get_size (GstBaseSrc * base_src, guint64 * size) g_clear_error (&err); } - } else if (G_IS_MEMORY_INPUT_STREAM (src->stream)) { - gsize data_size; + } else if (GST_GIO_STREAM_IS_SEEKABLE (src->stream)) { + goffset old; + goffset stream_size; + gboolean ret; + GSeekable *seekable = G_SEEKABLE (src->stream); + GError *err = NULL; - data_size = - g_memory_input_stream_get_data_size (G_MEMORY_INPUT_STREAM (src-> - stream)); + old = g_seekable_tell (seekable); - if (data_size != -1) { - *size = data_size; + ret = g_seekable_seek (seekable, 0, G_SEEK_END, src->cancel, &err); + if (!ret) { + if (!gst_gio_error (src, "g_seekable_seek", &err, NULL)) { + if (GST_GIO_ERROR_MATCHES (err, NOT_SUPPORTED)) + GST_DEBUG_OBJECT (src, + "Seeking to the end of stream is not supported"); + else + GST_WARNING_OBJECT (src, "Seeking to end of stream failed: %s", + err->message); + g_clear_error (&err); + } else { + GST_WARNING_OBJECT (src, "Seeking to end of stream failed"); + } + + return FALSE; + } + + stream_size = g_seekable_tell (seekable); + + ret = g_seekable_seek (seekable, old, G_SEEK_SET, src->cancel, &err); + if (!ret) { + if (!gst_gio_error (src, "g_seekable_seek", &err, NULL)) { + if (GST_GIO_ERROR_MATCHES (err, NOT_SUPPORTED)) + GST_ERROR_OBJECT (src, "Seeking to the old position not supported"); + else + GST_ERROR_OBJECT (src, "Seeking to the old position failed: %s", + err->message); + g_clear_error (&err); + } else { + GST_ERROR_OBJECT (src, "Seeking to the old position faile"); + } + + return FALSE; + } + + if (stream_size >= 0) { + *size = stream_size; return TRUE; } } diff --git a/tests/check/pipelines/gio.c b/tests/check/pipelines/gio.c index 8791b3328b..0cc7ac206f 100644 --- a/tests/check/pipelines/gio.c +++ b/tests/check/pipelines/gio.c @@ -57,6 +57,12 @@ message_handler (GstBus * bus, GstMessage * msg, gpointer data) return TRUE; } +static void +free_input (gpointer data) +{ + g_free (data); +} + GST_START_TEST (test_memory_stream) { GMainLoop *loop; @@ -70,6 +76,8 @@ GST_START_TEST (test_memory_stream) guint8 *in_data; GByteArray *out_data; gint i; + GstFormat fmt = GST_FORMAT_BYTES; + gint64 duration; got_eos = FALSE; @@ -78,8 +86,8 @@ GST_START_TEST (test_memory_stream) in_data[i] = i % 256; input = - G_MEMORY_INPUT_STREAM (g_memory_input_stream_from_data (in_data, 512)); - g_memory_input_stream_set_free_data (input, TRUE); + G_MEMORY_INPUT_STREAM (g_memory_input_stream_new_from_data (in_data, 512, + free_input)); out_data = g_byte_array_new (); output = G_MEMORY_OUTPUT_STREAM (g_memory_output_stream_new (out_data)); @@ -105,6 +113,11 @@ GST_START_TEST (test_memory_stream) gst_bus_add_watch (bus, message_handler, loop); gst_object_unref (bus); + gst_element_set_state (bin, GST_STATE_PAUSED); + + fail_unless (gst_element_query_duration (bin, &fmt, &duration)); + fail_unless_equals_int (duration, 512); + gst_element_set_state (bin, GST_STATE_PLAYING); g_main_loop_run (loop);