From b613647188ccf7f8030a28c1c5b94235a58ebda0 Mon Sep 17 00:00:00 2001 From: yero Date: Wed, 4 Sep 2024 05:39:17 -0400 Subject: [PATCH] Defines `InternalSampleType` in types.h (formerly leb128.h) - This allows controlling the type in a central place, in case we want to change it in the future. - Use this type for internal computation. Convert to/from int32_t only when necessary, e.g. - File IO. - Encoding and decoding using underlying codecs. - Computing recon gains. PiperOrigin-RevId: 670894393 --- iamf/cli/BUILD | 23 +- iamf/cli/audio_element_with_data.h | 2 +- iamf/cli/cli_util.cc | 2 +- iamf/cli/cli_util.h | 2 +- iamf/cli/codec/tests/BUILD | 2 +- iamf/cli/codec/tests/encoder_base_test.cc | 2 +- iamf/cli/demixing_module.cc | 291 +++++------------- iamf/cli/demixing_module.h | 7 +- iamf/cli/encoder_main_lib.cc | 2 +- iamf/cli/global_timing_module.cc | 2 +- iamf/cli/global_timing_module.h | 2 +- iamf/cli/iamf_encoder.cc | 4 +- iamf/cli/iamf_encoder.h | 4 +- iamf/cli/leb_generator.cc | 2 +- iamf/cli/leb_generator.h | 2 +- iamf/cli/mix_presentation_finalizer.h | 2 +- iamf/cli/obu_to_proto/BUILD | 2 +- .../parameter_block_metadata_generator.cc | 2 +- iamf/cli/obu_to_proto/tests/BUILD | 2 +- ...parameter_block_metadata_generator_test.cc | 2 +- iamf/cli/parameters_manager.cc | 2 +- iamf/cli/parameters_manager.h | 2 +- iamf/cli/proto_to_obu/BUILD | 8 +- .../proto_to_obu/audio_element_generator.cc | 2 +- .../proto_to_obu/audio_element_generator.h | 2 +- .../cli/proto_to_obu/audio_frame_generator.cc | 4 +- iamf/cli/proto_to_obu/audio_frame_generator.h | 4 +- .../mix_presentation_generator.cc | 2 +- .../proto_to_obu/parameter_block_generator.cc | 2 +- .../proto_to_obu/parameter_block_generator.h | 2 +- iamf/cli/proto_to_obu/tests/BUILD | 10 +- .../tests/audio_element_generator_test.cc | 2 +- .../tests/audio_frame_generator_test.cc | 10 +- .../tests/codec_config_generator_test.cc | 2 +- .../tests/mix_presentation_generator_test.cc | 2 +- .../tests/parameter_block_generator_test.cc | 4 +- iamf/cli/recon_gain_generator.cc | 16 +- iamf/cli/renderer/BUILD | 3 + .../renderer/audio_element_renderer_base.cc | 4 +- .../renderer/audio_element_renderer_base.h | 6 +- .../audio_element_renderer_passthrough.cc | 5 +- iamf/cli/renderer/renderer_utils.cc | 10 +- iamf/cli/renderer/renderer_utils.h | 4 +- iamf/cli/renderer/tests/BUILD | 3 + .../tests/audio_element_renderer_base_test.cc | 20 +- ...audio_element_renderer_passthrough_test.cc | 124 +++----- .../cli/renderer/tests/renderer_utils_test.cc | 60 ++-- iamf/cli/renderer_factory.cc | 2 +- iamf/cli/renderer_factory.h | 2 +- iamf/cli/tests/BUILD | 25 +- iamf/cli/tests/audio_frame_decoder_test.cc | 2 +- iamf/cli/tests/cli_test_utils.cc | 4 +- iamf/cli/tests/cli_test_utils.h | 4 +- iamf/cli/tests/cli_util_test.cc | 2 +- iamf/cli/tests/demixing_module_test.cc | 78 +++-- iamf/cli/tests/global_timing_module_test.cc | 2 +- iamf/cli/tests/iamf_encoder_test.cc | 4 +- iamf/cli/tests/leb_generator_test.cc | 2 +- .../tests/mix_presentation_finalizer_test.cc | 2 +- iamf/cli/tests/obu_sequencer_test.cc | 2 +- iamf/cli/tests/parameters_manager_test.cc | 2 +- iamf/cli/tests/profile_filter_test.cc | 2 +- iamf/cli/tests/recon_gain_generator_test.cc | 20 +- iamf/cli/tests/wav_sample_provider_test.cc | 12 +- iamf/cli/wav_sample_provider.cc | 5 +- iamf/cli/wav_sample_provider.h | 2 +- iamf/common/BUILD | 6 +- iamf/common/obu_util.cc | 2 +- iamf/common/obu_util.h | 2 +- iamf/common/read_bit_buffer.cc | 2 +- iamf/common/read_bit_buffer.h | 2 +- iamf/common/tests/BUILD | 4 +- iamf/common/tests/read_bit_buffer_test.cc | 2 +- iamf/common/tests/write_bit_buffer_test.cc | 2 +- iamf/common/write_bit_buffer.cc | 2 +- iamf/common/write_bit_buffer.h | 2 +- iamf/obu/BUILD | 18 +- iamf/obu/audio_element.cc | 2 +- iamf/obu/audio_element.h | 2 +- iamf/obu/audio_frame.cc | 2 +- iamf/obu/audio_frame.h | 2 +- iamf/obu/codec_config.cc | 2 +- iamf/obu/codec_config.h | 2 +- iamf/obu/mix_presentation.cc | 2 +- iamf/obu/mix_presentation.h | 2 +- iamf/obu/obu_header.cc | 2 +- iamf/obu/obu_header.h | 2 +- iamf/obu/param_definitions.cc | 2 +- iamf/obu/param_definitions.h | 2 +- iamf/obu/parameter_block.cc | 2 +- iamf/obu/parameter_block.h | 2 +- iamf/obu/tests/BUILD | 12 +- iamf/obu/tests/audio_element_test.cc | 2 +- iamf/obu/tests/audio_frame_test.cc | 2 +- iamf/obu/tests/codec_config_test.cc | 2 +- iamf/obu/tests/mix_presentation_test.cc | 2 +- iamf/obu/tests/param_definitions_test.cc | 2 +- iamf/obu/tests/parameter_block_test.cc | 2 +- iamf/obu/{leb128.h => types.h} | 7 +- 99 files changed, 407 insertions(+), 544 deletions(-) rename iamf/obu/{leb128.h => types.h} (83%) diff --git a/iamf/cli/BUILD b/iamf/cli/BUILD index b1023b28..8565df33 100644 --- a/iamf/cli/BUILD +++ b/iamf/cli/BUILD @@ -18,8 +18,8 @@ cc_library( ":channel_label", "//iamf/obu:audio_element", "//iamf/obu:codec_config", - "//iamf/obu:leb128", "//iamf/obu:parameter_block", + "//iamf/obu:types", "@com_google_absl//absl/container:flat_hash_map", ], ) @@ -95,11 +95,11 @@ cc_library( "//iamf/obu:codec_config", "//iamf/obu:demixing_info_param_data", "//iamf/obu:ia_sequence_header", - "//iamf/obu:leb128", "//iamf/obu:mix_presentation", "//iamf/obu:obu_header", "//iamf/obu:param_definitions", "//iamf/obu:parameter_block", + "//iamf/obu:types", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:flat_hash_set", "@com_google_absl//absl/log", @@ -126,8 +126,8 @@ cc_library( "//iamf/obu:audio_element", "//iamf/obu:audio_frame", "//iamf/obu:demixing_info_param_data", - "//iamf/obu:leb128", "//iamf/obu:parameter_block", + "//iamf/obu:types", "@com_google_absl//absl/container:btree", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:flat_hash_set", @@ -162,8 +162,8 @@ cc_library( "//iamf/obu:arbitrary_obu", "//iamf/obu:codec_config", "//iamf/obu:ia_sequence_header", - "//iamf/obu:leb128", "//iamf/obu:mix_presentation", + "//iamf/obu:types", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/log", "@com_google_absl//absl/status", @@ -185,8 +185,8 @@ cc_library( "//iamf/common:obu_util", "//iamf/obu:audio_element", "//iamf/obu:codec_config", - "//iamf/obu:leb128", "//iamf/obu:param_definitions", + "//iamf/obu:types", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:flat_hash_set", "@com_google_absl//absl/log", @@ -236,10 +236,10 @@ cc_library( "//iamf/common:macros", "//iamf/obu:codec_config", "//iamf/obu:ia_sequence_header", - "//iamf/obu:leb128", "//iamf/obu:mix_presentation", "//iamf/obu:param_definitions", "//iamf/obu:parameter_block", + "//iamf/obu:types", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/log", "@com_google_absl//absl/status", @@ -254,7 +254,7 @@ cc_library( deps = [ "//iamf/cli/proto:test_vector_metadata_cc_proto", "//iamf/cli/proto:user_metadata_cc_proto", - "//iamf/obu:leb128", + "//iamf/obu:types", "@com_google_absl//absl/log", "@com_google_absl//absl/memory", "@com_google_absl//absl/status", @@ -293,8 +293,8 @@ cc_library( ":parameter_block_with_data", ":wav_writer", "//iamf/cli/proto:mix_presentation_cc_proto", - "//iamf/obu:leb128", "//iamf/obu:mix_presentation", + "//iamf/obu:types", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/functional:any_invocable", "@com_google_absl//absl/log", @@ -364,9 +364,9 @@ cc_library( ":parameter_block_with_data", "//iamf/common:macros", "//iamf/obu:demixing_info_param_data", - "//iamf/obu:leb128", "//iamf/obu:param_definitions", "//iamf/obu:parameter_block", + "//iamf/obu:types", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/log", "@com_google_absl//absl/log:check", @@ -403,6 +403,7 @@ cc_library( ":demixing_module", "//iamf/common:macros", "//iamf/common:obu_util", + "//iamf/obu:types", "@com_google_absl//absl/base:no_destructor", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/log", @@ -419,8 +420,8 @@ cc_library( ":audio_element_with_data", "//iamf/cli/renderer:audio_element_renderer_base", "//iamf/obu:audio_element", - "//iamf/obu:leb128", "//iamf/obu:mix_presentation", + "//iamf/obu:types", ], ) @@ -448,7 +449,7 @@ cc_library( ":wav_reader", "//iamf/cli/proto:audio_frame_cc_proto", "//iamf/common:macros", - "//iamf/obu:leb128", + "//iamf/obu:types", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/log", "@com_google_absl//absl/status", diff --git a/iamf/cli/audio_element_with_data.h b/iamf/cli/audio_element_with_data.h index 4ef184b4..ad72f3f6 100644 --- a/iamf/cli/audio_element_with_data.h +++ b/iamf/cli/audio_element_with_data.h @@ -20,8 +20,8 @@ #include "iamf/cli/channel_label.h" #include "iamf/obu/audio_element.h" #include "iamf/obu/codec_config.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/parameter_block.h" +#include "iamf/obu/types.h" namespace iamf_tools { diff --git a/iamf/cli/cli_util.cc b/iamf/cli/cli_util.cc index 0f009044..adf00a59 100644 --- a/iamf/cli/cli_util.cc +++ b/iamf/cli/cli_util.cc @@ -38,11 +38,11 @@ #include "iamf/obu/codec_config.h" #include "iamf/obu/demixing_info_param_data.h" #include "iamf/obu/ia_sequence_header.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/mix_presentation.h" #include "iamf/obu/obu_header.h" #include "iamf/obu/param_definitions.h" #include "iamf/obu/parameter_block.h" +#include "iamf/obu/types.h" namespace iamf_tools { diff --git a/iamf/cli/cli_util.h b/iamf/cli/cli_util.h index 92809f39..10078d6b 100644 --- a/iamf/cli/cli_util.h +++ b/iamf/cli/cli_util.h @@ -31,11 +31,11 @@ #include "iamf/obu/codec_config.h" #include "iamf/obu/demixing_info_param_data.h" #include "iamf/obu/ia_sequence_header.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/mix_presentation.h" #include "iamf/obu/obu_header.h" #include "iamf/obu/param_definitions.h" #include "iamf/obu/parameter_block.h" +#include "iamf/obu/types.h" namespace iamf_tools { diff --git a/iamf/cli/codec/tests/BUILD b/iamf/cli/codec/tests/BUILD index acb4dba5..e74c6eb7 100644 --- a/iamf/cli/codec/tests/BUILD +++ b/iamf/cli/codec/tests/BUILD @@ -48,8 +48,8 @@ cc_test( "//iamf/cli/codec:encoder_base", "//iamf/obu:audio_frame", "//iamf/obu:codec_config", - "//iamf/obu:leb128", "//iamf/obu:obu_header", + "//iamf/obu:types", "@com_google_absl//absl/status", "@com_google_absl//absl/status:status_matchers", "@com_google_googletest//:gtest_main", diff --git a/iamf/cli/codec/tests/encoder_base_test.cc b/iamf/cli/codec/tests/encoder_base_test.cc index 70ff7358..72a4d4f2 100644 --- a/iamf/cli/codec/tests/encoder_base_test.cc +++ b/iamf/cli/codec/tests/encoder_base_test.cc @@ -24,8 +24,8 @@ #include "iamf/cli/audio_frame_with_data.h" #include "iamf/obu/audio_frame.h" #include "iamf/obu/codec_config.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/obu_header.h" +#include "iamf/obu/types.h" namespace iamf_tools { namespace { diff --git a/iamf/cli/demixing_module.cc b/iamf/cli/demixing_module.cc index 23f30feb..16324d7b 100644 --- a/iamf/cli/demixing_module.cc +++ b/iamf/cli/demixing_module.cc @@ -39,7 +39,7 @@ #include "iamf/obu/audio_element.h" #include "iamf/obu/audio_frame.h" #include "iamf/obu/demixing_info_param_data.h" -#include "iamf/obu/leb128.h" +#include "iamf/obu/types.h" namespace iamf_tools { @@ -83,23 +83,11 @@ absl::Status S7ToS5DownMixer(const DownMixingParams& down_mixing_params, // Handle Ls5 and Rs5. ls5_samples.resize(lss7_samples.size()); rs5_samples.resize(rss7_samples.size()); - - // Computation in double. - std::vector ls5_samples_double(ls5_samples.size(), 0.0); - std::vector rs5_samples_double(rs5_samples.size(), 0.0); - for (int i = 0; i < ls5_samples.size(); i++) { - ls5_samples_double[i] = - down_mixing_params.alpha * static_cast(lss7_samples[i]) + - down_mixing_params.beta * static_cast(lrs7_samples[i]); - rs5_samples_double[i] = - down_mixing_params.alpha * static_cast(rss7_samples[i]) + - down_mixing_params.beta * static_cast(rrs7_samples[i]); - } - - // Convert back to int32_t. for (int i = 0; i < ls5_samples.size(); i++) { - RETURN_IF_NOT_OK(ClipDoubleToInt32(ls5_samples_double[i], ls5_samples[i])); - RETURN_IF_NOT_OK(ClipDoubleToInt32(rs5_samples_double[i], rs5_samples[i])); + ls5_samples[i] = down_mixing_params.alpha * lss7_samples[i] + + down_mixing_params.beta * lrs7_samples[i]; + rs5_samples[i] = down_mixing_params.alpha * rss7_samples[i] + + down_mixing_params.beta * rrs7_samples[i]; } return absl::OkStatus(); @@ -109,12 +97,12 @@ absl::Status S5ToS7Demixer(const DownMixingParams& down_mixing_params, LabelSamplesMap& label_to_samples) { LOG_FIRST_N(INFO, 1) << "S5 to S7"; - const std::vector* l5_samples; - const std::vector* ls5_samples; - const std::vector* lss7_samples; - const std::vector* r5_samples; - const std::vector* rs5_samples; - const std::vector* rss7_samples; + const std::vector* l5_samples; + const std::vector* ls5_samples; + const std::vector* lss7_samples; + const std::vector* r5_samples; + const std::vector* rs5_samples; + const std::vector* rss7_samples; RETURN_IF_NOT_OK(DemixingModule::FindSamplesOrDemixedSamples( kL5, label_to_samples, &l5_samples)); RETURN_IF_NOT_OK(DemixingModule::FindSamplesOrDemixedSamples( @@ -141,29 +129,15 @@ absl::Status S5ToS7Demixer(const DownMixingParams& down_mixing_params, const size_t num_ticks = l5_samples->size(); lrs7_samples.resize(num_ticks, 0.0); rrs7_samples.resize(num_ticks, 0.0); - - // Computation in double. - std::vector lrs7_samples_double(num_ticks, 0.0); - std::vector rrs7_samples_double(num_ticks, 0.0); for (int i = 0; i < num_ticks; i++) { - lrs7_samples_double[i] = - (static_cast((*ls5_samples)[i]) - - down_mixing_params.alpha * static_cast((*lss7_samples)[i])) / + lrs7_samples[i] = + ((*ls5_samples)[i] - down_mixing_params.alpha * (*lss7_samples)[i]) / down_mixing_params.beta; - rrs7_samples_double[i] = - (static_cast((*rs5_samples)[i]) - - down_mixing_params.alpha * static_cast((*rss7_samples)[i])) / + rrs7_samples[i] = + ((*rs5_samples)[i] - down_mixing_params.alpha * (*rss7_samples)[i]) / down_mixing_params.beta; } - // Convert back to int32_t. - for (int i = 0; i < num_ticks; i++) { - RETURN_IF_NOT_OK( - ClipDoubleToInt32(lrs7_samples_double[i], lrs7_samples[i])); - RETURN_IF_NOT_OK( - ClipDoubleToInt32(rrs7_samples_double[i], rrs7_samples[i])); - } - return absl::OkStatus(); } @@ -188,23 +162,9 @@ absl::Status S5ToS3DownMixer(const DownMixingParams& down_mixing_params, auto& r3_samples = label_to_samples[kR3]; l3_samples.resize(l5_samples.size()); r3_samples.resize(r5_samples.size()); - - // Computation in double. - std::vector l3_samples_double(l3_samples.size(), 0.0); - std::vector r3_samples_double(r3_samples.size(), 0.0); for (int i = 0; i < l3_samples.size(); i++) { - l3_samples_double[i] = - static_cast(l5_samples[i]) + - down_mixing_params.delta * static_cast(ls5_samples[i]); - r3_samples_double[i] = - static_cast(r5_samples[i]) + - down_mixing_params.delta * static_cast(rs5_samples[i]); - } - - // Convert back to int32_t. - for (int i = 0; i < l3_samples.size(); i++) { - RETURN_IF_NOT_OK(ClipDoubleToInt32(l3_samples_double[i], l3_samples[i])); - RETURN_IF_NOT_OK(ClipDoubleToInt32(r3_samples_double[i], r3_samples[i])); + l3_samples[i] = l5_samples[i] + down_mixing_params.delta * ls5_samples[i]; + r3_samples[i] = r5_samples[i] + down_mixing_params.delta * rs5_samples[i]; } return absl::OkStatus(); @@ -214,10 +174,10 @@ absl::Status S3ToS5Demixer(const DownMixingParams& down_mixing_params, LabelSamplesMap& label_to_samples) { LOG_FIRST_N(INFO, 1) << "S3 to S5"; - const std::vector* l3_samples; - const std::vector* l5_samples; - const std::vector* r3_samples; - const std::vector* r5_samples; + const std::vector* l3_samples; + const std::vector* l5_samples; + const std::vector* r3_samples; + const std::vector* r5_samples; RETURN_IF_NOT_OK(DemixingModule::FindSamplesOrDemixedSamples( kL3, label_to_samples, &l3_samples)); RETURN_IF_NOT_OK(DemixingModule::FindSamplesOrDemixedSamples( @@ -233,23 +193,11 @@ absl::Status S3ToS5Demixer(const DownMixingParams& down_mixing_params, const size_t num_ticks = l3_samples->size(); ls5_samples.resize(num_ticks, 0.0); rs5_samples.resize(num_ticks, 0.0); - - // Computation in double. - std::vector ls5_samples_double(num_ticks, 0.0); - std::vector rs5_samples_double(num_ticks, 0.0); for (int i = 0; i < num_ticks; i++) { - ls5_samples_double[i] = (static_cast((*l3_samples)[i]) - - static_cast((*l5_samples)[i])) / - down_mixing_params.delta; - rs5_samples_double[i] = (static_cast((*r3_samples)[i]) - - static_cast((*r5_samples)[i])) / - down_mixing_params.delta; - } - - // Convert back to int32_t. - for (int i = 0; i < num_ticks; i++) { - RETURN_IF_NOT_OK(ClipDoubleToInt32(ls5_samples_double[i], ls5_samples[i])); - RETURN_IF_NOT_OK(ClipDoubleToInt32(rs5_samples_double[i], rs5_samples[i])); + ls5_samples[i] = + ((*l3_samples)[i] - (*l5_samples)[i]) / down_mixing_params.delta; + rs5_samples[i] = + ((*r3_samples)[i] - (*r5_samples)[i]) / down_mixing_params.delta; } return absl::OkStatus(); @@ -274,21 +222,9 @@ absl::Status S3ToS2DownMixer(const DownMixingParams& /*down_mixing_params*/, auto& r2_samples = label_to_samples[kR2]; l2_samples.resize(l3_samples.size()); r2_samples.resize(r3_samples.size()); - - // Computation in double. - std::vector l2_samples_double(l2_samples.size(), 0.0); - std::vector r2_samples_double(r2_samples.size(), 0.0); for (int i = 0; i < l2_samples.size(); i++) { - l2_samples_double[i] = static_cast(l3_samples[i]) + - 0.707 * static_cast(c_samples[i]); - r2_samples_double[i] = static_cast(r3_samples[i]) + - 0.707 * static_cast(c_samples[i]); - } - - // Convert back to int32_t. - for (int i = 0; i < l2_samples.size(); i++) { - RETURN_IF_NOT_OK(ClipDoubleToInt32(l2_samples_double[i], l2_samples[i])); - RETURN_IF_NOT_OK(ClipDoubleToInt32(r2_samples_double[i], r2_samples[i])); + l2_samples[i] = l3_samples[i] + 0.707 * c_samples[i]; + r2_samples[i] = r3_samples[i] + 0.707 * c_samples[i]; } return absl::OkStatus(); @@ -298,9 +234,9 @@ absl::Status S2ToS3Demixer(const DownMixingParams& /*down_mixing_params*/, LabelSamplesMap& label_to_samples) { LOG_FIRST_N(INFO, 1) << "S2 to S3"; - const std::vector* l2_samples; - const std::vector* r2_samples; - const std::vector* c_samples; + const std::vector* l2_samples; + const std::vector* r2_samples; + const std::vector* c_samples; RETURN_IF_NOT_OK(DemixingModule::FindSamplesOrDemixedSamples( kL2, label_to_samples, &l2_samples)); RETURN_IF_NOT_OK(DemixingModule::FindSamplesOrDemixedSamples( @@ -314,21 +250,9 @@ absl::Status S2ToS3Demixer(const DownMixingParams& /*down_mixing_params*/, const size_t num_ticks = c_samples->size(); l3_samples.resize(num_ticks, 0.0); r3_samples.resize(num_ticks, 0.0); - - // Computation in double. - std::vector l3_samples_double(num_ticks, 0.0); - std::vector r3_samples_double(num_ticks, 0.0); for (int i = 0; i < num_ticks; i++) { - l3_samples_double[i] = (static_cast((*l2_samples)[i]) - - 0.707 * static_cast((*c_samples)[i])); - r3_samples_double[i] = (static_cast((*r2_samples)[i]) - - 0.707 * static_cast((*c_samples)[i])); - } - - // Convert back to int32_t. - for (int i = 0; i < num_ticks; i++) { - RETURN_IF_NOT_OK(ClipDoubleToInt32(l3_samples_double[i], l3_samples[i])); - RETURN_IF_NOT_OK(ClipDoubleToInt32(r3_samples_double[i], r3_samples[i])); + l3_samples[i] = ((*l2_samples)[i] - 0.707 * (*c_samples)[i]); + r3_samples[i] = ((*r2_samples)[i] - 0.707 * (*c_samples)[i]); } return absl::OkStatus(); @@ -349,18 +273,8 @@ absl::Status S2ToS1DownMixer(const DownMixingParams& /*down_mixing_params*/, auto& mono_samples = label_to_samples[kMono]; mono_samples.resize(l2_samples.size()); - - // Computation in double. - std::vector mono_samples_double(l2_samples.size(), 0.0); - for (int i = 0; i < mono_samples_double.size(); i++) { - mono_samples_double[i] = 0.5 * (static_cast(l2_samples[i]) + - static_cast(r2_samples[i])); - } - - // Convert back to int32_t. for (int i = 0; i < mono_samples.size(); i++) { - RETURN_IF_NOT_OK( - ClipDoubleToInt32(mono_samples_double[i], mono_samples[i])); + mono_samples[i] = 0.5 * (l2_samples[i] + r2_samples[i]); } return absl::OkStatus(); @@ -370,8 +284,8 @@ absl::Status S1ToS2Demixer(const DownMixingParams& /*down_mixing_params*/, LabelSamplesMap& label_to_samples) { LOG_FIRST_N(INFO, 1) << "S1 to S2"; - const std::vector* l2_samples; - const std::vector* mono_samples; + const std::vector* l2_samples; + const std::vector* mono_samples; RETURN_IF_NOT_OK(DemixingModule::FindSamplesOrDemixedSamples( kL2, label_to_samples, &l2_samples)); RETURN_IF_NOT_OK(DemixingModule::FindSamplesOrDemixedSamples( @@ -380,17 +294,8 @@ absl::Status S1ToS2Demixer(const DownMixingParams& /*down_mixing_params*/, auto& r2_samples = label_to_samples[kDemixedR2]; const size_t num_ticks = mono_samples->size(); r2_samples.resize(num_ticks, 0.0); - - // Computation in double. - std::vector r2_samples_double(num_ticks, 0.0); - for (int i = 0; i < num_ticks; i++) { - r2_samples_double[i] = 2.0 * static_cast((*mono_samples)[i]) - - static_cast((*l2_samples)[i]); - } - - // Convert back to int32_t. for (int i = 0; i < num_ticks; i++) { - RETURN_IF_NOT_OK(ClipDoubleToInt32(r2_samples_double[i], r2_samples[i])); + r2_samples[i] = 2.0 * (*mono_samples)[i] - (*l2_samples)[i]; } return absl::OkStatus(); @@ -417,27 +322,11 @@ absl::Status T4ToT2DownMixer(const DownMixingParams& down_mixing_params, auto& rtf2_samples = label_to_samples[kRtf2]; ltf2_samples.resize(ltf4_samples.size()); rtf2_samples.resize(rtf4_samples.size()); - - // Computation in double. - std::vector ltf2_samples_double(ltf2_samples.size(), 0.0); - std::vector rtf2_samples_double(rtf2_samples.size(), 0.0); for (int i = 0; i < ltf2_samples.size(); i++) { - ltf2_samples_double[i] = - static_cast(ltf4_samples[i]) + - down_mixing_params.gamma * static_cast(ltb4_samples[i]); - rtf2_samples_double[i] = - static_cast(rtf4_samples[i]) + - down_mixing_params.gamma * static_cast(rtb4_samples[i]); - } - - // Clip and convert back to int32_t. - for (int i = 0; i < ltf2_samples.size(); i++) { - RETURN_IF_NOT_OK( - ClipDoubleToInt32(ltf2_samples_double[i], ltf2_samples[i])); - } - for (int i = 0; i < rtf2_samples.size(); i++) { - RETURN_IF_NOT_OK( - ClipDoubleToInt32(rtf2_samples_double[i], rtf2_samples[i])); + ltf2_samples[i] = + ltf4_samples[i] + down_mixing_params.gamma * ltb4_samples[i]; + rtf2_samples[i] = + rtf4_samples[i] + down_mixing_params.gamma * rtb4_samples[i]; } return absl::OkStatus(); @@ -447,10 +336,10 @@ absl::Status T2ToT4Demixer(const DownMixingParams& down_mixing_params, LabelSamplesMap& label_to_samples) { LOG_FIRST_N(INFO, 1) << "T2 to T4"; - const std::vector* ltf2_samples; - const std::vector* ltf4_samples; - const std::vector* rtf2_samples; - const std::vector* rtf4_samples; + const std::vector* ltf2_samples; + const std::vector* ltf4_samples; + const std::vector* rtf2_samples; + const std::vector* rtf4_samples; RETURN_IF_NOT_OK(DemixingModule::FindSamplesOrDemixedSamples( kLtf2, label_to_samples, <f2_samples)); RETURN_IF_NOT_OK(DemixingModule::FindSamplesOrDemixedSamples( @@ -465,25 +354,11 @@ absl::Status T2ToT4Demixer(const DownMixingParams& down_mixing_params, const size_t num_ticks = ltf2_samples->size(); ltb4_samples.resize(num_ticks, 0.0); rtb4_samples.resize(num_ticks, 0.0); - - // Computation in double. - std::vector ltb4_samples_double(num_ticks, 0.0); - std::vector rtb4_samples_double(num_ticks, 0.0); for (int i = 0; i < num_ticks; i++) { - ltb4_samples_double[i] = (static_cast((*ltf2_samples)[i]) - - static_cast((*ltf4_samples)[i])) / - down_mixing_params.gamma; - rtb4_samples_double[i] = (static_cast((*rtf2_samples)[i]) - - static_cast((*rtf4_samples)[i])) / - down_mixing_params.gamma; - } - - // Convert back to int32_t. - for (int i = 0; i < num_ticks; i++) { - RETURN_IF_NOT_OK( - ClipDoubleToInt32(ltb4_samples_double[i], ltb4_samples[i])); - RETURN_IF_NOT_OK( - ClipDoubleToInt32(rtb4_samples_double[i], rtb4_samples[i])); + ltb4_samples[i] = + ((*ltf2_samples)[i] - (*ltf4_samples)[i]) / down_mixing_params.gamma; + rtb4_samples[i] = + ((*rtf2_samples)[i] - (*rtf4_samples)[i]) / down_mixing_params.gamma; } return absl::OkStatus(); @@ -510,25 +385,13 @@ absl::Status T2ToTf2DownMixer(const DownMixingParams& down_mixing_params, auto& rtf3_samples = label_to_samples[kRtf3]; ltf3_samples.resize(ltf2_samples.size()); rtf3_samples.resize(rtf2_samples.size()); - - // Computation in double. - std::vector ltf3_samples_double(ltf3_samples.size(), 0.0); - std::vector rtf3_samples_double(rtf3_samples.size(), 0.0); for (int i = 0; i < ltf2_samples.size(); i++) { - ltf3_samples_double[i] = static_cast(ltf2_samples[i]) + - down_mixing_params.w * down_mixing_params.delta * - static_cast(ls5_samples[i]); - rtf3_samples_double[i] = static_cast(rtf2_samples[i]) + - down_mixing_params.w * down_mixing_params.delta * - static_cast(rs5_samples[i]); - } - - // Convert back to int32_t. - for (int i = 0; i < ltf3_samples.size(); i++) { - RETURN_IF_NOT_OK( - ClipDoubleToInt32(ltf3_samples_double[i], ltf3_samples[i])); - RETURN_IF_NOT_OK( - ClipDoubleToInt32(rtf3_samples_double[i], rtf3_samples[i])); + ltf3_samples[i] = ltf2_samples[i] + down_mixing_params.w * + down_mixing_params.delta * + ls5_samples[i]; + rtf3_samples[i] = rtf2_samples[i] + down_mixing_params.w * + down_mixing_params.delta * + rs5_samples[i]; } return absl::OkStatus(); @@ -538,12 +401,12 @@ absl::Status Tf2ToT2Demixer(const DownMixingParams& down_mixing_params, LabelSamplesMap& label_to_samples) { LOG_FIRST_N(INFO, 1) << "TF2 to T2"; - const std::vector* ltf3_samples; - const std::vector* l3_samples; - const std::vector* l5_samples; - const std::vector* rtf3_samples; - const std::vector* r3_samples; - const std::vector* r5_samples; + const std::vector* ltf3_samples; + const std::vector* l3_samples; + const std::vector* l5_samples; + const std::vector* rtf3_samples; + const std::vector* r3_samples; + const std::vector* r5_samples; RETURN_IF_NOT_OK(DemixingModule::FindSamplesOrDemixedSamples( kLtf3, label_to_samples, <f3_samples)); RETURN_IF_NOT_OK(DemixingModule::FindSamplesOrDemixedSamples( @@ -562,27 +425,13 @@ absl::Status Tf2ToT2Demixer(const DownMixingParams& down_mixing_params, const size_t num_ticks = ltf3_samples->size(); ltf2_samples.resize(num_ticks, 0.0); rtf2_samples.resize(num_ticks, 0.0); - - // Computation in double. - std::vector ltf2_samples_double(num_ticks, 0.0); - std::vector rtf2_samples_double(num_ticks, 0.0); for (int i = 0; i < num_ticks; i++) { - ltf2_samples_double[i] = - static_cast((*ltf3_samples)[i]) - - down_mixing_params.w * (static_cast((*l3_samples)[i]) - - static_cast((*l5_samples)[i])); - rtf2_samples_double[i] = - static_cast((*rtf3_samples)[i]) - - down_mixing_params.w * (static_cast((*r3_samples)[i]) - - static_cast((*r5_samples)[i])); - } - - // Convert back to int32_t. - for (int i = 0; i < num_ticks; i++) { - RETURN_IF_NOT_OK( - ClipDoubleToInt32(ltf2_samples_double[i], ltf2_samples[i])); - RETURN_IF_NOT_OK( - ClipDoubleToInt32(rtf2_samples_double[i], rtf2_samples[i])); + ltf2_samples[i] = + (*ltf3_samples)[i] - + down_mixing_params.w * ((*l3_samples)[i] - (*l5_samples)[i]); + rtf2_samples[i] = + (*rtf3_samples)[i] - + down_mixing_params.w * ((*r3_samples)[i] - (*r5_samples)[i]); } return absl::OkStatus(); @@ -835,7 +684,8 @@ absl::Status StoreSamplesForAudioElementId( auto& samples = labeled_frame.label_to_samples[label]; samples.resize(num_ticks, 0); for (int t = 0; t < samples.size(); t++) { - samples[t] = input_samples[t][channel_index]; + samples[t] = + static_cast(input_samples[t][channel_index]); } channel_index++; } @@ -922,7 +772,7 @@ void LogForAudioElementId( absl::Status DemixingModule::FindSamplesOrDemixedSamples( ChannelLabel::Label label, const LabelSamplesMap& label_to_samples, - const std::vector** samples) { + const std::vector** samples) { if (label_to_samples.find(label) != label_to_samples.end()) { *samples = &label_to_samples.at(label); return absl::OkStatus(); @@ -1023,7 +873,8 @@ absl::Status DemixingModule::DownMixSamplesToSubstreams( "Samples do not exist for channel: ", output_channel_label)); } for (int t = 0; t < num_time_ticks; t++) { - substream_samples[t][channel_index] = iter->second[t]; + RETURN_IF_NOT_OK(ClipDoubleToInt32( + iter->second[t], substream_samples[t][channel_index])); } // Compute and store the linear output gains. diff --git a/iamf/cli/demixing_module.h b/iamf/cli/demixing_module.h index 154b0e83..6983fa62 100644 --- a/iamf/cli/demixing_module.h +++ b/iamf/cli/demixing_module.h @@ -30,8 +30,8 @@ #include "iamf/cli/proto/user_metadata.pb.h" #include "iamf/obu/audio_element.h" #include "iamf/obu/demixing_info_param_data.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/parameter_block.h" +#include "iamf/obu/types.h" namespace iamf_tools { @@ -52,7 +52,8 @@ struct SubstreamData { }; // Mapping from channel label to a frame of samples. -typedef absl::node_hash_map> +typedef absl::node_hash_map> LabelSamplesMap; struct LabeledFrame { @@ -147,7 +148,7 @@ class DemixingModule { */ static absl::Status FindSamplesOrDemixedSamples( ChannelLabel::Label label, const LabelSamplesMap& label_to_samples, - const std::vector** samples); + const std::vector** samples); /*!\brief Down-mixes samples of input channels to substreams. * diff --git a/iamf/cli/encoder_main_lib.cc b/iamf/cli/encoder_main_lib.cc index 995bda62..d10fb108 100644 --- a/iamf/cli/encoder_main_lib.cc +++ b/iamf/cli/encoder_main_lib.cc @@ -42,8 +42,8 @@ #include "iamf/obu/arbitrary_obu.h" #include "iamf/obu/codec_config.h" #include "iamf/obu/ia_sequence_header.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/mix_presentation.h" +#include "iamf/obu/types.h" #include "src/google/protobuf/repeated_ptr_field.h" namespace iamf_tools { diff --git a/iamf/cli/global_timing_module.cc b/iamf/cli/global_timing_module.cc index d59612ef..f16f7176 100644 --- a/iamf/cli/global_timing_module.cc +++ b/iamf/cli/global_timing_module.cc @@ -26,8 +26,8 @@ #include "iamf/common/obu_util.h" #include "iamf/obu/audio_element.h" #include "iamf/obu/codec_config.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/param_definitions.h" +#include "iamf/obu/types.h" namespace iamf_tools { diff --git a/iamf/cli/global_timing_module.h b/iamf/cli/global_timing_module.h index 3e837d11..9da6f952 100644 --- a/iamf/cli/global_timing_module.h +++ b/iamf/cli/global_timing_module.h @@ -20,8 +20,8 @@ #include "absl/status/status.h" #include "iamf/cli/audio_element_with_data.h" #include "iamf/cli/proto/user_metadata.pb.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/param_definitions.h" +#include "iamf/obu/types.h" namespace iamf_tools { diff --git a/iamf/cli/iamf_encoder.cc b/iamf/cli/iamf_encoder.cc index 719fb86d..fd0651e1 100644 --- a/iamf/cli/iamf_encoder.cc +++ b/iamf/cli/iamf_encoder.cc @@ -41,8 +41,8 @@ #include "iamf/common/macros.h" #include "iamf/obu/codec_config.h" #include "iamf/obu/ia_sequence_header.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/mix_presentation.h" +#include "iamf/obu/types.h" namespace iamf_tools { @@ -171,7 +171,7 @@ absl::Status IamfEncoder::GetInputTimestamp(int32_t& input_timestamp) { void IamfEncoder::AddSamples(const DecodedUleb128 audio_element_id, ChannelLabel::Label label, - const std::vector& samples) { + const std::vector& samples) { id_to_labeled_samples_[audio_element_id][label] = samples; } diff --git a/iamf/cli/iamf_encoder.h b/iamf/cli/iamf_encoder.h index 96536a1e..9017af5e 100644 --- a/iamf/cli/iamf_encoder.h +++ b/iamf/cli/iamf_encoder.h @@ -35,10 +35,10 @@ #include "iamf/cli/proto_to_obu/parameter_block_generator.h" #include "iamf/obu/codec_config.h" #include "iamf/obu/ia_sequence_header.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/mix_presentation.h" #include "iamf/obu/param_definitions.h" #include "iamf/obu/parameter_block.h" +#include "iamf/obu/types.h" namespace iamf_tools { @@ -113,7 +113,7 @@ class IamfEncoder { * \param samples Audio samples to add. */ void AddSamples(DecodedUleb128 audio_element_id, ChannelLabel::Label label, - const std::vector& samples); + const std::vector& samples); /*!\brief Finalizes the process of adding samples. * diff --git a/iamf/cli/leb_generator.cc b/iamf/cli/leb_generator.cc index 7eded738..f08cc5a4 100644 --- a/iamf/cli/leb_generator.cc +++ b/iamf/cli/leb_generator.cc @@ -24,7 +24,7 @@ #include "absl/strings/str_cat.h" #include "iamf/cli/proto/test_vector_metadata.pb.h" #include "iamf/cli/proto/user_metadata.pb.h" -#include "iamf/obu/leb128.h" +#include "iamf/obu/types.h" namespace iamf_tools { diff --git a/iamf/cli/leb_generator.h b/iamf/cli/leb_generator.h index 983f5b82..8985768c 100644 --- a/iamf/cli/leb_generator.h +++ b/iamf/cli/leb_generator.h @@ -19,7 +19,7 @@ #include "absl/status/status.h" #include "iamf/cli/proto/user_metadata.pb.h" -#include "iamf/obu/leb128.h" +#include "iamf/obu/types.h" namespace iamf_tools { diff --git a/iamf/cli/mix_presentation_finalizer.h b/iamf/cli/mix_presentation_finalizer.h index 68b64b43..9ce542c5 100644 --- a/iamf/cli/mix_presentation_finalizer.h +++ b/iamf/cli/mix_presentation_finalizer.h @@ -26,8 +26,8 @@ #include "iamf/cli/parameter_block_with_data.h" #include "iamf/cli/proto/mix_presentation.pb.h" #include "iamf/cli/wav_writer.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/mix_presentation.h" +#include "iamf/obu/types.h" namespace iamf_tools { diff --git a/iamf/cli/obu_to_proto/BUILD b/iamf/cli/obu_to_proto/BUILD index 5dad9ba5..1e7b7aa3 100644 --- a/iamf/cli/obu_to_proto/BUILD +++ b/iamf/cli/obu_to_proto/BUILD @@ -12,8 +12,8 @@ cc_library( "//iamf/common:macros", "//iamf/common:obu_util", "//iamf/obu:demixing_info_param_data", - "//iamf/obu:leb128", "//iamf/obu:parameter_block", + "//iamf/obu:types", "@com_google_absl//absl/base:no_destructor", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/log", diff --git a/iamf/cli/obu_to_proto/parameter_block_metadata_generator.cc b/iamf/cli/obu_to_proto/parameter_block_metadata_generator.cc index 298ed0c2..2b49adfc 100644 --- a/iamf/cli/obu_to_proto/parameter_block_metadata_generator.cc +++ b/iamf/cli/obu_to_proto/parameter_block_metadata_generator.cc @@ -26,8 +26,8 @@ #include "iamf/common/macros.h" #include "iamf/common/obu_util.h" #include "iamf/obu/demixing_info_param_data.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/parameter_block.h" +#include "iamf/obu/types.h" namespace iamf_tools { diff --git a/iamf/cli/obu_to_proto/tests/BUILD b/iamf/cli/obu_to_proto/tests/BUILD index 981bd23f..a6fd2476 100644 --- a/iamf/cli/obu_to_proto/tests/BUILD +++ b/iamf/cli/obu_to_proto/tests/BUILD @@ -7,8 +7,8 @@ cc_test( "//iamf/cli/proto:parameter_data_cc_proto", "//iamf/cli/proto:user_metadata_cc_proto", "//iamf/obu:demixing_info_param_data", - "//iamf/obu:leb128", "//iamf/obu:parameter_block", + "//iamf/obu:types", "@com_google_absl//absl/status:status_matchers", "@com_google_absl//absl/strings:string_view", "@com_google_googletest//:gtest_main", diff --git a/iamf/cli/obu_to_proto/tests/parameter_block_metadata_generator_test.cc b/iamf/cli/obu_to_proto/tests/parameter_block_metadata_generator_test.cc index 596847ad..81f70437 100644 --- a/iamf/cli/obu_to_proto/tests/parameter_block_metadata_generator_test.cc +++ b/iamf/cli/obu_to_proto/tests/parameter_block_metadata_generator_test.cc @@ -23,8 +23,8 @@ #include "iamf/cli/proto/parameter_data.pb.h" #include "iamf/cli/proto/user_metadata.pb.h" #include "iamf/obu/demixing_info_param_data.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/parameter_block.h" +#include "iamf/obu/types.h" namespace iamf_tools { namespace { diff --git a/iamf/cli/parameters_manager.cc b/iamf/cli/parameters_manager.cc index 96703358..c03aa49b 100644 --- a/iamf/cli/parameters_manager.cc +++ b/iamf/cli/parameters_manager.cc @@ -24,9 +24,9 @@ #include "iamf/cli/parameter_block_with_data.h" #include "iamf/common/macros.h" #include "iamf/obu/demixing_info_param_data.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/param_definitions.h" #include "iamf/obu/parameter_block.h" +#include "iamf/obu/types.h" namespace iamf_tools { diff --git a/iamf/cli/parameters_manager.h b/iamf/cli/parameters_manager.h index cb7af981..a4539e11 100644 --- a/iamf/cli/parameters_manager.h +++ b/iamf/cli/parameters_manager.h @@ -20,9 +20,9 @@ #include "iamf/cli/audio_element_with_data.h" #include "iamf/cli/parameter_block_with_data.h" #include "iamf/obu/demixing_info_param_data.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/param_definitions.h" #include "iamf/obu/parameter_block.h" +#include "iamf/obu/types.h" namespace iamf_tools { diff --git a/iamf/cli/proto_to_obu/BUILD b/iamf/cli/proto_to_obu/BUILD index f15bc856..8ac4dce5 100644 --- a/iamf/cli/proto_to_obu/BUILD +++ b/iamf/cli/proto_to_obu/BUILD @@ -36,9 +36,9 @@ cc_library( "//iamf/common:obu_util", "//iamf/obu:audio_element", "//iamf/obu:codec_config", - "//iamf/obu:leb128", "//iamf/obu:param_definitions", "//iamf/obu:parameter_block", + "//iamf/obu:types", "@com_google_absl//absl/base:no_destructor", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:flat_hash_set", @@ -73,7 +73,7 @@ cc_library( "//iamf/obu:audio_frame", "//iamf/obu:codec_config", "//iamf/obu:demixing_info_param_data", - "//iamf/obu:leb128", + "//iamf/obu:types", "@com_google_absl//absl/base:core_headers", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:flat_hash_set", @@ -138,9 +138,9 @@ cc_library( "//iamf/cli/proto:user_metadata_cc_proto", "//iamf/common:macros", "//iamf/common:obu_util", - "//iamf/obu:leb128", "//iamf/obu:mix_presentation", "//iamf/obu:param_definitions", + "//iamf/obu:types", "@com_google_absl//absl/base:no_destructor", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/log", @@ -168,9 +168,9 @@ cc_library( "//iamf/common:obu_util", "//iamf/obu:audio_element", "//iamf/obu:demixing_info_param_data", - "//iamf/obu:leb128", "//iamf/obu:param_definitions", "//iamf/obu:parameter_block", + "//iamf/obu:types", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:flat_hash_set", "@com_google_absl//absl/log", diff --git a/iamf/cli/proto_to_obu/audio_element_generator.cc b/iamf/cli/proto_to_obu/audio_element_generator.cc index f838baa5..ac014bd9 100644 --- a/iamf/cli/proto_to_obu/audio_element_generator.cc +++ b/iamf/cli/proto_to_obu/audio_element_generator.cc @@ -35,9 +35,9 @@ #include "iamf/common/obu_util.h" #include "iamf/obu/audio_element.h" #include "iamf/obu/codec_config.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/param_definitions.h" #include "iamf/obu/parameter_block.h" +#include "iamf/obu/types.h" namespace iamf_tools { diff --git a/iamf/cli/proto_to_obu/audio_element_generator.h b/iamf/cli/proto_to_obu/audio_element_generator.h index f38e7997..fbb695ab 100644 --- a/iamf/cli/proto_to_obu/audio_element_generator.h +++ b/iamf/cli/proto_to_obu/audio_element_generator.h @@ -22,8 +22,8 @@ #include "iamf/cli/proto/audio_element.pb.h" #include "iamf/obu/audio_element.h" #include "iamf/obu/codec_config.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/parameter_block.h" +#include "iamf/obu/types.h" #include "src/google/protobuf/repeated_ptr_field.h" namespace iamf_tools { diff --git a/iamf/cli/proto_to_obu/audio_frame_generator.cc b/iamf/cli/proto_to_obu/audio_frame_generator.cc index 637393ba..8b42329b 100644 --- a/iamf/cli/proto_to_obu/audio_frame_generator.cc +++ b/iamf/cli/proto_to_obu/audio_frame_generator.cc @@ -50,7 +50,7 @@ #include "iamf/obu/audio_frame.h" #include "iamf/obu/codec_config.h" #include "iamf/obu/demixing_info_param_data.h" -#include "iamf/obu/leb128.h" +#include "iamf/obu/types.h" namespace iamf_tools { @@ -689,7 +689,7 @@ bool AudioFrameGenerator::TakingSamples() const { absl::Status AudioFrameGenerator::AddSamples( const DecodedUleb128 audio_element_id, ChannelLabel::Label label, - const std::vector& samples) { + const std::vector& samples) { const auto& audio_element_labels = audio_element_id_to_labels_.find(audio_element_id); if (audio_element_labels == audio_element_id_to_labels_.end()) { diff --git a/iamf/cli/proto_to_obu/audio_frame_generator.h b/iamf/cli/proto_to_obu/audio_frame_generator.h index 6af3969f..f06c5c7b 100644 --- a/iamf/cli/proto_to_obu/audio_frame_generator.h +++ b/iamf/cli/proto_to_obu/audio_frame_generator.h @@ -34,7 +34,7 @@ #include "iamf/cli/proto/audio_frame.pb.h" #include "iamf/cli/proto/codec_config.pb.h" #include "iamf/obu/codec_config.h" -#include "iamf/obu/leb128.h" +#include "iamf/obu/types.h" #include "src/google/protobuf/repeated_ptr_field.h" namespace iamf_tools { @@ -138,7 +138,7 @@ class AudioFrameGenerator { */ absl::Status AddSamples(DecodedUleb128 audio_element_id, ChannelLabel::Label label, - const std::vector& samples); + const std::vector& samples); /*!\brief Finalizes the sample-adding process. * diff --git a/iamf/cli/proto_to_obu/mix_presentation_generator.cc b/iamf/cli/proto_to_obu/mix_presentation_generator.cc index 235c8c1f..85887f9e 100644 --- a/iamf/cli/proto_to_obu/mix_presentation_generator.cc +++ b/iamf/cli/proto_to_obu/mix_presentation_generator.cc @@ -29,9 +29,9 @@ #include "iamf/cli/proto/parameter_data.pb.h" #include "iamf/common/macros.h" #include "iamf/common/obu_util.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/mix_presentation.h" #include "iamf/obu/param_definitions.h" +#include "iamf/obu/types.h" namespace iamf_tools { diff --git a/iamf/cli/proto_to_obu/parameter_block_generator.cc b/iamf/cli/proto_to_obu/parameter_block_generator.cc index f8046109..2020122f 100644 --- a/iamf/cli/proto_to_obu/parameter_block_generator.cc +++ b/iamf/cli/proto_to_obu/parameter_block_generator.cc @@ -39,9 +39,9 @@ #include "iamf/common/obu_util.h" #include "iamf/obu/audio_element.h" #include "iamf/obu/demixing_info_param_data.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/param_definitions.h" #include "iamf/obu/parameter_block.h" +#include "iamf/obu/types.h" namespace iamf_tools { diff --git a/iamf/cli/proto_to_obu/parameter_block_generator.h b/iamf/cli/proto_to_obu/parameter_block_generator.h index 638f66b8..b9207f76 100644 --- a/iamf/cli/proto_to_obu/parameter_block_generator.h +++ b/iamf/cli/proto_to_obu/parameter_block_generator.h @@ -22,9 +22,9 @@ #include "iamf/cli/global_timing_module.h" #include "iamf/cli/parameter_block_with_data.h" #include "iamf/cli/proto/parameter_block.pb.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/param_definitions.h" #include "iamf/obu/parameter_block.h" +#include "iamf/obu/types.h" namespace iamf_tools { diff --git a/iamf/cli/proto_to_obu/tests/BUILD b/iamf/cli/proto_to_obu/tests/BUILD index 6d4c4256..9006781c 100644 --- a/iamf/cli/proto_to_obu/tests/BUILD +++ b/iamf/cli/proto_to_obu/tests/BUILD @@ -27,9 +27,9 @@ cc_test( "//iamf/obu:audio_element", "//iamf/obu:codec_config", "//iamf/obu:demixing_info_param_data", - "//iamf/obu:leb128", "//iamf/obu:param_definitions", "//iamf/obu:parameter_block", + "//iamf/obu:types", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/status:status_matchers", "@com_google_googletest//:gtest_main", @@ -57,9 +57,9 @@ cc_test( "//iamf/cli/tests:cli_test_utils", "//iamf/obu:audio_frame", "//iamf/obu:codec_config", - "//iamf/obu:leb128", "//iamf/obu:obu_header", "//iamf/obu:param_definitions", + "//iamf/obu:types", "//iamf/obu/decoder_config:opus_decoder_config", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/status", @@ -78,8 +78,8 @@ cc_test( "//iamf/cli/proto:test_vector_metadata_cc_proto", "//iamf/cli/proto_to_obu:codec_config_generator", "//iamf/obu:codec_config", - "//iamf/obu:leb128", "//iamf/obu:obu_header", + "//iamf/obu:types", "//iamf/obu/decoder_config:aac_decoder_config", "//iamf/obu/decoder_config:flac_decoder_config", "//iamf/obu/decoder_config:lpcm_decoder_config", @@ -117,8 +117,8 @@ cc_test( "//iamf/cli/proto:param_definitions_cc_proto", "//iamf/cli/proto_to_obu:mix_presentation_generator", "//iamf/cli/tests:cli_test_utils", - "//iamf/obu:leb128", "//iamf/obu:mix_presentation", + "//iamf/obu:types", "@com_google_absl//absl/status:status_matchers", "@com_google_absl//absl/strings:string_view", "@com_google_googletest//:gtest_main", @@ -143,9 +143,9 @@ cc_test( "//iamf/obu:audio_element", "//iamf/obu:codec_config", "//iamf/obu:demixing_info_param_data", - "//iamf/obu:leb128", "//iamf/obu:param_definitions", "//iamf/obu:parameter_block", + "//iamf/obu:types", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/status:status_matchers", "@com_google_googletest//:gtest_main", diff --git a/iamf/cli/proto_to_obu/tests/audio_element_generator_test.cc b/iamf/cli/proto_to_obu/tests/audio_element_generator_test.cc index e74ba48d..8c01be69 100644 --- a/iamf/cli/proto_to_obu/tests/audio_element_generator_test.cc +++ b/iamf/cli/proto_to_obu/tests/audio_element_generator_test.cc @@ -29,9 +29,9 @@ #include "iamf/obu/audio_element.h" #include "iamf/obu/codec_config.h" #include "iamf/obu/demixing_info_param_data.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/param_definitions.h" #include "iamf/obu/parameter_block.h" +#include "iamf/obu/types.h" #include "src/google/protobuf/repeated_ptr_field.h" #include "src/google/protobuf/text_format.h" diff --git a/iamf/cli/proto_to_obu/tests/audio_frame_generator_test.cc b/iamf/cli/proto_to_obu/tests/audio_frame_generator_test.cc index 867a624f..3dd457f9 100644 --- a/iamf/cli/proto_to_obu/tests/audio_frame_generator_test.cc +++ b/iamf/cli/proto_to_obu/tests/audio_frame_generator_test.cc @@ -38,9 +38,9 @@ #include "iamf/obu/audio_frame.h" #include "iamf/obu/codec_config.h" #include "iamf/obu/decoder_config/opus_decoder_config.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/obu_header.h" #include "iamf/obu/param_definitions.h" +#include "iamf/obu/types.h" #include "src/google/protobuf/text_format.h" namespace iamf_tools { @@ -292,12 +292,12 @@ void GenerateAudioFrameWithEightSamples( // Add only one frame. int frame_count = 0; - const std::vector frame_0_l2 = {1 << 16, 2 << 16, 3 << 16, 4 << 16, - 5 << 16, 6 << 16, 7 << 16, 8 << 16}; - const std::vector frame_0_r2 = { + const std::vector frame_0_l2 = { + 1 << 16, 2 << 16, 3 << 16, 4 << 16, 5 << 16, 6 << 16, 7 << 16, 8 << 16}; + const std::vector frame_0_r2 = { 65535 << 16, 65534 << 16, 65533 << 16, 65532 << 16, 65531 << 16, 65530 << 16, 65529 << 16, 65528 << 16}; - const std::vector empty_frame; + const std::vector empty_frame; // TODO(b/329375123): Test adding samples and outputing frames in different // threads. diff --git a/iamf/cli/proto_to_obu/tests/codec_config_generator_test.cc b/iamf/cli/proto_to_obu/tests/codec_config_generator_test.cc index 89338ab9..a6a18ec7 100644 --- a/iamf/cli/proto_to_obu/tests/codec_config_generator_test.cc +++ b/iamf/cli/proto_to_obu/tests/codec_config_generator_test.cc @@ -30,8 +30,8 @@ #include "iamf/obu/decoder_config/flac_decoder_config.h" #include "iamf/obu/decoder_config/lpcm_decoder_config.h" #include "iamf/obu/decoder_config/opus_decoder_config.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/obu_header.h" +#include "iamf/obu/types.h" #include "src/google/protobuf/repeated_ptr_field.h" #include "src/google/protobuf/text_format.h" diff --git a/iamf/cli/proto_to_obu/tests/mix_presentation_generator_test.cc b/iamf/cli/proto_to_obu/tests/mix_presentation_generator_test.cc index 100288af..bd3aca53 100644 --- a/iamf/cli/proto_to_obu/tests/mix_presentation_generator_test.cc +++ b/iamf/cli/proto_to_obu/tests/mix_presentation_generator_test.cc @@ -25,8 +25,8 @@ #include "iamf/cli/proto/mix_presentation.pb.h" #include "iamf/cli/proto/param_definitions.pb.h" #include "iamf/cli/tests/cli_test_utils.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/mix_presentation.h" +#include "iamf/obu/types.h" #include "src/google/protobuf/repeated_ptr_field.h" #include "src/google/protobuf/text_format.h" 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 53f2978d..01385187 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 @@ -33,9 +33,9 @@ #include "iamf/obu/audio_element.h" #include "iamf/obu/codec_config.h" #include "iamf/obu/demixing_info_param_data.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/param_definitions.h" #include "iamf/obu/parameter_block.h" +#include "iamf/obu/types.h" #include "src/google/protobuf/text_format.h" namespace iamf_tools { @@ -438,7 +438,7 @@ void PrepareAudioElementWithDataForReconGain( IdLabeledFrameMap PrepareIdLabeledFrameMap() { using enum ChannelLabel::Label; - const std::vector samples(8, 10000); + const std::vector samples(8, 10000); LabelSamplesMap label_to_samples; for (const auto& label : {kL2, kR2, kDemixedL3, kDemixedR3, kDemixedLs5, kDemixedRs5}) { diff --git a/iamf/cli/recon_gain_generator.cc b/iamf/cli/recon_gain_generator.cc index 6bdb6694..fdd69e80 100644 --- a/iamf/cli/recon_gain_generator.cc +++ b/iamf/cli/recon_gain_generator.cc @@ -12,7 +12,6 @@ #include "iamf/cli/recon_gain_generator.h" #include -#include #include #include "absl/base/no_destructor.h" @@ -24,17 +23,18 @@ #include "iamf/cli/demixing_module.h" #include "iamf/common/macros.h" #include "iamf/common/obu_util.h" +#include "iamf/obu/types.h" namespace iamf_tools { namespace { // Returns the Root Mean Square (RMS) power of input `samples`. -double ComputeSignalPower(const std::vector& samples) { +double ComputeSignalPower(const std::vector& samples) { double mean_square = 0.0; const double scale = 1.0 / static_cast(samples.size()); - for (const int32_t s : samples) { - mean_square += scale * static_cast(s) * static_cast(s); + for (const auto s : samples) { + mean_square += scale * s * s; } return std::sqrt(mean_square); } @@ -46,7 +46,7 @@ double ComputeSignalPower(const std::vector& samples) { absl::Status FindRelevantMixedSamples( const bool additional_logging, ChannelLabel::Label label, const LabelSamplesMap& label_to_samples, - const std::vector** relevant_mixed_samples) { + const std::vector** relevant_mixed_samples) { using enum ChannelLabel::Label; static const absl::NoDestructor< absl::flat_hash_map> @@ -86,7 +86,7 @@ absl::Status ReconGainGenerator::ComputeReconGain( const LabelSamplesMap& label_to_decoded_samples, const bool additional_logging, double& recon_gain) { // Gather information about the original samples. - const std::vector* original_samples; + const std::vector* original_samples; RETURN_IF_NOT_OK(DemixingModule::FindSamplesOrDemixedSamples( label, label_to_samples, &original_samples)); LOG_IF(INFO, additional_logging) @@ -110,7 +110,7 @@ absl::Status ReconGainGenerator::ComputeReconGain( } // Gather information about mixed samples. - const std::vector* relevant_mixed_samples; + const std::vector* relevant_mixed_samples; RETURN_IF_NOT_OK(FindRelevantMixedSamples( additional_logging, label, label_to_samples, &relevant_mixed_samples)); LOG_IF(INFO, additional_logging) @@ -139,7 +139,7 @@ absl::Status ReconGainGenerator::ComputeReconGain( } // Gather information about the demixed samples. - const std::vector* demixed_samples; + const std::vector* demixed_samples; RETURN_IF_NOT_OK(DemixingModule::FindSamplesOrDemixedSamples( label, label_to_decoded_samples, &demixed_samples)); LOG_IF(INFO, additional_logging) diff --git a/iamf/cli/renderer/BUILD b/iamf/cli/renderer/BUILD index b4071503..550930ff 100644 --- a/iamf/cli/renderer/BUILD +++ b/iamf/cli/renderer/BUILD @@ -6,6 +6,7 @@ cc_library( hdrs = ["audio_element_renderer_base.h"], deps = [ "//iamf/cli:demixing_module", + "//iamf/obu:types", "@com_google_absl//absl/base:core_headers", "@com_google_absl//absl/log:check", "@com_google_absl//absl/status", @@ -29,6 +30,7 @@ cc_library( "//iamf/common:obu_util", "//iamf/obu:audio_element", "//iamf/obu:mix_presentation", + "//iamf/obu:types", "@com_google_absl//absl/base:no_destructor", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/log", @@ -59,6 +61,7 @@ cc_library( "//iamf/cli:demixing_module", "//iamf/common:macros", "//iamf/obu:mix_presentation", + "//iamf/obu:types", "@com_google_absl//absl/base:no_destructor", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/log:check", diff --git a/iamf/cli/renderer/audio_element_renderer_base.cc b/iamf/cli/renderer/audio_element_renderer_base.cc index 37502716..9e162927 100644 --- a/iamf/cli/renderer/audio_element_renderer_base.cc +++ b/iamf/cli/renderer/audio_element_renderer_base.cc @@ -11,19 +11,19 @@ */ #include "iamf/cli/renderer/audio_element_renderer_base.h" -#include #include #include "absl/log/check.h" #include "absl/status/status.h" #include "absl/synchronization/mutex.h" +#include "iamf/obu/types.h" namespace iamf_tools { AudioElementRendererBase::~AudioElementRendererBase() {} absl::Status AudioElementRendererBase::Flush( - std::vector& rendered_samples) { + std::vector& rendered_samples) { absl::MutexLock lock(&mutex_); rendered_samples.insert(rendered_samples.end(), rendered_samples_.begin(), rendered_samples_.end()); diff --git a/iamf/cli/renderer/audio_element_renderer_base.h b/iamf/cli/renderer/audio_element_renderer_base.h index c75ea749..cf0969bf 100644 --- a/iamf/cli/renderer/audio_element_renderer_base.h +++ b/iamf/cli/renderer/audio_element_renderer_base.h @@ -11,7 +11,6 @@ */ #ifndef CLI_RENDERER_AUDIO_ELEMENT_RENDERER_BASE_H_ #define CLI_RENDERER_AUDIO_ELEMENT_RENDERER_BASE_H_ -#include #include #include "absl/base/thread_annotations.h" @@ -19,6 +18,7 @@ #include "absl/status/statusor.h" #include "absl/synchronization/mutex.h" #include "iamf/cli/demixing_module.h" +#include "iamf/obu/types.h" namespace iamf_tools { /*!\brief Abstract class to render a demixed audio element to a playback layout. @@ -57,7 +57,7 @@ class AudioElementRendererBase { * \param rendered_samples Vector to append rendered samples to. * \return `absl::OkStatus()` on success. A specific status on failure. */ - absl::Status Flush(std::vector& rendered_samples); + absl::Status Flush(std::vector& rendered_samples); /*!\brief Finalizes the renderer. Waits for it to finish any remaining frames. * @@ -87,7 +87,7 @@ class AudioElementRendererBase { // Mutex to guard simultaneous access to data members. mutable absl::Mutex mutex_; - std::vector rendered_samples_ ABSL_GUARDED_BY(mutex_); + std::vector rendered_samples_ ABSL_GUARDED_BY(mutex_); bool is_finalized_ ABSL_GUARDED_BY(mutex_) = false; }; diff --git a/iamf/cli/renderer/audio_element_renderer_passthrough.cc b/iamf/cli/renderer/audio_element_renderer_passthrough.cc index 72bad17f..f2955126 100644 --- a/iamf/cli/renderer/audio_element_renderer_passthrough.cc +++ b/iamf/cli/renderer/audio_element_renderer_passthrough.cc @@ -13,7 +13,6 @@ #include "iamf/cli/renderer/audio_element_renderer_passthrough.h" -#include #include #include @@ -34,6 +33,8 @@ #include "iamf/common/obu_util.h" #include "iamf/obu/audio_element.h" #include "iamf/obu/mix_presentation.h" +#include "iamf/obu/types.h" + namespace iamf_tools { namespace { @@ -178,7 +179,7 @@ AudioElementRendererPassThrough::CreateFromScalableChannelLayoutConfig( absl::StatusOr AudioElementRendererPassThrough::RenderLabeledFrame( const LabeledFrame& labeled_frame) { - std::vector> samples_to_render; + std::vector> samples_to_render; RETURN_IF_NOT_OK(iamf_tools::renderer_utils::ArrangeSamplesToRender( labeled_frame, channel_order_, samples_to_render)); diff --git a/iamf/cli/renderer/renderer_utils.cc b/iamf/cli/renderer/renderer_utils.cc index c1fa32f9..32e9333e 100644 --- a/iamf/cli/renderer/renderer_utils.cc +++ b/iamf/cli/renderer/renderer_utils.cc @@ -9,7 +9,6 @@ * source code in the PATENTS file, you can obtain it at * www.aomedia.org/license/patent. */ -#include #include #include @@ -23,6 +22,7 @@ #include "iamf/cli/demixing_module.h" #include "iamf/common/macros.h" #include "iamf/obu/mix_presentation.h" +#include "iamf/obu/types.h" namespace iamf_tools { @@ -43,7 +43,7 @@ absl::StatusOr GetCommonNumTrimmedTimeTicks( continue; } - const std::vector* samples_to_render = nullptr; + const std::vector* samples_to_render = nullptr; RETURN_IF_NOT_OK(DemixingModule::FindSamplesOrDemixedSamples( label, labeled_frame.label_to_samples, &samples_to_render)); @@ -77,7 +77,7 @@ absl::StatusOr GetCommonNumTrimmedTimeTicks( absl::Status ArrangeSamplesToRender( const LabeledFrame& labeled_frame, const std::vector& ordered_labels, - std::vector>& samples_to_render) { + std::vector>& samples_to_render) { samples_to_render.clear(); if (ordered_labels.empty()) { return absl::OkStatus(); @@ -91,7 +91,7 @@ absl::Status ArrangeSamplesToRender( const auto num_channels = ordered_labels.size(); samples_to_render.resize(*num_trimmed_time_ticks, - std::vector(num_channels, 0)); + std::vector(num_channels, 0)); for (int channel = 0; channel < num_channels; ++channel) { const auto& channel_label = ordered_labels[channel]; @@ -101,7 +101,7 @@ absl::Status ArrangeSamplesToRender( continue; } - const std::vector* channel_samples = nullptr; + const std::vector* channel_samples = nullptr; RETURN_IF_NOT_OK(DemixingModule::FindSamplesOrDemixedSamples( channel_label, labeled_frame.label_to_samples, &channel_samples)); // The lookup should not fail because its presence was already checked in diff --git a/iamf/cli/renderer/renderer_utils.h b/iamf/cli/renderer/renderer_utils.h index ec4c394b..6a04c097 100644 --- a/iamf/cli/renderer/renderer_utils.h +++ b/iamf/cli/renderer/renderer_utils.h @@ -11,7 +11,6 @@ */ #ifndef CLI_RENDERER_RENDERER_UTILS_H_ #define CLI_RENDERER_RENDERER_UTILS_H_ -#include #include #include @@ -20,6 +19,7 @@ #include "iamf/cli/channel_label.h" #include "iamf/cli/demixing_module.h" #include "iamf/obu/mix_presentation.h" +#include "iamf/obu/types.h" namespace iamf_tools { @@ -40,7 +40,7 @@ namespace renderer_utils { absl::Status ArrangeSamplesToRender( const LabeledFrame& labeled_frame, const std::vector& ordered_labels, - std::vector>& samples_to_render); + std::vector>& samples_to_render); /*!\brief Gets a key associated with the playback layout. * diff --git a/iamf/cli/renderer/tests/BUILD b/iamf/cli/renderer/tests/BUILD index 12d995d8..4ba0872b 100644 --- a/iamf/cli/renderer/tests/BUILD +++ b/iamf/cli/renderer/tests/BUILD @@ -6,6 +6,7 @@ cc_test( deps = [ "//iamf/cli:demixing_module", "//iamf/cli/renderer:audio_element_renderer_base", + "//iamf/obu:types", "@com_google_absl//absl/status:status_matchers", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/synchronization", @@ -23,6 +24,7 @@ cc_test( "//iamf/cli/tests:cli_test_utils", "//iamf/obu:audio_element", "//iamf/obu:mix_presentation", + "//iamf/obu:types", "@com_google_absl//absl/status:status_matchers", "@com_google_googletest//:gtest_main", ], @@ -36,6 +38,7 @@ cc_test( "//iamf/cli:demixing_module", "//iamf/cli/renderer:renderer_utils", "//iamf/obu:mix_presentation", + "//iamf/obu:types", "@com_google_absl//absl/status:status_matchers", "@com_google_googletest//:gtest_main", ], diff --git a/iamf/cli/renderer/tests/audio_element_renderer_base_test.cc b/iamf/cli/renderer/tests/audio_element_renderer_base_test.cc index ef1631a8..b7e43a0b 100644 --- a/iamf/cli/renderer/tests/audio_element_renderer_base_test.cc +++ b/iamf/cli/renderer/tests/audio_element_renderer_base_test.cc @@ -21,11 +21,14 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" #include "iamf/cli/demixing_module.h" +#include "iamf/obu/types.h" namespace iamf_tools { namespace { using ::absl_testing::IsOk; +using testing::DoubleEq; +using testing::Pointwise; const std::vector kSamplesToRender = {0, 1, 2, 3}; @@ -59,14 +62,14 @@ TEST(AudioElementRendererBase, FinalizeAndFlushWithOutRenderingSucceeds) { MockAudioElementRenderer renderer; EXPECT_THAT(renderer.Finalize(), IsOk()); EXPECT_TRUE(renderer.IsFinalized()); - std::vector rendered_samples; + std::vector rendered_samples; EXPECT_THAT(renderer.Flush(rendered_samples), IsOk()); EXPECT_TRUE(rendered_samples.empty()); } TEST(AudioElementRendererBase, FlushingTwiceDoesNotAppendMore) { MockAudioElementRenderer renderer; - std::vector vector_to_collect_rendered_samples; + std::vector vector_to_collect_rendered_samples; EXPECT_THAT(renderer.RenderLabeledFrame({}), IsOk()); EXPECT_THAT(renderer.Finalize(), IsOk()); @@ -83,9 +86,11 @@ TEST(AudioElementRendererBase, FlushingTwiceDoesNotAppendMore) { TEST(AudioElementRendererBase, AppendsWhenFlushing) { MockAudioElementRenderer renderer; - std::vector vector_to_collect_rendered_samples({100, 200, 300, 400}); + std::vector vector_to_collect_rendered_samples( + {100, 200, 300, 400}); // Flush should append `kSamplesToRender` to the initial vector. - std::vector expected_samples(vector_to_collect_rendered_samples); + std::vector expected_samples( + vector_to_collect_rendered_samples); expected_samples.insert(expected_samples.end(), kSamplesToRender.begin(), kSamplesToRender.end()); @@ -94,11 +99,8 @@ TEST(AudioElementRendererBase, AppendsWhenFlushing) { EXPECT_TRUE(renderer.IsFinalized()); EXPECT_THAT(renderer.Flush(vector_to_collect_rendered_samples), IsOk()); - EXPECT_EQ(vector_to_collect_rendered_samples.size(), expected_samples.size()); - for (int i = 0; i < vector_to_collect_rendered_samples.size(); ++i) { - EXPECT_DOUBLE_EQ(vector_to_collect_rendered_samples[i], - expected_samples[i]); - } + EXPECT_THAT(vector_to_collect_rendered_samples, + Pointwise(DoubleEq(), expected_samples)); } } // namespace diff --git a/iamf/cli/renderer/tests/audio_element_renderer_passthrough_test.cc b/iamf/cli/renderer/tests/audio_element_renderer_passthrough_test.cc index 5a89e366..161c8f1a 100644 --- a/iamf/cli/renderer/tests/audio_element_renderer_passthrough_test.cc +++ b/iamf/cli/renderer/tests/audio_element_renderer_passthrough_test.cc @@ -12,7 +12,6 @@ #include "iamf/cli/renderer/audio_element_renderer_passthrough.h" -#include #include #include #include @@ -27,15 +26,18 @@ #include "iamf/cli/tests/cli_test_utils.h" #include "iamf/obu/audio_element.h" #include "iamf/obu/mix_presentation.h" +#include "iamf/obu/types.h" + namespace iamf_tools { namespace { using ::absl_testing::IsOk; -using enum ChannelLabel::Label; - -using enum LoudspeakersSsConventionLayout::SoundSystem; using enum ChannelAudioLayerConfig::LoudspeakerLayout; using enum ChannelAudioLayerConfig::ExpandedLoudspeakerLayout; +using enum ChannelLabel::Label; +using enum LoudspeakersSsConventionLayout::SoundSystem; +using testing::DoubleEq; +using testing::Pointwise; Layout GetScalableLayoutForSoundSystem( LoudspeakersSsConventionLayout::SoundSystem sound_system) { @@ -205,15 +207,13 @@ TEST(RenderLabeledFrame, RendersPassThroughStereo) { AudioElementRendererPassThrough::CreateFromScalableChannelLayoutConfig( kStereoScalableChannelLayoutConfig, kStereoLayout); - std::vector rendered_samples; + std::vector rendered_samples; RenderAndFlushExpectOk(kLabeledFrameWithL2AndR2, stereo_pass_through_renderer.get(), rendered_samples); - const std::vector expected_samples({1, 2, 3, 4, 5, 6, 7, 8}); - EXPECT_EQ(rendered_samples.size(), expected_samples.size()); - for (int i = 0; i < rendered_samples.size(); ++i) { - EXPECT_DOUBLE_EQ(rendered_samples[i], expected_samples[i]); - } + const std::vector expected_samples( + {1, 2, 3, 4, 5, 6, 7, 8}); + EXPECT_THAT(rendered_samples, Pointwise(DoubleEq(), expected_samples)); } TEST(RenderLabeledFrame, RendersPassThroughBinaural) { @@ -221,16 +221,14 @@ TEST(RenderLabeledFrame, RendersPassThroughBinaural) { AudioElementRendererPassThrough::CreateFromScalableChannelLayoutConfig( kBinauralScalableChannelLayoutConfig, kBinauralLayout); - std::vector rendered_samples; + std::vector rendered_samples; RenderAndFlushExpectOk(kLabeledFrameWithL2AndR2, binaural_pass_through_renderer.get(), rendered_samples); - const std::vector expected_samples({1, 2, 3, 4, 5, 6, 7, 8}); - EXPECT_EQ(rendered_samples.size(), expected_samples.size()); - for (int i = 0; i < rendered_samples.size(); ++i) { - EXPECT_DOUBLE_EQ(rendered_samples[i], expected_samples[i]); - } + const std::vector expected_samples( + {1, 2, 3, 4, 5, 6, 7, 8}); + EXPECT_THAT(rendered_samples, Pointwise(DoubleEq(), expected_samples)); } TEST(RenderLabeledFrame, RendersPassThrough7_1_4) { @@ -252,17 +250,14 @@ TEST(RenderLabeledFrame, RendersPassThrough7_1_4) { AudioElementRendererPassThrough::CreateFromScalableChannelLayoutConfig( k7_1_4ScalableChannelLayoutConfig, k7_1_4Layout); - std::vector rendered_samples; + std::vector rendered_samples; RenderAndFlushExpectOk(k7_1_4LabeledFrame, pass_through_renderer.get(), rendered_samples); - const std::vector expected_samples( + const std::vector expected_samples( {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111}); - EXPECT_EQ(rendered_samples.size(), expected_samples.size()); - for (int i = 0; i < rendered_samples.size(); ++i) { - EXPECT_DOUBLE_EQ(rendered_samples[i], expected_samples[i]); - } + EXPECT_THAT(rendered_samples, Pointwise(DoubleEq(), expected_samples)); } TEST(RenderLabeledFrame, RendersPassThroughLFE) { @@ -274,17 +269,14 @@ TEST(RenderLabeledFrame, RendersPassThroughLFE) { ChannelAudioLayerConfig::kExpandedLayoutLFE), GetScalableLayoutForSoundSystem(kSoundSystemJ_4_7_0)); - std::vector rendered_samples; + std::vector rendered_samples; RenderAndFlushExpectOk(kLFELabeledFrame, pass_through_renderer.get(), rendered_samples); - const std::vector expected_samples({0, 0, 0, 3, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 103, - 0, 0, 0, 0, 0, 0, 0, 0}); - EXPECT_EQ(rendered_samples.size(), expected_samples.size()); - for (int i = 0; i < rendered_samples.size(); ++i) { - EXPECT_DOUBLE_EQ(rendered_samples[i], expected_samples[i]); - } + const std::vector expected_samples( + {0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 103, 0, 0, 0, 0, 0, 0, 0, 0}); + EXPECT_THAT(rendered_samples, Pointwise(DoubleEq(), expected_samples)); } TEST(RenderLabeledFrame, RendersPassThroughStereoS) { @@ -298,16 +290,13 @@ TEST(RenderLabeledFrame, RendersPassThroughStereoS) { ChannelAudioLayerConfig::kExpandedLayoutStereoS), GetScalableLayoutForSoundSystem(kSoundSystemD_4_5_0)); - std::vector rendered_samples; + std::vector rendered_samples; RenderAndFlushExpectOk(kStereoSLabeledFrame, pass_through_renderer.get(), rendered_samples); - const std::vector expected_samples( + const std::vector expected_samples( {0, 0, 0, 0, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0, 104, 105, 0, 0, 0, 0}); - EXPECT_EQ(rendered_samples.size(), expected_samples.size()); - for (int i = 0; i < rendered_samples.size(); ++i) { - EXPECT_DOUBLE_EQ(rendered_samples[i], expected_samples[i]); - } + EXPECT_THAT(rendered_samples, Pointwise(DoubleEq(), expected_samples)); } TEST(RenderLabeledFrame, RendersPassThrough3_0_Ch) { @@ -322,17 +311,14 @@ TEST(RenderLabeledFrame, RendersPassThrough3_0_Ch) { ChannelAudioLayerConfig::kExpandedLayout3_0_ch), GetScalableLayoutForSoundSystem(kSoundSystemJ_4_7_0)); - std::vector rendered_samples; + std::vector rendered_samples; RenderAndFlushExpectOk(k7_1_4LabeledFrame, pass_through_renderer.get(), rendered_samples); - const std::vector expected_samples({0, 1, 2, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 100, 101, 102, 0, - 0, 0, 0, 0, 0, 0, 0, 0}); - EXPECT_EQ(rendered_samples.size(), expected_samples.size()); - for (int i = 0; i < rendered_samples.size(); ++i) { - EXPECT_DOUBLE_EQ(rendered_samples[i], expected_samples[i]); - } + const std::vector expected_samples( + {0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 100, 101, 102, 0, 0, 0, 0, 0, 0, 0, 0, 0}); + EXPECT_THAT(rendered_samples, Pointwise(DoubleEq(), expected_samples)); } TEST(RenderLabeledFrame, RendersPassThrough9_1_6) { @@ -360,18 +346,15 @@ TEST(RenderLabeledFrame, RendersPassThrough9_1_6) { ChannelAudioLayerConfig::kExpandedLayout9_1_6_ch), GetScalableLayoutForSoundSystem(kSoundSystem13_6_9_0)); - std::vector rendered_samples; + std::vector rendered_samples; RenderAndFlushExpectOk(k9_1_6LabeledFrame, pass_through_renderer.get(), rendered_samples); - const std::vector expected_samples( + const std::vector expected_samples( {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115}); - EXPECT_EQ(rendered_samples.size(), expected_samples.size()); - for (int i = 0; i < rendered_samples.size(); ++i) { - EXPECT_DOUBLE_EQ(rendered_samples[i], expected_samples[i]); - } + EXPECT_THAT(rendered_samples, Pointwise(DoubleEq(), expected_samples)); } TEST(RenderLabeledFrame, RendersPassThroughStereoF) { @@ -385,17 +368,14 @@ TEST(RenderLabeledFrame, RendersPassThroughStereoF) { ChannelAudioLayerConfig::kExpandedLayoutStereoF), GetScalableLayoutForSoundSystem(kSoundSystem13_6_9_0)); - std::vector rendered_samples; + std::vector rendered_samples; RenderAndFlushExpectOk(kStreoFLabeledFrame, pass_through_renderer.get(), rendered_samples); - const std::vector expected_samples( + const std::vector expected_samples( {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}); - EXPECT_EQ(rendered_samples.size(), expected_samples.size()); - for (int i = 0; i < rendered_samples.size(); ++i) { - EXPECT_DOUBLE_EQ(rendered_samples[i], expected_samples[i]); - } + EXPECT_THAT(rendered_samples, Pointwise(DoubleEq(), expected_samples)); } TEST(RenderLabeledFrame, RendersPassThroughTop6Ch) { @@ -413,17 +393,14 @@ TEST(RenderLabeledFrame, RendersPassThroughTop6Ch) { ChannelAudioLayerConfig::kExpandedLayoutTop6Ch), GetScalableLayoutForSoundSystem(kSoundSystem13_6_9_0)); - std::vector rendered_samples; + std::vector rendered_samples; RenderAndFlushExpectOk(kTop6ChLabeledFrame, pass_through_renderer.get(), rendered_samples); - const std::vector expected_samples( + const std::vector expected_samples( {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 11, 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 110, 111, 112, 113, 114, 115}); - EXPECT_EQ(rendered_samples.size(), expected_samples.size()); - for (int i = 0; i < rendered_samples.size(); ++i) { - EXPECT_DOUBLE_EQ(rendered_samples[i], expected_samples[i]); - } + EXPECT_THAT(rendered_samples, Pointwise(DoubleEq(), expected_samples)); } TEST(RenderLabeledFrame, RendersDemixedSamples) { @@ -439,13 +416,10 @@ TEST(RenderLabeledFrame, RendersDemixedSamples) { IsOk()); EXPECT_THAT(demixed_stereo_renderer->Finalize(), IsOk()); EXPECT_TRUE(demixed_stereo_renderer->IsFinalized()); - std::vector rendered_samples; + std::vector rendered_samples; EXPECT_THAT(demixed_stereo_renderer->Flush(rendered_samples), IsOk()); - const std::vector expected_samples({1, 2}); - EXPECT_EQ(rendered_samples.size(), expected_samples.size()); - for (int i = 0; i < rendered_samples.size(); ++i) { - EXPECT_DOUBLE_EQ(rendered_samples[i], expected_samples[i]); - } + const std::vector expected_samples({1, 2}); + EXPECT_THAT(rendered_samples, Pointwise(DoubleEq(), expected_samples)); } TEST(RenderLabeledFrame, ReturnsNumberOfTicksToRender) { @@ -482,7 +456,7 @@ void RenderMonoSequence(int num_frames, int samples_per_frame, AudioElementRendererPassThrough& renderer) { int sample = 0; for (int frame_index = 0; frame_index < num_frames; ++frame_index) { - std::vector samples(samples_per_frame); + std::vector samples(samples_per_frame); std::iota(samples.begin(), samples.end(), sample); sample += samples_per_frame; @@ -496,7 +470,7 @@ void RenderMonoSequence(int num_frames, int samples_per_frame, // Collects all of the rendered samples from `renderer` into `rendered_samples`. // This function blocks until the renderer is finalized. void CollectRenderedSamples(AudioElementRendererPassThrough& renderer, - std::vector& rendered_samples) { + std::vector& rendered_samples) { while (!renderer.IsFinalized()) { // In practice threads would be better off sleeping between calls. But // calling it very often is more likely to detect a problem. @@ -517,7 +491,7 @@ TEST(RenderLabeledFrame, IsThreadSafe) { std::thread render_thread(&RenderMonoSequence, kNumFrames, kSamplesPerFrame, std::ref(*mono_pass_through_renderer)); // Spawn a thread to collect all of the rendered samples. - std::vector rendered_samples; + std::vector rendered_samples; std::thread collector_thread(&CollectRenderedSamples, std::ref(*mono_pass_through_renderer), std::ref(rendered_samples)); @@ -526,12 +500,10 @@ TEST(RenderLabeledFrame, IsThreadSafe) { // If the render was not thread safe, then we would expect trouble, such as // missing samples or samples coming back in the wrong order. - std::vector expected_samples(kNumFrames * kSamplesPerFrame); + std::vector expected_samples(kNumFrames * + kSamplesPerFrame); std::iota(expected_samples.begin(), expected_samples.end(), 0); - EXPECT_EQ(rendered_samples.size(), expected_samples.size()); - for (int i = 0; i < rendered_samples.size(); ++i) { - EXPECT_DOUBLE_EQ(rendered_samples[i], expected_samples[i]); - } + EXPECT_THAT(rendered_samples, Pointwise(DoubleEq(), expected_samples)); } } // namespace diff --git a/iamf/cli/renderer/tests/renderer_utils_test.cc b/iamf/cli/renderer/tests/renderer_utils_test.cc index 5af161f3..dfe17cdc 100644 --- a/iamf/cli/renderer/tests/renderer_utils_test.cc +++ b/iamf/cli/renderer/tests/renderer_utils_test.cc @@ -12,7 +12,6 @@ #include "iamf/cli/renderer/renderer_utils.h" -#include #include #include "absl/status/status_matchers.h" @@ -21,17 +20,19 @@ #include "iamf/cli/channel_label.h" #include "iamf/cli/demixing_module.h" #include "iamf/obu/mix_presentation.h" +#include "iamf/obu/types.h" namespace iamf_tools { namespace renderer_utils { namespace { using ::absl_testing::IsOk; - using enum ChannelLabel::Label; +using testing::DoubleEq; +using testing::Pointwise; TEST(ArrangeSamplesToRender, SucceedsOnEmptyFrame) { - std::vector> samples; + std::vector> samples; EXPECT_THAT(ArrangeSamplesToRender({}, {}, samples), IsOk()); EXPECT_TRUE(samples.empty()); } @@ -41,13 +42,14 @@ TEST(ArrangeSamplesToRender, ArrangesSamplesInTimeChannelAxes) { .label_to_samples = {{kL2, {0, 1, 2}}, {kR2, {10, 11, 12}}}}; const std::vector kStereoArrangement = {kL2, kR2}; - std::vector> samples; + std::vector> samples; EXPECT_THAT( ArrangeSamplesToRender(kStereoLabeledFrame, kStereoArrangement, samples), IsOk()); - - EXPECT_EQ(samples, - std::vector>({{0, 10}, {1, 11}, {2, 12}})); + EXPECT_THAT(samples, + testing::ElementsAreArray({Pointwise(DoubleEq(), {0.0, 10.0}), + Pointwise(DoubleEq(), {1.0, 11.0}), + Pointwise(DoubleEq(), {2.0, 12.0})})); } TEST(ArrangeSamplesToRender, FindsDemixedLabels) { @@ -55,12 +57,12 @@ TEST(ArrangeSamplesToRender, FindsDemixedLabels) { .label_to_samples = {{kMono, {75}}, {kL2, {50}}, {kDemixedR2, {100}}}}; const std::vector kStereoArrangement = {kL2, kR2}; - std::vector> samples; + std::vector> samples; EXPECT_THAT(ArrangeSamplesToRender(kDemixedTwoLayerStereoFrame, kStereoArrangement, samples), IsOk()); - - EXPECT_EQ(samples, std::vector>({{50, 100}})); + EXPECT_THAT(samples, testing::ElementsAreArray( + {Pointwise(DoubleEq(), {50.0, 100.0})})); } TEST(ArrangeSamplesToRender, IgnoresExtraLabels) { @@ -68,11 +70,12 @@ TEST(ArrangeSamplesToRender, IgnoresExtraLabels) { .label_to_samples = {{kL2, {0}}, {kR2, {10}}, {kLFE, {999}}}}; const std::vector kStereoArrangement = {kL2, kR2}; - std::vector> samples; + std::vector> samples; EXPECT_THAT(ArrangeSamplesToRender(kStereoLabeledFrameWithExtraLabel, kStereoArrangement, samples), IsOk()); - EXPECT_EQ(samples, std::vector>({{0, 10}})); + EXPECT_THAT(samples, + testing::ElementsAreArray({Pointwise(DoubleEq(), {0.0, 10.0})})); } TEST(ArrangeSamplesToRender, LeavesOmittedLabelsZeroForMixedOrderAmbisonics) { @@ -82,13 +85,14 @@ TEST(ArrangeSamplesToRender, LeavesOmittedLabelsZeroForMixedOrderAmbisonics) { const std::vector kMixedFirstOrderAmbisonicsArrangement = {kA0, kOmitted, kA2, kA3}; - std::vector> samples; + std::vector> samples; EXPECT_THAT( ArrangeSamplesToRender(kMixedFirstOrderAmbisonicsFrame, kMixedFirstOrderAmbisonicsArrangement, samples), IsOk()); - EXPECT_EQ(samples, std::vector>( - {{1, 0, 201, 301}, {2, 0, 202, 302}})); + EXPECT_THAT(samples, testing::ElementsAreArray( + {Pointwise(DoubleEq(), {1.0, 0.0, 201.0, 301.0}), + Pointwise(DoubleEq(), {2.0, 0.0, 202.0, 302.0})})); } TEST(ArrangeSamplesToRender, LeavesOmittedLabelsZeroForChannelBasedLayout) { @@ -96,12 +100,13 @@ TEST(ArrangeSamplesToRender, LeavesOmittedLabelsZeroForChannelBasedLayout) { const std::vector kLFEAsSecondChannelArrangement = { kOmitted, kOmitted, kLFE, kOmitted}; - std::vector> samples; + std::vector> samples; EXPECT_THAT(ArrangeSamplesToRender(kLFEOnlyFrame, kLFEAsSecondChannelArrangement, samples), IsOk()); - EXPECT_EQ(samples, - std::vector>({{0, 0, 1, 0}, {0, 0, 2, 0}})); + EXPECT_THAT(samples, testing::ElementsAreArray( + {Pointwise(DoubleEq(), {0.0, 0.0, 1.0, 0.0}), + Pointwise(DoubleEq(), {0.0, 0.0, 2.0, 0.0})})); } TEST(ArrangeSamplesToRender, ExcludesSamplesToBeTrimmed) { @@ -111,11 +116,12 @@ TEST(ArrangeSamplesToRender, ExcludesSamplesToBeTrimmed) { .label_to_samples = {{kMono, {999, 100, 999, 999}}}}; const std::vector kMonoArrangement = {kMono}; - std::vector> samples; + std::vector> samples; EXPECT_THAT(ArrangeSamplesToRender(kMonoLabeledFrameWithSamplesToTrim, kMonoArrangement, samples), IsOk()); - EXPECT_EQ(samples, std::vector>({{100}})); + EXPECT_THAT(samples, + testing::ElementsAreArray({Pointwise(DoubleEq(), {100.0})})); } TEST(ArrangeSamplesToRender, ClearsInputVector) { @@ -123,11 +129,13 @@ TEST(ArrangeSamplesToRender, ClearsInputVector) { .label_to_samples = {{kMono, {1, 2}}}}; const std::vector kMonoArrangement = {kMono}; - std::vector> samples = {{999, 999}}; + std::vector> samples = {{999, 999}}; EXPECT_THAT( ArrangeSamplesToRender(kMonoLabeledFrame, kMonoArrangement, samples), IsOk()); - EXPECT_EQ(samples, std::vector>({{1}, {2}})); + EXPECT_THAT(samples, + testing::ElementsAreArray({Pointwise(DoubleEq(), {1.0}), + Pointwise(DoubleEq(), {2.0})})); } TEST(ArrangeSamplesToRender, TrimmingAllFramesFromStartIsResultsInEmptyOutput) { @@ -137,7 +145,7 @@ TEST(ArrangeSamplesToRender, TrimmingAllFramesFromStartIsResultsInEmptyOutput) { .label_to_samples = {{kMono, {999, 999, 999, 999}}}}; const std::vector kMonoArrangement = {kMono}; - std::vector> samples; + std::vector> samples; EXPECT_THAT(ArrangeSamplesToRender(kMonoLabeledFrameWithSamplesToTrim, kMonoArrangement, samples), IsOk()); @@ -150,7 +158,7 @@ TEST(ArrangeSamplesToRender, .label_to_samples = {{kL2, {0, 1}}, {kR2, {10}}}}; const std::vector kStereoArrangement = {kL2, kR2}; - std::vector> samples; + std::vector> samples; EXPECT_FALSE(ArrangeSamplesToRender(kStereoLabeledFrameWithMissingSample, kStereoArrangement, samples) .ok()); @@ -163,7 +171,7 @@ TEST(ArrangeSamplesToRender, InvalidWhenTrimIsImplausible) { .label_to_samples = {{kL2, {0, 1}}, {kR2, {10, 11}}}}; const std::vector kStereoArrangement = {kL2, kR2}; - std::vector> samples; + std::vector> samples; EXPECT_FALSE(ArrangeSamplesToRender(kFrameWithExcessSamplesTrimmed, kStereoArrangement, samples) .ok()); @@ -174,7 +182,7 @@ TEST(ArrangeSamplesToRender, InvalidMissingLabel) { .label_to_samples = {{kL2, {0}}, {kR2, {10}}}}; const std::vector kMonoArrangement = {kMono}; - std::vector> unused_samples; + std::vector> unused_samples; EXPECT_FALSE(ArrangeSamplesToRender(kStereoLabeledFrame, kMonoArrangement, unused_samples) .ok()); diff --git a/iamf/cli/renderer_factory.cc b/iamf/cli/renderer_factory.cc index a442176d..6922fa34 100644 --- a/iamf/cli/renderer_factory.cc +++ b/iamf/cli/renderer_factory.cc @@ -17,8 +17,8 @@ #include "iamf/cli/audio_element_with_data.h" #include "iamf/cli/renderer/audio_element_renderer_base.h" #include "iamf/obu/audio_element.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/mix_presentation.h" +#include "iamf/obu/types.h" namespace iamf_tools { diff --git a/iamf/cli/renderer_factory.h b/iamf/cli/renderer_factory.h index f418582e..22a7705e 100644 --- a/iamf/cli/renderer_factory.h +++ b/iamf/cli/renderer_factory.h @@ -18,8 +18,8 @@ #include "iamf/cli/audio_element_with_data.h" #include "iamf/cli/renderer/audio_element_renderer_base.h" #include "iamf/obu/audio_element.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/mix_presentation.h" +#include "iamf/obu/types.h" namespace iamf_tools { diff --git a/iamf/cli/tests/BUILD b/iamf/cli/tests/BUILD index cbf00532..3291e696 100644 --- a/iamf/cli/tests/BUILD +++ b/iamf/cli/tests/BUILD @@ -34,10 +34,10 @@ cc_library( "//iamf/obu:audio_element", "//iamf/obu:codec_config", "//iamf/obu:demixing_info_param_data", - "//iamf/obu:leb128", "//iamf/obu:mix_presentation", "//iamf/obu:obu_header", "//iamf/obu:param_definitions", + "//iamf/obu:types", "//iamf/obu/decoder_config:aac_decoder_config", "//iamf/obu/decoder_config:lpcm_decoder_config", "//iamf/obu/decoder_config:opus_decoder_config", @@ -60,8 +60,8 @@ cc_test( "//iamf/obu:audio_frame", "//iamf/obu:codec_config", "//iamf/obu:demixing_info_param_data", - "//iamf/obu:leb128", "//iamf/obu:obu_header", + "//iamf/obu:types", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/status:status_matchers", "@com_google_googletest//:gtest_main", @@ -87,11 +87,11 @@ cc_test( "//iamf/obu:codec_config", "//iamf/obu:demixing_info_param_data", "//iamf/obu:ia_sequence_header", - "//iamf/obu:leb128", "//iamf/obu:mix_presentation", "//iamf/obu:obu_header", "//iamf/obu:param_definitions", "//iamf/obu:parameter_block", + "//iamf/obu:types", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:flat_hash_set", "@com_google_absl//absl/status", @@ -116,9 +116,9 @@ cc_test( "//iamf/obu:audio_frame", "//iamf/obu:codec_config", "//iamf/obu:demixing_info_param_data", - "//iamf/obu:leb128", "//iamf/obu:obu_header", "//iamf/obu:parameter_block", + "//iamf/obu:types", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/status", "@com_google_absl//absl/status:status_matchers", @@ -162,8 +162,8 @@ cc_test( "//iamf/cli/proto:parameter_block_cc_proto", "//iamf/cli/proto:user_metadata_cc_proto", "//iamf/obu:codec_config", - "//iamf/obu:leb128", "//iamf/obu:param_definitions", + "//iamf/obu:types", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/status", "@com_google_absl//absl/status:status_matchers", @@ -201,8 +201,8 @@ cc_test( "//iamf/cli/proto:user_metadata_cc_proto", "//iamf/obu:codec_config", "//iamf/obu:ia_sequence_header", - "//iamf/obu:leb128", "//iamf/obu:mix_presentation", + "//iamf/obu:types", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/log", "@com_google_absl//absl/status", @@ -219,7 +219,7 @@ cc_test( "//iamf/cli:leb_generator", "//iamf/cli/proto:test_vector_metadata_cc_proto", "//iamf/cli/proto:user_metadata_cc_proto", - "//iamf/obu:leb128", + "//iamf/obu:types", "@com_google_absl//absl/status", "@com_google_absl//absl/status:status_matchers", "@com_google_googletest//:gtest_main", @@ -259,8 +259,8 @@ cc_test( ":cli_test_utils", "//iamf/cli:mix_presentation_finalizer", "//iamf/cli:wav_writer", - "//iamf/obu:leb128", "//iamf/obu:mix_presentation", + "//iamf/obu:types", "@com_google_absl//absl/status:status_matchers", "@com_google_googletest//:gtest_main", ], @@ -281,13 +281,13 @@ cc_test( "//iamf/obu:codec_config", "//iamf/obu:demixing_info_param_data", "//iamf/obu:ia_sequence_header", - "//iamf/obu:leb128", "//iamf/obu:mix_presentation", "//iamf/obu:obu_base", "//iamf/obu:obu_header", "//iamf/obu:param_definitions", "//iamf/obu:parameter_block", "//iamf/obu:temporal_delimiter", + "//iamf/obu:types", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/status:status_matchers", "@com_google_googletest//:gtest_main", @@ -321,10 +321,10 @@ cc_test( "//iamf/obu:audio_element", "//iamf/obu:codec_config", "//iamf/obu:demixing_info_param_data", - "//iamf/obu:leb128", "//iamf/obu:obu_header", "//iamf/obu:param_definitions", "//iamf/obu:parameter_block", + "//iamf/obu:types", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/status", "@com_google_absl//absl/status:status_matchers", @@ -345,10 +345,10 @@ cc_test( "//iamf/obu:audio_element", "//iamf/obu:codec_config", "//iamf/obu:ia_sequence_header", - "//iamf/obu:leb128", "//iamf/obu:mix_presentation", "//iamf/obu:obu_header", "//iamf/obu:param_definitions", + "//iamf/obu:types", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:flat_hash_set", "@com_google_absl//absl/status", @@ -365,6 +365,7 @@ cc_test( "//iamf/cli:demixing_module", "//iamf/cli:recon_gain_generator", "//iamf/cli/proto:user_metadata_cc_proto", + "//iamf/obu:types", "@com_google_absl//absl/status:status_matchers", "@com_google_googletest//:gtest_main", ], @@ -415,7 +416,7 @@ cc_test( "//iamf/cli:wav_sample_provider", "//iamf/cli/proto:user_metadata_cc_proto", "//iamf/obu:codec_config", - "//iamf/obu:leb128", + "//iamf/obu:types", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/status:status_matchers", "@com_google_absl//absl/strings:string_view", diff --git a/iamf/cli/tests/audio_frame_decoder_test.cc b/iamf/cli/tests/audio_frame_decoder_test.cc index 4589a4b8..81a4b8bf 100644 --- a/iamf/cli/tests/audio_frame_decoder_test.cc +++ b/iamf/cli/tests/audio_frame_decoder_test.cc @@ -26,8 +26,8 @@ #include "iamf/obu/audio_frame.h" #include "iamf/obu/codec_config.h" #include "iamf/obu/demixing_info_param_data.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/obu_header.h" +#include "iamf/obu/types.h" namespace iamf_tools { namespace { diff --git a/iamf/cli/tests/cli_test_utils.cc b/iamf/cli/tests/cli_test_utils.cc index ada1c0a4..3a56630e 100644 --- a/iamf/cli/tests/cli_test_utils.cc +++ b/iamf/cli/tests/cli_test_utils.cc @@ -39,10 +39,10 @@ #include "iamf/obu/decoder_config/lpcm_decoder_config.h" #include "iamf/obu/decoder_config/opus_decoder_config.h" #include "iamf/obu/demixing_info_param_data.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/mix_presentation.h" #include "iamf/obu/obu_header.h" #include "iamf/obu/param_definitions.h" +#include "iamf/obu/types.h" namespace iamf_tools { @@ -277,7 +277,7 @@ WavReader CreateWavReaderExpectOk(const std::string& filename, void RenderAndFlushExpectOk(const LabeledFrame& labeled_frame, AudioElementRendererBase* renderer, - std::vector& output_samples) { + std::vector& output_samples) { ASSERT_NE(renderer, nullptr); EXPECT_THAT(renderer->RenderLabeledFrame(labeled_frame), IsOk()); EXPECT_THAT(renderer->Finalize(), IsOk()); diff --git a/iamf/cli/tests/cli_test_utils.h b/iamf/cli/tests/cli_test_utils.h index 6e4dd6c9..dc1d99f2 100644 --- a/iamf/cli/tests/cli_test_utils.h +++ b/iamf/cli/tests/cli_test_utils.h @@ -26,9 +26,9 @@ #include "iamf/cli/wav_reader.h" #include "iamf/obu/audio_element.h" #include "iamf/obu/codec_config.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/mix_presentation.h" #include "iamf/obu/param_definitions.h" +#include "iamf/obu/types.h" namespace iamf_tools { @@ -153,7 +153,7 @@ WavReader CreateWavReaderExpectOk(const std::string& filename, */ void RenderAndFlushExpectOk(const LabeledFrame& labeled_frame, AudioElementRendererBase* renderer, - std::vector& output_samples); + std::vector& output_samples); /*!\brief Gets and cleans up unique file name based on the specified suffix. * diff --git a/iamf/cli/tests/cli_util_test.cc b/iamf/cli/tests/cli_util_test.cc index ba975776..983b69c2 100644 --- a/iamf/cli/tests/cli_util_test.cc +++ b/iamf/cli/tests/cli_util_test.cc @@ -37,11 +37,11 @@ #include "iamf/obu/codec_config.h" #include "iamf/obu/demixing_info_param_data.h" #include "iamf/obu/ia_sequence_header.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/mix_presentation.h" #include "iamf/obu/obu_header.h" #include "iamf/obu/param_definitions.h" #include "iamf/obu/parameter_block.h" +#include "iamf/obu/types.h" #include "src/google/protobuf/text_format.h" namespace iamf_tools { diff --git a/iamf/cli/tests/demixing_module_test.cc b/iamf/cli/tests/demixing_module_test.cc index a5f8f853..1e13a265 100644 --- a/iamf/cli/tests/demixing_module_test.cc +++ b/iamf/cli/tests/demixing_module_test.cc @@ -35,9 +35,9 @@ #include "iamf/obu/audio_frame.h" #include "iamf/obu/codec_config.h" #include "iamf/obu/demixing_info_param_data.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/obu_header.h" #include "iamf/obu/parameter_block.h" +#include "iamf/obu/types.h" #include "src/google/protobuf/text_format.h" namespace iamf_tools { @@ -45,6 +45,9 @@ namespace { using ::absl_testing::IsOk; using enum ChannelLabel::Label; +using testing::DoubleEq; +using testing::DoubleNear; +using testing::Pointwise; constexpr DecodedUleb128 kAudioElementId = 137; constexpr std::array kReconGainValues = { @@ -60,58 +63,57 @@ const DecodedUleb128 kL2SubstreamId = 1; // of erroneous input. TEST(FindSamplesOrDemixedSamples, FindsMatchingSamples) { - const std::vector kSamplesToFind = {1, 2, 3}; + const std::vector kSamplesToFind = {1, 2, 3}; const LabelSamplesMap kLabelToSamples = {{kL2, kSamplesToFind}}; - const std::vector* found_samples; + const std::vector* found_samples; EXPECT_THAT(DemixingModule::FindSamplesOrDemixedSamples(kL2, kLabelToSamples, &found_samples), IsOk()); - EXPECT_EQ(*found_samples, kSamplesToFind); + EXPECT_THAT(*found_samples, Pointwise(DoubleEq(), kSamplesToFind)); } TEST(FindSamplesOrDemixedSamples, FindsMatchingDemixedSamples) { - const std::vector kSamplesToFind = {1, 2, 3}; + const std::vector kSamplesToFind = {1, 2, 3}; const LabelSamplesMap kLabelToSamples = {{kDemixedR2, kSamplesToFind}}; - const std::vector* found_samples; + const std::vector* found_samples; EXPECT_THAT(DemixingModule::FindSamplesOrDemixedSamples(kR2, kLabelToSamples, &found_samples), IsOk()); - EXPECT_EQ(*found_samples, kSamplesToFind); + EXPECT_THAT(*found_samples, Pointwise(DoubleEq(), kSamplesToFind)); } TEST(FindSamplesOrDemixedSamples, InvalidWhenThereIsNoDemixingLabel) { - const std::vector kSamplesToFind = {1, 2, 3}; + const std::vector kSamplesToFind = {1, 2, 3}; const LabelSamplesMap kLabelToSamples = {{kDemixedR2, kSamplesToFind}}; - const std::vector* found_samples; + const std::vector* found_samples; EXPECT_FALSE(DemixingModule::FindSamplesOrDemixedSamples(kL2, kLabelToSamples, &found_samples) .ok()); } TEST(FindSamplesOrDemixedSamples, RegularSamplesTakePrecedence) { - const std::vector kSamplesToFind = {1, 2, 3}; - const std::vector kDemixedSamplesToIgnore = {4, 5, 6}; + const std::vector kSamplesToFind = {1, 2, 3}; + const std::vector kDemixedSamplesToIgnore = {4, 5, 6}; const LabelSamplesMap kLabelToSamples = { {kR2, kSamplesToFind}, {kDemixedR2, kDemixedSamplesToIgnore}}; - const std::vector* found_samples; + const std::vector* found_samples; EXPECT_THAT(DemixingModule::FindSamplesOrDemixedSamples(kR2, kLabelToSamples, &found_samples), IsOk()); - EXPECT_EQ(*found_samples, kSamplesToFind); + EXPECT_THAT(*found_samples, Pointwise(DoubleEq(), kSamplesToFind)); } TEST(FindSamplesOrDemixedSamples, ErrorNoMatchingSamples) { - const std::vector kSamplesToFind = {1, 2, 3}; + const std::vector kSamplesToFind = {1, 2, 3}; const LabelSamplesMap kLabelToSamples = {{kL2, kSamplesToFind}}; - const std::vector* found_samples; - EXPECT_EQ(DemixingModule::FindSamplesOrDemixedSamples(kL3, kLabelToSamples, - &found_samples) - .code(), - absl::StatusCode::kUnknown); + const std::vector* found_samples; + EXPECT_FALSE(DemixingModule::FindSamplesOrDemixedSamples(kL3, kLabelToSamples, + &found_samples) + .ok()); } void InitAudioElementWithLabelsAndLayers( @@ -414,10 +416,10 @@ TEST(DemixAudioSamples, OutputEchoesOriginalLabels) { // Examine the demixed frame. const auto& labeled_frame = id_to_labeled_decoded_frame.at(kAudioElementId); - EXPECT_EQ(labeled_frame.label_to_samples.at(kMono), - std::vector({1, 2, 3})); - EXPECT_EQ(labeled_frame.label_to_samples.at(kL2), - std::vector({9, 10, 11})); + EXPECT_THAT(labeled_frame.label_to_samples.at(kMono), + Pointwise(DoubleEq(), {1.0, 2.0, 3.0})); + EXPECT_THAT(labeled_frame.label_to_samples.at(kL2), + Pointwise(DoubleEq(), {9.0, 10.0, 11.0})); } TEST(DemixAudioSamples, OutputHasReconstructedLayers) { @@ -459,8 +461,8 @@ TEST(DemixAudioSamples, OutputHasReconstructedLayers) { // Examine the demixed frame. const auto& labeled_frame = id_to_labeled_decoded_frame.at(kAudioElementId); // D_R2 = M - (L2 - 6 dB) + 6 dB. - EXPECT_EQ(labeled_frame.label_to_samples.at(kDemixedR2), - std::vector({500})); + EXPECT_THAT(labeled_frame.label_to_samples.at(kDemixedR2), + Pointwise(DoubleEq(), {500})); } TEST(DemixAudioSamples, OutputContainsReconGainAndLayerInfo) { @@ -591,8 +593,9 @@ class DownMixingModuleTest : public DemixingModuleTestBase, } } - void ConfigureInputChannel(absl::string_view label_string, - const std::vector& input_samples) { + void ConfigureInputChannel( + absl::string_view label_string, + const std::vector& input_samples) { ConfigureAudioFrameMetadata(label_string); auto label = ChannelLabel::StringToLabel(label_string); ASSERT_TRUE(label.ok()); @@ -980,7 +983,7 @@ class DemixingModuleTest : public DemixingModuleTestBase, void ConfiguredExpectedDemixingChannelFrame( ChannelLabel::Label label, - std::vector expected_demixed_samples) { + std::vector expected_demixed_samples) { // Configure the expected demixed channels. Typically the input `label` // should have a "D_" prefix. expected_id_to_labeled_decoded_frame_[kAudioElementId] @@ -998,9 +1001,18 @@ class DemixingModuleTest : public DemixingModuleTestBase, IsOk()); // Check that the demixed samples have the correct values. - EXPECT_EQ(id_to_labeled_decoded_frame[kAudioElementId].label_to_samples, - expected_id_to_labeled_decoded_frame_[kAudioElementId] - .label_to_samples); + const auto& actual_label_to_samples = + id_to_labeled_decoded_frame[kAudioElementId].label_to_samples; + const auto& expected_label_to_samples = + expected_id_to_labeled_decoded_frame_[kAudioElementId].label_to_samples; + EXPECT_EQ(actual_label_to_samples.size(), expected_label_to_samples.size()); + for (const auto [label, samples] : actual_label_to_samples) { + // Use `DoubleNear` with a tolerance because floating-point arithmetic + // introduces errors larger than allowed by `DoubleEq`. + constexpr double kErrorTolerance = 1e-14; + EXPECT_THAT(samples, Pointwise(DoubleNear(kErrorTolerance), + expected_label_to_samples.at(label))); + } } protected: @@ -1083,8 +1095,8 @@ TEST_F(DemixingModuleTest, S2ToS3Demixer) { // L3/R3 get demixed from the lower layers. // L3 = L2 - (C - 3 dB). // R3 = R2 - (C - 3 dB). - ConfiguredExpectedDemixingChannelFrame(kDemixedL3, {0, 993}); - ConfiguredExpectedDemixingChannelFrame(kDemixedR3, {0, 993}); + ConfiguredExpectedDemixingChannelFrame(kDemixedL3, {-0.7, 993}); + ConfiguredExpectedDemixingChannelFrame(kDemixedR3, {-0.7, 993}); TestDemixing(1); } diff --git a/iamf/cli/tests/global_timing_module_test.cc b/iamf/cli/tests/global_timing_module_test.cc index 111059ce..0e55ac7d 100644 --- a/iamf/cli/tests/global_timing_module_test.cc +++ b/iamf/cli/tests/global_timing_module_test.cc @@ -26,8 +26,8 @@ #include "iamf/cli/proto/user_metadata.pb.h" #include "iamf/cli/tests/cli_test_utils.h" #include "iamf/obu/codec_config.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/param_definitions.h" +#include "iamf/obu/types.h" namespace iamf_tools { namespace { diff --git a/iamf/cli/tests/iamf_encoder_test.cc b/iamf/cli/tests/iamf_encoder_test.cc index 9578abf3..656f8bfc 100644 --- a/iamf/cli/tests/iamf_encoder_test.cc +++ b/iamf/cli/tests/iamf_encoder_test.cc @@ -25,8 +25,8 @@ #include "iamf/cli/proto/user_metadata.pb.h" #include "iamf/obu/codec_config.h" #include "iamf/obu/ia_sequence_header.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/mix_presentation.h" +#include "iamf/obu/types.h" #include "src/google/protobuf/text_format.h" namespace iamf_tools { @@ -240,7 +240,7 @@ TEST(IamfEncoderTest, GenerateDataObusTwoIterationsSucceeds) { IsOk()); // Temporary variables for one iteration. - const std::vector zero_samples(kNumSamplesPerFrame, 0); + const std::vector zero_samples(kNumSamplesPerFrame, 0.0); std::list temp_audio_frames; std::list temp_parameter_blocks; IdLabeledFrameMap id_to_labeled_frame; diff --git a/iamf/cli/tests/leb_generator_test.cc b/iamf/cli/tests/leb_generator_test.cc index 4d61ebd9..c76f8c02 100644 --- a/iamf/cli/tests/leb_generator_test.cc +++ b/iamf/cli/tests/leb_generator_test.cc @@ -22,7 +22,7 @@ #include "gtest/gtest.h" #include "iamf/cli/proto/test_vector_metadata.pb.h" #include "iamf/cli/proto/user_metadata.pb.h" -#include "iamf/obu/leb128.h" +#include "iamf/obu/types.h" #include "src/google/protobuf/text_format.h" namespace iamf_tools { diff --git a/iamf/cli/tests/mix_presentation_finalizer_test.cc b/iamf/cli/tests/mix_presentation_finalizer_test.cc index 94a868b6..98bc57d7 100644 --- a/iamf/cli/tests/mix_presentation_finalizer_test.cc +++ b/iamf/cli/tests/mix_presentation_finalizer_test.cc @@ -21,8 +21,8 @@ #include "gtest/gtest.h" #include "iamf/cli/tests/cli_test_utils.h" #include "iamf/cli/wav_writer.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/mix_presentation.h" +#include "iamf/obu/types.h" namespace iamf_tools { namespace { diff --git a/iamf/cli/tests/obu_sequencer_test.cc b/iamf/cli/tests/obu_sequencer_test.cc index 35673328..4dfc8f64 100644 --- a/iamf/cli/tests/obu_sequencer_test.cc +++ b/iamf/cli/tests/obu_sequencer_test.cc @@ -32,13 +32,13 @@ #include "iamf/obu/codec_config.h" #include "iamf/obu/demixing_info_param_data.h" #include "iamf/obu/ia_sequence_header.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/mix_presentation.h" #include "iamf/obu/obu_base.h" #include "iamf/obu/obu_header.h" #include "iamf/obu/param_definitions.h" #include "iamf/obu/parameter_block.h" #include "iamf/obu/temporal_delimiter.h" +#include "iamf/obu/types.h" namespace iamf_tools { namespace { diff --git a/iamf/cli/tests/parameters_manager_test.cc b/iamf/cli/tests/parameters_manager_test.cc index 2a277e1c..fba89d55 100644 --- a/iamf/cli/tests/parameters_manager_test.cc +++ b/iamf/cli/tests/parameters_manager_test.cc @@ -27,10 +27,10 @@ #include "iamf/obu/audio_element.h" #include "iamf/obu/codec_config.h" #include "iamf/obu/demixing_info_param_data.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/obu_header.h" #include "iamf/obu/param_definitions.h" #include "iamf/obu/parameter_block.h" +#include "iamf/obu/types.h" namespace iamf_tools { namespace { diff --git a/iamf/cli/tests/profile_filter_test.cc b/iamf/cli/tests/profile_filter_test.cc index 21e5b24d..0782f189 100644 --- a/iamf/cli/tests/profile_filter_test.cc +++ b/iamf/cli/tests/profile_filter_test.cc @@ -32,10 +32,10 @@ #include "iamf/obu/audio_element.h" #include "iamf/obu/codec_config.h" #include "iamf/obu/ia_sequence_header.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/mix_presentation.h" #include "iamf/obu/obu_header.h" #include "iamf/obu/param_definitions.h" +#include "iamf/obu/types.h" namespace iamf_tools { namespace { diff --git a/iamf/cli/tests/recon_gain_generator_test.cc b/iamf/cli/tests/recon_gain_generator_test.cc index 9438b376..a6970b86 100644 --- a/iamf/cli/tests/recon_gain_generator_test.cc +++ b/iamf/cli/tests/recon_gain_generator_test.cc @@ -22,6 +22,7 @@ #include "iamf/cli/channel_label.h" #include "iamf/cli/demixing_module.h" #include "iamf/cli/proto/user_metadata.pb.h" +#include "iamf/obu/types.h" namespace iamf_tools { namespace { @@ -30,12 +31,13 @@ using ::absl_testing::IsOk; using enum ChannelLabel::Label; -const int32_t kArbitrarySample = std::numeric_limits::max(); +const InternalSampleType kArbitrarySample = + static_cast(std::numeric_limits::max()); void TestComputeReconGainForOneChannelLrs7( - const std::vector& original_channel, - const std::vector& mixed_channel, - const std::vector& demixed_channel, + const std::vector& original_channel, + const std::vector& mixed_channel, + const std::vector& demixed_channel, const double expected_recon_gain) { const LabelSamplesMap label_to_samples{{kDemixedLrs7, original_channel}, {kLs5, mixed_channel}}; @@ -71,9 +73,9 @@ TEST(ComputeReconGain, LessThanSecondThreshold) { } TEST(ComputeReconGain, SucceedsForTwoLayerStereo) { - const std::vector kOriginalChannel{kArbitrarySample}; - const std::vector kMixedChannel{kArbitrarySample}; - const std::vector kDemixedChannel{kArbitrarySample}; + const std::vector kOriginalChannel{kArbitrarySample}; + const std::vector kMixedChannel{kArbitrarySample}; + const std::vector kDemixedChannel{kArbitrarySample}; const LabelSamplesMap label_to_samples{{kDemixedR2, kOriginalChannel}, {kMono, kMixedChannel}}; const LabelSamplesMap label_to_decoded_samples{{kDemixedR2, kDemixedChannel}}; @@ -86,8 +88,8 @@ TEST(ComputeReconGain, SucceedsForTwoLayerStereo) { } TEST(ComputeReconGain, InvalidWhenRelevantMixedSampleCannotBeFound) { - const std::vector kOriginalChannel{kArbitrarySample}; - const std::vector kDemixedChannel{kArbitrarySample}; + const std::vector kOriginalChannel{kArbitrarySample}; + const std::vector kDemixedChannel{kArbitrarySample}; const LabelSamplesMap label_to_samples{{kDemixedR2, kOriginalChannel}}; const LabelSamplesMap label_to_decoded_samples{{kDemixedR2, kDemixedChannel}}; diff --git a/iamf/cli/tests/wav_sample_provider_test.cc b/iamf/cli/tests/wav_sample_provider_test.cc index ee57ff1b..ad65ee56 100644 --- a/iamf/cli/tests/wav_sample_provider_test.cc +++ b/iamf/cli/tests/wav_sample_provider_test.cc @@ -28,7 +28,7 @@ #include "iamf/cli/proto/user_metadata.pb.h" #include "iamf/cli/tests/cli_test_utils.h" #include "iamf/obu/codec_config.h" -#include "iamf/obu/leb128.h" +#include "iamf/obu/types.h" #include "src/google/protobuf/text_format.h" namespace iamf_tools { @@ -36,6 +36,8 @@ namespace { using ::absl_testing::IsOk; using enum ChannelLabel::Label; +using testing::DoubleEq; +using testing::Pointwise; static constexpr DecodedUleb128 kAudioElementId = 300; static constexpr DecodedUleb128 kCodecConfigId = 200; @@ -155,13 +157,13 @@ TEST(WavSampleProviderTest, ReadFrameSucceeds) { EXPECT_TRUE(finished_reading); // Validate samples read from the WAV file. - const std::vector expected_samples_l2 = { + const std::vector expected_samples_l2 = { 1 << 16, 2 << 16, 3 << 16, 4 << 16, 5 << 16, 6 << 16, 7 << 16, 8 << 16}; - const std::vector expected_samples_r2 = { + const std::vector expected_samples_r2 = { 65535 << 16, 65534 << 16, 65533 << 16, 65532 << 16, 65531 << 16, 65530 << 16, 65529 << 16, 65528 << 16}; - EXPECT_THAT(labeled_samples[kL2], testing::Eq(expected_samples_l2)); - EXPECT_THAT(labeled_samples[kR2], testing::Eq(expected_samples_r2)); + EXPECT_THAT(labeled_samples[kL2], Pointwise(DoubleEq(), expected_samples_l2)); + EXPECT_THAT(labeled_samples[kR2], Pointwise(DoubleEq(), expected_samples_r2)); } TEST(WavSampleProviderTest, ReadFrameFailsWithWrongAudioElementId) { diff --git a/iamf/cli/wav_sample_provider.cc b/iamf/cli/wav_sample_provider.cc index 33274ea4..b69d252d 100644 --- a/iamf/cli/wav_sample_provider.cc +++ b/iamf/cli/wav_sample_provider.cc @@ -28,7 +28,7 @@ #include "iamf/cli/demixing_module.h" #include "iamf/cli/wav_reader.h" #include "iamf/common/macros.h" -#include "iamf/obu/leb128.h" +#include "iamf/obu/types.h" namespace iamf_tools { @@ -125,7 +125,8 @@ absl::Status WavSampleProvider::ReadFrames( auto& samples = labeled_samples[channel_labels[c]]; samples.resize(num_time_ticks); for (int t = 0; t < num_time_ticks; ++t) { - samples[t] = wav_reader.buffers_[t][channel_ids[c]]; + samples[t] = static_cast( + wav_reader.buffers_[t][channel_ids[c]]); } } finished_reading = (wav_reader.remaining_samples() == 0); diff --git a/iamf/cli/wav_sample_provider.h b/iamf/cli/wav_sample_provider.h index 1744a944..83f905dc 100644 --- a/iamf/cli/wav_sample_provider.h +++ b/iamf/cli/wav_sample_provider.h @@ -23,7 +23,7 @@ #include "iamf/cli/demixing_module.h" #include "iamf/cli/proto/audio_frame.pb.h" #include "iamf/cli/wav_reader.h" -#include "iamf/obu/leb128.h" +#include "iamf/obu/types.h" #include "src/google/protobuf/repeated_ptr_field.h" namespace iamf_tools { diff --git a/iamf/common/BUILD b/iamf/common/BUILD index fa847990..b237ef7e 100644 --- a/iamf/common/BUILD +++ b/iamf/common/BUILD @@ -18,7 +18,7 @@ cc_library( hdrs = ["obu_util.h"], deps = [ ":macros", - "//iamf/obu:leb128", + "//iamf/obu:types", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:flat_hash_set", "@com_google_absl//absl/functional:any_invocable", @@ -38,7 +38,7 @@ cc_library( deps = [ ":bit_buffer_util", ":macros", - "//iamf/obu:leb128", + "//iamf/obu:types", "@com_google_absl//absl/functional:any_invocable", "@com_google_absl//absl/status", "@com_google_absl//absl/strings", @@ -53,7 +53,7 @@ cc_library( ":bit_buffer_util", ":macros", "//iamf/cli:leb_generator", - "//iamf/obu:leb128", + "//iamf/obu:types", "@com_google_absl//absl/log", "@com_google_absl//absl/status", "@com_google_absl//absl/strings", diff --git a/iamf/common/obu_util.cc b/iamf/common/obu_util.cc index 3b8f2783..561debd1 100644 --- a/iamf/common/obu_util.cc +++ b/iamf/common/obu_util.cc @@ -27,7 +27,7 @@ #include "absl/status/status.h" #include "absl/strings/str_cat.h" #include "absl/types/span.h" -#include "iamf/obu/leb128.h" +#include "iamf/obu/types.h" namespace iamf_tools { diff --git a/iamf/common/obu_util.h b/iamf/common/obu_util.h index b5f50e9c..5c53c994 100644 --- a/iamf/common/obu_util.h +++ b/iamf/common/obu_util.h @@ -29,7 +29,7 @@ #include "absl/strings/string_view.h" #include "absl/types/span.h" #include "iamf/common/macros.h" -#include "iamf/obu/leb128.h" +#include "iamf/obu/types.h" namespace iamf_tools { diff --git a/iamf/common/read_bit_buffer.cc b/iamf/common/read_bit_buffer.cc index 9cd2e2b6..1f0deb3c 100644 --- a/iamf/common/read_bit_buffer.cc +++ b/iamf/common/read_bit_buffer.cc @@ -23,7 +23,7 @@ #include "absl/strings/str_cat.h" #include "iamf/common/bit_buffer_util.h" #include "iamf/common/macros.h" -#include "iamf/obu/leb128.h" +#include "iamf/obu/types.h" namespace iamf_tools { diff --git a/iamf/common/read_bit_buffer.h b/iamf/common/read_bit_buffer.h index 97544e43..48b8309d 100644 --- a/iamf/common/read_bit_buffer.h +++ b/iamf/common/read_bit_buffer.h @@ -17,7 +17,7 @@ #include #include "absl/status/status.h" -#include "iamf/obu/leb128.h" +#include "iamf/obu/types.h" namespace iamf_tools { diff --git a/iamf/common/tests/BUILD b/iamf/common/tests/BUILD index 3f8621e2..d7e4e9ee 100644 --- a/iamf/common/tests/BUILD +++ b/iamf/common/tests/BUILD @@ -32,7 +32,7 @@ cc_test( deps = [ "//iamf/common:bit_buffer_util", "//iamf/common:read_bit_buffer", - "//iamf/obu:leb128", + "//iamf/obu:types", "@com_google_absl//absl/status", "@com_google_absl//absl/status:status_matchers", "@com_google_googletest//:gtest_main", @@ -64,7 +64,7 @@ cc_test( "//iamf/cli:leb_generator", "//iamf/common:bit_buffer_util", "//iamf/common:write_bit_buffer", - "//iamf/obu:leb128", + "//iamf/obu:types", "@com_google_absl//absl/status", "@com_google_absl//absl/status:status_matchers", "@com_google_absl//absl/strings", diff --git a/iamf/common/tests/read_bit_buffer_test.cc b/iamf/common/tests/read_bit_buffer_test.cc index 17423173..5dc67535 100644 --- a/iamf/common/tests/read_bit_buffer_test.cc +++ b/iamf/common/tests/read_bit_buffer_test.cc @@ -22,7 +22,7 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" #include "iamf/common/bit_buffer_util.h" -#include "iamf/obu/leb128.h" +#include "iamf/obu/types.h" namespace iamf_tools { namespace { diff --git a/iamf/common/tests/write_bit_buffer_test.cc b/iamf/common/tests/write_bit_buffer_test.cc index 113bad0c..03146b59 100644 --- a/iamf/common/tests/write_bit_buffer_test.cc +++ b/iamf/common/tests/write_bit_buffer_test.cc @@ -25,7 +25,7 @@ #include "iamf/cli/leb_generator.h" #include "iamf/common/bit_buffer_util.h" #include "iamf/common/tests/test_utils.h" -#include "iamf/obu/leb128.h" +#include "iamf/obu/types.h" namespace iamf_tools { namespace { diff --git a/iamf/common/write_bit_buffer.cc b/iamf/common/write_bit_buffer.cc index 960f6594..bf1fa9b5 100644 --- a/iamf/common/write_bit_buffer.cc +++ b/iamf/common/write_bit_buffer.cc @@ -24,7 +24,7 @@ #include "iamf/cli/leb_generator.h" #include "iamf/common/bit_buffer_util.h" #include "iamf/common/macros.h" -#include "iamf/obu/leb128.h" +#include "iamf/obu/types.h" namespace iamf_tools { diff --git a/iamf/common/write_bit_buffer.h b/iamf/common/write_bit_buffer.h index 3c7a1fc0..86712913 100644 --- a/iamf/common/write_bit_buffer.h +++ b/iamf/common/write_bit_buffer.h @@ -19,7 +19,7 @@ #include "absl/status/status.h" #include "iamf/cli/leb_generator.h" -#include "iamf/obu/leb128.h" +#include "iamf/obu/types.h" namespace iamf_tools { diff --git a/iamf/obu/BUILD b/iamf/obu/BUILD index 55521e11..19afe28e 100644 --- a/iamf/obu/BUILD +++ b/iamf/obu/BUILD @@ -23,10 +23,10 @@ cc_library( srcs = ["audio_element.cc"], hdrs = ["audio_element.h"], deps = [ - ":leb128", ":obu_base", ":obu_header", ":param_definitions", + ":types", "//iamf/common:macros", "//iamf/common:obu_util", "//iamf/common:read_bit_buffer", @@ -46,9 +46,9 @@ cc_library( ], hdrs = ["audio_frame.h"], deps = [ - ":leb128", ":obu_base", ":obu_header", + ":types", "//iamf/common:macros", "//iamf/common:read_bit_buffer", "//iamf/common:write_bit_buffer", @@ -63,9 +63,9 @@ cc_library( srcs = ["codec_config.cc"], hdrs = ["codec_config.h"], deps = [ - ":leb128", ":obu_base", ":obu_header", + ":types", "//iamf/common:macros", "//iamf/common:read_bit_buffer", "//iamf/common:write_bit_buffer", @@ -115,8 +115,8 @@ cc_library( ) cc_library( - name = "leb128", - hdrs = ["leb128.h"], + name = "types", + hdrs = ["types.h"], ) cc_library( @@ -124,10 +124,10 @@ cc_library( srcs = ["mix_presentation.cc"], hdrs = ["mix_presentation.h"], deps = [ - ":leb128", ":obu_base", ":obu_header", ":param_definitions", + ":types", "//iamf/common:macros", "//iamf/common:obu_util", "//iamf/common:read_bit_buffer", @@ -162,7 +162,7 @@ cc_library( srcs = ["obu_header.cc"], hdrs = ["obu_header.h"], deps = [ - ":leb128", + ":types", "//iamf/cli:leb_generator", "//iamf/common:macros", "//iamf/common:obu_util", @@ -180,7 +180,7 @@ cc_library( hdrs = ["param_definitions.h"], deps = [ ":demixing_info_param_data", - ":leb128", + ":types", "//iamf/common:macros", "//iamf/common:obu_util", "//iamf/common:read_bit_buffer", @@ -197,10 +197,10 @@ cc_library( hdrs = ["parameter_block.h"], deps = [ ":demixing_info_param_data", - ":leb128", ":obu_base", ":obu_header", ":param_definitions", + ":types", "//iamf/common:macros", "//iamf/common:obu_util", "//iamf/common:read_bit_buffer", diff --git a/iamf/obu/audio_element.cc b/iamf/obu/audio_element.cc index f8b0e6e1..49747722 100644 --- a/iamf/obu/audio_element.cc +++ b/iamf/obu/audio_element.cc @@ -30,10 +30,10 @@ #include "iamf/common/obu_util.h" #include "iamf/common/read_bit_buffer.h" #include "iamf/common/write_bit_buffer.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/obu_base.h" #include "iamf/obu/obu_header.h" #include "iamf/obu/param_definitions.h" +#include "iamf/obu/types.h" namespace iamf_tools { diff --git a/iamf/obu/audio_element.h b/iamf/obu/audio_element.h index 89d16ede..060c72f7 100644 --- a/iamf/obu/audio_element.h +++ b/iamf/obu/audio_element.h @@ -23,10 +23,10 @@ #include "absl/status/statusor.h" #include "iamf/common/read_bit_buffer.h" #include "iamf/common/write_bit_buffer.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/obu_base.h" #include "iamf/obu/obu_header.h" #include "iamf/obu/param_definitions.h" +#include "iamf/obu/types.h" namespace iamf_tools { diff --git a/iamf/obu/audio_frame.cc b/iamf/obu/audio_frame.cc index 7d773b7d..52d77cf7 100644 --- a/iamf/obu/audio_frame.cc +++ b/iamf/obu/audio_frame.cc @@ -19,9 +19,9 @@ #include "iamf/common/macros.h" #include "iamf/common/read_bit_buffer.h" #include "iamf/common/write_bit_buffer.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/obu_base.h" #include "iamf/obu/obu_header.h" +#include "iamf/obu/types.h" namespace iamf_tools { diff --git a/iamf/obu/audio_frame.h b/iamf/obu/audio_frame.h index 5d183c6b..4dc48657 100644 --- a/iamf/obu/audio_frame.h +++ b/iamf/obu/audio_frame.h @@ -19,9 +19,9 @@ #include "absl/status/statusor.h" #include "iamf/common/read_bit_buffer.h" #include "iamf/common/write_bit_buffer.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/obu_base.h" #include "iamf/obu/obu_header.h" +#include "iamf/obu/types.h" namespace iamf_tools { /*!\brief The Audio Frame OBU. diff --git a/iamf/obu/codec_config.cc b/iamf/obu/codec_config.cc index 008f878c..b4329740 100644 --- a/iamf/obu/codec_config.cc +++ b/iamf/obu/codec_config.cc @@ -25,9 +25,9 @@ #include "iamf/obu/decoder_config/flac_decoder_config.h" #include "iamf/obu/decoder_config/lpcm_decoder_config.h" #include "iamf/obu/decoder_config/opus_decoder_config.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/obu_base.h" #include "iamf/obu/obu_header.h" +#include "iamf/obu/types.h" namespace iamf_tools { diff --git a/iamf/obu/codec_config.h b/iamf/obu/codec_config.h index 125859c5..1c88ae0c 100644 --- a/iamf/obu/codec_config.h +++ b/iamf/obu/codec_config.h @@ -23,9 +23,9 @@ #include "iamf/obu/decoder_config/flac_decoder_config.h" #include "iamf/obu/decoder_config/lpcm_decoder_config.h" #include "iamf/obu/decoder_config/opus_decoder_config.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/obu_base.h" #include "iamf/obu/obu_header.h" +#include "iamf/obu/types.h" namespace iamf_tools { diff --git a/iamf/obu/mix_presentation.cc b/iamf/obu/mix_presentation.cc index 2b3a8c79..b892ec9a 100644 --- a/iamf/obu/mix_presentation.cc +++ b/iamf/obu/mix_presentation.cc @@ -25,9 +25,9 @@ #include "iamf/common/obu_util.h" #include "iamf/common/read_bit_buffer.h" #include "iamf/common/write_bit_buffer.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/obu_header.h" #include "iamf/obu/param_definitions.h" +#include "iamf/obu/types.h" namespace iamf_tools { diff --git a/iamf/obu/mix_presentation.h b/iamf/obu/mix_presentation.h index 7934364a..cb964e0f 100644 --- a/iamf/obu/mix_presentation.h +++ b/iamf/obu/mix_presentation.h @@ -23,10 +23,10 @@ #include "absl/status/statusor.h" #include "iamf/common/read_bit_buffer.h" #include "iamf/common/write_bit_buffer.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/obu_base.h" #include "iamf/obu/obu_header.h" #include "iamf/obu/param_definitions.h" +#include "iamf/obu/types.h" namespace iamf_tools { diff --git a/iamf/obu/obu_header.cc b/iamf/obu/obu_header.cc index 78d23218..f577663f 100644 --- a/iamf/obu/obu_header.cc +++ b/iamf/obu/obu_header.cc @@ -23,7 +23,7 @@ #include "iamf/common/obu_util.h" #include "iamf/common/read_bit_buffer.h" #include "iamf/common/write_bit_buffer.h" -#include "iamf/obu/leb128.h" +#include "iamf/obu/types.h" namespace iamf_tools { diff --git a/iamf/obu/obu_header.h b/iamf/obu/obu_header.h index 408887e5..d448f2c6 100644 --- a/iamf/obu/obu_header.h +++ b/iamf/obu/obu_header.h @@ -19,7 +19,7 @@ #include "iamf/cli/leb_generator.h" #include "iamf/common/read_bit_buffer.h" #include "iamf/common/write_bit_buffer.h" -#include "iamf/obu/leb128.h" +#include "iamf/obu/types.h" namespace iamf_tools { diff --git a/iamf/obu/param_definitions.cc b/iamf/obu/param_definitions.cc index e169554b..de93b1a0 100644 --- a/iamf/obu/param_definitions.cc +++ b/iamf/obu/param_definitions.cc @@ -21,7 +21,7 @@ #include "iamf/common/read_bit_buffer.h" #include "iamf/common/write_bit_buffer.h" #include "iamf/obu/demixing_info_param_data.h" -#include "iamf/obu/leb128.h" +#include "iamf/obu/types.h" namespace iamf_tools { diff --git a/iamf/obu/param_definitions.h b/iamf/obu/param_definitions.h index acedefad..2b239143 100644 --- a/iamf/obu/param_definitions.h +++ b/iamf/obu/param_definitions.h @@ -22,7 +22,7 @@ #include "iamf/common/read_bit_buffer.h" #include "iamf/common/write_bit_buffer.h" #include "iamf/obu/demixing_info_param_data.h" -#include "iamf/obu/leb128.h" +#include "iamf/obu/types.h" namespace iamf_tools { diff --git a/iamf/obu/parameter_block.cc b/iamf/obu/parameter_block.cc index 89a0e4af..6d017598 100644 --- a/iamf/obu/parameter_block.cc +++ b/iamf/obu/parameter_block.cc @@ -25,10 +25,10 @@ #include "iamf/common/read_bit_buffer.h" #include "iamf/common/write_bit_buffer.h" #include "iamf/obu/demixing_info_param_data.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/obu_base.h" #include "iamf/obu/obu_header.h" #include "iamf/obu/param_definitions.h" +#include "iamf/obu/types.h" namespace iamf_tools { namespace { diff --git a/iamf/obu/parameter_block.h b/iamf/obu/parameter_block.h index 5935af63..3a0825ad 100644 --- a/iamf/obu/parameter_block.h +++ b/iamf/obu/parameter_block.h @@ -23,10 +23,10 @@ #include "iamf/common/read_bit_buffer.h" #include "iamf/common/write_bit_buffer.h" #include "iamf/obu/demixing_info_param_data.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/obu_base.h" #include "iamf/obu/obu_header.h" #include "iamf/obu/param_definitions.h" +#include "iamf/obu/types.h" namespace iamf_tools { diff --git a/iamf/obu/tests/BUILD b/iamf/obu/tests/BUILD index 78105d05..091f844a 100644 --- a/iamf/obu/tests/BUILD +++ b/iamf/obu/tests/BUILD @@ -40,9 +40,9 @@ cc_test( "//iamf/common/tests:test_utils", "//iamf/obu:audio_element", "//iamf/obu:demixing_info_param_data", - "//iamf/obu:leb128", "//iamf/obu:obu_header", "//iamf/obu:param_definitions", + "//iamf/obu:types", "@com_google_absl//absl/status", "@com_google_absl//absl/status:status_matchers", "@com_google_googletest//:gtest_main", @@ -59,8 +59,8 @@ cc_test( "//iamf/common:read_bit_buffer", "//iamf/common:write_bit_buffer", "//iamf/obu:audio_frame", - "//iamf/obu:leb128", "//iamf/obu:obu_header", + "//iamf/obu:types", "@com_google_absl//absl/status", "@com_google_absl//absl/status:status_matchers", "@com_google_googletest//:gtest_main", @@ -77,8 +77,8 @@ cc_test( "//iamf/common:read_bit_buffer", "//iamf/common:write_bit_buffer", "//iamf/obu:codec_config", - "//iamf/obu:leb128", "//iamf/obu:obu_header", + "//iamf/obu:types", "//iamf/obu/decoder_config:aac_decoder_config", "//iamf/obu/decoder_config:lpcm_decoder_config", "//iamf/obu/decoder_config:opus_decoder_config", @@ -132,10 +132,10 @@ cc_test( "//iamf/common:read_bit_buffer", "//iamf/common:write_bit_buffer", "//iamf/common/tests:test_utils", - "//iamf/obu:leb128", "//iamf/obu:mix_presentation", "//iamf/obu:obu_header", "//iamf/obu:param_definitions", + "//iamf/obu:types", "@com_google_absl//absl/status", "@com_google_absl//absl/status:status_matchers", "@com_google_googletest//:gtest_main", @@ -185,8 +185,8 @@ cc_test( "//iamf/common:write_bit_buffer", "//iamf/common/tests:test_utils", "//iamf/obu:demixing_info_param_data", - "//iamf/obu:leb128", "//iamf/obu:param_definitions", + "//iamf/obu:types", "@com_google_absl//absl/status", "@com_google_absl//absl/status:status_matchers", "@com_google_googletest//:gtest_main", @@ -203,10 +203,10 @@ cc_test( "//iamf/common:read_bit_buffer", "//iamf/common:write_bit_buffer", "//iamf/obu:demixing_info_param_data", - "//iamf/obu:leb128", "//iamf/obu:obu_header", "//iamf/obu:param_definitions", "//iamf/obu:parameter_block", + "//iamf/obu:types", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/status", "@com_google_absl//absl/status:status_matchers", diff --git a/iamf/obu/tests/audio_element_test.cc b/iamf/obu/tests/audio_element_test.cc index 65ece257..d8d6e8d0 100644 --- a/iamf/obu/tests/audio_element_test.cc +++ b/iamf/obu/tests/audio_element_test.cc @@ -29,10 +29,10 @@ #include "iamf/common/tests/test_utils.h" #include "iamf/common/write_bit_buffer.h" #include "iamf/obu/demixing_info_param_data.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/obu_header.h" #include "iamf/obu/param_definitions.h" #include "iamf/obu/tests/obu_test_base.h" +#include "iamf/obu/types.h" namespace iamf_tools { namespace { diff --git a/iamf/obu/tests/audio_frame_test.cc b/iamf/obu/tests/audio_frame_test.cc index 43f58ef5..066f71ad 100644 --- a/iamf/obu/tests/audio_frame_test.cc +++ b/iamf/obu/tests/audio_frame_test.cc @@ -24,9 +24,9 @@ #include "iamf/cli/leb_generator.h" #include "iamf/common/read_bit_buffer.h" #include "iamf/common/write_bit_buffer.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/obu_header.h" #include "iamf/obu/tests/obu_test_base.h" +#include "iamf/obu/types.h" namespace iamf_tools { namespace { diff --git a/iamf/obu/tests/codec_config_test.cc b/iamf/obu/tests/codec_config_test.cc index 37cdc069..41461513 100644 --- a/iamf/obu/tests/codec_config_test.cc +++ b/iamf/obu/tests/codec_config_test.cc @@ -28,9 +28,9 @@ #include "iamf/obu/decoder_config/aac_decoder_config.h" #include "iamf/obu/decoder_config/lpcm_decoder_config.h" #include "iamf/obu/decoder_config/opus_decoder_config.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/obu_header.h" #include "iamf/obu/tests/obu_test_base.h" +#include "iamf/obu/types.h" namespace iamf_tools { namespace { diff --git a/iamf/obu/tests/mix_presentation_test.cc b/iamf/obu/tests/mix_presentation_test.cc index a45aaeac..ff4e152b 100644 --- a/iamf/obu/tests/mix_presentation_test.cc +++ b/iamf/obu/tests/mix_presentation_test.cc @@ -27,10 +27,10 @@ #include "iamf/common/read_bit_buffer.h" #include "iamf/common/tests/test_utils.h" #include "iamf/common/write_bit_buffer.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/obu_header.h" #include "iamf/obu/param_definitions.h" #include "iamf/obu/tests/obu_test_base.h" +#include "iamf/obu/types.h" namespace iamf_tools { namespace { diff --git a/iamf/obu/tests/param_definitions_test.cc b/iamf/obu/tests/param_definitions_test.cc index 40cd7079..9386545c 100644 --- a/iamf/obu/tests/param_definitions_test.cc +++ b/iamf/obu/tests/param_definitions_test.cc @@ -25,7 +25,7 @@ #include "iamf/common/tests/test_utils.h" #include "iamf/common/write_bit_buffer.h" #include "iamf/obu/demixing_info_param_data.h" -#include "iamf/obu/leb128.h" +#include "iamf/obu/types.h" namespace iamf_tools { namespace { diff --git a/iamf/obu/tests/parameter_block_test.cc b/iamf/obu/tests/parameter_block_test.cc index adf8bedb..a4db5389 100644 --- a/iamf/obu/tests/parameter_block_test.cc +++ b/iamf/obu/tests/parameter_block_test.cc @@ -26,10 +26,10 @@ #include "iamf/common/read_bit_buffer.h" #include "iamf/common/write_bit_buffer.h" #include "iamf/obu/demixing_info_param_data.h" -#include "iamf/obu/leb128.h" #include "iamf/obu/obu_header.h" #include "iamf/obu/param_definitions.h" #include "iamf/obu/tests/obu_test_base.h" +#include "iamf/obu/types.h" namespace iamf_tools { namespace { diff --git a/iamf/obu/leb128.h b/iamf/obu/types.h similarity index 83% rename from iamf/obu/leb128.h rename to iamf/obu/types.h index 245393cd..cb5bfb45 100644 --- a/iamf/obu/leb128.h +++ b/iamf/obu/types.h @@ -20,12 +20,15 @@ namespace iamf_tools { */ inline constexpr int kMaxLeb128Size = 8; -/*!\brief A decoded `leb128` in IAMF. */ +/*!\brief Decoded `leb128` in IAMF. */ typedef uint32_t DecodedUleb128; -/*!\brief A decoded `sleb128` in IAMF. */ +/*!\brief Decoded `sleb128` in IAMF. */ typedef int32_t DecodedSleb128; +/*!\brief Type of audio samples for internal computation. */ +typedef double InternalSampleType; + } // namespace iamf_tools #endif // OBU_LEB128_H_