diff --git a/iamf/cli/proto_to_obu/tests/BUILD b/iamf/cli/proto_to_obu/tests/BUILD index a00b0c7..3ea844e 100644 --- a/iamf/cli/proto_to_obu/tests/BUILD +++ b/iamf/cli/proto_to_obu/tests/BUILD @@ -148,6 +148,7 @@ cc_test( "//iamf/obu:types", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/status:status_matchers", + "@com_google_absl//absl/types:span", "@com_google_googletest//:gtest_main", "@com_google_protobuf//:protobuf", ], diff --git a/iamf/cli/proto_to_obu/tests/parameter_block_generator_test.cc b/iamf/cli/proto_to_obu/tests/parameter_block_generator_test.cc index 83b0332..cc8c110 100644 --- a/iamf/cli/proto_to_obu/tests/parameter_block_generator_test.cc +++ b/iamf/cli/proto_to_obu/tests/parameter_block_generator_test.cc @@ -11,6 +11,7 @@ */ #include "iamf/cli/proto_to_obu/parameter_block_generator.h" +#include #include #include #include @@ -18,6 +19,7 @@ #include "absl/container/flat_hash_map.h" #include "absl/status/status_matchers.h" +#include "absl/types/span.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include "iamf/cli/audio_element_with_data.h" @@ -44,11 +46,12 @@ using ::absl_testing::IsOk; constexpr DecodedUleb128 kCodecConfigId = 200; constexpr DecodedUleb128 kAudioElementId = 300; -constexpr DecodedUleb128 kMixPresentationId = 1337; constexpr DecodedUleb128 kParameterId = 100; constexpr DecodedUleb128 kParameterRate = 48000; constexpr DecodedUleb128 kDuration = 8; constexpr bool kOverrideComputedReconGains = false; +constexpr std::array kOneSubstreamId{0}; +constexpr std::array kFourSubtreamIds{0, 1, 2, 3}; TEST(ParameterBlockGeneratorTest, NoParameterBlocks) { absl::flat_hash_map @@ -109,7 +112,7 @@ void ConfigureDemixingParameterBlocks( } void InitializePrerequisiteObus( - const std::vector& substream_ids, + absl::Span substream_ids, absl::flat_hash_map& codec_config_obus, absl::flat_hash_map& audio_elements) { constexpr uint32_t kSampleRate = 48000; @@ -153,7 +156,7 @@ TEST(ParameterBlockGeneratorTest, GenerateTwoDemixingParameterBlocks) { // Initialize pre-requisite OBUs. absl::flat_hash_map codec_config_obus; absl::flat_hash_map audio_elements; - InitializePrerequisiteObus(/*substream_ids=*/{0}, codec_config_obus, + InitializePrerequisiteObus(kOneSubstreamId, codec_config_obus, audio_elements); // Add a demixing parameter definition inside the Audio Element OBU. @@ -268,7 +271,7 @@ TEST(ParameterBlockGeneratorTest, GenerateMixGainParameterBlocks) { // Initialize pre-requisite OBUs. absl::flat_hash_map codec_config_obus; absl::flat_hash_map audio_elements; - InitializePrerequisiteObus(/*substream_ids=*/{0}, codec_config_obus, + InitializePrerequisiteObus(kOneSubstreamId, codec_config_obus, audio_elements); // Add param definition. It would normally be owned by a Mix Presentation OBU. @@ -428,7 +431,7 @@ TEST(ParameterBlockGeneratorTest, GenerateReconGainParameterBlocks) { // Initialize pre-requisite OBUs. absl::flat_hash_map codec_config_obus; absl::flat_hash_map audio_elements; - InitializePrerequisiteObus(/*substream_ids=*/{0, 1, 2, 3}, codec_config_obus, + InitializePrerequisiteObus(kFourSubtreamIds, codec_config_obus, audio_elements); // Extra data needed to compute recon gain. @@ -486,7 +489,7 @@ TEST(Initialize, FailsWhenThereAreStrayParameterBlocks) { ConfigureDemixingParameterBlocks(user_metadata); absl::flat_hash_map codec_config_obus; absl::flat_hash_map audio_elements; - InitializePrerequisiteObus(/*substream_ids=*/{0, 1, 2, 3}, codec_config_obus, + InitializePrerequisiteObus(kFourSubtreamIds, codec_config_obus, audio_elements); // Construct and initialize. diff --git a/iamf/cli/tests/cli_test_utils.cc b/iamf/cli/tests/cli_test_utils.cc index a0e687c..0f2116d 100644 --- a/iamf/cli/tests/cli_test_utils.cc +++ b/iamf/cli/tests/cli_test_utils.cc @@ -174,7 +174,7 @@ void AddAacCodecConfigWithId( void AddAmbisonicsMonoAudioElementWithSubstreamIds( DecodedUleb128 audio_element_id, uint32_t codec_config_id, - const std::vector& substream_ids, + absl::Span substream_ids, const absl::flat_hash_map& codec_config_obus, absl::flat_hash_map& audio_elements) { // Check the `codec_config_id` is known and this is a new @@ -187,10 +187,9 @@ void AddAmbisonicsMonoAudioElementWithSubstreamIds( AudioElementObu obu = AudioElementObu( ObuHeader(), audio_element_id, AudioElementObu::kAudioElementSceneBased, 0, codec_config_id); - obu.audio_substream_ids_ = substream_ids; obu.InitializeParams(0); obu.InitializeAudioSubstreams(substream_ids.size()); - obu.audio_substream_ids_ = substream_ids; + obu.audio_substream_ids_.assign(substream_ids.begin(), substream_ids.end()); // Initialize to n-th order ambisonics. Choose the lowest order that can fit // all `substream_ids`. This may result in mixed-order ambisonics. @@ -226,7 +225,7 @@ void AddAmbisonicsMonoAudioElementWithSubstreamIds( // Adds a scalable Audio Element OBU based on the input arguments. void AddScalableAudioElementWithSubstreamIds( DecodedUleb128 audio_element_id, uint32_t codec_config_id, - const std::vector& substream_ids, + absl::Span substream_ids, const absl::flat_hash_map& codec_config_obus, absl::flat_hash_map& audio_elements) { // Check the `codec_config_id` is known and this is a new @@ -239,7 +238,8 @@ void AddScalableAudioElementWithSubstreamIds( AudioElementObu obu(ObuHeader(), audio_element_id, AudioElementObu::kAudioElementChannelBased, 0, codec_config_id); - obu.audio_substream_ids_ = substream_ids; + obu.InitializeAudioSubstreams(substream_ids.size()); + obu.audio_substream_ids_.assign(substream_ids.begin(), substream_ids.end()); obu.InitializeParams(0); EXPECT_THAT(obu.InitializeScalableChannelLayout(1, 0), IsOk()); diff --git a/iamf/cli/tests/cli_test_utils.h b/iamf/cli/tests/cli_test_utils.h index 57a2aab..5c1fefe 100644 --- a/iamf/cli/tests/cli_test_utils.h +++ b/iamf/cli/tests/cli_test_utils.h @@ -19,7 +19,6 @@ #include #include "absl/container/flat_hash_map.h" -#include "absl/status/statusor.h" #include "absl/strings/string_view.h" #include "absl/types/span.h" #include "iamf/cli/audio_element_with_data.h" @@ -92,7 +91,7 @@ void AddAacCodecConfigWithId( */ void AddAmbisonicsMonoAudioElementWithSubstreamIds( DecodedUleb128 audio_element_id, uint32_t codec_config_id, - const std::vector& substream_ids, + absl::Span substream_ids, const absl::flat_hash_map& codec_config_obus, absl::flat_hash_map& audio_elements); @@ -106,7 +105,7 @@ void AddAmbisonicsMonoAudioElementWithSubstreamIds( */ void AddScalableAudioElementWithSubstreamIds( DecodedUleb128 audio_element_id, uint32_t codec_config_id, - const std::vector& substream_ids, + absl::Span substream_ids, const absl::flat_hash_map& codec_config_obus, absl::flat_hash_map& audio_elements); diff --git a/iamf/cli/tests/cli_util_test.cc b/iamf/cli/tests/cli_util_test.cc index 4deaa76..e5c69fc 100644 --- a/iamf/cli/tests/cli_util_test.cc +++ b/iamf/cli/tests/cli_util_test.cc @@ -11,6 +11,7 @@ */ #include "iamf/cli/cli_util.h" +#include #include #include #include @@ -55,6 +56,8 @@ constexpr DecodedUleb128 kParameterId = 99999; constexpr DecodedUleb128 kParameterRate = 48000; constexpr DecodedUleb128 kFirstSubstreamId = 31; constexpr DecodedUleb128 kSecondSubstreamId = 32; +constexpr std::array kZerothOrderAmbisonicsSubstreamId{ + kFirstSubstreamId}; TEST(WritePcmFrameToBuffer, ResizesOutputBuffer) { const size_t kExpectedSize = 12; // 3 bytes per sample * 4 samples. @@ -525,8 +528,8 @@ TEST(CollectAndValidateParamDefinitions, const std::list kNoMixPresentationObus = {}; absl::flat_hash_map audio_elements; AddAmbisonicsMonoAudioElementWithSubstreamIds( - kAudioElementId, kCodecConfigId, {kFirstSubstreamId}, input_codec_configs, - audio_elements); + kAudioElementId, kCodecConfigId, kZerothOrderAmbisonicsSubstreamId, + input_codec_configs, audio_elements); auto& audio_element = audio_elements.at(kAudioElementId); audio_element.obu.InitializeParams(1); audio_element.obu.audio_element_params_[0] = AudioElementParam{ @@ -547,8 +550,8 @@ TEST(CollectAndValidateParamDefinitions, const std::list kNoMixPresentationObus = {}; absl::flat_hash_map audio_elements; AddAmbisonicsMonoAudioElementWithSubstreamIds( - kAudioElementId, kCodecConfigId, {kFirstSubstreamId}, input_codec_configs, - audio_elements); + kAudioElementId, kCodecConfigId, kZerothOrderAmbisonicsSubstreamId, + input_codec_configs, audio_elements); // Add an extension param definition to the audio element. It is not possible // to determine the ID to store it or to use further processing. diff --git a/iamf/cli/tests/demixing_module_test.cc b/iamf/cli/tests/demixing_module_test.cc index 534b363..405a293 100644 --- a/iamf/cli/tests/demixing_module_test.cc +++ b/iamf/cli/tests/demixing_module_test.cc @@ -273,12 +273,13 @@ TEST(InitializeForReconstruction, CreatesNoDemixersForSingleLayerChannelBased) { TEST(InitializeForReconstruction, CreatesNoDemixersForAmbisonics) { const DecodedUleb128 kCodecConfigId = 0; + constexpr std::array kAmbisonicsSubstreamIds{0, 1, 2, 3}; absl::flat_hash_map codec_configs; AddLpcmCodecConfigWithIdAndSampleRate(kCodecConfigId, 48000, codec_configs); absl::flat_hash_map audio_elements; AddAmbisonicsMonoAudioElementWithSubstreamIds(kAudioElementId, kCodecConfigId, - {0, 1, 2, 3}, codec_configs, - audio_elements); + kAmbisonicsSubstreamIds, + codec_configs, audio_elements); DemixingModule demixing_module; EXPECT_THAT(demixing_module.InitializeForReconstruction(audio_elements), IsOk()); diff --git a/iamf/cli/tests/global_timing_module_test.cc b/iamf/cli/tests/global_timing_module_test.cc index 0e55ac7..b2e0334 100644 --- a/iamf/cli/tests/global_timing_module_test.cc +++ b/iamf/cli/tests/global_timing_module_test.cc @@ -14,7 +14,6 @@ #include #include #include -#include #include "absl/container/flat_hash_map.h" #include "absl/status/status.h" @@ -39,7 +38,6 @@ const DecodedUleb128 kSampleRate = 48000; const DecodedUleb128 kFirstAudioElementId = 0; const DecodedUleb128 kFirstAudioFrameId = 1000; const DecodedUleb128 kFirstParameterId = 0; -const DecodedUleb128 kParameterIdForLoggingPurposes = kFirstParameterId; class GlobalTimingModuleTest : public ::testing::Test { protected: @@ -47,8 +45,8 @@ class GlobalTimingModuleTest : public ::testing::Test { AddLpcmCodecConfigWithIdAndSampleRate(kCodecConfigId, kSampleRate, codec_config_obus_); AddAmbisonicsMonoAudioElementWithSubstreamIds( - kFirstAudioElementId, kCodecConfigId, {1000}, codec_config_obus_, - audio_elements_); + kFirstAudioElementId, kCodecConfigId, {kFirstAudioFrameId}, + codec_config_obus_, audio_elements_); EXPECT_THAT(Initialize(), IsOk()); TestGetNextAudioFrameStamps(kFirstAudioFrameId, 512, 0, 512); @@ -128,14 +126,15 @@ TEST_F(GlobalTimingModuleTest, OneSubstream) { } TEST_F(GlobalTimingModuleTest, InvalidUnknownSubstreamId) { + constexpr DecodedUleb128 kSubstreamId = 9999; + constexpr DecodedUleb128 kUnknownSubstreamId = 10000; AddLpcmCodecConfigWithIdAndSampleRate(kCodecConfigId, kSampleRate, codec_config_obus_); AddAmbisonicsMonoAudioElementWithSubstreamIds( - kFirstAudioElementId, kCodecConfigId, {0}, codec_config_obus_, + kFirstAudioElementId, kCodecConfigId, {kSubstreamId}, codec_config_obus_, audio_elements_); EXPECT_THAT(Initialize(), IsOk()); - const DecodedUleb128 kUnknownSubstreamId = 9999; TestGetNextAudioFrameStamps(kUnknownSubstreamId, 128, 0, 128, absl::StatusCode::kInvalidArgument); } @@ -152,22 +151,24 @@ TEST_F(GlobalTimingModuleTest, InvalidDuplicateSubstreamIds) { } TEST_F(GlobalTimingModuleTest, TwoAudioElements) { + constexpr DecodedUleb128 kFirstSubstreamId = kFirstAudioFrameId; + constexpr DecodedUleb128 kSecondSubstreamId = 2000; AddLpcmCodecConfigWithIdAndSampleRate(kCodecConfigId, kSampleRate, codec_config_obus_); AddAmbisonicsMonoAudioElementWithSubstreamIds( - kFirstAudioElementId, kCodecConfigId, {kFirstAudioFrameId}, + kFirstAudioElementId, kCodecConfigId, {kFirstSubstreamId}, codec_config_obus_, audio_elements_); const DecodedUleb128 kSecondAudioElementId = 1; ASSERT_NE(kFirstAudioElementId, kSecondAudioElementId); AddAmbisonicsMonoAudioElementWithSubstreamIds( - kSecondAudioElementId, kCodecConfigId, {2000}, codec_config_obus_, - audio_elements_); + kSecondAudioElementId, kCodecConfigId, {kSecondSubstreamId}, + codec_config_obus_, audio_elements_); EXPECT_THAT(Initialize(), IsOk()); // All subtreams have separate time keeping functionality. - TestGetNextAudioFrameStamps(kFirstAudioFrameId, 128, 0, 128); - TestGetNextAudioFrameStamps(kFirstAudioFrameId, 128, 128, 256); - TestGetNextAudioFrameStamps(kFirstAudioFrameId, 128, 256, 384); + TestGetNextAudioFrameStamps(kFirstSubstreamId, 128, 0, 128); + TestGetNextAudioFrameStamps(kFirstSubstreamId, 128, 128, 256); + TestGetNextAudioFrameStamps(kFirstSubstreamId, 128, 256, 384); TestGetNextAudioFrameStamps(2000, 256, 0, 256); TestGetNextAudioFrameStamps(2000, 256, 256, 512); diff --git a/iamf/cli/tests/parameters_manager_test.cc b/iamf/cli/tests/parameters_manager_test.cc index 30f8842..c37e435 100644 --- a/iamf/cli/tests/parameters_manager_test.cc +++ b/iamf/cli/tests/parameters_manager_test.cc @@ -41,6 +41,8 @@ using ::absl_testing::IsOk; constexpr DecodedUleb128 kCodecConfigId = 1450; constexpr DecodedUleb128 kSampleRate = 16000; constexpr DecodedUleb128 kAudioElementId = 157; +constexpr DecodedUleb128 kFirstSubstreamId = 0; +constexpr DecodedUleb128 kSecondSubstreamId = 1; constexpr DecodedUleb128 kParameterId = 995; constexpr DecodedUleb128 kSecondParameterId = 996; constexpr DecodedUleb128 kDuration = 8; @@ -112,8 +114,8 @@ class ParametersManagerTest : public testing::Test { AddLpcmCodecConfigWithIdAndSampleRate(kCodecConfigId, kSampleRate, codec_config_obus_); AddAmbisonicsMonoAudioElementWithSubstreamIds( - kAudioElementId, kCodecConfigId, - /*substream_ids=*/{100}, codec_config_obus_, audio_elements_); + kAudioElementId, kCodecConfigId, {kFirstSubstreamId}, + codec_config_obus_, audio_elements_); auto& audio_element_obu = audio_elements_.at(kAudioElementId).obu; AddDemixingParamDefinition(kParameterId, kSampleRate, kDuration, @@ -554,8 +556,8 @@ TEST_F(ParametersManagerTest, // Add a second audio element sharing the same demixing parameter. constexpr DecodedUleb128 kAudioElementId2 = kAudioElementId + 1; AddAmbisonicsMonoAudioElementWithSubstreamIds( - kAudioElementId2, kCodecConfigId, - /*substream_ids=*/{200}, codec_config_obus_, audio_elements_); + kAudioElementId2, kCodecConfigId, {kSecondSubstreamId}, + codec_config_obus_, audio_elements_); auto& second_audio_element_obu = audio_elements_.at(kAudioElementId2).obu; AddDemixingParamDefinition(kParameterId, kSampleRate, kDuration, second_audio_element_obu, diff --git a/iamf/cli/tests/profile_filter_test.cc b/iamf/cli/tests/profile_filter_test.cc index 0782f18..8154681 100644 --- a/iamf/cli/tests/profile_filter_test.cc +++ b/iamf/cli/tests/profile_filter_test.cc @@ -11,6 +11,7 @@ */ #include "iamf/cli/profile_filter.h" +#include #include #include #include @@ -54,7 +55,8 @@ const uint32_t kCommonMixGainParameterRate = kSampleRate; const uint8_t kAudioElementReserved = 0; const int kOneLayer = 1; -const std::vector kSubstreamIdsForFourthOrderAmbisonics = { +constexpr std::array kZerothOrderAmbisonicsSubstreamId{100}; +constexpr std::array kFourthOrderAmbisonicsSubstreamIds = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24}; @@ -369,7 +371,7 @@ void InitializeDescriptorObusForOneMonoAmbisonicsAudioElement( AddLpcmCodecConfigWithIdAndSampleRate(kCodecConfigId, kSampleRate, codec_config_obus); AddAmbisonicsMonoAudioElementWithSubstreamIds( - kFirstAudioElementId, kCodecConfigId, {kFirstSubstreamId}, + kFirstAudioElementId, kCodecConfigId, kZerothOrderAmbisonicsSubstreamId, codec_config_obus, audio_elements); AddMixPresentationObuWithAudioElementIds( kFirstMixPresentationId, {kFirstAudioElementId}, @@ -384,8 +386,8 @@ void InitializeDescriptorObusForOneFourthOrderAmbisonicsAudioElement( AddLpcmCodecConfigWithIdAndSampleRate(kCodecConfigId, kSampleRate, codec_config_obus); AddAmbisonicsMonoAudioElementWithSubstreamIds( - kFirstAudioElementId, kCodecConfigId, - kSubstreamIdsForFourthOrderAmbisonics, codec_config_obus, audio_elements); + kFirstAudioElementId, kCodecConfigId, kFourthOrderAmbisonicsSubstreamIds, + codec_config_obus, audio_elements); AddMixPresentationObuWithAudioElementIds( kFirstMixPresentationId, {kFirstAudioElementId}, diff --git a/iamf/cli/tests/rendering_mix_presentation_finalizer_test.cc b/iamf/cli/tests/rendering_mix_presentation_finalizer_test.cc index 7675c0f..6efabfc 100644 --- a/iamf/cli/tests/rendering_mix_presentation_finalizer_test.cc +++ b/iamf/cli/tests/rendering_mix_presentation_finalizer_test.cc @@ -11,6 +11,7 @@ */ #include "iamf/cli/rendering_mix_presentation_finalizer.h" +#include #include #include #include @@ -175,12 +176,12 @@ constexpr uint8_t kCodecConfigBitDepth = 16; void InitPrerequisiteObusForStereoInput( absl::flat_hash_map& codec_configs, absl::flat_hash_map& audio_elements) { - const std::vector kStereoSubstreamIds = {0}; + constexpr std::array kStereoSubstreamId{0}; AddLpcmCodecConfigWithIdAndSampleRate(kCodecConfigId, kSampleRate, codec_configs); AddScalableAudioElementWithSubstreamIds(kAudioElementId, kCodecConfigId, - kStereoSubstreamIds, codec_configs, + kStereoSubstreamId, codec_configs, audio_elements); // Fill in the first layer correctly for stereo input. @@ -195,12 +196,12 @@ void InitPrerequisiteObusForStereoInput( void InitPrerequisiteObusForMonoInput( absl::flat_hash_map& codec_configs, absl::flat_hash_map& audio_elements) { - const std::vector kMonoSubstreamIds = {0}; + constexpr std::array kMonoSubstreamId{0}; AddLpcmCodecConfigWithIdAndSampleRate(kCodecConfigId, kSampleRate, codec_configs); AddScalableAudioElementWithSubstreamIds(kAudioElementId, kCodecConfigId, - kMonoSubstreamIds, codec_configs, + kMonoSubstreamId, codec_configs, audio_elements); // Fill in the first layer correctly for mono input. diff --git a/iamf/cli/tests/wav_sample_provider_test.cc b/iamf/cli/tests/wav_sample_provider_test.cc index 65c8679..b94a1c8 100644 --- a/iamf/cli/tests/wav_sample_provider_test.cc +++ b/iamf/cli/tests/wav_sample_provider_test.cc @@ -15,7 +15,6 @@ #include #include #include -#include // [internal] Placeholder for get runfiles header. #include "absl/container/flat_hash_map.h" @@ -43,6 +42,7 @@ using testing::DoubleEq; using testing::Pointwise; constexpr DecodedUleb128 kAudioElementId = 300; +constexpr DecodedUleb128 kSubstreamId = 0; constexpr DecodedUleb128 kCodecConfigId = 200; constexpr uint32_t kSampleRate = 48000; @@ -102,9 +102,8 @@ void InitializeTestData( codec_config_obus.clear(); AddLpcmCodecConfigWithIdAndSampleRate(kCodecConfigId, sample_rate, codec_config_obus); - const std::vector kSubstreamIds = {0}; AddScalableAudioElementWithSubstreamIds(kAudioElementId, kCodecConfigId, - kSubstreamIds, codec_config_obus, + {kSubstreamId}, codec_config_obus, audio_elements); }