Mercurial > audlegacy-plugins
changeset 1255:37598c8f4425
- Add flac_is_our_fd()
author | Ralf Ertzinger <ralf@skytale.net> |
---|---|
date | Thu, 12 Jul 2007 22:34:44 +0200 |
parents | 0e0f73fed025 |
children | 84b837791e36 |
files | src/flacng/plugin.c src/flacng/tools.c src/flacng/tools.h |
diffstat | 3 files changed, 45 insertions(+), 19 deletions(-) [+] |
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; }
--- a/src/flacng/tools.c Thu Jul 12 19:58:09 2007 +0200 +++ b/src/flacng/tools.c Thu Jul 12 22:34:44 2007 +0200 @@ -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 Thu Jul 12 19:58:09 2007 +0200 +++ b/src/flacng/tools.h Thu Jul 12 22:34:44 2007 +0200 @@ -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