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

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: Created 4 years, 8 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 if (destination->IsDuplication()) {
miu 2016/04/21 00:15:24 See comment I made in the .h file about the IsDupl
qiangchen 2016/04/28 00:00:56 Done.
86 for (StreamRoutes::const_iterator it = routes_.begin(); it != routes_.end();
87 ++it) {
88 candidates.insert(it->source_render_frame);
89 }
90 if (!candidates.empty()) {
91 destination->QueryForMatches(
92 candidates,
93 base::Bind(&AudioMirroringManager::UpdateRoutesToDupDestination,
94 base::Unretained(this), destination, false));
95 }
96 return;
97 }
98
84 // Query the MirroringDestination to see which of the audio streams should be 99 // Query the MirroringDestination to see which of the audio streams should be
85 // diverted. 100 // diverted.
86 std::set<SourceFrameRef> candidates;
87 for (StreamRoutes::const_iterator it = routes_.begin(); it != routes_.end(); 101 for (StreamRoutes::const_iterator it = routes_.begin(); it != routes_.end();
88 ++it) { 102 ++it) {
89 if (!it->destination || it->destination == destination) 103 if (!it->destination || it->destination == destination)
90 candidates.insert(it->source_render_frame); 104 candidates.insert(it->source_render_frame);
91 } 105 }
92 if (!candidates.empty()) { 106 if (!candidates.empty()) {
93 destination->QueryForMatches( 107 destination->QueryForMatches(
94 candidates, 108 candidates,
95 base::Bind(&AudioMirroringManager::UpdateRoutesToDestination, 109 base::Bind(&AudioMirroringManager::UpdateRoutesToDestination,
96 base::Unretained(this), 110 base::Unretained(this),
97 destination, 111 destination,
98 false)); 112 false));
99 } 113 }
100 } 114 }
101 115
102 void AudioMirroringManager::StopMirroring(MirroringDestination* destination) { 116 void AudioMirroringManager::StopMirroring(MirroringDestination* destination) {
103 DCHECK(thread_checker_.CalledOnValidThread()); 117 DCHECK(thread_checker_.CalledOnValidThread());
104 118
105 // Stop diverting each audio stream in the mirroring session being stopped. 119 if (destination->IsDuplication()) {
106 // Each stopped stream becomes a candidate to be diverted to another 120 std::set<SourceFrameRef> matches;
107 // destination. 121 UpdateRoutesToDupDestination(destination, false, matches);
108 std::set<SourceFrameRef> redivert_candidates; 122 } else {
109 for (StreamRoutes::iterator it = routes_.begin(); it != routes_.end(); ++it) { 123 // Stop diverting each audio stream in the mirroring session being stopped.
110 if (it->destination == destination) { 124 // Each stopped stream becomes a candidate to be diverted to another
111 ChangeRoute(&(*it), NULL); 125 // destination.
112 redivert_candidates.insert(it->source_render_frame); 126 std::set<SourceFrameRef> redivert_candidates;
127 for (StreamRoutes::iterator it = routes_.begin(); it != routes_.end();
128 ++it) {
129 if (it->destination == destination) {
130 ChangeRoute(&(*it), NULL);
131 redivert_candidates.insert(it->source_render_frame);
132 }
113 } 133 }
134 if (!redivert_candidates.empty())
135 InitiateQueriesToFindNewDestination(destination, redivert_candidates);
114 } 136 }
115 if (!redivert_candidates.empty())
116 InitiateQueriesToFindNewDestination(destination, redivert_candidates);
117 137
118 // Remove the entry from the set of active mirroring sessions. 138 // Remove the entry from the set of active mirroring sessions.
119 const Destinations::iterator dest_it = 139 const Destinations::iterator dest_it =
120 std::find(sessions_.begin(), sessions_.end(), destination); 140 std::find(sessions_.begin(), sessions_.end(), destination);
121 if (dest_it == sessions_.end()) { 141 if (dest_it == sessions_.end()) {
122 NOTREACHED(); 142 NOTREACHED();
123 return; 143 return;
124 } 144 }
125 sessions_.erase(dest_it); 145 sessions_.erase(dest_it);
126 } 146 }
127 147
128 void AudioMirroringManager::InitiateQueriesToFindNewDestination( 148 void AudioMirroringManager::InitiateQueriesToFindNewDestination(
129 MirroringDestination* old_destination, 149 MirroringDestination* old_destination,
130 const std::set<SourceFrameRef>& candidates) { 150 const std::set<SourceFrameRef>& candidates) {
131 DCHECK(thread_checker_.CalledOnValidThread()); 151 DCHECK(thread_checker_.CalledOnValidThread());
132 152
133 for (Destinations::const_iterator it = sessions_.begin(); 153 for (Destinations::const_iterator it = sessions_.begin();
134 it != sessions_.end(); ++it) { 154 it != sessions_.end(); ++it) {
135 if (*it != old_destination) { 155 if (*it == old_destination)
156 continue;
157
158 if ((*it)->IsDuplication()) {
159 (*it)->QueryForMatches(
160 candidates,
161 base::Bind(&AudioMirroringManager::UpdateRoutesToDupDestination,
162 base::Unretained(this), *it, true));
163 } else {
136 (*it)->QueryForMatches( 164 (*it)->QueryForMatches(
137 candidates, 165 candidates,
138 base::Bind(&AudioMirroringManager::UpdateRoutesToDestination, 166 base::Bind(&AudioMirroringManager::UpdateRoutesToDestination,
139 base::Unretained(this), 167 base::Unretained(this),
140 *it, 168 *it,
141 true)); 169 true));
142 } 170 }
143 } 171 }
144 } 172 }
145 173
(...skipping 24 matching lines...) Expand all
170 if (it->destination == destination) { 198 if (it->destination == destination) {
171 ChangeRoute(&(*it), NULL); 199 ChangeRoute(&(*it), NULL);
172 redivert_candidates.insert(it->source_render_frame); 200 redivert_candidates.insert(it->source_render_frame);
173 } 201 }
174 } 202 }
175 } 203 }
176 if (!redivert_candidates.empty()) 204 if (!redivert_candidates.empty())
177 InitiateQueriesToFindNewDestination(destination, redivert_candidates); 205 InitiateQueriesToFindNewDestination(destination, redivert_candidates);
178 } 206 }
179 207
208 void AudioMirroringManager::UpdateRoutesToDupDestination(
209 MirroringDestination* destination,
210 bool add_only,
211 const std::set<SourceFrameRef>& matches) {
212 DCHECK(thread_checker_.CalledOnValidThread());
213 if (std::find(sessions_.begin(), sessions_.end(), destination) ==
214 sessions_.end()) {
215 return; // Query result callback invoked after StopMirroring().
216 }
217
218 for (StreamRoutes::iterator it = routes_.begin(); it != routes_.end(); ++it) {
219 if (matches.find(it->source_render_frame) != matches.end()) {
220 if (it->dup_destinations.count(destination) == 0) {
221 it->dup_destinations[destination] =
222 destination->AddPushInput(it->diverter->GetAudioParameters());
223 it->diverter->StartDuplicating(it->dup_destinations[destination]);
224 }
225
226 } else if (!add_only) {
227 if (it->dup_destinations.count(destination) > 0) {
228 it->diverter->StopDuplicating(it->dup_destinations[destination]);
229 it->dup_destinations.erase(destination);
230 }
231 }
232 }
233 }
234
180 // static 235 // static
181 void AudioMirroringManager::ChangeRoute( 236 void AudioMirroringManager::ChangeRoute(
182 StreamRoutingState* route, MirroringDestination* new_destination) { 237 StreamRoutingState* route, MirroringDestination* new_destination) {
183 if (route->destination == new_destination) 238 if (route->destination == new_destination)
184 return; // No change. 239 return; // No change.
185 240
186 if (route->destination) { 241 if (route->destination) {
187 DVLOG(1) << "Stop diverting render_process_id:render_frame_id=" 242 DVLOG(1) << "Stop diverting render_process_id:render_frame_id="
188 << route->source_render_frame.first << ':' 243 << route->source_render_frame.first << ':'
189 << route->source_render_frame.second 244 << route->source_render_frame.second
(...skipping 18 matching lines...) Expand all
208 : source_render_frame(source_frame), 263 : source_render_frame(source_frame),
209 diverter(stream_diverter), 264 diverter(stream_diverter),
210 destination(NULL) {} 265 destination(NULL) {}
211 266
212 AudioMirroringManager::StreamRoutingState::StreamRoutingState( 267 AudioMirroringManager::StreamRoutingState::StreamRoutingState(
213 const StreamRoutingState& other) = default; 268 const StreamRoutingState& other) = default;
214 269
215 AudioMirroringManager::StreamRoutingState::~StreamRoutingState() {} 270 AudioMirroringManager::StreamRoutingState::~StreamRoutingState() {}
216 271
217 } // namespace content 272 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698