1 /* 2 * Copyright (c) 2025, 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 #include "iamf/api/conversion/mix_presentation_conversion.h" 14 15 #include <variant> 16 17 #include "absl/log/log.h" 18 #include "absl/status/status.h" 19 #include "absl/strings/str_cat.h" 20 #include "iamf/api/types.h" 21 #include "iamf/obu/mix_presentation.h" 22 23 namespace iamf_tools { 24 namespace { 25 InternalLayoutToApiLayout(const LoudspeakersReservedOrBinauralLayout & specific_layout)26absl::StatusOr<api::OutputLayout> InternalLayoutToApiLayout( 27 const LoudspeakersReservedOrBinauralLayout& specific_layout) { 28 return absl::InvalidArgumentError("Invalid layout type."); 29 } 30 InternalLayoutToApiLayout(const LoudspeakersSsConventionLayout & specific_layout)31absl::StatusOr<api::OutputLayout> InternalLayoutToApiLayout( 32 const LoudspeakersSsConventionLayout& specific_layout) { 33 switch (specific_layout.sound_system) { 34 case LoudspeakersSsConventionLayout::kSoundSystemA_0_2_0: 35 return api::OutputLayout::kItu2051_SoundSystemA_0_2_0; 36 case LoudspeakersSsConventionLayout::kSoundSystemB_0_5_0: 37 return api::OutputLayout::kItu2051_SoundSystemB_0_5_0; 38 case LoudspeakersSsConventionLayout::kSoundSystemC_2_5_0: 39 return api::OutputLayout::kItu2051_SoundSystemC_2_5_0; 40 case LoudspeakersSsConventionLayout::kSoundSystemD_4_5_0: 41 return api::OutputLayout::kItu2051_SoundSystemD_4_5_0; 42 case LoudspeakersSsConventionLayout::kSoundSystemE_4_5_1: 43 return api::OutputLayout::kItu2051_SoundSystemE_4_5_1; 44 case LoudspeakersSsConventionLayout::kSoundSystemF_3_7_0: 45 return api::OutputLayout::kItu2051_SoundSystemF_3_7_0; 46 case LoudspeakersSsConventionLayout::kSoundSystemG_4_9_0: 47 return api::OutputLayout::kItu2051_SoundSystemG_4_9_0; 48 case LoudspeakersSsConventionLayout::kSoundSystemH_9_10_3: 49 return api::OutputLayout::kItu2051_SoundSystemH_9_10_3; 50 case LoudspeakersSsConventionLayout::kSoundSystemI_0_7_0: 51 return api::OutputLayout::kItu2051_SoundSystemI_0_7_0; 52 case LoudspeakersSsConventionLayout::kSoundSystemJ_4_7_0: 53 return api::OutputLayout::kItu2051_SoundSystemJ_4_7_0; 54 case LoudspeakersSsConventionLayout::kSoundSystem10_2_7_0: 55 return api::OutputLayout::kIAMF_SoundSystemExtension_2_7_0; 56 case LoudspeakersSsConventionLayout::kSoundSystem11_2_3_0: 57 return api::OutputLayout::kIAMF_SoundSystemExtension_2_3_0; 58 case LoudspeakersSsConventionLayout::kSoundSystem12_0_1_0: 59 return api::OutputLayout::kIAMF_SoundSystemExtension_0_1_0; 60 case LoudspeakersSsConventionLayout::kSoundSystem13_6_9_0: 61 return api::OutputLayout::kIAMF_SoundSystemExtension_6_9_0; 62 default: 63 return absl::InvalidArgumentError( 64 absl::StrCat("Invalid layout: ", specific_layout.sound_system)); 65 }; 66 } 67 68 } // namespace 69 MakeLayout(LoudspeakersSsConventionLayout::SoundSystem sound_system)70Layout MakeLayout(LoudspeakersSsConventionLayout::SoundSystem sound_system) { 71 return {.layout_type = Layout::kLayoutTypeLoudspeakersSsConvention, 72 .specific_layout = 73 LoudspeakersSsConventionLayout{.sound_system = sound_system}}; 74 }; 75 ApiToInternalType(api::OutputLayout api_output_layout)76Layout ApiToInternalType(api::OutputLayout api_output_layout) { 77 switch (api_output_layout) { 78 case api::OutputLayout::kItu2051_SoundSystemA_0_2_0: 79 return MakeLayout(LoudspeakersSsConventionLayout::kSoundSystemA_0_2_0); 80 case api::OutputLayout::kItu2051_SoundSystemB_0_5_0: 81 return MakeLayout(LoudspeakersSsConventionLayout::kSoundSystemB_0_5_0); 82 case api::OutputLayout::kItu2051_SoundSystemC_2_5_0: 83 return MakeLayout(LoudspeakersSsConventionLayout::kSoundSystemC_2_5_0); 84 case api::OutputLayout::kItu2051_SoundSystemD_4_5_0: 85 return MakeLayout(LoudspeakersSsConventionLayout::kSoundSystemD_4_5_0); 86 case api::OutputLayout::kItu2051_SoundSystemE_4_5_1: 87 return MakeLayout(LoudspeakersSsConventionLayout::kSoundSystemE_4_5_1); 88 case api::OutputLayout::kItu2051_SoundSystemF_3_7_0: 89 return MakeLayout(LoudspeakersSsConventionLayout::kSoundSystemF_3_7_0); 90 case api::OutputLayout::kItu2051_SoundSystemG_4_9_0: 91 return MakeLayout(LoudspeakersSsConventionLayout::kSoundSystemG_4_9_0); 92 case api::OutputLayout::kItu2051_SoundSystemH_9_10_3: 93 return MakeLayout(LoudspeakersSsConventionLayout::kSoundSystemH_9_10_3); 94 case api::OutputLayout::kItu2051_SoundSystemI_0_7_0: 95 return MakeLayout(LoudspeakersSsConventionLayout::kSoundSystemI_0_7_0); 96 case api::OutputLayout::kItu2051_SoundSystemJ_4_7_0: 97 return MakeLayout(LoudspeakersSsConventionLayout::kSoundSystemJ_4_7_0); 98 case api::OutputLayout::kIAMF_SoundSystemExtension_2_7_0: 99 return MakeLayout(LoudspeakersSsConventionLayout::kSoundSystem10_2_7_0); 100 case api::OutputLayout::kIAMF_SoundSystemExtension_2_3_0: 101 return MakeLayout(LoudspeakersSsConventionLayout::kSoundSystem11_2_3_0); 102 case api::OutputLayout::kIAMF_SoundSystemExtension_0_1_0: 103 return MakeLayout(LoudspeakersSsConventionLayout::kSoundSystem12_0_1_0); 104 case api::OutputLayout::kIAMF_SoundSystemExtension_6_9_0: 105 return MakeLayout(LoudspeakersSsConventionLayout::kSoundSystem13_6_9_0); 106 }; 107 // Switch above is exhaustive. 108 LOG(FATAL) << "Invalid output layout."; 109 } 110 InternalToApiType(Layout internal_layout)111absl::StatusOr<api::OutputLayout> InternalToApiType(Layout internal_layout) { 112 return std::visit( 113 [](const auto& specific_layout) { 114 return InternalLayoutToApiLayout(specific_layout); 115 }, 116 internal_layout.specific_layout); 117 } 118 119 } // namespace iamf_tools 120