• 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 
13 #ifndef CLI_ADM_TO_USER_METADATA_IAMF_USER_METADATA_GENERATOR_H_
14 #define CLI_ADM_TO_USER_METADATA_IAMF_USER_METADATA_GENERATOR_H_
15 
16 #include <cstdint>
17 #include <filesystem>
18 
19 #include "absl/status/status.h"
20 #include "absl/status/statusor.h"
21 #include "absl/strings/string_view.h"
22 #include "iamf/cli/adm_to_user_metadata/adm/adm_elements.h"
23 #include "iamf/cli/adm_to_user_metadata/adm/format_info_chunk.h"
24 #include "iamf/cli/proto/ia_sequence_header.pb.h"
25 #include "iamf/cli/proto/user_metadata.pb.h"
26 
27 namespace iamf_tools {
28 namespace adm_to_user_metadata {
29 
30 class UserMetadataGenerator {
31  public:
32   /*!\brief Writes a `UserMetadata` as a text proto to a file.
33    *
34    * \param write_binary_proto `true` to write a binary proto, `false` to write
35    *        a text proto.
36    * \param path Path to write the data to.
37    * \param user_metadata User metadata to write. The filename is determined by
38    *        the inner `file_name_prefix` field with a suffix of `.binpb` for
39    *        binary protos or `.textproto` for text protos.
40    * \return `absl::OkStatus()` if the write was successful a specific error
41    *         otherwise.
42    */
43   static absl::Status WriteUserMetadataToFile(
44       bool write_binary_proto, const std::filesystem::path& path,
45       const iamf_tools_cli_proto::UserMetadata& user_metadata);
46 
47   /*!\brief Constructor.
48    *
49    * \param adm ADM to use.
50    * \param format_info Format info chunk to use.
51    * \param max_frame_duration_ms Maximum frame duration in milliseconds. The
52    *        actual frame duration may be shorter due to rounding.
53    */
UserMetadataGenerator(const ADM & adm,const FormatInfoChunk & format_info,int32_t max_frame_duration)54   UserMetadataGenerator(const ADM& adm, const FormatInfoChunk& format_info,
55                         int32_t max_frame_duration)
56       : adm_(adm),
57         format_info_(format_info),
58         max_frame_duration_(max_frame_duration) {};
59 
60   /*!\brief Generates a `UserMetadata` proto.
61    *
62    * \param profile_version IAMF output specification version to use for
63    *        textproto generation.
64    * \param file_prefix File prefix to use when naming output wav files.
65    * \return Proto based on the constructor arguments or a specific error code
66    *         on failure.
67    */
68   absl::StatusOr<iamf_tools_cli_proto::UserMetadata> GenerateUserMetadata(
69       iamf_tools_cli_proto::ProfileVersion profile_version,
70       absl::string_view file_prefix) const;
71 
72  private:
73   const ADM& adm_;
74   const FormatInfoChunk& format_info_;
75   const int32_t max_frame_duration_;
76 };
77 
78 }  // namespace adm_to_user_metadata
79 }  // namespace iamf_tools
80 
81 #endif  // CLI_ADM_TO_USER_METADATA_IAMF_USER_METADATA_GENERATOR_H_
82