Skip to content

Commit c584887

Browse files
committed
Loosen blockformat ID validation to allow for S-ADM frames
An audioChannelFormat in an S-ADM frame can contain a set of AudioBlockFormats with an initialiser block. This is a special block that has a counter value of 0. It may also contain a run of contiguous blocks that start from some integer n > 1. This commit allows non-contiguous IDs to be added to a document for this case only.
1 parent 8d1164a commit c584887

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

include/adm/elements/audio_channel_format.hpp

+11-6
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,12 @@ namespace adm {
376376
}
377377
}
378378

379+
namespace detail {
380+
inline bool isValidCounterIncrement(AudioBlockFormatIdCounter const previous, AudioBlockFormatIdCounter const current) {
381+
return previous == 0u || current == previous.get() + 1u;
382+
}
383+
}
384+
379385
template <typename BlockFormat>
380386
void AudioChannelFormat::assignId(BlockFormat &blockFormat,
381387
BlockFormat *previousBlock) {
@@ -408,13 +414,12 @@ namespace adm {
408414
throw std::runtime_error("Invalid ID - incorrect value");
409415

410416
if (previousBlock) {
411-
int thisCounterValue =
412-
thisId.template get<AudioBlockFormatIdCounter>().get();
413-
auto prevId = previousBlock->template get<AudioBlockFormatId>();
414-
int expectedCounterValue =
415-
prevId.template get<AudioBlockFormatIdCounter>().get() + 1;
416-
if (thisCounterValue != expectedCounterValue)
417+
auto currentCounter = thisId.template get<AudioBlockFormatIdCounter>();
418+
auto previousCounter = previousBlock->template get<AudioBlockFormatId>()
419+
.template get<AudioBlockFormatIdCounter>();
420+
if (!detail::isValidCounterIncrement(previousCounter, currentCounter)) {
417421
throw std::runtime_error("Invalid ID - unexpected counter");
422+
}
418423
}
419424
}
420425
}

0 commit comments

Comments
 (0)