Skip to content

Commit

Permalink
Add reading functionality for MixGainParamDefinition.
Browse files Browse the repository at this point in the history
This is necessary to read the full MixPresentationObu.

PiperOrigin-RevId: 628141412
  • Loading branch information
Googler authored and jwcullen committed Apr 25, 2024
1 parent 1305d1d commit 8797b4f
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
9 changes: 9 additions & 0 deletions iamf/obu/param_definitions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,15 @@ absl::Status MixGainParamDefinition::ValidateAndWrite(
return absl::OkStatus();
}

absl::Status MixGainParamDefinition::ReadAndValidate(ReadBitBuffer& rb) {
// The common part.
RETURN_IF_NOT_OK(ParamDefinition::ReadAndValidate(rb));

// The sub-class specific part.
RETURN_IF_NOT_OK(rb.ReadSigned16(default_mix_gain_));
return absl::OkStatus();
}

void MixGainParamDefinition::Print() const {
LOG(INFO) << "MixGainParamDefinition:";
ParamDefinition::Print();
Expand Down
7 changes: 7 additions & 0 deletions iamf/obu/param_definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,13 @@ class MixGainParamDefinition : public ParamDefinition {
*/
absl::Status ValidateAndWrite(WriteBitBuffer& wb) const override;

/*!\brief Reads from a buffer and validates the resulting output.
*
* \param rb Buffer to read from.
* \return `absl::OkStatus()` if successful. A specific status on failure.
*/
absl::Status ReadAndValidate(ReadBitBuffer& rb) override;

/*!\brief Prints the parameter definition.
*/
void Print() const override;
Expand Down
47 changes: 47 additions & 0 deletions iamf/obu/tests/param_definitions_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -628,5 +628,52 @@ TEST(ReadParamDefinitionTest, Mode0SubblockArray) {
EXPECT_TRUE(param_definition.ReadAndValidate(buffer).ok());
}

TEST(ReadMixGainParamDefinitionTest, DefaultMixGainMode1) {
MixGainParamDefinition param_definition;
std::vector<uint8_t> source = {
// Parameter ID.
0x00,
// Parameter Rate.
1,
// Param Definition Mode (upper bit), next 7 bits reserved.
0x80,
// Default Mix Gain.
0, 4};
ReadBitBuffer buffer(1024, &source);
EXPECT_TRUE(param_definition.ReadAndValidate(buffer).ok());
EXPECT_EQ(param_definition.GetType().value(),
ParamDefinition::kParameterDefinitionMixGain);
EXPECT_EQ(param_definition.default_mix_gain_, 4);
}

TEST(ReadMixGainParamDefinitionTest, DefaultMixGainWithSubblockArray) {
MixGainParamDefinition param_definition;
std::vector<uint8_t> source = {
// Parameter ID.
0x00,
// Parameter Rate.
1,
// Param Definition Mode (upper bit), next 7 bits reserved.
0x00,
// `duration` (64).
0xc0, 0x00,
// `constant_subblock_duration`.
0x00,
// `num_subblocks`
0x02,
// `subblock_durations`
// `subblock_duration`
40,
// `subblock_duration`
24,
// Default Mix Gain.
0, 3};
ReadBitBuffer buffer(1024, &source);
EXPECT_TRUE(param_definition.ReadAndValidate(buffer).ok());
EXPECT_EQ(param_definition.GetType().value(),
ParamDefinition::kParameterDefinitionMixGain);
EXPECT_EQ(param_definition.default_mix_gain_, 3);
}

} // namespace
} // namespace iamf_tools

0 comments on commit 8797b4f

Please sign in to comment.