Skip to content

Commit

Permalink
Decouple MixPresentationFinalizer from user metadata.
Browse files Browse the repository at this point in the history
  - MixPresentationGenerator: Copies all of user loudness instead of just `info_type`.
  - `MeasureLoudnessOrFallbackToUserLoudnessMixPresentationFinalizer` no longer needs to do anything in fallback mode (currently it always falls back).
  - Update style of some related tests.

PiperOrigin-RevId: 633777182
  • Loading branch information
jwcullen committed May 16, 2024
1 parent 904beda commit 6bca287
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 297 deletions.
4 changes: 0 additions & 4 deletions iamf/cli/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ cc_library(
"//iamf/cli/proto:user_metadata_cc_proto",
"@com_google_absl//absl/log",
"@com_google_absl//absl/strings",
"@com_google_protobuf//:protobuf",
],
)

Expand Down Expand Up @@ -359,15 +358,12 @@ cc_library(
deps = [
":audio_element_with_data",
":demixing_module",
":mix_presentation_generator",
":parameter_block_with_data",
"//iamf/cli/proto:mix_presentation_cc_proto",
"//iamf/common:macros",
"//iamf/obu:mix_presentation",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/log",
"@com_google_absl//absl/status",
"@com_google_protobuf//:protobuf",
],
)

Expand Down
1 change: 0 additions & 1 deletion iamf/cli/encoder_main_lib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,6 @@ absl::Status GenerateObus(
}

auto mix_presentation_finalizer = CreateMixPresentationFinalizer(
user_metadata.mix_presentation_metadata(),
user_metadata.test_vector_metadata().file_name_prefix(),
output_wav_file_bit_depth_override,
user_metadata.test_vector_metadata().validate_user_loudness());
Expand Down
7 changes: 1 addition & 6 deletions iamf/cli/iamf_components.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,15 @@
#include "iamf/cli/obu_sequencer.h"
#include "iamf/cli/proto/test_vector_metadata.pb.h"
#include "iamf/cli/proto/user_metadata.pb.h"
#include "src/google/protobuf/repeated_ptr_field.h"

namespace iamf_tools {

std::unique_ptr<MixPresentationFinalizerBase> CreateMixPresentationFinalizer(
const ::google::protobuf::RepeatedPtrField<
iamf_tools_cli_proto::MixPresentationObuMetadata>&
mix_presentation_metadata,
const std::string& /*file_name_prefix*/,
std::optional<uint8_t> /*output_wav_file_bit_depth_override*/,
bool /*validate_loudness*/) {
return std::make_unique<
MeasureLoudnessOrFallbackToUserLoudnessMixPresentationFinalizer>(
mix_presentation_metadata);
MeasureLoudnessOrFallbackToUserLoudnessMixPresentationFinalizer>();
}

std::vector<std::unique_ptr<ObuSequencerBase>> CreateObuSequencers(
Expand Down
5 changes: 0 additions & 5 deletions iamf/cli/iamf_components.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@
#include "iamf/cli/obu_sequencer.h"
#include "iamf/cli/proto/mix_presentation.pb.h"
#include "iamf/cli/proto/user_metadata.pb.h"
#include "src/google/protobuf/repeated_ptr_field.h"

namespace iamf_tools {

/*\!brief Creates an instance of `MixPresentationFinalizerBase`.
*
* This is useful for binding different kinds of finalizers in an IAMF Encoder.
*
* \param mix_presentation_metadata Input mix presentation metadata.
* \param file_name_prefix Prefix of output file name.
* \param output_wav_file_bit_depth_override Override for the bit-depth of
* the rendered wav file.
Expand All @@ -40,9 +38,6 @@ namespace iamf_tools {
* \return Unique pointer to the created Mix Presentation finalizer.
*/
std::unique_ptr<MixPresentationFinalizerBase> CreateMixPresentationFinalizer(
const ::google::protobuf::RepeatedPtrField<
iamf_tools_cli_proto::MixPresentationObuMetadata>&
mix_presentation_metadata,
const std::string& file_name_prefix,
std::optional<uint8_t> output_wav_file_bit_depth_override,
bool validate_loudness);
Expand Down
41 changes: 0 additions & 41 deletions iamf/cli/mix_presentation_finalizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
#include "absl/status/status.h"
#include "iamf/cli/audio_element_with_data.h"
#include "iamf/cli/demixing_module.h"
#include "iamf/cli/mix_presentation_generator.h"
#include "iamf/cli/parameter_block_with_data.h"
#include "iamf/cli/proto/mix_presentation.pb.h"
#include "iamf/common/macros.h"
#include "iamf/obu/mix_presentation.h"

namespace iamf_tools {
Expand All @@ -41,45 +39,6 @@ MeasureLoudnessOrFallbackToUserLoudnessMixPresentationFinalizer::Finalize(
// TODO(b/332567539): Use `RendererFactory` to render certain layouts.
// TODO(b/302273947): Once layouts are rendered and mixed then use a
// `LoudnessCalculatorFactory` to measure loudness.
int metadata_index = 0;
for (auto& mix_presentation_obu : mix_presentation_obus) {
for (int sub_mix_index = 0;
sub_mix_index < mix_presentation_obu.sub_mixes_.size();
++sub_mix_index) {
MixPresentationSubMix& sub_mix =
mix_presentation_obu.sub_mixes_[sub_mix_index];
for (int layout_index = 0; layout_index < sub_mix.layouts.size();
layout_index++) {
const auto& user_loudness =
mix_presentation_metadata_.at(metadata_index)
.sub_mixes(sub_mix_index)
.layouts(layout_index)
.loudness();
auto& output_loudness = sub_mix.layouts[layout_index].loudness;

// The `info_type` should already be copied over in the
// `MixPresentationGenerator`. Check it is equivalent for extra safety.
uint8_t user_info_type;
RETURN_IF_NOT_OK(MixPresentationGenerator::CopyInfoType(
user_loudness, user_info_type));
if (user_info_type != output_loudness.info_type) {
LOG(ERROR) << "Mismatching loudness info types: ("
<< static_cast<uint32_t>(user_info_type) << " vs "
<< static_cast<uint32_t>(output_loudness.info_type) << ")";
return absl::InvalidArgumentError("");
}
RETURN_IF_NOT_OK(
MixPresentationGenerator::CopyUserIntegratedLoudnessAndPeaks(
user_loudness, output_loudness));
RETURN_IF_NOT_OK(MixPresentationGenerator::CopyUserAnchoredLoudness(
user_loudness, output_loudness));
RETURN_IF_NOT_OK(MixPresentationGenerator::CopyUserLayoutExtension(
user_loudness, output_loudness));
}
}

metadata_index++;
}

// Examine Mix Presentation OBUs.
for (const auto& mix_presentation_obu : mix_presentation_obus) {
Expand Down
29 changes: 5 additions & 24 deletions iamf/cli/mix_presentation_finalizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,13 @@
#include "iamf/cli/parameter_block_with_data.h"
#include "iamf/cli/proto/mix_presentation.pb.h"
#include "iamf/obu/mix_presentation.h"
#include "src/google/protobuf/repeated_ptr_field.h"

namespace iamf_tools {

class MixPresentationFinalizerBase {
public:
/*\!brief Constructor.
*
* \param mix_presentation_metadata Input mix presentation metadata.
*/
explicit MixPresentationFinalizerBase(
const ::google::protobuf::RepeatedPtrField<
iamf_tools_cli_proto::MixPresentationObuMetadata>&
mix_presentation_metadata)
: mix_presentation_metadata_(mix_presentation_metadata) {}
/*\!brief Constructor. */
explicit MixPresentationFinalizerBase() {}

/*\!brief Destructor.
*/
Expand All @@ -59,26 +51,15 @@ class MixPresentationFinalizerBase {
const IdTimeLabeledFrameMap& id_to_time_to_labeled_frame,
const std::list<ParameterBlockWithData>& parameter_blocks,
std::list<MixPresentationObu>& mix_presentation_obus) = 0;

protected:
const ::google::protobuf::RepeatedPtrField<
iamf_tools_cli_proto::MixPresentationObuMetadata>
mix_presentation_metadata_;
};

/*\!brief Finalizer that measures loudness or echoes user provided loudness. */
class MeasureLoudnessOrFallbackToUserLoudnessMixPresentationFinalizer
: public MixPresentationFinalizerBase {
public:
/*\!brief Constructor.
*
* \param mix_presentation_metadata Input mix presentation metadata.
*/
explicit MeasureLoudnessOrFallbackToUserLoudnessMixPresentationFinalizer(
const ::google::protobuf::RepeatedPtrField<
iamf_tools_cli_proto::MixPresentationObuMetadata>&
mix_presentation_metadata)
: MixPresentationFinalizerBase(mix_presentation_metadata) {}
/*\!brief Constructor. */
explicit MeasureLoudnessOrFallbackToUserLoudnessMixPresentationFinalizer()
: MixPresentationFinalizerBase() {}

/*\!brief Destructor.
*/
Expand Down
8 changes: 8 additions & 0 deletions iamf/cli/mix_presentation_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,14 @@ absl::Status FillLayouts(
RETURN_IF_NOT_OK(MixPresentationGenerator::CopyInfoType(
input_layout.loudness(), layout.loudness.info_type));

RETURN_IF_NOT_OK(
MixPresentationGenerator::CopyUserIntegratedLoudnessAndPeaks(
input_layout.loudness(), layout.loudness));
RETURN_IF_NOT_OK(MixPresentationGenerator::CopyUserAnchoredLoudness(
input_layout.loudness(), layout.loudness));
RETURN_IF_NOT_OK(MixPresentationGenerator::CopyUserLayoutExtension(
input_layout.loudness(), layout.loudness));

sub_mix.layouts.push_back(layout);
}

Expand Down
1 change: 0 additions & 1 deletion iamf/cli/tests/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ cc_test(
"//iamf/obu:mix_presentation",
"@com_google_absl//absl/status",
"@com_google_googletest//:gtest_main",
"@com_google_protobuf//:protobuf",
],
)

Expand Down
6 changes: 3 additions & 3 deletions iamf/cli/tests/iamf_components_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ constexpr bool kValidateLoudness = true;

TEST(IamfComponentsTest, CreateMixPresentationFinalizerReturnsNonNull) {
EXPECT_NE(CreateMixPresentationFinalizer(
{}, /*file_name_prefix=*/"",
/*file_name_prefix=*/"",
/*output_wav_file_bit_depth_override=*/std::nullopt,
kValidateLoudness),
nullptr);
Expand Down Expand Up @@ -67,8 +67,8 @@ TEST(IamfComponentsTest, CanBeConfiguredWithFixedSizeLebGenerator) {

TEST(IamfComponentsTest, CanBeConfiguredWithOutputWavFileBitDepthOverride) {
const uint8_t kOutputWavFileBitDepthOverride = 16;
EXPECT_NE(CreateMixPresentationFinalizer(
{}, "", kOutputWavFileBitDepthOverride, kValidateLoudness),
EXPECT_NE(CreateMixPresentationFinalizer("", kOutputWavFileBitDepthOverride,
kValidateLoudness),
nullptr);
}

Expand Down
Loading

0 comments on commit 6bca287

Please sign in to comment.