Mercurial > audlegacy-plugins
changeset 462:c488d191b528 trunk
[svn] - modified the sid plugin to use vfs, for both libsidplay v1 and v2; still requires testing and some work in the is_our_file part
author | giacomo |
---|---|
date | Fri, 19 Jan 2007 09:56:06 -0800 |
parents | cfd1b8a88e2d |
children | 1e5cb7a00cb0 |
files | ChangeLog src/sid/xmms-sid.c src/sid/xmms-sid.h src/sid/xs_sidplay.h src/sid/xs_sidplay1.cc src/sid/xs_sidplay2.cc |
diffstat | 6 files changed, 178 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Fri Jan 19 04:46:00 2007 -0800 +++ b/ChangeLog Fri Jan 19 09:56:06 2007 -0800 @@ -1,3 +1,11 @@ +2007-01-19 12:46:00 +0000 Giacomo Lozito <james@develia.org> + revision [1006] + - updated amidi-plug to the new plugin API + trunk/src/amidi-plug/amidi-plug.c | 79 ++++++++++++++++++++++---------------- + trunk/src/amidi-plug/amidi-plug.h | 62 ++++++++++++++--------------- + 2 files changed, 78 insertions(+), 63 deletions(-) + + 2007-01-19 02:52:45 +0000 Daniel Barkalow <barkalow@iabervon.org> revision [1004] Time out curl connections eventually, and don't retry them on the same VFSFile.
--- a/src/sid/xmms-sid.c Fri Jan 19 04:46:00 2007 -0800 +++ b/src/sid/xmms-sid.c Fri Jan 19 09:56:06 2007 -0800 @@ -162,6 +162,7 @@ xs_status.audioFormat = -1; xs_status.oversampleEnable = xs_cfg.oversampleEnable; xs_status.oversampleFactor = xs_cfg.oversampleFactor; + xs_status.buffer = NULL; /* Try to initialize emulator engine */ XSDEBUG("initializing emulator engine #%i...\n", xs_cfg.playerEngine);
--- a/src/sid/xmms-sid.h Fri Jan 19 04:46:00 2007 -0800 +++ b/src/sid/xmms-sid.h Fri Jan 19 09:56:06 2007 -0800 @@ -158,6 +158,7 @@ gint currSong, /* Current sub-tune */ lastTime; t_xs_tuneinfo *tuneInfo; + gchar *buffer; /* Added by Audacious, to store file content got via VFS */ } t_xs_status;
--- a/src/sid/xs_sidplay.h Fri Jan 19 04:46:00 2007 -0800 +++ b/src/sid/xs_sidplay.h Fri Jan 19 09:56:06 2007 -0800 @@ -11,12 +11,18 @@ TTUNE *testTune; gboolean haveInfo = TRUE; gint i; + gchar *buffer = NULL; + glong buffer_size = 0; + + if ( TBUFFGETFUNC( pcFilename , &buffer , &buffer_size ) != 0 ) + return NULL; /* Check if the tune exists and is readable */ - if ((testTune = new TTUNE(pcFilename)) == NULL) + if ((testTune = new TTUNE((TBUFFTYPEMEM)buffer,(TBUFFTYPESIZE)buffer_size)) == NULL) return NULL; if (!testTune->getStatus()) { + g_free( buffer ); delete testTune; return NULL; } @@ -40,6 +46,7 @@ tuneInfo.loadAddr, tuneInfo.initAddr, tuneInfo.playAddr, tuneInfo.dataFileLen); if (!pResult) { + g_free( buffer ); delete testTune; return NULL; } @@ -62,6 +69,7 @@ pResult->subTunes[i].tuneLength = -1; } + g_free( buffer ); delete testTune; return pResult; @@ -71,3 +79,6 @@ #undef TFUNCTION #undef TTUNEINFO #undef TTUNE +#undef TBUFFGETFUNC +#undef TBUFFTYPEMEM +#undef TBUFFTYPESIZE
--- a/src/sid/xs_sidplay1.cc Fri Jan 19 04:46:00 2007 -0800 +++ b/src/sid/xs_sidplay1.cc Fri Jan 19 09:56:06 2007 -0800 @@ -33,6 +33,7 @@ #include <sidplay/player.h> #include <sidplay/myendian.h> #include <sidplay/fformat.h> +#include <audacious/vfs.h> typedef struct @@ -48,21 +49,78 @@ { +static gboolean xs_sidplay1_detect_by_content( VFSFile * fp ) +{ + gchar magic_bytes[4]; + gboolean res = FALSE; + + if ( fp == NULL ) + return FALSE; + + if ( vfs_fread( magic_bytes , 1 , 4 , fp ) != 4 ) + return FALSE; + + if ( !strncmp( magic_bytes , "PSID" , 4 ) ) + return TRUE; + else + return FALSE; + return FALSE; +} + + +static gint xs_sidplay1_load_file_in_buffer( gchar * pcFilename , gchar ** buffer , glong * buffer_size ) +{ + VFSFile *fp; + + if ( *buffer != NULL ) { + g_free( *buffer ); + *buffer = NULL; + } + + fp = vfs_fopen( pcFilename , "rb" ); + + if ( fp == NULL ) + return -1; + + vfs_fseek( fp , 0 , SEEK_END ); + *buffer_size = vfs_ftell( fp ); + + if ( *buffer_size > 0 ) + { + glong readsize; + *buffer = (gchar*)g_malloc(*buffer_size); + vfs_fseek( fp , 0 , SEEK_SET ); + readsize = vfs_fread( *buffer , 1 , *buffer_size , fp ); + vfs_fclose( fp ); + if ( readsize != *buffer_size ) + return -1; + else + return 0; + } + else + { + vfs_fclose( fp ); + return -1; + } +} + + /* Check if we can play the given file */ gboolean xs_sidplay1_isourfile(gchar * pcFilename) { - sidTune *testTune = new sidTune(pcFilename); + VFSFile * fp; + gboolean result = FALSE; - if (!testTune) return FALSE; + fp = vfs_fopen( pcFilename , "rb" ); - if (!testTune->getStatus()) { - delete testTune; - return FALSE; - } + if ( fp == NULL ) + return FALSE; - delete testTune; - return TRUE; + result = xs_sidplay1_detect_by_content( fp ); + vfs_fclose( fp ); + + return result; } @@ -248,6 +306,11 @@ g_free(myEngine); myStatus->sidEngine = NULL; + + if ( myStatus->buffer != NULL ) { + g_free(myStatus->buffer); + myStatus->buffer = NULL; + } } @@ -298,6 +361,7 @@ t_xs_sidplay1 *myEngine; sidTune *newTune; assert(myStatus); + glong buffer_size = 0; myEngine = (t_xs_sidplay1 *) myStatus->sidEngine; if (!myEngine) return FALSE; @@ -305,7 +369,10 @@ /* Try to load the file/tune */ if (!pcFilename) return FALSE; - newTune = new sidTune(pcFilename); + if ( xs_sidplay1_load_file_in_buffer( pcFilename , &myStatus->buffer , &buffer_size ) != 0 ) + return FALSE; + + newTune = new sidTune((ubyte*)myStatus->buffer,(udword)buffer_size); if (!newTune) return FALSE; myEngine->currTune = newTune; @@ -336,6 +403,9 @@ #define TFUNCTION xs_sidplay1_getsidinfo #define TTUNEINFO sidTuneInfo #define TTUNE sidTune +#define TBUFFGETFUNC xs_sidplay1_load_file_in_buffer +#define TBUFFTYPEMEM ubyte* +#define TBUFFTYPESIZE udword #include "xs_sidplay.h" } /* extern "C" */
--- a/src/sid/xs_sidplay2.cc Fri Jan 19 04:46:00 2007 -0800 +++ b/src/sid/xs_sidplay2.cc Fri Jan 19 09:56:06 2007 -0800 @@ -38,6 +38,7 @@ #ifdef HAVE_HARDSID_BUILDER #include <sidplay/builders/hardsid.h> #endif +#include <audacious/vfs.h> typedef struct @@ -53,22 +54,78 @@ extern "C" { +static gboolean xs_sidplay2_detect_by_content( VFSFile * fp ) +{ + gchar magic_bytes[4]; + gboolean res = FALSE; + + if ( fp == NULL ) + return FALSE; + + if ( vfs_fread( magic_bytes , 1 , 4 , fp ) != 4 ) + return FALSE; + + if ( !strncmp( magic_bytes , "PSID" , 4 ) ) + return TRUE; + else + return FALSE; + return FALSE; +} + + +static gint xs_sidplay2_load_file_in_buffer( gchar * pcFilename , gchar ** buffer , glong * buffer_size ) +{ + VFSFile *fp; + + if ( *buffer != NULL ) { + g_free( *buffer ); + *buffer = NULL; + } + + fp = vfs_fopen( pcFilename , "rb" ); + + if ( fp == NULL ) + return -1; + + vfs_fseek( fp , 0 , SEEK_END ); + *buffer_size = vfs_ftell( fp ); + + if ( *buffer_size > 0 ) + { + glong readsize; + *buffer = (gchar*)g_malloc(*buffer_size); + vfs_fseek( fp , 0 , SEEK_SET ); + readsize = vfs_fread( *buffer , 1 , *buffer_size , fp ); + vfs_fclose( fp ); + if ( readsize != *buffer_size ) + return -1; + else + return 0; + } + else + { + vfs_fclose( fp ); + return -1; + } +} + /* Check if we can play the given file */ gboolean xs_sidplay2_isourfile(gchar * pcFilename) { - SidTune *testTune = new SidTune(pcFilename); + VFSFile * fp; + gboolean result = FALSE; - if (!testTune) return FALSE; + fp = vfs_fopen( pcFilename , "rb" ); - if (!testTune->getStatus()) { - delete testTune; + if ( fp == NULL ) return FALSE; - } - delete testTune; - return TRUE; + result = xs_sidplay2_detect_by_content( fp ); + vfs_fclose( fp ); + + return result; } @@ -344,6 +401,11 @@ g_free(myEngine); myStatus->sidEngine = NULL; + + if ( myStatus->buffer != NULL ) { + g_free(myStatus->buffer); + myStatus->buffer = NULL; + } } @@ -391,6 +453,7 @@ { t_xs_sidplay2 *myEngine; assert(myStatus); + glong buffer_size = 0; myEngine = (t_xs_sidplay2 *) myStatus->sidEngine; if (!myEngine) return FALSE; @@ -398,7 +461,10 @@ /* Try to get the tune */ if (!pcFilename) return FALSE; - if (!myEngine->currTune->load(pcFilename)) + if ( xs_sidplay2_load_file_in_buffer( pcFilename , &myStatus->buffer , &buffer_size ) != 0 ) + return FALSE; + + if (!myEngine->currTune->read((uint_least8_t*)myStatus->buffer,(uint_least32_t)buffer_size)) return FALSE; return TRUE; @@ -420,6 +486,9 @@ #define TFUNCTION xs_sidplay2_getsidinfo #define TTUNEINFO SidTuneInfo #define TTUNE SidTune +#define TBUFFGETFUNC xs_sidplay2_load_file_in_buffer +#define TBUFFTYPEMEM uint_least8_t* +#define TBUFFTYPESIZE uint_least32_t #include "xs_sidplay.h" } /* extern "C" */