Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(332)

Side by Side Diff: media/capture/video/video_capture_device_client.cc

Issue 2607203002: [Mojo Video Capture] Retire buffers when Android Chromium goes to the background (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include "media/capture/video/video_capture_device_client.h" 5 #include "media/capture/video/video_capture_device_client.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 : receiver_(std::move(receiver)), 88 : receiver_(std::move(receiver)),
89 jpeg_decoder_factory_callback_(jpeg_decoder_factory), 89 jpeg_decoder_factory_callback_(jpeg_decoder_factory),
90 external_jpeg_decoder_initialized_(false), 90 external_jpeg_decoder_initialized_(false),
91 buffer_pool_(std::move(buffer_pool)), 91 buffer_pool_(std::move(buffer_pool)),
92 last_captured_pixel_format_(media::PIXEL_FORMAT_UNKNOWN) {} 92 last_captured_pixel_format_(media::PIXEL_FORMAT_UNKNOWN) {}
93 93
94 VideoCaptureDeviceClient::~VideoCaptureDeviceClient() { 94 VideoCaptureDeviceClient::~VideoCaptureDeviceClient() {
95 // This should be on the platform auxiliary thread since 95 // This should be on the platform auxiliary thread since
96 // |external_jpeg_decoder_| need to be destructed on the same thread as 96 // |external_jpeg_decoder_| need to be destructed on the same thread as
97 // OnIncomingCapturedData. 97 // OnIncomingCapturedData.
98
99 for (int buffer_id : buffer_ids_known_by_receiver_) {
100 receiver_->OnBufferRetired(buffer_id);
101 }
mcasas 2017/01/20 22:41:32 No {} for one-line bodies.
chfremer 2017/01/25 23:45:21 Done.
98 } 102 }
99 103
100 // static 104 // static
101 VideoCaptureDevice::Client::Buffer VideoCaptureDeviceClient::MakeBufferStruct( 105 VideoCaptureDevice::Client::Buffer VideoCaptureDeviceClient::MakeBufferStruct(
102 scoped_refptr<VideoCaptureBufferPool> buffer_pool, 106 scoped_refptr<VideoCaptureBufferPool> buffer_pool,
103 int buffer_id, 107 int buffer_id,
104 int frame_feedback_id) { 108 int frame_feedback_id) {
105 return Buffer( 109 return Buffer(
106 buffer_id, frame_feedback_id, 110 buffer_id, frame_feedback_id,
107 base::MakeUnique<BufferPoolBufferHandleProvider>(buffer_pool, buffer_id), 111 base::MakeUnique<BufferPoolBufferHandleProvider>(buffer_pool, buffer_id),
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 OnIncomingCapturedBuffer(std::move(buffer), output_format, reference_time, 290 OnIncomingCapturedBuffer(std::move(buffer), output_format, reference_time,
287 timestamp); 291 timestamp);
288 } 292 }
289 293
290 media::VideoCaptureDevice::Client::Buffer 294 media::VideoCaptureDevice::Client::Buffer
291 VideoCaptureDeviceClient::ReserveOutputBuffer( 295 VideoCaptureDeviceClient::ReserveOutputBuffer(
292 const gfx::Size& frame_size, 296 const gfx::Size& frame_size,
293 media::VideoPixelFormat pixel_format, 297 media::VideoPixelFormat pixel_format,
294 media::VideoPixelStorage pixel_storage, 298 media::VideoPixelStorage pixel_storage,
295 int frame_feedback_id) { 299 int frame_feedback_id) {
300 DFAKE_SCOPED_RECURSIVE_LOCK(call_from_producer_);
296 DCHECK_GT(frame_size.width(), 0); 301 DCHECK_GT(frame_size.width(), 0);
297 DCHECK_GT(frame_size.height(), 0); 302 DCHECK_GT(frame_size.height(), 0);
298 DCHECK(IsFormatSupported(pixel_format)); 303 DCHECK(IsFormatSupported(pixel_format));
299 304
300 int buffer_id_to_drop = VideoCaptureBufferPool::kInvalidId; 305 int buffer_id_to_drop = VideoCaptureBufferPool::kInvalidId;
301 const int buffer_id = 306 const int buffer_id =
302 buffer_pool_->ReserveForProducer(frame_size, pixel_format, pixel_storage, 307 buffer_pool_->ReserveForProducer(frame_size, pixel_format, pixel_storage,
303 frame_feedback_id, &buffer_id_to_drop); 308 frame_feedback_id, &buffer_id_to_drop);
304 if (buffer_id_to_drop != VideoCaptureBufferPool::kInvalidId) 309 if (buffer_id_to_drop != VideoCaptureBufferPool::kInvalidId) {
305 receiver_->OnBufferDestroyed(buffer_id_to_drop); 310 // Buffer pool has decided to releasea buffer. Notify receiver in case
mcasas 2017/01/20 22:41:32 s/releasea/release a/ s/Buffer pool/|buffer_pool_
chfremer 2017/01/25 23:45:21 Done.
311 // the buffer has already been shared with it.
312 if (buffer_ids_known_by_receiver_.find(buffer_id_to_drop) !=
313 buffer_ids_known_by_receiver_.end()) {
314 buffer_ids_known_by_receiver_.erase(buffer_id_to_drop);
315 receiver_->OnBufferRetired(buffer_id_to_drop);
mcasas 2017/01/20 22:41:32 if (base::ContainsValue(buffer_ids_known_by_receiv
chfremer 2017/01/25 23:45:22 Done. Thanks. That is much nicer indeed.
316 }
317 }
306 if (buffer_id == VideoCaptureBufferPool::kInvalidId) 318 if (buffer_id == VideoCaptureBufferPool::kInvalidId)
307 return Buffer(); 319 return Buffer();
308 return MakeBufferStruct(buffer_pool_, buffer_id, frame_feedback_id); 320 return MakeBufferStruct(buffer_pool_, buffer_id, frame_feedback_id);
309 } 321 }
310 322
311 void VideoCaptureDeviceClient::OnIncomingCapturedBuffer( 323 void VideoCaptureDeviceClient::OnIncomingCapturedBuffer(
312 Buffer buffer, 324 Buffer buffer,
313 const VideoCaptureFormat& format, 325 const VideoCaptureFormat& format,
314 base::TimeTicks reference_time, 326 base::TimeTicks reference_time,
315 base::TimeDelta timestamp) { 327 base::TimeDelta timestamp) {
328 DFAKE_SCOPED_RECURSIVE_LOCK(call_from_producer_);
316 OnIncomingCapturedBufferExt(std::move(buffer), format, reference_time, 329 OnIncomingCapturedBufferExt(std::move(buffer), format, reference_time,
317 timestamp, gfx::Rect(format.frame_size), 330 timestamp, gfx::Rect(format.frame_size),
318 VideoFrameMetadata()); 331 VideoFrameMetadata());
319 } 332 }
320 333
321 void VideoCaptureDeviceClient::OnIncomingCapturedBufferExt( 334 void VideoCaptureDeviceClient::OnIncomingCapturedBufferExt(
322 Buffer buffer, 335 Buffer buffer,
323 const VideoCaptureFormat& format, 336 const VideoCaptureFormat& format,
324 base::TimeTicks reference_time, 337 base::TimeTicks reference_time,
325 base::TimeDelta timestamp, 338 base::TimeDelta timestamp,
326 gfx::Rect visible_rect, 339 gfx::Rect visible_rect,
327 const VideoFrameMetadata& additional_metadata) { 340 const VideoFrameMetadata& additional_metadata) {
341 DFAKE_SCOPED_RECURSIVE_LOCK(call_from_producer_);
342
343 if (buffer_ids_known_by_receiver_.find(buffer.id()) ==
344 buffer_ids_known_by_receiver_.end()) {
345 buffer_ids_known_by_receiver_.insert(buffer.id());
346 }
mcasas 2017/01/20 22:41:32 if (base::ContainsValue(buffer_ids_known_by_receiv
chfremer 2017/01/25 23:45:21 Done.
347
328 auto buffer_access = buffer.handle_provider()->GetHandleForInProcessAccess(); 348 auto buffer_access = buffer.handle_provider()->GetHandleForInProcessAccess();
329 scoped_refptr<media::VideoFrame> frame = 349 scoped_refptr<media::VideoFrame> frame =
330 media::VideoFrame::WrapExternalSharedMemory( 350 media::VideoFrame::WrapExternalSharedMemory(
331 format.pixel_format, // format 351 format.pixel_format, // format
332 format.frame_size, // coded_size 352 format.frame_size, // coded_size
333 visible_rect, // visible_rect 353 visible_rect, // visible_rect
334 format.frame_size, // natural_size 354 format.frame_size, // natural_size
335 buffer_access->data(), // data 355 buffer_access->data(), // data
336 buffer_access->mapped_size(), // data_size 356 buffer_access->mapped_size(), // data_size
337 base::SharedMemory::NULLHandle(), // handle 357 base::SharedMemory::NULLHandle(), // handle
338 0u, // shared_memory_offset 358 0u, // shared_memory_offset
339 timestamp); // timestamp 359 timestamp); // timestamp
340 frame->metadata()->MergeMetadataFrom(&additional_metadata); 360 frame->metadata()->MergeMetadataFrom(&additional_metadata);
341 frame->metadata()->SetDouble(media::VideoFrameMetadata::FRAME_RATE, 361 frame->metadata()->SetDouble(media::VideoFrameMetadata::FRAME_RATE,
342 format.frame_rate); 362 format.frame_rate);
343 frame->metadata()->SetTimeTicks(media::VideoFrameMetadata::REFERENCE_TIME, 363 frame->metadata()->SetTimeTicks(media::VideoFrameMetadata::REFERENCE_TIME,
344 reference_time); 364 reference_time);
345 365
346 receiver_->OnIncomingCapturedVideoFrame(std::move(buffer), std::move(frame)); 366 receiver_->OnIncomingCapturedVideoFrame(std::move(buffer), std::move(frame));
347 } 367 }
348 368
349 media::VideoCaptureDevice::Client::Buffer 369 media::VideoCaptureDevice::Client::Buffer
350 VideoCaptureDeviceClient::ResurrectLastOutputBuffer( 370 VideoCaptureDeviceClient::ResurrectLastOutputBuffer(
351 const gfx::Size& dimensions, 371 const gfx::Size& dimensions,
352 media::VideoPixelFormat format, 372 media::VideoPixelFormat format,
353 media::VideoPixelStorage storage, 373 media::VideoPixelStorage storage,
354 int new_frame_feedback_id) { 374 int new_frame_feedback_id) {
375 DFAKE_SCOPED_RECURSIVE_LOCK(call_from_producer_);
355 const int buffer_id = 376 const int buffer_id =
356 buffer_pool_->ResurrectLastForProducer(dimensions, format, storage); 377 buffer_pool_->ResurrectLastForProducer(dimensions, format, storage);
357 if (buffer_id == VideoCaptureBufferPool::kInvalidId) 378 if (buffer_id == VideoCaptureBufferPool::kInvalidId)
358 return Buffer(); 379 return Buffer();
359 return MakeBufferStruct(buffer_pool_, buffer_id, new_frame_feedback_id); 380 return MakeBufferStruct(buffer_pool_, buffer_id, new_frame_feedback_id);
360 } 381 }
361 382
362 void VideoCaptureDeviceClient::OnError( 383 void VideoCaptureDeviceClient::OnError(
363 const tracked_objects::Location& from_here, 384 const tracked_objects::Location& from_here,
364 const std::string& reason) { 385 const std::string& reason) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 auto buffer_access = buffer.handle_provider()->GetHandleForInProcessAccess(); 446 auto buffer_access = buffer.handle_provider()->GetHandleForInProcessAccess();
426 memcpy(buffer_access->data(), data, length); 447 memcpy(buffer_access->data(), data, length);
427 const VideoCaptureFormat output_format = 448 const VideoCaptureFormat output_format =
428 VideoCaptureFormat(format.frame_size, format.frame_rate, 449 VideoCaptureFormat(format.frame_size, format.frame_rate,
429 media::PIXEL_FORMAT_Y16, media::PIXEL_STORAGE_CPU); 450 media::PIXEL_FORMAT_Y16, media::PIXEL_STORAGE_CPU);
430 OnIncomingCapturedBuffer(std::move(buffer), output_format, reference_time, 451 OnIncomingCapturedBuffer(std::move(buffer), output_format, reference_time,
431 timestamp); 452 timestamp);
432 } 453 }
433 454
434 } // namespace media 455 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698