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:
parent
c7a374bdcb
commit
c9e15bc418
@ -300,7 +300,7 @@ flac_common_write(FlacData *data, const FLAC__Frame * frame,
|
|||||||
c_samp, c_samp + num_samples);
|
c_samp, c_samp + num_samples);
|
||||||
|
|
||||||
cmd = decoder_data(data->decoder, data->inStream,
|
cmd = decoder_data(data->decoder, data->inStream,
|
||||||
1, data->chunk,
|
data->chunk,
|
||||||
num_samples * bytes_per_channel,
|
num_samples * bytes_per_channel,
|
||||||
data->time, data->bitRate,
|
data->time, data->bitRate,
|
||||||
data->replayGainInfo);
|
data->replayGainInfo);
|
||||||
|
@ -391,7 +391,8 @@ aac_stream_decode(struct decoder *mpd_decoder, struct input_stream *inStream)
|
|||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
audio_format.channels = frameInfo.channels;
|
audio_format.channels = frameInfo.channels;
|
||||||
audio_format.sample_rate = sample_rate;
|
audio_format.sample_rate = sample_rate;
|
||||||
decoder_initialized(mpd_decoder, &audio_format, totalTime);
|
decoder_initialized(mpd_decoder, &audio_format,
|
||||||
|
false, totalTime);
|
||||||
initialized = true;
|
initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -410,7 +411,7 @@ aac_stream_decode(struct decoder *mpd_decoder, struct input_stream *inStream)
|
|||||||
|
|
||||||
sampleBufferLen = sampleCount * 2;
|
sampleBufferLen = sampleCount * 2;
|
||||||
|
|
||||||
decoder_data(mpd_decoder, NULL, 0, sampleBuffer,
|
decoder_data(mpd_decoder, NULL, sampleBuffer,
|
||||||
sampleBufferLen, file_time,
|
sampleBufferLen, file_time,
|
||||||
bitRate, NULL);
|
bitRate, NULL);
|
||||||
if (decoder_get_command(mpd_decoder) == DECODE_COMMAND_SEEK) {
|
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.channels = frameInfo.channels;
|
||||||
audio_format.sample_rate = sample_rate;
|
audio_format.sample_rate = sample_rate;
|
||||||
decoder_initialized(mpd_decoder, &audio_format,
|
decoder_initialized(mpd_decoder, &audio_format,
|
||||||
totalTime);
|
false, totalTime);
|
||||||
initialized = true;
|
initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -546,7 +547,7 @@ aac_decode(struct decoder *mpd_decoder, const char *path)
|
|||||||
|
|
||||||
sampleBufferLen = sampleCount * 2;
|
sampleBufferLen = sampleCount * 2;
|
||||||
|
|
||||||
decoder_data(mpd_decoder, NULL, 0, sampleBuffer,
|
decoder_data(mpd_decoder, NULL, sampleBuffer,
|
||||||
sampleBufferLen, file_time,
|
sampleBufferLen, file_time,
|
||||||
bitRate, NULL);
|
bitRate, NULL);
|
||||||
if (decoder_get_command(mpd_decoder) == DECODE_COMMAND_SEEK) {
|
if (decoder_get_command(mpd_decoder) == DECODE_COMMAND_SEEK) {
|
||||||
|
@ -89,7 +89,7 @@ audiofile_decode(struct decoder *decoder, const char *path)
|
|||||||
|
|
||||||
fs = (int)afGetVirtualFrameSize(af_fp, AF_DEFAULT_TRACK, 1);
|
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 {
|
do {
|
||||||
if (decoder_get_command(decoder) == DECODE_COMMAND_SEEK) {
|
if (decoder_get_command(decoder) == DECODE_COMMAND_SEEK) {
|
||||||
@ -105,7 +105,7 @@ audiofile_decode(struct decoder *decoder, const char *path)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
current += ret;
|
current += ret;
|
||||||
decoder_data(decoder, NULL, 1,
|
decoder_data(decoder, NULL,
|
||||||
chunk, ret * fs,
|
chunk, ret * fs,
|
||||||
(float)current / (float)audio_format.sample_rate,
|
(float)current / (float)audio_format.sample_rate,
|
||||||
bitRate, NULL);
|
bitRate, NULL);
|
||||||
|
@ -239,7 +239,7 @@ ffmpeg_send_packet(struct decoder *decoder, struct input_stream *is,
|
|||||||
|
|
||||||
assert(audio_size >= 0);
|
assert(audio_size >= 0);
|
||||||
|
|
||||||
return decoder_data(decoder, is, is->seekable,
|
return decoder_data(decoder, is,
|
||||||
audio_buf, audio_size,
|
audio_buf, audio_size,
|
||||||
position,
|
position,
|
||||||
codec_context->bit_rate / 1000, NULL);
|
codec_context->bit_rate / 1000, NULL);
|
||||||
@ -271,7 +271,8 @@ ffmpeg_decode_internal(BasePtrs *base)
|
|||||||
total_time = pFormatCtx->duration / AV_TIME_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 {
|
do {
|
||||||
if (av_read_frame(pFormatCtx, &packet) < 0)
|
if (av_read_frame(pFormatCtx, &packet) < 0)
|
||||||
|
@ -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) {
|
while (true) {
|
||||||
if (!flac_process_single(flacDec))
|
if (!flac_process_single(flacDec))
|
||||||
|
@ -197,7 +197,7 @@ mod_decode(struct decoder *decoder, const char *path)
|
|||||||
1.0 / ((audio_format.bits * audio_format.channels / 8.0) *
|
1.0 / ((audio_format.bits * audio_format.channels / 8.0) *
|
||||||
(float)audio_format.sample_rate);
|
(float)audio_format.sample_rate);
|
||||||
|
|
||||||
decoder_initialized(decoder, &audio_format, 0);
|
decoder_initialized(decoder, &audio_format, false, 0);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (decoder_get_command(decoder) == DECODE_COMMAND_SEEK) {
|
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);
|
ret = VC_WriteBytes(data->audio_buffer, MIKMOD_FRAME_SIZE);
|
||||||
total_time += ret * secPerByte;
|
total_time += ret * secPerByte;
|
||||||
decoder_data(decoder, NULL, 0,
|
decoder_data(decoder, NULL,
|
||||||
(char *)data->audio_buffer, ret,
|
(char *)data->audio_buffer, ret,
|
||||||
total_time, 0, NULL);
|
total_time, 0, NULL);
|
||||||
}
|
}
|
||||||
|
@ -900,7 +900,6 @@ mp3_send_pcm(struct mp3_data *data, unsigned i, unsigned pcm_length,
|
|||||||
num_samples *= MAD_NCHANNELS(&(data->frame).header);
|
num_samples *= MAD_NCHANNELS(&(data->frame).header);
|
||||||
|
|
||||||
cmd = decoder_data(data->decoder, data->input_stream,
|
cmd = decoder_data(data->decoder, data->input_stream,
|
||||||
data->input_stream->seekable,
|
|
||||||
data->output_buffer,
|
data->output_buffer,
|
||||||
sizeof(data->output_buffer[0]) * num_samples,
|
sizeof(data->output_buffer[0]) * num_samples,
|
||||||
data->elapsed_time,
|
data->elapsed_time,
|
||||||
@ -1108,7 +1107,8 @@ mp3_decode(struct decoder *decoder, struct input_stream *input_stream)
|
|||||||
tag_free(tag);
|
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)) ;
|
while (mp3_read(&data, &replay_gain_info)) ;
|
||||||
|
|
||||||
|
@ -258,7 +258,7 @@ mp4_decode(struct decoder *mpd_decoder, struct input_stream *inStream)
|
|||||||
audio_format.sample_rate = scale;
|
audio_format.sample_rate = scale;
|
||||||
audio_format.channels = frameInfo.channels;
|
audio_format.channels = frameInfo.channels;
|
||||||
decoder_initialized(mpd_decoder, &audio_format,
|
decoder_initialized(mpd_decoder, &audio_format,
|
||||||
total_time);
|
inStream->seekable, total_time);
|
||||||
initialized = true;
|
initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -280,7 +280,7 @@ mp4_decode(struct decoder *mpd_decoder, struct input_stream *inStream)
|
|||||||
|
|
||||||
sampleBuffer += offset * channels * 2;
|
sampleBuffer += offset * channels * 2;
|
||||||
|
|
||||||
decoder_data(mpd_decoder, inStream, 1, sampleBuffer,
|
decoder_data(mpd_decoder, inStream, sampleBuffer,
|
||||||
sampleBufferLen, file_time,
|
sampleBufferLen, file_time,
|
||||||
bitRate, NULL);
|
bitRate, NULL);
|
||||||
if (decoder_get_command(mpd_decoder) == DECODE_COMMAND_STOP)
|
if (decoder_get_command(mpd_decoder) == DECODE_COMMAND_STOP)
|
||||||
|
@ -163,6 +163,7 @@ mpc_decode(struct decoder *mpd_decoder, struct input_stream *inStream)
|
|||||||
replayGainInfo->trackPeak = info.peak_title / 32767.0;
|
replayGainInfo->trackPeak = info.peak_title / 32767.0;
|
||||||
|
|
||||||
decoder_initialized(mpd_decoder, &audio_format,
|
decoder_initialized(mpd_decoder, &audio_format,
|
||||||
|
inStream->seekable,
|
||||||
mpc_streaminfo_get_length(&info));
|
mpc_streaminfo_get_length(&info));
|
||||||
|
|
||||||
while (!eof) {
|
while (!eof) {
|
||||||
@ -204,7 +205,6 @@ mpc_decode(struct decoder *mpd_decoder, struct input_stream *inStream)
|
|||||||
audio_format.sample_rate / 1152 / 1000;
|
audio_format.sample_rate / 1152 / 1000;
|
||||||
|
|
||||||
decoder_data(mpd_decoder, inStream,
|
decoder_data(mpd_decoder, inStream,
|
||||||
inStream->seekable,
|
|
||||||
chunk, chunkpos,
|
chunk, chunkpos,
|
||||||
total_time,
|
total_time,
|
||||||
bitRate, replayGainInfo);
|
bitRate, replayGainInfo);
|
||||||
@ -226,7 +226,7 @@ mpc_decode(struct decoder *mpd_decoder, struct input_stream *inStream)
|
|||||||
bitRate =
|
bitRate =
|
||||||
vbrUpdateBits * audio_format.sample_rate / 1152 / 1000;
|
vbrUpdateBits * audio_format.sample_rate / 1152 / 1000;
|
||||||
|
|
||||||
decoder_data(mpd_decoder, NULL, inStream->seekable,
|
decoder_data(mpd_decoder, NULL,
|
||||||
chunk, chunkpos, total_time, bitRate,
|
chunk, chunkpos, total_time, bitRate,
|
||||||
replayGainInfo);
|
replayGainInfo);
|
||||||
}
|
}
|
||||||
|
@ -303,7 +303,8 @@ oggflac_decode(struct decoder * mpd_decoder, struct input_stream *inStream)
|
|||||||
goto fail;
|
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) {
|
while (true) {
|
||||||
OggFLAC__seekable_stream_decoder_process_single(decoder);
|
OggFLAC__seekable_stream_decoder_process_single(decoder);
|
||||||
|
@ -279,6 +279,7 @@ oggvorbis_decode(struct decoder *decoder, struct input_stream *inStream)
|
|||||||
if (total_time < 0)
|
if (total_time < 0)
|
||||||
total_time = 0;
|
total_time = 0;
|
||||||
decoder_initialized(decoder, &audio_format,
|
decoder_initialized(decoder, &audio_format,
|
||||||
|
inStream->seekable,
|
||||||
total_time);
|
total_time);
|
||||||
initialized = true;
|
initialized = true;
|
||||||
}
|
}
|
||||||
@ -304,7 +305,6 @@ oggvorbis_decode(struct decoder *decoder, struct input_stream *inStream)
|
|||||||
bitRate = test / 1000;
|
bitRate = test / 1000;
|
||||||
}
|
}
|
||||||
decoder_data(decoder, inStream,
|
decoder_data(decoder, inStream,
|
||||||
inStream->seekable,
|
|
||||||
chunk, chunkpos,
|
chunk, chunkpos,
|
||||||
ov_pcm_tell(&vf) / audio_format.sample_rate,
|
ov_pcm_tell(&vf) / audio_format.sample_rate,
|
||||||
bitRate, replayGainInfo);
|
bitRate, replayGainInfo);
|
||||||
@ -316,7 +316,7 @@ oggvorbis_decode(struct decoder *decoder, struct input_stream *inStream)
|
|||||||
|
|
||||||
if (decoder_get_command(decoder) == DECODE_COMMAND_NONE &&
|
if (decoder_get_command(decoder) == DECODE_COMMAND_NONE &&
|
||||||
chunkpos > 0) {
|
chunkpos > 0) {
|
||||||
decoder_data(decoder, NULL, inStream->seekable,
|
decoder_data(decoder, NULL,
|
||||||
chunk, chunkpos,
|
chunk, chunkpos,
|
||||||
ov_time_tell(&vf), bitRate,
|
ov_time_tell(&vf), bitRate,
|
||||||
replayGainInfo);
|
replayGainInfo);
|
||||||
|
@ -164,7 +164,7 @@ static void wavpack_decode(struct decoder * decoder,
|
|||||||
|
|
||||||
samplesreq = sizeof(chunk) / (4 * audio_format.channels);
|
samplesreq = sizeof(chunk) / (4 * audio_format.channels);
|
||||||
|
|
||||||
decoder_initialized(decoder, &audio_format,
|
decoder_initialized(decoder, &audio_format, false,
|
||||||
(float)allsamples / audio_format.sample_rate);
|
(float)allsamples / audio_format.sample_rate);
|
||||||
|
|
||||||
position = 0;
|
position = 0;
|
||||||
@ -200,7 +200,7 @@ static void wavpack_decode(struct decoder * decoder,
|
|||||||
format_samples(Bps, chunk,
|
format_samples(Bps, chunk,
|
||||||
samplesgot * audio_format.channels);
|
samplesgot * audio_format.channels);
|
||||||
|
|
||||||
decoder_data(decoder, NULL, 0, chunk,
|
decoder_data(decoder, NULL, chunk,
|
||||||
samplesgot * outsamplesize,
|
samplesgot * outsamplesize,
|
||||||
file_time, bitrate,
|
file_time, bitrate,
|
||||||
replayGainInfo);
|
replayGainInfo);
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
|
|
||||||
void decoder_initialized(struct decoder * decoder,
|
void decoder_initialized(struct decoder * decoder,
|
||||||
const struct audio_format *audio_format,
|
const struct audio_format *audio_format,
|
||||||
float total_time)
|
bool seekable, float total_time)
|
||||||
{
|
{
|
||||||
assert(dc.state == DECODE_STATE_START);
|
assert(dc.state == DECODE_STATE_START);
|
||||||
assert(audio_format != NULL);
|
assert(audio_format != NULL);
|
||||||
@ -42,6 +42,7 @@ void decoder_initialized(struct decoder * decoder,
|
|||||||
dc.in_audio_format = *audio_format;
|
dc.in_audio_format = *audio_format;
|
||||||
getOutputAudioFormat(audio_format, &dc.out_audio_format);
|
getOutputAudioFormat(audio_format, &dc.out_audio_format);
|
||||||
|
|
||||||
|
dc.seekable = seekable;
|
||||||
dc.totalTime = total_time;
|
dc.totalTime = total_time;
|
||||||
|
|
||||||
dc.state = DECODE_STATE_DECODE;
|
dc.state = DECODE_STATE_DECODE;
|
||||||
@ -121,19 +122,11 @@ size_t decoder_read(struct decoder *decoder,
|
|||||||
* one.
|
* one.
|
||||||
*/
|
*/
|
||||||
static enum decoder_command
|
static enum decoder_command
|
||||||
need_chunks(struct decoder *decoder,
|
need_chunks(struct input_stream *inStream)
|
||||||
struct input_stream *inStream, int seekable)
|
|
||||||
{
|
{
|
||||||
if (dc.command == DECODE_COMMAND_STOP)
|
if (dc.command == DECODE_COMMAND_STOP ||
|
||||||
return DECODE_COMMAND_STOP;
|
dc.command == DECODE_COMMAND_SEEK)
|
||||||
|
return dc.command;
|
||||||
if (dc.command == DECODE_COMMAND_SEEK) {
|
|
||||||
if (seekable) {
|
|
||||||
return DECODE_COMMAND_SEEK;
|
|
||||||
} else {
|
|
||||||
decoder_seek_error(decoder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!inStream ||
|
if (!inStream ||
|
||||||
input_stream_buffer(inStream) <= 0) {
|
input_stream_buffer(inStream) <= 0) {
|
||||||
@ -146,7 +139,7 @@ need_chunks(struct decoder *decoder,
|
|||||||
|
|
||||||
enum decoder_command
|
enum decoder_command
|
||||||
decoder_data(struct decoder *decoder,
|
decoder_data(struct decoder *decoder,
|
||||||
struct input_stream *inStream, int seekable,
|
struct input_stream *inStream,
|
||||||
void *dataIn, size_t dataInLen,
|
void *dataIn, size_t dataInLen,
|
||||||
float data_time, uint16_t bitRate,
|
float data_time, uint16_t bitRate,
|
||||||
ReplayGainInfo * replayGainInfo)
|
ReplayGainInfo * replayGainInfo)
|
||||||
@ -189,8 +182,7 @@ decoder_data(struct decoder *decoder,
|
|||||||
data += nbytes;
|
data += nbytes;
|
||||||
|
|
||||||
if (datalen > 0) {
|
if (datalen > 0) {
|
||||||
enum decoder_command cmd =
|
enum decoder_command cmd = need_chunks(inStream);
|
||||||
need_chunks(decoder, inStream, seekable);
|
|
||||||
if (cmd != DECODE_COMMAND_NONE)
|
if (cmd != DECODE_COMMAND_NONE)
|
||||||
return cmd;
|
return cmd;
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,7 @@ struct decoder;
|
|||||||
*/
|
*/
|
||||||
void decoder_initialized(struct decoder * decoder,
|
void decoder_initialized(struct decoder * decoder,
|
||||||
const struct audio_format *audio_format,
|
const struct audio_format *audio_format,
|
||||||
float total_time);
|
bool seekable, float total_time);
|
||||||
|
|
||||||
const char *decoder_get_url(struct decoder * decoder, char * buffer);
|
const char *decoder_get_url(struct decoder * decoder, char * buffer);
|
||||||
|
|
||||||
@ -151,7 +151,7 @@ size_t decoder_read(struct decoder *decoder,
|
|||||||
*/
|
*/
|
||||||
enum decoder_command
|
enum decoder_command
|
||||||
decoder_data(struct decoder *decoder,
|
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,
|
void *data, size_t datalen, float data_time, uint16_t bitRate,
|
||||||
ReplayGainInfo * replayGainInfo);
|
ReplayGainInfo * replayGainInfo);
|
||||||
|
|
||||||
|
@ -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) {
|
if (dc.command == DECODE_COMMAND_STOP) {
|
||||||
input_stream_close(&inStream);
|
input_stream_close(&inStream);
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user