1 /* 2 * Copyright (c) 2024, Alliance for Open Media. All rights reserved 3 * 4 * This source code is subject to the terms of the BSD 3-Clause Clear License 5 * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear 6 * License was not distributed with this source code in the LICENSE file, you 7 * can obtain it at www.aomedia.org/license/software-license/bsd-3-c-c. If the 8 * Alliance for Open Media Patent License 1.0 was not distributed with this 9 * source code in the PATENTS file, you can obtain it at 10 * www.aomedia.org/license/patent. 11 */ 12 #ifndef CLI_LOUDNESS_CALCULATOR_BASE_H_ 13 #define CLI_LOUDNESS_CALCULATOR_BASE_H_ 14 15 #include <cstdint> 16 #include <vector> 17 18 #include "absl/status/status.h" 19 #include "absl/status/statusor.h" 20 #include "absl/types/span.h" 21 #include "iamf/obu/mix_presentation.h" 22 23 namespace iamf_tools { 24 25 /*!\brief Abstract class for calculate loudness from an input audio stream. 26 * 27 * - Call the constructor with an input `MixPresentationLayout`. 28 * - Call `AccumulateLoudnessForSamples()` to accumlate interleaved audio 29 * samples to measure loudness on. 30 * - Call `QueryLoudness()` to query the current loudness. The types to be 31 * measured are determined from the constructor argument. 32 */ 33 class LoudnessCalculatorBase { 34 public: 35 /*!\brief Destructor. */ 36 virtual ~LoudnessCalculatorBase() = 0; 37 38 /*!\brief Accumulates samples to be measured. 39 * 40 * \param time_channel_samples Samples to push arranged in (time, channel). 41 * \return `absl::OkStatus()` on success. A specific status on failure. 42 */ 43 virtual absl::Status AccumulateLoudnessForSamples( 44 absl::Span<const std::vector<int32_t>> time_channel_samples) = 0; 45 46 /*!\brief Outputs the measured loudness. 47 * 48 * \return Measured loudness on success. A specific status on failure. 49 */ 50 virtual absl::StatusOr<LoudnessInfo> QueryLoudness() const = 0; 51 52 protected: 53 /*!\brief Constructor. */ LoudnessCalculatorBase()54 LoudnessCalculatorBase() {} 55 }; 56 57 } // namespace iamf_tools 58 59 #endif // CLI_LOUDNESS_CALCULATOR_BASE_H_ 60