Mercurial > audlegacy-plugins
changeset 1272:47559538ce3d
- stop read_metadata from stomping on the wrong file descriptors
author | Ralf Ertzinger <ralf@skytale.net> |
---|---|
date | Sun, 15 Jul 2007 15:00:10 +0200 |
parents | 5fe8289b9aed |
children | 463729c87300 |
files | src/flacng/plugin.c src/flacng/seekable_stream_callbacks.c src/flacng/tools.c src/flacng/tools.h |
diffstat | 4 files changed, 19 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/src/flacng/plugin.c Fri Jul 13 21:31:17 2007 +0200 +++ b/src/flacng/plugin.c Sun Jul 15 15:00:10 2007 +0200 @@ -184,7 +184,7 @@ _LEAVE FALSE; } - _DEBUG("Testing file: %s", filename); + _DEBUG("Testing fd for file: %s", filename); if (FALSE == read_metadata(fd, test_decoder, test_info)) { _DEBUG("File not handled by this plugin!"); @@ -203,10 +203,7 @@ * If we get here, the file is supported by FLAC. * The stream characteristics have been filled in by * the metadata callback. - * Do not close the stream, though. */ - test_info->input_stream = NULL; - _DEBUG("Stream encoded at %d Hz, %d bps, %d channels", test_info->stream.samplerate, @@ -233,7 +230,7 @@ _DEBUG("Accepting file %s", filename); - reset_info(test_info); + reset_info(test_info, FALSE); _LEAVE TRUE; } @@ -683,7 +680,7 @@ _ERROR("Could not read file info!"); *length = -1; *title = g_strdup(""); - vfs_fclose(fd); + reset_info(test_info, TRUE); _LEAVE; } @@ -701,7 +698,7 @@ *length = l; *title = get_title(filename, test_info); - reset_info(test_info); + reset_info(test_info, TRUE); _LEAVE; } @@ -726,13 +723,13 @@ if (FALSE == read_metadata(fd, test_decoder, test_info)) { _ERROR("Could not read metadata tuple for file <%s>", filename); - vfs_fclose(fd); + reset_info(test_info, TRUE); _LEAVE NULL; } tuple = get_tuple(filename, test_info); - reset_info(test_info); + reset_info(test_info, TRUE); _LEAVE tuple; }
--- a/src/flacng/seekable_stream_callbacks.c Fri Jul 13 21:31:17 2007 +0200 +++ b/src/flacng/seekable_stream_callbacks.c Sun Jul 15 15:00:10 2007 +0200 @@ -116,7 +116,7 @@ if (-1 == (position = vfs_ftell(info->input_stream))) { _ERROR("Could not tell current position!"); - return FLAC__STREAM_DECODER_TELL_STATUS_ERROR; + _LEAVE FLAC__STREAM_DECODER_TELL_STATUS_ERROR; } _DEBUG("Current position: %ld", position); @@ -145,7 +145,7 @@ */ if (0 == info->read_max) { _DEBUG("read_max exhausted, faking EOF"); - return TRUE; + _LEAVE TRUE; } eof = vfs_feof(info->input_stream);
--- a/src/flacng/tools.c Fri Jul 13 21:31:17 2007 +0200 +++ b/src/flacng/tools.c Sun Jul 15 15:00:10 2007 +0200 @@ -64,7 +64,7 @@ info->replaygain.track_peak = NULL; info->replaygain.album_gain = NULL; info->replaygain.album_peak = NULL; - reset_info(info); + reset_info(info, FALSE); _DEBUG("Playback buffer allocated for %d samples, %d bytes", BUFFER_SIZE_SAMP, BUFFER_SIZE_BYTE); @@ -73,16 +73,17 @@ /* --- */ -void reset_info(callback_info* info) { +void reset_info(callback_info* info, gboolean close_fd) { _ENTER; _DEBUG("Using callback_info %s", info->name); - if (NULL != info->input_stream) { + if (close_fd && (NULL != info->input_stream)) { + _DEBUG("Closing fd"); vfs_fclose(info->input_stream); - info->input_stream = NULL; } + info->input_stream = NULL; // memset(info->output_buffer, 0, BUFFER_SIZE * sizeof(int16_t)); info->stream.samplerate = 0; @@ -180,6 +181,10 @@ _DEBUG("Using callback_info %s", info->name); + reset_info(info, FALSE); + + info->input_stream = fd; + /* * Reset the decoder */ @@ -188,10 +193,6 @@ _LEAVE FALSE; } - reset_info(info); - - info->input_stream = fd; - /* * Just scan the first 8k for the start of metadata */ @@ -212,8 +213,7 @@ _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); + reset_info(info, FALSE); _LEAVE FALSE; }
--- a/src/flacng/tools.h Fri Jul 13 21:31:17 2007 +0200 +++ b/src/flacng/tools.h Sun Jul 15 15:00:10 2007 +0200 @@ -25,7 +25,7 @@ #include "flac_compat.h" callback_info* init_callback_info(gchar* name); -void reset_info(callback_info* info); +void reset_info(callback_info* info, gboolean close_fd); 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);