More metadata checks

This commit is contained in:
Marcus Holland-Moritz 2023-07-18 20:22:57 +02:00
parent c17ab2b44a
commit 0d7f08515a

View File

@ -104,6 +104,28 @@ struct pcmaudio_metadata {
// uint32_t samples_per_second;
auto operator<=>(pcmaudio_metadata const&) const = default;
bool check() const {
if (!(bits_per_sample == 8 || bits_per_sample == 16 ||
bits_per_sample == 20 || bits_per_sample == 24 ||
bits_per_sample == 32)) {
return false;
}
if (bits_per_sample == 8 && bytes_per_sample != 1) {
return false;
}
if (bits_per_sample == 16 && bytes_per_sample != 2) {
return false;
}
if (bits_per_sample == 32 && bytes_per_sample != 4) {
return false;
}
return bytes_per_sample == 3 || bytes_per_sample == 4;
}
};
std::ostream& operator<<(std::ostream& os, pcmaudio_metadata const& m) {
@ -292,6 +314,11 @@ bool pcmaudio_categorizer_<LoggerPolicy>::check_aiff(
return false;
}
if (!meta.check()) {
LOG_WARN << "[AIFF] " << path << ": metadata check failed: " << meta;
return false;
}
meta_valid = true;
LOG_TRACE << "[AIFF] " << path << ": meta=" << meta;
@ -505,6 +532,11 @@ bool pcmaudio_categorizer_<LoggerPolicy>::check_caf(
assert(meta.bytes_per_sample > 0);
if (!meta.check()) {
LOG_WARN << "[CAF] " << path << ": metadata check failed: " << meta;
return false;
}
meta_valid = true;
LOG_TRACE << "[CAF] " << path << ": meta=" << meta;