diff src/flacng/plugin.c @ 1255:37598c8f4425

- Add flac_is_our_fd()
author Ralf Ertzinger <ralf@skytale.net>
date Thu, 12 Jul 2007 22:34:44 +0200
parents 626f78ff2439
children 574ee15195f3
line wrap: on
line diff
--- a/src/flacng/plugin.c	Thu Jul 12 19:58:09 2007 +0200
+++ b/src/flacng/plugin.c	Thu Jul 12 22:34:44 2007 +0200
@@ -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(filename, "rb"))) {
+        _ERROR("Could not open file for reading! (%s)", filename);
+        _LEAVE;
+    }
+
+    if (FALSE == read_metadata(fd, main_decoder, main_info)) {
         _ERROR("Could not prepare file for playing!");
         _LEAVE;
     }