1 /* 2 * Copyright (c) 2023, 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 13 #ifndef CLI_PROTO_CONVERSION_PROTO_TO_OBU_MIX_PRESENTATION_GENERATOR_H_ 14 #define CLI_PROTO_CONVERSION_PROTO_TO_OBU_MIX_PRESENTATION_GENERATOR_H_ 15 16 #include <cstdint> 17 #include <list> 18 19 #include "absl/status/status.h" 20 #include "iamf/cli/proto/mix_presentation.pb.h" 21 #include "iamf/cli/proto/user_metadata.pb.h" 22 #include "iamf/obu/mix_presentation.h" 23 #include "src/google/protobuf/repeated_ptr_field.h" 24 25 namespace iamf_tools { 26 27 class MixPresentationGenerator { 28 public: 29 /*!\brief Copies the sound system from the corresponding protocol buffer. 30 * 31 * \param input_sound_system Input protocol buffer. 32 * \param output_sound_system Result. 33 * \return `absl::OkStatus()` on success. A specific status on failure. 34 */ 35 static absl::Status CopySoundSystem( 36 iamf_tools_cli_proto::SoundSystem input_sound_system, 37 LoudspeakersSsConventionLayout::SoundSystem& output_sound_system); 38 39 /*!\brief Copies the info type from the corresponding protocol buffer. 40 * 41 * \param input_loudness_info Input protocol buffer. 42 * \param loudness_info_type Result. 43 * \return `absl::OkStatus()` on success. A specific status on failure. 44 */ 45 static absl::Status CopyInfoType( 46 const iamf_tools_cli_proto::LoudnessInfo& input_loudness_info, 47 uint8_t& loudness_info_type); 48 49 /*!\brief Copies over user provided integrated loudness and peak values. 50 * 51 * \param user_loudness User provided loudness information. 52 * \param output_loudness Output loudness information with `info_type` 53 * initialized. 54 * \return `absl::OkStatus()` on success. A specific status on failure. 55 */ 56 static absl::Status CopyUserIntegratedLoudnessAndPeaks( 57 const iamf_tools_cli_proto::LoudnessInfo& user_loudness, 58 LoudnessInfo& output_loudness); 59 60 /*!\brief Copies over user provided anchored loudness. 61 * 62 * \param user_loudness User provided loudness information. 63 * \param output_loudness Output loudness information with `info_type` 64 * initialized. 65 * \return `absl::OkStatus()` on success. A specific status on failure. 66 */ 67 static absl::Status CopyUserAnchoredLoudness( 68 const iamf_tools_cli_proto::LoudnessInfo& user_loudness, 69 LoudnessInfo& output_loudness); 70 71 /*!\brief Copies over user provided layout extension. 72 * 73 * \param user_loudness User provided loudness information. 74 * \param output_loudness Output loudness information with `info_type` 75 * initialized. 76 * \return `absl::OkStatus()` on success. A specific status on failure. 77 */ 78 static absl::Status CopyUserLayoutExtension( 79 const iamf_tools_cli_proto::LoudnessInfo& user_loudness, 80 LoudnessInfo& output_loudness); 81 82 /*!\brief Constructor. 83 * \param mix_presentation_metadata Input mix presentation metadata. 84 */ MixPresentationGenerator(const::google::protobuf::RepeatedPtrField<iamf_tools_cli_proto::MixPresentationObuMetadata> & mix_presentation_metadata)85 MixPresentationGenerator(const ::google::protobuf::RepeatedPtrField< 86 iamf_tools_cli_proto::MixPresentationObuMetadata>& 87 mix_presentation_metadata) 88 : mix_presentation_metadata_(mix_presentation_metadata) {} 89 90 /*!\brief Generates a list of Mix Presentation OBUs from the input metadata. 91 * 92 * Note that `finalize_mix_presentation_obus` must be called afterwards to 93 * populate the loudness information for the OBUs. 94 * 95 * \param append_build_information_tag Whether to append an additional 96 * `MixPresentationTag` which signals the encoder version which 97 * generated the bitstream. 98 * \param mix_presentation_obus Output list of OBUs. 99 * \return `absl::OkStatus()` on success. A specific status on failure. 100 */ 101 absl::Status Generate(bool append_build_information_tag, 102 std::list<MixPresentationObu>& mix_presentation_obus); 103 104 private: 105 const ::google::protobuf::RepeatedPtrField< 106 iamf_tools_cli_proto::MixPresentationObuMetadata> 107 mix_presentation_metadata_; 108 }; 109 110 } // namespace iamf_tools 111 112 #endif // PROTO_TO_OBU_CLI_MIX_PRESENTATION_GENERATOR_H_ 113