• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <filesystem>
13 #include <string>
14 #include <vector>
15 
16 // [internal] Placeholder for get runfiles header.
17 #include "absl/log/log.h"
18 #include "absl/status/status_matchers.h"
19 #include "absl/strings/string_view.h"
20 #include "gmock/gmock.h"
21 #include "gtest/gtest.h"
22 #include "iamf/cli/encoder_main_lib.h"
23 #include "iamf/cli/proto/audio_frame.pb.h"
24 #include "iamf/cli/proto/test_vector_metadata.pb.h"
25 #include "iamf/cli/proto/user_metadata.pb.h"
26 #include "iamf/cli/tests/cli_test_utils.h"
27 
28 namespace iamf_tools {
29 namespace {
30 
31 using ::absl_testing::IsOk;
32 constexpr absl::string_view kIgnoredOutputPath = "";
33 
34 struct TextprotoTemplateTestCase {
35   absl::string_view textproto_filename;
36   std::vector<absl::string_view> wav_filenames;
37 };
38 
39 using TextprotoTemplate = ::testing::TestWithParam<TextprotoTemplateTestCase>;
40 
41 // Validate that the textproto templates will encode successful.
TEST_P(TextprotoTemplate,ValidateTextprotos)42 TEST_P(TextprotoTemplate, ValidateTextprotos) {
43   const TextprotoTemplateTestCase& test_case = GetParam();
44 
45   // Get the location of test wav files.
46   static const auto input_wav_dir =
47       std::filesystem::current_path() / std::string("iamf/cli/testdata");
48 
49   // Get the textproto to test.
50   const auto user_metadata_filename =
51       std::filesystem::current_path() /
52       std::string("iamf/cli/textproto_templates") /
53       test_case.textproto_filename;
54   iamf_tools_cli_proto::UserMetadata user_metadata;
55   ParseUserMetadataAssertSuccess(user_metadata_filename.string(),
56                                  user_metadata);
57 
58   // Clear `file_name_prefix`; we only care about the status and not the output
59   // files.
60   user_metadata.mutable_test_vector_metadata()->clear_file_name_prefix();
61   LOG(INFO) << "Testing with " << test_case.textproto_filename;
62 
63   // Replace the wav filenames.
64   ASSERT_EQ(user_metadata.audio_frame_metadata_size(),
65             test_case.wav_filenames.size());
66   for (int i = 0; i < test_case.wav_filenames.size(); ++i) {
67     user_metadata.mutable_audio_frame_metadata(i)->set_wav_filename(
68         test_case.wav_filenames[i]);
69   }
70 
71   // Call encoder and check that the encoding was successful.
72   const absl::Status result =
73       iamf_tools::TestMain(user_metadata, input_wav_dir.string().c_str(),
74                            std::string(kIgnoredOutputPath));
75 
76   EXPECT_THAT(result, IsOk()) << "File= " << test_case.textproto_filename;
77 }
78 
79 INSTANTIATE_TEST_SUITE_P(PcmStereo, TextprotoTemplate,
80                          testing::ValuesIn<TextprotoTemplateTestCase>(
81                              {{"stereo_pcm24bit.textproto",
82                                std::vector<absl::string_view>{
83                                    "sawtooth_10000_stereo_48khz_s24le.wav"}}}));
84 
85 INSTANTIATE_TEST_SUITE_P(OpusStereo, TextprotoTemplate,
86                          testing::ValuesIn<TextprotoTemplateTestCase>(
87                              {{"stereo_opus.textproto",
88                                std::vector<absl::string_view>{
89                                    "sawtooth_10000_stereo_48khz_s24le.wav"}}}));
90 
91 INSTANTIATE_TEST_SUITE_P(Pcm5dot1, TextprotoTemplate,
92                          testing::ValuesIn<TextprotoTemplateTestCase>(
93                              {{"5dot1_pcm24bit.textproto",
94                                std::vector<absl::string_view>{
95                                    "Mechanism_5s.wav"}}}));
96 
97 INSTANTIATE_TEST_SUITE_P(Opus5dot1, TextprotoTemplate,
98                          testing::ValuesIn<TextprotoTemplateTestCase>(
99                              {{"5dot1_opus.textproto",
100                                std::vector<absl::string_view>{
101                                    "Mechanism_5s.wav"}}}));
102 
103 INSTANTIATE_TEST_SUITE_P(Pcm5dot1dot2, TextprotoTemplate,
104                          testing::ValuesIn<TextprotoTemplateTestCase>(
105                              {{"5dot1dot2_pcm24bit.textproto",
106                                std::vector<absl::string_view>{
107                                    "Mechanism_5s.wav"}}}));
108 
109 INSTANTIATE_TEST_SUITE_P(Opus5dot1dot2, TextprotoTemplate,
110                          testing::ValuesIn<TextprotoTemplateTestCase>(
111                              {{"5dot1dot2_opus.textproto",
112                                std::vector<absl::string_view>{
113                                    "Mechanism_5s.wav"}}}));
114 
115 INSTANTIATE_TEST_SUITE_P(Pcm7dot1dot4, TextprotoTemplate,
116                          testing::ValuesIn<TextprotoTemplateTestCase>(
117                              {{"7dot1dot4_pcm24bit.textproto",
118                                std::vector<absl::string_view>{
119                                    "Mechanism_5s.wav"}}}));
120 
121 INSTANTIATE_TEST_SUITE_P(Opus7dot1dot4, TextprotoTemplate,
122                          testing::ValuesIn<TextprotoTemplateTestCase>(
123                              {{"7dot1dot4_opus.textproto",
124                                std::vector<absl::string_view>{
125                                    "Mechanism_5s.wav"}}}));
126 
127 INSTANTIATE_TEST_SUITE_P(PcmFoa, TextprotoTemplate,
128                          testing::ValuesIn<TextprotoTemplateTestCase>(
129                              {{"1OA_pcm24bit.textproto",
130                                std::vector<absl::string_view>{
131                                    "sawtooth_10000_foa_48khz.wav"}}}));
132 
133 INSTANTIATE_TEST_SUITE_P(OpusFoa, TextprotoTemplate,
134                          testing::ValuesIn<TextprotoTemplateTestCase>(
135                              {{"1OA_opus.textproto",
136                                std::vector<absl::string_view>{
137                                    "sawtooth_10000_foa_48khz.wav"}}}));
138 
139 INSTANTIATE_TEST_SUITE_P(PcmToa, TextprotoTemplate,
140                          testing::ValuesIn<TextprotoTemplateTestCase>(
141                              {{"3OA_pcm24bit.textproto",
142                                std::vector<absl::string_view>{
143                                    "sawtooth_8000_toa_48khz.wav"}}}));
144 
145 INSTANTIATE_TEST_SUITE_P(OpusToa, TextprotoTemplate,
146                          testing::ValuesIn<TextprotoTemplateTestCase>(
147                              {{"3OA_opus.textproto",
148                                std::vector<absl::string_view>{
149                                    "sawtooth_8000_toa_48khz.wav"}}}));
150 
151 INSTANTIATE_TEST_SUITE_P(PcmFoaAndStereo, TextprotoTemplate,
152                          testing::ValuesIn<TextprotoTemplateTestCase>(
153                              {{"1OA_and_stereo_pcm24bit.textproto",
154                                std::vector<absl::string_view>{
155                                    "sawtooth_10000_foa_48khz.wav",
156                                    "sawtooth_10000_stereo_48khz_s24le.wav"}}}));
157 
158 INSTANTIATE_TEST_SUITE_P(OpusFoaAndStereo, TextprotoTemplate,
159                          testing::ValuesIn<TextprotoTemplateTestCase>(
160                              {{"1OA_and_stereo_opus.textproto",
161                                std::vector<absl::string_view>{
162                                    "sawtooth_10000_foa_48khz.wav",
163                                    "sawtooth_10000_stereo_48khz_s24le.wav"}}}));
164 
165 INSTANTIATE_TEST_SUITE_P(PcmToaAndStereo, TextprotoTemplate,
166                          testing::ValuesIn<TextprotoTemplateTestCase>(
167                              {{"3OA_and_stereo_pcm24bit.textproto",
168                                std::vector<absl::string_view>{
169                                    "sawtooth_8000_toa_48khz.wav",
170                                    "sawtooth_10000_stereo_48khz_s24le.wav"}}}));
171 
172 INSTANTIATE_TEST_SUITE_P(OpusToaAndStereo, TextprotoTemplate,
173                          testing::ValuesIn<TextprotoTemplateTestCase>(
174                              {{"3OA_and_stereo_opus.textproto",
175                                std::vector<absl::string_view>{
176                                    "sawtooth_8000_toa_48khz.wav",
177                                    "sawtooth_10000_stereo_48khz_s24le.wav"}}}));
178 
179 }  // namespace
180 }  // namespace iamf_tools
181