From 5b55df7766f9374c2884ad7d776c1b40308e2733 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Tue, 29 Aug 2006 15:23:46 +0000 Subject: [PATCH] ext/gnomevfs/gstgnomevfssrc.c: Try harder to get the size from a uri by using _info_uri() when _info_from_handle() do... MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Original commit message from CVS: Patch by: Tim-Philipp Müller * ext/gnomevfs/gstgnomevfssrc.c: (gst_gnome_vfs_src_create), (gst_gnome_vfs_src_start): Try harder to get the size from a uri by using _info_uri() when _info_from_handle() does not give us enough info. Also follow symlinks when getting the size. Partially Fixes #332864. --- ChangeLog | 11 ++++++++++ ext/gnomevfs/gstgnomevfssrc.c | 38 ++++++++++++++++++++++++----------- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8ee752ccd5..0a7eb8023a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2006-08-29 Wim Taymans + + Patch by: Tim-Philipp Müller + + * ext/gnomevfs/gstgnomevfssrc.c: (gst_gnome_vfs_src_create), + (gst_gnome_vfs_src_start): + Try harder to get the size from a uri by using _info_uri() when + _info_from_handle() does not give us enough info. + Also follow symlinks when getting the size. + Partially Fixes #332864. + 2006-08-29 Tim-Philipp Müller Patch by: Viktor Peters diff --git a/ext/gnomevfs/gstgnomevfssrc.c b/ext/gnomevfs/gstgnomevfssrc.c index 8f9e562c7d..e05c1fb505 100644 --- a/ext/gnomevfs/gstgnomevfssrc.c +++ b/ext/gnomevfs/gstgnomevfssrc.c @@ -107,7 +107,6 @@ static GStaticMutex count_lock = G_STATIC_MUTEX_INIT; static gint ref_count = 0; static gboolean vfs_owner = FALSE; - static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC, GST_PAD_ALWAYS, @@ -633,7 +632,7 @@ gst_gnome_vfs_src_create (GstBaseSrc * basesrc, guint64 offset, guint size, size); /* seek if required */ - if (src->curoffset != offset) { + if (G_UNLIKELY (src->curoffset != offset)) { GST_DEBUG ("need to seek"); if (src->seekable) { GST_DEBUG ("seeking to %lld", offset); @@ -656,12 +655,13 @@ gst_gnome_vfs_src_create (GstBaseSrc * basesrc, guint64 offset, guint size, res = gnome_vfs_read (src->handle, data, size, &readbytes); - if (res == GNOME_VFS_ERROR_EOF || (res == GNOME_VFS_OK && readbytes == 0)) + if (G_UNLIKELY (res == GNOME_VFS_ERROR_EOF || (res == GNOME_VFS_OK + && readbytes == 0))) goto eos; GST_BUFFER_SIZE (buf) = readbytes; - if (res != GNOME_VFS_OK) + if (G_UNLIKELY (res != GNOME_VFS_OK)) goto read_failed; src->curoffset += readbytes; @@ -776,6 +776,7 @@ gst_gnome_vfs_src_get_size (GstBaseSrc * basesrc, guint64 * size) static gboolean gst_gnome_vfs_src_start (GstBaseSrc * basesrc) { + GnomeVFSFileInfoOptions options; GnomeVFSResult res; GnomeVFSFileInfo *info; GstGnomeVFSSrc *src; @@ -785,9 +786,12 @@ gst_gnome_vfs_src_start (GstBaseSrc * basesrc) gst_gnome_vfs_src_push_callbacks (src); if (src->uri != NULL) { + GnomeVFSOpenMode mode; + /* this can block... */ - if ((res = gnome_vfs_open_uri (&src->handle, src->uri, - GNOME_VFS_OPEN_READ)) != GNOME_VFS_OK) + mode = GNOME_VFS_OPEN_READ | GNOME_VFS_OPEN_RANDOM; + res = gnome_vfs_open_uri (&src->handle, src->uri, mode); + if (res != GNOME_VFS_OK) goto open_failed; src->own_handle = TRUE; } else if (!src->handle) { @@ -798,13 +802,23 @@ gst_gnome_vfs_src_start (GstBaseSrc * basesrc) src->size = (GnomeVFSFileSize) - 1; info = gnome_vfs_file_info_new (); - if ((res = gnome_vfs_get_file_info_from_handle (src->handle, - info, GNOME_VFS_FILE_INFO_DEFAULT)) == GNOME_VFS_OK) { - if (info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_SIZE) { + options = GNOME_VFS_FILE_INFO_DEFAULT | GNOME_VFS_FILE_INFO_FOLLOW_LINKS; + res = gnome_vfs_get_file_info_from_handle (src->handle, info, options); + if (res == GNOME_VFS_OK) { + if ((info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_SIZE) != 0) { src->size = info->size; - GST_DEBUG_OBJECT (src, "size: %llu bytes", src->size); - } else - GST_LOG_OBJECT (src, "filesize not known"); + GST_DEBUG_OBJECT (src, "size: %" G_GUINT64_FORMAT " bytes", src->size); + } else if (src->own_handle && gnome_vfs_uri_is_local (src->uri)) { + GST_DEBUG_OBJECT (src, "file size not known, trying fallback"); + res = gnome_vfs_get_file_info_uri (src->uri, info, options); + if (res == GNOME_VFS_OK && + (info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_SIZE) != 0) { + src->size = info->size; + GST_DEBUG_OBJECT (src, "size: %" G_GUINT64_FORMAT " bytes", src->size); + } + } + if (src->size == (GnomeVFSFileSize) - 1) + GST_DEBUG_OBJECT (src, "file size not known"); } else { GST_WARNING_OBJECT (src, "getting info failed: %s", gnome_vfs_result_to_string (res));