Index: content/browser/media/capture/audio_mirroring_manager.cc |
diff --git a/content/browser/media/capture/audio_mirroring_manager.cc b/content/browser/media/capture/audio_mirroring_manager.cc |
index f8b8b3a5b183e9d1b1ff07dd6728279b368d0c88..eb66f431b05f6ce5abb9d8c52ea9bdecdeafa24e 100644 |
--- a/content/browser/media/capture/audio_mirroring_manager.cc |
+++ b/content/browser/media/capture/audio_mirroring_manager.cc |
@@ -81,12 +81,12 @@ void AudioMirroringManager::StartMirroring(MirroringDestination* destination) { |
sessions_.push_back(destination); |
} |
+ std::set<SourceFrameRef> candidates; |
+ |
// Query the MirroringDestination to see which of the audio streams should be |
// diverted. |
- std::set<SourceFrameRef> candidates; |
for (StreamRoutes::const_iterator it = routes_.begin(); it != routes_.end(); |
++it) { |
- if (!it->destination || it->destination == destination) |
candidates.insert(it->source_render_frame); |
} |
if (!candidates.empty()) { |
@@ -111,6 +111,11 @@ void AudioMirroringManager::StopMirroring(MirroringDestination* destination) { |
ChangeRoute(&(*it), NULL); |
redivert_candidates.insert(it->source_render_frame); |
} |
+ auto dup_it = it->duplications.find(destination); |
+ if (dup_it != it->duplications.end()) { |
+ it->diverter->StopDuplicating(dup_it->second); |
+ it->duplications.erase(dup_it); |
+ } |
} |
if (!redivert_candidates.empty()) |
InitiateQueriesToFindNewDestination(destination, redivert_candidates); |
@@ -132,20 +137,30 @@ void AudioMirroringManager::InitiateQueriesToFindNewDestination( |
for (Destinations::const_iterator it = sessions_.begin(); |
it != sessions_.end(); ++it) { |
- if (*it != old_destination) { |
- (*it)->QueryForMatches( |
- candidates, |
- base::Bind(&AudioMirroringManager::UpdateRoutesToDestination, |
- base::Unretained(this), |
- *it, |
- true)); |
- } |
+ if (*it == old_destination) |
+ continue; |
+ |
+ (*it)->QueryForMatches( |
+ candidates, |
+ base::Bind(&AudioMirroringManager::UpdateRoutesToDestination, |
+ base::Unretained(this), *it, true)); |
} |
} |
void AudioMirroringManager::UpdateRoutesToDestination( |
MirroringDestination* destination, |
bool add_only, |
+ const std::set<SourceFrameRef>& matches, |
+ bool is_duplicate) { |
+ if (is_duplicate) |
+ UpdateRoutesToDuplicateDestination(destination, add_only, matches); |
+ else |
+ UpdateRoutesToDivertDestination(destination, add_only, matches); |
+} |
+ |
+void AudioMirroringManager::UpdateRoutesToDivertDestination( |
+ MirroringDestination* destination, |
+ bool add_only, |
const std::set<SourceFrameRef>& matches) { |
DCHECK(thread_checker_.CalledOnValidThread()); |
@@ -177,6 +192,34 @@ void AudioMirroringManager::UpdateRoutesToDestination( |
InitiateQueriesToFindNewDestination(destination, redivert_candidates); |
} |
+void AudioMirroringManager::UpdateRoutesToDuplicateDestination( |
+ MirroringDestination* destination, |
+ bool add_only, |
+ const std::set<SourceFrameRef>& matches) { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+ if (std::find(sessions_.begin(), sessions_.end(), destination) == |
+ sessions_.end()) { |
+ return; // Query result callback invoked after StopMirroring(). |
+ } |
+ |
+ for (StreamRoutes::iterator it = routes_.begin(); it != routes_.end(); ++it) { |
+ if (matches.find(it->source_render_frame) != matches.end()) { |
+ media::AudioPushSink*& pusher = it->duplications[destination]; |
miu
2016/05/06 22:29:49
Just before this line, please add a consistency ch
qiangchen
2016/05/10 22:36:52
Done.
|
+ if (!pusher) { |
+ pusher = destination->AddPushInput(it->diverter->GetAudioParameters()); |
+ DCHECK(pusher); |
+ it->diverter->StartDuplicating(pusher); |
+ } |
+ } else if (!add_only) { |
+ auto dup_it = it->duplications.find(destination); |
+ if (dup_it != it->duplications.end()) { |
+ it->diverter->StopDuplicating(dup_it->second); |
+ it->duplications.erase(dup_it); |
+ } |
+ } |
+ } |
+} |
+ |
// static |
void AudioMirroringManager::ChangeRoute( |
miu
2016/05/06 22:29:49
To aid readability, could you change the name of t
qiangchen
2016/05/10 22:36:52
Done.
|
StreamRoutingState* route, MirroringDestination* new_destination) { |