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 #ifndef OBU_RECON_GAIN_INFO_PARAMETER_DATA_H_ 13 #define OBU_RECON_GAIN_INFO_PARAMETER_DATA_H_ 14 15 #include <array> 16 #include <cstdint> 17 #include <optional> 18 #include <vector> 19 20 #include "absl/status/status.h" 21 #include "iamf/common/read_bit_buffer.h" 22 #include "iamf/common/write_bit_buffer.h" 23 #include "iamf/obu/parameter_data.h" 24 #include "iamf/obu/types.h" 25 26 namespace iamf_tools { 27 28 /*!\brief An element of the vector inside the `ReconGainInfoParameterData`. 29 * 30 * This is not present in the bitstream when 31 * `recon_gain_is_present_flags(i) == 0` in the associated Audio Element OBU. 32 */ 33 struct ReconGainElement { 34 /*!\brief A `DecodedUleb128` bitmask to determine channels with recon gain. 35 * 36 * Apply the bitmask to the `ReconGainElement::recon_gain_flag` to determine 37 * if recon gain should be applied. Values are offset from the spec as they 38 * will be applied to a `DecodedUleb128` instead of a serialized LEB128. 39 */ 40 enum ReconGainFlagBitmask : DecodedUleb128 { 41 kReconGainFlagL = 0x01, 42 kReconGainFlagC = 0x02, 43 kReconGainFlagR = 0x04, 44 kReconGainFlagLss = 0x08, 45 kReconGainFlagRss = 0x10, 46 kReconGainFlagLtf = 0x20, 47 kReconGainFlagRtf = 0x40, 48 kReconGainFlagLrs = 0x80, 49 kReconGainFlagRrs = 0x100, 50 kReconGainFlagLtb = 0x200, 51 kReconGainFlagRtb = 0x400, 52 kReconGainFlagLfe = 0x800, 53 }; 54 55 // Apply the `ReconGainFlagBitmaskDecodedUleb` bitmask to determine which 56 // channels recon gain should be applied to. 57 DecodedUleb128 recon_gain_flag; 58 59 // Value is only present in the stream for channels with Recon Gain flag set. 60 std::array<uint8_t, 12> recon_gain; 61 }; 62 63 struct ReconGainInfoParameterData : public ParameterData { 64 /*!\brief Default constructor.*/ 65 ReconGainInfoParameterData() = default; 66 67 /*!\brief Overridden destructor.*/ 68 ~ReconGainInfoParameterData() override = default; 69 70 /*!\brief Reads and validates a `ReconGainInfoParameterData` from a buffer. 71 * 72 * \param rb Buffer to read from. 73 * \return `absl::OkStatus()`. A specific error code on failure. 74 */ 75 absl::Status ReadAndValidate(ReadBitBuffer& rb) override; 76 77 /*!\brief Validates and writes to a buffer. 78 * 79 * \param wb Buffer to write to. 80 * \return `absl::OkStatus()` if successful. A specific status on failure. 81 */ 82 absl::Status Write(WriteBitBuffer& wb) const override; 83 84 /*!\brief Prints the recon gain info parameter data. 85 */ 86 void Print() const override; 87 88 // Vector of length `num_layers` in the Audio associated Audio Element OBU. 89 // Each element may hold no value if the corresponding 90 // `recon_gain_is_present_flag` is false. 91 std::vector<std::optional<ReconGainElement>> recon_gain_elements; 92 93 // TODO(b/399599739): Remove. Pass the same information to `ReadAndValidate()` 94 // instead. 95 // Whether recon gain is present per layer; only used in `ReadAndValidate()` 96 // and is not present in bitstreams. 97 std::vector<bool> recon_gain_is_present_flags; 98 }; 99 100 } // namespace iamf_tools 101 102 #endif // OBU_RECON_GAIN_INFO_PARAMETER_DATA_H_ 103