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 13 #ifndef CLI_ADM_TO_USER_METADATA_IAMF_IAMF_H_ 14 #define CLI_ADM_TO_USER_METADATA_IAMF_IAMF_H_ 15 16 #include <cstdint> 17 #include <map> 18 #include <string> 19 #include <vector> 20 21 #include "absl/status/statusor.h" 22 #include "iamf/cli/adm_to_user_metadata/adm/adm_elements.h" 23 #include "iamf/cli/adm_to_user_metadata/iamf/mix_presentation_handler.h" 24 #include "iamf/cli/proto/user_metadata.pb.h" 25 #include "iamf/cli/user_metadata_builder/audio_element_metadata_builder.h" 26 #include "iamf/cli/user_metadata_builder/iamf_input_layout.h" 27 28 namespace iamf_tools { 29 namespace adm_to_user_metadata { 30 31 /*!\brief Helps maintain consistency within an IAMF stream. 32 * 33 * This class holds the mapping between ADM objects and IAMF OBUs. It also holds 34 * several handlers which help maintain consistency between particular types of 35 * OBUs. 36 */ 37 class IAMF { 38 public: 39 struct AudioObjectsAndMetadata { 40 std::vector<AudioObject> audio_objects; 41 int32_t original_audio_programme_index; 42 }; 43 44 /*!\brief Creates an `IAMF` object. 45 * 46 * \param adm ADM data to initialize with. 47 * \param max_frame_duration_ms Maximum frame duration in milliseconds. The 48 * actual frame duration may be shorter due to rounding. 49 * \param samples_per_sec Sample rate of the input audio files in Hertz. 50 * \return `IAMF` object or a specific error code on failure. 51 */ 52 static absl::StatusOr<IAMF> Create(const ADM& adm, int32_t frame_duration_ms, 53 uint32_t samples_per_sec); 54 55 const std::map<int32_t, AudioObjectsAndMetadata> 56 mix_presentation_id_to_audio_objects_and_metadata_; 57 const std::map<std::string, uint32_t> audio_object_to_audio_element_; 58 59 const std::string file_name_prefix_; 60 const int64_t num_samples_per_frame_; 61 const std::vector<IamfInputLayout> input_layouts_; 62 63 AudioElementMetadataBuilder audio_element_metadata_builder_; 64 MixPresentationHandler mix_presentation_handler_; 65 66 private: 67 /*!\brief Constructor. 68 * 69 * \param mix_presentation_id_to_audio_objects_and_metadata Map of mix 70 * presentation IDs to audio objects and metadata to initialize with. 71 * \param audio_object_to_audio_element Map of audio object reference IDs to 72 * audio element IDs. 73 * \param num_samples_per_frame Number of samples per frame. 74 * \param samples_per_sec Sample rate of the input audio files in Hertz. 75 * \param input_layouts Vector of iamf input layouts format ids. 76 */ 77 IAMF(const std::map<int32_t, AudioObjectsAndMetadata>& 78 mix_presentation_id_to_audio_objects_and_metadata, 79 const std::map<std::string, uint32_t>& audio_object_to_audio_element, 80 int64_t num_samples_per_frame, uint32_t samples_per_sec, 81 const std::vector<IamfInputLayout>& input_layouts); 82 }; 83 84 } // namespace adm_to_user_metadata 85 } // namespace iamf_tools 86 87 #endif // CLI_ADM_TO_USER_METADATA_IAMF_IAMF_H_ 88