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/browser/renderer_host/media/video_capture_host.h" | 5 #include "content/browser/renderer_host/media/video_capture_host.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "content/browser/browser_main_loop.h" | 9 #include "content/browser/browser_main_loop.h" |
10 #include "content/browser/renderer_host/media/media_stream_manager.h" | 10 #include "content/browser/renderer_host/media/media_stream_manager.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 const VideoCaptureControllerID& controller_id, | 50 const VideoCaptureControllerID& controller_id, |
51 base::SharedMemoryHandle handle, | 51 base::SharedMemoryHandle handle, |
52 int length, | 52 int length, |
53 int buffer_id) { | 53 int buffer_id) { |
54 BrowserThread::PostTask( | 54 BrowserThread::PostTask( |
55 BrowserThread::IO, FROM_HERE, | 55 BrowserThread::IO, FROM_HERE, |
56 base::Bind(&VideoCaptureHost::DoSendNewBufferOnIOThread, | 56 base::Bind(&VideoCaptureHost::DoSendNewBufferOnIOThread, |
57 this, controller_id, handle, length, buffer_id)); | 57 this, controller_id, handle, length, buffer_id)); |
58 } | 58 } |
59 | 59 |
| 60 void VideoCaptureHost::OnBufferDestroyed( |
| 61 const VideoCaptureControllerID& controller_id, |
| 62 int buffer_id) { |
| 63 BrowserThread::PostTask( |
| 64 BrowserThread::IO, FROM_HERE, |
| 65 base::Bind(&VideoCaptureHost::DoSendFreeBufferOnIOThread, |
| 66 this, controller_id, buffer_id)); |
| 67 } |
| 68 |
60 void VideoCaptureHost::OnBufferReady( | 69 void VideoCaptureHost::OnBufferReady( |
61 const VideoCaptureControllerID& controller_id, | 70 const VideoCaptureControllerID& controller_id, |
62 int buffer_id, | 71 int buffer_id, |
63 base::Time timestamp) { | 72 base::Time timestamp, |
| 73 const media::VideoCaptureFormat& frame_format) { |
64 BrowserThread::PostTask( | 74 BrowserThread::PostTask( |
65 BrowserThread::IO, FROM_HERE, | 75 BrowserThread::IO, FROM_HERE, |
66 base::Bind(&VideoCaptureHost::DoSendFilledBufferOnIOThread, | 76 base::Bind(&VideoCaptureHost::DoSendFilledBufferOnIOThread, |
67 this, controller_id, buffer_id, timestamp)); | 77 this, controller_id, buffer_id, timestamp, |
68 } | 78 frame_format)); |
69 | |
70 void VideoCaptureHost::OnFrameInfo( | |
71 const VideoCaptureControllerID& controller_id, | |
72 const media::VideoCaptureCapability& format) { | |
73 BrowserThread::PostTask( | |
74 BrowserThread::IO, | |
75 FROM_HERE, | |
76 base::Bind(&VideoCaptureHost::DoSendFrameInfoOnIOThread, | |
77 this, controller_id, format)); | |
78 } | |
79 | |
80 void VideoCaptureHost::OnFrameInfoChanged( | |
81 const VideoCaptureControllerID& controller_id, | |
82 int width, | |
83 int height, | |
84 int frame_rate) { | |
85 BrowserThread::PostTask( | |
86 BrowserThread::IO, FROM_HERE, | |
87 base::Bind(&VideoCaptureHost::DoSendFrameInfoChangedOnIOThread, | |
88 this, controller_id, width, height, frame_rate)); | |
89 } | 79 } |
90 | 80 |
91 void VideoCaptureHost::OnEnded(const VideoCaptureControllerID& controller_id) { | 81 void VideoCaptureHost::OnEnded(const VideoCaptureControllerID& controller_id) { |
92 DVLOG(1) << "VideoCaptureHost::OnEnded"; | 82 DVLOG(1) << "VideoCaptureHost::OnEnded"; |
93 BrowserThread::PostTask( | 83 BrowserThread::PostTask( |
94 BrowserThread::IO, FROM_HERE, | 84 BrowserThread::IO, FROM_HERE, |
95 base::Bind(&VideoCaptureHost::DoEndedOnIOThread, this, controller_id)); | 85 base::Bind(&VideoCaptureHost::DoEndedOnIOThread, this, controller_id)); |
96 } | 86 } |
97 | 87 |
98 void VideoCaptureHost::DoSendNewBufferOnIOThread( | 88 void VideoCaptureHost::DoSendNewBufferOnIOThread( |
99 const VideoCaptureControllerID& controller_id, | 89 const VideoCaptureControllerID& controller_id, |
100 base::SharedMemoryHandle handle, | 90 base::SharedMemoryHandle handle, |
101 int length, | 91 int length, |
102 int buffer_id) { | 92 int buffer_id) { |
103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
104 | 94 |
105 if (entries_.find(controller_id) == entries_.end()) | 95 if (entries_.find(controller_id) == entries_.end()) |
106 return; | 96 return; |
107 | 97 |
108 Send(new VideoCaptureMsg_NewBuffer(controller_id.device_id, handle, | 98 Send(new VideoCaptureMsg_NewBuffer(controller_id.device_id, handle, |
109 length, buffer_id)); | 99 length, buffer_id)); |
110 } | 100 } |
111 | 101 |
| 102 void VideoCaptureHost::DoSendFreeBufferOnIOThread( |
| 103 const VideoCaptureControllerID& controller_id, |
| 104 int buffer_id) { |
| 105 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 106 |
| 107 if (entries_.find(controller_id) == entries_.end()) |
| 108 return; |
| 109 |
| 110 Send(new VideoCaptureMsg_FreeBuffer(controller_id.device_id, buffer_id)); |
| 111 } |
| 112 |
112 void VideoCaptureHost::DoSendFilledBufferOnIOThread( | 113 void VideoCaptureHost::DoSendFilledBufferOnIOThread( |
113 const VideoCaptureControllerID& controller_id, | 114 const VideoCaptureControllerID& controller_id, |
114 int buffer_id, base::Time timestamp) { | 115 int buffer_id, base::Time timestamp, |
| 116 const media::VideoCaptureFormat& format) { |
115 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
116 | 118 |
117 if (entries_.find(controller_id) == entries_.end()) | 119 if (entries_.find(controller_id) == entries_.end()) |
118 return; | 120 return; |
119 | 121 |
120 Send(new VideoCaptureMsg_BufferReady(controller_id.device_id, buffer_id, | 122 Send(new VideoCaptureMsg_BufferReady(controller_id.device_id, buffer_id, |
121 timestamp)); | 123 timestamp, format)); |
122 } | 124 } |
123 | 125 |
124 void VideoCaptureHost::DoHandleErrorOnIOThread( | 126 void VideoCaptureHost::DoHandleErrorOnIOThread( |
125 const VideoCaptureControllerID& controller_id) { | 127 const VideoCaptureControllerID& controller_id) { |
126 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 128 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
127 | 129 |
128 if (entries_.find(controller_id) == entries_.end()) | 130 if (entries_.find(controller_id) == entries_.end()) |
129 return; | 131 return; |
130 | 132 |
131 Send(new VideoCaptureMsg_StateChanged(controller_id.device_id, | 133 Send(new VideoCaptureMsg_StateChanged(controller_id.device_id, |
132 VIDEO_CAPTURE_STATE_ERROR)); | 134 VIDEO_CAPTURE_STATE_ERROR)); |
133 DeleteVideoCaptureControllerOnIOThread(controller_id); | 135 DeleteVideoCaptureControllerOnIOThread(controller_id); |
134 } | 136 } |
135 | 137 |
136 void VideoCaptureHost::DoEndedOnIOThread( | 138 void VideoCaptureHost::DoEndedOnIOThread( |
137 const VideoCaptureControllerID& controller_id) { | 139 const VideoCaptureControllerID& controller_id) { |
138 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 140 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
139 DVLOG(1) << "VideoCaptureHost::DoEndedOnIOThread"; | 141 DVLOG(1) << "VideoCaptureHost::DoEndedOnIOThread"; |
140 if (entries_.find(controller_id) == entries_.end()) | 142 if (entries_.find(controller_id) == entries_.end()) |
141 return; | 143 return; |
142 | 144 |
143 Send(new VideoCaptureMsg_StateChanged(controller_id.device_id, | 145 Send(new VideoCaptureMsg_StateChanged(controller_id.device_id, |
144 VIDEO_CAPTURE_STATE_ENDED)); | 146 VIDEO_CAPTURE_STATE_ENDED)); |
145 DeleteVideoCaptureControllerOnIOThread(controller_id); | 147 DeleteVideoCaptureControllerOnIOThread(controller_id); |
146 } | 148 } |
147 | 149 |
148 void VideoCaptureHost::DoSendFrameInfoOnIOThread( | |
149 const VideoCaptureControllerID& controller_id, | |
150 const media::VideoCaptureCapability& format) { | |
151 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
152 | |
153 if (entries_.find(controller_id) == entries_.end()) | |
154 return; | |
155 | |
156 media::VideoCaptureParams params; | |
157 params.width = format.width; | |
158 params.height = format.height; | |
159 params.frame_rate = format.frame_rate; | |
160 params.frame_size_type = format.frame_size_type; | |
161 Send(new VideoCaptureMsg_DeviceInfo(controller_id.device_id, params)); | |
162 Send(new VideoCaptureMsg_StateChanged(controller_id.device_id, | |
163 VIDEO_CAPTURE_STATE_STARTED)); | |
164 } | |
165 | |
166 void VideoCaptureHost::DoSendFrameInfoChangedOnIOThread( | |
167 const VideoCaptureControllerID& controller_id, | |
168 int width, | |
169 int height, | |
170 int frame_rate) { | |
171 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
172 | |
173 if (entries_.find(controller_id) == entries_.end()) | |
174 return; | |
175 | |
176 media::VideoCaptureParams params; | |
177 params.width = width; | |
178 params.height = height; | |
179 params.frame_rate = frame_rate; | |
180 Send(new VideoCaptureMsg_DeviceInfoChanged(controller_id.device_id, params)); | |
181 } | |
182 | |
183 /////////////////////////////////////////////////////////////////////////////// | 150 /////////////////////////////////////////////////////////////////////////////// |
184 // IPC Messages handler. | 151 // IPC Messages handler. |
185 bool VideoCaptureHost::OnMessageReceived(const IPC::Message& message, | 152 bool VideoCaptureHost::OnMessageReceived(const IPC::Message& message, |
186 bool* message_was_ok) { | 153 bool* message_was_ok) { |
187 bool handled = true; | 154 bool handled = true; |
188 IPC_BEGIN_MESSAGE_MAP_EX(VideoCaptureHost, message, *message_was_ok) | 155 IPC_BEGIN_MESSAGE_MAP_EX(VideoCaptureHost, message, *message_was_ok) |
189 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Start, OnStartCapture) | 156 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Start, OnStartCapture) |
190 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Pause, OnPauseCapture) | 157 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Pause, OnPauseCapture) |
191 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Stop, OnStopCapture) | 158 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Stop, OnStopCapture) |
192 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_BufferReady, OnReceiveEmptyBuffer) | 159 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_BufferReady, OnReceiveEmptyBuffer) |
(...skipping 25 matching lines...) Expand all Loading... |
218 void VideoCaptureHost::OnControllerAdded( | 185 void VideoCaptureHost::OnControllerAdded( |
219 int device_id, const media::VideoCaptureParams& params, | 186 int device_id, const media::VideoCaptureParams& params, |
220 const base::WeakPtr<VideoCaptureController>& controller) { | 187 const base::WeakPtr<VideoCaptureController>& controller) { |
221 BrowserThread::PostTask( | 188 BrowserThread::PostTask( |
222 BrowserThread::IO, FROM_HERE, | 189 BrowserThread::IO, FROM_HERE, |
223 base::Bind(&VideoCaptureHost::DoControllerAddedOnIOThread, | 190 base::Bind(&VideoCaptureHost::DoControllerAddedOnIOThread, |
224 this, device_id, params, controller)); | 191 this, device_id, params, controller)); |
225 } | 192 } |
226 | 193 |
227 void VideoCaptureHost::DoControllerAddedOnIOThread( | 194 void VideoCaptureHost::DoControllerAddedOnIOThread( |
228 int device_id, const media::VideoCaptureParams params, | 195 int device_id, const media::VideoCaptureParams& params, |
229 const base::WeakPtr<VideoCaptureController>& controller) { | 196 const base::WeakPtr<VideoCaptureController>& controller) { |
230 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
231 VideoCaptureControllerID controller_id(device_id); | 198 VideoCaptureControllerID controller_id(device_id); |
232 EntryMap::iterator it = entries_.find(controller_id); | 199 EntryMap::iterator it = entries_.find(controller_id); |
233 if (it == entries_.end()) { | 200 if (it == entries_.end()) { |
234 if (controller) { | 201 if (controller) { |
235 media_stream_manager_->video_capture_manager()->StopCaptureForClient( | 202 media_stream_manager_->video_capture_manager()->StopCaptureForClient( |
236 controller.get(), controller_id, this); | 203 controller.get(), controller_id, this); |
237 } | 204 } |
238 return; | 205 return; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 return; | 255 return; |
289 | 256 |
290 if (it->second) { | 257 if (it->second) { |
291 media_stream_manager_->video_capture_manager()->StopCaptureForClient( | 258 media_stream_manager_->video_capture_manager()->StopCaptureForClient( |
292 it->second.get(), controller_id, this); | 259 it->second.get(), controller_id, this); |
293 } | 260 } |
294 entries_.erase(it); | 261 entries_.erase(it); |
295 } | 262 } |
296 | 263 |
297 } // namespace content | 264 } // namespace content |
OLD | NEW |