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 #include "iamf/cli/iamf_components.h"
13
14 #include <filesystem>
15 #include <memory>
16 #include <string>
17 #include <vector>
18
19 #include "absl/log/log.h"
20 #include "absl/strings/str_cat.h"
21 #include "absl/strings/string_view.h"
22 #include "iamf/cli/loudness_calculator_factory_base.h"
23 #include "iamf/cli/obu_sequencer_base.h"
24 #include "iamf/cli/obu_sequencer_iamf.h"
25 #include "iamf/cli/proto/test_vector_metadata.pb.h"
26 #include "iamf/cli/proto/user_metadata.pb.h"
27 #include "iamf/cli/proto_conversion/proto_utils.h"
28 #include "iamf/cli/renderer_factory.h"
29
30 namespace iamf_tools {
31
32 namespace {
33
34 constexpr absl::string_view kOmitIamfFile = "";
35
36 }
37
CreateRendererFactory()38 std::unique_ptr<RendererFactoryBase> CreateRendererFactory() {
39 // Skip rendering.
40 return nullptr;
41 }
42
43 std::unique_ptr<LoudnessCalculatorFactoryBase>
CreateLoudnessCalculatorFactory()44 CreateLoudnessCalculatorFactory() {
45 // Skip loudness calculation.
46 return nullptr;
47 }
48
CreateObuSequencers(const iamf_tools_cli_proto::UserMetadata & user_metadata,const std::string & output_iamf_directory,const bool include_temporal_delimiters)49 std::vector<std::unique_ptr<ObuSequencerBase>> CreateObuSequencers(
50 const iamf_tools_cli_proto::UserMetadata& user_metadata,
51 const std::string& output_iamf_directory,
52 const bool include_temporal_delimiters) {
53 const auto leb_generator =
54 CreateLebGenerator(user_metadata.test_vector_metadata().leb_generator());
55 if (leb_generator == nullptr) {
56 LOG(ERROR) << "Failed to create LebGenerator.";
57 return {};
58 }
59
60 std::vector<std::unique_ptr<ObuSequencerBase>> obu_sequencers;
61 const std::string& prefix =
62 user_metadata.test_vector_metadata().file_name_prefix();
63
64 // Create an OBU sequencer that writes to a standalone IAMF file.
65 const std::string iamf_filename =
66 prefix.empty() ? std::string(kOmitIamfFile)
67 : (std::filesystem::path(output_iamf_directory) /
68 std::filesystem::path(absl::StrCat(prefix, ".iamf")))
69 .string();
70 obu_sequencers.emplace_back(std::make_unique<ObuSequencerIamf>(
71 iamf_filename, include_temporal_delimiters, *leb_generator));
72
73 return obu_sequencers;
74 }
75
76 } // namespace iamf_tools
77