Made some audio info fields now mandatory, otherwise consider parsing failed
This commit is contained in:
@@ -37,18 +37,30 @@ namespace lms::audio::ffmpeg
|
||||
const auto containerInfo{ audioFile.getContainerInfo() };
|
||||
const auto bestStreamInfo{ audioFile.getBestStreamInfo() };
|
||||
if (!bestStreamInfo)
|
||||
throw AudioFileParsingException{ audioFile.getPath(), "Cannot find best audio stream" };
|
||||
throw AudioFileParsingException{ "Cannot find best audio stream" };
|
||||
|
||||
if (!containerInfo.container)
|
||||
throw AudioFileParsingException{ audioFile.getPath(), "Unhandled container type '" + containerInfo.containerName + "'" };
|
||||
throw AudioFileParsingException{ "Unhandled container type '" + containerInfo.containerName + "'" };
|
||||
|
||||
if (!bestStreamInfo->codec)
|
||||
throw AudioFileParsingException{ "Unhandled codec type '" + bestStreamInfo->codecName + "'" };
|
||||
|
||||
if (!bestStreamInfo->bitrate || *bestStreamInfo->bitrate == 0)
|
||||
throw AudioFileParsingException{ "Cannot determine bitrate" };
|
||||
|
||||
if (!bestStreamInfo->channelCount || *bestStreamInfo->channelCount == 0)
|
||||
throw AudioFileParsingException{ "Cannot determine channel count" };
|
||||
|
||||
if (!bestStreamInfo->sampleRate || *bestStreamInfo->sampleRate == 0)
|
||||
throw AudioFileParsingException{ "Cannot determine sample rate" };
|
||||
|
||||
audioProperties.container = *containerInfo.container;
|
||||
audioProperties.duration = containerInfo.duration;
|
||||
audioProperties.codec = bestStreamInfo->codec;
|
||||
audioProperties.bitrate = bestStreamInfo->bitrate;
|
||||
audioProperties.codec = *bestStreamInfo->codec;
|
||||
audioProperties.bitrate = *bestStreamInfo->bitrate;
|
||||
audioProperties.channelCount = *bestStreamInfo->channelCount;
|
||||
audioProperties.sampleRate = *bestStreamInfo->sampleRate;
|
||||
audioProperties.bitsPerSample = bestStreamInfo->bitsPerSample;
|
||||
audioProperties.channelCount = bestStreamInfo->channelCount;
|
||||
audioProperties.sampleRate = bestStreamInfo->sampleRate;
|
||||
|
||||
return audioProperties;
|
||||
}
|
||||
|
||||
@@ -60,9 +60,20 @@ namespace lms::audio::taglib
|
||||
|
||||
// Common properties
|
||||
audioProperties.bitrate = static_cast<std::size_t>(properties.bitrate() * 1000);
|
||||
if (audioProperties.bitrate == 0)
|
||||
throw AudioFileParsingException{ "Cannot determine bitrate" };
|
||||
|
||||
audioProperties.channelCount = static_cast<std::size_t>(properties.channels());
|
||||
if (audioProperties.channelCount == 0)
|
||||
throw AudioFileParsingException{ "Cannot determine channel count" };
|
||||
|
||||
audioProperties.duration = std::chrono::milliseconds{ properties.lengthInMilliseconds() };
|
||||
if (audioProperties.duration == decltype(audioProperties.duration)::zero())
|
||||
throw AudioFileParsingException{ "Cannot determine duration" };
|
||||
|
||||
audioProperties.sampleRate = static_cast<std::size_t>(properties.sampleRate());
|
||||
if (audioProperties.sampleRate == 0)
|
||||
throw AudioFileParsingException{ "Cannot determine sample rate" };
|
||||
|
||||
// Guess container from the file type
|
||||
if (const auto* apeFile{ dynamic_cast<const ::TagLib::APE::File*>(&file) })
|
||||
@@ -90,8 +101,7 @@ namespace lms::audio::taglib
|
||||
audioProperties.codec = CodecType::WMA9Pro;
|
||||
break;
|
||||
case ::TagLib::ASF::Properties::Codec::Unknown:
|
||||
audioProperties.codec = std::nullopt;
|
||||
break;
|
||||
throw AudioFileParsingException{ "Unhandled ASF codec type" };
|
||||
}
|
||||
|
||||
audioProperties.bitsPerSample = asfFile->audioProperties()->bitsPerSample();
|
||||
@@ -122,8 +132,7 @@ namespace lms::audio::taglib
|
||||
audioProperties.codec = CodecType::ALAC;
|
||||
break;
|
||||
case ::TagLib::MP4::Properties::Codec::Unknown:
|
||||
audioProperties.codec = std::nullopt;
|
||||
break;
|
||||
throw AudioFileParsingException{ "Unhandled MP4 codec type" };
|
||||
}
|
||||
|
||||
audioProperties.bitsPerSample = mp4File->audioProperties()->bitsPerSample();
|
||||
@@ -195,6 +204,13 @@ namespace lms::audio::taglib
|
||||
audioProperties.codec = CodecType::WavPack;
|
||||
audioProperties.bitsPerSample = wavPackFile->audioProperties()->bitsPerSample();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw AudioFileParsingException{ "Unhandled file type" };
|
||||
}
|
||||
|
||||
if (audioProperties.bitsPerSample && *audioProperties.bitsPerSample == 0)
|
||||
audioProperties.bitsPerSample.reset();
|
||||
|
||||
return audioProperties;
|
||||
}
|
||||
|
||||
@@ -229,16 +229,10 @@ namespace lms::audio::taglib::utils
|
||||
}
|
||||
|
||||
if (!file)
|
||||
{
|
||||
LMS_LOG(METADATA, ERROR, "File " << p << ": parsing failed");
|
||||
throw AudioFileParsingException{ p, "Parsing failed" };
|
||||
}
|
||||
throw AudioFileParsingException{ "Parsing failed" };
|
||||
|
||||
if (!file->audioProperties())
|
||||
{
|
||||
LMS_LOG(METADATA, ERROR, "File " << p << ": no audio properties");
|
||||
throw AudioFileNoAudioPropertiesException{ p };
|
||||
}
|
||||
throw AudioFileParsingException{ "No audio properties" };
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user