decoder_api: pass "seekable" flag to decoder_initialized()

Don't pass the "seekable" flag with every decoder_data() invocation.
Since that flag won't change within the file, it is enough to pass it
to decoder_initialized() once per file.
This commit is contained in:
Max Kellermann 2008-11-02 17:01:51 +01:00
parent c7a374bdcb
commit c9e15bc418
15 changed files with 37 additions and 44 deletions

View File

@ -300,7 +300,7 @@ flac_common_write(FlacData *data, const FLAC__Frame * frame,
c_samp, c_samp + num_samples);
cmd = decoder_data(data->decoder, data->inStream,
1, data->chunk,
data->chunk,
num_samples * bytes_per_channel,
data->time, data->bitRate,
data->replayGainInfo);

View File

@ -391,7 +391,8 @@ aac_stream_decode(struct decoder *mpd_decoder, struct input_stream *inStream)
if (!initialized) {
audio_format.channels = frameInfo.channels;
audio_format.sample_rate = sample_rate;
decoder_initialized(mpd_decoder, &audio_format, totalTime);
decoder_initialized(mpd_decoder, &audio_format,
false, totalTime);
initialized = true;
}
@ -410,7 +411,7 @@ aac_stream_decode(struct decoder *mpd_decoder, struct input_stream *inStream)
sampleBufferLen = sampleCount * 2;
decoder_data(mpd_decoder, NULL, 0, sampleBuffer,
decoder_data(mpd_decoder, NULL, sampleBuffer,
sampleBufferLen, file_time,
bitRate, NULL);
if (decoder_get_command(mpd_decoder) == DECODE_COMMAND_SEEK) {
@ -527,7 +528,7 @@ aac_decode(struct decoder *mpd_decoder, const char *path)
audio_format.channels = frameInfo.channels;
audio_format.sample_rate = sample_rate;
decoder_initialized(mpd_decoder, &audio_format,
totalTime);
false, totalTime);
initialized = true;
}
@ -546,7 +547,7 @@ aac_decode(struct decoder *mpd_decoder, const char *path)
sampleBufferLen = sampleCount * 2;
decoder_data(mpd_decoder, NULL, 0, sampleBuffer,
decoder_data(mpd_decoder, NULL, sampleBuffer,
sampleBufferLen, file_time,
bitRate, NULL);
if (decoder_get_command(mpd_decoder) == DECODE_COMMAND_SEEK) {

View File

@ -89,7 +89,7 @@ audiofile_decode(struct decoder *decoder, const char *path)
fs = (int)afGetVirtualFrameSize(af_fp, AF_DEFAULT_TRACK, 1);
decoder_initialized(decoder, &audio_format, total_time);
decoder_initialized(decoder, &audio_format, true, total_time);
do {
if (decoder_get_command(decoder) == DECODE_COMMAND_SEEK) {
@ -105,7 +105,7 @@ audiofile_decode(struct decoder *decoder, const char *path)
break;
current += ret;
decoder_data(decoder, NULL, 1,
decoder_data(decoder, NULL,
chunk, ret * fs,
(float)current / (float)audio_format.sample_rate,
bitRate, NULL);

View File

@ -239,7 +239,7 @@ ffmpeg_send_packet(struct decoder *decoder, struct input_stream *is,
assert(audio_size >= 0);
return decoder_data(decoder, is, is->seekable,
return decoder_data(decoder, is,
audio_buf, audio_size,
position,
codec_context->bit_rate / 1000, NULL);
@ -271,7 +271,8 @@ ffmpeg_decode_internal(BasePtrs *base)
total_time = pFormatCtx->duration / AV_TIME_BASE;
}
decoder_initialized(decoder, &audio_format, total_time);
decoder_initialized(decoder, &audio_format,
base->input->seekable, total_time);
do {
if (av_read_frame(pFormatCtx, &packet) < 0)

View File

@ -341,7 +341,8 @@ flac_decode_internal(struct decoder * decoder, struct input_stream *inStream,
}
}
decoder_initialized(decoder, &data.audio_format, data.total_time);
decoder_initialized(decoder, &data.audio_format,
inStream->seekable, data.total_time);
while (true) {
if (!flac_process_single(flacDec))

View File

@ -197,7 +197,7 @@ mod_decode(struct decoder *decoder, const char *path)
1.0 / ((audio_format.bits * audio_format.channels / 8.0) *
(float)audio_format.sample_rate);
decoder_initialized(decoder, &audio_format, 0);
decoder_initialized(decoder, &audio_format, false, 0);
while (true) {
if (decoder_get_command(decoder) == DECODE_COMMAND_SEEK) {
@ -212,7 +212,7 @@ mod_decode(struct decoder *decoder, const char *path)
ret = VC_WriteBytes(data->audio_buffer, MIKMOD_FRAME_SIZE);
total_time += ret * secPerByte;
decoder_data(decoder, NULL, 0,
decoder_data(decoder, NULL,
(char *)data->audio_buffer, ret,
total_time, 0, NULL);
}

View File

@ -900,7 +900,6 @@ mp3_send_pcm(struct mp3_data *data, unsigned i, unsigned pcm_length,
num_samples *= MAD_NCHANNELS(&(data->frame).header);
cmd = decoder_data(data->decoder, data->input_stream,
data->input_stream->seekable,
data->output_buffer,
sizeof(data->output_buffer[0]) * num_samples,
data->elapsed_time,
@ -1108,7 +1107,8 @@ mp3_decode(struct decoder *decoder, struct input_stream *input_stream)
tag_free(tag);
}
decoder_initialized(decoder, &audio_format, data.total_time);
decoder_initialized(decoder, &audio_format,
data.input_stream->seekable, data.total_time);
while (mp3_read(&data, &replay_gain_info)) ;

View File

@ -258,7 +258,7 @@ mp4_decode(struct decoder *mpd_decoder, struct input_stream *inStream)
audio_format.sample_rate = scale;
audio_format.channels = frameInfo.channels;
decoder_initialized(mpd_decoder, &audio_format,
total_time);
inStream->seekable, total_time);
initialized = true;
}
@ -280,7 +280,7 @@ mp4_decode(struct decoder *mpd_decoder, struct input_stream *inStream)
sampleBuffer += offset * channels * 2;
decoder_data(mpd_decoder, inStream, 1, sampleBuffer,
decoder_data(mpd_decoder, inStream, sampleBuffer,
sampleBufferLen, file_time,
bitRate, NULL);
if (decoder_get_command(mpd_decoder) == DECODE_COMMAND_STOP)

View File

@ -163,6 +163,7 @@ mpc_decode(struct decoder *mpd_decoder, struct input_stream *inStream)
replayGainInfo->trackPeak = info.peak_title / 32767.0;
decoder_initialized(mpd_decoder, &audio_format,
inStream->seekable,
mpc_streaminfo_get_length(&info));
while (!eof) {
@ -204,7 +205,6 @@ mpc_decode(struct decoder *mpd_decoder, struct input_stream *inStream)
audio_format.sample_rate / 1152 / 1000;
decoder_data(mpd_decoder, inStream,
inStream->seekable,
chunk, chunkpos,
total_time,
bitRate, replayGainInfo);
@ -226,7 +226,7 @@ mpc_decode(struct decoder *mpd_decoder, struct input_stream *inStream)
bitRate =
vbrUpdateBits * audio_format.sample_rate / 1152 / 1000;
decoder_data(mpd_decoder, NULL, inStream->seekable,
decoder_data(mpd_decoder, NULL,
chunk, chunkpos, total_time, bitRate,
replayGainInfo);
}

View File

@ -303,7 +303,8 @@ oggflac_decode(struct decoder * mpd_decoder, struct input_stream *inStream)
goto fail;
}
decoder_initialized(mpd_decoder, &data.audio_format, data.total_time);
decoder_initialized(mpd_decoder, &data.audio_format,
inStream->seekable, data.total_time);
while (true) {
OggFLAC__seekable_stream_decoder_process_single(decoder);

View File

@ -279,6 +279,7 @@ oggvorbis_decode(struct decoder *decoder, struct input_stream *inStream)
if (total_time < 0)
total_time = 0;
decoder_initialized(decoder, &audio_format,
inStream->seekable,
total_time);
initialized = true;
}
@ -304,7 +305,6 @@ oggvorbis_decode(struct decoder *decoder, struct input_stream *inStream)
bitRate = test / 1000;
}
decoder_data(decoder, inStream,
inStream->seekable,
chunk, chunkpos,
ov_pcm_tell(&vf) / audio_format.sample_rate,
bitRate, replayGainInfo);
@ -316,7 +316,7 @@ oggvorbis_decode(struct decoder *decoder, struct input_stream *inStream)
if (decoder_get_command(decoder) == DECODE_COMMAND_NONE &&
chunkpos > 0) {
decoder_data(decoder, NULL, inStream->seekable,
decoder_data(decoder, NULL,
chunk, chunkpos,
ov_time_tell(&vf), bitRate,
replayGainInfo);

View File

@ -164,7 +164,7 @@ static void wavpack_decode(struct decoder * decoder,
samplesreq = sizeof(chunk) / (4 * audio_format.channels);
decoder_initialized(decoder, &audio_format,
decoder_initialized(decoder, &audio_format, false,
(float)allsamples / audio_format.sample_rate);
position = 0;
@ -200,7 +200,7 @@ static void wavpack_decode(struct decoder * decoder,
format_samples(Bps, chunk,
samplesgot * audio_format.channels);
decoder_data(decoder, NULL, 0, chunk,
decoder_data(decoder, NULL, chunk,
samplesgot * outsamplesize,
file_time, bitrate,
replayGainInfo);

View File

@ -32,7 +32,7 @@
void decoder_initialized(struct decoder * decoder,
const struct audio_format *audio_format,
float total_time)
bool seekable, float total_time)
{
assert(dc.state == DECODE_STATE_START);
assert(audio_format != NULL);
@ -42,6 +42,7 @@ void decoder_initialized(struct decoder * decoder,
dc.in_audio_format = *audio_format;
getOutputAudioFormat(audio_format, &dc.out_audio_format);
dc.seekable = seekable;
dc.totalTime = total_time;
dc.state = DECODE_STATE_DECODE;
@ -121,19 +122,11 @@ size_t decoder_read(struct decoder *decoder,
* one.
*/
static enum decoder_command
need_chunks(struct decoder *decoder,
struct input_stream *inStream, int seekable)
need_chunks(struct input_stream *inStream)
{
if (dc.command == DECODE_COMMAND_STOP)
return DECODE_COMMAND_STOP;
if (dc.command == DECODE_COMMAND_SEEK) {
if (seekable) {
return DECODE_COMMAND_SEEK;
} else {
decoder_seek_error(decoder);
}
}
if (dc.command == DECODE_COMMAND_STOP ||
dc.command == DECODE_COMMAND_SEEK)
return dc.command;
if (!inStream ||
input_stream_buffer(inStream) <= 0) {
@ -146,7 +139,7 @@ need_chunks(struct decoder *decoder,
enum decoder_command
decoder_data(struct decoder *decoder,
struct input_stream *inStream, int seekable,
struct input_stream *inStream,
void *dataIn, size_t dataInLen,
float data_time, uint16_t bitRate,
ReplayGainInfo * replayGainInfo)
@ -189,8 +182,7 @@ decoder_data(struct decoder *decoder,
data += nbytes;
if (datalen > 0) {
enum decoder_command cmd =
need_chunks(decoder, inStream, seekable);
enum decoder_command cmd = need_chunks(inStream);
if (cmd != DECODE_COMMAND_NONE)
return cmd;
}

View File

@ -116,7 +116,7 @@ struct decoder;
*/
void decoder_initialized(struct decoder * decoder,
const struct audio_format *audio_format,
float total_time);
bool seekable, float total_time);
const char *decoder_get_url(struct decoder * decoder, char * buffer);
@ -151,7 +151,7 @@ size_t decoder_read(struct decoder *decoder,
*/
enum decoder_command
decoder_data(struct decoder *decoder,
struct input_stream *inStream, int seekable,
struct input_stream *inStream,
void *data, size_t datalen, float data_time, uint16_t bitRate,
ReplayGainInfo * replayGainInfo);

View File

@ -76,9 +76,6 @@ static void decodeStart(void)
}
}
/* for http streams, seekable is determined in input_stream_buffer */
dc.seekable = inStream.seekable;
if (dc.command == DECODE_COMMAND_STOP) {
input_stream_close(&inStream);
return;