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_MIX_GAIN_PARAMETER_DATA_H_ 13 #define OBU_MIX_GAIN_PARAMETER_DATA_H_ 14 15 #include <cstdint> 16 #include <variant> 17 18 #include "absl/status/status.h" 19 #include "iamf/common/read_bit_buffer.h" 20 #include "iamf/common/write_bit_buffer.h" 21 #include "iamf/obu/parameter_data.h" 22 #include "iamf/obu/types.h" 23 24 namespace iamf_tools { 25 /*!\brief The metadata to describe animation of type `kAnimateStep`. */ 26 struct AnimationStepInt16 { 27 friend bool operator==(const AnimationStepInt16& lhs, 28 const AnimationStepInt16& rhs) = default; 29 30 /*!\brief Prints the `AnimationStepInt16`. 31 */ 32 void Print() const; 33 34 /*!\brief Validates and writes to a buffer. 35 * 36 * \param wb Buffer to write to. 37 * \return `absl::OkStatus()` if successful. A specific status on failure. 38 */ 39 absl::Status ValidateAndWrite(WriteBitBuffer& wb) const; 40 41 /*!\brief Reads and validates the `AnimationStepInt16` from a buffer. 42 * 43 * \param rb Buffer to read from. 44 * \return `absl::OkStatus()` unless the buffer is exhausted during reading. 45 */ 46 absl::Status ReadAndValidate(ReadBitBuffer& rb); 47 48 int16_t start_point_value; 49 }; 50 51 /*!\brief The metadata to describe animation of type `kAnimateLinear`. */ 52 struct AnimationLinearInt16 { 53 friend bool operator==(const AnimationLinearInt16& lhs, 54 const AnimationLinearInt16& rhs) = default; 55 56 /*!\brief Prints the `AnimationLinearInt16`. 57 */ 58 void Print() const; 59 60 /*!\brief Validates and writes to a buffer. 61 * 62 * \param wb Buffer to write to. 63 * \return `absl::OkStatus()` if successful. A specific status on failure. 64 */ 65 absl::Status ValidateAndWrite(WriteBitBuffer& wb) const; 66 67 /*!\brief Reads and validates the `AnimationLinearInt16` from a buffer. 68 * 69 * \param rb Buffer to read from. 70 * \return `absl::OkStatus()` unless the buffer is exhausted during reading. 71 */ 72 absl::Status ReadAndValidate(ReadBitBuffer& rb); 73 74 int16_t start_point_value; 75 int16_t end_point_value; 76 }; 77 78 /*!\brief The metadata to describe animation of type `kAnimateBezier`. */ 79 struct AnimationBezierInt16 { 80 friend bool operator==(const AnimationBezierInt16& lhs, 81 const AnimationBezierInt16& rhs) = default; 82 83 /*!\brief Prints the `AnimationBezierInt16`. 84 */ 85 void Print() const; 86 87 /*!\brief Validates and writes to a buffer. 88 * 89 * \param wb Buffer to write to. 90 * \return `absl::OkStatus()` if successful. A specific status on failure. 91 */ 92 absl::Status ValidateAndWrite(WriteBitBuffer& wb) const; 93 94 /*!\brief Reads and validates the `AnimationBezierInt16` from a buffer. 95 * 96 * \param rb Buffer to read from. 97 * \return `absl::OkStatus()` unless the buffer is exhausted during reading. 98 */ 99 absl::Status ReadAndValidate(ReadBitBuffer& rb); 100 101 int16_t start_point_value; 102 int16_t end_point_value; 103 int16_t control_point_value; 104 uint8_t control_point_relative_time; // Q0.8 format. 105 }; 106 107 struct MixGainParameterData : public ParameterData { 108 /*!\brief A `DecodedUleb128` enum for the type of animation to apply. */ 109 enum AnimationType : DecodedUleb128 { 110 kAnimateStep = 0, 111 kAnimateLinear = 1, 112 kAnimateBezier = 2, 113 }; 114 115 /*!\brief Constructor. 116 * 117 * \param input_animation_type Input animation type. 118 * \param input_param_data Input metadata describing the animation type. 119 */ MixGainParameterDataMixGainParameterData120 MixGainParameterData( 121 AnimationType input_animation_type, 122 const std::variant<AnimationStepInt16, AnimationLinearInt16, 123 AnimationBezierInt16>& input_param_data) 124 : ParameterData(), 125 animation_type(input_animation_type), 126 param_data(input_param_data) {} 127 MixGainParameterData() = default; 128 129 /*!\brief Overridden destructor.*/ 130 ~MixGainParameterData() override = default; 131 132 /*!\brief Reads and validates a `MixGainParameterData` from a buffer. 133 * 134 * \param rb Buffer to read from. 135 * \return `absl::OkStatus()`. Or a specific error code on failure. 136 */ 137 absl::Status ReadAndValidate(ReadBitBuffer& rb) override; 138 139 /*!\brief Validates and writes to a buffer. 140 * 141 * \param wb Buffer to write to. 142 * \return `absl::OkStatus()` if successful. A specific status on failure. 143 */ 144 absl::Status Write(WriteBitBuffer& wb) const override; 145 146 /*!\brief Prints the mix gain parameter data. 147 */ 148 void Print() const override; 149 150 AnimationType animation_type; // Serialized to a ULEB128. 151 152 // The active field depends on `animation_type`. 153 std::variant<AnimationStepInt16, AnimationLinearInt16, AnimationBezierInt16> 154 param_data; 155 }; 156 157 } // namespace iamf_tools 158 159 #endif // OBU_MIX_GAIN_PARAMETER_DATA_H_ 160