| 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 "base/message_loop_proxy.h" | 8 #include "base/message_loop_proxy.h" |
| 9 #include "content/common/media/media_stream_messages.h" | 9 #include "content/common/media/media_stream_messages.h" |
| 10 #include "content/renderer/media/media_stream_dispatcher_eventhandler.h" | 10 #include "content/renderer/media/media_stream_dispatcher_eventhandler.h" |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 request_id, event_handler, &video_enumeration_state_); | 157 request_id, event_handler, &video_enumeration_state_); |
| 158 } | 158 } |
| 159 | 159 |
| 160 void MediaStreamDispatcher::RemoveEnumerationRequest( | 160 void MediaStreamDispatcher::RemoveEnumerationRequest( |
| 161 int request_id, | 161 int request_id, |
| 162 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, | 162 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, |
| 163 EnumerationState* state) { | 163 EnumerationState* state) { |
| 164 EnumerationRequestList* requests = &state->requests; | 164 EnumerationRequestList* requests = &state->requests; |
| 165 for (EnumerationRequestList::iterator it = requests->begin(); | 165 for (EnumerationRequestList::iterator it = requests->begin(); |
| 166 it != requests->end(); ++it) { | 166 it != requests->end(); ++it) { |
| 167 if (it->request_id == request_id && it->handler == event_handler) { | 167 if (it->request_id == request_id && |
| 168 it->handler.get() == event_handler.get()) { |
| 168 requests->erase(it); | 169 requests->erase(it); |
| 169 if (requests->empty() && state->cached_devices) { | 170 if (requests->empty() && state->cached_devices) { |
| 170 // No more request and has a label, try to stop the label | 171 // No more request and has a label, try to stop the label |
| 171 // and invalidate the state. | 172 // and invalidate the state. |
| 172 Send(new MediaStreamHostMsg_StopGeneratedStream( | 173 Send(new MediaStreamHostMsg_StopGeneratedStream( |
| 173 routing_id(), state->cached_devices->label)); | 174 routing_id(), state->cached_devices->label)); |
| 174 state->ipc_id = -1; | 175 state->ipc_id = -1; |
| 175 state->cached_devices.reset(); | 176 state->cached_devices.reset(); |
| 176 } | 177 } |
| 177 return; | 178 return; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 | 243 |
| 243 for (RequestList::iterator it = requests_.begin(); | 244 for (RequestList::iterator it = requests_.begin(); |
| 244 it != requests_.end(); ++it) { | 245 it != requests_.end(); ++it) { |
| 245 Request& request = *it; | 246 Request& request = *it; |
| 246 if (request.ipc_request == request_id) { | 247 if (request.ipc_request == request_id) { |
| 247 Stream new_stream; | 248 Stream new_stream; |
| 248 new_stream.handler = request.handler; | 249 new_stream.handler = request.handler; |
| 249 new_stream.audio_array = audio_array; | 250 new_stream.audio_array = audio_array; |
| 250 new_stream.video_array = video_array; | 251 new_stream.video_array = video_array; |
| 251 label_stream_map_[label] = new_stream; | 252 label_stream_map_[label] = new_stream; |
| 252 if (request.handler) { | 253 if (request.handler.get()) { |
| 253 request.handler->OnStreamGenerated(request.request_id, label, | 254 request.handler->OnStreamGenerated( |
| 254 audio_array, video_array); | 255 request.request_id, label, audio_array, video_array); |
| 255 DVLOG(1) << "MediaStreamDispatcher::OnStreamGenerated(" | 256 DVLOG(1) << "MediaStreamDispatcher::OnStreamGenerated(" |
| 256 << request.request_id << ", " << label << ")"; | 257 << request.request_id << ", " << label << ")"; |
| 257 } | 258 } |
| 258 requests_.erase(it); | 259 requests_.erase(it); |
| 259 break; | 260 break; |
| 260 } | 261 } |
| 261 } | 262 } |
| 262 } | 263 } |
| 263 | 264 |
| 264 void MediaStreamDispatcher::OnStreamGenerationFailed(int request_id) { | 265 void MediaStreamDispatcher::OnStreamGenerationFailed(int request_id) { |
| 265 DCHECK(main_loop_->BelongsToCurrentThread()); | 266 DCHECK(main_loop_->BelongsToCurrentThread()); |
| 266 for (RequestList::iterator it = requests_.begin(); | 267 for (RequestList::iterator it = requests_.begin(); |
| 267 it != requests_.end(); ++it) { | 268 it != requests_.end(); ++it) { |
| 268 Request& request = *it; | 269 Request& request = *it; |
| 269 if (request.ipc_request == request_id) { | 270 if (request.ipc_request == request_id) { |
| 270 if (request.handler) { | 271 if (request.handler.get()) { |
| 271 request.handler->OnStreamGenerationFailed(request.request_id); | 272 request.handler->OnStreamGenerationFailed(request.request_id); |
| 272 DVLOG(1) << "MediaStreamDispatcher::OnStreamGenerationFailed(" | 273 DVLOG(1) << "MediaStreamDispatcher::OnStreamGenerationFailed(" |
| 273 << request.request_id << ")\n"; | 274 << request.request_id << ")\n"; |
| 274 } | 275 } |
| 275 requests_.erase(it); | 276 requests_.erase(it); |
| 276 break; | 277 break; |
| 277 } | 278 } |
| 278 } | 279 } |
| 279 } | 280 } |
| 280 | 281 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 298 Send(new MediaStreamHostMsg_StopGeneratedStream(routing_id(), label)); | 299 Send(new MediaStreamHostMsg_StopGeneratedStream(routing_id(), label)); |
| 299 return; | 300 return; |
| 300 } | 301 } |
| 301 | 302 |
| 302 DCHECK(!label.empty()); | 303 DCHECK(!label.empty()); |
| 303 state->cached_devices.reset(new EnumerationState::CachedDevices( | 304 state->cached_devices.reset(new EnumerationState::CachedDevices( |
| 304 label, device_array)); | 305 label, device_array)); |
| 305 | 306 |
| 306 for (EnumerationRequestList::iterator it = state->requests.begin(); | 307 for (EnumerationRequestList::iterator it = state->requests.begin(); |
| 307 it != state->requests.end(); ++it) { | 308 it != state->requests.end(); ++it) { |
| 308 if (it->handler) { | 309 if (it->handler.get()) { |
| 309 it->handler->OnDevicesEnumerated(it->request_id, device_array); | 310 it->handler->OnDevicesEnumerated(it->request_id, device_array); |
| 310 DVLOG(1) << "MediaStreamDispatcher::OnDevicesEnumerated(" | 311 DVLOG(1) << "MediaStreamDispatcher::OnDevicesEnumerated(" |
| 311 << it->request_id << ")"; | 312 << it->request_id << ")"; |
| 312 } | 313 } |
| 313 } | 314 } |
| 314 } | 315 } |
| 315 | 316 |
| 316 void MediaStreamDispatcher::OnDevicesEnumerationFailed(int request_id) { | 317 void MediaStreamDispatcher::OnDevicesEnumerationFailed(int request_id) { |
| 317 DCHECK(main_loop_->BelongsToCurrentThread()); | 318 DCHECK(main_loop_->BelongsToCurrentThread()); |
| 318 for (RequestList::iterator it = requests_.begin(); | 319 for (RequestList::iterator it = requests_.begin(); |
| 319 it != requests_.end(); ++it) { | 320 it != requests_.end(); ++it) { |
| 320 Request& request = *it; | 321 Request& request = *it; |
| 321 if (request.ipc_request == request_id) { | 322 if (request.ipc_request == request_id) { |
| 322 if (request.handler) { | 323 if (request.handler.get()) { |
| 323 request.handler->OnDevicesEnumerationFailed(request.request_id); | 324 request.handler->OnDevicesEnumerationFailed(request.request_id); |
| 324 DVLOG(1) << "MediaStreamDispatcher::OnDevicesEnumerationFailed(" | 325 DVLOG(1) << "MediaStreamDispatcher::OnDevicesEnumerationFailed(" |
| 325 << request.request_id << ")\n"; | 326 << request.request_id << ")\n"; |
| 326 } | 327 } |
| 327 requests_.erase(it); | 328 requests_.erase(it); |
| 328 break; | 329 break; |
| 329 } | 330 } |
| 330 } | 331 } |
| 331 } | 332 } |
| 332 | 333 |
| 333 void MediaStreamDispatcher::OnDeviceOpened( | 334 void MediaStreamDispatcher::OnDeviceOpened( |
| 334 int request_id, | 335 int request_id, |
| 335 const std::string& label, | 336 const std::string& label, |
| 336 const StreamDeviceInfo& device_info) { | 337 const StreamDeviceInfo& device_info) { |
| 337 DCHECK(main_loop_->BelongsToCurrentThread()); | 338 DCHECK(main_loop_->BelongsToCurrentThread()); |
| 338 for (RequestList::iterator it = requests_.begin(); | 339 for (RequestList::iterator it = requests_.begin(); |
| 339 it != requests_.end(); ++it) { | 340 it != requests_.end(); ++it) { |
| 340 Request& request = *it; | 341 Request& request = *it; |
| 341 if (request.ipc_request == request_id) { | 342 if (request.ipc_request == request_id) { |
| 342 Stream new_stream; | 343 Stream new_stream; |
| 343 new_stream.handler = request.handler; | 344 new_stream.handler = request.handler; |
| 344 if (IsAudioMediaType(device_info.device.type)) { | 345 if (IsAudioMediaType(device_info.device.type)) { |
| 345 new_stream.audio_array.push_back(device_info); | 346 new_stream.audio_array.push_back(device_info); |
| 346 } else if (IsVideoMediaType(device_info.device.type)) { | 347 } else if (IsVideoMediaType(device_info.device.type)) { |
| 347 new_stream.video_array.push_back(device_info); | 348 new_stream.video_array.push_back(device_info); |
| 348 } else { | 349 } else { |
| 349 NOTREACHED(); | 350 NOTREACHED(); |
| 350 } | 351 } |
| 351 label_stream_map_[label] = new_stream; | 352 label_stream_map_[label] = new_stream; |
| 352 if (request.handler) { | 353 if (request.handler.get()) { |
| 353 request.handler->OnDeviceOpened(request.request_id, label, | 354 request.handler->OnDeviceOpened(request.request_id, label, device_info); |
| 354 device_info); | |
| 355 DVLOG(1) << "MediaStreamDispatcher::OnDeviceOpened(" | 355 DVLOG(1) << "MediaStreamDispatcher::OnDeviceOpened(" |
| 356 << request.request_id << ", " << label << ")"; | 356 << request.request_id << ", " << label << ")"; |
| 357 } | 357 } |
| 358 requests_.erase(it); | 358 requests_.erase(it); |
| 359 break; | 359 break; |
| 360 } | 360 } |
| 361 } | 361 } |
| 362 } | 362 } |
| 363 | 363 |
| 364 void MediaStreamDispatcher::OnDeviceOpenFailed(int request_id) { | 364 void MediaStreamDispatcher::OnDeviceOpenFailed(int request_id) { |
| 365 DCHECK(main_loop_->BelongsToCurrentThread()); | 365 DCHECK(main_loop_->BelongsToCurrentThread()); |
| 366 for (RequestList::iterator it = requests_.begin(); | 366 for (RequestList::iterator it = requests_.begin(); |
| 367 it != requests_.end(); ++it) { | 367 it != requests_.end(); ++it) { |
| 368 Request& request = *it; | 368 Request& request = *it; |
| 369 if (request.ipc_request == request_id) { | 369 if (request.ipc_request == request_id) { |
| 370 if (request.handler) { | 370 if (request.handler.get()) { |
| 371 request.handler->OnDeviceOpenFailed(request.request_id); | 371 request.handler->OnDeviceOpenFailed(request.request_id); |
| 372 DVLOG(1) << "MediaStreamDispatcher::OnDeviceOpenFailed(" | 372 DVLOG(1) << "MediaStreamDispatcher::OnDeviceOpenFailed(" |
| 373 << request.request_id << ")\n"; | 373 << request.request_id << ")\n"; |
| 374 } | 374 } |
| 375 requests_.erase(it); | 375 requests_.erase(it); |
| 376 break; | 376 break; |
| 377 } | 377 } |
| 378 } | 378 } |
| 379 } | 379 } |
| 380 | 380 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 396 int index) { | 396 int index) { |
| 397 LabelStreamMap::iterator it = label_stream_map_.find(label); | 397 LabelStreamMap::iterator it = label_stream_map_.find(label); |
| 398 if (it == label_stream_map_.end()) | 398 if (it == label_stream_map_.end()) |
| 399 return StreamDeviceInfo::kNoId; | 399 return StreamDeviceInfo::kNoId; |
| 400 | 400 |
| 401 DCHECK_GT(it->second.video_array.size(), static_cast<size_t>(index)); | 401 DCHECK_GT(it->second.video_array.size(), static_cast<size_t>(index)); |
| 402 return it->second.video_array[index].session_id; | 402 return it->second.video_array[index].session_id; |
| 403 } | 403 } |
| 404 | 404 |
| 405 } // namespace content | 405 } // namespace content |
| OLD | NEW |