decoder: check audio_format_valid() in all decoders

Refuse to play audio formats which are not supported by MPD.
This commit is contained in:
Max Kellermann 2008-11-21 20:27:30 +01:00
parent be9e60d55e
commit 976d5045c6
10 changed files with 71 additions and 7 deletions

View File

@ -405,6 +405,11 @@ aac_stream_decode(struct decoder *mpd_decoder, struct input_stream *inStream)
.sample_rate = sample_rate,
};
if (!audio_format_valid(&audio_format)) {
g_warning("aac: invalid audio format\n");
break;
}
decoder_initialized(mpd_decoder, &audio_format,
false, totalTime);
initialized = true;

View File

@ -77,19 +77,20 @@ audiofile_decode(struct decoder *decoder, const char *path)
audio_format.channels =
(uint8_t)afGetVirtualChannels(af_fp, AF_DEFAULT_TRACK);
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);
afCloseFile(af_fp);
return;
}
frame_count = afGetFrameCount(af_fp, AF_DEFAULT_TRACK);
total_time = ((float)frame_count / (float)audio_format.sample_rate);
bitRate = (uint16_t)(st.st_size * 8.0 / total_time / 1000.0 + 0.5);
if (audio_format.bits != 8 && audio_format.bits != 16) {
g_warning("Only 8 and 16-bit files are supported. %s is %i-bit\n",
path, audio_format.bits);
afCloseFile(af_fp);
return;
}
fs = (int)afGetVirtualFrameSize(af_fp, AF_DEFAULT_TRACK, 1);
decoder_initialized(decoder, &audio_format, true, total_time);

View File

@ -255,6 +255,13 @@ ffmpeg_decode_internal(struct ffmpeg_context *ctx)
audio_format.sample_rate = (unsigned int)codec_context->sample_rate;
audio_format.channels = codec_context->channels;
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);
return false;
}
//there is some problem with this on some demux (mp3 at least)
if (format_context->duration != (int)AV_NOPTS_VALUE) {
total_time = format_context->duration / AV_TIME_BASE;

View File

@ -343,6 +343,14 @@ flac_decode_internal(struct decoder * decoder, struct input_stream *inStream,
goto fail;
}
if (!audio_format_valid(&data.audio_format)) {
g_warning("Invalid audio format: %u:%u:%u\n",
data.audio_format.sample_rate,
data.audio_format.bits,
data.audio_format.channels);
goto fail;
}
decoder_initialized(decoder, &data.audio_format,
inStream->seekable, data.total_time);

View File

@ -275,6 +275,15 @@ mp4_decode(struct decoder *mpd_decoder, struct input_stream *input_stream)
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);

View File

@ -155,6 +155,14 @@ mpc_decode(struct decoder *mpd_decoder, struct input_stream *inStream)
audio_format.channels = info.channels;
audio_format.sample_rate = info.sample_freq;
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);
return;
}
replayGainInfo = replay_gain_info_new();
replayGainInfo->tuples[REPLAY_GAIN_ALBUM].gain = info.gain_album * 0.01;
replayGainInfo->tuples[REPLAY_GAIN_ALBUM].peak = info.peak_album / 32767.0;

View File

@ -294,6 +294,14 @@ oggflac_decode(struct decoder * mpd_decoder, struct input_stream *inStream)
goto fail;
}
if (!audio_format_valid(&data.audio_format)) {
g_warning("Invalid audio format: %u:%u:%u\n",
data.audio_format.sample_rate,
data.audio_format.bits,
data.audio_format.channels);
goto fail;
}
decoder_initialized(mpd_decoder, &data.audio_format,
inStream->seekable, data.total_time);

View File

@ -288,6 +288,15 @@ oggvorbis_decode(struct decoder *decoder, struct input_stream *inStream)
audio_format.channels = vi->channels;
audio_format.sample_rate = vi->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);
break;
}
if (!initialized) {
float total_time = ov_time_total(&vf, -1);
if (total_time < 0)

View File

@ -148,6 +148,14 @@ wavpack_decode(struct decoder *decoder, WavpackContext *wpc, bool can_seek,
audio_format.bits = 24;
}
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);
return;
}
if ((WavpackGetMode(wpc) & MODE_FLOAT) == MODE_FLOAT) {
format_samples = format_samples_float;
} else {

View File

@ -40,6 +40,7 @@ void decoder_initialized(struct decoder * decoder,
assert(!decoder->seeking);
assert(audio_format != NULL);
assert(audio_format_defined(audio_format));
assert(audio_format_valid(audio_format));
pcm_convert_init(&decoder->conv_state);