• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
13 #ifndef CLI_PROTO_CONVERSION_PROTO_TO_OBU_CODEC_CONFIG_GENERATOR_H_
14 #define CLI_PROTO_CONVERSION_PROTO_TO_OBU_CODEC_CONFIG_GENERATOR_H_
15 
16 #include <cstdint>
17 
18 #include "absl/container/flat_hash_map.h"
19 #include "absl/status/status.h"
20 #include "iamf/cli/proto/codec_config.pb.h"
21 #include "iamf/obu/codec_config.h"
22 #include "src/google/protobuf/repeated_ptr_field.h"
23 
24 namespace iamf_tools {
25 
26 class CodecConfigGenerator {
27  public:
28   /*!\brief Constructor.
29    * \param codec_config_metadata Input codec config metadata.
30    */
CodecConfigGenerator(const::google::protobuf::RepeatedPtrField<iamf_tools_cli_proto::CodecConfigObuMetadata> & codec_config_metadata)31   CodecConfigGenerator(
32       const ::google::protobuf::RepeatedPtrField<
33           iamf_tools_cli_proto::CodecConfigObuMetadata>& codec_config_metadata)
34       : codec_config_metadata_(codec_config_metadata) {}
35 
36   /*!\brief Generates a map of Codec Config OBUs from the input metadata.
37    *
38    * The generator only performs enough validation required to construct the
39    * OBU; it validates that enumeration values are known and casting of fields
40    * does not result in lost information. It does not validate IAMF requirements
41    * or restrictions of the fields which is typically performed in functions of
42    * the OBU class.
43    *
44    * Performing minimal validation allows OBUs which are not compliant with
45    * IAMF to be generated. These can be used to create illegal streams for
46    * debugging purposes.
47    *
48    * \param codec_config_obus Map of Codec Config ID to generated Codec Config
49    *        OBUs.
50    * \return `absl::OkStatus()` on success. `absl::InvalidArgumentError()` if
51    *         invalid values of enumerations are used or if casting input fields
52    *         would result in lost information. `kIamfInvalidBitstream` if
53    *         `codec_id` is unrecognized.
54    */
55   absl::Status Generate(
56       absl::flat_hash_map<uint32_t, CodecConfigObu>& codec_config_obus);
57 
58  private:
59   const ::google::protobuf::RepeatedPtrField<
60       iamf_tools_cli_proto::CodecConfigObuMetadata>
61       codec_config_metadata_;
62 };
63 
64 }  // namespace iamf_tools
65 
66 #endif  // CLI_PROTO_CONVERSION_PROTO_TO_OBU_CODEC_CONFIG_GENERATOR_H_
67