changeset 1261:df8673a3e2f3

branch merge
author William Pitcock <nenolod@atheme-project.org>
date Fri, 13 Jul 2007 10:32:32 -0500
parents e1df1bad7837 (current diff) 690659633ec5 (diff)
children 0618841906ca
files
diffstat 5 files changed, 80 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/src/flacng/plugin.c	Fri Jul 13 08:04:43 2007 -0500
+++ b/src/flacng/plugin.c	Fri Jul 13 10:32:32 2007 -0500
@@ -57,7 +57,7 @@
     flac_get_song_tuple,	// get a tuple
     NULL,
     NULL,			// write a tuple back to a file as a tag
-/*    flac_is_our_fd */ NULL,	// version of is_our_file which is handed an FD
+    flac_is_our_fd,	// version of is_our_file which is handed an FD
     flac_fmts			// vector of fileextensions allowed by the plugin
 };
 
@@ -175,7 +175,7 @@
 
 /* --- */
 
-gboolean flac_is_our_file(gchar* filename) {
+gboolean flac_is_our_fd(gchar* filename, VFSFile* fd) {
 
     _ENTER;
 
@@ -186,7 +186,7 @@
 
     _DEBUG("Testing file: %s", filename);
 
-    if (FALSE == read_metadata(filename, test_decoder, test_info)) {
+    if (FALSE == read_metadata(fd, test_decoder, test_info)) {
         _DEBUG("File not handled by this plugin!");
         _LEAVE FALSE;
     }
@@ -203,10 +203,8 @@
      * If we get here, the file is supported by FLAC.
      * The stream characteristics have been filled in by
      * the metadata callback.
-     * We can close the stream now.
+     * Do not close the stream, though.
      */
-
-     vfs_fclose(test_info->input_stream);
      test_info->input_stream = NULL;
 
 
@@ -242,6 +240,31 @@
 
 /* --- */
 
+gboolean flac_is_our_file(gchar* filename) {
+
+    VFSFile* fd;
+    gboolean ret;
+
+    _ENTER;
+
+    _DEBUG("Testing file: %s", filename);
+    /*
+     * Open the file
+     */
+    if (NULL == (fd = vfs_fopen(filename, "rb"))) {
+        _ERROR("Could not open file for reading! (%s)", filename);
+        _LEAVE FALSE;
+    }
+
+    ret = flac_is_our_fd(filename, fd);
+
+    vfs_fclose(fd);
+
+    _LEAVE ret;
+}
+
+/* --- */
+
 void squeeze_audio(gint32* src, void* dst, guint count, guint src_res, guint dst_res) {
 
     /*
@@ -530,6 +553,7 @@
 
 void flac_play_file (InputPlayback* input) {
 
+    VFSFile* fd;
     gint l;
 
     _ENTER;
@@ -545,7 +569,15 @@
     input->playing = FALSE;
     xmms_usleep(20000);
 
-    if (FALSE == read_metadata(input->filename, main_decoder, main_info)) {
+    /*
+     * Open the file
+     */
+    if (NULL == (fd = vfs_fopen(input->filename, "rb"))) {
+        _ERROR("Could not open file for reading! (%s)", input->filename);
+        _LEAVE;
+    }
+
+    if (FALSE == read_metadata(fd, main_decoder, main_info)) {
         _ERROR("Could not prepare file for playing!");
         _LEAVE;
     }
@@ -634,13 +666,24 @@
 void flac_get_song_info(gchar* filename, gchar** title, gint* length) {
 
     gint l;
+    VFSFile* fd;
 
     _ENTER;
 
-    if (FALSE == read_metadata(filename, test_decoder, test_info)) {
+    _DEBUG("Testing file: %s", filename);
+    /*
+     * Open the file
+     */
+    if (NULL == (fd = vfs_fopen(filename, "rb"))) {
+        _ERROR("Could not open file for reading! (%s)", filename);
+        _LEAVE;
+    }
+
+    if (FALSE == read_metadata(fd, test_decoder, test_info)) {
         _ERROR("Could not read file info!");
         *length = -1;
         *title = g_strdup("");
+        vfs_fclose(fd);
         _LEAVE;
     }
 
@@ -667,12 +710,23 @@
 
 TitleInput *flac_get_song_tuple(gchar* filename) {
 
+    VFSFile *fd;
     TitleInput *tuple;
 
     _ENTER;
 
-    if (FALSE == read_metadata(filename, test_decoder, test_info)) {
+    _DEBUG("Testing file: %s", filename);
+    /*
+     * Open the file
+     */
+    if (NULL == (fd = vfs_fopen(filename, "rb"))) {
+        _ERROR("Could not open file for reading! (%s)", filename);
+        _LEAVE NULL;
+    }
+
+    if (FALSE == read_metadata(fd, test_decoder, test_info)) {
         _ERROR("Could not read metadata tuple for file <%s>", filename);
+        vfs_fclose(fd);
         _LEAVE NULL;
     }
 
--- a/src/flacng/plugin.h	Fri Jul 13 08:04:43 2007 -0500
+++ b/src/flacng/plugin.h	Fri Jul 13 10:32:32 2007 -0500
@@ -4,6 +4,7 @@
 void flac_init(void);
 void flac_aboutbox(void);
 gboolean flac_is_our_file(gchar* filename);
+gboolean flac_is_our_fd(gchar* filename, VFSFile* fd);
 void flac_play_file (InputPlayback* input);
 void flac_stop(InputPlayback* input);
 void flac_pause(InputPlayback* input, gshort p);
--- a/src/flacng/seekable_stream_callbacks.c	Fri Jul 13 08:04:43 2007 -0500
+++ b/src/flacng/seekable_stream_callbacks.c	Fri Jul 13 10:32:32 2007 -0500
@@ -138,6 +138,16 @@
     info = (callback_info*) client_data;
     _DEBUG("Using callback_info %s", info->name);
 
+    /*
+     * If we are testing a stream and use restricted reading,
+     * return EOF if we have exhausted our alotted reading
+     * quota
+     */
+    if (0 == info->read_max) {
+        _DEBUG("read_max exhausted, faking EOF");
+        return TRUE;
+    }
+
     eof = vfs_feof(info->input_stream);
 
     _LEAVE eof;
--- a/src/flacng/tools.c	Fri Jul 13 08:04:43 2007 -0500
+++ b/src/flacng/tools.c	Fri Jul 13 10:32:32 2007 -0500
@@ -172,7 +172,7 @@
 
 /* --- */
 
-gboolean read_metadata(gchar* filename, FLAC__StreamDecoder* decoder, callback_info* info) {
+gboolean read_metadata(VFSFile* fd, FLAC__StreamDecoder* decoder, callback_info* info) {
 
     FLAC__StreamDecoderState ret;
 
@@ -180,8 +180,6 @@
 
     _DEBUG("Using callback_info %s", info->name);
 
-    _DEBUG("Opening file %s", filename);
-
     /*
      * Reset the decoder
      */
@@ -192,6 +190,8 @@
 
     reset_info(info);
 
+    info->input_stream = fd;
+
     /*
      * Just scan the first 8k for the start of metadata
      */
@@ -205,20 +205,14 @@
     info->testing = TRUE;
 
     /*
-     * Open the file
-     */
-    if (NULL == (info->input_stream = vfs_fopen(filename, "rb"))) {
-        _ERROR("Could not open file for reading! (%s)", filename);
-        _LEAVE FALSE;
-    }
-
-    /*
      * Try to decode the metadata
      */
     if (false == FLAC__stream_decoder_process_until_end_of_metadata(decoder)) {
         ret = FLAC__stream_decoder_get_state(decoder);
         _DEBUG("Could not read the metadata: %s(%d)!",
                 FLAC__StreamDecoderStateString[ret], ret);
+        /* Do not close the filehandle, it was passed to us */
+        info->input_stream = NULL;
         reset_info(info);
         _LEAVE FALSE;
     }
--- a/src/flacng/tools.h	Fri Jul 13 08:04:43 2007 -0500
+++ b/src/flacng/tools.h	Fri Jul 13 10:32:32 2007 -0500
@@ -29,6 +29,6 @@
 gchar* get_title(const gchar* filename, callback_info* info);
 TitleInput *get_tuple(const gchar *filename, callback_info* info);
 void add_comment(callback_info* info, gchar* key, gchar* value);
-gboolean read_metadata(gchar* filename, FLAC__StreamDecoder* decoder, callback_info* info);
+gboolean read_metadata(VFSFile* fd, FLAC__StreamDecoder* decoder, callback_info* info);
 
 #endif