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_RENDERER_FACTORY_H_ 13 #define CLI_RENDERER_FACTORY_H_ 14 15 #include <cstddef> 16 #include <memory> 17 #include <vector> 18 19 #include "iamf/cli/audio_element_with_data.h" 20 #include "iamf/cli/renderer/audio_element_renderer_base.h" 21 #include "iamf/obu/audio_element.h" 22 #include "iamf/obu/mix_presentation.h" 23 #include "iamf/obu/types.h" 24 25 namespace iamf_tools { 26 27 /*!\brief Abstract class to create renderers. 28 * 29 * This class will be used when rendering the loudness of a mix presentation 30 * layout. The mix presentation finalizer will take in a factory and use them to 31 * create a renderers. By taking in a factory the finalizer can be agnostic to 32 * the collection of renderers that are being used and it what circumstances 33 * they are used. 34 */ 35 class RendererFactoryBase { 36 public: 37 /*!\brief Creates a renderer based on the audio element and layout. 38 * 39 * \param audio_substream_ids Audio susbtream IDs. 40 * \param substream_id_to_labels Mapping of substream IDs to labels. 41 * \param audio_element_type Type of the audio element. 42 * \param audio_element_config Configuration of the audio element. 43 * \param rendering_config Configuration of the renderer. 44 * \param loudness_layout Layout to render to. 45 * \param num_samples_per_frame Number of samples per frame. 46 * \return Unique pointer to an audio element renderer or `nullptr` if it not 47 * known how to render the audio element. 48 */ 49 virtual std::unique_ptr<AudioElementRendererBase> CreateRendererForLayout( 50 const std::vector<DecodedUleb128>& audio_substream_ids, 51 const SubstreamIdLabelsMap& substream_id_to_labels, 52 AudioElementObu::AudioElementType audio_element_type, 53 const AudioElementObu::AudioElementConfig& audio_element_config, 54 const RenderingConfig& rendering_config, const Layout& loudness_layout, 55 size_t num_samples_per_frame) const = 0; 56 57 /*!\brief Destructor. */ 58 virtual ~RendererFactoryBase() = 0; 59 }; 60 61 /*!\brief Factory which creates a renderers. 62 * 63 * This factory provides renderers in a best-effort manner according to the 64 * recommendations in the IAMF specification (section 7.3.2). When a recommended 65 * renderer is not implemented by `iamf-tools` the factory will fallback to 66 * returning a `nullptr`. 67 */ 68 class RendererFactory : public RendererFactoryBase { 69 public: 70 /*!\brief Creates a renderer based on the audio element and layout. 71 * 72 * \param audio_substream_ids Audio susbtream IDs. 73 * \param substream_id_to_labels Mapping of substream IDs to labels. 74 * \param audio_element_type Type of the audio element. 75 * \param audio_element_config Configuration of the audio element. 76 * \param rendering_config Configuration of the renderer. 77 * \param loudness_layout Layout to render to. 78 * \param num_samples_per_frame Number of samples per frame. 79 * \return Unique pointer to an audio element renderer or `nullptr` if it not 80 * known how to render the audio element. 81 */ 82 std::unique_ptr<AudioElementRendererBase> CreateRendererForLayout( 83 const std::vector<DecodedUleb128>& audio_substream_ids, 84 const SubstreamIdLabelsMap& substream_id_to_labels, 85 AudioElementObu::AudioElementType audio_element_type, 86 const AudioElementObu::AudioElementConfig& audio_element_config, 87 const RenderingConfig& rendering_config, const Layout& loudness_layout, 88 size_t num_samples_per_frame) const override; 89 90 /*!\brief Destructor. */ 91 ~RendererFactory() override = default; 92 }; 93 94 } // namespace iamf_tools 95 96 #endif // CLI_LOUDNESS_CALCULATOR_H_ 97