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

Unified 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: Added tests and fixed a bug uncovered by the tests. 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 side-by-side diff with in-line comments
Download patch
Index: media/capture/video/video_capture_device_client.cc
diff --git a/media/capture/video/video_capture_device_client.cc b/media/capture/video/video_capture_device_client.cc
index 9d3b70661fa25ba460c9449aa3fe64d166e67ca6..3ab0e1dd128f9d907f141b978341aebc5d61e79f 100644
--- a/media/capture/video/video_capture_device_client.cc
+++ b/media/capture/video/video_capture_device_client.cc
@@ -95,6 +95,9 @@ VideoCaptureDeviceClient::~VideoCaptureDeviceClient() {
// This should be on the platform auxiliary thread since
// |external_jpeg_decoder_| need to be destructed on the same thread as
// OnIncomingCapturedData.
+
+ for (int buffer_id : buffer_ids_known_by_receiver_)
+ receiver_->OnBufferRetired(buffer_id);
}
// static
@@ -293,6 +296,7 @@ VideoCaptureDeviceClient::ReserveOutputBuffer(
media::VideoPixelFormat pixel_format,
media::VideoPixelStorage pixel_storage,
int frame_feedback_id) {
+ DFAKE_SCOPED_RECURSIVE_LOCK(call_from_producer_);
DCHECK_GT(frame_size.width(), 0);
DCHECK_GT(frame_size.height(), 0);
DCHECK(IsFormatSupported(pixel_format));
@@ -301,8 +305,14 @@ VideoCaptureDeviceClient::ReserveOutputBuffer(
const int buffer_id =
buffer_pool_->ReserveForProducer(frame_size, pixel_format, pixel_storage,
frame_feedback_id, &buffer_id_to_drop);
- if (buffer_id_to_drop != VideoCaptureBufferPool::kInvalidId)
- receiver_->OnBufferDestroyed(buffer_id_to_drop);
+ if (buffer_id_to_drop != VideoCaptureBufferPool::kInvalidId) {
+ // |buffer_pool_| has decided to release a buffer. Notify receiver in case
+ // the buffer has already been shared with it.
+ if (base::ContainsValue(buffer_ids_known_by_receiver_, buffer_id_to_drop)) {
+ buffer_ids_known_by_receiver_.erase(buffer_id_to_drop);
+ receiver_->OnBufferRetired(buffer_id_to_drop);
+ }
+ }
if (buffer_id == VideoCaptureBufferPool::kInvalidId)
return Buffer();
return MakeBufferStruct(buffer_pool_, buffer_id, frame_feedback_id);
@@ -313,6 +323,7 @@ void VideoCaptureDeviceClient::OnIncomingCapturedBuffer(
const VideoCaptureFormat& format,
base::TimeTicks reference_time,
base::TimeDelta timestamp) {
+ DFAKE_SCOPED_RECURSIVE_LOCK(call_from_producer_);
OnIncomingCapturedBufferExt(std::move(buffer), format, reference_time,
timestamp, gfx::Rect(format.frame_size),
VideoFrameMetadata());
@@ -325,6 +336,11 @@ void VideoCaptureDeviceClient::OnIncomingCapturedBufferExt(
base::TimeDelta timestamp,
gfx::Rect visible_rect,
const VideoFrameMetadata& additional_metadata) {
+ DFAKE_SCOPED_RECURSIVE_LOCK(call_from_producer_);
+
+ if (!base::ContainsValue(buffer_ids_known_by_receiver_, buffer.id()))
+ buffer_ids_known_by_receiver_.insert(buffer.id());
+
auto buffer_access = buffer.handle_provider()->GetHandleForInProcessAccess();
scoped_refptr<media::VideoFrame> frame =
media::VideoFrame::WrapExternalSharedMemory(
@@ -352,6 +368,7 @@ VideoCaptureDeviceClient::ResurrectLastOutputBuffer(
media::VideoPixelFormat format,
media::VideoPixelStorage storage,
int new_frame_feedback_id) {
+ DFAKE_SCOPED_RECURSIVE_LOCK(call_from_producer_);
const int buffer_id =
buffer_pool_->ResurrectLastForProducer(dimensions, format, storage);
if (buffer_id == VideoCaptureBufferPool::kInvalidId)

Powered by Google App Engine
This is Rietveld 408576698