Skip to content

Commit

Permalink
Refactor to use a customized and unified "Mix Presentation Finalizer".
Browse files Browse the repository at this point in the history
  - Previously we had separate finalizers. But now we have one finalizer that can be configured with custom rendering and loudness calculating behavior.
  - Now that we only need one finalizer, it is better to have a single implementation. The different behaviors can be configured at construction time.
    - `MeasureLoudnessOrFallbackToUserLoudnessMixPresentationFinalizer` behavior is mimicked by configuring it with `nullptr` factories.
    - `iamf/cli/iamf_components.cc`: Return `nullptr` factories to match the long-standing behavior; bypass rendering and trust the user-provided loudness.
  - Clean up related cruft.

PiperOrigin-RevId: 688961745
  • Loading branch information
jwcullen committed Oct 23, 2024
1 parent 190a2f8 commit c0d60b0
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 433 deletions.
23 changes: 1 addition & 22 deletions iamf/cli/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ cc_library(
":obu_sequencer",
":parameter_block_partitioner",
":parameter_block_with_data",
":rendering_mix_presentation_finalizer",
":wav_sample_provider",
":wav_writer",
"//iamf/cli/proto:test_vector_metadata_cc_proto",
Expand Down Expand Up @@ -202,10 +203,8 @@ cc_library(
deps = [
":leb_generator",
":loudness_calculator_factory_base",
":mix_presentation_finalizer",
":obu_sequencer",
":renderer_factory",
":rendering_mix_presentation_finalizer",
"//iamf/cli/proto:mix_presentation_cc_proto",
"//iamf/cli/proto:test_vector_metadata_cc_proto",
"//iamf/cli/proto:user_metadata_cc_proto",
Expand Down Expand Up @@ -285,25 +284,6 @@ cc_library(
],
)

cc_library(
name = "mix_presentation_finalizer",
srcs = ["mix_presentation_finalizer.cc"],
hdrs = ["mix_presentation_finalizer.h"],
deps = [
":audio_element_with_data",
":demixing_module",
":parameter_block_with_data",
":wav_writer",
"//iamf/cli/proto:mix_presentation_cc_proto",
"//iamf/obu:mix_presentation",
"//iamf/obu:types",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/functional:any_invocable",
"@com_google_absl//absl/log",
"@com_google_absl//absl/status",
],
)

cc_library(
name = "obu_sequencer",
srcs = ["obu_sequencer.cc"],
Expand Down Expand Up @@ -440,7 +420,6 @@ cc_library(
":demixing_module",
":loudness_calculator_base",
":loudness_calculator_factory_base",
":mix_presentation_finalizer",
":parameter_block_with_data",
":renderer_factory",
":wav_writer",
Expand Down
8 changes: 5 additions & 3 deletions iamf/cli/encoder_main_lib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "iamf/cli/proto/test_vector_metadata.pb.h"
#include "iamf/cli/proto/user_metadata.pb.h"
#include "iamf/cli/proto_to_obu/arbitrary_obu_generator.h"
#include "iamf/cli/rendering_mix_presentation_finalizer.h"
#include "iamf/cli/wav_sample_provider.h"
#include "iamf/cli/wav_writer.h"
#include "iamf/common/macros.h"
Expand Down Expand Up @@ -288,10 +289,11 @@ absl::Status GenerateObus(
user_metadata.test_vector_metadata().file_name_prefix())
.string();
LOG(INFO) << "output_wav_file_prefix = " << output_wav_file_prefix;
auto mix_presentation_finalizer = CreateMixPresentationFinalizer(
RenderingMixPresentationFinalizer mix_presentation_finalizer(
output_wav_file_prefix, output_wav_file_bit_depth_override,
user_metadata.test_vector_metadata().validate_user_loudness());
RETURN_IF_NOT_OK(mix_presentation_finalizer->Finalize(
user_metadata.test_vector_metadata().validate_user_loudness(),
CreateRendererFactory(), CreateLoudnessCalculatorFactory());
RETURN_IF_NOT_OK(mix_presentation_finalizer.Finalize(
audio_elements, id_to_time_to_labeled_frame, parameter_blocks,
ProduceAllWavWriters, mix_presentation_obus));

Expand Down
24 changes: 9 additions & 15 deletions iamf/cli/iamf_components.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,20 @@
*/
#include "iamf/cli/iamf_components.h"

#include <cstdint>
#include <filesystem>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>

#include "absl/log/log.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "iamf/cli/leb_generator.h"
#include "iamf/cli/loudness_calculator_factory_base.h"
#include "iamf/cli/mix_presentation_finalizer.h"
#include "iamf/cli/obu_sequencer.h"
#include "iamf/cli/proto/test_vector_metadata.pb.h"
#include "iamf/cli/proto/user_metadata.pb.h"
#include "iamf/cli/renderer_factory.h"
#include "iamf/cli/rendering_mix_presentation_finalizer.h"

namespace iamf_tools {

Expand All @@ -39,16 +34,15 @@ constexpr absl::string_view kOmitIamfFile = "";

}

std::unique_ptr<MixPresentationFinalizerBase> CreateMixPresentationFinalizer(
const std::string& file_name_prefix,
std::optional<uint8_t> output_wav_file_bit_depth_override,
bool validate_loudness) {
std::unique_ptr<RendererFactoryBase> skip_rendering = nullptr;
std::unique_ptr<LoudnessCalculatorFactoryBase> preserve_user_loudness =
nullptr;
return std::make_unique<RenderingMixPresentationFinalizer>(
file_name_prefix, output_wav_file_bit_depth_override, validate_loudness,
std::move(skip_rendering), std::move(preserve_user_loudness));
std::unique_ptr<RendererFactoryBase> CreateRendererFactory() {
// Skip rendering.
return nullptr;
}

std::unique_ptr<LoudnessCalculatorFactoryBase>
CreateLoudnessCalculatorFactory() {
// Skip loudness calculation.
return nullptr;
}

std::vector<std::unique_ptr<ObuSequencerBase>> CreateObuSequencers(
Expand Down
32 changes: 17 additions & 15 deletions iamf/cli/iamf_components.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,36 @@
#ifndef CLI_IAMF_COMPONENTS_H_
#define CLI_IAMF_COMPONENTS_H_

#include <cstdint>
#include <memory>
#include <optional>
#include <string>
#include <vector>

#include "iamf/cli/mix_presentation_finalizer.h"
#include "iamf/cli/loudness_calculator_factory_base.h"
#include "iamf/cli/obu_sequencer.h"
#include "iamf/cli/proto/mix_presentation.pb.h"
#include "iamf/cli/proto/user_metadata.pb.h"
#include "iamf/cli/renderer_factory.h"

namespace iamf_tools {

/*!\brief Creates an instance of `MixPresentationFinalizerBase`.
/*!\brief Creates an instance of `RendererFactoryBase`.
*
* This is useful for binding different kinds of finalizers in an IAMF Encoder.
* This is useful for binding different kinds of renderer factories in an IAMF
* Encoder.
*
* \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.
* \param validate_loudness Whether to validate computed loudness matches the
* user-provided loudness.
* \return Unique pointer to the created Mix Presentation finalizer.
* \return Unique pointer to the created renderer factory
*/
std::unique_ptr<MixPresentationFinalizerBase> CreateMixPresentationFinalizer(
const std::string& file_name_prefix,
std::optional<uint8_t> output_wav_file_bit_depth_override,
bool validate_loudness);
std::unique_ptr<RendererFactoryBase> CreateRendererFactory();

/*!\brief Creates an instance of `LoudnessCalculatorFactoryBase`.
*
* This is useful for binding different kinds of loudness calculator factories
* in an IAMF Encoder.
*
* \return Unique pointer to the created loudness calculator factory.
*/
std::unique_ptr<LoudnessCalculatorFactoryBase>
CreateLoudnessCalculatorFactory();

/*!\brief Creates instances of `ObuSequencerBase`.
*
Expand Down
51 changes: 0 additions & 51 deletions iamf/cli/mix_presentation_finalizer.cc

This file was deleted.

125 changes: 0 additions & 125 deletions iamf/cli/mix_presentation_finalizer.h

This file was deleted.

4 changes: 2 additions & 2 deletions iamf/cli/rendering_mix_presentation_finalizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#include "iamf/cli/demixing_module.h"
#include "iamf/cli/loudness_calculator_base.h"
#include "iamf/cli/loudness_calculator_factory_base.h"
#include "iamf/cli/mix_presentation_finalizer.h"
#include "iamf/cli/parameter_block_with_data.h"
#include "iamf/cli/proto/mix_presentation.pb.h"
#include "iamf/cli/proto/test_vector_metadata.pb.h"
Expand Down Expand Up @@ -474,7 +473,8 @@ absl::Status ValidateUserLoudness(const LoudnessInfo& user_loudness,
absl::Status FillLoudnessInfo(
bool validate_loudness, const RendererFactoryBase& renderer_factory,
const LoudnessCalculatorFactoryBase* loudness_calculator_factory,
const MixPresentationFinalizerBase::WavWriterFactory& wav_writer_factory,
const RenderingMixPresentationFinalizer::WavWriterFactory&
wav_writer_factory,
const std::filesystem::path& file_path_prefix,
const absl::flat_hash_map<uint32_t, AudioElementWithData>& audio_elements,
const IdTimeLabeledFrameMap& id_to_time_to_labeled_frame,
Expand Down
Loading

0 comments on commit c0d60b0

Please sign in to comment.