Skip to content

Commit

Permalink
[Style] Update names and nesting of Mix Presentation fields for consi…
Browse files Browse the repository at this point in the history
…stency with the spec.

  - In general we prefer names in `iamf/common/obu` mimic the spec as much as possible.
  - In AOMediaCodec/iamf#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
  • Loading branch information
jwcullen committed Jul 17, 2024
1 parent da28873 commit 733262c
Show file tree
Hide file tree
Showing 14 changed files with 185 additions and 259 deletions.
7 changes: 3 additions & 4 deletions iamf/cli/cli_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down
43 changes: 23 additions & 20 deletions iamf/cli/proto_to_obu/mix_presentation_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>& language_labels,
std::vector<MixPresentationAnnotations>& mix_presentation_annotations) {
DecodedUleb128& count_label, std::vector<std::string>& annotations_language,
std::vector<std::string>& 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());
}
}

Expand All @@ -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();
Expand Down Expand Up @@ -405,9 +406,9 @@ absl::Status MixPresentationGenerator::Generate(
struct {
DecodedUleb128 mix_presentation_id;
DecodedUleb128 count_label;
std::vector<std::string> language_labels;
std::vector<std::string> annotations_language;
// Length `count_label`.
std::vector<MixPresentationAnnotations> mix_presentation_annotations;
std::vector<std::string> localized_presentation_annotations;

DecodedUleb128 num_sub_mixes;
// Length `num_sub_mixes`.
Expand All @@ -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);
Expand All @@ -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(
Expand All @@ -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));
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions iamf/cli/testdata/test_000119.textproto
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
4 changes: 2 additions & 2 deletions iamf/cli/testdata/test_000120.textproto
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
4 changes: 2 additions & 2 deletions iamf/cli/testdata/test_000122.textproto
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
4 changes: 2 additions & 2 deletions iamf/cli/testdata/test_000129.textproto
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
4 changes: 2 additions & 2 deletions iamf/cli/testdata/test_000130.textproto
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
6 changes: 3 additions & 3 deletions iamf/cli/tests/cli_test_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ void AddMixPresentationObuWithAudioElementIds(
std::vector<MixPresentationSubMix> sub_mixes = {
{.num_audio_elements =
static_cast<DecodedUleb128>(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 =
Expand All @@ -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,
});
}

Expand Down
17 changes: 7 additions & 10 deletions iamf/cli/tests/cli_util_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ TEST(CollectAndValidateParamDefinitions, IdenticalMixGain) {
// Initialize prerequisites.
absl::flat_hash_map<DecodedUleb128, AudioElementWithData> 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<MixPresentationObu> mix_presentation_obus;
AddMixPresentationObuWithAudioElementIds(
Expand All @@ -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<DecodedUleb128, const ParamDefinition*> result;
EXPECT_THAT(CollectAndValidateParamDefinitions(audio_elements,
Expand All @@ -550,21 +548,20 @@ TEST(CollectAndValidateParamDefinitions,
// Initialize prerequisites.
absl::flat_hash_map<DecodedUleb128, AudioElementWithData> 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<MixPresentationObu> 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<DecodedUleb128, const ParamDefinition*> result;
Expand Down
42 changes: 20 additions & 22 deletions iamf/cli/tests/profile_filter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -438,28 +438,26 @@ void InitializeDescriptorObusWithTwoSubmixes(
.loudness = {
.info_type = 0, .integrated_loudness = 0, .digital_peak = 0}};
std::vector<MixPresentationSubMix> 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,
Expand Down
Loading

0 comments on commit 733262c

Please sign in to comment.