changeset 461:cfd1b8a88e2d trunk

[svn] - updated amidi-plug to the new plugin API
author giacomo
date Fri, 19 Jan 2007 04:46:00 -0800
parents cc7faecc7619
children c488d191b528
files ChangeLog src/amidi-plug/amidi-plug.c src/amidi-plug/amidi-plug.h
diffstat 3 files changed, 86 insertions(+), 63 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Jan 18 18:52:45 2007 -0800
+++ b/ChangeLog	Fri Jan 19 04:46:00 2007 -0800
@@ -1,3 +1,11 @@
+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.
+  
+  trunk/src/curl/curl.c |   67 +++++++++++++++++++++++++++++++++++++-------------
+  1 file changed, 50 insertions(+), 17 deletions(-)
+
+
 2007-01-17 18:50:00 +0000  Jonathan Schleifer <js@h3c.de>
   revision [1002]
   D'oh, a 2 was missing.
--- a/src/amidi-plug/amidi-plug.c	Thu Jan 18 18:52:45 2007 -0800
+++ b/src/amidi-plug/amidi-plug.c	Fri Jan 19 04:46:00 2007 -0800
@@ -28,52 +28,67 @@
 }
 
 
-static gint amidiplug_is_our_file( gchar * filename )
+static gboolean amidiplug_detect_by_content( VFSFile * fp )
 {
-#if defined(MIDIFILE_PROBE_MAGICBYTES)
-    VFSFile * fp;
-    gchar magic_bytes[4];
+  gchar magic_bytes[4];
+  gint res = 0;
+
+  if ( fp == NULL )
+    return FALSE;
+
+  if ( VFS_FREAD( magic_bytes , 1 , 4 , fp ) != 4 )
+    return FALSE;
 
-    fp = VFS_FOPEN( filename , "rb" );
+  if ( !strncmp( magic_bytes , "MThd" , 4 ) )
+  {
+    DEBUGMSG( "MIDI found, %s is a standard midi file\n" , filename );
+    return TRUE;
+  }
 
-    if ( fp == NULL )
+  if ( !strncmp( magic_bytes , "RIFF" , 4 ) )
+  {
+    /* skip the four bytes after RIFF,
+       then read the next four */
+    if ( VFS_FSEEK( fp , 4 , SEEK_CUR ) != 0 )
       return FALSE;
 
-    VFS_FREAD( magic_bytes , 1 , 4 , fp );
+    if ( VFS_FREAD( magic_bytes , 1 , 4 , fp ) != 4 )
+      return FALSE;
 
-    if ( !strncmp( magic_bytes , "MThd" , 4 ) )
+    if ( !strncmp( magic_bytes , "RMID" , 4 ) )
     {
-      VFS_FCLOSE( fp );
-      DEBUGMSG( "MIDI found, %s is a standard midi file\n" , filename );
+      DEBUGMSG( "MIDI found, %s is a riff midi file\n" , filename );
       return TRUE;
     }
+  }
 
-    if ( !strncmp( magic_bytes , "RIFF" , 4 ) )
-    {
-      /* skip the four bytes after RIFF,
-         then read the next four */
-      VFS_FSEEK( fp , 4 , SEEK_CUR );
-      VFS_FREAD( magic_bytes , 1 , 4 , fp );
-      if ( !strncmp( magic_bytes , "RMID" , 4 ) )
-      {
-        VFS_FCLOSE( fp );
-        DEBUGMSG( "MIDI found, %s is a riff midi file\n" , filename );
-        return TRUE;
-      }
-    }
-    VFS_FCLOSE( fp );
-#else
-    gchar * ext = strrchr( filename, '.' );
-    /* check the filename extension */
-    if ( ( ext ) &&
-         (( !strcasecmp(ext,".mid") ) || ( !strcasecmp(ext,".midi") ) ||
-          ( !strcasecmp(ext,".rmi") ) || ( !strcasecmp(ext,".rmid") )) )
-      return TRUE;
-#endif
   return FALSE;
 }
 
 
+static gint amidiplug_is_our_file( gchar * filename )
+{
+  VFSFile * fp;
+  gboolean result = FALSE;
+
+  fp = VFS_FOPEN( filename , "rb" );
+
+  if ( fp == NULL )
+    return FALSE;
+
+  result = amidiplug_detect_by_content( fp );
+  VFS_FCLOSE( fp );
+
+  return result;
+}
+
+
+static gint amidiplug_is_our_file_from_vfs( gchar *filename , VFSFile *fp )
+{
+  return amidiplug_detect_by_content( fp );
+}
+
+
 static void amidiplug_init( void )
 {
   g_log_set_handler(NULL , G_LOG_LEVEL_WARNING , g_log_default_handler , NULL);
--- a/src/amidi-plug/amidi-plug.h	Thu Jan 18 18:52:45 2007 -0800
+++ b/src/amidi-plug/amidi-plug.h	Fri Jan 19 04:46:00 2007 -0800
@@ -39,12 +39,6 @@
 #include "i_utils.h"
 
 
-/* if this is defined, possible midi files are
-   checked by looking at their first (magic) bytes
-   instead of just reading the file extension */
-#define MIDIFILE_PROBE_MAGICBYTES 1
-
-
 static pthread_t amidiplug_play_thread;
 static pthread_t amidiplug_audio_thread;
 static pthread_mutex_t amidiplug_gettime_mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -67,6 +61,7 @@
   0		/* ap_opts_lyrics_extract */
 };
 
+gchar *amidiplug_vfs_extensions[] = { "mid" , "midi" , "rmi" , "rmid" , NULL };
 
 void * amidiplug_play_loop( void * );
 void * amidiplug_audio_loop( void * );
@@ -76,6 +71,7 @@
 static void amidiplug_aboutbox( void );
 static void amidiplug_configure( void );
 static gint amidiplug_is_our_file( gchar * );
+static gint amidiplug_is_our_file_from_vfs( gchar * , VFSFile * );
 static void amidiplug_play( gchar * );
 static void amidiplug_stop( void );
 static void amidiplug_pause( gshort );
@@ -88,31 +84,35 @@
 
 InputPlugin amidiplug_ip =
 {
-  NULL,				/* handle */
-  NULL,				/* filename */
-  NULL,				/* description */
-  amidiplug_init,		/* init */
-  amidiplug_aboutbox,		/* aboutbox */
-  amidiplug_configure,		/* configure */
-  amidiplug_is_our_file,	/* is_our_file */
-  NULL,				/* scan_dir */
-  amidiplug_play,		/* play_file */
-  amidiplug_stop,		/* stop */
-  amidiplug_pause,		/* pause */
-  amidiplug_seek,		/* seek */
-  NULL,				/* set_eq */
-  amidiplug_get_time,		/* get_time */
-  amidiplug_get_volume,		/* get_volume */
-  amidiplug_set_volume,		/* set_volume */
-  amidiplug_cleanup,		/* cleanup */
-  NULL,				/* get_vis_type */
-  NULL,				/* add_vis_pcm */
-  NULL,				/* set_info */
-  NULL,				/* set_info_text */
-  amidiplug_get_song_info,	/* get_song_info */
-  amidiplug_file_info_box,	/* file_info_box */
-  NULL,				/* output */
-  NULL				/* get_song_tuple */
+  NULL,					/* handle */
+  NULL,					/* filename */
+  NULL,					/* description */
+  amidiplug_init,			/* init */
+  amidiplug_aboutbox,			/* aboutbox */
+  amidiplug_configure,			/* configure */
+  amidiplug_is_our_file,		/* is_our_file */
+  NULL,					/* scan_dir */
+  amidiplug_play,			/* play_file */
+  amidiplug_stop,			/* stop */
+  amidiplug_pause,			/* pause */
+  amidiplug_seek,			/* seek */
+  NULL,					/* set_eq */
+  amidiplug_get_time,			/* get_time */
+  amidiplug_get_volume,			/* get_volume */
+  amidiplug_set_volume,			/* set_volume */
+  amidiplug_cleanup,			/* cleanup */
+  NULL,					/* get_vis_type */
+  NULL,					/* add_vis_pcm */
+  NULL,					/* set_info */
+  NULL,					/* set_info_text */
+  amidiplug_get_song_info,		/* get_song_info */
+  amidiplug_file_info_box,		/* file_info_box */
+  NULL,					/* output */
+  NULL,					/* get_song_tuple */
+  NULL,					/* set_song_tuple */
+  NULL,					/* set_status_buffering */
+  amidiplug_is_our_file_from_vfs,	/* is_our_file_from_vfs */
+  amidiplug_vfs_extensions		/* vfs_extensions */
 };
 
 #endif /* !_I_AMIDIPLUG_H */