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, size_t buffer_size) |
45 size_t buffer_size) | 47 : buffer_(buffer.Pass()), buffer_size_(buffer_size) {} |
46 : buffer(buffer.Pass()), | 48 |
47 buffer_size(buffer_size) {} | 49 base::SharedMemory* buffer() const { return buffer_.get(); } |
48 const scoped_ptr<base::SharedMemory> buffer; | 50 size_t buffer_size() const { return buffer_size_; } |
49 const size_t buffer_size; | |
50 | 51 |
51 private: | 52 private: |
52 friend class base::RefCountedThreadSafe<ClientBuffer>; | 53 friend class base::RefCountedThreadSafe<ClientBuffer>; |
53 | 54 |
54 virtual ~ClientBuffer() {} | 55 virtual ~ClientBuffer() {} |
55 | 56 |
57 const scoped_ptr<base::SharedMemory> buffer_; | |
58 const size_t buffer_size_; | |
59 | |
56 DISALLOW_COPY_AND_ASSIGN(ClientBuffer); | 60 DISALLOW_COPY_AND_ASSIGN(ClientBuffer); |
57 }; | 61 }; |
58 | 62 |
63 // A holder of a GpuMemoryBuffer-backed buffer, Map()ed on ctor and Unmap()ed on | |
64 // dtor. Creates and owns GpuMemoryBuffer instances. | |
65 class VideoCaptureImpl::ClientVideoCaptureBuffer | |
reveman
2015/08/26 11:54:05
ClientBuffer2?
emircan
2015/08/26 21:23:12
Done.
| |
66 : public base::RefCountedThreadSafe<ClientVideoCaptureBuffer> { | |
67 public: | |
68 ClientVideoCaptureBuffer( | |
69 const std::vector<gfx::GpuMemoryBufferHandle>& client_gmb_handles, | |
reveman
2015/08/26 11:54:05
nit: s/gmb_handles/handles/
btw, why does this ta
emircan
2015/08/26 21:23:12
::ClientBuffer relies on ShMem being mapped earlie
| |
70 const gfx::Size& size) | |
71 : gmb_handles_(client_gmb_handles), | |
72 size_(size), | |
73 format_(media::PIXEL_FORMAT_I420) { | |
74 Init(); | |
75 } | |
76 | |
77 uint8* data(int plane) const { return data_[plane]; } | |
78 int32 stride(int plane) const { return strides_[plane]; } | |
79 std::vector<gfx::GpuMemoryBufferHandle> gpu_memory_buffer_handles() { | |
80 return gmb_handles_; | |
81 } | |
82 | |
83 private: | |
84 friend class base::RefCountedThreadSafe<ClientVideoCaptureBuffer>; | |
85 | |
86 virtual ~ClientVideoCaptureBuffer() { | |
87 for (auto& gmb : gmbs_) | |
88 gmb->Unmap(); | |
89 } | |
90 | |
91 void Init() { | |
reveman
2015/08/26 11:54:05
why the Init function instead of doing this in the
emircan
2015/08/26 21:23:12
Done. Moved Init() to ctor.
| |
92 for (size_t i = 0; i < gmb_handles_.size(); ++i) { | |
93 const size_t width = | |
94 media::VideoFrame::Columns(i, format_, size_.width()); | |
95 const size_t height = media::VideoFrame::Rows(i, format_, size_.height()); | |
96 gmbs_.push_back(GpuMemoryBufferImpl::CreateFromHandle( | |
97 gmb_handles_[i], | |
98 gfx::Size(width, height), | |
99 gfx::BufferFormat::R_8, | |
100 gfx::BufferUsage::MAP, | |
101 base::Bind(&ClientVideoCaptureBuffer::DestroyGpuMemoryBuffer, | |
102 base::Unretained(this)))); | |
103 void* data_ptr = nullptr; | |
104 gmbs_[i]->Map(&data_ptr); | |
105 data_[i] = reinterpret_cast<uint8*>(data_ptr); | |
106 strides_[i] = width; | |
107 } | |
108 } | |
109 void DestroyGpuMemoryBuffer(uint32 sync_point) {} | |
110 | |
111 const std::vector<gfx::GpuMemoryBufferHandle> gmb_handles_; | |
reveman
2015/08/26 11:54:05
nit: s/gmb_handles/handles/
emircan
2015/08/26 21:23:12
Done.
| |
112 const gfx::Size size_; | |
113 const media::VideoPixelFormat format_; | |
reveman
2015/08/26 11:54:05
this member doesn't seem useful. Init is hardcoded
emircan
2015/08/26 21:23:12
Done.
| |
114 // Owned instances of GMBs. | |
reveman
2015/08/26 11:54:05
nit: unnecessary comment. Owned is implied from Sc
emircan
2015/08/26 21:23:12
Done.
| |
115 ScopedVector<gfx::GpuMemoryBuffer> gmbs_; | |
reveman
2015/08/26 11:54:05
nit: s/gmbs_/buffers_/ or gpu_memory_buffers_
emircan
2015/08/26 21:23:12
Done.
| |
116 uint8* data_[media::VideoFrame::kMaxPlanes]; | |
117 int32 strides_[media::VideoFrame::kMaxPlanes]; | |
118 | |
119 DISALLOW_COPY_AND_ASSIGN(ClientVideoCaptureBuffer); | |
120 }; | |
121 | |
59 VideoCaptureImpl::VideoCaptureImpl( | 122 VideoCaptureImpl::VideoCaptureImpl( |
60 const media::VideoCaptureSessionId session_id, | 123 const media::VideoCaptureSessionId session_id, |
61 VideoCaptureMessageFilter* filter) | 124 VideoCaptureMessageFilter* filter) |
62 : message_filter_(filter), | 125 : message_filter_(filter), |
63 device_id_(kUndefinedDeviceId), | 126 device_id_(kUndefinedDeviceId), |
64 session_id_(session_id), | 127 session_id_(session_id), |
65 state_(VIDEO_CAPTURE_STATE_STOPPED), | 128 state_(VIDEO_CAPTURE_STATE_STOPPED), |
66 weak_factory_(this) { | 129 weak_factory_(this) { |
67 DCHECK(filter); | 130 DCHECK(filter); |
68 } | 131 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 | 202 |
140 void VideoCaptureImpl::StopCapture() { | 203 void VideoCaptureImpl::StopCapture() { |
141 DCHECK(io_task_runner_->BelongsToCurrentThread()); | 204 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
142 if (state_ == VIDEO_CAPTURE_STATE_STOPPED || !IsInitialized()) | 205 if (state_ == VIDEO_CAPTURE_STATE_STOPPED || !IsInitialized()) |
143 return; | 206 return; |
144 | 207 |
145 DVLOG(1) << "StopCapture: Stopping capture."; | 208 DVLOG(1) << "StopCapture: Stopping capture."; |
146 state_update_cb_.Run(VIDEO_CAPTURE_STATE_STOPPED); | 209 state_update_cb_.Run(VIDEO_CAPTURE_STATE_STOPPED); |
147 StopDevice(); | 210 StopDevice(); |
148 client_buffers_.clear(); | 211 client_buffers_.clear(); |
212 client_video_capture_buffers_.clear(); | |
149 ResetClient(); | 213 ResetClient(); |
150 weak_factory_.InvalidateWeakPtrs(); | 214 weak_factory_.InvalidateWeakPtrs(); |
151 } | 215 } |
152 | 216 |
153 void VideoCaptureImpl::GetDeviceSupportedFormats( | 217 void VideoCaptureImpl::GetDeviceSupportedFormats( |
154 const VideoCaptureDeviceFormatsCB& callback) { | 218 const VideoCaptureDeviceFormatsCB& callback) { |
155 DCHECK(io_task_runner_->BelongsToCurrentThread()); | 219 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
156 device_formats_cb_queue_.push_back(callback); | 220 device_formats_cb_queue_.push_back(callback); |
157 if (device_formats_cb_queue_.size() == 1) | 221 if (device_formats_cb_queue_.size() == 1) |
158 Send(new VideoCaptureHostMsg_GetDeviceSupportedFormats(device_id_, | 222 Send(new VideoCaptureHostMsg_GetDeviceSupportedFormats(device_id_, |
(...skipping 19 matching lines...) Expand all Loading... | |
178 if (state_ != VIDEO_CAPTURE_STATE_STARTED) { | 242 if (state_ != VIDEO_CAPTURE_STATE_STARTED) { |
179 base::SharedMemory::CloseHandle(handle); | 243 base::SharedMemory::CloseHandle(handle); |
180 return; | 244 return; |
181 } | 245 } |
182 | 246 |
183 scoped_ptr<base::SharedMemory> shm(new base::SharedMemory(handle, false)); | 247 scoped_ptr<base::SharedMemory> shm(new base::SharedMemory(handle, false)); |
184 if (!shm->Map(length)) { | 248 if (!shm->Map(length)) { |
185 DLOG(ERROR) << "OnBufferCreated: Map failed."; | 249 DLOG(ERROR) << "OnBufferCreated: Map failed."; |
186 return; | 250 return; |
187 } | 251 } |
188 | |
189 const bool inserted = | 252 const bool inserted = |
190 client_buffers_.insert(std::make_pair(buffer_id, new ClientBuffer( | 253 client_buffers_.insert(std::make_pair(buffer_id, new ClientBuffer( |
191 shm.Pass(), length))) | 254 shm.Pass(), length))) |
192 .second; | 255 .second; |
193 DCHECK(inserted); | 256 DCHECK(inserted); |
194 } | 257 } |
195 | 258 |
259 void VideoCaptureImpl::OnBufferCreated2( | |
260 const std::vector<gfx::GpuMemoryBufferHandle>& gmb_handles, | |
reveman
2015/08/26 11:54:05
nit: s/gmb_handles/handles/
emircan
2015/08/26 21:23:12
Done.
| |
261 const gfx::Size& size, | |
262 int buffer_id) { | |
263 DCHECK(io_task_runner_->BelongsToCurrentThread()); | |
264 | |
265 // In case client calls StopCapture before the arrival of created buffer, | |
266 // just close this buffer and return. | |
267 if (state_ != VIDEO_CAPTURE_STATE_STARTED) | |
268 return; | |
269 | |
270 const bool inserted = | |
271 client_video_capture_buffers_ | |
272 .insert(std::make_pair( | |
273 buffer_id, new ClientVideoCaptureBuffer(gmb_handles, size))) | |
274 .second; | |
275 DCHECK(inserted); | |
276 } | |
277 | |
196 void VideoCaptureImpl::OnBufferDestroyed(int buffer_id) { | 278 void VideoCaptureImpl::OnBufferDestroyed(int buffer_id) { |
197 DCHECK(io_task_runner_->BelongsToCurrentThread()); | 279 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
198 | 280 |
199 const ClientBufferMap::iterator iter = client_buffers_.find(buffer_id); | 281 const auto& cb_iter = client_buffers_.find(buffer_id); |
200 if (iter == client_buffers_.end()) | 282 const auto& cgmb_iter = client_video_capture_buffers_.find(buffer_id); |
201 return; | 283 if (cb_iter != client_buffers_.end()) { |
202 | 284 DCHECK(!cb_iter->second.get() || cb_iter->second->HasOneRef()) |
203 DCHECK(!iter->second.get() || iter->second->HasOneRef()) | 285 << "Instructed to delete buffer we are still using."; |
204 << "Instructed to delete buffer we are still using."; | 286 client_buffers_.erase(cb_iter); |
205 client_buffers_.erase(iter); | 287 } else if (cgmb_iter != client_video_capture_buffers_.end()) { |
reveman
2015/08/26 11:54:05
hm, why not a OnBufferDestroyed2 instead?
emircan
2015/08/26 21:23:12
Browser sends the buffer_id and we do not exactly
| |
288 DCHECK(!cgmb_iter->second.get() || cgmb_iter->second->HasOneRef()) | |
289 << "Instructed to delete buffer we are still using."; | |
290 client_video_capture_buffers_.erase(cgmb_iter); | |
291 } | |
206 } | 292 } |
207 | 293 |
208 void VideoCaptureImpl::OnBufferReceived( | 294 void VideoCaptureImpl::OnBufferReceived( |
209 int buffer_id, | 295 int buffer_id, |
210 base::TimeTicks timestamp, | 296 base::TimeTicks timestamp, |
211 const base::DictionaryValue& metadata, | 297 const base::DictionaryValue& metadata, |
212 media::VideoPixelFormat pixel_format, | 298 media::VideoPixelFormat pixel_format, |
213 media::VideoFrame::StorageType storage_type, | 299 media::VideoFrame::StorageType storage_type, |
214 const gfx::Size& coded_size, | 300 const gfx::Size& coded_size, |
215 const gfx::Rect& visible_rect, | 301 const gfx::Rect& visible_rect, |
216 const gpu::MailboxHolder& mailbox_holder) { | 302 const gpu::MailboxHolder& mailbox_holder) { |
217 DCHECK(io_task_runner_->BelongsToCurrentThread()); | 303 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
218 if (state_ != VIDEO_CAPTURE_STATE_STARTED) { | 304 if (state_ != VIDEO_CAPTURE_STATE_STARTED) { |
219 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id, 0, -1.0)); | 305 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id, 0, -1.0)); |
220 return; | 306 return; |
221 } | 307 } |
222 if (first_frame_timestamp_.is_null()) | 308 if (first_frame_timestamp_.is_null()) |
223 first_frame_timestamp_ = timestamp; | 309 first_frame_timestamp_ = timestamp; |
224 | 310 |
225 // Used by chrome/browser/extension/api/cast_streaming/performance_test.cc | 311 // Used by chrome/browser/extension/api/cast_streaming/performance_test.cc |
226 TRACE_EVENT_INSTANT2("cast_perf_test", "OnBufferReceived", | 312 TRACE_EVENT_INSTANT2("cast_perf_test", "OnBufferReceived", |
227 TRACE_EVENT_SCOPE_THREAD, "timestamp", | 313 TRACE_EVENT_SCOPE_THREAD, "timestamp", |
228 timestamp.ToInternalValue(), "time_delta", | 314 timestamp.ToInternalValue(), "time_delta", |
229 (timestamp - first_frame_timestamp_).ToInternalValue()); | 315 (timestamp - first_frame_timestamp_).ToInternalValue()); |
316 // TODO(emircan): Handle texture upload and video frame creation for GMB | |
317 // backed buffers. | |
230 | 318 |
231 scoped_refptr<media::VideoFrame> frame; | 319 scoped_refptr<media::VideoFrame> frame; |
232 uint32* release_sync_point_storage = nullptr; | 320 uint32* release_sync_point_storage = nullptr; |
233 scoped_refptr<ClientBuffer> buffer; | 321 scoped_refptr<ClientBuffer> buffer; |
234 | |
235 if (mailbox_holder.mailbox.IsZero()) { | 322 if (mailbox_holder.mailbox.IsZero()) { |
236 DCHECK_EQ(media::PIXEL_FORMAT_I420, pixel_format); | 323 DCHECK_EQ(media::PIXEL_FORMAT_I420, pixel_format); |
237 const ClientBufferMap::const_iterator iter = | 324 const auto& iter = client_buffers_.find(buffer_id); |
238 client_buffers_.find(buffer_id); | |
239 DCHECK(iter != client_buffers_.end()); | 325 DCHECK(iter != client_buffers_.end()); |
240 buffer = iter->second; | 326 buffer = iter->second; |
241 frame = media::VideoFrame::WrapExternalSharedMemory( | 327 frame = media::VideoFrame::WrapExternalSharedMemory( |
242 pixel_format, | 328 pixel_format, |
243 coded_size, | 329 coded_size, |
244 visible_rect, | 330 visible_rect, |
245 gfx::Size(visible_rect.width(), visible_rect.height()), | 331 gfx::Size(visible_rect.width(), visible_rect.height()), |
246 reinterpret_cast<uint8*>(buffer->buffer->memory()), | 332 reinterpret_cast<uint8*>(buffer->buffer()->memory()), |
247 buffer->buffer_size, | 333 buffer->buffer_size(), |
248 buffer->buffer->handle(), | 334 buffer->buffer()->handle(), |
249 0 /* shared_memory_offset */, | 335 0 /* shared_memory_offset */, |
250 timestamp - first_frame_timestamp_); | 336 timestamp - first_frame_timestamp_); |
251 | |
252 } else { | 337 } else { |
253 DCHECK_EQ(media::PIXEL_FORMAT_ARGB, pixel_format); | 338 DCHECK_EQ(media::PIXEL_FORMAT_ARGB, pixel_format); |
254 DCHECK(mailbox_holder.mailbox.Verify()); // Paranoia? | 339 DCHECK(mailbox_holder.mailbox.Verify()); // Paranoia? |
255 // To be deleted in DidFinishConsumingFrame(). | 340 // To be deleted in DidFinishConsumingFrame(). |
256 release_sync_point_storage = new uint32(0); | 341 release_sync_point_storage = new uint32(0); |
257 frame = media::VideoFrame::WrapNativeTexture( | 342 frame = media::VideoFrame::WrapNativeTexture( |
258 pixel_format, | 343 pixel_format, |
259 mailbox_holder, | 344 mailbox_holder, |
260 base::Bind(&SaveReleaseSyncPoint, release_sync_point_storage), | 345 base::Bind(&SaveReleaseSyncPoint, release_sync_point_storage), |
261 coded_size, | 346 coded_size, |
262 gfx::Rect(coded_size), | 347 gfx::Rect(coded_size), |
263 coded_size, | 348 coded_size, |
264 timestamp - first_frame_timestamp_); | 349 timestamp - first_frame_timestamp_); |
265 } | 350 } |
266 frame->AddDestructionObserver( | 351 frame->AddDestructionObserver( |
267 base::Bind(&VideoCaptureImpl::DidFinishConsumingFrame, frame->metadata(), | 352 base::Bind(&VideoCaptureImpl::DidFinishConsumingFrame, frame->metadata(), |
268 release_sync_point_storage, | 353 release_sync_point_storage, |
269 media::BindToCurrentLoop(base::Bind( | 354 media::BindToCurrentLoop(base::Bind( |
270 &VideoCaptureImpl::OnClientBufferFinished, | 355 &VideoCaptureImpl::OnClientBufferFinished, |
271 weak_factory_.GetWeakPtr(), buffer_id, buffer)))); | 356 weak_factory_.GetWeakPtr(), buffer_id, buffer)))); |
272 | |
273 frame->metadata()->MergeInternalValuesFrom(metadata); | 357 frame->metadata()->MergeInternalValuesFrom(metadata); |
274 deliver_frame_cb_.Run(frame, timestamp); | 358 deliver_frame_cb_.Run(frame, timestamp); |
275 } | 359 } |
276 | 360 |
277 void VideoCaptureImpl::OnClientBufferFinished( | 361 void VideoCaptureImpl::OnClientBufferFinished( |
278 int buffer_id, | 362 int buffer_id, |
279 const scoped_refptr<ClientBuffer>& /* ignored_buffer */, | 363 const scoped_refptr<ClientBuffer>& /* ignored_buffer */, |
280 uint32 release_sync_point, | 364 uint32 release_sync_point, |
281 double consumer_resource_utilization) { | 365 double consumer_resource_utilization) { |
282 DCHECK(io_task_runner_->BelongsToCurrentThread()); | 366 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
283 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id, | 367 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id, |
284 release_sync_point, | 368 release_sync_point, |
285 consumer_resource_utilization)); | 369 consumer_resource_utilization)); |
286 } | 370 } |
371 void VideoCaptureImpl::OnClientBufferFinished2( | |
372 int buffer_id, | |
373 const scoped_refptr<ClientVideoCaptureBuffer>& gpu_memory_buffer, | |
374 uint32 release_sync_point, | |
375 double consumer_resource_utilization) { | |
376 OnClientBufferFinished(buffer_id, scoped_refptr<ClientBuffer>(), | |
377 release_sync_point, consumer_resource_utilization); | |
378 } | |
287 | 379 |
288 void VideoCaptureImpl::OnStateChanged(VideoCaptureState state) { | 380 void VideoCaptureImpl::OnStateChanged(VideoCaptureState state) { |
289 // TODO(ajose): http://crbug.com/522155 improve this state machine. | 381 // TODO(ajose): http://crbug.com/522155 improve this state machine. |
290 DCHECK(io_task_runner_->BelongsToCurrentThread()); | 382 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
291 state_ = state; | 383 state_ = state; |
292 | 384 |
293 if (state == VIDEO_CAPTURE_STATE_STOPPED) { | 385 if (state == VIDEO_CAPTURE_STATE_STOPPED) { |
294 DVLOG(1) << "OnStateChanged: stopped!, device_id = " << device_id_; | 386 DVLOG(1) << "OnStateChanged: stopped!, device_id = " << device_id_; |
295 client_buffers_.clear(); | 387 client_buffers_.clear(); |
388 client_video_capture_buffers_.clear(); | |
296 weak_factory_.InvalidateWeakPtrs(); | 389 weak_factory_.InvalidateWeakPtrs(); |
297 return; | 390 return; |
298 } | 391 } |
299 if (state == VIDEO_CAPTURE_STATE_ERROR) { | 392 if (state == VIDEO_CAPTURE_STATE_ERROR) { |
300 DVLOG(1) << "OnStateChanged: error!, device_id = " << device_id_; | 393 DVLOG(1) << "OnStateChanged: error!, device_id = " << device_id_; |
301 if (!state_update_cb_.is_null()) | 394 if (!state_update_cb_.is_null()) |
302 state_update_cb_.Run(VIDEO_CAPTURE_STATE_ERROR); | 395 state_update_cb_.Run(VIDEO_CAPTURE_STATE_ERROR); |
303 ResetClient(); | 396 ResetClient(); |
304 return; | 397 return; |
305 } | 398 } |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
399 void VideoCaptureImpl::ResetClient() { | 492 void VideoCaptureImpl::ResetClient() { |
400 client_params_ = media::VideoCaptureParams(); | 493 client_params_ = media::VideoCaptureParams(); |
401 state_update_cb_.Reset(); | 494 state_update_cb_.Reset(); |
402 deliver_frame_cb_.Reset(); | 495 deliver_frame_cb_.Reset(); |
403 first_frame_timestamp_ = base::TimeTicks(); | 496 first_frame_timestamp_ = base::TimeTicks(); |
404 device_id_ = kUndefinedDeviceId; | 497 device_id_ = kUndefinedDeviceId; |
405 state_ = VIDEO_CAPTURE_STATE_STOPPED; | 498 state_ = VIDEO_CAPTURE_STATE_STOPPED; |
406 } | 499 } |
407 | 500 |
408 } // namespace content | 501 } // namespace content |
OLD | NEW |