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 // Notes about usage of this object by VideoCaptureImplManager. | 5 // Notes about usage of this object by VideoCaptureImplManager. |
6 // | 6 // |
7 // VideoCaptureImplManager access this object by using a Unretained() | 7 // VideoCaptureImplManager access this object by using a Unretained() |
8 // binding and tasks on the IO thread. It is then important that | 8 // binding and tasks on the IO thread. It is then important that |
9 // VideoCaptureImpl never post task to itself. All operations must be | 9 // VideoCaptureImpl never post task to itself. All operations must be |
10 // synchronous. | 10 // synchronous. |
11 | 11 |
12 #include "content/renderer/media/video_capture_impl.h" | 12 #include "content/renderer/media/video_capture_impl.h" |
13 | 13 |
14 #include "base/bind.h" | 14 #include "base/bind.h" |
15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
16 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
17 #include "content/child/child_process.h" | 17 #include "content/child/child_process.h" |
18 #include "content/common/gpu/client/gpu_memory_buffer_impl.h" | |
18 #include "content/common/media/video_capture_messages.h" | 19 #include "content/common/media/video_capture_messages.h" |
19 #include "media/base/bind_to_current_loop.h" | 20 #include "media/base/bind_to_current_loop.h" |
20 #include "media/base/limits.h" | 21 #include "media/base/limits.h" |
21 #include "media/base/video_frame.h" | 22 #include "media/base/video_frame.h" |
22 | 23 |
23 namespace content { | 24 namespace content { |
24 | 25 |
25 namespace { | 26 namespace { |
26 | 27 |
27 const int kUndefinedDeviceId = 0; | 28 const int kUndefinedDeviceId = 0; |
28 | 29 |
29 // This is called on an unknown thread when the VideoFrame destructor executes. | 30 // This is called on an unknown thread when the VideoFrame destructor executes. |
30 // As of this writing, this callback mechanism is the only interface in | 31 // As of this writing, this callback mechanism is the only interface in |
31 // VideoFrame to provide the final value for |release_sync_point|. | 32 // VideoFrame to provide the final value for |release_sync_point|. |
32 // VideoCaptureImpl::DidFinishConsumingFrame() will read the value saved here, | 33 // VideoCaptureImpl::DidFinishConsumingFrame() will read the value saved here, |
33 // and pass it back to the IO thread to pass back to the host via the | 34 // and pass it back to the IO thread to pass back to the host via the |
34 // BufferReady IPC. | 35 // BufferReady IPC. |
35 void SaveReleaseSyncPoint(uint32* storage, uint32 release_sync_point) { | 36 void SaveReleaseSyncPoint(uint32* storage, uint32 release_sync_point) { |
36 *storage = release_sync_point; | 37 *storage = release_sync_point; |
37 } | 38 } |
38 | 39 |
39 } // namespace | 40 } // namespace |
40 | 41 |
42 // A holder of a memory-backed buffer and accessors to it. | |
41 class VideoCaptureImpl::ClientBuffer | 43 class VideoCaptureImpl::ClientBuffer |
42 : public base::RefCountedThreadSafe<ClientBuffer> { | 44 : public base::RefCountedThreadSafe<ClientBuffer> { |
43 public: | 45 public: |
44 ClientBuffer(scoped_ptr<base::SharedMemory> buffer, | 46 ClientBuffer(scoped_ptr<base::SharedMemory> buffer, |
mcasas
2015/08/21 03:57:25
nit: Fits in one line.
ClientBuffer(scoped_ptr<
emircan
2015/08/22 03:13:26
Done.
| |
45 size_t buffer_size) | 47 size_t buffer_size) |
46 : buffer(buffer.Pass()), | 48 : buffer(buffer.Pass()), |
47 buffer_size(buffer_size) {} | 49 buffer_size(buffer_size) {} |
48 const scoped_ptr<base::SharedMemory> buffer; | 50 const scoped_ptr<base::SharedMemory> buffer; |
mcasas
2015/08/21 03:57:25
Shouldn't |buffer| and |buffer_size| be private an
emircan
2015/08/22 03:13:26
Done.
| |
49 const size_t buffer_size; | 51 const size_t buffer_size; |
50 | 52 |
51 private: | 53 private: |
52 friend class base::RefCountedThreadSafe<ClientBuffer>; | 54 friend class base::RefCountedThreadSafe<ClientBuffer>; |
53 | 55 |
54 virtual ~ClientBuffer() {} | 56 virtual ~ClientBuffer() {} |
55 | 57 |
56 DISALLOW_COPY_AND_ASSIGN(ClientBuffer); | 58 DISALLOW_COPY_AND_ASSIGN(ClientBuffer); |
57 }; | 59 }; |
58 | 60 |
61 // A holder of a GpuMemoryBuffer-backed buffer, Map()ed on ctor and Unmap()ed on | |
62 // dtor. Creates and owns GpuMemoryBuffer instances. | |
63 class VideoCaptureImpl::ClientGpuMemoryBuffer | |
64 : public base::RefCountedThreadSafe<ClientGpuMemoryBuffer> { | |
65 public: | |
66 ClientGpuMemoryBuffer( | |
67 const std::vector<gfx::GpuMemoryBufferHandle>& client_gmb_handles, | |
68 const gfx::Size& size) | |
69 : gmb_handles_(client_gmb_handles), | |
70 size_(size), | |
71 format_(media::PIXEL_FORMAT_I420) { | |
72 Init(); | |
73 } | |
74 uint8* data(int plane) { return data_[plane]; } | |
mcasas
2015/08/21 03:57:25
const method?
Here an l.75, 76.
emircan
2015/08/22 03:13:26
Done.
| |
75 int32 stride(int plane) { return strides_[plane]; } | |
76 std::vector<gfx::GpuMemoryBufferHandle> gpu_memory_buffer_handles() { | |
77 return gmb_handles_; | |
78 } | |
79 | |
80 private: | |
81 friend class base::RefCountedThreadSafe<ClientGpuMemoryBuffer>; | |
82 | |
83 virtual ~ClientGpuMemoryBuffer() { | |
84 for (auto& gmb : gmbs_) | |
85 gmb->Unmap(); | |
86 } | |
mcasas
2015/08/21 03:57:25
Insert blank line.
emircan
2015/08/22 03:13:26
Done.
| |
87 void Init() { | |
88 for (size_t i = 0; i < gmb_handles_.size(); ++i) { | |
89 const size_t width = | |
90 media::VideoFrame::Columns(i, format_, size_.width()); | |
91 const size_t height = media::VideoFrame::Rows(i, format_, size_.height()); | |
92 gmbs_.push_back(GpuMemoryBufferImpl::CreateFromHandle( | |
93 gmb_handles_[i], | |
94 gfx::Size(width, height), | |
95 gfx::BufferFormat::R_8, | |
96 gfx::BufferUsage::MAP, | |
97 base::Bind(&ClientGpuMemoryBuffer::DestroyGpuMemoryBuffer, | |
98 base::Unretained(this)))); | |
99 void* data_ptr = NULL; | |
mcasas
2015/08/21 03:57:25
s/NULL/nullptr/
emircan
2015/08/22 03:13:26
Done.
| |
100 gmbs_[i]->Map(&data_ptr); | |
101 data_[i] = reinterpret_cast<uint8*>(data_ptr); | |
102 strides_[i] = width; | |
103 } | |
104 } | |
105 void DestroyGpuMemoryBuffer(uint32 sync_point) {} | |
106 | |
107 const std::vector<gfx::GpuMemoryBufferHandle> gmb_handles_; | |
108 const gfx::Size size_; | |
109 const media::VideoPixelFormat format_; | |
110 // Owned instances of GMBs. | |
111 ScopedVector<gfx::GpuMemoryBuffer> gmbs_; | |
112 uint8* data_[media::VideoFrame::kMaxPlanes]; | |
113 int32 strides_[media::VideoFrame::kMaxPlanes]; | |
114 | |
115 DISALLOW_COPY_AND_ASSIGN(ClientGpuMemoryBuffer); | |
116 }; | |
117 | |
59 VideoCaptureImpl::VideoCaptureImpl( | 118 VideoCaptureImpl::VideoCaptureImpl( |
60 const media::VideoCaptureSessionId session_id, | 119 const media::VideoCaptureSessionId session_id, |
61 VideoCaptureMessageFilter* filter) | 120 VideoCaptureMessageFilter* filter) |
62 : message_filter_(filter), | 121 : message_filter_(filter), |
63 device_id_(kUndefinedDeviceId), | 122 device_id_(kUndefinedDeviceId), |
64 session_id_(session_id), | 123 session_id_(session_id), |
65 state_(VIDEO_CAPTURE_STATE_STOPPED), | 124 state_(VIDEO_CAPTURE_STATE_STOPPED), |
66 weak_factory_(this) { | 125 weak_factory_(this) { |
67 DCHECK(filter); | 126 DCHECK(filter); |
68 } | 127 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 | 198 |
140 void VideoCaptureImpl::StopCapture() { | 199 void VideoCaptureImpl::StopCapture() { |
141 DCHECK(io_task_runner_->BelongsToCurrentThread()); | 200 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
142 if (state_ == VIDEO_CAPTURE_STATE_STOPPED || !IsInitialized()) | 201 if (state_ == VIDEO_CAPTURE_STATE_STOPPED || !IsInitialized()) |
143 return; | 202 return; |
144 | 203 |
145 DVLOG(1) << "StopCapture: Stopping capture."; | 204 DVLOG(1) << "StopCapture: Stopping capture."; |
146 state_update_cb_.Run(VIDEO_CAPTURE_STATE_STOPPED); | 205 state_update_cb_.Run(VIDEO_CAPTURE_STATE_STOPPED); |
147 StopDevice(); | 206 StopDevice(); |
148 client_buffers_.clear(); | 207 client_buffers_.clear(); |
208 client_gmb_buffers_.clear(); | |
149 ResetClient(); | 209 ResetClient(); |
150 weak_factory_.InvalidateWeakPtrs(); | 210 weak_factory_.InvalidateWeakPtrs(); |
151 } | 211 } |
152 | 212 |
153 void VideoCaptureImpl::GetDeviceSupportedFormats( | 213 void VideoCaptureImpl::GetDeviceSupportedFormats( |
154 const VideoCaptureDeviceFormatsCB& callback) { | 214 const VideoCaptureDeviceFormatsCB& callback) { |
155 DCHECK(io_task_runner_->BelongsToCurrentThread()); | 215 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
156 device_formats_cb_queue_.push_back(callback); | 216 device_formats_cb_queue_.push_back(callback); |
157 if (device_formats_cb_queue_.size() == 1) | 217 if (device_formats_cb_queue_.size() == 1) |
158 Send(new VideoCaptureHostMsg_GetDeviceSupportedFormats(device_id_, | 218 Send(new VideoCaptureHostMsg_GetDeviceSupportedFormats(device_id_, |
159 session_id_)); | 219 session_id_)); |
160 } | 220 } |
161 | 221 |
162 void VideoCaptureImpl::GetDeviceFormatsInUse( | 222 void VideoCaptureImpl::GetDeviceFormatsInUse( |
163 const VideoCaptureDeviceFormatsCB& callback) { | 223 const VideoCaptureDeviceFormatsCB& callback) { |
164 DCHECK(io_task_runner_->BelongsToCurrentThread()); | 224 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
165 device_formats_in_use_cb_queue_.push_back(callback); | 225 device_formats_in_use_cb_queue_.push_back(callback); |
166 if (device_formats_in_use_cb_queue_.size() == 1) | 226 if (device_formats_in_use_cb_queue_.size() == 1) |
167 Send( | 227 Send( |
168 new VideoCaptureHostMsg_GetDeviceFormatsInUse(device_id_, session_id_)); | 228 new VideoCaptureHostMsg_GetDeviceFormatsInUse(device_id_, session_id_)); |
169 } | 229 } |
170 | 230 |
171 void VideoCaptureImpl::OnBufferCreated(base::SharedMemoryHandle handle, | 231 void VideoCaptureImpl::OnBufferCreated( |
172 int length, | 232 base::SharedMemoryHandle handle, |
mcasas
2015/08/21 03:57:25
Revert to old indent.
emircan
2015/08/22 03:13:26
Done.
| |
173 int buffer_id) { | 233 int length, |
234 int buffer_id) { | |
174 DCHECK(io_task_runner_->BelongsToCurrentThread()); | 235 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
175 | 236 |
176 // In case client calls StopCapture before the arrival of created buffer, | 237 // In case client calls StopCapture before the arrival of created buffer, |
177 // just close this buffer and return. | 238 // just close this buffer and return. |
178 if (state_ != VIDEO_CAPTURE_STATE_STARTED) { | 239 if (state_ != VIDEO_CAPTURE_STATE_STARTED) { |
179 base::SharedMemory::CloseHandle(handle); | 240 base::SharedMemory::CloseHandle(handle); |
180 return; | 241 return; |
181 } | 242 } |
182 | 243 |
183 scoped_ptr<base::SharedMemory> shm(new base::SharedMemory(handle, false)); | 244 scoped_ptr<base::SharedMemory> shm(new base::SharedMemory(handle, false)); |
184 if (!shm->Map(length)) { | 245 if (!shm->Map(length)) { |
185 DLOG(ERROR) << "OnBufferCreated: Map failed."; | 246 DLOG(ERROR) << "OnBufferCreated: Map failed."; |
186 return; | 247 return; |
187 } | 248 } |
188 | |
189 const bool inserted = | 249 const bool inserted = |
190 client_buffers_.insert(std::make_pair(buffer_id, new ClientBuffer( | 250 client_buffers_.insert(std::make_pair(buffer_id, new ClientBuffer( |
191 shm.Pass(), length))) | 251 shm.Pass(), length))) |
192 .second; | 252 .second; |
193 DCHECK(inserted); | 253 DCHECK(inserted); |
194 } | 254 } |
195 | 255 |
256 void VideoCaptureImpl::OnGpuMemoryBufferCreated( | |
257 const std::vector<gfx::GpuMemoryBufferHandle>& gmb_handles, | |
258 const gfx::Size& size, | |
259 int buffer_id) { | |
260 DCHECK(io_task_runner_->BelongsToCurrentThread()); | |
261 | |
262 // In case client calls StopCapture before the arrival of created buffer, | |
263 // just close this buffer and return. | |
264 if (state_ != VIDEO_CAPTURE_STATE_STARTED) | |
265 return; | |
266 | |
267 const bool inserted = | |
268 client_gmb_buffers_.insert(std::make_pair(buffer_id, | |
269 new ClientGpuMemoryBuffer( | |
270 gmb_handles, size))) | |
271 .second; | |
272 DCHECK(inserted); | |
273 } | |
274 | |
196 void VideoCaptureImpl::OnBufferDestroyed(int buffer_id) { | 275 void VideoCaptureImpl::OnBufferDestroyed(int buffer_id) { |
197 DCHECK(io_task_runner_->BelongsToCurrentThread()); | 276 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
198 | 277 |
199 const ClientBufferMap::iterator iter = client_buffers_.find(buffer_id); | 278 const auto& cb_iter = client_buffers_.find(buffer_id); |
200 if (iter == client_buffers_.end()) | 279 const auto& cgmb_iter = client_gmb_buffers_.find(buffer_id); |
201 return; | 280 if (cb_iter != client_buffers_.end()) { |
202 | 281 DCHECK(!cb_iter->second.get() || cb_iter->second->HasOneRef()) |
203 DCHECK(!iter->second.get() || iter->second->HasOneRef()) | 282 << "Instructed to delete buffer we are still using."; |
204 << "Instructed to delete buffer we are still using."; | 283 client_buffers_.erase(cb_iter); |
205 client_buffers_.erase(iter); | 284 } else if (cgmb_iter != client_gmb_buffers_.end()) { |
285 DCHECK(!cgmb_iter->second.get() || cgmb_iter->second->HasOneRef()) | |
286 << "Instructed to delete buffer we are still using."; | |
287 client_gmb_buffers_.erase(cgmb_iter); | |
288 } | |
206 } | 289 } |
207 | 290 |
208 void VideoCaptureImpl::OnBufferReceived( | 291 void VideoCaptureImpl::OnBufferReceived( |
209 int buffer_id, | 292 int buffer_id, |
210 base::TimeTicks timestamp, | 293 base::TimeTicks timestamp, |
211 const base::DictionaryValue& metadata, | 294 const base::DictionaryValue& metadata, |
212 media::VideoPixelFormat pixel_format, | 295 media::VideoPixelFormat pixel_format, |
213 media::VideoFrame::StorageType storage_type, | 296 media::VideoFrame::StorageType storage_type, |
214 const gfx::Size& coded_size, | 297 const gfx::Size& coded_size, |
215 const gfx::Rect& visible_rect, | 298 const gfx::Rect& visible_rect, |
216 const gpu::MailboxHolder& mailbox_holder) { | 299 const std::vector<gpu::MailboxHolder>& mailbox_holders) { |
217 DCHECK(io_task_runner_->BelongsToCurrentThread()); | 300 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
301 DCHECK_EQ(media::PIXEL_FORMAT_I420, pixel_format); | |
218 if (state_ != VIDEO_CAPTURE_STATE_STARTED) { | 302 if (state_ != VIDEO_CAPTURE_STATE_STARTED) { |
219 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id, 0, -1.0)); | 303 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id, 0, -1.0)); |
220 return; | 304 return; |
221 } | 305 } |
222 if (first_frame_timestamp_.is_null()) | 306 if (first_frame_timestamp_.is_null()) |
223 first_frame_timestamp_ = timestamp; | 307 first_frame_timestamp_ = timestamp; |
224 | 308 |
225 // Used by chrome/browser/extension/api/cast_streaming/performance_test.cc | 309 // Used by chrome/browser/extension/api/cast_streaming/performance_test.cc |
226 TRACE_EVENT_INSTANT2("cast_perf_test", "OnBufferReceived", | 310 TRACE_EVENT_INSTANT2("cast_perf_test", "OnBufferReceived", |
227 TRACE_EVENT_SCOPE_THREAD, "timestamp", | 311 TRACE_EVENT_SCOPE_THREAD, "timestamp", |
228 timestamp.ToInternalValue(), "time_delta", | 312 timestamp.ToInternalValue(), "time_delta", |
229 (timestamp - first_frame_timestamp_).ToInternalValue()); | 313 (timestamp - first_frame_timestamp_).ToInternalValue()); |
230 | 314 |
231 scoped_refptr<media::VideoFrame> frame; | 315 scoped_refptr<media::VideoFrame> frame; |
232 uint32* release_sync_point_storage = nullptr; | 316 uint32* release_sync_point_storage = nullptr; |
233 scoped_refptr<ClientBuffer> buffer; | 317 if (mailbox_holders.empty()) { |
318 const auto& iter = client_buffers_.find(buffer_id); | |
319 DCHECK(iter != client_buffers_.end()); | |
320 const scoped_refptr<ClientBuffer> buffer = iter->second; | |
321 frame = media::VideoFrame::WrapExternalSharedMemory( | |
322 pixel_format, coded_size, visible_rect, | |
323 gfx::Size(visible_rect.width(), visible_rect.height()), | |
324 reinterpret_cast<uint8*>(buffer->buffer->memory()), buffer->buffer_size, | |
325 buffer->buffer->handle(), 0 /* shared_memory_offset */, | |
326 timestamp - first_frame_timestamp_); | |
327 frame->AddDestructionObserver( | |
328 base::Bind(&VideoCaptureImpl::DidFinishConsumingFrame, | |
329 frame->metadata(), release_sync_point_storage, | |
330 media::BindToCurrentLoop(base::Bind( | |
331 &VideoCaptureImpl::OnClientBufferFinished, | |
332 weak_factory_.GetWeakPtr(), buffer_id, buffer)))); | |
333 } else if (storage_type == media::VideoFrame::STORAGE_OPAQUE) { | |
334 for (const auto& mailbox_holder : mailbox_holders) | |
335 DCHECK(mailbox_holder.mailbox.Verify()); // Paranoia? | |
234 | 336 |
235 if (mailbox_holder.mailbox.IsZero()) { | 337 const auto& gmb_iter = client_gmb_buffers_.find(buffer_id); |
236 DCHECK_EQ(media::PIXEL_FORMAT_I420, pixel_format); | 338 DCHECK(gmb_iter != client_gmb_buffers_.end()); |
237 const ClientBufferMap::const_iterator iter = | 339 const scoped_refptr<ClientGpuMemoryBuffer> gpu_memory_buffer = |
238 client_buffers_.find(buffer_id); | 340 gmb_iter->second; |
239 DCHECK(iter != client_buffers_.end()); | 341 release_sync_point_storage = new uint32(0); |
240 buffer = iter->second; | 342 frame = media::VideoFrame::WrapYUV420NativeTextures( |
241 frame = media::VideoFrame::WrapExternalSharedMemory( | 343 mailbox_holders[media::VideoFrame::kYPlane], |
242 pixel_format, | 344 mailbox_holders[media::VideoFrame::kUPlane], |
243 coded_size, | 345 mailbox_holders[media::VideoFrame::kVPlane], |
244 visible_rect, | 346 base::Bind(&SaveReleaseSyncPoint, release_sync_point_storage), |
245 gfx::Size(visible_rect.width(), visible_rect.height()), | 347 coded_size, gfx::Rect(coded_size), coded_size, |
246 reinterpret_cast<uint8*>(buffer->buffer->memory()), | |
247 buffer->buffer_size, | |
248 buffer->buffer->handle(), | |
249 0 /* shared_memory_offset */, | |
250 timestamp - first_frame_timestamp_); | 348 timestamp - first_frame_timestamp_); |
251 | 349 frame->AddDestructionObserver(base::Bind( |
252 } else { | 350 &VideoCaptureImpl::DidFinishConsumingFrame, frame->metadata(), |
253 DCHECK_EQ(media::PIXEL_FORMAT_ARGB, pixel_format); | 351 release_sync_point_storage, |
254 DCHECK(mailbox_holder.mailbox.Verify()); // Paranoia? | 352 media::BindToCurrentLoop(base::Bind( |
255 // To be deleted in DidFinishConsumingFrame(). | 353 &VideoCaptureImpl::OnClientGpuMemoryBufferFinished, |
256 release_sync_point_storage = new uint32(0); | 354 weak_factory_.GetWeakPtr(), buffer_id, gpu_memory_buffer)))); |
257 frame = media::VideoFrame::WrapNativeTexture( | |
258 pixel_format, | |
259 mailbox_holder, | |
260 base::Bind(&SaveReleaseSyncPoint, release_sync_point_storage), | |
261 coded_size, | |
262 gfx::Rect(coded_size), | |
263 coded_size, | |
264 timestamp - first_frame_timestamp_); | |
265 } | 355 } |
266 frame->AddDestructionObserver( | |
267 base::Bind(&VideoCaptureImpl::DidFinishConsumingFrame, frame->metadata(), | |
268 release_sync_point_storage, | |
269 media::BindToCurrentLoop(base::Bind( | |
270 &VideoCaptureImpl::OnClientBufferFinished, | |
271 weak_factory_.GetWeakPtr(), buffer_id, buffer)))); | |
272 | |
273 frame->metadata()->MergeInternalValuesFrom(metadata); | 356 frame->metadata()->MergeInternalValuesFrom(metadata); |
274 deliver_frame_cb_.Run(frame, timestamp); | 357 deliver_frame_cb_.Run(frame, timestamp); |
275 } | 358 } |
276 | 359 |
277 void VideoCaptureImpl::OnClientBufferFinished( | 360 void VideoCaptureImpl::OnClientBufferFinished( |
278 int buffer_id, | 361 int buffer_id, |
279 const scoped_refptr<ClientBuffer>& /* ignored_buffer */, | 362 const scoped_refptr<ClientBuffer>& /* ignored_buffer */, |
280 uint32 release_sync_point, | 363 uint32 release_sync_point, |
281 double consumer_resource_utilization) { | 364 double consumer_resource_utilization) { |
282 DCHECK(io_task_runner_->BelongsToCurrentThread()); | 365 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
283 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id, | 366 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id, |
284 release_sync_point, | 367 release_sync_point, |
285 consumer_resource_utilization)); | 368 consumer_resource_utilization)); |
286 } | 369 } |
370 void VideoCaptureImpl::OnClientGpuMemoryBufferFinished( | |
371 int buffer_id, | |
372 const scoped_refptr<ClientGpuMemoryBuffer>& gpu_memory_buffer, | |
373 uint32 release_sync_point, | |
374 double consumer_resource_utilization) { | |
375 OnClientBufferFinished(buffer_id, scoped_refptr<ClientBuffer>(), | |
376 release_sync_point, consumer_resource_utilization); | |
377 } | |
287 | 378 |
288 void VideoCaptureImpl::OnStateChanged(VideoCaptureState state) { | 379 void VideoCaptureImpl::OnStateChanged(VideoCaptureState state) { |
289 // TODO(ajose): http://crbug.com/522155 improve this state machine. | 380 // TODO(ajose): http://crbug.com/522155 improve this state machine. |
290 DCHECK(io_task_runner_->BelongsToCurrentThread()); | 381 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
291 state_ = state; | 382 state_ = state; |
292 | 383 |
293 if (state == VIDEO_CAPTURE_STATE_STOPPED) { | 384 if (state == VIDEO_CAPTURE_STATE_STOPPED) { |
294 DVLOG(1) << "OnStateChanged: stopped!, device_id = " << device_id_; | 385 DVLOG(1) << "OnStateChanged: stopped!, device_id = " << device_id_; |
295 client_buffers_.clear(); | 386 client_buffers_.clear(); |
387 client_gmb_buffers_.clear(); | |
296 weak_factory_.InvalidateWeakPtrs(); | 388 weak_factory_.InvalidateWeakPtrs(); |
297 return; | 389 return; |
298 } | 390 } |
299 if (state == VIDEO_CAPTURE_STATE_ERROR) { | 391 if (state == VIDEO_CAPTURE_STATE_ERROR) { |
300 DVLOG(1) << "OnStateChanged: error!, device_id = " << device_id_; | 392 DVLOG(1) << "OnStateChanged: error!, device_id = " << device_id_; |
301 if (!state_update_cb_.is_null()) | 393 if (!state_update_cb_.is_null()) |
302 state_update_cb_.Run(VIDEO_CAPTURE_STATE_ERROR); | 394 state_update_cb_.Run(VIDEO_CAPTURE_STATE_ERROR); |
303 ResetClient(); | 395 ResetClient(); |
304 return; | 396 return; |
305 } | 397 } |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
399 void VideoCaptureImpl::ResetClient() { | 491 void VideoCaptureImpl::ResetClient() { |
400 client_params_ = media::VideoCaptureParams(); | 492 client_params_ = media::VideoCaptureParams(); |
401 state_update_cb_.Reset(); | 493 state_update_cb_.Reset(); |
402 deliver_frame_cb_.Reset(); | 494 deliver_frame_cb_.Reset(); |
403 first_frame_timestamp_ = base::TimeTicks(); | 495 first_frame_timestamp_ = base::TimeTicks(); |
404 device_id_ = kUndefinedDeviceId; | 496 device_id_ = kUndefinedDeviceId; |
405 state_ = VIDEO_CAPTURE_STATE_STOPPED; | 497 state_ = VIDEO_CAPTURE_STATE_STOPPED; |
406 } | 498 } |
407 | 499 |
408 } // namespace content | 500 } // namespace content |
OLD | NEW |