| 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 <stddef.h> | 14 #include <stddef.h> |
| 15 #include <utility> | 15 #include <utility> |
| 16 | 16 |
| 17 #include "base/bind.h" | 17 #include "base/bind.h" |
| 18 #include "base/macros.h" | 18 #include "base/macros.h" |
| 19 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
| 20 #include "base/threading/thread_task_runner_handle.h" | 20 #include "base/threading/thread_task_runner_handle.h" |
| 21 #include "content/child/child_process.h" | 21 #include "content/child/child_process.h" |
| 22 #include "content/common/media/video_capture_messages.h" | 22 #include "content/common/media/video_capture_messages.h" |
| 23 #include "gpu/ipc/client/gpu_memory_buffer_impl.h" | |
| 24 #include "media/base/bind_to_current_loop.h" | 23 #include "media/base/bind_to_current_loop.h" |
| 25 #include "media/base/limits.h" | 24 #include "media/base/limits.h" |
| 26 #include "media/base/video_frame.h" | 25 #include "media/base/video_frame.h" |
| 27 | 26 |
| 28 namespace content { | 27 namespace content { |
| 29 | 28 |
| 30 // A holder of a memory-backed buffer and accessors to it. | 29 // A holder of a memory-backed buffer and accessors to it. |
| 31 class VideoCaptureImpl::ClientBuffer | 30 class VideoCaptureImpl::ClientBuffer |
| 32 : public base::RefCountedThreadSafe<ClientBuffer> { | 31 : public base::RefCountedThreadSafe<ClientBuffer> { |
| 33 public: | 32 public: |
| 34 ClientBuffer(std::unique_ptr<base::SharedMemory> buffer, size_t buffer_size) | 33 ClientBuffer(std::unique_ptr<base::SharedMemory> buffer, size_t buffer_size) |
| 35 : buffer_(std::move(buffer)), buffer_size_(buffer_size) {} | 34 : buffer_(std::move(buffer)), buffer_size_(buffer_size) {} |
| 36 | 35 |
| 37 base::SharedMemory* buffer() const { return buffer_.get(); } | 36 base::SharedMemory* buffer() const { return buffer_.get(); } |
| 38 size_t buffer_size() const { return buffer_size_; } | 37 size_t buffer_size() const { return buffer_size_; } |
| 39 | 38 |
| 40 private: | 39 private: |
| 41 friend class base::RefCountedThreadSafe<ClientBuffer>; | 40 friend class base::RefCountedThreadSafe<ClientBuffer>; |
| 42 | 41 |
| 43 virtual ~ClientBuffer() {} | 42 virtual ~ClientBuffer() {} |
| 44 | 43 |
| 45 const std::unique_ptr<base::SharedMemory> buffer_; | 44 const std::unique_ptr<base::SharedMemory> buffer_; |
| 46 const size_t buffer_size_; | 45 const size_t buffer_size_; |
| 47 | 46 |
| 48 DISALLOW_COPY_AND_ASSIGN(ClientBuffer); | 47 DISALLOW_COPY_AND_ASSIGN(ClientBuffer); |
| 49 }; | 48 }; |
| 50 | 49 |
| 51 // A holder of a GpuMemoryBuffer-backed buffer, Map()ed on ctor and Unmap()ed on | |
| 52 // dtor. Creates and owns GpuMemoryBuffer instances. | |
| 53 class VideoCaptureImpl::ClientBuffer2 | |
| 54 : public base::RefCountedThreadSafe<ClientBuffer2> { | |
| 55 public: | |
| 56 ClientBuffer2( | |
| 57 const std::vector<gfx::GpuMemoryBufferHandle>& client_handles, | |
| 58 const gfx::Size& size) | |
| 59 : handles_(client_handles), | |
| 60 size_(size) { | |
| 61 const media::VideoPixelFormat format = media::PIXEL_FORMAT_I420; | |
| 62 DCHECK_EQ(handles_.size(), media::VideoFrame::NumPlanes(format)); | |
| 63 for (size_t i = 0; i < handles_.size(); ++i) { | |
| 64 const size_t width = media::VideoFrame::Columns(i, format, size_.width()); | |
| 65 const size_t height = media::VideoFrame::Rows(i, format, size_.height()); | |
| 66 buffers_.push_back(gpu::GpuMemoryBufferImpl::CreateFromHandle( | |
| 67 handles_[i], gfx::Size(width, height), gfx::BufferFormat::R_8, | |
| 68 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, | |
| 69 base::Bind(&ClientBuffer2::DestroyGpuMemoryBuffer, | |
| 70 base::Unretained(this)))); | |
| 71 bool rv = buffers_[i]->Map(); | |
| 72 DCHECK(rv); | |
| 73 data_[i] = reinterpret_cast<uint8_t*>(buffers_[i]->memory(0u)); | |
| 74 strides_[i] = width; | |
| 75 } | |
| 76 } | |
| 77 | |
| 78 uint8_t* data(int plane) const { return data_[plane]; } | |
| 79 int32_t stride(int plane) const { return strides_[plane]; } | |
| 80 std::vector<gfx::GpuMemoryBufferHandle> gpu_memory_buffer_handles() { | |
| 81 return handles_; | |
| 82 } | |
| 83 | |
| 84 private: | |
| 85 friend class base::RefCountedThreadSafe<ClientBuffer2>; | |
| 86 | |
| 87 virtual ~ClientBuffer2() { | |
| 88 for (auto* buffer : buffers_) | |
| 89 buffer->Unmap(); | |
| 90 } | |
| 91 | |
| 92 void DestroyGpuMemoryBuffer(const gpu::SyncToken& sync_token) {} | |
| 93 | |
| 94 const std::vector<gfx::GpuMemoryBufferHandle> handles_; | |
| 95 const gfx::Size size_; | |
| 96 ScopedVector<gfx::GpuMemoryBuffer> buffers_; | |
| 97 uint8_t* data_[media::VideoFrame::kMaxPlanes]; | |
| 98 int32_t strides_[media::VideoFrame::kMaxPlanes]; | |
| 99 | |
| 100 DISALLOW_COPY_AND_ASSIGN(ClientBuffer2); | |
| 101 }; | |
| 102 | |
| 103 VideoCaptureImpl::ClientInfo::ClientInfo() {} | 50 VideoCaptureImpl::ClientInfo::ClientInfo() {} |
| 104 VideoCaptureImpl::ClientInfo::ClientInfo(const ClientInfo& other) = default; | 51 VideoCaptureImpl::ClientInfo::ClientInfo(const ClientInfo& other) = default; |
| 105 VideoCaptureImpl::ClientInfo::~ClientInfo() {} | 52 VideoCaptureImpl::ClientInfo::~ClientInfo() {} |
| 106 | 53 |
| 107 VideoCaptureImpl::VideoCaptureImpl( | 54 VideoCaptureImpl::VideoCaptureImpl( |
| 108 media::VideoCaptureSessionId session_id, | 55 media::VideoCaptureSessionId session_id, |
| 109 VideoCaptureMessageFilter* filter, | 56 VideoCaptureMessageFilter* filter, |
| 110 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) | 57 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) |
| 111 : message_filter_(filter), | 58 : message_filter_(filter), |
| 112 device_id_(0), | 59 device_id_(0), |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 if (!RemoveClient(client_id, &clients_pending_on_restart_)) { | 143 if (!RemoveClient(client_id, &clients_pending_on_restart_)) { |
| 197 RemoveClient(client_id, &clients_); | 144 RemoveClient(client_id, &clients_); |
| 198 } | 145 } |
| 199 } | 146 } |
| 200 | 147 |
| 201 if (!clients_.empty()) | 148 if (!clients_.empty()) |
| 202 return; | 149 return; |
| 203 DVLOG(1) << "StopCapture: No more client, stopping ..."; | 150 DVLOG(1) << "StopCapture: No more client, stopping ..."; |
| 204 StopDevice(); | 151 StopDevice(); |
| 205 client_buffers_.clear(); | 152 client_buffers_.clear(); |
| 206 client_buffer2s_.clear(); | |
| 207 weak_factory_.InvalidateWeakPtrs(); | 153 weak_factory_.InvalidateWeakPtrs(); |
| 208 } | 154 } |
| 209 | 155 |
| 210 void VideoCaptureImpl::RequestRefreshFrame() { | 156 void VideoCaptureImpl::RequestRefreshFrame() { |
| 211 DCHECK(io_task_runner_->BelongsToCurrentThread()); | 157 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| 212 GetVideoCaptureHost()->RequestRefreshFrame(device_id_); | 158 GetVideoCaptureHost()->RequestRefreshFrame(device_id_); |
| 213 } | 159 } |
| 214 | 160 |
| 215 void VideoCaptureImpl::GetDeviceSupportedFormats( | 161 void VideoCaptureImpl::GetDeviceSupportedFormats( |
| 216 const VideoCaptureDeviceFormatsCB& callback) { | 162 const VideoCaptureDeviceFormatsCB& callback) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 return; | 195 return; |
| 250 } | 196 } |
| 251 const bool inserted = | 197 const bool inserted = |
| 252 client_buffers_.insert(std::make_pair( | 198 client_buffers_.insert(std::make_pair( |
| 253 buffer_id, | 199 buffer_id, |
| 254 new ClientBuffer(std::move(shm), length))) | 200 new ClientBuffer(std::move(shm), length))) |
| 255 .second; | 201 .second; |
| 256 DCHECK(inserted); | 202 DCHECK(inserted); |
| 257 } | 203 } |
| 258 | 204 |
| 259 void VideoCaptureImpl::OnBufferCreated2( | |
| 260 const std::vector<gfx::GpuMemoryBufferHandle>& handles, | |
| 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_buffer2s_.insert(std::make_pair(buffer_id, | |
| 272 new ClientBuffer2(handles, size))) | |
| 273 .second; | |
| 274 DCHECK(inserted); | |
| 275 } | |
| 276 | |
| 277 void VideoCaptureImpl::OnBufferDestroyed(int buffer_id) { | 205 void VideoCaptureImpl::OnBufferDestroyed(int buffer_id) { |
| 278 DCHECK(io_task_runner_->BelongsToCurrentThread()); | 206 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| 279 | 207 |
| 280 const auto& cb_iter = client_buffers_.find(buffer_id); | 208 const auto& cb_iter = client_buffers_.find(buffer_id); |
| 281 if (cb_iter != client_buffers_.end()) { | 209 if (cb_iter != client_buffers_.end()) { |
| 282 DCHECK(!cb_iter->second.get() || cb_iter->second->HasOneRef()) | 210 DCHECK(!cb_iter->second.get() || cb_iter->second->HasOneRef()) |
| 283 << "Instructed to delete buffer we are still using."; | 211 << "Instructed to delete buffer we are still using."; |
| 284 client_buffers_.erase(cb_iter); | 212 client_buffers_.erase(cb_iter); |
| 285 } else { | |
| 286 const auto& cb2_iter = client_buffer2s_.find(buffer_id); | |
| 287 if (cb2_iter != client_buffer2s_.end()) { | |
| 288 DCHECK(!cb2_iter->second.get() || cb2_iter->second->HasOneRef()) | |
| 289 << "Instructed to delete buffer we are still using."; | |
| 290 client_buffer2s_.erase(cb2_iter); | |
| 291 } | |
| 292 } | 213 } |
| 293 } | 214 } |
| 294 | 215 |
| 295 void VideoCaptureImpl::OnBufferReceived( | 216 void VideoCaptureImpl::OnBufferReceived( |
| 296 int buffer_id, | 217 int buffer_id, |
| 297 base::TimeDelta timestamp, | 218 base::TimeDelta timestamp, |
| 298 const base::DictionaryValue& metadata, | 219 const base::DictionaryValue& metadata, |
| 299 media::VideoPixelFormat pixel_format, | 220 media::VideoPixelFormat pixel_format, |
| 300 media::VideoFrame::StorageType storage_type, | 221 media::VideoFrame::StorageType storage_type, |
| 301 const gfx::Size& coded_size, | 222 const gfx::Size& coded_size, |
| 302 const gfx::Rect& visible_rect) { | 223 const gfx::Rect& visible_rect) { |
| 303 DCHECK(io_task_runner_->BelongsToCurrentThread()); | 224 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| 225 // Crash in debug builds since the host should not have provided a buffer |
| 226 // with an unsupported pixel format or storage type. |
| 227 DCHECK_EQ(media::PIXEL_FORMAT_I420, pixel_format); |
| 228 DCHECK(storage_type == media::VideoFrame::STORAGE_SHMEM); |
| 304 if (state_ != VIDEO_CAPTURE_STATE_STARTED || | 229 if (state_ != VIDEO_CAPTURE_STATE_STARTED || |
| 305 pixel_format != media::PIXEL_FORMAT_I420 || | 230 pixel_format != media::PIXEL_FORMAT_I420 || |
| 306 (storage_type != media::VideoFrame::STORAGE_SHMEM && | 231 storage_type != media::VideoFrame::STORAGE_SHMEM) { |
| 307 storage_type != media::VideoFrame::STORAGE_GPU_MEMORY_BUFFERS)) { | |
| 308 // Crash in debug builds since the host should not have provided a buffer | |
| 309 // with an unsupported pixel format or storage type. | |
| 310 DCHECK_EQ(media::PIXEL_FORMAT_I420, pixel_format); | |
| 311 DCHECK(storage_type == media::VideoFrame::STORAGE_SHMEM || | |
| 312 storage_type == media::VideoFrame::STORAGE_GPU_MEMORY_BUFFERS); | |
| 313 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id, | 232 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id, |
| 314 gpu::SyncToken(), -1.0)); | 233 gpu::SyncToken(), -1.0)); |
| 315 return; | 234 return; |
| 316 } | 235 } |
| 317 | 236 |
| 318 base::TimeTicks reference_time; | 237 base::TimeTicks reference_time; |
| 319 media::VideoFrameMetadata frame_metadata; | 238 media::VideoFrameMetadata frame_metadata; |
| 320 frame_metadata.MergeInternalValuesFrom(metadata); | 239 frame_metadata.MergeInternalValuesFrom(metadata); |
| 321 const bool success = frame_metadata.GetTimeTicks( | 240 const bool success = frame_metadata.GetTimeTicks( |
| 322 media::VideoFrameMetadata::REFERENCE_TIME, &reference_time); | 241 media::VideoFrameMetadata::REFERENCE_TIME, &reference_time); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 333 timestamp = reference_time - first_frame_ref_time_; | 252 timestamp = reference_time - first_frame_ref_time_; |
| 334 | 253 |
| 335 // TODO(qiangchen): Change the metric name to "reference_time" and | 254 // TODO(qiangchen): Change the metric name to "reference_time" and |
| 336 // "timestamp", so that we have consistent naming everywhere. | 255 // "timestamp", so that we have consistent naming everywhere. |
| 337 // Used by chrome/browser/extension/api/cast_streaming/performance_test.cc | 256 // Used by chrome/browser/extension/api/cast_streaming/performance_test.cc |
| 338 TRACE_EVENT_INSTANT2("cast_perf_test", "OnBufferReceived", | 257 TRACE_EVENT_INSTANT2("cast_perf_test", "OnBufferReceived", |
| 339 TRACE_EVENT_SCOPE_THREAD, "timestamp", | 258 TRACE_EVENT_SCOPE_THREAD, "timestamp", |
| 340 (reference_time - base::TimeTicks()).InMicroseconds(), | 259 (reference_time - base::TimeTicks()).InMicroseconds(), |
| 341 "time_delta", timestamp.InMicroseconds()); | 260 "time_delta", timestamp.InMicroseconds()); |
| 342 | 261 |
| 343 scoped_refptr<media::VideoFrame> frame; | 262 const auto& iter = client_buffers_.find(buffer_id); |
| 344 BufferFinishedCallback buffer_finished_callback; | 263 DCHECK(iter != client_buffers_.end()); |
| 345 std::unique_ptr<gpu::SyncToken> release_sync_token(new gpu::SyncToken); | 264 const scoped_refptr<ClientBuffer> buffer = iter->second; |
| 346 switch (storage_type) { | 265 scoped_refptr<media::VideoFrame> frame = |
| 347 case media::VideoFrame::STORAGE_GPU_MEMORY_BUFFERS: { | 266 media::VideoFrame::WrapExternalSharedMemory( |
| 348 const auto& iter = client_buffer2s_.find(buffer_id); | |
| 349 DCHECK(iter != client_buffer2s_.end()); | |
| 350 scoped_refptr<ClientBuffer2> buffer = iter->second; | |
| 351 const auto& handles = buffer->gpu_memory_buffer_handles(); | |
| 352 frame = media::VideoFrame::WrapExternalYuvGpuMemoryBuffers( | |
| 353 media::PIXEL_FORMAT_I420, coded_size, gfx::Rect(coded_size), | |
| 354 coded_size, buffer->stride(media::VideoFrame::kYPlane), | |
| 355 buffer->stride(media::VideoFrame::kUPlane), | |
| 356 buffer->stride(media::VideoFrame::kVPlane), | |
| 357 buffer->data(media::VideoFrame::kYPlane), | |
| 358 buffer->data(media::VideoFrame::kUPlane), | |
| 359 buffer->data(media::VideoFrame::kVPlane), | |
| 360 handles[media::VideoFrame::kYPlane], | |
| 361 handles[media::VideoFrame::kUPlane], | |
| 362 handles[media::VideoFrame::kVPlane], timestamp); | |
| 363 buffer_finished_callback = media::BindToCurrentLoop( | |
| 364 base::Bind(&VideoCaptureImpl::OnClientBufferFinished2, | |
| 365 weak_factory_.GetWeakPtr(), buffer_id, buffer)); | |
| 366 break; | |
| 367 } | |
| 368 case media::VideoFrame::STORAGE_SHMEM: { | |
| 369 const auto& iter = client_buffers_.find(buffer_id); | |
| 370 DCHECK(iter != client_buffers_.end()); | |
| 371 const scoped_refptr<ClientBuffer> buffer = iter->second; | |
| 372 frame = media::VideoFrame::WrapExternalSharedMemory( | |
| 373 pixel_format, coded_size, visible_rect, | 267 pixel_format, coded_size, visible_rect, |
| 374 gfx::Size(visible_rect.width(), visible_rect.height()), | 268 gfx::Size(visible_rect.width(), visible_rect.height()), |
| 375 reinterpret_cast<uint8_t*>(buffer->buffer()->memory()), | 269 reinterpret_cast<uint8_t*>(buffer->buffer()->memory()), |
| 376 buffer->buffer_size(), buffer->buffer()->handle(), | 270 buffer->buffer_size(), buffer->buffer()->handle(), |
| 377 0 /* shared_memory_offset */, timestamp); | 271 0 /* shared_memory_offset */, timestamp); |
| 378 buffer_finished_callback = media::BindToCurrentLoop( | |
| 379 base::Bind(&VideoCaptureImpl::OnClientBufferFinished, | |
| 380 weak_factory_.GetWeakPtr(), buffer_id, buffer)); | |
| 381 break; | |
| 382 } | |
| 383 default: | |
| 384 NOTREACHED(); | |
| 385 break; | |
| 386 } | |
| 387 if (!frame) { | 272 if (!frame) { |
| 388 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id, | 273 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id, |
| 389 gpu::SyncToken(), -1.0)); | 274 gpu::SyncToken(), -1.0)); |
| 390 return; | 275 return; |
| 391 } | 276 } |
| 392 | 277 |
| 278 BufferFinishedCallback buffer_finished_callback = media::BindToCurrentLoop( |
| 279 base::Bind(&VideoCaptureImpl::OnClientBufferFinished, |
| 280 weak_factory_.GetWeakPtr(), buffer_id, buffer)); |
| 281 std::unique_ptr<gpu::SyncToken> release_sync_token(new gpu::SyncToken); |
| 393 frame->AddDestructionObserver( | 282 frame->AddDestructionObserver( |
| 394 base::Bind(&VideoCaptureImpl::DidFinishConsumingFrame, frame->metadata(), | 283 base::Bind(&VideoCaptureImpl::DidFinishConsumingFrame, frame->metadata(), |
| 395 base::Passed(&release_sync_token), buffer_finished_callback)); | 284 base::Passed(&release_sync_token), buffer_finished_callback)); |
| 396 | 285 |
| 397 frame->metadata()->MergeInternalValuesFrom(metadata); | 286 frame->metadata()->MergeInternalValuesFrom(metadata); |
| 398 | 287 |
| 399 // TODO(qiangchen): Dive into the full code path to let frame metadata hold | 288 // TODO(qiangchen): Dive into the full code path to let frame metadata hold |
| 400 // reference time rather than using an extra parameter. | 289 // reference time rather than using an extra parameter. |
| 401 for (const auto& client : clients_) | 290 for (const auto& client : clients_) |
| 402 client.second.deliver_frame_cb.Run(frame, reference_time); | 291 client.second.deliver_frame_cb.Run(frame, reference_time); |
| 403 } | 292 } |
| 404 | 293 |
| 405 void VideoCaptureImpl::OnClientBufferFinished( | 294 void VideoCaptureImpl::OnClientBufferFinished( |
| 406 int buffer_id, | 295 int buffer_id, |
| 407 const scoped_refptr<ClientBuffer>& /* ignored_buffer */, | 296 const scoped_refptr<ClientBuffer>& /* ignored_buffer */, |
| 408 const gpu::SyncToken& release_sync_token, | 297 const gpu::SyncToken& release_sync_token, |
| 409 double consumer_resource_utilization) { | 298 double consumer_resource_utilization) { |
| 410 DCHECK(io_task_runner_->BelongsToCurrentThread()); | 299 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| 411 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id, | 300 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id, |
| 412 release_sync_token, | 301 release_sync_token, |
| 413 consumer_resource_utilization)); | 302 consumer_resource_utilization)); |
| 414 } | 303 } |
| 415 void VideoCaptureImpl::OnClientBufferFinished2( | |
| 416 int buffer_id, | |
| 417 const scoped_refptr<ClientBuffer2>& gpu_memory_buffer /* ignored_buffer */, | |
| 418 const gpu::SyncToken& release_sync_token, | |
| 419 double consumer_resource_utilization) { | |
| 420 OnClientBufferFinished(buffer_id, scoped_refptr<ClientBuffer>(), | |
| 421 release_sync_token, consumer_resource_utilization); | |
| 422 } | |
| 423 | 304 |
| 424 void VideoCaptureImpl::OnStateChanged(VideoCaptureState state) { | 305 void VideoCaptureImpl::OnStateChanged(VideoCaptureState state) { |
| 425 DCHECK(io_task_runner_->BelongsToCurrentThread()); | 306 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| 426 | 307 |
| 427 switch (state) { | 308 switch (state) { |
| 428 case VIDEO_CAPTURE_STATE_STARTED: | 309 case VIDEO_CAPTURE_STATE_STARTED: |
| 429 // Camera has started in the browser process. Since we have already | 310 // Camera has started in the browser process. Since we have already |
| 430 // told all clients that we have started there's nothing to do. | 311 // told all clients that we have started there's nothing to do. |
| 431 break; | 312 break; |
| 432 case VIDEO_CAPTURE_STATE_STOPPED: | 313 case VIDEO_CAPTURE_STATE_STOPPED: |
| 433 state_ = VIDEO_CAPTURE_STATE_STOPPED; | 314 state_ = VIDEO_CAPTURE_STATE_STOPPED; |
| 434 DVLOG(1) << "OnStateChanged: stopped!, device_id = " << device_id_; | 315 DVLOG(1) << "OnStateChanged: stopped!, device_id = " << device_id_; |
| 435 client_buffers_.clear(); | 316 client_buffers_.clear(); |
| 436 client_buffer2s_.clear(); | |
| 437 weak_factory_.InvalidateWeakPtrs(); | 317 weak_factory_.InvalidateWeakPtrs(); |
| 438 if (!clients_.empty() || !clients_pending_on_restart_.empty()) | 318 if (!clients_.empty() || !clients_pending_on_restart_.empty()) |
| 439 RestartCapture(); | 319 RestartCapture(); |
| 440 break; | 320 break; |
| 441 case VIDEO_CAPTURE_STATE_PAUSED: | 321 case VIDEO_CAPTURE_STATE_PAUSED: |
| 442 case VIDEO_CAPTURE_STATE_RESUMED: | 322 case VIDEO_CAPTURE_STATE_RESUMED: |
| 443 for (const auto& client : clients_) | 323 for (const auto& client : clients_) |
| 444 client.second.state_update_cb.Run(state); | 324 client.second.state_update_cb.Run(state); |
| 445 break; | 325 break; |
| 446 case VIDEO_CAPTURE_STATE_ERROR: | 326 case VIDEO_CAPTURE_STATE_ERROR: |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 double consumer_resource_utilization = -1.0; | 454 double consumer_resource_utilization = -1.0; |
| 575 if (!metadata->GetDouble(media::VideoFrameMetadata::RESOURCE_UTILIZATION, | 455 if (!metadata->GetDouble(media::VideoFrameMetadata::RESOURCE_UTILIZATION, |
| 576 &consumer_resource_utilization)) { | 456 &consumer_resource_utilization)) { |
| 577 consumer_resource_utilization = -1.0; | 457 consumer_resource_utilization = -1.0; |
| 578 } | 458 } |
| 579 | 459 |
| 580 callback_to_io_thread.Run(*release_sync_token, consumer_resource_utilization); | 460 callback_to_io_thread.Run(*release_sync_token, consumer_resource_utilization); |
| 581 } | 461 } |
| 582 | 462 |
| 583 } // namespace content | 463 } // namespace content |
| OLD | NEW |