Chromium Code Reviews| 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. |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 media::VideoFrame::StorageType storage_type, | 220 media::VideoFrame::StorageType storage_type, |
| 221 const gfx::Size& coded_size, | 221 const gfx::Size& coded_size, |
| 222 const gfx::Rect& visible_rect) { | 222 const gfx::Rect& visible_rect) { |
| 223 DCHECK(io_task_runner_->BelongsToCurrentThread()); | 223 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| 224 DCHECK_EQ(media::PIXEL_FORMAT_I420, pixel_format); | 224 DCHECK_EQ(media::PIXEL_FORMAT_I420, pixel_format); |
| 225 DCHECK_EQ(media::VideoFrame::STORAGE_SHMEM, storage_type); | 225 DCHECK_EQ(media::VideoFrame::STORAGE_SHMEM, storage_type); |
| 226 | 226 |
| 227 if (state_ != VIDEO_CAPTURE_STATE_STARTED || | 227 if (state_ != VIDEO_CAPTURE_STATE_STARTED || |
| 228 pixel_format != media::PIXEL_FORMAT_I420 || | 228 pixel_format != media::PIXEL_FORMAT_I420 || |
| 229 storage_type != media::VideoFrame::STORAGE_SHMEM) { | 229 storage_type != media::VideoFrame::STORAGE_SHMEM) { |
| 230 GetVideoCaptureHost()->ReleaseBuffer(device_id_, buffer_id, | 230 GetVideoCaptureHost()->ReleaseBuffer(device_id_, buffer_id, -1.0); |
| 231 gpu::SyncToken(), -1.0); | |
| 232 return; | 231 return; |
| 233 } | 232 } |
| 234 | 233 |
| 235 base::TimeTicks reference_time; | 234 base::TimeTicks reference_time; |
| 236 media::VideoFrameMetadata frame_metadata; | 235 media::VideoFrameMetadata frame_metadata; |
| 237 frame_metadata.MergeInternalValuesFrom(metadata); | 236 frame_metadata.MergeInternalValuesFrom(metadata); |
| 238 const bool success = frame_metadata.GetTimeTicks( | 237 const bool success = frame_metadata.GetTimeTicks( |
| 239 media::VideoFrameMetadata::REFERENCE_TIME, &reference_time); | 238 media::VideoFrameMetadata::REFERENCE_TIME, &reference_time); |
| 240 DCHECK(success); | 239 DCHECK(success); |
| 241 | 240 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 261 DCHECK(iter != client_buffers_.end()); | 260 DCHECK(iter != client_buffers_.end()); |
| 262 const scoped_refptr<ClientBuffer> buffer = iter->second; | 261 const scoped_refptr<ClientBuffer> buffer = iter->second; |
| 263 scoped_refptr<media::VideoFrame> frame = | 262 scoped_refptr<media::VideoFrame> frame = |
| 264 media::VideoFrame::WrapExternalSharedMemory( | 263 media::VideoFrame::WrapExternalSharedMemory( |
| 265 pixel_format, coded_size, visible_rect, | 264 pixel_format, coded_size, visible_rect, |
| 266 gfx::Size(visible_rect.width(), visible_rect.height()), | 265 gfx::Size(visible_rect.width(), visible_rect.height()), |
| 267 reinterpret_cast<uint8_t*>(buffer->buffer()->memory()), | 266 reinterpret_cast<uint8_t*>(buffer->buffer()->memory()), |
| 268 buffer->buffer_size(), buffer->buffer()->handle(), | 267 buffer->buffer_size(), buffer->buffer()->handle(), |
| 269 0 /* shared_memory_offset */, timestamp); | 268 0 /* shared_memory_offset */, timestamp); |
| 270 if (!frame) { | 269 if (!frame) { |
| 271 GetVideoCaptureHost()->ReleaseBuffer(device_id_, buffer_id, | 270 GetVideoCaptureHost()->ReleaseBuffer(device_id_, buffer_id, -1.0); |
| 272 gpu::SyncToken(), -1.0); | |
| 273 return; | 271 return; |
| 274 } | 272 } |
| 275 | 273 |
| 276 BufferFinishedCallback buffer_finished_callback = media::BindToCurrentLoop( | 274 BufferFinishedCallback buffer_finished_callback = media::BindToCurrentLoop( |
| 277 base::Bind(&VideoCaptureImpl::OnClientBufferFinished, | 275 base::Bind(&VideoCaptureImpl::OnClientBufferFinished, |
| 278 weak_factory_.GetWeakPtr(), buffer_id, buffer)); | 276 weak_factory_.GetWeakPtr(), buffer_id, buffer)); |
| 279 std::unique_ptr<gpu::SyncToken> release_sync_token(new gpu::SyncToken); | |
| 280 frame->AddDestructionObserver( | 277 frame->AddDestructionObserver( |
| 281 base::Bind(&VideoCaptureImpl::DidFinishConsumingFrame, frame->metadata(), | 278 base::Bind(&VideoCaptureImpl::DidFinishConsumingFrame, frame->metadata(), |
| 282 base::Passed(&release_sync_token), buffer_finished_callback)); | 279 buffer_finished_callback)); |
| 283 | 280 |
| 284 frame->metadata()->MergeInternalValuesFrom(metadata); | 281 frame->metadata()->MergeInternalValuesFrom(metadata); |
| 285 | 282 |
| 286 // TODO(qiangchen): Dive into the full code path to let frame metadata hold | 283 // TODO(qiangchen): Dive into the full code path to let frame metadata hold |
| 287 // reference time rather than using an extra parameter. | 284 // reference time rather than using an extra parameter. |
| 288 for (const auto& client : clients_) | 285 for (const auto& client : clients_) |
| 289 client.second.deliver_frame_cb.Run(frame, reference_time); | 286 client.second.deliver_frame_cb.Run(frame, reference_time); |
| 290 } | 287 } |
| 291 | 288 |
| 292 void VideoCaptureImpl::OnDelegateAdded(int32_t device_id) { | 289 void VideoCaptureImpl::OnDelegateAdded(int32_t device_id) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 340 client.second.state_update_cb.Run(VIDEO_CAPTURE_STATE_STOPPED); | 337 client.second.state_update_cb.Run(VIDEO_CAPTURE_STATE_STOPPED); |
| 341 clients_.clear(); | 338 clients_.clear(); |
| 342 state_ = VIDEO_CAPTURE_STATE_ENDED; | 339 state_ = VIDEO_CAPTURE_STATE_ENDED; |
| 343 break; | 340 break; |
| 344 } | 341 } |
| 345 } | 342 } |
| 346 | 343 |
| 347 void VideoCaptureImpl::OnClientBufferFinished( | 344 void VideoCaptureImpl::OnClientBufferFinished( |
| 348 int buffer_id, | 345 int buffer_id, |
| 349 const scoped_refptr<ClientBuffer>& /* ignored_buffer */, | 346 const scoped_refptr<ClientBuffer>& /* ignored_buffer */, |
| 350 const gpu::SyncToken& release_sync_token, | |
| 351 double consumer_resource_utilization) { | 347 double consumer_resource_utilization) { |
| 352 DCHECK(io_task_runner_->BelongsToCurrentThread()); | 348 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| 353 GetVideoCaptureHost()->ReleaseBuffer( | 349 GetVideoCaptureHost()->ReleaseBuffer( |
| 354 device_id_, buffer_id, release_sync_token, consumer_resource_utilization); | 350 device_id_, buffer_id, consumer_resource_utilization); |
| 355 } | 351 } |
| 356 | 352 |
| 357 void VideoCaptureImpl::StopDevice() { | 353 void VideoCaptureImpl::StopDevice() { |
| 358 DCHECK(io_task_runner_->BelongsToCurrentThread()); | 354 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| 359 if (state_ != VIDEO_CAPTURE_STATE_STARTED) | 355 if (state_ != VIDEO_CAPTURE_STATE_STARTED) |
| 360 return; | 356 return; |
| 361 state_ = VIDEO_CAPTURE_STATE_STOPPING; | 357 state_ = VIDEO_CAPTURE_STATE_STOPPING; |
| 362 GetVideoCaptureHost()->Stop(device_id_); | 358 GetVideoCaptureHost()->Stop(device_id_); |
| 363 params_.requested_format.frame_size.SetSize(0, 0); | 359 params_.requested_format.frame_size.SetSize(0, 0); |
| 364 } | 360 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 435 if (!interface_support) | 431 if (!interface_support) |
| 436 return nullptr; | 432 return nullptr; |
| 437 interface_support->GetRemoteAssociatedInterface(&video_capture_host_); | 433 interface_support->GetRemoteAssociatedInterface(&video_capture_host_); |
| 438 } | 434 } |
| 439 return video_capture_host_.get(); | 435 return video_capture_host_.get(); |
| 440 }; | 436 }; |
| 441 | 437 |
| 442 // static | 438 // static |
| 443 void VideoCaptureImpl::DidFinishConsumingFrame( | 439 void VideoCaptureImpl::DidFinishConsumingFrame( |
| 444 const media::VideoFrameMetadata* metadata, | 440 const media::VideoFrameMetadata* metadata, |
| 445 std::unique_ptr<gpu::SyncToken> release_sync_token, | |
| 446 const BufferFinishedCallback& callback_to_io_thread) { | 441 const BufferFinishedCallback& callback_to_io_thread) { |
| 447 // Note: This function may be called on any thread by the VideoFrame | 442 // Note: This function may be called on any thread by the VideoFrame |
| 448 // destructor. |metadata| is still valid for read-access at this point. | 443 // destructor. |metadata| is still valid for read-access at this point. |
| 449 double consumer_resource_utilization = -1.0; | 444 double consumer_resource_utilization = -1.0; |
| 450 if (!metadata->GetDouble(media::VideoFrameMetadata::RESOURCE_UTILIZATION, | 445 if (!metadata->GetDouble(media::VideoFrameMetadata::RESOURCE_UTILIZATION, |
| 451 &consumer_resource_utilization)) { | 446 &consumer_resource_utilization)) { |
| 452 consumer_resource_utilization = -1.0; | 447 consumer_resource_utilization = -1.0; |
| 453 } | 448 } |
| 454 | |
| 455 callback_to_io_thread.Run(*release_sync_token, consumer_resource_utilization); | |
|
emircan
2016/10/24 21:45:28
callback_to_io_thread.Run(consumer_resource_utiliz
| |
| 456 } | 449 } |
| 457 | 450 |
| 458 } // namespace content | 451 } // namespace content |
| OLD | NEW |