summaryrefslogtreecommitdiffstats
path: root/src/sources/soundsourcemp3.cpp
diff options
context:
space:
mode:
authorUwe Klotz <uklotz@mixxx.org>2019-02-10 11:58:27 +0100
committerUwe Klotz <uklotz@mixxx.org>2019-02-10 17:32:33 +0100
commit398b291eca9c33841db9f38eefd9824541698d07 (patch)
treeca9d86fb8718e57a1eeabadd389cfbbf8324fe15 /src/sources/soundsourcemp3.cpp
parent13dc290ea78d2ca17474ef03e5752cac4896dfac (diff)
Improve error handling for corrupt MP3 files
...thereby fixing compiler warnings.
Diffstat (limited to 'src/sources/soundsourcemp3.cpp')
-rw-r--r--src/sources/soundsourcemp3.cpp40
1 files changed, 28 insertions, 12 deletions
diff --git a/src/sources/soundsourcemp3.cpp b/src/sources/soundsourcemp3.cpp
index a4d1d89cbb..d550b35208 100644
--- a/src/sources/soundsourcemp3.cpp
+++ b/src/sources/soundsourcemp3.cpp
@@ -270,13 +270,20 @@ SoundSource::OpenResult SoundSourceMp3::tryOpen(
}
const ChannelCount madChannelCount(MAD_NCHANNELS(&madHeader));
- if (maxChannelCount.valid() && (madChannelCount != maxChannelCount)) {
- kLogger.warning() << "Differing number of channels"
- << madChannelCount << "<>" << maxChannelCount
- << "in some MP3 frame headers:"
+ if (madChannelCount.valid()) {
+ if (maxChannelCount.valid() && (madChannelCount != maxChannelCount)) {
+ kLogger.warning()
+ << "Differing number of channels"
+ << madChannelCount << "<>" << maxChannelCount
+ << "in MP3 frame headers:"
+ << m_file.fileName();
+ }
+ maxChannelCount = math_max(madChannelCount, maxChannelCount);
+ } else {
+ kLogger.warning()
+ << "Missing number of channels in MP3 frame header:"
<< m_file.fileName();
}
- maxChannelCount = math_max(madChannelCount, maxChannelCount);
const int sampleRateIndex = getIndexBySampleRate(SampleRate(madSampleRate));
if (sampleRateIndex >= kSampleRateCount) {
@@ -321,7 +328,7 @@ SoundSource::OpenResult SoundSourceMp3::tryOpen(
if (m_seekFrameList.empty()) {
// This is not a working MP3 file.
- kLogger.warning() << "SSMP3: This is not a working MP3 file:"
+ kLogger.warning() << "This is not a working MP3 file:"
<< m_file.fileName();
// Abort
return OpenResult::Failed;
@@ -354,15 +361,24 @@ SoundSource::OpenResult SoundSourceMp3::tryOpen(
kLogger.warning() << "Mixxx tries to plays it with the most common sample rate for this file";
}
- if (mostCommonSampleRateIndex < kSampleRateCount) {
- setSampleRate(getSampleRateByIndex(mostCommonSampleRateIndex));
- } else {
- kLogger.warning() << "No single valid sample rate in header";
+ // Initialize the AudioSource
+ if (mostCommonSampleRateIndex > kSampleRateCount) {
+ kLogger.warning()
+ << "Unknown sample rate in MP3 file:"
+ << m_file.fileName();
+ // Abort
+ return OpenResult::Failed;
+ }
+ setSampleRate(getSampleRateByIndex(mostCommonSampleRateIndex));
+ if (!maxChannelCount.valid() || (maxChannelCount > kChannelCountMax)) {
+ kLogger.warning()
+ << "Invalid number of channels"
+ << maxChannelCount
+ << "in MP3 file:"
+ << m_file.fileName();
// Abort
return OpenResult::Failed;
}
-
- // Initialize the AudioSource
setChannelCount(maxChannelCount);
initFrameIndexRangeOnce(IndexRange::forward(0, m_curFrameIndex));