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.
This commit is contained in:
Sebastian Dröge 2008-01-06 16:36:32 +00:00
parent 38a7abe545
commit ba9e0cc8d5
2 changed files with 59 additions and 9 deletions

View file

@ -185,15 +185,52 @@ gst_gio_base_src_get_size (GstBaseSrc * base_src, guint64 * size)
g_clear_error (&err); g_clear_error (&err);
} }
} else if (G_IS_MEMORY_INPUT_STREAM (src->stream)) { } else if (GST_GIO_STREAM_IS_SEEKABLE (src->stream)) {
gsize data_size; goffset old;
goffset stream_size;
gboolean ret;
GSeekable *seekable = G_SEEKABLE (src->stream);
GError *err = NULL;
data_size = old = g_seekable_tell (seekable);
g_memory_input_stream_get_data_size (G_MEMORY_INPUT_STREAM (src->
stream));
if (data_size != -1) { ret = g_seekable_seek (seekable, 0, G_SEEK_END, src->cancel, &err);
*size = data_size; 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; return TRUE;
} }
} }

View file

@ -57,6 +57,12 @@ message_handler (GstBus * bus, GstMessage * msg, gpointer data)
return TRUE; return TRUE;
} }
static void
free_input (gpointer data)
{
g_free (data);
}
GST_START_TEST (test_memory_stream) GST_START_TEST (test_memory_stream)
{ {
GMainLoop *loop; GMainLoop *loop;
@ -70,6 +76,8 @@ GST_START_TEST (test_memory_stream)
guint8 *in_data; guint8 *in_data;
GByteArray *out_data; GByteArray *out_data;
gint i; gint i;
GstFormat fmt = GST_FORMAT_BYTES;
gint64 duration;
got_eos = FALSE; got_eos = FALSE;
@ -78,8 +86,8 @@ GST_START_TEST (test_memory_stream)
in_data[i] = i % 256; in_data[i] = i % 256;
input = input =
G_MEMORY_INPUT_STREAM (g_memory_input_stream_from_data (in_data, 512)); G_MEMORY_INPUT_STREAM (g_memory_input_stream_new_from_data (in_data, 512,
g_memory_input_stream_set_free_data (input, TRUE); free_input));
out_data = g_byte_array_new (); out_data = g_byte_array_new ();
output = G_MEMORY_OUTPUT_STREAM (g_memory_output_stream_new (out_data)); 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_bus_add_watch (bus, message_handler, loop);
gst_object_unref (bus); 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); gst_element_set_state (bin, GST_STATE_PLAYING);
g_main_loop_run (loop); g_main_loop_run (loop);