Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Side by Side Diff: content/browser/media/capture/audio_mirroring_manager.cc

Issue 1897953003: Unmute Tab Audio For Desktop Share (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix trybot error Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/media/capture/audio_mirroring_manager.h" 5 #include "content/browser/media/capture/audio_mirroring_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 DCHECK(thread_checker_.CalledOnValidThread()); 74 DCHECK(thread_checker_.CalledOnValidThread());
75 DCHECK(destination); 75 DCHECK(destination);
76 76
77 // Insert an entry into the set of active mirroring sessions, if this is a 77 // Insert an entry into the set of active mirroring sessions, if this is a
78 // previously-unknown destination. 78 // previously-unknown destination.
79 if (std::find(sessions_.begin(), sessions_.end(), destination) == 79 if (std::find(sessions_.begin(), sessions_.end(), destination) ==
80 sessions_.end()) { 80 sessions_.end()) {
81 sessions_.push_back(destination); 81 sessions_.push_back(destination);
82 } 82 }
83 83
84 std::set<SourceFrameRef> candidates;
85
84 // Query the MirroringDestination to see which of the audio streams should be 86 // Query the MirroringDestination to see which of the audio streams should be
85 // diverted. 87 // diverted.
86 std::set<SourceFrameRef> candidates;
87 for (StreamRoutes::const_iterator it = routes_.begin(); it != routes_.end(); 88 for (StreamRoutes::const_iterator it = routes_.begin(); it != routes_.end();
88 ++it) { 89 ++it) {
89 if (!it->destination || it->destination == destination)
90 candidates.insert(it->source_render_frame); 90 candidates.insert(it->source_render_frame);
qiangchen 2016/05/03 16:58:23 Can you double check whether removing the "if" con
91 } 91 }
92 if (!candidates.empty()) { 92 if (!candidates.empty()) {
93 destination->QueryForMatches( 93 destination->QueryForMatches(
94 candidates, 94 candidates,
95 base::Bind(&AudioMirroringManager::UpdateRoutesToDestination, 95 base::Bind(&AudioMirroringManager::UpdateRoutesToDestination,
96 base::Unretained(this), 96 base::Unretained(this),
97 destination, 97 destination,
98 false)); 98 false));
99 } 99 }
100 } 100 }
101 101
102 void AudioMirroringManager::StopMirroring(MirroringDestination* destination) { 102 void AudioMirroringManager::StopMirroring(MirroringDestination* destination) {
103 DCHECK(thread_checker_.CalledOnValidThread()); 103 DCHECK(thread_checker_.CalledOnValidThread());
104 104
105 // Stop diverting each audio stream in the mirroring session being stopped. 105 std::set<SourceFrameRef> matches;
106 // Each stopped stream becomes a candidate to be diverted to another 106 destination->QueryForMatches(
miu 2016/05/02 20:06:12 This won't work, since |destination| is allowed to
qiangchen 2016/05/03 16:58:22 Done.
107 // destination. 107 matches, base::Bind(&AudioMirroringManager::UpdateRoutesToDestination,
108 std::set<SourceFrameRef> redivert_candidates; 108 base::Unretained(this), destination, false));
109 for (StreamRoutes::iterator it = routes_.begin(); it != routes_.end(); ++it) {
110 if (it->destination == destination) {
111 ChangeRoute(&(*it), NULL);
112 redivert_candidates.insert(it->source_render_frame);
113 }
114 }
115 if (!redivert_candidates.empty())
116 InitiateQueriesToFindNewDestination(destination, redivert_candidates);
117 109
118 // Remove the entry from the set of active mirroring sessions. 110 // Remove the entry from the set of active mirroring sessions.
119 const Destinations::iterator dest_it = 111 const Destinations::iterator dest_it =
120 std::find(sessions_.begin(), sessions_.end(), destination); 112 std::find(sessions_.begin(), sessions_.end(), destination);
121 if (dest_it == sessions_.end()) { 113 if (dest_it == sessions_.end()) {
122 NOTREACHED(); 114 NOTREACHED();
123 return; 115 return;
124 } 116 }
125 sessions_.erase(dest_it); 117 sessions_.erase(dest_it);
126 } 118 }
127 119
128 void AudioMirroringManager::InitiateQueriesToFindNewDestination( 120 void AudioMirroringManager::InitiateQueriesToFindNewDestination(
129 MirroringDestination* old_destination, 121 MirroringDestination* old_destination,
130 const std::set<SourceFrameRef>& candidates) { 122 const std::set<SourceFrameRef>& candidates) {
131 DCHECK(thread_checker_.CalledOnValidThread()); 123 DCHECK(thread_checker_.CalledOnValidThread());
132 124
133 for (Destinations::const_iterator it = sessions_.begin(); 125 for (Destinations::const_iterator it = sessions_.begin();
134 it != sessions_.end(); ++it) { 126 it != sessions_.end(); ++it) {
135 if (*it != old_destination) { 127 if (*it == old_destination)
136 (*it)->QueryForMatches( 128 continue;
137 candidates, 129
138 base::Bind(&AudioMirroringManager::UpdateRoutesToDestination, 130 (*it)->QueryForMatches(
139 base::Unretained(this), 131 candidates,
140 *it, 132 base::Bind(&AudioMirroringManager::UpdateRoutesToDestination,
141 true)); 133 base::Unretained(this), *it, true));
142 }
143 } 134 }
144 } 135 }
145 136
146 void AudioMirroringManager::UpdateRoutesToDestination( 137 void AudioMirroringManager::UpdateRoutesToDestination(
147 MirroringDestination* destination, 138 MirroringDestination* destination,
148 bool add_only, 139 bool add_only,
140 const std::set<SourceFrameRef>& matches,
141 bool is_duplicate) {
142 if (is_duplicate)
143 UpdateRoutesToDuplicateDestination(destination, add_only, matches);
144 else
145 UpdateRoutesToDivertDestination(destination, add_only, matches);
146 }
147
148 void AudioMirroringManager::UpdateRoutesToDivertDestination(
149 MirroringDestination* destination,
150 bool add_only,
149 const std::set<SourceFrameRef>& matches) { 151 const std::set<SourceFrameRef>& matches) {
150 DCHECK(thread_checker_.CalledOnValidThread()); 152 DCHECK(thread_checker_.CalledOnValidThread());
151 153
152 if (std::find(sessions_.begin(), sessions_.end(), destination) == 154 if (std::find(sessions_.begin(), sessions_.end(), destination) ==
153 sessions_.end()) { 155 sessions_.end()) {
154 return; // Query result callback invoked after StopMirroring(). 156 return; // Query result callback invoked after StopMirroring().
155 } 157 }
156 158
157 DVLOG(1) << (add_only ? "Add " : "Replace with ") << matches.size() 159 DVLOG(1) << (add_only ? "Add " : "Replace with ") << matches.size()
158 << " routes to MirroringDestination@" << destination; 160 << " routes to MirroringDestination@" << destination;
(...skipping 11 matching lines...) Expand all
170 if (it->destination == destination) { 172 if (it->destination == destination) {
171 ChangeRoute(&(*it), NULL); 173 ChangeRoute(&(*it), NULL);
172 redivert_candidates.insert(it->source_render_frame); 174 redivert_candidates.insert(it->source_render_frame);
173 } 175 }
174 } 176 }
175 } 177 }
176 if (!redivert_candidates.empty()) 178 if (!redivert_candidates.empty())
177 InitiateQueriesToFindNewDestination(destination, redivert_candidates); 179 InitiateQueriesToFindNewDestination(destination, redivert_candidates);
178 } 180 }
179 181
182 void AudioMirroringManager::UpdateRoutesToDuplicateDestination(
183 MirroringDestination* destination,
184 bool add_only,
185 const std::set<SourceFrameRef>& matches) {
186 DCHECK(thread_checker_.CalledOnValidThread());
187 if (std::find(sessions_.begin(), sessions_.end(), destination) ==
188 sessions_.end()) {
189 return; // Query result callback invoked after StopMirroring().
190 }
191
192 for (StreamRoutes::iterator it = routes_.begin(); it != routes_.end(); ++it) {
193 if (matches.find(it->source_render_frame) != matches.end()) {
194 if (it->dup_destinations.count(destination) == 0) {
miu 2016/05/02 20:06:12 These five lines of code do a map look-up three ti
qiangchen 2016/05/03 16:58:22 Done.
195 it->dup_destinations[destination] =
196 destination->AddPushInput(it->diverter->GetAudioParameters());
197 it->diverter->StartDuplicating(it->dup_destinations[destination]);
198 }
199
miu 2016/05/02 20:06:12 nit: remove extra line
qiangchen 2016/05/03 16:58:22 Done.
200 } else if (!add_only) {
201 if (it->dup_destinations.count(destination) > 0) {
miu 2016/05/02 20:06:12 Same problem here (with repeated map look-ups). S
qiangchen 2016/05/03 16:58:23 Done.
202 it->diverter->StopDuplicating(it->dup_destinations[destination]);
203 it->dup_destinations.erase(destination);
204 }
205 }
206 }
207 }
208
180 // static 209 // static
181 void AudioMirroringManager::ChangeRoute( 210 void AudioMirroringManager::ChangeRoute(
182 StreamRoutingState* route, MirroringDestination* new_destination) { 211 StreamRoutingState* route, MirroringDestination* new_destination) {
183 if (route->destination == new_destination) 212 if (route->destination == new_destination)
184 return; // No change. 213 return; // No change.
185 214
186 if (route->destination) { 215 if (route->destination) {
187 DVLOG(1) << "Stop diverting render_process_id:render_frame_id=" 216 DVLOG(1) << "Stop diverting render_process_id:render_frame_id="
188 << route->source_render_frame.first << ':' 217 << route->source_render_frame.first << ':'
189 << route->source_render_frame.second 218 << route->source_render_frame.second
(...skipping 18 matching lines...) Expand all
208 : source_render_frame(source_frame), 237 : source_render_frame(source_frame),
209 diverter(stream_diverter), 238 diverter(stream_diverter),
210 destination(NULL) {} 239 destination(NULL) {}
211 240
212 AudioMirroringManager::StreamRoutingState::StreamRoutingState( 241 AudioMirroringManager::StreamRoutingState::StreamRoutingState(
213 const StreamRoutingState& other) = default; 242 const StreamRoutingState& other) = default;
214 243
215 AudioMirroringManager::StreamRoutingState::~StreamRoutingState() {} 244 AudioMirroringManager::StreamRoutingState::~StreamRoutingState() {}
216 245
217 } // namespace content 246 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698