Skip to content

Commit

Permalink
Increase coverage regarding mix presentation labels.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 662908429
  • Loading branch information
jwcullen committed Aug 14, 2024
1 parent 469f580 commit b28461c
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 2 deletions.
100 changes: 100 additions & 0 deletions iamf/cli/proto_to_obu/tests/mix_presentation_generator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<MixPresentationObu> 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<std::string> kAnnotationsLanguage = {"en-us", "en-gb"};
const std::vector<std::string> kLocalizedPresentationAnnotations = {
"US Label", "GB Label"};
const std::vector<std::string> 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<MixPresentationObu> 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<std::string> kAnnotationsLanguage = {"Language 1",
"Language 2"};
const std::vector<std::string> kOnlyOneLocalizedPresentationAnnotation = {
"Localized annotation 1"};
const std::vector<std::string> 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<MixPresentationObu> 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 {
Expand Down
14 changes: 13 additions & 1 deletion iamf/obu/mix_presentation.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<MixPresentationObu> CreateFromBuffer(
const ObuHeader& header, ReadBitBuffer& rb);
Expand All @@ -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<std::string> 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<std::string> GetLocalizedPresentationAnnotations() const {
return localized_presentation_annotations_;
}
Expand Down
11 changes: 10 additions & 1 deletion iamf/obu/tests/mix_presentation_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,10 @@ TEST(CreateFromBufferTest, RejectNoSubMix) {
}

TEST(CreateFromBufferTest, OneSubMix) {
const std::vector<std::string> kAnnotationsLanguage = {"en-us"};
const std::vector<std::string> kLocalizedPresentationAnnotations = {"Mix 1"};
const std::vector<std::string> kAudioElementLocalizedElementAnnotations = {
"Submix 1"};
std::vector<uint8_t> source = {
// Start Mix OBU.
// mix_presentation_id
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit b28461c

Please sign in to comment.