OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 << ", {label = " << label << "}"; | 58 << ", {label = " << label << "}"; |
59 | 59 |
60 LabelStreamMap::iterator it = label_stream_map_.find(label); | 60 LabelStreamMap::iterator it = label_stream_map_.find(label); |
61 if (it == label_stream_map_.end()) | 61 if (it == label_stream_map_.end()) |
62 return; | 62 return; |
63 | 63 |
64 Send(new MediaStreamHostMsg_StopGeneratedStream(routing_id(), label)); | 64 Send(new MediaStreamHostMsg_StopGeneratedStream(routing_id(), label)); |
65 label_stream_map_.erase(it); | 65 label_stream_map_.erase(it); |
66 } | 66 } |
67 | 67 |
| 68 void MediaStreamDispatcher::EnumerateDevices( |
| 69 int request_id, |
| 70 MediaStreamDispatcherEventHandler* event_handler, |
| 71 media_stream::MediaStreamType type, |
| 72 const std::string& security_origin) { |
| 73 DVLOG(1) << "MediaStreamDispatcher::EnumerateDevices(" |
| 74 << request_id << ")"; |
| 75 |
| 76 requests_.push_back(Request(event_handler, request_id, next_ipc_id_)); |
| 77 Send(new MediaStreamHostMsg_EnumerateDevices(routing_id(), |
| 78 next_ipc_id_++, |
| 79 type, |
| 80 security_origin)); |
| 81 } |
| 82 |
| 83 void MediaStreamDispatcher::OpenDevice( |
| 84 int request_id, |
| 85 MediaStreamDispatcherEventHandler* event_handler, |
| 86 const std::string& device_id, |
| 87 media_stream::MediaStreamType type, |
| 88 const std::string& security_origin) { |
| 89 DVLOG(1) << "MediaStreamDispatcher::OpenDevice(" << request_id << ")"; |
| 90 |
| 91 requests_.push_back(Request(event_handler, request_id, next_ipc_id_)); |
| 92 Send(new MediaStreamHostMsg_OpenDevice(routing_id(), |
| 93 next_ipc_id_++, |
| 94 device_id, |
| 95 type, |
| 96 security_origin)); |
| 97 } |
| 98 |
| 99 void MediaStreamDispatcher::CloseDevice(const std::string& label) { |
| 100 DVLOG(1) << "MediaStreamDispatcher::CloseDevice" |
| 101 << ", {label = " << label << "}"; |
| 102 |
| 103 StopStream(label); |
| 104 } |
| 105 |
68 bool MediaStreamDispatcher::OnMessageReceived(const IPC::Message& message) { | 106 bool MediaStreamDispatcher::OnMessageReceived(const IPC::Message& message) { |
69 bool handled = true; | 107 bool handled = true; |
70 IPC_BEGIN_MESSAGE_MAP(MediaStreamDispatcher, message) | 108 IPC_BEGIN_MESSAGE_MAP(MediaStreamDispatcher, message) |
71 IPC_MESSAGE_HANDLER(MediaStreamMsg_StreamGenerated, | 109 IPC_MESSAGE_HANDLER(MediaStreamMsg_StreamGenerated, |
72 OnStreamGenerated) | 110 OnStreamGenerated) |
73 IPC_MESSAGE_HANDLER(MediaStreamMsg_StreamGenerationFailed, | 111 IPC_MESSAGE_HANDLER(MediaStreamMsg_StreamGenerationFailed, |
74 OnStreamGenerationFailed) | 112 OnStreamGenerationFailed) |
75 IPC_MESSAGE_HANDLER(MediaStreamHostMsg_VideoDeviceFailed, | 113 IPC_MESSAGE_HANDLER(MediaStreamHostMsg_VideoDeviceFailed, |
76 OnVideoDeviceFailed) | 114 OnVideoDeviceFailed) |
77 IPC_MESSAGE_HANDLER(MediaStreamHostMsg_AudioDeviceFailed, | 115 IPC_MESSAGE_HANDLER(MediaStreamHostMsg_AudioDeviceFailed, |
78 OnAudioDeviceFailed) | 116 OnAudioDeviceFailed) |
| 117 IPC_MESSAGE_HANDLER(MediaStreamMsg_DevicesEnumerated, |
| 118 OnDevicesEnumerated) |
| 119 IPC_MESSAGE_HANDLER(MediaStreamMsg_DevicesEnumerationFailed, |
| 120 OnDevicesEnumerationFailed) |
| 121 IPC_MESSAGE_HANDLER(MediaStreamMsg_DeviceOpened, |
| 122 OnDeviceOpened) |
| 123 IPC_MESSAGE_HANDLER(MediaStreamMsg_DeviceOpenFailed, |
| 124 OnDeviceOpenFailed) |
79 IPC_MESSAGE_UNHANDLED(handled = false) | 125 IPC_MESSAGE_UNHANDLED(handled = false) |
80 IPC_END_MESSAGE_MAP() | 126 IPC_END_MESSAGE_MAP() |
81 return handled; | 127 return handled; |
82 } | 128 } |
83 | 129 |
84 void MediaStreamDispatcher::OnStreamGenerated( | 130 void MediaStreamDispatcher::OnStreamGenerated( |
85 int request_id, | 131 int request_id, |
86 const std::string& label, | 132 const std::string& label, |
87 const media_stream::StreamDeviceInfoArray& audio_array, | 133 const media_stream::StreamDeviceInfoArray& audio_array, |
88 const media_stream::StreamDeviceInfoArray& video_array) { | 134 const media_stream::StreamDeviceInfoArray& video_array) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 return; | 187 return; |
142 | 188 |
143 // index is the index in the audio_array that has failed. | 189 // index is the index in the audio_array that has failed. |
144 DCHECK_GT(it->second.audio_array.size(), static_cast<size_t>(index)); | 190 DCHECK_GT(it->second.audio_array.size(), static_cast<size_t>(index)); |
145 media_stream::StreamDeviceInfoArray::iterator device_it = | 191 media_stream::StreamDeviceInfoArray::iterator device_it = |
146 it->second.audio_array.begin(); | 192 it->second.audio_array.begin(); |
147 it->second.audio_array.erase(device_it + index); | 193 it->second.audio_array.erase(device_it + index); |
148 it->second.handler->OnAudioDeviceFailed(label, index); | 194 it->second.handler->OnAudioDeviceFailed(label, index); |
149 } | 195 } |
150 | 196 |
| 197 void MediaStreamDispatcher::OnDevicesEnumerated( |
| 198 int request_id, |
| 199 const media_stream::StreamDeviceInfoArray& device_array) { |
| 200 |
| 201 for (RequestList::iterator it = requests_.begin(); |
| 202 it != requests_.end(); ++it) { |
| 203 Request& request = *it; |
| 204 if (request.ipc_request == request_id) { |
| 205 request.handler->OnDevicesEnumerated(request.request_id, device_array); |
| 206 DVLOG(1) << "MediaStreamDispatcher::OnDevicesEnumerated(" |
| 207 << request.request_id << ")"; |
| 208 requests_.erase(it); |
| 209 break; |
| 210 } |
| 211 } |
| 212 } |
| 213 |
| 214 void MediaStreamDispatcher::OnDevicesEnumerationFailed(int request_id) { |
| 215 for (RequestList::iterator it = requests_.begin(); |
| 216 it != requests_.end(); ++it) { |
| 217 Request& request = *it; |
| 218 if (request.ipc_request == request_id) { |
| 219 request.handler->OnStreamGenerationFailed(request.request_id); |
| 220 DVLOG(1) << "MediaStreamDispatcher::OnDevicesEnumerationFailed(" |
| 221 << request.request_id << ")\n"; |
| 222 requests_.erase(it); |
| 223 break; |
| 224 } |
| 225 } |
| 226 } |
| 227 |
| 228 void MediaStreamDispatcher::OnDeviceOpened( |
| 229 int request_id, |
| 230 const std::string& label, |
| 231 const media_stream::StreamDeviceInfo& device_info) { |
| 232 for (RequestList::iterator it = requests_.begin(); |
| 233 it != requests_.end(); ++it) { |
| 234 Request& request = *it; |
| 235 if (request.ipc_request == request_id) { |
| 236 Stream new_stream; |
| 237 new_stream.handler = request.handler; |
| 238 new_stream.video_array.push_back(device_info); |
| 239 label_stream_map_[label] = new_stream; |
| 240 request.handler->OnDeviceOpened(request.request_id, label, |
| 241 device_info); |
| 242 DVLOG(1) << "MediaStreamDispatcher::OnDeviceOpened(" |
| 243 << request.request_id << ", " << label << ")"; |
| 244 requests_.erase(it); |
| 245 break; |
| 246 } |
| 247 } |
| 248 } |
| 249 |
| 250 void MediaStreamDispatcher::OnDeviceOpenFailed(int request_id) { |
| 251 for (RequestList::iterator it = requests_.begin(); |
| 252 it != requests_.end(); ++it) { |
| 253 Request& request = *it; |
| 254 if (request.ipc_request == request_id) { |
| 255 request.handler->OnDeviceOpenFailed(request.request_id); |
| 256 DVLOG(1) << "MediaStreamDispatcher::OnDeviceOpenFailed(" |
| 257 << request.request_id << ")\n"; |
| 258 requests_.erase(it); |
| 259 break; |
| 260 } |
| 261 } |
| 262 } |
| 263 |
151 int MediaStreamDispatcher::audio_session_id(const std::string& label, | 264 int MediaStreamDispatcher::audio_session_id(const std::string& label, |
152 int index) { | 265 int index) { |
153 LabelStreamMap::iterator it = label_stream_map_.find(label); | 266 LabelStreamMap::iterator it = label_stream_map_.find(label); |
154 if (it == label_stream_map_.end()) | 267 if (it == label_stream_map_.end()) |
155 return media_stream::StreamDeviceInfo::kNoId; | 268 return media_stream::StreamDeviceInfo::kNoId; |
156 | 269 |
157 DCHECK_GT(it->second.audio_array.size(), static_cast<size_t>(index)); | 270 DCHECK_GT(it->second.audio_array.size(), static_cast<size_t>(index)); |
158 return it->second.audio_array[index].session_id; | 271 return it->second.audio_array[index].session_id; |
159 } | 272 } |
160 | 273 |
161 bool MediaStreamDispatcher::IsStream(const std::string& label) { | 274 bool MediaStreamDispatcher::IsStream(const std::string& label) { |
162 return label_stream_map_.find(label) != label_stream_map_.end(); | 275 return label_stream_map_.find(label) != label_stream_map_.end(); |
163 } | 276 } |
164 | 277 |
165 int MediaStreamDispatcher::video_session_id(const std::string& label, | 278 int MediaStreamDispatcher::video_session_id(const std::string& label, |
166 int index) { | 279 int index) { |
167 LabelStreamMap::iterator it = label_stream_map_.find(label); | 280 LabelStreamMap::iterator it = label_stream_map_.find(label); |
168 if (it == label_stream_map_.end()) | 281 if (it == label_stream_map_.end()) |
169 return media_stream::StreamDeviceInfo::kNoId; | 282 return media_stream::StreamDeviceInfo::kNoId; |
170 | 283 |
171 DCHECK_GT(it->second.video_array.size(), static_cast<size_t>(index)); | 284 DCHECK_GT(it->second.video_array.size(), static_cast<size_t>(index)); |
172 return it->second.video_array[index].session_id; | 285 return it->second.video_array[index].session_id; |
173 } | 286 } |
OLD | NEW |