From a6f8776c944a91202fcd20acb8c7c1f4aed90685 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 29 Oct 2008 16:12:26 +0100 Subject: mp3: moved code to mp3_time_to_frame() Break the large function mp3_read() into smaller pieces. --- src/decoder/mp3_plugin.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/decoder/mp3_plugin.c b/src/decoder/mp3_plugin.c index 29c0bde43..a4fd52738 100644 --- a/src/decoder/mp3_plugin.c +++ b/src/decoder/mp3_plugin.c @@ -820,6 +820,22 @@ mp3_open(struct input_stream *is, struct mp3_data *data, return true; } +static long +mp3_time_to_frame(const struct mp3_data *data, double t) +{ + unsigned long i; + + for (i = 0; i < data->highest_frame; ++i) { + double frame_time = + mad_timer_count(data->times[i], + MAD_UNITS_MILLISECONDS) / 1000.; + if (frame_time >= t) + break; + } + + return i; +} + static enum mp3_action mp3_read(struct mp3_data *data, ReplayGainInfo **replay_gain_info_r) { @@ -951,18 +967,12 @@ mp3_read(struct mp3_data *data, ReplayGainInfo **replay_gain_info_r) return DECODE_BREAK; if (decoder_get_command(decoder) == DECODE_COMMAND_SEEK) { - unsigned long j = 0; + unsigned long j; assert(data->input_stream->seekable); - data->mute_frame = MUTEFRAME_SEEK; - while (j < data->highest_frame && - decoder_seek_where(decoder) > - ((float)mad_timer_count(data->times[j], - MAD_UNITS_MILLISECONDS)) - / 1000) { - j++; - } + j = mp3_time_to_frame(data, + decoder_seek_where(decoder)); if (j < data->highest_frame) { if (mp3_seek(data, data->frame_offsets[j])) { decoder_clear(decoder); @@ -970,8 +980,8 @@ mp3_read(struct mp3_data *data, ReplayGainInfo **replay_gain_info_r) decoder_command_finished(decoder); } else decoder_seek_error(decoder); - data->mute_frame = MUTEFRAME_NONE; - } + } else + data->mute_frame = MUTEFRAME_SEEK; } } -- cgit v1.2.3