use a local "initialized" flag instead of dc->state
Since we want to hide mpd internals from the decoder plugins, the plugins should not check dc->state whether they have already called decoder_initialized(). Use a local variable to track that.
This commit is contained in:
parent
17e9cc84c5
commit
dc4d774481
@ -298,6 +298,7 @@ static int aac_decode(struct decoder * mpd_decoder, char *path)
|
|||||||
mpd_uint16 bitRate = 0;
|
mpd_uint16 bitRate = 0;
|
||||||
AacBuffer b;
|
AacBuffer b;
|
||||||
InputStream inStream;
|
InputStream inStream;
|
||||||
|
int initialized = 0;
|
||||||
|
|
||||||
if ((totalTime = getAacFloatTotalTime(path)) < 0)
|
if ((totalTime = getAacFloatTotalTime(path)) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
@ -364,11 +365,12 @@ static int aac_decode(struct decoder * mpd_decoder, char *path)
|
|||||||
sampleRate = frameInfo.samplerate;
|
sampleRate = frameInfo.samplerate;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (dc.state != DECODE_STATE_DECODE) {
|
if (!initialized) {
|
||||||
audio_format.channels = frameInfo.channels;
|
audio_format.channels = frameInfo.channels;
|
||||||
audio_format.sampleRate = sampleRate;
|
audio_format.sampleRate = sampleRate;
|
||||||
decoder_initialized(mpd_decoder, &audio_format,
|
decoder_initialized(mpd_decoder, &audio_format,
|
||||||
totalTime);
|
totalTime);
|
||||||
|
initialized = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
advanceAacBuffer(&b, frameInfo.bytesconsumed);
|
advanceAacBuffer(&b, frameInfo.bytesconsumed);
|
||||||
@ -401,7 +403,7 @@ static int aac_decode(struct decoder * mpd_decoder, char *path)
|
|||||||
if (b.buffer)
|
if (b.buffer)
|
||||||
free(b.buffer);
|
free(b.buffer);
|
||||||
|
|
||||||
if (dc.state != DECODE_STATE_DECODE)
|
if (!initialized)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (decoder_get_command(mpd_decoder) == DECODE_COMMAND_SEEK) {
|
if (decoder_get_command(mpd_decoder) == DECODE_COMMAND_SEEK) {
|
||||||
|
@ -107,6 +107,7 @@ static int mp4_decode(struct decoder * mpd_decoder, InputStream * inStream)
|
|||||||
mpd_uint16 bitRate = 0;
|
mpd_uint16 bitRate = 0;
|
||||||
int seeking = 0;
|
int seeking = 0;
|
||||||
double seek_where = 0;
|
double seek_where = 0;
|
||||||
|
int initialized = 0;
|
||||||
|
|
||||||
mp4cb = xmalloc(sizeof(mp4ff_callback_t));
|
mp4cb = xmalloc(sizeof(mp4ff_callback_t));
|
||||||
mp4cb->read = mp4_inputStreamReadCallback;
|
mp4cb->read = mp4_inputStreamReadCallback;
|
||||||
@ -241,7 +242,7 @@ static int mp4_decode(struct decoder * mpd_decoder, InputStream * inStream)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dc.state != DECODE_STATE_DECODE) {
|
if (!initialized) {
|
||||||
channels = frameInfo.channels;
|
channels = frameInfo.channels;
|
||||||
#ifdef HAVE_FAACDECFRAMEINFO_SAMPLERATE
|
#ifdef HAVE_FAACDECFRAMEINFO_SAMPLERATE
|
||||||
scale = frameInfo.samplerate;
|
scale = frameInfo.samplerate;
|
||||||
@ -250,6 +251,7 @@ static int mp4_decode(struct decoder * mpd_decoder, InputStream * inStream)
|
|||||||
audio_format.channels = frameInfo.channels;
|
audio_format.channels = frameInfo.channels;
|
||||||
decoder_initialized(mpd_decoder, &audio_format,
|
decoder_initialized(mpd_decoder, &audio_format,
|
||||||
total_time);
|
total_time);
|
||||||
|
initialized = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (channels * (unsigned long)(dur + offset) > frameInfo.samples) {
|
if (channels * (unsigned long)(dur + offset) > frameInfo.samples) {
|
||||||
@ -282,7 +284,7 @@ static int mp4_decode(struct decoder * mpd_decoder, InputStream * inStream)
|
|||||||
mp4ff_close(mp4fh);
|
mp4ff_close(mp4fh);
|
||||||
free(mp4cb);
|
free(mp4cb);
|
||||||
|
|
||||||
if (dc.state != DECODE_STATE_DECODE)
|
if (!initialized)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (decoder_get_command(mpd_decoder) == DECODE_COMMAND_SEEK && seeking) {
|
if (decoder_get_command(mpd_decoder) == DECODE_COMMAND_SEEK && seeking) {
|
||||||
|
@ -228,6 +228,7 @@ static int oggvorbis_decode(struct decoder * decoder, InputStream * inStream)
|
|||||||
ReplayGainInfo *replayGainInfo = NULL;
|
ReplayGainInfo *replayGainInfo = NULL;
|
||||||
char **comments;
|
char **comments;
|
||||||
const char *errorStr;
|
const char *errorStr;
|
||||||
|
int initialized = 0;
|
||||||
|
|
||||||
data.inStream = inStream;
|
data.inStream = inStream;
|
||||||
data.decoder = decoder;
|
data.decoder = decoder;
|
||||||
@ -284,12 +285,13 @@ static int oggvorbis_decode(struct decoder * decoder, InputStream * inStream)
|
|||||||
vorbis_info *vi = ov_info(&vf, -1);
|
vorbis_info *vi = ov_info(&vf, -1);
|
||||||
audio_format.channels = vi->channels;
|
audio_format.channels = vi->channels;
|
||||||
audio_format.sampleRate = vi->rate;
|
audio_format.sampleRate = vi->rate;
|
||||||
if (dc.state == DECODE_STATE_START) {
|
if (!initialized) {
|
||||||
float total_time = ov_time_total(&vf, -1);
|
float total_time = ov_time_total(&vf, -1);
|
||||||
if (total_time < 0)
|
if (total_time < 0)
|
||||||
total_time = 0;
|
total_time = 0;
|
||||||
decoder_initialized(decoder, &audio_format,
|
decoder_initialized(decoder, &audio_format,
|
||||||
total_time);
|
total_time);
|
||||||
|
initialized = 1;
|
||||||
}
|
}
|
||||||
comments = ov_comment(&vf, -1)->user_comments;
|
comments = ov_comment(&vf, -1)->user_comments;
|
||||||
putOggCommentsIntoOutputBuffer(inStream->metaName,
|
putOggCommentsIntoOutputBuffer(inStream->metaName,
|
||||||
|
Loading…
Reference in New Issue
Block a user