-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create an abstract
LoudnessCalculatorFactory
.
- Implement a simple version which just copies user loudness. - In the future this will be used to configure a module which actually measures loudness for a Mix Presentation OBU. PiperOrigin-RevId: 628083616
- Loading branch information
Showing
7 changed files
with
170 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright (c) 2024, Alliance for Open Media. All rights reserved | ||
* | ||
* This source code is subject to the terms of the BSD 3-Clause Clear License | ||
* and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear | ||
* License was not distributed with this source code in the LICENSE file, you | ||
* can obtain it at www.aomedia.org/license/software-license/bsd-3-c-c. If the | ||
* Alliance for Open Media Patent License 1.0 was not distributed with this | ||
* source code in the PATENTS file, you can obtain it at | ||
* www.aomedia.org/license/patent. | ||
*/ | ||
#include "iamf/cli/loudness_calculator_factory.h" | ||
|
||
#include <cstdint> | ||
#include <memory> | ||
|
||
#include "iamf/cli/loudness_calculator.h" | ||
#include "iamf/obu/mix_presentation.h" | ||
|
||
namespace iamf_tools { | ||
|
||
LoudnessCalculatorFactoryBase::~LoudnessCalculatorFactoryBase() {} | ||
|
||
std::unique_ptr<LoudnessCalculatorBase> | ||
LoudnessCalculatorFactoryUserProvidedLoudness::CreateLoudnessCalculator( | ||
const MixPresentationLayout& layout, int32_t, int32_t) const { | ||
return std::make_unique<LoudnessCalculatorUserProvidedLoudness>( | ||
layout.loudness); | ||
} | ||
|
||
} // namespace iamf_tools |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright (c) 2024, Alliance for Open Media. All rights reserved | ||
* | ||
* This source code is subject to the terms of the BSD 3-Clause Clear License | ||
* and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear | ||
* License was not distributed with this source code in the LICENSE file, you | ||
* can obtain it at www.aomedia.org/license/software-license/bsd-3-c-c. If the | ||
* Alliance for Open Media Patent License 1.0 was not distributed with this | ||
* source code in the PATENTS file, you can obtain it at | ||
* www.aomedia.org/license/patent. | ||
*/ | ||
#ifndef CLI_LOUDNESS_CALCULATOR_FACTORY_H_ | ||
#define CLI_LOUDNESS_CALCULATOR_FACTORY_H_ | ||
|
||
#include <cstdint> | ||
#include <memory> | ||
|
||
#include "iamf/cli/loudness_calculator.h" | ||
#include "iamf/obu/mix_presentation.h" | ||
|
||
namespace iamf_tools { | ||
|
||
/*\!brief Abstract class to create loudness calculators. | ||
* | ||
* This class will be used when calculating the loudness of a mix presentation | ||
* layout. The mix presentation finalizer will take in a factory (or factories) | ||
* and use them to create a loudness calculator for each stream. By taking in a | ||
* factory the finalizer can be agnostic to the type of loudness calculator | ||
* being used which may depend on implementation details, or it may depend on | ||
* the specific layouts. | ||
*/ | ||
class LoudnessCalculatorFactoryBase { | ||
public: | ||
/*\!brief Creates a loudness calculator. | ||
* | ||
* \param layout Layout to measure loudness on. | ||
* \param rendered_sample_rate Sample rate of the rendered audio. | ||
* \param rendered_bit_depth Bit-depth of the rendered audio. | ||
* \return Unique pointer to a loudness calculator. | ||
*/ | ||
virtual std::unique_ptr<LoudnessCalculatorBase> CreateLoudnessCalculator( | ||
const MixPresentationLayout& layout, int32_t rendered_sample_rate, | ||
int32_t rendered_bit_depth) const = 0; | ||
|
||
/*\!brief Destructor. */ | ||
virtual ~LoudnessCalculatorFactoryBase() = 0; | ||
}; | ||
|
||
// TODO(b/302273947): Use this class to measure loudness when finalizing mix | ||
// presentations. | ||
/*\!brief Factory which always provides a fallback loudness calculator. */ | ||
class LoudnessCalculatorFactoryUserProvidedLoudness | ||
: public LoudnessCalculatorFactoryBase { | ||
public: | ||
/*\!brief Creates a fallback loudness calculator. | ||
* | ||
* \param layout Layout to use when echoing loudness back. | ||
* \param rendered_sample_rate Sample rate of the rendered audio to ignore. | ||
* \param rendered_bit_depth Bit-depth of the rendered audio to ignore. | ||
* \return Unique pointer to a loudness calculator. | ||
*/ | ||
std::unique_ptr<LoudnessCalculatorBase> CreateLoudnessCalculator( | ||
const MixPresentationLayout& layout, int32_t /*rendered_sample_rate*/, | ||
int32_t /*rendered_bit_depth*/) const override; | ||
|
||
/*\!brief Destructor. */ | ||
~LoudnessCalculatorFactoryUserProvidedLoudness() override = default; | ||
}; | ||
|
||
} // namespace iamf_tools | ||
|
||
#endif // CLI_LOUDNESS_CALCULATOR_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (c) 2024, Alliance for Open Media. All rights reserved | ||
* | ||
* This source code is subject to the terms of the BSD 3-Clause Clear License | ||
* and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear | ||
* License was not distributed with this source code in the LICENSE file, you | ||
* can obtain it at www.aomedia.org/license/software-license/bsd-3-c-c. If the | ||
* Alliance for Open Media Patent License 1.0 was not distributed with this | ||
* source code in the PATENTS file, you can obtain it at | ||
* www.aomedia.org/license/patent. | ||
*/ | ||
#include "iamf/cli/loudness_calculator_factory.h" | ||
|
||
#include <cstdint> | ||
|
||
#include "gtest/gtest.h" | ||
#include "iamf/cli/proto/obu_header.pb.h" | ||
#include "iamf/cli/proto/parameter_data.pb.h" | ||
#include "iamf/cli/proto/temporal_delimiter.pb.h" | ||
#include "iamf/cli/proto/user_metadata.pb.h" | ||
#include "iamf/obu/mix_presentation.h" | ||
|
||
namespace iamf_tools { | ||
namespace { | ||
|
||
constexpr int32_t kUnusedRenderedSampleRate = 0; | ||
constexpr int32_t kUnusedRenderedBitDepth = 0; | ||
|
||
TEST(CreatePrimaryLoudnessCalculator, NeverReturnsNull) { | ||
const LoudnessCalculatorFactoryUserProvidedLoudness factory; | ||
const MixPresentationLayout layout = {}; | ||
|
||
EXPECT_NE(factory.CreateLoudnessCalculator(layout, kUnusedRenderedSampleRate, | ||
kUnusedRenderedBitDepth), | ||
nullptr); | ||
} | ||
|
||
} // namespace | ||
} // namespace iamf_tools |