OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/renderer/media/media_stream_dispatcher.h" | 5 #include "content/renderer/media/media_stream_dispatcher.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "content/common/media/media_stream_messages.h" | 8 #include "content/common/media/media_stream_messages.h" |
9 #include "content/renderer/media/media_stream_dispatcher_eventhandler.h" | 9 #include "content/renderer/media/media_stream_dispatcher_eventhandler.h" |
10 #include "content/renderer/render_view_impl.h" | 10 #include "content/renderer/render_view_impl.h" |
(...skipping 13 matching lines...) Expand all Loading... | |
24 }; | 24 }; |
25 | 25 |
26 struct MediaStreamDispatcher::Stream { | 26 struct MediaStreamDispatcher::Stream { |
27 Stream() {} | 27 Stream() {} |
28 ~Stream() {} | 28 ~Stream() {} |
29 base::WeakPtr<MediaStreamDispatcherEventHandler> handler; | 29 base::WeakPtr<MediaStreamDispatcherEventHandler> handler; |
30 media_stream::StreamDeviceInfoArray audio_array; | 30 media_stream::StreamDeviceInfoArray audio_array; |
31 media_stream::StreamDeviceInfoArray video_array; | 31 media_stream::StreamDeviceInfoArray video_array; |
32 }; | 32 }; |
33 | 33 |
34 MediaStreamDispatcher::EnumerationRequest::EnumerationRequest( | |
35 const base::WeakPtr<MediaStreamDispatcherEventHandler>& handler, | |
36 int request_id) | |
37 : handler(handler), | |
38 request_id(request_id) { | |
39 } | |
40 | |
41 MediaStreamDispatcher::EnumerationRequest::~EnumerationRequest() {} | |
42 | |
43 MediaStreamDispatcher::EnumerationState::EnumerationState() | |
44 : started(false), | |
45 ipc_id(0), | |
46 cache_valid(false) { | |
47 } | |
48 | |
49 MediaStreamDispatcher::EnumerationState::~EnumerationState() {} | |
50 | |
34 MediaStreamDispatcher::MediaStreamDispatcher(RenderViewImpl* render_view) | 51 MediaStreamDispatcher::MediaStreamDispatcher(RenderViewImpl* render_view) |
35 : content::RenderViewObserver(render_view), | 52 : content::RenderViewObserver(render_view), |
53 main_loop_(base::MessageLoopProxy::current()), | |
36 next_ipc_id_(0) { | 54 next_ipc_id_(0) { |
37 } | 55 } |
38 | 56 |
39 MediaStreamDispatcher::~MediaStreamDispatcher() {} | 57 MediaStreamDispatcher::~MediaStreamDispatcher() {} |
40 | 58 |
41 void MediaStreamDispatcher::GenerateStream( | 59 void MediaStreamDispatcher::GenerateStream( |
42 int request_id, | 60 int request_id, |
43 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, | 61 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, |
44 media_stream::StreamOptions components, | 62 media_stream::StreamOptions components, |
45 const GURL& security_origin) { | 63 const GURL& security_origin) { |
64 DCHECK(main_loop_->BelongsToCurrentThread()); | |
46 DVLOG(1) << "MediaStreamDispatcher::GenerateStream(" << request_id << ")"; | 65 DVLOG(1) << "MediaStreamDispatcher::GenerateStream(" << request_id << ")"; |
47 | 66 |
48 requests_.push_back(Request(event_handler, request_id, next_ipc_id_)); | 67 requests_.push_back(Request(event_handler, request_id, next_ipc_id_)); |
49 Send(new MediaStreamHostMsg_GenerateStream(routing_id(), | 68 Send(new MediaStreamHostMsg_GenerateStream(routing_id(), |
50 next_ipc_id_++, | 69 next_ipc_id_++, |
51 components, | 70 components, |
52 security_origin)); | 71 security_origin)); |
53 } | 72 } |
54 | 73 |
55 void MediaStreamDispatcher::CancelGenerateStream(int request_id) { | 74 void MediaStreamDispatcher::CancelGenerateStream(int request_id) { |
75 DCHECK(main_loop_->BelongsToCurrentThread()); | |
56 DVLOG(1) << "MediaStreamDispatcher::CancelGenerateStream" | 76 DVLOG(1) << "MediaStreamDispatcher::CancelGenerateStream" |
57 << ", {request_id = " << request_id << "}"; | 77 << ", {request_id = " << request_id << "}"; |
58 | 78 |
59 RequestList::iterator it = requests_.begin(); | 79 RequestList::iterator it = requests_.begin(); |
60 for (; it != requests_.end(); ++it) { | 80 for (; it != requests_.end(); ++it) { |
61 Request& request = *it; | 81 Request& request = *it; |
62 if (request.request_id == request_id) { | 82 if (request.request_id == request_id) { |
63 requests_.erase(it); | 83 requests_.erase(it); |
64 Send(new MediaStreamHostMsg_CancelGenerateStream(routing_id(), | 84 Send(new MediaStreamHostMsg_CancelGenerateStream(routing_id(), |
65 request_id)); | 85 request_id)); |
66 break; | 86 break; |
67 } | 87 } |
68 } | 88 } |
69 } | 89 } |
70 | 90 |
71 void MediaStreamDispatcher::StopStream(const std::string& label) { | 91 void MediaStreamDispatcher::StopStream(const std::string& label) { |
92 DCHECK(main_loop_->BelongsToCurrentThread()); | |
72 DVLOG(1) << "MediaStreamDispatcher::StopStream" | 93 DVLOG(1) << "MediaStreamDispatcher::StopStream" |
73 << ", {label = " << label << "}"; | 94 << ", {label = " << label << "}"; |
74 | 95 |
75 LabelStreamMap::iterator it = label_stream_map_.find(label); | 96 LabelStreamMap::iterator it = label_stream_map_.find(label); |
76 if (it == label_stream_map_.end()) | 97 if (it == label_stream_map_.end()) |
77 return; | 98 return; |
78 | 99 |
79 Send(new MediaStreamHostMsg_StopGeneratedStream(routing_id(), label)); | 100 Send(new MediaStreamHostMsg_StopGeneratedStream(routing_id(), label)); |
80 label_stream_map_.erase(it); | 101 label_stream_map_.erase(it); |
81 } | 102 } |
82 | 103 |
83 void MediaStreamDispatcher::EnumerateDevices( | 104 void MediaStreamDispatcher::EnumerateDevices( |
84 int request_id, | 105 int request_id, |
85 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, | 106 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, |
86 media_stream::MediaStreamType type, | 107 media_stream::MediaStreamType type, |
87 const GURL& security_origin) { | 108 const GURL& security_origin) { |
109 DCHECK(main_loop_->BelongsToCurrentThread()); | |
110 DCHECK(type == content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE || | |
111 type == content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE); | |
88 DVLOG(1) << "MediaStreamDispatcher::EnumerateDevices(" | 112 DVLOG(1) << "MediaStreamDispatcher::EnumerateDevices(" |
89 << request_id << ")"; | 113 << request_id << ")"; |
90 | 114 |
91 requests_.push_back(Request(event_handler, request_id, next_ipc_id_)); | 115 EnumerationState* state = |
92 Send(new MediaStreamHostMsg_EnumerateDevices(routing_id(), | 116 (type == content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE ? |
93 next_ipc_id_++, | 117 &audio_enumeration_state_ : &video_enumeration_state_); |
94 type, | 118 state->requests.push_back( |
95 security_origin)); | 119 EnumerationRequest(event_handler, request_id)); |
120 | |
121 if (state->cache_valid) { | |
122 event_handler->OnDevicesEnumerated(request_id, state->cached_device); | |
123 } else if (!state->started) { | |
124 state->started = true; | |
125 Send(new MediaStreamHostMsg_EnumerateDevices(routing_id(), | |
126 next_ipc_id_, | |
127 type, | |
128 security_origin)); | |
129 state->ipc_id = next_ipc_id_++; | |
130 } | |
131 } | |
132 | |
133 void MediaStreamDispatcher::StopEnumerateDevices( | |
134 int request_id, | |
135 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler) { | |
136 DCHECK(main_loop_->BelongsToCurrentThread()); | |
137 DVLOG(1) << "MediaStreamDispatcher::StopEnumerateDevices(" | |
138 << request_id << ")"; | |
139 | |
140 // Just need remove the request from one type. | |
141 RemoveEnumerationRequest(request_id, event_handler, | |
142 &audio_enumeration_state_) || | |
scherkus (not reviewing)
2012/08/02 00:14:19
I don't think there's any harm in calling RER() fo
wjia(left Chromium)
2012/08/02 22:15:27
Done.
| |
143 RemoveEnumerationRequest(request_id, event_handler, | |
144 &video_enumeration_state_); | |
145 } | |
146 | |
147 bool MediaStreamDispatcher::RemoveEnumerationRequest( | |
148 int request_id, | |
149 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, | |
150 EnumerationState* state) { | |
151 EnumerationRequestList* requests = &state->requests; | |
152 for (EnumerationRequestList::iterator it = requests->begin(); | |
153 it != requests->end(); ++it) { | |
154 if (it->request_id == request_id && it->handler == event_handler) { | |
155 requests->erase(it); | |
156 if (requests->empty() && !state->label.empty()) { | |
157 // No more request and has a label, try to stop the label | |
158 // and invalidate the state. | |
159 Send(new MediaStreamHostMsg_StopGeneratedStream( | |
160 routing_id(), state->label)); | |
161 state->started = false; | |
162 state->cache_valid = false; | |
163 } | |
164 return true; | |
165 } | |
166 } | |
167 return false; | |
96 } | 168 } |
97 | 169 |
98 void MediaStreamDispatcher::OpenDevice( | 170 void MediaStreamDispatcher::OpenDevice( |
99 int request_id, | 171 int request_id, |
100 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, | 172 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, |
101 const std::string& device_id, | 173 const std::string& device_id, |
102 media_stream::MediaStreamType type, | 174 media_stream::MediaStreamType type, |
103 const GURL& security_origin) { | 175 const GURL& security_origin) { |
176 DCHECK(main_loop_->BelongsToCurrentThread()); | |
104 DVLOG(1) << "MediaStreamDispatcher::OpenDevice(" << request_id << ")"; | 177 DVLOG(1) << "MediaStreamDispatcher::OpenDevice(" << request_id << ")"; |
105 | 178 |
106 requests_.push_back(Request(event_handler, request_id, next_ipc_id_)); | 179 requests_.push_back(Request(event_handler, request_id, next_ipc_id_)); |
107 Send(new MediaStreamHostMsg_OpenDevice(routing_id(), | 180 Send(new MediaStreamHostMsg_OpenDevice(routing_id(), |
108 next_ipc_id_++, | 181 next_ipc_id_++, |
109 device_id, | 182 device_id, |
110 type, | 183 type, |
111 security_origin)); | 184 security_origin)); |
112 } | 185 } |
113 | 186 |
114 void MediaStreamDispatcher::CloseDevice(const std::string& label) { | 187 void MediaStreamDispatcher::CloseDevice(const std::string& label) { |
188 DCHECK(main_loop_->BelongsToCurrentThread()); | |
115 DVLOG(1) << "MediaStreamDispatcher::CloseDevice" | 189 DVLOG(1) << "MediaStreamDispatcher::CloseDevice" |
116 << ", {label = " << label << "}"; | 190 << ", {label = " << label << "}"; |
117 | 191 |
118 StopStream(label); | 192 StopStream(label); |
119 } | 193 } |
120 | 194 |
121 bool MediaStreamDispatcher::OnMessageReceived(const IPC::Message& message) { | 195 bool MediaStreamDispatcher::OnMessageReceived(const IPC::Message& message) { |
122 bool handled = true; | 196 bool handled = true; |
123 IPC_BEGIN_MESSAGE_MAP(MediaStreamDispatcher, message) | 197 IPC_BEGIN_MESSAGE_MAP(MediaStreamDispatcher, message) |
124 IPC_MESSAGE_HANDLER(MediaStreamMsg_StreamGenerated, | 198 IPC_MESSAGE_HANDLER(MediaStreamMsg_StreamGenerated, |
(...skipping 15 matching lines...) Expand all Loading... | |
140 IPC_MESSAGE_UNHANDLED(handled = false) | 214 IPC_MESSAGE_UNHANDLED(handled = false) |
141 IPC_END_MESSAGE_MAP() | 215 IPC_END_MESSAGE_MAP() |
142 return handled; | 216 return handled; |
143 } | 217 } |
144 | 218 |
145 void MediaStreamDispatcher::OnStreamGenerated( | 219 void MediaStreamDispatcher::OnStreamGenerated( |
146 int request_id, | 220 int request_id, |
147 const std::string& label, | 221 const std::string& label, |
148 const media_stream::StreamDeviceInfoArray& audio_array, | 222 const media_stream::StreamDeviceInfoArray& audio_array, |
149 const media_stream::StreamDeviceInfoArray& video_array) { | 223 const media_stream::StreamDeviceInfoArray& video_array) { |
224 DCHECK(main_loop_->BelongsToCurrentThread()); | |
150 | 225 |
151 for (RequestList::iterator it = requests_.begin(); | 226 for (RequestList::iterator it = requests_.begin(); |
152 it != requests_.end(); ++it) { | 227 it != requests_.end(); ++it) { |
153 Request& request = *it; | 228 Request& request = *it; |
154 if (request.ipc_request == request_id) { | 229 if (request.ipc_request == request_id) { |
155 Stream new_stream; | 230 Stream new_stream; |
156 new_stream.handler = request.handler; | 231 new_stream.handler = request.handler; |
157 new_stream.audio_array = audio_array; | 232 new_stream.audio_array = audio_array; |
158 new_stream.video_array = video_array; | 233 new_stream.video_array = video_array; |
159 label_stream_map_[label] = new_stream; | 234 label_stream_map_[label] = new_stream; |
160 if (request.handler) { | 235 if (request.handler) { |
161 request.handler->OnStreamGenerated(request.request_id, label, | 236 request.handler->OnStreamGenerated(request.request_id, label, |
162 audio_array, video_array); | 237 audio_array, video_array); |
163 DVLOG(1) << "MediaStreamDispatcher::OnStreamGenerated(" | 238 DVLOG(1) << "MediaStreamDispatcher::OnStreamGenerated(" |
164 << request.request_id << ", " << label << ")"; | 239 << request.request_id << ", " << label << ")"; |
165 } | 240 } |
166 requests_.erase(it); | 241 requests_.erase(it); |
167 break; | 242 break; |
168 } | 243 } |
169 } | 244 } |
170 } | 245 } |
171 | 246 |
172 void MediaStreamDispatcher::OnStreamGenerationFailed(int request_id) { | 247 void MediaStreamDispatcher::OnStreamGenerationFailed(int request_id) { |
248 DCHECK(main_loop_->BelongsToCurrentThread()); | |
173 for (RequestList::iterator it = requests_.begin(); | 249 for (RequestList::iterator it = requests_.begin(); |
174 it != requests_.end(); ++it) { | 250 it != requests_.end(); ++it) { |
175 Request& request = *it; | 251 Request& request = *it; |
176 if (request.ipc_request == request_id) { | 252 if (request.ipc_request == request_id) { |
177 if (request.handler) { | 253 if (request.handler) { |
178 request.handler->OnStreamGenerationFailed(request.request_id); | 254 request.handler->OnStreamGenerationFailed(request.request_id); |
179 DVLOG(1) << "MediaStreamDispatcher::OnStreamGenerationFailed(" | 255 DVLOG(1) << "MediaStreamDispatcher::OnStreamGenerationFailed(" |
180 << request.request_id << ")\n"; | 256 << request.request_id << ")\n"; |
181 } | 257 } |
182 requests_.erase(it); | 258 requests_.erase(it); |
183 break; | 259 break; |
184 } | 260 } |
185 } | 261 } |
186 } | 262 } |
187 | 263 |
188 void MediaStreamDispatcher::OnVideoDeviceFailed(const std::string& label, | 264 void MediaStreamDispatcher::OnVideoDeviceFailed(const std::string& label, |
189 int index) { | 265 int index) { |
266 DCHECK(main_loop_->BelongsToCurrentThread()); | |
190 LabelStreamMap::iterator it = label_stream_map_.find(label); | 267 LabelStreamMap::iterator it = label_stream_map_.find(label); |
191 if (it == label_stream_map_.end()) | 268 if (it == label_stream_map_.end()) |
192 return; | 269 return; |
193 | 270 |
194 // index is the index in the video_array that has failed. | 271 // index is the index in the video_array that has failed. |
195 DCHECK_GT(it->second.video_array.size(), static_cast<size_t>(index)); | 272 DCHECK_GT(it->second.video_array.size(), static_cast<size_t>(index)); |
196 media_stream::StreamDeviceInfoArray::iterator device_it = | 273 media_stream::StreamDeviceInfoArray::iterator device_it = |
197 it->second.video_array.begin(); | 274 it->second.video_array.begin(); |
198 it->second.video_array.erase(device_it + index); | 275 it->second.video_array.erase(device_it + index); |
199 if (it->second.handler) | 276 if (it->second.handler) |
200 it->second.handler->OnVideoDeviceFailed(label, index); | 277 it->second.handler->OnVideoDeviceFailed(label, index); |
201 } | 278 } |
202 | 279 |
203 void MediaStreamDispatcher::OnAudioDeviceFailed(const std::string& label, | 280 void MediaStreamDispatcher::OnAudioDeviceFailed(const std::string& label, |
204 int index) { | 281 int index) { |
282 DCHECK(main_loop_->BelongsToCurrentThread()); | |
205 LabelStreamMap::iterator it = label_stream_map_.find(label); | 283 LabelStreamMap::iterator it = label_stream_map_.find(label); |
206 if (it == label_stream_map_.end()) | 284 if (it == label_stream_map_.end()) |
207 return; | 285 return; |
208 | 286 |
209 // index is the index in the audio_array that has failed. | 287 // index is the index in the audio_array that has failed. |
210 DCHECK_GT(it->second.audio_array.size(), static_cast<size_t>(index)); | 288 DCHECK_GT(it->second.audio_array.size(), static_cast<size_t>(index)); |
211 media_stream::StreamDeviceInfoArray::iterator device_it = | 289 media_stream::StreamDeviceInfoArray::iterator device_it = |
212 it->second.audio_array.begin(); | 290 it->second.audio_array.begin(); |
213 it->second.audio_array.erase(device_it + index); | 291 it->second.audio_array.erase(device_it + index); |
214 if (it->second.handler) | 292 if (it->second.handler) |
215 it->second.handler->OnAudioDeviceFailed(label, index); | 293 it->second.handler->OnAudioDeviceFailed(label, index); |
216 } | 294 } |
217 | 295 |
218 void MediaStreamDispatcher::OnDevicesEnumerated( | 296 void MediaStreamDispatcher::OnDevicesEnumerated( |
219 int request_id, | 297 int request_id, |
298 const std::string& label, | |
220 const media_stream::StreamDeviceInfoArray& device_array) { | 299 const media_stream::StreamDeviceInfoArray& device_array) { |
300 DCHECK(main_loop_->BelongsToCurrentThread()); | |
301 EnumerationState* state; | |
302 if (audio_enumeration_state_.started && | |
303 request_id == audio_enumeration_state_.ipc_id) { | |
304 state = &audio_enumeration_state_; | |
305 } else if (video_enumeration_state_.started && | |
306 request_id == video_enumeration_state_.ipc_id) { | |
307 state = &video_enumeration_state_; | |
308 } else { | |
309 return; | |
310 } | |
221 | 311 |
222 for (RequestList::iterator it = requests_.begin(); | 312 DCHECK(!label.empty()); |
223 it != requests_.end(); ++it) { | 313 state->label = label; |
224 Request& request = *it; | 314 state->cache_valid = true; |
225 if (request.ipc_request == request_id) { | 315 state->cached_device = device_array; |
226 if (request.handler) { | 316 |
227 request.handler->OnDevicesEnumerated(request.request_id, device_array); | 317 for (EnumerationRequestList::iterator it = state->requests.begin(); |
228 DVLOG(1) << "MediaStreamDispatcher::OnDevicesEnumerated(" | 318 it != state->requests.end(); ++it) { |
229 << request.request_id << ")"; | 319 if (it->handler) { |
230 } | 320 it->handler->OnDevicesEnumerated(it->request_id, device_array); |
231 requests_.erase(it); | 321 DVLOG(1) << "MediaStreamDispatcher::OnDevicesEnumerated(" |
232 break; | 322 << it->request_id << ")"; |
233 } | 323 } |
234 } | 324 } |
235 } | 325 } |
236 | 326 |
237 void MediaStreamDispatcher::OnDevicesEnumerationFailed(int request_id) { | 327 void MediaStreamDispatcher::OnDevicesEnumerationFailed(int request_id) { |
328 DCHECK(main_loop_->BelongsToCurrentThread()); | |
238 for (RequestList::iterator it = requests_.begin(); | 329 for (RequestList::iterator it = requests_.begin(); |
239 it != requests_.end(); ++it) { | 330 it != requests_.end(); ++it) { |
240 Request& request = *it; | 331 Request& request = *it; |
241 if (request.ipc_request == request_id) { | 332 if (request.ipc_request == request_id) { |
242 if (request.handler) { | 333 if (request.handler) { |
243 request.handler->OnStreamGenerationFailed(request.request_id); | 334 request.handler->OnStreamGenerationFailed(request.request_id); |
244 DVLOG(1) << "MediaStreamDispatcher::OnDevicesEnumerationFailed(" | 335 DVLOG(1) << "MediaStreamDispatcher::OnDevicesEnumerationFailed(" |
245 << request.request_id << ")\n"; | 336 << request.request_id << ")\n"; |
246 } | 337 } |
247 requests_.erase(it); | 338 requests_.erase(it); |
248 break; | 339 break; |
249 } | 340 } |
250 } | 341 } |
251 } | 342 } |
252 | 343 |
253 void MediaStreamDispatcher::OnDeviceOpened( | 344 void MediaStreamDispatcher::OnDeviceOpened( |
254 int request_id, | 345 int request_id, |
255 const std::string& label, | 346 const std::string& label, |
256 const media_stream::StreamDeviceInfo& device_info) { | 347 const media_stream::StreamDeviceInfo& device_info) { |
348 DCHECK(main_loop_->BelongsToCurrentThread()); | |
257 for (RequestList::iterator it = requests_.begin(); | 349 for (RequestList::iterator it = requests_.begin(); |
258 it != requests_.end(); ++it) { | 350 it != requests_.end(); ++it) { |
259 Request& request = *it; | 351 Request& request = *it; |
260 if (request.ipc_request == request_id) { | 352 if (request.ipc_request == request_id) { |
261 Stream new_stream; | 353 Stream new_stream; |
262 new_stream.handler = request.handler; | 354 new_stream.handler = request.handler; |
263 if (device_info.stream_type == | 355 if (device_info.stream_type == |
264 content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE) { | 356 content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE) { |
265 new_stream.video_array.push_back(device_info); | 357 new_stream.video_array.push_back(device_info); |
266 } else { | 358 } else { |
267 new_stream.audio_array.push_back(device_info); | 359 new_stream.audio_array.push_back(device_info); |
268 } | 360 } |
269 label_stream_map_[label] = new_stream; | 361 label_stream_map_[label] = new_stream; |
270 if (request.handler) { | 362 if (request.handler) { |
271 request.handler->OnDeviceOpened(request.request_id, label, | 363 request.handler->OnDeviceOpened(request.request_id, label, |
272 device_info); | 364 device_info); |
273 DVLOG(1) << "MediaStreamDispatcher::OnDeviceOpened(" | 365 DVLOG(1) << "MediaStreamDispatcher::OnDeviceOpened(" |
274 << request.request_id << ", " << label << ")"; | 366 << request.request_id << ", " << label << ")"; |
275 } | 367 } |
276 requests_.erase(it); | 368 requests_.erase(it); |
277 break; | 369 break; |
278 } | 370 } |
279 } | 371 } |
280 } | 372 } |
281 | 373 |
282 void MediaStreamDispatcher::OnDeviceOpenFailed(int request_id) { | 374 void MediaStreamDispatcher::OnDeviceOpenFailed(int request_id) { |
375 DCHECK(main_loop_->BelongsToCurrentThread()); | |
283 for (RequestList::iterator it = requests_.begin(); | 376 for (RequestList::iterator it = requests_.begin(); |
284 it != requests_.end(); ++it) { | 377 it != requests_.end(); ++it) { |
285 Request& request = *it; | 378 Request& request = *it; |
286 if (request.ipc_request == request_id) { | 379 if (request.ipc_request == request_id) { |
287 if (request.handler) { | 380 if (request.handler) { |
288 request.handler->OnDeviceOpenFailed(request.request_id); | 381 request.handler->OnDeviceOpenFailed(request.request_id); |
289 DVLOG(1) << "MediaStreamDispatcher::OnDeviceOpenFailed(" | 382 DVLOG(1) << "MediaStreamDispatcher::OnDeviceOpenFailed(" |
290 << request.request_id << ")\n"; | 383 << request.request_id << ")\n"; |
291 } | 384 } |
292 requests_.erase(it); | 385 requests_.erase(it); |
(...skipping 18 matching lines...) Expand all Loading... | |
311 | 404 |
312 int MediaStreamDispatcher::video_session_id(const std::string& label, | 405 int MediaStreamDispatcher::video_session_id(const std::string& label, |
313 int index) { | 406 int index) { |
314 LabelStreamMap::iterator it = label_stream_map_.find(label); | 407 LabelStreamMap::iterator it = label_stream_map_.find(label); |
315 if (it == label_stream_map_.end()) | 408 if (it == label_stream_map_.end()) |
316 return media_stream::StreamDeviceInfo::kNoId; | 409 return media_stream::StreamDeviceInfo::kNoId; |
317 | 410 |
318 DCHECK_GT(it->second.video_array.size(), static_cast<size_t>(index)); | 411 DCHECK_GT(it->second.video_array.size(), static_cast<size_t>(index)); |
319 return it->second.video_array[index].session_id; | 412 return it->second.video_array[index].session_id; |
320 } | 413 } |
OLD | NEW |