mp4ff: call decoder_initialized() after libfaad initialization
Don't wait for the first frame to be decoded. We already have the sample rate and the channel count from faacDecInit2().
This commit is contained in:
parent
47e3eab872
commit
2bc0fabe73
@ -111,6 +111,7 @@ mp4_decode(struct decoder *mpd_decoder, struct input_stream *input_stream)
|
|||||||
float file_time, total_time;
|
float file_time, total_time;
|
||||||
int32_t scale;
|
int32_t scale;
|
||||||
faacDecHandle decoder;
|
faacDecHandle decoder;
|
||||||
|
struct audio_format audio_format;
|
||||||
faacDecFrameInfo frame_info;
|
faacDecFrameInfo frame_info;
|
||||||
faacDecConfigurationPtr config;
|
faacDecConfigurationPtr config;
|
||||||
unsigned char *mp4_buffer;
|
unsigned char *mp4_buffer;
|
||||||
@ -139,7 +140,6 @@ mp4_decode(struct decoder *mpd_decoder, struct input_stream *input_stream)
|
|||||||
uint16_t bit_rate = 0;
|
uint16_t bit_rate = 0;
|
||||||
bool seeking = false;
|
bool seeking = false;
|
||||||
double seek_where = 0;
|
double seek_where = 0;
|
||||||
bool initialized = false;
|
|
||||||
enum decoder_command cmd = DECODE_COMMAND_NONE;
|
enum decoder_command cmd = DECODE_COMMAND_NONE;
|
||||||
|
|
||||||
mp4fh = mp4ff_open_read(&callback);
|
mp4fh = mp4ff_open_read(&callback);
|
||||||
@ -204,6 +204,26 @@ mp4_decode(struct decoder *mpd_decoder, struct input_stream *input_stream)
|
|||||||
|
|
||||||
seek_table = g_malloc(sizeof(float) * num_samples);
|
seek_table = g_malloc(sizeof(float) * num_samples);
|
||||||
|
|
||||||
|
audio_format = (struct audio_format){
|
||||||
|
.bits = 16,
|
||||||
|
.channels = channels,
|
||||||
|
.sample_rate = sample_rate,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!audio_format_valid(&audio_format)) {
|
||||||
|
g_warning("Invalid audio format: %u:%u:%u\n",
|
||||||
|
audio_format.sample_rate,
|
||||||
|
audio_format.bits,
|
||||||
|
audio_format.channels);
|
||||||
|
faacDecClose(decoder);
|
||||||
|
mp4ff_close(mp4fh);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
decoder_initialized(mpd_decoder, &audio_format,
|
||||||
|
input_stream->seekable,
|
||||||
|
total_time);
|
||||||
|
|
||||||
for (sample_id = 0;
|
for (sample_id = 0;
|
||||||
sample_id < num_samples && cmd != DECODE_COMMAND_STOP;
|
sample_id < num_samples && cmd != DECODE_COMMAND_STOP;
|
||||||
sample_id++) {
|
sample_id++) {
|
||||||
@ -268,32 +288,21 @@ mp4_decode(struct decoder *mpd_decoder, struct input_stream *input_stream)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!initialized) {
|
if (frame_info.channels != audio_format.channels) {
|
||||||
struct audio_format audio_format = {
|
g_warning("channel count changed from %u to %u",
|
||||||
.bits = 16,
|
audio_format.channels, frame_info.channels);
|
||||||
.channels = frame_info.channels,
|
break;
|
||||||
};
|
|
||||||
|
|
||||||
channels = frame_info.channels;
|
|
||||||
#ifdef HAVE_FAACDECFRAMEINFO_SAMPLERATE
|
|
||||||
scale = frame_info.samplerate;
|
|
||||||
#endif
|
|
||||||
audio_format.sample_rate = scale;
|
|
||||||
|
|
||||||
if (!audio_format_valid(&audio_format)) {
|
|
||||||
g_warning("Invalid audio format: %u:%u:%u\n",
|
|
||||||
audio_format.sample_rate,
|
|
||||||
audio_format.bits,
|
|
||||||
audio_format.channels);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
decoder_initialized(mpd_decoder, &audio_format,
|
|
||||||
input_stream->seekable,
|
|
||||||
total_time);
|
|
||||||
initialized = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_FAACDECFRAMEINFO_SAMPLERATE
|
||||||
|
if (frame_info.samplerate != audio_format.sample_rate) {
|
||||||
|
g_warning("sample rate changed from %u to %lu",
|
||||||
|
audio_format.sample_rate,
|
||||||
|
(unsigned long)frame_info.samplerate);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (channels * (unsigned long)(dur + offset) > frame_info.samples) {
|
if (channels * (unsigned long)(dur + offset) > frame_info.samples) {
|
||||||
dur = frame_info.samples / channels;
|
dur = frame_info.samples / channels;
|
||||||
offset = 0;
|
offset = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user