• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <utility>
16 #include <variant>
17 
18 #include "absl/status/status_matchers.h"
19 #include "gmock/gmock.h"
20 #include "gtest/gtest.h"
21 #include "iamf/api/types.h"
22 #include "iamf/obu/mix_presentation.h"
23 
24 namespace iamf_tools {
25 namespace {
26 
27 using ::absl_testing::IsOk;
28 using ::testing::TestWithParam;
29 
30 using LayoutPair =
31     std::pair<api::OutputLayout, LoudspeakersSsConventionLayout::SoundSystem>;
32 using ApiToInternalType_OutputLayout = TestWithParam<LayoutPair>;
33 
34 auto kApiOutputToInternalSoundSystemPairs = ::testing::Values(
35     LayoutPair(api::OutputLayout::kItu2051_SoundSystemA_0_2_0,
36                LoudspeakersSsConventionLayout::kSoundSystemA_0_2_0),
37     LayoutPair(api::OutputLayout::kItu2051_SoundSystemB_0_5_0,
38                LoudspeakersSsConventionLayout::kSoundSystemB_0_5_0),
39     LayoutPair(api::OutputLayout::kItu2051_SoundSystemC_2_5_0,
40                LoudspeakersSsConventionLayout::kSoundSystemC_2_5_0),
41     LayoutPair(api::OutputLayout::kItu2051_SoundSystemD_4_5_0,
42                LoudspeakersSsConventionLayout::kSoundSystemD_4_5_0),
43     LayoutPair(api::OutputLayout::kItu2051_SoundSystemE_4_5_1,
44                LoudspeakersSsConventionLayout::kSoundSystemE_4_5_1),
45     LayoutPair(api::OutputLayout::kItu2051_SoundSystemF_3_7_0,
46                LoudspeakersSsConventionLayout::kSoundSystemF_3_7_0),
47     LayoutPair(api::OutputLayout::kItu2051_SoundSystemG_4_9_0,
48                LoudspeakersSsConventionLayout::kSoundSystemG_4_9_0),
49     LayoutPair(api::OutputLayout::kItu2051_SoundSystemH_9_10_3,
50                LoudspeakersSsConventionLayout::kSoundSystemH_9_10_3),
51     LayoutPair(api::OutputLayout::kItu2051_SoundSystemI_0_7_0,
52                LoudspeakersSsConventionLayout::kSoundSystemI_0_7_0),
53     LayoutPair(api::OutputLayout::kItu2051_SoundSystemJ_4_7_0,
54                LoudspeakersSsConventionLayout::kSoundSystemJ_4_7_0),
55     LayoutPair(api::OutputLayout::kIAMF_SoundSystemExtension_2_7_0,
56                LoudspeakersSsConventionLayout::kSoundSystem10_2_7_0),
57     LayoutPair(api::OutputLayout::kIAMF_SoundSystemExtension_2_3_0,
58                LoudspeakersSsConventionLayout::kSoundSystem11_2_3_0),
59     LayoutPair(api::OutputLayout::kIAMF_SoundSystemExtension_0_1_0,
60                LoudspeakersSsConventionLayout::kSoundSystem12_0_1_0),
61     LayoutPair(api::OutputLayout::kIAMF_SoundSystemExtension_6_9_0,
62                LoudspeakersSsConventionLayout::kSoundSystem13_6_9_0));
63 
TEST_P(ApiToInternalType_OutputLayout,ConvertsOutputStereoToInternalLayout)64 TEST_P(ApiToInternalType_OutputLayout, ConvertsOutputStereoToInternalLayout) {
65   const auto& [api_output_layout, expected_specific_layout] = GetParam();
66 
67   Layout resulting_layout = ApiToInternalType(api_output_layout);
68 
69   EXPECT_EQ(resulting_layout.layout_type,
70             Layout::kLayoutTypeLoudspeakersSsConvention);
71   EXPECT_TRUE(std::holds_alternative<LoudspeakersSsConventionLayout>(
72       resulting_layout.specific_layout));
73   EXPECT_EQ(
74       std::get<LoudspeakersSsConventionLayout>(resulting_layout.specific_layout)
75           .sound_system,
76       expected_specific_layout);
77 }
78 
79 INSTANTIATE_TEST_SUITE_P(ApiToInternalType_OutputLayout_Instantiation,
80                          ApiToInternalType_OutputLayout,
81                          kApiOutputToInternalSoundSystemPairs);
82 
MakeLayout(LoudspeakersSsConventionLayout::SoundSystem sound_system)83 Layout MakeLayout(LoudspeakersSsConventionLayout::SoundSystem sound_system) {
84   return {.layout_type = Layout::kLayoutTypeLoudspeakersSsConvention,
85           .specific_layout =
86               LoudspeakersSsConventionLayout{.sound_system = sound_system}};
87 };
88 
89 using InternalTypeToApi_OutputLayout = TestWithParam<LayoutPair>;
90 
TEST_P(InternalTypeToApi_OutputLayout,ConvertsInternalStereoToOutputLayout)91 TEST_P(InternalTypeToApi_OutputLayout, ConvertsInternalStereoToOutputLayout) {
92   const auto& [expected_api_output_layout, internal_sound_system] = GetParam();
93   Layout internal_layout = MakeLayout(internal_sound_system);
94 
95   auto api_output_layout = InternalToApiType(internal_layout);
96 
97   EXPECT_THAT(api_output_layout, IsOk());
98   EXPECT_EQ(*api_output_layout, expected_api_output_layout);
99 }
100 
101 INSTANTIATE_TEST_SUITE_P(InternalTypeToApi_OutputLayout_Instantiation,
102                          InternalTypeToApi_OutputLayout,
103                          kApiOutputToInternalSoundSystemPairs);
104 }  // namespace
105 }  // namespace iamf_tools
106