• 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 #ifndef CLI_PARAMETER_BLOCK_PARTITIONER_H_
13 #define CLI_PARAMETER_BLOCK_PARTITIONER_H_
14 
15 #include <cstdint>
16 #include <list>
17 #include <vector>
18 
19 #include "absl/status/status.h"
20 #include "iamf/cli/proto/codec_config.pb.h"
21 #include "iamf/cli/proto/ia_sequence_header.pb.h"
22 #include "iamf/cli/proto/parameter_block.pb.h"
23 
24 namespace iamf_tools {
25 
26 /*!\brief Static functions to partition `ParameterBlockObuMetadata`.
27  *
28  * Useful when the `ParameterBlockObuMetadata` are specified as "virtual"
29  * parameter blocks which do not necessarily have durations and alignment that
30  * comply with the IAMF specification.
31  *
32  * This class provides functions to assist splitting
33  * `ParameterBlockObuMetadata`s which can be used to ensure they obey IAMF
34  * requirements (e.g. frame alignment, number of subblocks, etc.).
35  */
36 class ParameterBlockPartitioner {
37  public:
38   /*!\brief Finds the `constant_subblock_duration` for the input durations.
39    *
40    * \param subblock_durations Vector of subblock durations.
41    * \return `constant_subblock_duration` which results in the best bit-rate.
42    */
43   static uint32_t FindConstantSubblockDuration(
44       const std::vector<uint32_t>& subblock_durations);
45 
46   /*!\brief Finds the desired duration of partitioned parameter blocks.
47    *
48    * \param primary_profile Input primary profile version.
49    * \param codec_config_obu_metadata Input codec config OBU metadata.
50    * \return `absl::OkStatus()` on success. A specific status on failure.
51    */
52   static absl::Status FindPartitionDuration(
53       iamf_tools_cli_proto::ProfileVersion primary_profile,
54       const iamf_tools_cli_proto::CodecConfigObuMetadata&
55           codec_config_obu_metadata,
56       uint32_t& partition_duration);
57 
58   /*!\brief Partitions the input parameter block into a smaller one.
59    *
60    * \param full_parameter_block Input full parameter block OBU metadata.
61    * \param partitioned_start_time Start time of the output partitioned
62    *        parameter block.
63    * \param partitioned_end_time End time of the output partitioned parameter
64    *        block.
65    * \param partitioned_parameter_block Output partitioned parameter block OBU
66    *        metadata.
67    * \return `absl::OkStatus()` on success. A specific status on failure.
68    */
69   static absl::Status PartitionParameterBlock(
70       const iamf_tools_cli_proto::ParameterBlockObuMetadata&
71           full_parameter_block,
72       int32_t partitioned_start_time, int32_t partitioned_end_time,
73       iamf_tools_cli_proto::ParameterBlockObuMetadata&
74           partitioned_parameter_block);
75 
76   /*!\brief Partitions the input parameter block into frame-aligned ones.
77    *
78    * \param partition_duration Duration of each partitioned parameter block.
79    * \param full_parameter_block Input full parameter block.
80    * \param partitioned_parameter_blocks Output list to append partitioned
81    *        parameter blocks to.
82    * \return `absl::OkStatus()` on success. A specific status on failure.
83    */
84   static absl::Status PartitionFrameAligned(
85       uint32_t partition_duration,
86       const iamf_tools_cli_proto::ParameterBlockObuMetadata&
87           full_parameter_block,
88       std::list<iamf_tools_cli_proto::ParameterBlockObuMetadata>&
89           partitioned_parameter_blocks);
90 };
91 
92 }  // namespace iamf_tools
93 #endif  // CLI_PARAMETER_BLOCK_PARTITIONER_H_
94