mp3: moved code to mp3_synth_and_send()
Break the large function mp3_read() into smaller pieces.
This commit is contained in:
parent
e0532ae0a8
commit
6158858f82
@ -912,34 +912,19 @@ mp3_send_pcm(struct mp3_data *data, unsigned i, unsigned pcm_length,
|
||||
return DECODE_COMMAND_NONE;
|
||||
}
|
||||
|
||||
static enum mp3_action
|
||||
mp3_read(struct mp3_data *data, ReplayGainInfo **replay_gain_info_r)
|
||||
/**
|
||||
* Synthesize the current frame and send it via decoder_data().
|
||||
*/
|
||||
static enum decoder_command
|
||||
mp3_synth_and_send(struct mp3_data *data, ReplayGainInfo *replay_gain_info)
|
||||
{
|
||||
struct decoder *decoder = data->decoder;
|
||||
unsigned int pcm_length;
|
||||
unsigned int i;
|
||||
int ret;
|
||||
int skip;
|
||||
unsigned i, pcm_length;
|
||||
enum decoder_command cmd;
|
||||
|
||||
mp3_update_timer_next_frame(data);
|
||||
|
||||
switch (data->mute_frame) {
|
||||
case MUTEFRAME_SKIP:
|
||||
data->mute_frame = MUTEFRAME_NONE;
|
||||
break;
|
||||
case MUTEFRAME_SEEK:
|
||||
if (decoder_seek_where(decoder) <= data->elapsed_time) {
|
||||
decoder_clear(decoder);
|
||||
data->mute_frame = MUTEFRAME_NONE;
|
||||
decoder_command_finished(decoder);
|
||||
}
|
||||
break;
|
||||
case MUTEFRAME_NONE:
|
||||
mad_synth_frame(&data->synth, &data->frame);
|
||||
|
||||
if (!data->found_first_frame) {
|
||||
unsigned int samples_per_frame = (data->synth).pcm.length;
|
||||
unsigned int samples_per_frame = data->synth.pcm.length;
|
||||
data->drop_start_frames = data->drop_start_samples / samples_per_frame;
|
||||
data->drop_end_frames = data->drop_end_samples / samples_per_frame;
|
||||
data->drop_start_samples = data->drop_start_samples % samples_per_frame;
|
||||
@ -949,12 +934,12 @@ mp3_read(struct mp3_data *data, ReplayGainInfo **replay_gain_info_r)
|
||||
|
||||
if (data->drop_start_frames > 0) {
|
||||
data->drop_start_frames--;
|
||||
break;
|
||||
return DECODE_COMMAND_NONE;
|
||||
} else if ((data->drop_end_frames > 0) &&
|
||||
(data->current_frame == (data->max_frames + 1 - data->drop_end_frames))) {
|
||||
/* stop decoding, effectively dropping all remaining
|
||||
* frames */
|
||||
return DECODE_BREAK;
|
||||
frames */
|
||||
return DECODE_COMMAND_STOP;
|
||||
}
|
||||
|
||||
if (data->input_stream->meta_title) {
|
||||
@ -985,16 +970,45 @@ mp3_read(struct mp3_data *data, ReplayGainInfo **replay_gain_info_r)
|
||||
pcm_length -= data->drop_end_samples;
|
||||
}
|
||||
|
||||
cmd = mp3_send_pcm(data, i, pcm_length,
|
||||
replay_gain_info_r != NULL
|
||||
? *replay_gain_info_r : NULL);
|
||||
cmd = mp3_send_pcm(data, i, pcm_length, replay_gain_info);
|
||||
if (cmd == DECODE_COMMAND_STOP)
|
||||
return DECODE_BREAK;
|
||||
return cmd;
|
||||
|
||||
if (data->drop_end_samples &&
|
||||
(data->current_frame == data->max_frames - data->drop_end_frames))
|
||||
/* stop decoding, effectively dropping
|
||||
* all remaining samples */
|
||||
return DECODE_COMMAND_STOP;
|
||||
|
||||
return DECODE_COMMAND_NONE;
|
||||
}
|
||||
|
||||
static enum mp3_action
|
||||
mp3_read(struct mp3_data *data, ReplayGainInfo **replay_gain_info_r)
|
||||
{
|
||||
struct decoder *decoder = data->decoder;
|
||||
int ret;
|
||||
int skip;
|
||||
enum decoder_command cmd;
|
||||
|
||||
mp3_update_timer_next_frame(data);
|
||||
|
||||
switch (data->mute_frame) {
|
||||
case MUTEFRAME_SKIP:
|
||||
data->mute_frame = MUTEFRAME_NONE;
|
||||
break;
|
||||
case MUTEFRAME_SEEK:
|
||||
if (decoder_seek_where(decoder) <= data->elapsed_time) {
|
||||
decoder_clear(decoder);
|
||||
data->mute_frame = MUTEFRAME_NONE;
|
||||
decoder_command_finished(decoder);
|
||||
}
|
||||
break;
|
||||
case MUTEFRAME_NONE:
|
||||
cmd = mp3_synth_and_send(data,
|
||||
replay_gain_info_r != NULL
|
||||
? *replay_gain_info_r : NULL);
|
||||
if (cmd == DECODE_COMMAND_STOP)
|
||||
return DECODE_BREAK;
|
||||
|
||||
if (decoder_get_command(decoder) == DECODE_COMMAND_SEEK) {
|
||||
|
Loading…
Reference in New Issue
Block a user