| OLD | NEW |
| 1 /* | 1 /* |
| 2 * libjingle | 2 * libjingle |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 namespace cricket { | 34 namespace cricket { |
| 35 | 35 |
| 36 namespace { | 36 namespace { |
| 37 const int kMaxAudioLevel = 9; | 37 const int kMaxAudioLevel = 9; |
| 38 // To avoid overswitching, we disable switching for a period of time after a | 38 // To avoid overswitching, we disable switching for a period of time after a |
| 39 // switch is done. | 39 // switch is done. |
| 40 const int kDefaultMinTimeBetweenSwitches = 1000; | 40 const int kDefaultMinTimeBetweenSwitches = 1000; |
| 41 } | 41 } |
| 42 | 42 |
| 43 CurrentSpeakerMonitor::CurrentSpeakerMonitor( | 43 CurrentSpeakerMonitor::CurrentSpeakerMonitor( |
| 44 AudioSourceContext* audio_source_context, BaseSession* session) | 44 AudioSourceContext* audio_source_context) |
| 45 : started_(false), | 45 : started_(false), |
| 46 audio_source_context_(audio_source_context), | 46 audio_source_context_(audio_source_context), |
| 47 session_(session), | |
| 48 current_speaker_ssrc_(0), | 47 current_speaker_ssrc_(0), |
| 49 earliest_permitted_switch_time_(0), | 48 earliest_permitted_switch_time_(0), |
| 50 min_time_between_switches_(kDefaultMinTimeBetweenSwitches) { | 49 min_time_between_switches_(kDefaultMinTimeBetweenSwitches) {} |
| 51 } | |
| 52 | 50 |
| 53 CurrentSpeakerMonitor::~CurrentSpeakerMonitor() { | 51 CurrentSpeakerMonitor::~CurrentSpeakerMonitor() { |
| 54 Stop(); | 52 Stop(); |
| 55 } | 53 } |
| 56 | 54 |
| 57 void CurrentSpeakerMonitor::Start() { | 55 void CurrentSpeakerMonitor::Start() { |
| 58 if (!started_) { | 56 if (!started_) { |
| 59 audio_source_context_->SignalAudioMonitor.connect( | 57 audio_source_context_->SignalAudioMonitor.connect( |
| 60 this, &CurrentSpeakerMonitor::OnAudioMonitor); | 58 this, &CurrentSpeakerMonitor::OnAudioMonitor); |
| 61 audio_source_context_->SignalMediaStreamsUpdate.connect( | 59 audio_source_context_->SignalMediaStreamsUpdate.connect( |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 if (earliest_permitted_switch_time_ <= now && | 184 if (earliest_permitted_switch_time_ <= now && |
| 187 current_speaker_ssrc_ != loudest_speaker_ssrc) { | 185 current_speaker_ssrc_ != loudest_speaker_ssrc) { |
| 188 current_speaker_ssrc_ = loudest_speaker_ssrc; | 186 current_speaker_ssrc_ = loudest_speaker_ssrc; |
| 189 LOG(LS_INFO) << "Current speaker changed to " << current_speaker_ssrc_; | 187 LOG(LS_INFO) << "Current speaker changed to " << current_speaker_ssrc_; |
| 190 earliest_permitted_switch_time_ = now + min_time_between_switches_; | 188 earliest_permitted_switch_time_ = now + min_time_between_switches_; |
| 191 SignalUpdate(this, current_speaker_ssrc_); | 189 SignalUpdate(this, current_speaker_ssrc_); |
| 192 } | 190 } |
| 193 } | 191 } |
| 194 | 192 |
| 195 void CurrentSpeakerMonitor::OnMediaStreamsUpdate( | 193 void CurrentSpeakerMonitor::OnMediaStreamsUpdate( |
| 196 AudioSourceContext* audio_source_context, BaseSession* session, | 194 AudioSourceContext* audio_source_context, |
| 197 const MediaStreams& added, const MediaStreams& removed) { | 195 const MediaStreams& added, |
| 198 | 196 const MediaStreams& removed) { |
| 199 if (audio_source_context == audio_source_context_ && session == session_) { | 197 if (audio_source_context == audio_source_context_) { |
| 200 // Update the speaking state map based on added and removed streams. | 198 // Update the speaking state map based on added and removed streams. |
| 201 for (std::vector<cricket::StreamParams>::const_iterator | 199 for (std::vector<cricket::StreamParams>::const_iterator |
| 202 it = removed.audio().begin(); it != removed.audio().end(); ++it) { | 200 it = removed.audio().begin(); it != removed.audio().end(); ++it) { |
| 203 ssrc_to_speaking_state_map_.erase(it->first_ssrc()); | 201 ssrc_to_speaking_state_map_.erase(it->first_ssrc()); |
| 204 } | 202 } |
| 205 | 203 |
| 206 for (std::vector<cricket::StreamParams>::const_iterator | 204 for (std::vector<cricket::StreamParams>::const_iterator |
| 207 it = added.audio().begin(); it != added.audio().end(); ++it) { | 205 it = added.audio().begin(); it != added.audio().end(); ++it) { |
| 208 ssrc_to_speaking_state_map_[it->first_ssrc()] = SS_NOT_SPEAKING; | 206 ssrc_to_speaking_state_map_[it->first_ssrc()] = SS_NOT_SPEAKING; |
| 209 } | 207 } |
| 210 } | 208 } |
| 211 } | 209 } |
| 212 | 210 |
| 213 void CurrentSpeakerMonitor::OnMediaStreamsReset( | 211 void CurrentSpeakerMonitor::OnMediaStreamsReset( |
| 214 AudioSourceContext* audio_source_context, BaseSession* session) { | 212 AudioSourceContext* audio_source_context) { |
| 215 if (audio_source_context == audio_source_context_ && session == session_) { | 213 if (audio_source_context == audio_source_context_) { |
| 216 ssrc_to_speaking_state_map_.clear(); | 214 ssrc_to_speaking_state_map_.clear(); |
| 217 } | 215 } |
| 218 } | 216 } |
| 219 | 217 |
| 220 } // namespace cricket | 218 } // namespace cricket |
| OLD | NEW |