• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022, 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 OBU_IA_SEQUENCE_HEADER_H_
13 #define OBU_IA_SEQUENCE_HEADER_H_
14 
15 #include <cstdint>
16 
17 #include "absl/status/status.h"
18 #include "absl/status/statusor.h"
19 #include "iamf/common/read_bit_buffer.h"
20 #include "iamf/common/write_bit_buffer.h"
21 #include "iamf/obu/obu_base.h"
22 #include "iamf/obu/obu_header.h"
23 
24 namespace iamf_tools {
25 
26 /*!\brief An 8-bit enum for the profile. */
27 enum class ProfileVersion : uint8_t {
28   kIamfSimpleProfile = 0,
29   kIamfBaseProfile = 1,
30   kIamfBaseEnhancedProfile = 2,
31   kIamfReserved255Profile = 255
32 };
33 
34 class IASequenceHeaderObu : public ObuBase {
35  public:
36   /*!\brief The spec requires the `ia_code` field to be: "iamf".
37    *
38    * This four-character code (4CC) is used to determine the start of an IA
39    * Sequence.
40    */
41   static constexpr uint32_t kIaCode = 0x69616d66;  // "iamf".
42 
43   /*!\brief Constructor. */
IASequenceHeaderObu(const ObuHeader & header,uint32_t ia_code,ProfileVersion primary_profile,ProfileVersion additional_profile)44   IASequenceHeaderObu(const ObuHeader& header, uint32_t ia_code,
45                       ProfileVersion primary_profile,
46                       ProfileVersion additional_profile)
47       : ObuBase(header, kObuIaSequenceHeader),
48         ia_code_(ia_code),
49         primary_profile_(primary_profile),
50         additional_profile_(additional_profile) {}
51 
52   IASequenceHeaderObu() = default;
53 
54   /*!\brief Creates a `IASequenceHeaderObu` from a `ReadBitBuffer`.
55    *
56    * This function is designed to be used from the perspective of the decoder.
57    * It will call `ReadAndValidatePayload` in order to read from the buffer;
58    * therefore it can fail.
59    *
60    * \param header `ObuHeader` of the OBU.
61    * \param payload_size Size of the obu payload in bytes.
62    * \param rb `ReadBitBuffer` where the `IASequenceHeaderObu` data is stored.
63    *        Data read from the buffer is consumed.
64    * \return `IASequenceHeaderObu` on success. A specific status on failure.
65    */
66   static absl::StatusOr<IASequenceHeaderObu> CreateFromBuffer(
67       const ObuHeader& header, int64_t payload_size, ReadBitBuffer& rb);
68 
69   /*!\brief Destructor. */
70   ~IASequenceHeaderObu() override = default;
71 
72   friend bool operator==(const IASequenceHeaderObu& lhs,
73                          const IASequenceHeaderObu& rhs) = default;
74 
75   /*!\brief Prints logging information about the OBU.*/
76   void PrintObu() const override;
77 
78   /*!\brief Validates the OBU.
79    *
80    * \return `absl::OkStatus()` if successful. A specific status on failure.
81    */
82   absl::Status Validate() const;
83 
84   /*!\brief Gets the IA Code of the OBU.
85    *
86    * \return IA Code of the OBU.
87    */
GetIaCode()88   uint32_t GetIaCode() const { return ia_code_; }
89 
90   /*!\brief Gets the primary profile of the OBU.
91    *
92    * \return primary profile of the OBU.
93    */
GetPrimaryProfile()94   ProfileVersion GetPrimaryProfile() const { return primary_profile_; }
95 
96   /*!\brief Gets the additional profile of the OBU.
97    *
98    * \return additional profile of the OBU.
99    */
GetAdditionalProfile()100   ProfileVersion GetAdditionalProfile() const { return additional_profile_; }
101 
102  private:
103   uint32_t ia_code_;
104   ProfileVersion primary_profile_;
105   ProfileVersion additional_profile_;
106 
107   // Used only by the factory create function.
IASequenceHeaderObu(const ObuHeader & header)108   explicit IASequenceHeaderObu(const ObuHeader& header)
109       : ObuBase(header, kObuIaSequenceHeader),
110         ia_code_(kIaCode),
111         primary_profile_(ProfileVersion::kIamfBaseProfile),
112         additional_profile_(ProfileVersion::kIamfBaseProfile) {}
113 
114   /*!\brief Writes the OBU payload to the buffer.
115    *
116    * \param wb Buffer to write to.
117    * \return `absl::OkStatus()` if OBU is valid. A specific status on
118    */
119   absl::Status ValidateAndWritePayload(WriteBitBuffer& wb) const override;
120 
121   /*!\brief Reads the OBU payload from the buffer.
122    *
123    * \param payload_size Size of the obu payload in bytes.
124    * \param rb Buffer to read from.
125    * \return `absl::OkStatus()` if the payload is valid. A specific status on
126    *         failure.
127    */
128   absl::Status ReadAndValidatePayloadDerived(int64_t payload_size,
129                                              ReadBitBuffer& rb) override;
130 };
131 }  // namespace iamf_tools
132 
133 #endif  // OBU_IA_SEQUENCE_HEADER_H_
134