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