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 a48709c3..7b092ffd 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 @@ -173,6 +173,106 @@ TEST(Generate, CopiesReservedHeadphonesRenderingMode3) { kExpectedHeadphonesRenderingMode3); } +TEST(Generate, CopiesNoAnnotations) { + MixPresentationObuMetadatas mix_presentation_metadata; + FillMixPresentationMetadata(mix_presentation_metadata.Add()); + mix_presentation_metadata.at(0).set_count_label(0); + mix_presentation_metadata.at(0).clear_language_labels(); + mix_presentation_metadata.at(0).clear_mix_presentation_annotations_array(); + mix_presentation_metadata.at(0) + .mutable_sub_mixes(0) + ->mutable_audio_elements(0) + ->clear_mix_presentation_element_annotations_array(); + + MixPresentationGenerator generator(mix_presentation_metadata); + + std::list generated_obus; + EXPECT_THAT(generator.Generate(generated_obus), IsOk()); + + const auto& first_obu = generated_obus.front(); + EXPECT_TRUE(first_obu.GetAnnotationsLanguage().empty()); + EXPECT_TRUE(first_obu.GetLocalizedPresentationAnnotations().empty()); + EXPECT_TRUE(first_obu.sub_mixes_[0] + .audio_elements[0] + .localized_element_annotations.empty()); +} + +TEST(Generate, CopiesAnnotations) { + constexpr int kCountLabel = 2; + const std::vector kAnnotationsLanguage = {"en-us", "en-gb"}; + const std::vector kLocalizedPresentationAnnotations = { + "US Label", "GB Label"}; + const std::vector kAudioElementLocalizedElementAnnotations = { + "US AE Label", "GB AE Label"}; + MixPresentationObuMetadatas mix_presentation_metadata; + FillMixPresentationMetadata(mix_presentation_metadata.Add()); + auto& mix_presentation = mix_presentation_metadata.at(0); + mix_presentation.set_count_label(kCountLabel); + mix_presentation.mutable_language_labels()->Add(kAnnotationsLanguage.begin(), + kAnnotationsLanguage.end()); + *mix_presentation.mutable_mix_presentation_annotations_array() + ->Add() + ->mutable_mix_presentation_friendly_label() = + kLocalizedPresentationAnnotations[0]; + *mix_presentation.mutable_mix_presentation_annotations_array() + ->Add() + ->mutable_mix_presentation_friendly_label() = + kLocalizedPresentationAnnotations[1]; + auto* first_element_annotations_array = + mix_presentation.mutable_sub_mixes(0) + ->mutable_audio_elements(0) + ->mutable_mix_presentation_element_annotations_array(); + first_element_annotations_array->Add()->set_audio_element_friendly_label( + kAudioElementLocalizedElementAnnotations[0]); + first_element_annotations_array->Add()->set_audio_element_friendly_label( + kAudioElementLocalizedElementAnnotations[1]); + + MixPresentationGenerator generator(mix_presentation_metadata); + + std::list generated_obus; + EXPECT_THAT(generator.Generate(generated_obus), IsOk()); + + const auto& first_obu = generated_obus.front(); + EXPECT_EQ(first_obu.GetAnnotationsLanguage(), kAnnotationsLanguage); + EXPECT_EQ(first_obu.GetLocalizedPresentationAnnotations(), + kLocalizedPresentationAnnotations); + EXPECT_EQ( + first_obu.sub_mixes_[0].audio_elements[0].localized_element_annotations, + kAudioElementLocalizedElementAnnotations); +} + +TEST(Generate, ObeysInconsistentNumberOfLabels) { + const std::vector kAnnotationsLanguage = {"Language 1", + "Language 2"}; + const std::vector kOnlyOneLocalizedPresentationAnnotation = { + "Localized annotation 1"}; + const std::vector kNoAudioElementLocalizedElementAnnotations = + {}; + MixPresentationObuMetadatas mix_presentation_metadata; + FillMixPresentationMetadata(mix_presentation_metadata.Add()); + auto& mix_presentation = mix_presentation_metadata.at(0); + mix_presentation.set_count_label(2); + mix_presentation.mutable_language_labels()->Add(kAnnotationsLanguage.begin(), + kAnnotationsLanguage.end()); + *mix_presentation.mutable_mix_presentation_annotations_array() + ->Add() + ->mutable_mix_presentation_friendly_label() = + kOnlyOneLocalizedPresentationAnnotation[0]; + + MixPresentationGenerator generator(mix_presentation_metadata); + + std::list generated_obus; + EXPECT_THAT(generator.Generate(generated_obus), IsOk()); + + const auto& first_obu = generated_obus.front(); + EXPECT_EQ(first_obu.GetAnnotationsLanguage(), kAnnotationsLanguage); + EXPECT_EQ(first_obu.GetLocalizedPresentationAnnotations(), + kOnlyOneLocalizedPresentationAnnotation); + EXPECT_EQ( + first_obu.sub_mixes_[0].audio_elements[0].localized_element_annotations, + kNoAudioElementLocalizedElementAnnotations); +} + class MixPresentationGeneratorTest : public ::testing::Test { public: void SetUp() override { diff --git a/iamf/obu/mix_presentation.h b/iamf/obu/mix_presentation.h index 3f979af9..43ea997b 100644 --- a/iamf/obu/mix_presentation.h +++ b/iamf/obu/mix_presentation.h @@ -369,7 +369,7 @@ class MixPresentationObu : public ObuBase { * \param header `ObuHeader` of the OBU. * \param rb `ReadBitBuffer` where the `MixPresentationObu` data is stored. * Data read from the buffer is consumed. - * \return an `MixPresentationObu` on success. A specific status on failure. + * \return A `MixPresentationObu` on success. A specific status on failure. */ static absl::StatusOr CreateFromBuffer( const ObuHeader& header, ReadBitBuffer& rb); @@ -391,6 +391,18 @@ class MixPresentationObu : public ObuBase { DecodedUleb128 GetMixPresentationId() const { return mix_presentation_id_; } + /*!\brief Gets a copy of the `annotations_language`. + * + * \return A copy of the `annotations_language` member variable. + */ + std::vector GetAnnotationsLanguage() const { + return annotations_language_; + } + + /*!\brief Gets a copy of the `localized_presentation_annotations`. + * + * \return A copy of the `localized_presentation_annotations` member variable. + */ std::vector GetLocalizedPresentationAnnotations() const { return localized_presentation_annotations_; } diff --git a/iamf/obu/tests/mix_presentation_test.cc b/iamf/obu/tests/mix_presentation_test.cc index 367703dd..96779e63 100644 --- a/iamf/obu/tests/mix_presentation_test.cc +++ b/iamf/obu/tests/mix_presentation_test.cc @@ -954,6 +954,10 @@ TEST(CreateFromBufferTest, RejectNoSubMix) { } TEST(CreateFromBufferTest, OneSubMix) { + const std::vector kAnnotationsLanguage = {"en-us"}; + const std::vector kLocalizedPresentationAnnotations = {"Mix 1"}; + const std::vector kAudioElementLocalizedElementAnnotations = { + "Submix 1"}; std::vector source = { // Start Mix OBU. // mix_presentation_id @@ -992,8 +996,13 @@ TEST(CreateFromBufferTest, OneSubMix) { EXPECT_THAT(obu, IsOk()); EXPECT_EQ(obu->header_.obu_type, kObuIaMixPresentation); EXPECT_EQ(obu->GetMixPresentationId(), 10); - EXPECT_EQ(obu->GetLocalizedPresentationAnnotations()[0], "Mix 1"); + EXPECT_EQ(obu->GetAnnotationsLanguage(), kAnnotationsLanguage); + EXPECT_EQ(obu->GetLocalizedPresentationAnnotations(), + kLocalizedPresentationAnnotations); EXPECT_EQ(obu->GetNumSubMixes(), 1); + ASSERT_FALSE(obu->sub_mixes_[0].audio_elements.empty()); + EXPECT_EQ(obu->sub_mixes_[0].audio_elements[0].localized_element_annotations, + kAudioElementLocalizedElementAnnotations); } TEST(ReadSubMixAudioElementTest, AllFieldsPresent) {