Skip to content

Commit

Permalink
Add UpdateReconGainState() to ParametersManager.
Browse files Browse the repository at this point in the history
This will be used to update the state of recon gain parameters for an audio element.

PiperOrigin-RevId: 657634896
  • Loading branch information
Googler authored and jwcullen committed Jul 31, 2024
1 parent f6694c8 commit fdd134f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
41 changes: 41 additions & 0 deletions iamf/cli/parameters_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,45 @@ absl::Status ParametersManager::UpdateDemixingState(
return absl::OkStatus();
}

// TODO(b/356393945): Refactor to use a template function.
absl::Status ParametersManager::UpdateReconGainState(
DecodedUleb128 audio_element_id, int32_t expected_timestamp) {
const auto recon_gain_states_iter = recon_gain_states_.find(audio_element_id);
if (recon_gain_states_iter == recon_gain_states_.end()) {
// No recon gain parameter definition found for the audio element ID, so
// nothing to update.
return absl::OkStatus();
}

// Validate the timestamps before updating.
auto& recon_gain_state = recon_gain_states_iter->second;

// Using `.at()` here is safe because if the recon gain state exists for the
// `audio_element_id`, an entry in `recon_gain_parameter_blocks_` with the key
// `recon_gain_state.param_definition->parameter_id_` has already been
// created during `Initialize()`.
auto& parameter_block = recon_gain_parameter_blocks_.at(
recon_gain_state.param_definition->parameter_id_);
if (parameter_block == nullptr) {
// No parameter block found for this ID. Do not validate the timestamp
// or update anything else.
return absl::OkStatus();
}

if (expected_timestamp != recon_gain_state.next_timestamp) {
return absl::InvalidArgumentError(absl::StrCat(
"Mismatching timestamps for recon gain parameters: (",
recon_gain_state.next_timestamp, " vs ", expected_timestamp, ")"));
}

// Update the next timestamp for the next frame.
recon_gain_state.next_timestamp = parameter_block->end_timestamp;

// Clear out the parameter block, which should not be used before a new
// one is added via `AddReconGainParameterBlock()`.
parameter_block = nullptr;

return absl::OkStatus();
}

} // namespace iamf_tools
13 changes: 13 additions & 0 deletions iamf/cli/parameters_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,19 @@ class ParametersManager {
absl::Status UpdateDemixingState(DecodedUleb128 audio_element_id,
int32_t expected_timestamp);

/*!\brief Updates the state of recon gain parameters for an audio element.
*
* Also validates the timestamp is as expected.
*
* \param audio_element_id Audio Element ID whose corresponding recon gain
* state are to be updated.
* \param expected_timestamp Expected timestamp of the next set of
* recon gain parameter blocks.
* \return `absl::OkStatus()` on success. A specific status on failure.
*/
absl::Status UpdateReconGainState(DecodedUleb128 audio_element_id,
int32_t expected_timestamp);

private:
// State used when generating demixing parameters for an audio element.
struct DemixingState {
Expand Down

0 comments on commit fdd134f

Please sign in to comment.