src/media/audio/audio_core/thermal_agent.cc
// Constructs a map {target_name: configs_by_thermal_state}, where configs_by_thermal_state
// is a vector of configurations for the target indexed by thermal state.
Constructs a map {target_name: configs_by_thermal_state}, where configs_by_thermal_state
is a vector of configurations for the target indexed by thermal state.
Constructs a map { target_name : configs_by_thermal_state } where configs_by_thermal_state is a vector of configurations for the target indexed by thermal state .
std::unordered_map<std::string, std::vector<std::string>> PopulateTargetConfigurations(
    const ThermalConfig& thermal_config, const DeviceConfig& device_config) {
  const auto& entries = thermal_config.entries();
  const size_t num_thermal_states = entries.size() + 1;
  std::unordered_map<std::string, std::vector<std::string>> result;
  std::unordered_set<std::string> bad_targets;
  for (size_t i = 0; i < entries.size(); i++) {
    const auto& entry = entries[i];
    for (const auto& transition : entry.state_transitions()) {
      const auto& target_name = transition.target_name();
      if (bad_targets.find(target_name) != bad_targets.end()) {
        continue;
      }
      auto configs_it = result.find(target_name);
      if (configs_it == result.end()) {
        auto nominal_config = FindNominalConfigForTarget(target_name, device_config);
        if (!nominal_config.has_value()) {
          bad_targets.insert(target_name);
          FX_LOGS(ERROR) << "Thermal config references unknown target '" << target_name << "'.";
          continue;
        }
        configs_it = result.insert({target_name, {}}).first;
        auto& configs = configs_it->second;
        configs.reserve(num_thermal_states);
        configs.push_back(nominal_config.value());
      }
      std::vector<std::string>& configs = configs_it->second;
      for (size_t j = configs.size(); j < i + 1; j++) {
        configs.push_back(configs.back());
      }
      configs.push_back(transition.config());
    }
  }
  for (auto& entry : result) {
    auto& configs = entry.second;
    if (configs.size() < num_thermal_states) {
      for (size_t j = configs.size(); j < num_thermal_states + 1; j++) {
        configs.push_back(configs.back());
      }
    }
  }
  return result;
}
std :: unordered_map < std :: string , std :: vector < std :: string > > PopulateTargetConfigurations ( const ThermalConfig & thermal_config , const DeviceConfig & device_config ) { const auto & entries = thermal_config . entries ( ) ; const size_t num_thermal_states = entries . size ( ) + 1 ; std :: unordered_map < std :: string , std :: vector < std :: string > > result ; std :: unordered_set < std :: string > bad_targets ; for ( size_t i = 0 ; i < entries . size ( ) ; i ++ ) { const auto & entry = entries [ i ] ; for ( const auto & transition : entry . state_transitions ( ) ) { const auto & target_name = transition . target_name ( ) ; if ( bad_targets . find ( target_name ) != bad_targets . end ( ) ) { continue ; } auto configs_it = result . find ( target_name ) ; if ( configs_it == result . end ( ) ) { auto nominal_config = FindNominalConfigForTarget ( target_name , device_config ) ; if ( ! nominal_config . has_value ( ) ) { bad_targets . insert ( target_name ) ; FX_LOGS ( ERROR ) << " " << target_name << " " ; continue ; } configs_it = result . insert ( { target_name , { } } ) . first ; auto & configs = configs_it -> second ; configs . reserve ( num_thermal_states ) ; configs . push_back ( nominal_config . value ( ) ) ; } std :: vector < std :: string > & configs = configs_it -> second ; for ( size_t j = configs . size ( ) ; j < i + 1 ; j ++ ) { configs . push_back ( configs . back ( ) ) ; } configs . push_back ( transition . config ( ) ) ; } } for ( auto & entry : result ) { auto & configs = entry . second ; if ( configs . size ( ) < num_thermal_states ) { for ( size_t j = configs . size ( ) ; j < num_thermal_states + 1 ; j ++ ) { configs . push_back ( configs . back ( ) ) ; } } } return result ; }
Constructs a map {target_name: configs_by_thermal_state}, where configs_by_thermal_state
is a vector of configurations for the target indexed by thermal state.
Constructs a map { target_name : configs_by_thermal_state } where configs_by_thermal_state is a vector of configurations for the target indexed by thermal state .
// "Bad" targets have no nominal configuration. We record them so the name of every such target // can be logged only once. // This target isn't in target_configurations. If there's no corresponding nominal config, // record it as a bad target and continue. Otherwise, initialize this target's entry in // `result`. // `transition` specifies that this target should change from its previous configuration at // state `i` to `transition.config()` at state `i+1`. Copy the last element until entry `i` // is populated, and then copy the new config into position `i+1`. // Extend the configs for each target to the appropriate length -- any target not present in the // final state transition will have missing elements.