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