Mercurial > audlegacy
changeset 2341:02a850a2533b trunk
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
author | nenolod |
---|---|
date | Mon, 15 Jan 2007 18:33:42 -0800 |
parents | eb71fec30e9a |
children | f140d0a27093 |
files | ChangeLog src/audacious/Makefile src/audacious/vfs_buffered_file.c src/audacious/vfs_buffered_file.h |
diffstat | 4 files changed, 241 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Mon Jan 15 12:39:22 2007 -0800 +++ b/ChangeLog Mon Jan 15 18:33:42 2007 -0800 @@ -1,3 +1,11 @@ +2007-01-15 20:39:22 +0000 Giacomo Lozito <james@develia.org> + revision [3690] + - added audacious_get_localdir() in util.c/h, returns a string with the full path of audacious local datadir + trunk/src/audacious/util.h | 2 ++ + trunk/src/libaudacious/util.c | 25 +++++++++++++++++++++++++ + 2 files changed, 27 insertions(+) + + 2007-01-15 17:48:56 +0000 Giacomo Lozito <james@develia.org> revision [3688] - removed a couple of useless gdk calls in mainwin_real_hide()
--- a/src/audacious/Makefile Mon Jan 15 12:39:22 2007 -0800 +++ b/src/audacious/Makefile Mon Jan 15 18:33:42 2007 -0800 @@ -45,6 +45,7 @@ build_stamp.c \ vfs.c \ vfs_buffer.c \ + vfs_buffered_file.c \ vfs_common.c \ genevent.c \ util.c \
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/audacious/vfs_buffered_file.c Mon Jan 15 18:33:42 2007 -0800 @@ -0,0 +1,175 @@ +/* Audacious + * Copyright (c) 2006-2007 William Pitcock + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; under version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#include <glib.h> +#include <string.h> +#include "vfs.h" +#include "vfs_buffer.h" +#include "vfs_buffered_file.h" + +VFSFile * +buffered_file_vfs_fopen_impl(const gchar * path, + const gchar * mode) +{ + return NULL; +} + +gint +buffered_file_vfs_fclose_impl(VFSFile * file) +{ + g_return_val_if_fail(file != NULL, -1); + + if (file->handle) + { + VFSBufferedFile *handle = (VFSBufferedFile *) file->handle; + + vfs_fclose(handle->fd); + vfs_fclose(handle->buffer); + g_free(handle->mem); + g_free(handle); + } + + return 0; +} + +size_t +buffered_file_vfs_fread_impl(gpointer i_ptr, + size_t size, + size_t nmemb, + VFSFile * file) +{ + VFSBufferedFile *handle = (VFSBufferedFile *) file->handle; + + return vfs_fread(i_ptr, size, nmemb, handle->which == TRUE ? handle->fd : handle->buffer); +} + +size_t +buffered_file_vfs_fwrite_impl(gconstpointer i_ptr, + size_t size, + size_t nmemb, + VFSFile * file) +{ + VFSBufferedFile *handle = (VFSBufferedFile *) file->handle; + + return vfs_fwrite(i_ptr, size, nmemb, handle->fd); +} + +gint +buffered_file_vfs_getc_impl(VFSFile *stream) +{ + VFSBufferedFile *handle = (VFSBufferedFile *) stream->handle; + + return vfs_getc(handle->which == TRUE ? handle->fd : handle->buffer); +} + +gint +buffered_file_vfs_ungetc_impl(gint c, VFSFile *stream) +{ + return -1; +} + +gint +buffered_file_vfs_fseek_impl(VFSFile * file, + glong offset, + gint whence) +{ + VFSBufferedFile *handle = (VFSBufferedFile *) file->handle; + + vfs_fseek(handle->buffer, offset, whence); + + /* if we go OOB, switch to live FD */ + if (vfs_ftell(handle->buffer) > ((VFSBuffer *) handle->buffer->handle)->size) + { + vfs_rewind(handle->buffer); + handle->which = TRUE; + vfs_fseek(handle->buffer, offset, whence); + } + + return 0; +} + +void +buffered_file_vfs_rewind_impl(VFSFile * file) +{ + VFSBufferedFile *handle = (VFSBufferedFile *) file->handle; + + vfs_rewind(handle->buffer); + handle->which = FALSE; +} + +glong +buffered_file_vfs_ftell_impl(VFSFile * file) +{ + VFSBufferedFile *handle = (VFSBufferedFile *) file->handle; + + return vfs_ftell(handle->which == TRUE ? handle->fd : handle->buffer); +} + +gboolean +buffered_file_vfs_feof_impl(VFSFile * file) +{ + VFSBufferedFile *handle = (VFSBufferedFile *) file->handle; + + return vfs_feof(handle->which == TRUE ? handle->fd : handle->buffer); +} + +gint +buffered_file_vfs_truncate_impl(VFSFile * file, glong size) +{ + return 0; +} + +VFSConstructor buffered_file_const = { + NULL, // not a normal VFS class + buffered_file_vfs_fopen_impl, + buffered_file_vfs_fclose_impl, + buffered_file_vfs_fread_impl, + buffered_file_vfs_fwrite_impl, + buffered_file_vfs_getc_impl, + buffered_file_vfs_ungetc_impl, + buffered_file_vfs_fseek_impl, + buffered_file_vfs_rewind_impl, + buffered_file_vfs_ftell_impl, + buffered_file_vfs_feof_impl, + buffered_file_vfs_truncate_impl +}; + +VFSFile * +vfs_buffered_file_new_from_uri(gchar *uri) +{ + VFSFile *handle; + VFSBufferedFile *fd; + gsize sz; + + g_return_val_if_fail(uri != NULL, NULL); + + handle = g_new0(VFSFile, 1); + fd = g_new0(VFSBufferedFile, 1); + fd->mem = g_malloc0(32768); + fd->fd = vfs_fopen(uri, "rb"); + + sz = vfs_fread(fd->mem, 1, 32768, fd->fd); + + fd->buffer = vfs_buffer_new(fd->mem, sz); + + handle->handle = fd; + handle->base = &buffered_file_const; + + return handle; +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/audacious/vfs_buffered_file.h Mon Jan 15 18:33:42 2007 -0800 @@ -0,0 +1,57 @@ +/* Audacious + * Copyright (c) 2006-2007 William Pitcock + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; under version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#ifndef AUDACIOUS_VFS_BUFFERED_FILE_H +#define AUDACIOUS_VFS_BUFFERED_FILE_H + +#include <glib.h> +#include "vfs.h" +#include "vfs_buffer.h" + +G_BEGIN_DECLS + +/** + * VFSBufferedFile: + * @fd: The VFS handle for the active FD. + * @buffer: The first 32kb read from the FD. + * @mem: The memory for the buffer. + * @which: Whether to use the live FD or the buffer. + * + * Private data for the VFS memorybuffer class. + **/ + +typedef struct { + VFSFile *fd; + VFSFile *buffer; + gchar *mem; + gboolean which; +} VFSBufferedFile; + +/** + * vfs_buffered_file_new_from_uri: + * @uri: The location to read from. + * + * Creates a VFSBufferedFile. VFSBufferedFile is read-only. + * + * Return value: A VFSFile handle for the VFSBufferedFile. + **/ +VFSFile *vfs_buffered_file_new_from_uri(gchar *uri); + +G_END_DECLS + +#endif