From 733262c402d92feb722ebe2eb8132fff86009c99 Mon Sep 17 00:00:00 2001 From: jwcullen Date: Wed, 17 Jul 2024 14:16:38 -0400 Subject: [PATCH] [Style] Update names and nesting of Mix Presentation fields for consistency with the spec. - In general we prefer names in `iamf/common/obu` mimic the spec as much as possible. - In https://github.com/AOMediaCodec/iamf/pull/844 the spec made some stylistic changes by renaming fields, or folding in some similar structures related to the Mix Presentation OBU. - Rename the fields, update the nesting, and keep various comments, function names, etc. up to date with the current spec. PiperOrigin-RevId: 653298984 --- iamf/cli/cli_util.cc | 7 +- .../mix_presentation_generator.cc | 43 ++++--- .../tests/mix_presentation_generator_test.cc | 9 +- iamf/cli/testdata/test_000119.textproto | 4 +- iamf/cli/testdata/test_000120.textproto | 4 +- iamf/cli/testdata/test_000122.textproto | 4 +- iamf/cli/testdata/test_000129.textproto | 4 +- iamf/cli/testdata/test_000130.textproto | 4 +- iamf/cli/tests/cli_test_utils.cc | 6 +- iamf/cli/tests/cli_util_test.cc | 17 ++- iamf/cli/tests/profile_filter_test.cc | 42 +++---- iamf/obu/mix_presentation.cc | 94 +++++++-------- iamf/obu/mix_presentation.h | 92 ++++---------- iamf/obu/tests/mix_presentation_test.cc | 114 ++++++++---------- 14 files changed, 185 insertions(+), 259 deletions(-) diff --git a/iamf/cli/cli_util.cc b/iamf/cli/cli_util.cc index 7a949c75..d0510b05 100644 --- a/iamf/cli/cli_util.cc +++ b/iamf/cli/cli_util.cc @@ -224,11 +224,10 @@ absl::Status CollectAndValidateParamDefinitions( for (const auto& mix_presentation_obu : mix_presentation_obus) { for (const auto& sub_mix : mix_presentation_obu.sub_mixes_) { for (const auto& audio_element : sub_mix.audio_elements) { - RETURN_IF_NOT_OK(insert_and_check_equivalence( - &audio_element.element_mix_config.mix_gain)); + RETURN_IF_NOT_OK( + insert_and_check_equivalence(&audio_element.element_mix_gain)); } - RETURN_IF_NOT_OK(insert_and_check_equivalence( - &sub_mix.output_mix_config.output_mix_gain)); + RETURN_IF_NOT_OK(insert_and_check_equivalence(&sub_mix.output_mix_gain)); } } diff --git a/iamf/cli/proto_to_obu/mix_presentation_generator.cc b/iamf/cli/proto_to_obu/mix_presentation_generator.cc index f207fc19..bde2e8e1 100644 --- a/iamf/cli/proto_to_obu/mix_presentation_generator.cc +++ b/iamf/cli/proto_to_obu/mix_presentation_generator.cc @@ -35,24 +35,25 @@ namespace iamf_tools { namespace { -void FillLanguageLabelsAndAnnotations( +void FillAnnotationsLanguageAndAnnotations( const iamf_tools_cli_proto::MixPresentationObuMetadata& mix_presentation_metadata, - DecodedUleb128& count_label, std::vector& language_labels, - std::vector& mix_presentation_annotations) { + DecodedUleb128& count_label, std::vector& annotations_language, + std::vector& localized_presentation_annotations) { count_label = mix_presentation_metadata.count_label(); - language_labels.reserve(mix_presentation_metadata.count_label()); + annotations_language.reserve(mix_presentation_metadata.count_label()); for (const auto& language_label : mix_presentation_metadata.language_labels()) { - language_labels.push_back(language_label); + annotations_language.push_back(language_label); } - mix_presentation_annotations.reserve(mix_presentation_metadata.count_label()); + localized_presentation_annotations.reserve( + mix_presentation_metadata.count_label()); for (const auto& mix_presentation_annotation : mix_presentation_metadata.mix_presentation_annotations_array()) { - mix_presentation_annotations.push_back( - {mix_presentation_annotation.mix_presentation_friendly_label()}); + localized_presentation_annotations.push_back( + mix_presentation_annotation.mix_presentation_friendly_label()); } } @@ -72,14 +73,14 @@ void FillSubMixNumAudioElements( sub_mix.audio_elements.reserve(input_sub_mix.num_audio_elements()); } -absl::Status FillMixPresentationElementAnnotations( +absl::Status FillLocalizedElementAnnotations( const iamf_tools_cli_proto::SubMixAudioElement& input_sub_mix_audio_element, SubMixAudioElement& sub_mix_audio_element) { for (const auto& input_audio_element_friendly_label : input_sub_mix_audio_element .mix_presentation_element_annotations_array()) { - sub_mix_audio_element.mix_presentation_element_annotations.push_back( - {input_audio_element_friendly_label.audio_element_friendly_label()}); + sub_mix_audio_element.localized_element_annotations.push_back( + input_audio_element_friendly_label.audio_element_friendly_label()); } return absl::OkStatus(); @@ -405,9 +406,9 @@ absl::Status MixPresentationGenerator::Generate( struct { DecodedUleb128 mix_presentation_id; DecodedUleb128 count_label; - std::vector language_labels; + std::vector annotations_language; // Length `count_label`. - std::vector mix_presentation_annotations; + std::vector localized_presentation_annotations; DecodedUleb128 num_sub_mixes; // Length `num_sub_mixes`. @@ -417,9 +418,10 @@ absl::Status MixPresentationGenerator::Generate( obu_args.mix_presentation_id = mix_presentation_metadata.mix_presentation_id(); - FillLanguageLabelsAndAnnotations( + FillAnnotationsLanguageAndAnnotations( mix_presentation_metadata, obu_args.count_label, - obu_args.language_labels, obu_args.mix_presentation_annotations); + obu_args.annotations_language, + obu_args.localized_presentation_annotations); FillNumSubMixes(mix_presentation_metadata, obu_args.num_sub_mixes, obu_args.sub_mixes); @@ -433,7 +435,7 @@ absl::Status MixPresentationGenerator::Generate( sub_mix_audio_element.audio_element_id = input_sub_mix_audio_element.audio_element_id(); - RETURN_IF_NOT_OK(FillMixPresentationElementAnnotations( + RETURN_IF_NOT_OK(FillLocalizedElementAnnotations( input_sub_mix_audio_element, sub_mix_audio_element)); RETURN_IF_NOT_OK( @@ -442,13 +444,13 @@ absl::Status MixPresentationGenerator::Generate( RETURN_IF_NOT_OK(FillMixConfig( input_sub_mix_audio_element.element_mix_config().mix_gain(), - sub_mix_audio_element.element_mix_config.mix_gain)); + sub_mix_audio_element.element_mix_gain)); sub_mix.audio_elements.push_back(sub_mix_audio_element); } RETURN_IF_NOT_OK( FillMixConfig(input_sub_mix.output_mix_config().output_mix_gain(), - sub_mix.output_mix_config.output_mix_gain)); + sub_mix.output_mix_gain)); RETURN_IF_NOT_OK(FillLayouts(input_sub_mix, sub_mix)); obu_args.sub_mixes.push_back(std::move(sub_mix)); @@ -457,8 +459,9 @@ absl::Status MixPresentationGenerator::Generate( mix_presentation_obus.emplace_back( GetHeaderFromMetadata(mix_presentation_metadata.obu_header()), obu_args.mix_presentation_id, obu_args.count_label, - obu_args.language_labels, obu_args.mix_presentation_annotations, - obu_args.num_sub_mixes, obu_args.sub_mixes); + obu_args.annotations_language, + obu_args.localized_presentation_annotations, obu_args.num_sub_mixes, + obu_args.sub_mixes); } return absl::OkStatus(); } 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 36243231..a48709c3 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 @@ -210,12 +210,11 @@ TEST_F(MixPresentationGeneratorTest, SupportsUtf8) { MixPresentationGenerator generator(mix_presentation_metadata_); ASSERT_THAT(generator.Generate(generated_obus_), IsOk()); - ASSERT_FALSE(generated_obus_.back().GetMixPresentationAnnotations().empty()); - EXPECT_EQ(generated_obus_.back() - .GetMixPresentationAnnotations()[0] - .mix_presentation_friendly_label, - kUtf8FourByteSequenceCode); + const auto generated_annotations = + generated_obus_.back().GetLocalizedPresentationAnnotations(); + ASSERT_FALSE(generated_annotations.empty()); + EXPECT_EQ(generated_annotations[0], kUtf8FourByteSequenceCode); } TEST_F(MixPresentationGeneratorTest, InvalidHeadphonesRenderingMode) { diff --git a/iamf/cli/testdata/test_000119.textproto b/iamf/cli/testdata/test_000119.textproto index 412caee0..2387b83f 100644 --- a/iamf/cli/testdata/test_000119.textproto +++ b/iamf/cli/testdata/test_000119.textproto @@ -75,12 +75,12 @@ arbitrary_obu_metadata: [ "\x33" # audio_element_id. "\x00" # headphones_rendering_mode (2), reserved (6). "\x00" # rendering_config_size. - # Begin ElementMixConfig. + # Begin ElementMixGain. "\x66" # parameter_id. "\x80\xf7\x02" # parameter_rate (leb128). "\x80" # param_definition_mode (1), reserved (7). "\x00\00" # default_mix_gain. - # Begin OutputMixConfig. + # Begin OutputMixGain. "\x66" # parameter_id. "\x80\xf7\x02" # parameter_rate (leb128). "\x80" # param_definition_mode (1), reserved (7). diff --git a/iamf/cli/testdata/test_000120.textproto b/iamf/cli/testdata/test_000120.textproto index a81a37fe..68c34cdc 100644 --- a/iamf/cli/testdata/test_000120.textproto +++ b/iamf/cli/testdata/test_000120.textproto @@ -73,12 +73,12 @@ arbitrary_obu_metadata: [ "\x33" # audio_element_id. "\x00" # headphones_rendering_mode (2), reserved (6). "\x00" # rendering_config_size. - # Begin ElementMixConfig. + # Begin ElementMixGain. "\x66" # parameter_id. "\x80\xf7\x02" # parameter_rate (leb128). "\x80" # param_definition_mode (1), reserved (7). "\x00\00" # default_mix_gain. - # Begin OutputMixConfig. + # Begin OutputMixGain. "\x66" # parameter_id. "\x80\xf7\x02" # parameter_rate (leb128). "\x80" # param_definition_mode (1), reserved (7). diff --git a/iamf/cli/testdata/test_000122.textproto b/iamf/cli/testdata/test_000122.textproto index f7274c28..f7b4b55d 100644 --- a/iamf/cli/testdata/test_000122.textproto +++ b/iamf/cli/testdata/test_000122.textproto @@ -76,12 +76,12 @@ arbitrary_obu_metadata: [ "\x33" # audio_element_id. "\x00" # headphones_rendering_mode (2), reserved (6). "\x00" # rendering_config_size. - # Begin ElementMixConfig. + # Begin ElementMixGain. "\x66" # parameter_id. "\x80\xf7\x02" # parameter_rate (leb128). "\x80" # param_definition_mode (1), reserved (7). "\x00\00" # default_mix_gain. - # Begin OutputMixConfig. + # Begin OutputMixGain. "\x66" # parameter_id. "\x80\xf7\x02" # parameter_rate (leb128). "\x80" # param_definition_mode (1), reserved (7). diff --git a/iamf/cli/testdata/test_000129.textproto b/iamf/cli/testdata/test_000129.textproto index 2a627090..4a761af9 100644 --- a/iamf/cli/testdata/test_000129.textproto +++ b/iamf/cli/testdata/test_000129.textproto @@ -80,12 +80,12 @@ arbitrary_obu_metadata: [ "\x33" # audio_element_id. "\x00" # headphones_rendering_mode (2), reserved (6). "\x00" # rendering_config_size. - # Begin ElementMixConfig. + # Begin ElementMixGain. "\x66" # parameter_id. "\x80\xf7\x02" # parameter_rate (leb128). "\x80" # param_definition_mode (1), reserved (7). "\x00\00" # default_mix_gain. - # Begin OutputMixConfig. + # Begin OutputMixGain. "\x66" # parameter_id. "\x80\xf7\x02" # parameter_rate (leb128). "\x80" # param_definition_mode (1), reserved (7). diff --git a/iamf/cli/testdata/test_000130.textproto b/iamf/cli/testdata/test_000130.textproto index 9b5fc272..07aed3a9 100644 --- a/iamf/cli/testdata/test_000130.textproto +++ b/iamf/cli/testdata/test_000130.textproto @@ -73,12 +73,12 @@ arbitrary_obu_metadata: [ "\x33" # audio_element_id. "\x00" # headphones_rendering_mode (2), reserved (6). "\x00" # rendering_config_size. - # Begin ElementMixConfig. + # Begin ElementMixGain. "\x66" # parameter_id. "\x80\xf7\x02" # parameter_rate (leb128). "\x80" # param_definition_mode (1), reserved (7). "\x00\00" # default_mix_gain. - # Begin OutputMixConfig. + # Begin OutputMixGain. "\x66" # parameter_id. "\x80\xf7\x02" # parameter_rate (leb128). "\x80" # param_definition_mode (1), reserved (7). diff --git a/iamf/cli/tests/cli_test_utils.cc b/iamf/cli/tests/cli_test_utils.cc index c33d5dd1..9a979edd 100644 --- a/iamf/cli/tests/cli_test_utils.cc +++ b/iamf/cli/tests/cli_test_utils.cc @@ -188,7 +188,7 @@ void AddMixPresentationObuWithAudioElementIds( std::vector sub_mixes = { {.num_audio_elements = static_cast(audio_element_ids.size()), - .output_mix_config = {common_mix_gain_param_definition}, + .output_mix_gain = common_mix_gain_param_definition, .num_layouts = 1, .layouts = { {.loudness_layout = @@ -204,14 +204,14 @@ void AddMixPresentationObuWithAudioElementIds( for (const auto& audio_element_id : audio_element_ids) { sub_mixes[0].audio_elements.push_back({ .audio_element_id = audio_element_id, - .mix_presentation_element_annotations = {}, + .localized_element_annotations = {}, .rendering_config = {.headphones_rendering_mode = RenderingConfig::kHeadphonesRenderingModeStereo, .reserved = 0, .rendering_config_extension_size = 0, .rendering_config_extension_bytes = {}}, - .element_mix_config = {common_mix_gain_param_definition}, + .element_mix_gain = common_mix_gain_param_definition, }); } diff --git a/iamf/cli/tests/cli_util_test.cc b/iamf/cli/tests/cli_util_test.cc index 093b8a8e..903bd2df 100644 --- a/iamf/cli/tests/cli_util_test.cc +++ b/iamf/cli/tests/cli_util_test.cc @@ -522,7 +522,7 @@ TEST(CollectAndValidateParamDefinitions, IdenticalMixGain) { // Initialize prerequisites. absl::flat_hash_map audio_elements = {}; - // Create a mix presentation OBU. It will have a `element_mix_config` and + // Create a mix presentation OBU. It will have a `element_mix_gain` and // `output_mix_gain` which common settings. std::list mix_presentation_obus; AddMixPresentationObuWithAudioElementIds( @@ -532,10 +532,8 @@ TEST(CollectAndValidateParamDefinitions, IdenticalMixGain) { ASSERT_EQ(mix_presentation_obus.back() .sub_mixes_[0] .audio_elements[0] - .element_mix_config.mix_gain, - mix_presentation_obus.back() - .sub_mixes_[0] - .output_mix_config.output_mix_gain); + .element_mix_gain, + mix_presentation_obus.back().sub_mixes_[0].output_mix_gain); absl::flat_hash_map result; EXPECT_THAT(CollectAndValidateParamDefinitions(audio_elements, @@ -550,21 +548,20 @@ TEST(CollectAndValidateParamDefinitions, // Initialize prerequisites. absl::flat_hash_map audio_elements = {}; - // Create a mix presentation OBU. It will have a `element_mix_config` and + // Create a mix presentation OBU. It will have a `element_mix_gain` and // `output_mix_gain` which common settings. std::list mix_presentation_obus; AddMixPresentationObuWithAudioElementIds( kMixPresentationId, {kAudioElementId}, kParameterId, kParameterRate, mix_presentation_obus); - auto& output_mix_gain = mix_presentation_obus.back() - .sub_mixes_[0] - .output_mix_config.output_mix_gain; + auto& output_mix_gain = + mix_presentation_obus.back().sub_mixes_[0].output_mix_gain; output_mix_gain.default_mix_gain_ = 1; // Assert that the new mix presentation OBU has different param definitions. ASSERT_NE(mix_presentation_obus.back() .sub_mixes_[0] .audio_elements[0] - .element_mix_config.mix_gain, + .element_mix_gain, output_mix_gain); absl::flat_hash_map result; diff --git a/iamf/cli/tests/profile_filter_test.cc b/iamf/cli/tests/profile_filter_test.cc index 0861c77d..3cd23473 100644 --- a/iamf/cli/tests/profile_filter_test.cc +++ b/iamf/cli/tests/profile_filter_test.cc @@ -438,28 +438,26 @@ void InitializeDescriptorObusWithTwoSubmixes( .loudness = { .info_type = 0, .integrated_loudness = 0, .digital_peak = 0}}; std::vector sub_mixes; - sub_mixes.push_back( - {.num_audio_elements = kNumAudioElementsPerSubmix, - .audio_elements = {{ - .audio_element_id = kFirstAudioElementId, - .mix_presentation_element_annotations = {}, - .rendering_config = kRenderingConfig, - .element_mix_config = {common_mix_gain_param_definition}, - }}, - .output_mix_config = {common_mix_gain_param_definition}, - .num_layouts = 1, - .layouts = {kStereoLayout}}); - sub_mixes.push_back( - {.num_audio_elements = kNumAudioElementsPerSubmix, - .audio_elements = {{ - .audio_element_id = kSecondAudioElementId, - .mix_presentation_element_annotations = {}, - .rendering_config = kRenderingConfig, - .element_mix_config = {common_mix_gain_param_definition}, - }}, - .output_mix_config = {common_mix_gain_param_definition}, - .num_layouts = 1, - .layouts = {kStereoLayout}}); + sub_mixes.push_back({.num_audio_elements = kNumAudioElementsPerSubmix, + .audio_elements = {{ + .audio_element_id = kFirstAudioElementId, + .localized_element_annotations = {}, + .rendering_config = kRenderingConfig, + .element_mix_gain = common_mix_gain_param_definition, + }}, + .output_mix_gain = common_mix_gain_param_definition, + .num_layouts = 1, + .layouts = {kStereoLayout}}); + sub_mixes.push_back({.num_audio_elements = kNumAudioElementsPerSubmix, + .audio_elements = {{ + .audio_element_id = kSecondAudioElementId, + .localized_element_annotations = {}, + .rendering_config = kRenderingConfig, + .element_mix_gain = common_mix_gain_param_definition, + }}, + .output_mix_gain = common_mix_gain_param_definition, + .num_layouts = 1, + .layouts = {kStereoLayout}}); mix_presentation_obus.push_back(MixPresentationObu( ObuHeader(), kFirstMixPresentationId, diff --git a/iamf/obu/mix_presentation.cc b/iamf/obu/mix_presentation.cc index 4ad4c966..845d87b9 100644 --- a/iamf/obu/mix_presentation.cc +++ b/iamf/obu/mix_presentation.cc @@ -66,10 +66,9 @@ absl::Status ValidateAndWriteSubMixAudioElement( const SubMixAudioElement& element, WriteBitBuffer& wb) { // Write the main portion of an `SubMixAudioElement`. RETURN_IF_NOT_OK(wb.WriteUleb128(element.audio_element_id)); - for (const auto& mix_presentation_element_annotation : - element.mix_presentation_element_annotations) { - RETURN_IF_NOT_OK(wb.WriteString( - mix_presentation_element_annotation.audio_element_friendly_label)); + for (const auto& localized_element_annotation : + element.localized_element_annotations) { + RETURN_IF_NOT_OK(wb.WriteString(localized_element_annotation)); } // Write out `rendering_config`. @@ -87,7 +86,7 @@ absl::Status ValidateAndWriteSubMixAudioElement( RETURN_IF_NOT_OK(wb.WriteUint8Vector( element.rendering_config.rendering_config_extension_bytes)); - RETURN_IF_NOT_OK(element.element_mix_config.mix_gain.ValidateAndWrite(wb)); + RETURN_IF_NOT_OK(element.element_mix_gain.ValidateAndWrite(wb)); return absl::OkStatus(); } @@ -176,8 +175,7 @@ absl::Status ValidateAndWriteSubMix(const MixPresentationSubMix& sub_mix, ValidateAndWriteSubMixAudioElement(sub_mix_audio_element, wb)); } - RETURN_IF_NOT_OK( - sub_mix.output_mix_config.output_mix_gain.ValidateAndWrite(wb)); + RETURN_IF_NOT_OK(sub_mix.output_mix_gain.ValidateAndWrite(wb)); RETURN_IF_NOT_OK(wb.WriteUleb128(sub_mix.num_layouts)); // Loop to write the `layouts` array. @@ -278,11 +276,9 @@ absl::Status SubMixAudioElement::ReadAndValidate(const int32_t& count_label, // Read the main portion of an `SubMixAudioElement`. RETURN_IF_NOT_OK(rb.ReadULeb128(audio_element_id)); for (int i = 0; i < count_label; ++i) { - MixPresentationElementAnnotations mix_presentation_element_annotation; - RETURN_IF_NOT_OK(rb.ReadString( - mix_presentation_element_annotation.audio_element_friendly_label)); - mix_presentation_element_annotations.push_back( - mix_presentation_element_annotation); + std::string localized_element_annotation; + RETURN_IF_NOT_OK(rb.ReadString(localized_element_annotation)); + localized_element_annotations.push_back(localized_element_annotation); } // Read `rendering_config`. @@ -301,7 +297,7 @@ absl::Status SubMixAudioElement::ReadAndValidate(const int32_t& count_label, rb.ReadUint8Vector(rendering_config.rendering_config_extension_size, rendering_config.rendering_config_extension_bytes)); - RETURN_IF_NOT_OK(element_mix_config.mix_gain.ReadAndValidate(rb)); + RETURN_IF_NOT_OK(element_mix_gain.ReadAndValidate(rb)); return absl::OkStatus(); } @@ -317,7 +313,7 @@ absl::Status MixPresentationSubMix::ReadAndValidate(const int32_t& count_label, audio_elements.push_back(sub_mix_audio_element); } - RETURN_IF_NOT_OK(output_mix_config.output_mix_gain.ReadAndValidate(rb)); + RETURN_IF_NOT_OK(output_mix_gain.ReadAndValidate(rb)); RETURN_IF_NOT_OK(rb.ReadULeb128(num_layouts)); for (int i = 0; i < num_layouts; ++i) { MixPresentationLayout mix_presentation_layout; @@ -416,21 +412,21 @@ absl::Status MixPresentationObu::ValidateAndWritePayload( RETURN_IF_NOT_OK(wb.WriteUleb128(count_label_)); RETURN_IF_NOT_OK(ValidateVectorSizeEqual( - "language_labels", language_labels_.size(), count_label_)); - RETURN_IF_NOT_OK(ValidateUnique(language_labels_.begin(), - language_labels_.end(), "Language labels")); + "language_labels", annotations_language_.size(), count_label_)); + RETURN_IF_NOT_OK(ValidateUnique(annotations_language_.begin(), + annotations_language_.end(), + "Language labels")); - for (const auto& language_label : language_labels_) { - RETURN_IF_NOT_OK(wb.WriteString(language_label)); + for (const auto& annotations_language : annotations_language_) { + RETURN_IF_NOT_OK(wb.WriteString(annotations_language)); } RETURN_IF_NOT_OK(ValidateVectorSizeEqual("mix presentation annotations", - mix_presentation_annotations_.size(), + annotations_language_.size(), count_label_)); - for (const auto& mix_presentation_annotation : - mix_presentation_annotations_) { - RETURN_IF_NOT_OK(wb.WriteString( - mix_presentation_annotation.mix_presentation_friendly_label)); + for (const auto& localized_presentation_annotation : + localized_presentation_annotations_) { + RETURN_IF_NOT_OK(wb.WriteString(localized_presentation_annotation)); } RETURN_IF_NOT_OK(wb.WriteUleb128(num_sub_mixes_)); @@ -460,18 +456,19 @@ absl::Status MixPresentationObu::ValidateAndReadPayload(ReadBitBuffer& rb) { RETURN_IF_NOT_OK(rb.ReadULeb128(count_label_)); for (int i = 0; i < count_label_; ++i) { - std::string language_label; - RETURN_IF_NOT_OK(rb.ReadString(language_label)); - language_labels_.push_back(language_label); + std::string annotations_language; + RETURN_IF_NOT_OK(rb.ReadString(annotations_language)); + annotations_language_.push_back(annotations_language); } - RETURN_IF_NOT_OK(ValidateUnique(language_labels_.begin(), - language_labels_.end(), "Language labels")); + RETURN_IF_NOT_OK(ValidateUnique(annotations_language_.begin(), + annotations_language_.end(), + "Annotation languages")); for (int i = 0; i < count_label_; ++i) { - MixPresentationAnnotations mix_presentation_annotation; - RETURN_IF_NOT_OK(rb.ReadString( - mix_presentation_annotation.mix_presentation_friendly_label)); - mix_presentation_annotations_.push_back(mix_presentation_annotation); + std::string localized_presentation_annotation; + RETURN_IF_NOT_OK(rb.ReadString(localized_presentation_annotation)); + localized_presentation_annotations_.push_back( + localized_presentation_annotation); } RETURN_IF_NOT_OK(rb.ReadULeb128(num_sub_mixes_)); @@ -504,15 +501,13 @@ void MixPresentationObu::PrintObu() const { LOG(INFO) << " count_label= " << count_label_; LOG(INFO) << " language_labels:"; for (int i = 0; i < count_label_; ++i) { - LOG(INFO) << " language_label[" << i << "]= \"" << language_labels_[i] - << "\""; + LOG(INFO) << " annotations_languages[" << i << "]= \"" + << annotations_language_[i] << "\""; } LOG(INFO) << " mix_presentation_annotations:"; for (int i = 0; i < count_label_; ++i) { - LOG(INFO) - << " mix_presentation_friendly_label[" << i << "]= \"" - << mix_presentation_annotations_[i].mix_presentation_friendly_label - << "\""; + LOG(INFO) << " localized_presentation_annotations[" << i << "]= \"" + << localized_presentation_annotations_[i] << "\""; } LOG(INFO) << " num_sub_mixes= " << num_sub_mixes_; @@ -526,12 +521,10 @@ void MixPresentationObu::PrintObu() const { const auto& audio_element = sub_mix.audio_elements[j]; LOG(INFO) << " // audio_elements[" << j << "]:"; LOG(INFO) << " audio_element_id= " << audio_element.audio_element_id; - LOG(INFO) << " mix_presentation_element_annotations:"; + LOG(INFO) << " localized_presentation_annotations:"; for (int k = 0; k < count_label_; ++k) { - LOG(INFO) << " audio_element_friendly_label= \"" - << audio_element.mix_presentation_element_annotations[k] - .audio_element_friendly_label - << "\""; + LOG(INFO) << " localized_element_annotations= \"" + << audio_element.localized_element_annotations[k] << "\""; } LOG(INFO) << " rendering_config:"; LOG(INFO) << " headphones_rendering_mode= " @@ -543,17 +536,12 @@ void MixPresentationObu::PrintObu() const { << " rendering_config_extension_size= " << audio_element.rendering_config.rendering_config_extension_size; LOG(INFO) << " rendering_config_extension_bytes omitted."; - LOG(INFO) << " element_mix_config:"; - LOG(INFO) << " mix_gain:"; - audio_element.element_mix_config.mix_gain.Print(); + LOG(INFO) << " element_mix_gain:"; + audio_element.element_mix_gain.Print(); } - // `output_mix_config`. - { - LOG(INFO) << " output_mix_config:"; - LOG(INFO) << " output_mix_gain:"; - sub_mix.output_mix_config.output_mix_gain.Print(); - } + LOG(INFO) << " output_mix_gain:"; + sub_mix.output_mix_gain.Print(); LOG(INFO) << " num_layouts= " << sub_mix.num_layouts; diff --git a/iamf/obu/mix_presentation.h b/iamf/obu/mix_presentation.h index 34577cd6..4b9b0268 100644 --- a/iamf/obu/mix_presentation.h +++ b/iamf/obu/mix_presentation.h @@ -29,15 +29,6 @@ namespace iamf_tools { -/*!\brief A human-friendly label to describe the audio element in a sub-mix. */ -struct MixPresentationElementAnnotations { - friend bool operator==(const MixPresentationElementAnnotations& lhs, - const MixPresentationElementAnnotations& rhs) = - default; - - std::string audio_element_friendly_label; -}; - struct RenderingConfig { /*!\brief A 2-bit enum describing how to render the content to headphones. */ enum HeadphonesRenderingMode : uint8_t { @@ -56,14 +47,6 @@ struct RenderingConfig { std::vector rendering_config_extension_bytes; }; -/*!\brief The gain value to be applied to the rendered audio element signal. */ -struct ElementMixConfig { - friend bool operator==(const ElementMixConfig& lhs, - const ElementMixConfig& rhs) = default; - - MixGainParamDefinition mix_gain; -}; - /*!\brief One of the audio elements within a sub-mix. */ struct SubMixAudioElement { friend bool operator==(const SubMixAudioElement& lhs, @@ -80,10 +63,10 @@ struct SubMixAudioElement { // The ID of the associated Audio Element OBU. DecodedUleb128 audio_element_id; // Length `count_labels`. - std::vector - mix_presentation_element_annotations; + std::vector localized_element_annotations; RenderingConfig rendering_config; - ElementMixConfig element_mix_config; + // The gain value to be applied to the rendered audio element signal. + MixGainParamDefinition element_mix_gain; }; struct AnchoredLoudnessElement { @@ -296,31 +279,6 @@ struct MixPresentationLayout { LoudnessInfo loudness; }; -/*!\brief Informational metadata about a Mix Presentation OBU. - * - * The informational metadata that an IA parser should refer to when - * selecting the mix presentation to use. May be used by the playback system to - * display information to the user, but is not used in the rendering or mixing - * process to generate the final output audio signal. - */ -struct MixPresentationAnnotations { - friend bool operator==(const MixPresentationAnnotations& lhs, - const MixPresentationAnnotations& rhs) = default; - - std::string mix_presentation_friendly_label; -}; - -/*!\brief Metadata required for post-processing the mixed audio signal. - * - * The gain value to be applied in post-processing the mixed audio signal to - * generate the audio signal for playback. - */ -struct OutputMixConfig { - friend bool operator==(const OutputMixConfig& lhs, - const OutputMixConfig& rhs) = default; - MixGainParamDefinition output_mix_gain; -}; - /*!\brief One of the sub-mixes within a Mix Presentation Obu. */ struct MixPresentationSubMix { friend bool operator==(const MixPresentationSubMix& lhs, @@ -338,7 +296,9 @@ struct MixPresentationSubMix { // Length `num_audio_elements`. std::vector audio_elements; - OutputMixConfig output_mix_config; + // The gain value to be applied in post-processing the mixed audio signal to + // generate the audio signal for playback. + MixGainParamDefinition output_mix_gain; DecodedUleb128 num_layouts; // Length `num_layouts`. @@ -378,27 +338,26 @@ class MixPresentationObu : public ObuBase { * \param header `ObuHeader` of the OBU. * \param mix_presentation_id `mix_presentation_id` in the OBU. * \param count_label `count_label` in the OBU. - * \param language_labels Vector representing all of the `language_label`s in - * the OBU. - * \param mix_presentation_annotations Vector representing all of the - * `mix_presentation_annotations`s in the OBU. + * \param annotations_language Vector representing all of the + * `annotations_language`s in the OBU. + * \param localized_presentation_annotations Vector representing all of the + * `localized_presentation_annotations`s in the OBU. * \param num_sub_mixes `num_sub_mixes` in the OBU. * \param sub_mixes Vector representing all of the sub mixes in the OBU. */ - MixPresentationObu(const ObuHeader& header, - DecodedUleb128 mix_presentation_id, - DecodedUleb128 count_label, - const std::vector& language_labels, - const std::vector& - mix_presentation_annotations, - DecodedUleb128 num_sub_mixes, - std::vector& sub_mixes) + MixPresentationObu( + const ObuHeader& header, DecodedUleb128 mix_presentation_id, + DecodedUleb128 count_label, + const std::vector& annotations_language, + const std::vector& localized_presentation_annotations, + DecodedUleb128 num_sub_mixes, + std::vector& sub_mixes) : ObuBase(header, kObuIaMixPresentation), sub_mixes_(std::move(sub_mixes)), mix_presentation_id_(mix_presentation_id), count_label_(count_label), - language_labels_(language_labels), - mix_presentation_annotations_(mix_presentation_annotations), + annotations_language_(annotations_language), + localized_presentation_annotations_(localized_presentation_annotations), num_sub_mixes_(num_sub_mixes) {} /*!\brief Creates a `MixPresentationObu` from a `ReadBitBuffer`. @@ -432,9 +391,8 @@ class MixPresentationObu : public ObuBase { DecodedUleb128 GetMixPresentationId() const { return mix_presentation_id_; } - std::vector GetMixPresentationAnnotations() - const { - return mix_presentation_annotations_; + std::vector GetLocalizedPresentationAnnotations() const { + return localized_presentation_annotations_; } DecodedUleb128 GetNumSubMixes() const { return num_sub_mixes_; } @@ -445,9 +403,9 @@ class MixPresentationObu : public ObuBase { DecodedUleb128 mix_presentation_id_; DecodedUleb128 count_label_; // Length `count_label`. - std::vector language_labels_; + std::vector annotations_language_; // Length `count_label`. - std::vector mix_presentation_annotations_; + std::vector localized_presentation_annotations_; DecodedUleb128 num_sub_mixes_; @@ -457,8 +415,8 @@ class MixPresentationObu : public ObuBase { sub_mixes_({}), mix_presentation_id_(DecodedUleb128()), count_label_(DecodedUleb128()), - language_labels_({}), - mix_presentation_annotations_({}), + annotations_language_({}), + localized_presentation_annotations_({}), num_sub_mixes_(DecodedUleb128()) {} /*!\brief Writes the OBU payload to the buffer. * diff --git a/iamf/obu/tests/mix_presentation_test.cc b/iamf/obu/tests/mix_presentation_test.cc index c39ccabe..cb2fd2d7 100644 --- a/iamf/obu/tests/mix_presentation_test.cc +++ b/iamf/obu/tests/mix_presentation_test.cc @@ -74,14 +74,14 @@ class MixPresentationObuTest : public ObuTestBase, public testing::Test { }), mix_presentation_id_(10), count_label_(1), - language_labels_({{"en-us"}}), - mix_presentation_annotations_({{"Mix 1"}}), + annotations_language_({"en-us"}), + localized_presentation_annotations_({"Mix 1"}), num_sub_mixes_(1), sub_mixes_( {{.num_audio_elements = 1, .audio_elements = {{ .audio_element_id = 11, - .mix_presentation_element_annotations = {{"Submix 1"}}, + .localized_element_annotations = {"Submix 1"}, .rendering_config = {.headphones_rendering_mode = RenderingConfig::kHeadphonesRenderingModeStereo, @@ -111,8 +111,7 @@ class MixPresentationObuTest : public ObuTestBase, public testing::Test { element_mix_gain.param_definition_mode_ = true; element_mix_gain.reserved_ = 0; element_mix_gain.default_mix_gain_ = 14; - sub_mixes_[0].audio_elements[0].element_mix_config.mix_gain = - element_mix_gain; + sub_mixes_[0].audio_elements[0].element_mix_gain = element_mix_gain; MixGainParamDefinition output_mix_gain; output_mix_gain.parameter_id_ = 15; @@ -120,7 +119,7 @@ class MixPresentationObuTest : public ObuTestBase, public testing::Test { output_mix_gain.param_definition_mode_ = true; output_mix_gain.reserved_ = 0; output_mix_gain.default_mix_gain_ = 17; - sub_mixes_[0].output_mix_config.output_mix_gain = output_mix_gain; + sub_mixes_[0].output_mix_gain = output_mix_gain; } ~MixPresentationObuTest() override = default; @@ -136,9 +135,9 @@ class MixPresentationObuTest : public ObuTestBase, public testing::Test { DecodedUleb128 mix_presentation_id_; DecodedUleb128 count_label_; - std::vector language_labels_; + std::vector annotations_language_; // Length `count_label`. - std::vector mix_presentation_annotations_; + std::vector localized_presentation_annotations_; DecodedUleb128 num_sub_mixes_; // Length `num_sub_mixes`. @@ -163,28 +162,27 @@ class MixPresentationObuTest : public ObuTestBase, public testing::Test { const auto& audio_element_args = sub_mix_args.element_mix_gain_subblocks[j]; - audio_element.element_mix_config.mix_gain.InitializeSubblockDurations( + audio_element.element_mix_gain.InitializeSubblockDurations( static_cast(audio_element_args.size())); ASSERT_EQ(audio_element_args.size(), - audio_element.element_mix_config.mix_gain.GetNumSubblocks()); + audio_element.element_mix_gain.GetNumSubblocks()); for (int k = 0; k < audio_element_args.size(); ++k) { - EXPECT_THAT( - audio_element.element_mix_config.mix_gain.SetSubblockDuration( - k, audio_element_args[k]), - IsOk()); + EXPECT_THAT(audio_element.element_mix_gain.SetSubblockDuration( + k, audio_element_args[k]), + IsOk()); } } // Create and initialize memory for the subblock durations within the // output mix config. - sub_mix.output_mix_config.output_mix_gain.InitializeSubblockDurations( + sub_mix.output_mix_gain.InitializeSubblockDurations( static_cast( sub_mix_args.output_mix_gain_subblocks.size())); ASSERT_EQ(sub_mix_args.output_mix_gain_subblocks.size(), - sub_mix.output_mix_config.output_mix_gain.GetNumSubblocks()); + sub_mix.output_mix_gain.GetNumSubblocks()); for (int j = 0; j < sub_mix_args.output_mix_gain_subblocks.size(); ++j) { - EXPECT_THAT(sub_mix.output_mix_config.output_mix_gain.SetSubblockDuration( + EXPECT_THAT(sub_mix.output_mix_gain.SetSubblockDuration( j, sub_mix_args.output_mix_gain_subblocks[j]), IsOk()); } @@ -200,8 +198,8 @@ class MixPresentationObuTest : public ObuTestBase, public testing::Test { // Construct and transfer ownership of the memory to the OBU. obu_ = std::make_unique( - header_, mix_presentation_id_, count_label_, language_labels_, - mix_presentation_annotations_, num_sub_mixes_, sub_mixes_); + header_, mix_presentation_id_, count_label_, annotations_language_, + localized_presentation_annotations_, num_sub_mixes_, sub_mixes_); } }; @@ -441,17 +439,13 @@ TEST_F(MixPresentationObuTest, NonMinimalLebGeneratorAffectsAllLeb128s) { // `rendering_config_extension_size` is affected by the `LebGenerator`. 0x80 | 2, 0x00, 'e', 'x', // End RenderingConfig. - // `element_mix_config.mix_gain.parameter_id` is affected by the - // `LebGenerator`. + // `element_mix_gain.parameter_id` is affected by the `LebGenerator`. 0x80 | 12, 0x00, - // `element_mix_config.mix_gain.parameter_rate` is affected by the - // `LebGenerator`. + // `element_mix_gain.parameter_rate` is affected by the `LebGenerator`. 0x80 | 13, 0x00, 0x80, 0, 14, - // `output_mix_config.mix_gain.parameter_id` is affected by the - // `LebGenerator`. + // `output_mix_gain.parameter_id` is affected by the `LebGenerator`. 0x80 | 15, 0x00, - // `output_mix_config.mix_gain.parameter_rate` is affected by the - // `LebGenerator`. + // `output_mix_gain.parameter_rate` is affected by the `LebGenerator`. 0x80 | 16, 0x00, 0x80, 0, 17, // `num_layouts` is affected by the `LebGenerator`. 0x80 | 1, 0x00, @@ -496,8 +490,7 @@ TEST_F(MixPresentationObuTest, ValidateAndWriteFailsWithIllegalIamfStringOver128Bytes) { // Create a string that has no null terminator in the first 128 bytes. const std::string kIllegalIamfString(kIamfMaxStringSize, 'a'); - mix_presentation_annotations_[0].mix_presentation_friendly_label = - kIllegalIamfString; + localized_presentation_annotations_[0] = kIllegalIamfString; InitExpectOk(); WriteBitBuffer unused_wb(0); @@ -506,10 +499,10 @@ TEST_F(MixPresentationObuTest, TEST_F(MixPresentationObuTest, MultipleLabels) { count_label_ = 2; - language_labels_ = {{"en-us"}, {"en-gb"}}; - mix_presentation_annotations_ = {{"Mix 1"}, {"Mix 1"}}; - sub_mixes_[0].audio_elements[0].mix_presentation_element_annotations = { - {{"Submix 1"}, {"GB Submix 1"}}}; + annotations_language_ = {"en-us", "en-gb"}; + localized_presentation_annotations_ = {"Mix 1", "Mix 1"}; + sub_mixes_[0].audio_elements[0].localized_element_annotations = { + "Submix 1", "GB Submix 1"}; expected_header_ = {kObuIaMixPresentation << 3, 71}; expected_payload_ = { @@ -534,15 +527,14 @@ TEST_F(MixPresentationObuTest, MultipleLabels) { } TEST_F(MixPresentationObuTest, - ValidateAndWriteSucceedsWhenLanguageLabelsAreUnique) { - const std::vector kLanguageLabelsWithDifferentRegions = { + ValidateAndWriteSucceedsWhenAnnotationsLanguagesAreUnique) { + const std::vector kAnnotationsLanaguesWithDifferentRegions = { {"en-us"}, {"en-gb"}}; - language_labels_ = kLanguageLabelsWithDifferentRegions; + annotations_language_ = kAnnotationsLanaguesWithDifferentRegions; count_label_ = 2; - mix_presentation_annotations_ = {{"0"}, {"1"}}; - sub_mixes_[0].audio_elements[0].mix_presentation_element_annotations = { - {{"0"}, {"1"}}}; + localized_presentation_annotations_ = {"0", "1"}; + sub_mixes_[0].audio_elements[0].localized_element_annotations = {"0", "1"}; InitExpectOk(); WriteBitBuffer unused_wb(0); @@ -550,16 +542,15 @@ TEST_F(MixPresentationObuTest, } TEST_F(MixPresentationObuTest, - ValidateAndWriteFailsWhenLanguageLabelsAreNotUnique) { - const std::vector kInvalidLanguageLabelsWithDuplicate = { + ValidateAndWriteFailsWhenAnnotationsLanguagesAreNotUnique) { + const std::vector kInvalidAnnotationsLanguagesWithDuplicate = { {"en-us"}, {"en-us"}}; - language_labels_ = kInvalidLanguageLabelsWithDuplicate; + annotations_language_ = kInvalidAnnotationsLanguagesWithDuplicate; // Configure plausible values for the related fields. count_label_ = 2; - mix_presentation_annotations_ = {{"0"}, {"1"}}; - sub_mixes_[0].audio_elements[0].mix_presentation_element_annotations = { - {{"0"}, {"1"}}}; + localized_presentation_annotations_ = {"0", "1"}; + sub_mixes_[0].audio_elements[0].localized_element_annotations = {"0", "1"}; InitExpectOk(); WriteBitBuffer unused_wb(0); @@ -654,7 +645,7 @@ TEST_F(MixPresentationObuTest, MultipleSubmixesAndLayouts) { {.num_audio_elements = 1, .audio_elements = {{ .audio_element_id = 21, - .mix_presentation_element_annotations = {{"Submix 2"}}, + .localized_element_annotations = {"Submix 2"}, .rendering_config = {.headphones_rendering_mode = RenderingConfig::kHeadphonesRenderingModeBinaural, @@ -701,8 +692,7 @@ TEST_F(MixPresentationObuTest, MultipleSubmixesAndLayouts) { element_mix_gain.param_definition_mode_ = true; element_mix_gain.reserved_ = 0; element_mix_gain.default_mix_gain_ = 24; - sub_mixes_.back().audio_elements[0].element_mix_config.mix_gain = - element_mix_gain; + sub_mixes_.back().audio_elements[0].element_mix_gain = element_mix_gain; MixGainParamDefinition output_mix_gain; output_mix_gain.parameter_id_ = 25; @@ -710,7 +700,7 @@ TEST_F(MixPresentationObuTest, MultipleSubmixesAndLayouts) { output_mix_gain.param_definition_mode_ = true; output_mix_gain.reserved_ = 0; output_mix_gain.default_mix_gain_ = 27; - sub_mixes_.back().output_mix_config.output_mix_gain = output_mix_gain; + sub_mixes_.back().output_mix_gain = output_mix_gain; dynamic_sub_mix_args_.push_back( {.element_mix_gain_subblocks = {{}}, .output_mix_gain_subblocks = {}}); @@ -967,9 +957,7 @@ TEST(CreateFromBufferTest, OneSubMix) { EXPECT_THAT(obu, IsOk()); EXPECT_EQ(obu->header_.obu_type, kObuIaMixPresentation); EXPECT_EQ(obu->GetMixPresentationId(), 10); - EXPECT_EQ( - obu->GetMixPresentationAnnotations()[0].mix_presentation_friendly_label, - "Mix 1"); + EXPECT_EQ(obu->GetLocalizedPresentationAnnotations()[0], "Mix 1"); EXPECT_EQ(obu->GetNumSubMixes(), 1); } @@ -983,7 +971,7 @@ TEST(ReadSubMixAudioElementTest, AllFieldsPresent) { // Start RenderingConfig. RenderingConfig::kHeadphonesRenderingModeBinaural << 6, 0, // End RenderingConfig. - // Start ElementMixConfig + // Start ElementMixGain // Parameter ID. 0x00, // Parameter Rate. @@ -992,7 +980,7 @@ TEST(ReadSubMixAudioElementTest, AllFieldsPresent) { 0x80, // Default Mix Gain. 0, 4 - // End ElementMixConfig + // End ElementMixGain }; ReadBitBuffer buffer(1024, &source); SubMixAudioElement audio_element; @@ -1001,20 +989,16 @@ TEST(ReadSubMixAudioElementTest, AllFieldsPresent) { // Set up expected values. SubMixAudioElement expected_submix_audio_element = SubMixAudioElement{ .audio_element_id = 11, - .mix_presentation_element_annotations = - {MixPresentationElementAnnotations( - {.audio_element_friendly_label = "Submix 1"})}, + .localized_element_annotations = {"Submix 1"}, .rendering_config = {.headphones_rendering_mode = RenderingConfig::kHeadphonesRenderingModeBinaural}, - .element_mix_config = {.mix_gain = MixGainParamDefinition()}}; - expected_submix_audio_element.element_mix_config.mix_gain.parameter_id_ = 0; - expected_submix_audio_element.element_mix_config.mix_gain.parameter_rate_ = 1; - expected_submix_audio_element.element_mix_config.mix_gain - .param_definition_mode_ = true; - expected_submix_audio_element.element_mix_config.mix_gain.reserved_ = 0; - expected_submix_audio_element.element_mix_config.mix_gain.default_mix_gain_ = - 4; + .element_mix_gain = MixGainParamDefinition()}; + expected_submix_audio_element.element_mix_gain.parameter_id_ = 0; + expected_submix_audio_element.element_mix_gain.parameter_rate_ = 1; + expected_submix_audio_element.element_mix_gain.param_definition_mode_ = true; + expected_submix_audio_element.element_mix_gain.reserved_ = 0; + expected_submix_audio_element.element_mix_gain.default_mix_gain_ = 4; EXPECT_EQ(audio_element, expected_submix_audio_element); }