decoder: check audio_format_valid() in all decoders
Refuse to play audio formats which are not supported by MPD.
This commit is contained in:
parent
be9e60d55e
commit
976d5045c6
|
@ -405,6 +405,11 @@ aac_stream_decode(struct decoder *mpd_decoder, struct input_stream *inStream)
|
||||||
.sample_rate = sample_rate,
|
.sample_rate = sample_rate,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (!audio_format_valid(&audio_format)) {
|
||||||
|
g_warning("aac: invalid audio format\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
decoder_initialized(mpd_decoder, &audio_format,
|
decoder_initialized(mpd_decoder, &audio_format,
|
||||||
false, totalTime);
|
false, totalTime);
|
||||||
initialized = true;
|
initialized = true;
|
||||||
|
|
|
@ -77,19 +77,20 @@ audiofile_decode(struct decoder *decoder, const char *path)
|
||||||
audio_format.channels =
|
audio_format.channels =
|
||||||
(uint8_t)afGetVirtualChannels(af_fp, AF_DEFAULT_TRACK);
|
(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);
|
frame_count = afGetFrameCount(af_fp, AF_DEFAULT_TRACK);
|
||||||
|
|
||||||
total_time = ((float)frame_count / (float)audio_format.sample_rate);
|
total_time = ((float)frame_count / (float)audio_format.sample_rate);
|
||||||
|
|
||||||
bitRate = (uint16_t)(st.st_size * 8.0 / total_time / 1000.0 + 0.5);
|
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);
|
fs = (int)afGetVirtualFrameSize(af_fp, AF_DEFAULT_TRACK, 1);
|
||||||
|
|
||||||
decoder_initialized(decoder, &audio_format, true, total_time);
|
decoder_initialized(decoder, &audio_format, true, total_time);
|
||||||
|
|
|
@ -255,6 +255,13 @@ ffmpeg_decode_internal(struct ffmpeg_context *ctx)
|
||||||
audio_format.sample_rate = (unsigned int)codec_context->sample_rate;
|
audio_format.sample_rate = (unsigned int)codec_context->sample_rate;
|
||||||
audio_format.channels = codec_context->channels;
|
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)
|
//there is some problem with this on some demux (mp3 at least)
|
||||||
if (format_context->duration != (int)AV_NOPTS_VALUE) {
|
if (format_context->duration != (int)AV_NOPTS_VALUE) {
|
||||||
total_time = format_context->duration / AV_TIME_BASE;
|
total_time = format_context->duration / AV_TIME_BASE;
|
||||||
|
|
|
@ -343,6 +343,14 @@ flac_decode_internal(struct decoder * decoder, struct input_stream *inStream,
|
||||||
goto fail;
|
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,
|
decoder_initialized(decoder, &data.audio_format,
|
||||||
inStream->seekable, data.total_time);
|
inStream->seekable, data.total_time);
|
||||||
|
|
||||||
|
|
|
@ -275,6 +275,15 @@ mp4_decode(struct decoder *mpd_decoder, struct input_stream *input_stream)
|
||||||
scale = frame_info.samplerate;
|
scale = frame_info.samplerate;
|
||||||
#endif
|
#endif
|
||||||
audio_format.sample_rate = scale;
|
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,
|
decoder_initialized(mpd_decoder, &audio_format,
|
||||||
input_stream->seekable,
|
input_stream->seekable,
|
||||||
total_time);
|
total_time);
|
||||||
|
|
|
@ -155,6 +155,14 @@ mpc_decode(struct decoder *mpd_decoder, struct input_stream *inStream)
|
||||||
audio_format.channels = info.channels;
|
audio_format.channels = info.channels;
|
||||||
audio_format.sample_rate = info.sample_freq;
|
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 = replay_gain_info_new();
|
||||||
replayGainInfo->tuples[REPLAY_GAIN_ALBUM].gain = info.gain_album * 0.01;
|
replayGainInfo->tuples[REPLAY_GAIN_ALBUM].gain = info.gain_album * 0.01;
|
||||||
replayGainInfo->tuples[REPLAY_GAIN_ALBUM].peak = info.peak_album / 32767.0;
|
replayGainInfo->tuples[REPLAY_GAIN_ALBUM].peak = info.peak_album / 32767.0;
|
||||||
|
|
|
@ -294,6 +294,14 @@ oggflac_decode(struct decoder * mpd_decoder, struct input_stream *inStream)
|
||||||
goto fail;
|
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,
|
decoder_initialized(mpd_decoder, &data.audio_format,
|
||||||
inStream->seekable, data.total_time);
|
inStream->seekable, data.total_time);
|
||||||
|
|
||||||
|
|
|
@ -288,6 +288,15 @@ oggvorbis_decode(struct decoder *decoder, struct input_stream *inStream)
|
||||||
|
|
||||||
audio_format.channels = vi->channels;
|
audio_format.channels = vi->channels;
|
||||||
audio_format.sample_rate = vi->rate;
|
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) {
|
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)
|
||||||
|
|
|
@ -148,6 +148,14 @@ wavpack_decode(struct decoder *decoder, WavpackContext *wpc, bool can_seek,
|
||||||
audio_format.bits = 24;
|
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) {
|
if ((WavpackGetMode(wpc) & MODE_FLOAT) == MODE_FLOAT) {
|
||||||
format_samples = format_samples_float;
|
format_samples = format_samples_float;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -40,6 +40,7 @@ void decoder_initialized(struct decoder * decoder,
|
||||||
assert(!decoder->seeking);
|
assert(!decoder->seeking);
|
||||||
assert(audio_format != NULL);
|
assert(audio_format != NULL);
|
||||||
assert(audio_format_defined(audio_format));
|
assert(audio_format_defined(audio_format));
|
||||||
|
assert(audio_format_valid(audio_format));
|
||||||
|
|
||||||
pcm_convert_init(&decoder->conv_state);
|
pcm_convert_init(&decoder->conv_state);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue