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 : ipc_id(-1) { | |
45 } | |
46 | |
47 MediaStreamDispatcher::EnumerationState::~EnumerationState() {} | |
48 | |
49 struct MediaStreamDispatcher::EnumerationState::CachedDevices { | |
50 CachedDevices(const std::string& label, | |
51 const media_stream::StreamDeviceInfoArray& device_array) | |
52 : label(label), | |
53 devices(device_array) { | |
54 } | |
55 ~CachedDevices() {} | |
56 | |
57 std::string label; | |
58 media_stream::StreamDeviceInfoArray devices; | |
59 }; | |
60 | |
61 MediaStreamDispatcher::MediaStreamDispatcher(RenderViewImpl* render_view) | 34 MediaStreamDispatcher::MediaStreamDispatcher(RenderViewImpl* render_view) |
62 : content::RenderViewObserver(render_view), | 35 : content::RenderViewObserver(render_view), |
63 main_loop_(base::MessageLoopProxy::current()), | |
64 next_ipc_id_(0) { | 36 next_ipc_id_(0) { |
65 } | 37 } |
66 | 38 |
67 MediaStreamDispatcher::~MediaStreamDispatcher() {} | 39 MediaStreamDispatcher::~MediaStreamDispatcher() {} |
68 | 40 |
69 void MediaStreamDispatcher::GenerateStream( | 41 void MediaStreamDispatcher::GenerateStream( |
70 int request_id, | 42 int request_id, |
71 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, | 43 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, |
72 media_stream::StreamOptions components, | 44 media_stream::StreamOptions components, |
73 const GURL& security_origin) { | 45 const GURL& security_origin) { |
74 DCHECK(main_loop_->BelongsToCurrentThread()); | |
75 DVLOG(1) << "MediaStreamDispatcher::GenerateStream(" << request_id << ")"; | 46 DVLOG(1) << "MediaStreamDispatcher::GenerateStream(" << request_id << ")"; |
76 | 47 |
77 requests_.push_back(Request(event_handler, request_id, next_ipc_id_)); | 48 requests_.push_back(Request(event_handler, request_id, next_ipc_id_)); |
78 Send(new MediaStreamHostMsg_GenerateStream(routing_id(), | 49 Send(new MediaStreamHostMsg_GenerateStream(routing_id(), |
79 next_ipc_id_++, | 50 next_ipc_id_++, |
80 components, | 51 components, |
81 security_origin)); | 52 security_origin)); |
82 } | 53 } |
83 | 54 |
84 void MediaStreamDispatcher::CancelGenerateStream(int request_id) { | 55 void MediaStreamDispatcher::CancelGenerateStream(int request_id) { |
85 DCHECK(main_loop_->BelongsToCurrentThread()); | |
86 DVLOG(1) << "MediaStreamDispatcher::CancelGenerateStream" | 56 DVLOG(1) << "MediaStreamDispatcher::CancelGenerateStream" |
87 << ", {request_id = " << request_id << "}"; | 57 << ", {request_id = " << request_id << "}"; |
88 | 58 |
89 RequestList::iterator it = requests_.begin(); | 59 RequestList::iterator it = requests_.begin(); |
90 for (; it != requests_.end(); ++it) { | 60 for (; it != requests_.end(); ++it) { |
91 Request& request = *it; | 61 Request& request = *it; |
92 if (request.request_id == request_id) { | 62 if (request.request_id == request_id) { |
93 requests_.erase(it); | 63 requests_.erase(it); |
94 Send(new MediaStreamHostMsg_CancelGenerateStream(routing_id(), | 64 Send(new MediaStreamHostMsg_CancelGenerateStream(routing_id(), |
95 request_id)); | 65 request_id)); |
96 break; | 66 break; |
97 } | 67 } |
98 } | 68 } |
99 } | 69 } |
100 | 70 |
101 void MediaStreamDispatcher::StopStream(const std::string& label) { | 71 void MediaStreamDispatcher::StopStream(const std::string& label) { |
102 DCHECK(main_loop_->BelongsToCurrentThread()); | |
103 DVLOG(1) << "MediaStreamDispatcher::StopStream" | 72 DVLOG(1) << "MediaStreamDispatcher::StopStream" |
104 << ", {label = " << label << "}"; | 73 << ", {label = " << label << "}"; |
105 | 74 |
106 LabelStreamMap::iterator it = label_stream_map_.find(label); | 75 LabelStreamMap::iterator it = label_stream_map_.find(label); |
107 if (it == label_stream_map_.end()) | 76 if (it == label_stream_map_.end()) |
108 return; | 77 return; |
109 | 78 |
110 Send(new MediaStreamHostMsg_StopGeneratedStream(routing_id(), label)); | 79 Send(new MediaStreamHostMsg_StopGeneratedStream(routing_id(), label)); |
111 label_stream_map_.erase(it); | 80 label_stream_map_.erase(it); |
112 } | 81 } |
113 | 82 |
114 void MediaStreamDispatcher::EnumerateDevices( | 83 void MediaStreamDispatcher::EnumerateDevices( |
115 int request_id, | 84 int request_id, |
116 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, | 85 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, |
117 media_stream::MediaStreamType type, | 86 media_stream::MediaStreamType type, |
118 const GURL& security_origin) { | 87 const GURL& security_origin) { |
119 DCHECK(main_loop_->BelongsToCurrentThread()); | |
120 DCHECK(type == content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE || | |
121 type == content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE); | |
122 DVLOG(1) << "MediaStreamDispatcher::EnumerateDevices(" | 88 DVLOG(1) << "MediaStreamDispatcher::EnumerateDevices(" |
123 << request_id << ")"; | 89 << request_id << ")"; |
124 | 90 |
125 EnumerationState* state = | 91 requests_.push_back(Request(event_handler, request_id, next_ipc_id_)); |
126 (type == content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE ? | 92 Send(new MediaStreamHostMsg_EnumerateDevices(routing_id(), |
127 &audio_enumeration_state_ : &video_enumeration_state_); | 93 next_ipc_id_++, |
128 state->requests.push_back( | 94 type, |
129 EnumerationRequest(event_handler, request_id)); | 95 security_origin)); |
130 | |
131 if (state->cached_devices.get()) { | |
132 event_handler->OnDevicesEnumerated( | |
133 request_id, state->cached_devices->devices); | |
134 } else if (state->ipc_id < 0) { | |
135 Send(new MediaStreamHostMsg_EnumerateDevices(routing_id(), | |
136 next_ipc_id_, | |
137 type, | |
138 security_origin)); | |
139 state->ipc_id = next_ipc_id_++; | |
140 } | |
141 } | |
142 | |
143 void MediaStreamDispatcher::StopEnumerateDevices( | |
144 int request_id, | |
145 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler) { | |
146 DCHECK(main_loop_->BelongsToCurrentThread()); | |
147 DVLOG(1) << "MediaStreamDispatcher::StopEnumerateDevices(" | |
148 << request_id << ")"; | |
149 | |
150 // Remove the request. | |
151 RemoveEnumerationRequest( | |
152 request_id, event_handler, &audio_enumeration_state_); | |
153 RemoveEnumerationRequest( | |
154 request_id, event_handler, &video_enumeration_state_); | |
155 } | |
156 | |
157 void MediaStreamDispatcher::RemoveEnumerationRequest( | |
158 int request_id, | |
159 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, | |
160 EnumerationState* state) { | |
161 EnumerationRequestList* requests = &state->requests; | |
162 for (EnumerationRequestList::iterator it = requests->begin(); | |
163 it != requests->end(); ++it) { | |
164 if (it->request_id == request_id && it->handler == event_handler) { | |
165 requests->erase(it); | |
166 if (requests->empty() && !state->cached_devices.get()) { | |
167 // No more request and has a label, try to stop the label | |
168 // and invalidate the state. | |
169 Send(new MediaStreamHostMsg_StopGeneratedStream( | |
170 routing_id(), state->cached_devices->label)); | |
171 state->ipc_id = -1; | |
172 state->cached_devices.reset(); | |
173 } | |
174 return; | |
175 } | |
176 } | |
177 } | 96 } |
178 | 97 |
179 void MediaStreamDispatcher::OpenDevice( | 98 void MediaStreamDispatcher::OpenDevice( |
180 int request_id, | 99 int request_id, |
181 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, | 100 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, |
182 const std::string& device_id, | 101 const std::string& device_id, |
183 media_stream::MediaStreamType type, | 102 media_stream::MediaStreamType type, |
184 const GURL& security_origin) { | 103 const GURL& security_origin) { |
185 DCHECK(main_loop_->BelongsToCurrentThread()); | |
186 DVLOG(1) << "MediaStreamDispatcher::OpenDevice(" << request_id << ")"; | 104 DVLOG(1) << "MediaStreamDispatcher::OpenDevice(" << request_id << ")"; |
187 | 105 |
188 requests_.push_back(Request(event_handler, request_id, next_ipc_id_)); | 106 requests_.push_back(Request(event_handler, request_id, next_ipc_id_)); |
189 Send(new MediaStreamHostMsg_OpenDevice(routing_id(), | 107 Send(new MediaStreamHostMsg_OpenDevice(routing_id(), |
190 next_ipc_id_++, | 108 next_ipc_id_++, |
191 device_id, | 109 device_id, |
192 type, | 110 type, |
193 security_origin)); | 111 security_origin)); |
194 } | 112 } |
195 | 113 |
196 void MediaStreamDispatcher::CloseDevice(const std::string& label) { | 114 void MediaStreamDispatcher::CloseDevice(const std::string& label) { |
197 DCHECK(main_loop_->BelongsToCurrentThread()); | |
198 DVLOG(1) << "MediaStreamDispatcher::CloseDevice" | 115 DVLOG(1) << "MediaStreamDispatcher::CloseDevice" |
199 << ", {label = " << label << "}"; | 116 << ", {label = " << label << "}"; |
200 | 117 |
201 StopStream(label); | 118 StopStream(label); |
202 } | 119 } |
203 | 120 |
204 bool MediaStreamDispatcher::OnMessageReceived(const IPC::Message& message) { | 121 bool MediaStreamDispatcher::OnMessageReceived(const IPC::Message& message) { |
205 bool handled = true; | 122 bool handled = true; |
206 IPC_BEGIN_MESSAGE_MAP(MediaStreamDispatcher, message) | 123 IPC_BEGIN_MESSAGE_MAP(MediaStreamDispatcher, message) |
207 IPC_MESSAGE_HANDLER(MediaStreamMsg_StreamGenerated, | 124 IPC_MESSAGE_HANDLER(MediaStreamMsg_StreamGenerated, |
(...skipping 15 matching lines...) Expand all Loading... |
223 IPC_MESSAGE_UNHANDLED(handled = false) | 140 IPC_MESSAGE_UNHANDLED(handled = false) |
224 IPC_END_MESSAGE_MAP() | 141 IPC_END_MESSAGE_MAP() |
225 return handled; | 142 return handled; |
226 } | 143 } |
227 | 144 |
228 void MediaStreamDispatcher::OnStreamGenerated( | 145 void MediaStreamDispatcher::OnStreamGenerated( |
229 int request_id, | 146 int request_id, |
230 const std::string& label, | 147 const std::string& label, |
231 const media_stream::StreamDeviceInfoArray& audio_array, | 148 const media_stream::StreamDeviceInfoArray& audio_array, |
232 const media_stream::StreamDeviceInfoArray& video_array) { | 149 const media_stream::StreamDeviceInfoArray& video_array) { |
233 DCHECK(main_loop_->BelongsToCurrentThread()); | |
234 | 150 |
235 for (RequestList::iterator it = requests_.begin(); | 151 for (RequestList::iterator it = requests_.begin(); |
236 it != requests_.end(); ++it) { | 152 it != requests_.end(); ++it) { |
237 Request& request = *it; | 153 Request& request = *it; |
238 if (request.ipc_request == request_id) { | 154 if (request.ipc_request == request_id) { |
239 Stream new_stream; | 155 Stream new_stream; |
240 new_stream.handler = request.handler; | 156 new_stream.handler = request.handler; |
241 new_stream.audio_array = audio_array; | 157 new_stream.audio_array = audio_array; |
242 new_stream.video_array = video_array; | 158 new_stream.video_array = video_array; |
243 label_stream_map_[label] = new_stream; | 159 label_stream_map_[label] = new_stream; |
244 if (request.handler) { | 160 if (request.handler) { |
245 request.handler->OnStreamGenerated(request.request_id, label, | 161 request.handler->OnStreamGenerated(request.request_id, label, |
246 audio_array, video_array); | 162 audio_array, video_array); |
247 DVLOG(1) << "MediaStreamDispatcher::OnStreamGenerated(" | 163 DVLOG(1) << "MediaStreamDispatcher::OnStreamGenerated(" |
248 << request.request_id << ", " << label << ")"; | 164 << request.request_id << ", " << label << ")"; |
249 } | 165 } |
250 requests_.erase(it); | 166 requests_.erase(it); |
251 break; | 167 break; |
252 } | 168 } |
253 } | 169 } |
254 } | 170 } |
255 | 171 |
256 void MediaStreamDispatcher::OnStreamGenerationFailed(int request_id) { | 172 void MediaStreamDispatcher::OnStreamGenerationFailed(int request_id) { |
257 DCHECK(main_loop_->BelongsToCurrentThread()); | |
258 for (RequestList::iterator it = requests_.begin(); | 173 for (RequestList::iterator it = requests_.begin(); |
259 it != requests_.end(); ++it) { | 174 it != requests_.end(); ++it) { |
260 Request& request = *it; | 175 Request& request = *it; |
261 if (request.ipc_request == request_id) { | 176 if (request.ipc_request == request_id) { |
262 if (request.handler) { | 177 if (request.handler) { |
263 request.handler->OnStreamGenerationFailed(request.request_id); | 178 request.handler->OnStreamGenerationFailed(request.request_id); |
264 DVLOG(1) << "MediaStreamDispatcher::OnStreamGenerationFailed(" | 179 DVLOG(1) << "MediaStreamDispatcher::OnStreamGenerationFailed(" |
265 << request.request_id << ")\n"; | 180 << request.request_id << ")\n"; |
266 } | 181 } |
267 requests_.erase(it); | 182 requests_.erase(it); |
268 break; | 183 break; |
269 } | 184 } |
270 } | 185 } |
271 } | 186 } |
272 | 187 |
273 void MediaStreamDispatcher::OnVideoDeviceFailed(const std::string& label, | 188 void MediaStreamDispatcher::OnVideoDeviceFailed(const std::string& label, |
274 int index) { | 189 int index) { |
275 DCHECK(main_loop_->BelongsToCurrentThread()); | |
276 LabelStreamMap::iterator it = label_stream_map_.find(label); | 190 LabelStreamMap::iterator it = label_stream_map_.find(label); |
277 if (it == label_stream_map_.end()) | 191 if (it == label_stream_map_.end()) |
278 return; | 192 return; |
279 | 193 |
280 // index is the index in the video_array that has failed. | 194 // index is the index in the video_array that has failed. |
281 DCHECK_GT(it->second.video_array.size(), static_cast<size_t>(index)); | 195 DCHECK_GT(it->second.video_array.size(), static_cast<size_t>(index)); |
282 media_stream::StreamDeviceInfoArray::iterator device_it = | 196 media_stream::StreamDeviceInfoArray::iterator device_it = |
283 it->second.video_array.begin(); | 197 it->second.video_array.begin(); |
284 it->second.video_array.erase(device_it + index); | 198 it->second.video_array.erase(device_it + index); |
285 if (it->second.handler) | 199 if (it->second.handler) |
286 it->second.handler->OnVideoDeviceFailed(label, index); | 200 it->second.handler->OnVideoDeviceFailed(label, index); |
287 } | 201 } |
288 | 202 |
289 void MediaStreamDispatcher::OnAudioDeviceFailed(const std::string& label, | 203 void MediaStreamDispatcher::OnAudioDeviceFailed(const std::string& label, |
290 int index) { | 204 int index) { |
291 DCHECK(main_loop_->BelongsToCurrentThread()); | |
292 LabelStreamMap::iterator it = label_stream_map_.find(label); | 205 LabelStreamMap::iterator it = label_stream_map_.find(label); |
293 if (it == label_stream_map_.end()) | 206 if (it == label_stream_map_.end()) |
294 return; | 207 return; |
295 | 208 |
296 // index is the index in the audio_array that has failed. | 209 // index is the index in the audio_array that has failed. |
297 DCHECK_GT(it->second.audio_array.size(), static_cast<size_t>(index)); | 210 DCHECK_GT(it->second.audio_array.size(), static_cast<size_t>(index)); |
298 media_stream::StreamDeviceInfoArray::iterator device_it = | 211 media_stream::StreamDeviceInfoArray::iterator device_it = |
299 it->second.audio_array.begin(); | 212 it->second.audio_array.begin(); |
300 it->second.audio_array.erase(device_it + index); | 213 it->second.audio_array.erase(device_it + index); |
301 if (it->second.handler) | 214 if (it->second.handler) |
302 it->second.handler->OnAudioDeviceFailed(label, index); | 215 it->second.handler->OnAudioDeviceFailed(label, index); |
303 } | 216 } |
304 | 217 |
305 void MediaStreamDispatcher::OnDevicesEnumerated( | 218 void MediaStreamDispatcher::OnDevicesEnumerated( |
306 int request_id, | 219 int request_id, |
307 const std::string& label, | |
308 const media_stream::StreamDeviceInfoArray& device_array) { | 220 const media_stream::StreamDeviceInfoArray& device_array) { |
309 DCHECK(main_loop_->BelongsToCurrentThread()); | |
310 DCHECK_GE(request_id, 0); | |
311 | 221 |
312 EnumerationState* state; | 222 for (RequestList::iterator it = requests_.begin(); |
313 if (request_id == audio_enumeration_state_.ipc_id) { | 223 it != requests_.end(); ++it) { |
314 state = &audio_enumeration_state_; | 224 Request& request = *it; |
315 } else if (request_id == video_enumeration_state_.ipc_id) { | 225 if (request.ipc_request == request_id) { |
316 state = &video_enumeration_state_; | 226 if (request.handler) { |
317 } else { | 227 request.handler->OnDevicesEnumerated(request.request_id, device_array); |
318 // This could happen when requester has stopped enumeration while some | 228 DVLOG(1) << "MediaStreamDispatcher::OnDevicesEnumerated(" |
319 // enumerated response is on the way. Have to stop the |label| because | 229 << request.request_id << ")"; |
320 // this might be the first enumerated device list is received. This also | 230 } |
321 // lead to same label being stopped multiple times. | 231 requests_.erase(it); |
322 Send(new MediaStreamHostMsg_StopGeneratedStream(routing_id(), label)); | 232 break; |
323 return; | |
324 } | |
325 | |
326 DCHECK(!label.empty()); | |
327 state->cached_devices.reset(new EnumerationState::CachedDevices( | |
328 label, device_array)); | |
329 | |
330 for (EnumerationRequestList::iterator it = state->requests.begin(); | |
331 it != state->requests.end(); ++it) { | |
332 if (it->handler) { | |
333 it->handler->OnDevicesEnumerated(it->request_id, device_array); | |
334 DVLOG(1) << "MediaStreamDispatcher::OnDevicesEnumerated(" | |
335 << it->request_id << ")"; | |
336 } | 233 } |
337 } | 234 } |
338 } | 235 } |
339 | 236 |
340 void MediaStreamDispatcher::OnDevicesEnumerationFailed(int request_id) { | 237 void MediaStreamDispatcher::OnDevicesEnumerationFailed(int request_id) { |
341 DCHECK(main_loop_->BelongsToCurrentThread()); | |
342 for (RequestList::iterator it = requests_.begin(); | 238 for (RequestList::iterator it = requests_.begin(); |
343 it != requests_.end(); ++it) { | 239 it != requests_.end(); ++it) { |
344 Request& request = *it; | 240 Request& request = *it; |
345 if (request.ipc_request == request_id) { | 241 if (request.ipc_request == request_id) { |
346 if (request.handler) { | 242 if (request.handler) { |
347 request.handler->OnDevicesEnumerationFailed(request.request_id); | 243 request.handler->OnDevicesEnumerationFailed(request.request_id); |
348 DVLOG(1) << "MediaStreamDispatcher::OnDevicesEnumerationFailed(" | 244 DVLOG(1) << "MediaStreamDispatcher::OnDevicesEnumerationFailed(" |
349 << request.request_id << ")\n"; | 245 << request.request_id << ")\n"; |
350 } | 246 } |
351 requests_.erase(it); | 247 requests_.erase(it); |
352 break; | 248 break; |
353 } | 249 } |
354 } | 250 } |
355 } | 251 } |
356 | 252 |
357 void MediaStreamDispatcher::OnDeviceOpened( | 253 void MediaStreamDispatcher::OnDeviceOpened( |
358 int request_id, | 254 int request_id, |
359 const std::string& label, | 255 const std::string& label, |
360 const media_stream::StreamDeviceInfo& device_info) { | 256 const media_stream::StreamDeviceInfo& device_info) { |
361 DCHECK(main_loop_->BelongsToCurrentThread()); | |
362 for (RequestList::iterator it = requests_.begin(); | 257 for (RequestList::iterator it = requests_.begin(); |
363 it != requests_.end(); ++it) { | 258 it != requests_.end(); ++it) { |
364 Request& request = *it; | 259 Request& request = *it; |
365 if (request.ipc_request == request_id) { | 260 if (request.ipc_request == request_id) { |
366 Stream new_stream; | 261 Stream new_stream; |
367 new_stream.handler = request.handler; | 262 new_stream.handler = request.handler; |
368 if (device_info.stream_type == | 263 if (device_info.stream_type == |
369 content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE) { | 264 content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE) { |
370 new_stream.video_array.push_back(device_info); | 265 new_stream.video_array.push_back(device_info); |
371 } else { | 266 } else { |
372 new_stream.audio_array.push_back(device_info); | 267 new_stream.audio_array.push_back(device_info); |
373 } | 268 } |
374 label_stream_map_[label] = new_stream; | 269 label_stream_map_[label] = new_stream; |
375 if (request.handler) { | 270 if (request.handler) { |
376 request.handler->OnDeviceOpened(request.request_id, label, | 271 request.handler->OnDeviceOpened(request.request_id, label, |
377 device_info); | 272 device_info); |
378 DVLOG(1) << "MediaStreamDispatcher::OnDeviceOpened(" | 273 DVLOG(1) << "MediaStreamDispatcher::OnDeviceOpened(" |
379 << request.request_id << ", " << label << ")"; | 274 << request.request_id << ", " << label << ")"; |
380 } | 275 } |
381 requests_.erase(it); | 276 requests_.erase(it); |
382 break; | 277 break; |
383 } | 278 } |
384 } | 279 } |
385 } | 280 } |
386 | 281 |
387 void MediaStreamDispatcher::OnDeviceOpenFailed(int request_id) { | 282 void MediaStreamDispatcher::OnDeviceOpenFailed(int request_id) { |
388 DCHECK(main_loop_->BelongsToCurrentThread()); | |
389 for (RequestList::iterator it = requests_.begin(); | 283 for (RequestList::iterator it = requests_.begin(); |
390 it != requests_.end(); ++it) { | 284 it != requests_.end(); ++it) { |
391 Request& request = *it; | 285 Request& request = *it; |
392 if (request.ipc_request == request_id) { | 286 if (request.ipc_request == request_id) { |
393 if (request.handler) { | 287 if (request.handler) { |
394 request.handler->OnDeviceOpenFailed(request.request_id); | 288 request.handler->OnDeviceOpenFailed(request.request_id); |
395 DVLOG(1) << "MediaStreamDispatcher::OnDeviceOpenFailed(" | 289 DVLOG(1) << "MediaStreamDispatcher::OnDeviceOpenFailed(" |
396 << request.request_id << ")\n"; | 290 << request.request_id << ")\n"; |
397 } | 291 } |
398 requests_.erase(it); | 292 requests_.erase(it); |
(...skipping 18 matching lines...) Expand all Loading... |
417 | 311 |
418 int MediaStreamDispatcher::video_session_id(const std::string& label, | 312 int MediaStreamDispatcher::video_session_id(const std::string& label, |
419 int index) { | 313 int index) { |
420 LabelStreamMap::iterator it = label_stream_map_.find(label); | 314 LabelStreamMap::iterator it = label_stream_map_.find(label); |
421 if (it == label_stream_map_.end()) | 315 if (it == label_stream_map_.end()) |
422 return media_stream::StreamDeviceInfo::kNoId; | 316 return media_stream::StreamDeviceInfo::kNoId; |
423 | 317 |
424 DCHECK_GT(it->second.video_array.size(), static_cast<size_t>(index)); | 318 DCHECK_GT(it->second.video_array.size(), static_cast<size_t>(index)); |
425 return it->second.video_array[index].session_id; | 319 return it->second.video_array[index].session_id; |
426 } | 320 } |
OLD | NEW |