| 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 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 bool consume_buffer = state_ == VIDEO_CAPTURE_STATE_STARTED; | 262 bool consume_buffer = state_ == VIDEO_CAPTURE_STATE_STARTED; |
| 263 if ((info->pixel_format != media::PIXEL_FORMAT_I420 && | 263 if ((info->pixel_format != media::PIXEL_FORMAT_I420 && |
| 264 info->pixel_format != media::PIXEL_FORMAT_Y16) || | 264 info->pixel_format != media::PIXEL_FORMAT_Y16) || |
| 265 info->storage_type != media::PIXEL_STORAGE_CPU) { | 265 info->storage_type != media::PIXEL_STORAGE_CPU) { |
| 266 consume_buffer = false; | 266 consume_buffer = false; |
| 267 LOG(DFATAL) << "Wrong pixel format or storage, got pixel format:" | 267 LOG(DFATAL) << "Wrong pixel format or storage, got pixel format:" |
| 268 << VideoPixelFormatToString(info->pixel_format) | 268 << VideoPixelFormatToString(info->pixel_format) |
| 269 << ", storage:" << info->storage_type; | 269 << ", storage:" << info->storage_type; |
| 270 } | 270 } |
| 271 if (!consume_buffer) { | 271 if (!consume_buffer) { |
| 272 GetVideoCaptureHost()->ReleaseBuffer(device_id_, buffer_id, | 272 GetVideoCaptureHost()->ReleaseBuffer(device_id_, buffer_id, -1.0); |
| 273 gpu::SyncToken(), -1.0); | |
| 274 return; | 273 return; |
| 275 } | 274 } |
| 276 | 275 |
| 277 base::TimeTicks reference_time; | 276 base::TimeTicks reference_time; |
| 278 media::VideoFrameMetadata frame_metadata; | 277 media::VideoFrameMetadata frame_metadata; |
| 279 frame_metadata.MergeInternalValuesFrom(*info->metadata); | 278 frame_metadata.MergeInternalValuesFrom(*info->metadata); |
| 280 const bool success = frame_metadata.GetTimeTicks( | 279 const bool success = frame_metadata.GetTimeTicks( |
| 281 media::VideoFrameMetadata::REFERENCE_TIME, &reference_time); | 280 media::VideoFrameMetadata::REFERENCE_TIME, &reference_time); |
| 282 DCHECK(success); | 281 DCHECK(success); |
| 283 | 282 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 303 DCHECK(iter != client_buffers_.end()); | 302 DCHECK(iter != client_buffers_.end()); |
| 304 const scoped_refptr<ClientBuffer> buffer = iter->second; | 303 const scoped_refptr<ClientBuffer> buffer = iter->second; |
| 305 scoped_refptr<media::VideoFrame> frame = | 304 scoped_refptr<media::VideoFrame> frame = |
| 306 media::VideoFrame::WrapExternalSharedMemory( | 305 media::VideoFrame::WrapExternalSharedMemory( |
| 307 static_cast<media::VideoPixelFormat>(info->pixel_format), | 306 static_cast<media::VideoPixelFormat>(info->pixel_format), |
| 308 info->coded_size, info->visible_rect, info->visible_rect.size(), | 307 info->coded_size, info->visible_rect, info->visible_rect.size(), |
| 309 reinterpret_cast<uint8_t*>(buffer->buffer()->memory()), | 308 reinterpret_cast<uint8_t*>(buffer->buffer()->memory()), |
| 310 buffer->buffer_size(), buffer->buffer()->handle(), | 309 buffer->buffer_size(), buffer->buffer()->handle(), |
| 311 0 /* shared_memory_offset */, info->timestamp); | 310 0 /* shared_memory_offset */, info->timestamp); |
| 312 if (!frame) { | 311 if (!frame) { |
| 313 GetVideoCaptureHost()->ReleaseBuffer(device_id_, buffer_id, | 312 GetVideoCaptureHost()->ReleaseBuffer(device_id_, buffer_id, -1.0); |
| 314 gpu::SyncToken(), -1.0); | |
| 315 return; | 313 return; |
| 316 } | 314 } |
| 317 | 315 |
| 318 BufferFinishedCallback buffer_finished_callback = media::BindToCurrentLoop( | 316 BufferFinishedCallback buffer_finished_callback = media::BindToCurrentLoop( |
| 319 base::Bind(&VideoCaptureImpl::OnClientBufferFinished, | 317 base::Bind(&VideoCaptureImpl::OnClientBufferFinished, |
| 320 weak_factory_.GetWeakPtr(), buffer_id, buffer)); | 318 weak_factory_.GetWeakPtr(), buffer_id, buffer)); |
| 321 std::unique_ptr<gpu::SyncToken> release_sync_token(new gpu::SyncToken); | |
| 322 frame->AddDestructionObserver( | 319 frame->AddDestructionObserver( |
| 323 base::Bind(&VideoCaptureImpl::DidFinishConsumingFrame, frame->metadata(), | 320 base::Bind(&VideoCaptureImpl::DidFinishConsumingFrame, frame->metadata(), |
| 324 base::Passed(&release_sync_token), buffer_finished_callback)); | 321 buffer_finished_callback)); |
| 325 | 322 |
| 326 frame->metadata()->MergeInternalValuesFrom(*info->metadata); | 323 frame->metadata()->MergeInternalValuesFrom(*info->metadata); |
| 327 | 324 |
| 328 // TODO(qiangchen): Dive into the full code path to let frame metadata hold | 325 // TODO(qiangchen): Dive into the full code path to let frame metadata hold |
| 329 // reference time rather than using an extra parameter. | 326 // reference time rather than using an extra parameter. |
| 330 for (const auto& client : clients_) | 327 for (const auto& client : clients_) |
| 331 client.second.deliver_frame_cb.Run(frame, reference_time); | 328 client.second.deliver_frame_cb.Run(frame, reference_time); |
| 332 } | 329 } |
| 333 | 330 |
| 334 void VideoCaptureImpl::OnBufferDestroyed(int32_t buffer_id) { | 331 void VideoCaptureImpl::OnBufferDestroyed(int32_t buffer_id) { |
| 335 DCHECK(io_thread_checker_.CalledOnValidThread()); | 332 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 336 | 333 |
| 337 const auto& cb_iter = client_buffers_.find(buffer_id); | 334 const auto& cb_iter = client_buffers_.find(buffer_id); |
| 338 if (cb_iter != client_buffers_.end()) { | 335 if (cb_iter != client_buffers_.end()) { |
| 339 DCHECK(!cb_iter->second.get() || cb_iter->second->HasOneRef()) | 336 DCHECK(!cb_iter->second.get() || cb_iter->second->HasOneRef()) |
| 340 << "Instructed to delete buffer we are still using."; | 337 << "Instructed to delete buffer we are still using."; |
| 341 client_buffers_.erase(cb_iter); | 338 client_buffers_.erase(cb_iter); |
| 342 } | 339 } |
| 343 } | 340 } |
| 344 | 341 |
| 345 void VideoCaptureImpl::OnClientBufferFinished( | 342 void VideoCaptureImpl::OnClientBufferFinished( |
| 346 int buffer_id, | 343 int buffer_id, |
| 347 const scoped_refptr<ClientBuffer>& /* ignored_buffer */, | 344 const scoped_refptr<ClientBuffer>& /* ignored_buffer */, |
| 348 const gpu::SyncToken& release_sync_token, | |
| 349 double consumer_resource_utilization) { | 345 double consumer_resource_utilization) { |
| 350 DCHECK(io_thread_checker_.CalledOnValidThread()); | 346 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 351 GetVideoCaptureHost()->ReleaseBuffer( | 347 GetVideoCaptureHost()->ReleaseBuffer( |
| 352 device_id_, buffer_id, release_sync_token, consumer_resource_utilization); | 348 device_id_, buffer_id, consumer_resource_utilization); |
| 353 } | 349 } |
| 354 | 350 |
| 355 void VideoCaptureImpl::StopDevice() { | 351 void VideoCaptureImpl::StopDevice() { |
| 356 DCHECK(io_thread_checker_.CalledOnValidThread()); | 352 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 357 if (state_ != VIDEO_CAPTURE_STATE_STARTED) | 353 if (state_ != VIDEO_CAPTURE_STATE_STARTED) |
| 358 return; | 354 return; |
| 359 state_ = VIDEO_CAPTURE_STATE_STOPPING; | 355 state_ = VIDEO_CAPTURE_STATE_STOPPING; |
| 360 GetVideoCaptureHost()->Stop(device_id_); | 356 GetVideoCaptureHost()->Stop(device_id_); |
| 361 params_.requested_format.frame_size.SetSize(0, 0); | 357 params_.requested_format.frame_size.SetSize(0, 0); |
| 362 } | 358 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 return video_capture_host_for_testing_; | 417 return video_capture_host_for_testing_; |
| 422 | 418 |
| 423 if (!video_capture_host_.get()) | 419 if (!video_capture_host_.get()) |
| 424 video_capture_host_.Bind(std::move(video_capture_host_info_)); | 420 video_capture_host_.Bind(std::move(video_capture_host_info_)); |
| 425 return video_capture_host_.get(); | 421 return video_capture_host_.get(); |
| 426 }; | 422 }; |
| 427 | 423 |
| 428 // static | 424 // static |
| 429 void VideoCaptureImpl::DidFinishConsumingFrame( | 425 void VideoCaptureImpl::DidFinishConsumingFrame( |
| 430 const media::VideoFrameMetadata* metadata, | 426 const media::VideoFrameMetadata* metadata, |
| 431 std::unique_ptr<gpu::SyncToken> release_sync_token, | |
| 432 const BufferFinishedCallback& callback_to_io_thread) { | 427 const BufferFinishedCallback& callback_to_io_thread) { |
| 433 // Note: This function may be called on any thread by the VideoFrame | 428 // Note: This function may be called on any thread by the VideoFrame |
| 434 // destructor. |metadata| is still valid for read-access at this point. | 429 // destructor. |metadata| is still valid for read-access at this point. |
| 435 double consumer_resource_utilization = -1.0; | 430 double consumer_resource_utilization = -1.0; |
| 436 if (!metadata->GetDouble(media::VideoFrameMetadata::RESOURCE_UTILIZATION, | 431 if (!metadata->GetDouble(media::VideoFrameMetadata::RESOURCE_UTILIZATION, |
| 437 &consumer_resource_utilization)) { | 432 &consumer_resource_utilization)) { |
| 438 consumer_resource_utilization = -1.0; | 433 consumer_resource_utilization = -1.0; |
| 439 } | 434 } |
| 440 | 435 callback_to_io_thread.Run(consumer_resource_utilization); |
| 441 callback_to_io_thread.Run(*release_sync_token, consumer_resource_utilization); | |
| 442 } | 436 } |
| 443 | 437 |
| 444 } // namespace content | 438 } // namespace content |
| OLD | NEW |