OLD | NEW |
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 20 matching lines...) Expand all Loading... |
31 namespace { | 31 namespace { |
32 | 32 |
33 bool IsFormatSupported(media::VideoPixelFormat pixel_format) { | 33 bool IsFormatSupported(media::VideoPixelFormat pixel_format) { |
34 return (pixel_format == media::PIXEL_FORMAT_I420 || | 34 return (pixel_format == media::PIXEL_FORMAT_I420 || |
35 pixel_format == media::PIXEL_FORMAT_Y16); | 35 pixel_format == media::PIXEL_FORMAT_Y16); |
36 } | 36 } |
37 } | 37 } |
38 | 38 |
39 namespace media { | 39 namespace media { |
40 | 40 |
41 // Class combining a Client::Buffer interface implementation and a pool buffer | 41 class BufferPoolProducerReservationReleaser |
42 // implementation to guarantee proper cleanup on destruction on our side. | 42 : public VideoCaptureDevice::Client::Buffer::ScopedAccessPermission { |
43 class AutoReleaseBuffer : public media::VideoCaptureDevice::Client::Buffer { | |
44 public: | 43 public: |
45 AutoReleaseBuffer(scoped_refptr<VideoCaptureBufferPool> pool, | 44 BufferPoolProducerReservationReleaser( |
46 int buffer_id, | 45 scoped_refptr<VideoCaptureBufferPool> buffer_pool, |
47 int frame_feedback_id) | 46 int buffer_id) |
48 : pool_(std::move(pool)), | 47 : buffer_pool_(std::move(buffer_pool)), buffer_id_(buffer_id) {} |
49 id_(buffer_id), | 48 |
50 frame_feedback_id_(frame_feedback_id), | 49 ~BufferPoolProducerReservationReleaser() override { |
51 buffer_handle_(pool_->GetBufferHandle(buffer_id)) { | 50 buffer_pool_->RelinquishProducerReservation(buffer_id_); |
52 DCHECK(pool_.get()); | |
53 } | |
54 int id() const override { return id_; } | |
55 int frame_feedback_id() const override { return frame_feedback_id_; } | |
56 gfx::Size dimensions() const override { return buffer_handle_->dimensions(); } | |
57 size_t mapped_size() const override { return buffer_handle_->mapped_size(); } | |
58 void* data(int plane) override { return buffer_handle_->data(plane); } | |
59 #if defined(OS_POSIX) && !defined(OS_MACOSX) | |
60 base::FileDescriptor AsPlatformFile() override { | |
61 return buffer_handle_->AsPlatformFile(); | |
62 } | |
63 #endif | |
64 bool IsBackedByVideoFrame() const override { | |
65 return buffer_handle_->IsBackedByVideoFrame(); | |
66 } | |
67 scoped_refptr<VideoFrame> GetVideoFrame() override { | |
68 return buffer_handle_->GetVideoFrame(); | |
69 } | 51 } |
70 | 52 |
71 private: | 53 private: |
72 ~AutoReleaseBuffer() override { pool_->RelinquishProducerReservation(id_); } | 54 const scoped_refptr<VideoCaptureBufferPool> buffer_pool_; |
| 55 const int buffer_id_; |
| 56 }; |
73 | 57 |
74 const scoped_refptr<VideoCaptureBufferPool> pool_; | 58 class BufferPoolBufferHandleProvider |
75 const int id_; | 59 : public VideoCaptureDevice::Client::Buffer::HandleProvider { |
76 const int frame_feedback_id_; | 60 public: |
77 const std::unique_ptr<VideoCaptureBufferHandle> buffer_handle_; | 61 BufferPoolBufferHandleProvider( |
| 62 scoped_refptr<VideoCaptureBufferPool> buffer_pool, |
| 63 int buffer_id) |
| 64 : buffer_pool_(std::move(buffer_pool)), buffer_id_(buffer_id) {} |
| 65 |
| 66 // Implementation of HandleProvider: |
| 67 mojo::ScopedSharedBufferHandle GetHandleForInterProcessTransit() override { |
| 68 return buffer_pool_->GetHandleForInterProcessTransit(buffer_id_); |
| 69 } |
| 70 base::SharedMemoryHandle GetNonOwnedSharedMemoryHandleForLegacyIPC() |
| 71 override { |
| 72 return buffer_pool_->GetNonOwnedSharedMemoryHandleForLegacyIPC(buffer_id_); |
| 73 } |
| 74 std::unique_ptr<VideoCaptureBufferHandle> GetHandleForInProcessAccess() |
| 75 override { |
| 76 return buffer_pool_->GetHandleForInProcessAccess(buffer_id_); |
| 77 } |
| 78 |
| 79 private: |
| 80 const scoped_refptr<VideoCaptureBufferPool> buffer_pool_; |
| 81 const int buffer_id_; |
78 }; | 82 }; |
79 | 83 |
80 VideoCaptureDeviceClient::VideoCaptureDeviceClient( | 84 VideoCaptureDeviceClient::VideoCaptureDeviceClient( |
81 std::unique_ptr<VideoFrameReceiver> receiver, | 85 std::unique_ptr<VideoFrameReceiver> receiver, |
82 scoped_refptr<VideoCaptureBufferPool> buffer_pool, | 86 scoped_refptr<VideoCaptureBufferPool> buffer_pool, |
83 const VideoCaptureJpegDecoderFactoryCB& jpeg_decoder_factory) | 87 const VideoCaptureJpegDecoderFactoryCB& jpeg_decoder_factory) |
84 : receiver_(std::move(receiver)), | 88 : receiver_(std::move(receiver)), |
85 jpeg_decoder_factory_callback_(jpeg_decoder_factory), | 89 jpeg_decoder_factory_callback_(jpeg_decoder_factory), |
86 external_jpeg_decoder_initialized_(false), | 90 external_jpeg_decoder_initialized_(false), |
87 buffer_pool_(std::move(buffer_pool)), | 91 buffer_pool_(std::move(buffer_pool)), |
88 last_captured_pixel_format_(media::PIXEL_FORMAT_UNKNOWN) {} | 92 last_captured_pixel_format_(media::PIXEL_FORMAT_UNKNOWN) {} |
89 | 93 |
90 VideoCaptureDeviceClient::~VideoCaptureDeviceClient() { | 94 VideoCaptureDeviceClient::~VideoCaptureDeviceClient() { |
91 // This should be on the platform auxiliary thread since | 95 // This should be on the platform auxiliary thread since |
92 // |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 |
93 // OnIncomingCapturedData. | 97 // OnIncomingCapturedData. |
94 } | 98 } |
95 | 99 |
| 100 // static |
| 101 VideoCaptureDevice::Client::Buffer VideoCaptureDeviceClient::MakeBufferStruct( |
| 102 scoped_refptr<VideoCaptureBufferPool> buffer_pool, |
| 103 int buffer_id, |
| 104 int frame_feedback_id) { |
| 105 return Buffer( |
| 106 buffer_id, frame_feedback_id, |
| 107 base::MakeUnique<BufferPoolBufferHandleProvider>(buffer_pool, buffer_id), |
| 108 base::MakeUnique<BufferPoolProducerReservationReleaser>(buffer_pool, |
| 109 buffer_id)); |
| 110 } |
| 111 |
96 void VideoCaptureDeviceClient::OnIncomingCapturedData( | 112 void VideoCaptureDeviceClient::OnIncomingCapturedData( |
97 const uint8_t* data, | 113 const uint8_t* data, |
98 int length, | 114 int length, |
99 const VideoCaptureFormat& format, | 115 const VideoCaptureFormat& format, |
100 int rotation, | 116 int rotation, |
101 base::TimeTicks reference_time, | 117 base::TimeTicks reference_time, |
102 base::TimeDelta timestamp, | 118 base::TimeDelta timestamp, |
103 int frame_feedback_id) { | 119 int frame_feedback_id) { |
104 TRACE_EVENT0("video", "VideoCaptureDeviceClient::OnIncomingCapturedData"); | 120 TRACE_EVENT0("video", "VideoCaptureDeviceClient::OnIncomingCapturedData"); |
105 DCHECK_EQ(media::PIXEL_STORAGE_CPU, format.pixel_storage); | 121 DCHECK_EQ(media::PIXEL_STORAGE_CPU, format.pixel_storage); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 << rotation; | 157 << rotation; |
142 libyuv::RotationMode rotation_mode = libyuv::kRotate0; | 158 libyuv::RotationMode rotation_mode = libyuv::kRotate0; |
143 if (rotation == 90) | 159 if (rotation == 90) |
144 rotation_mode = libyuv::kRotate90; | 160 rotation_mode = libyuv::kRotate90; |
145 else if (rotation == 180) | 161 else if (rotation == 180) |
146 rotation_mode = libyuv::kRotate180; | 162 rotation_mode = libyuv::kRotate180; |
147 else if (rotation == 270) | 163 else if (rotation == 270) |
148 rotation_mode = libyuv::kRotate270; | 164 rotation_mode = libyuv::kRotate270; |
149 | 165 |
150 const gfx::Size dimensions(destination_width, destination_height); | 166 const gfx::Size dimensions(destination_width, destination_height); |
151 uint8_t *y_plane_data, *u_plane_data, *v_plane_data; | 167 Buffer buffer = |
152 std::unique_ptr<Buffer> buffer(ReserveI420OutputBuffer( | 168 ReserveOutputBuffer(dimensions, media::PIXEL_FORMAT_I420, |
153 dimensions, media::PIXEL_STORAGE_CPU, frame_feedback_id, &y_plane_data, | 169 media::PIXEL_STORAGE_CPU, frame_feedback_id); |
154 &u_plane_data, &v_plane_data)); | |
155 #if DCHECK_IS_ON() | 170 #if DCHECK_IS_ON() |
156 dropped_frame_counter_ = buffer.get() ? 0 : dropped_frame_counter_ + 1; | 171 dropped_frame_counter_ = buffer.is_valid() ? 0 : dropped_frame_counter_ + 1; |
157 if (dropped_frame_counter_ >= kMaxDroppedFrames) | 172 if (dropped_frame_counter_ >= kMaxDroppedFrames) |
158 OnError(FROM_HERE, "Too many frames dropped"); | 173 OnError(FROM_HERE, "Too many frames dropped"); |
159 #endif | 174 #endif |
160 // Failed to reserve I420 output buffer, so drop the frame. | 175 // Failed to reserve I420 output buffer, so drop the frame. |
161 if (!buffer.get()) | 176 if (!buffer.is_valid()) |
162 return; | 177 return; |
163 | 178 |
| 179 auto buffer_access = buffer.handle_provider()->GetHandleForInProcessAccess(); |
| 180 uint8_t *y_plane_data, *u_plane_data, *v_plane_data; |
| 181 InitializeI420PlanePointers(dimensions, buffer_access->data(), &y_plane_data, |
| 182 &u_plane_data, &v_plane_data); |
| 183 |
164 const int yplane_stride = dimensions.width(); | 184 const int yplane_stride = dimensions.width(); |
165 const int uv_plane_stride = yplane_stride / 2; | 185 const int uv_plane_stride = yplane_stride / 2; |
166 int crop_x = 0; | 186 int crop_x = 0; |
167 int crop_y = 0; | 187 int crop_y = 0; |
168 libyuv::FourCC origin_colorspace = libyuv::FOURCC_ANY; | 188 libyuv::FourCC origin_colorspace = libyuv::FOURCC_ANY; |
169 | 189 |
170 bool flip = false; | 190 bool flip = false; |
171 switch (format.pixel_format) { | 191 switch (format.pixel_format) { |
172 case media::PIXEL_FORMAT_UNKNOWN: // Color format not set. | 192 case media::PIXEL_FORMAT_UNKNOWN: // Color format not set. |
173 break; | 193 break; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 return; | 280 return; |
261 } | 281 } |
262 | 282 |
263 const VideoCaptureFormat output_format = | 283 const VideoCaptureFormat output_format = |
264 VideoCaptureFormat(dimensions, format.frame_rate, | 284 VideoCaptureFormat(dimensions, format.frame_rate, |
265 media::PIXEL_FORMAT_I420, media::PIXEL_STORAGE_CPU); | 285 media::PIXEL_FORMAT_I420, media::PIXEL_STORAGE_CPU); |
266 OnIncomingCapturedBuffer(std::move(buffer), output_format, reference_time, | 286 OnIncomingCapturedBuffer(std::move(buffer), output_format, reference_time, |
267 timestamp); | 287 timestamp); |
268 } | 288 } |
269 | 289 |
270 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> | 290 media::VideoCaptureDevice::Client::Buffer |
271 VideoCaptureDeviceClient::ReserveOutputBuffer( | 291 VideoCaptureDeviceClient::ReserveOutputBuffer( |
272 const gfx::Size& frame_size, | 292 const gfx::Size& frame_size, |
273 media::VideoPixelFormat pixel_format, | 293 media::VideoPixelFormat pixel_format, |
274 media::VideoPixelStorage pixel_storage, | 294 media::VideoPixelStorage pixel_storage, |
275 int frame_feedback_id) { | 295 int frame_feedback_id) { |
276 DCHECK_GT(frame_size.width(), 0); | 296 DCHECK_GT(frame_size.width(), 0); |
277 DCHECK_GT(frame_size.height(), 0); | 297 DCHECK_GT(frame_size.height(), 0); |
278 DCHECK(IsFormatSupported(pixel_format)); | 298 DCHECK(IsFormatSupported(pixel_format)); |
279 | 299 |
280 // TODO(mcasas): For PIXEL_STORAGE_GPUMEMORYBUFFER, find a way to indicate if | |
281 // it's a ShMem GMB or a DmaBuf GMB. | |
282 int buffer_id_to_drop = VideoCaptureBufferPool::kInvalidId; | 300 int buffer_id_to_drop = VideoCaptureBufferPool::kInvalidId; |
283 const int buffer_id = | 301 const int buffer_id = |
284 buffer_pool_->ReserveForProducer(frame_size, pixel_format, pixel_storage, | 302 buffer_pool_->ReserveForProducer(frame_size, pixel_format, pixel_storage, |
285 frame_feedback_id, &buffer_id_to_drop); | 303 frame_feedback_id, &buffer_id_to_drop); |
286 if (buffer_id_to_drop != VideoCaptureBufferPool::kInvalidId) | 304 if (buffer_id_to_drop != VideoCaptureBufferPool::kInvalidId) |
287 receiver_->OnBufferDestroyed(buffer_id_to_drop); | 305 receiver_->OnBufferDestroyed(buffer_id_to_drop); |
288 if (buffer_id == VideoCaptureBufferPool::kInvalidId) | 306 if (buffer_id == VideoCaptureBufferPool::kInvalidId) |
289 return nullptr; | 307 return Buffer(); |
290 return base::WrapUnique<Buffer>( | 308 return MakeBufferStruct(buffer_pool_, buffer_id, frame_feedback_id); |
291 new AutoReleaseBuffer(buffer_pool_, buffer_id, frame_feedback_id)); | |
292 } | 309 } |
293 | 310 |
294 void VideoCaptureDeviceClient::OnIncomingCapturedBuffer( | 311 void VideoCaptureDeviceClient::OnIncomingCapturedBuffer( |
295 std::unique_ptr<Buffer> buffer, | 312 Buffer buffer, |
296 const VideoCaptureFormat& format, | 313 const VideoCaptureFormat& format, |
297 base::TimeTicks reference_time, | 314 base::TimeTicks reference_time, |
298 base::TimeDelta timestamp) { | 315 base::TimeDelta timestamp) { |
299 OnIncomingCapturedBufferExt(std::move(buffer), format, reference_time, | 316 OnIncomingCapturedBufferExt(std::move(buffer), format, reference_time, |
300 timestamp, gfx::Rect(format.frame_size), | 317 timestamp, gfx::Rect(format.frame_size), |
301 VideoFrameMetadata()); | 318 VideoFrameMetadata()); |
302 } | 319 } |
303 | 320 |
304 void VideoCaptureDeviceClient::OnIncomingCapturedBufferExt( | 321 void VideoCaptureDeviceClient::OnIncomingCapturedBufferExt( |
305 std::unique_ptr<Buffer> buffer, | 322 Buffer buffer, |
306 const VideoCaptureFormat& format, | 323 const VideoCaptureFormat& format, |
307 base::TimeTicks reference_time, | 324 base::TimeTicks reference_time, |
308 base::TimeDelta timestamp, | 325 base::TimeDelta timestamp, |
309 gfx::Rect visible_rect, | 326 gfx::Rect visible_rect, |
310 const VideoFrameMetadata& additional_metadata) { | 327 const VideoFrameMetadata& additional_metadata) { |
| 328 auto buffer_access = buffer.handle_provider()->GetHandleForInProcessAccess(); |
311 scoped_refptr<media::VideoFrame> frame = | 329 scoped_refptr<media::VideoFrame> frame = |
312 media::VideoFrame::WrapExternalSharedMemory( | 330 media::VideoFrame::WrapExternalSharedMemory( |
313 format.pixel_format, // format | 331 format.pixel_format, // format |
314 format.frame_size, // coded_size | 332 format.frame_size, // coded_size |
315 visible_rect, // visible_rect | 333 visible_rect, // visible_rect |
316 format.frame_size, // natural_size | 334 format.frame_size, // natural_size |
317 static_cast<uint8_t*>(buffer->data()), // data | 335 buffer_access->data(), // data |
318 buffer->mapped_size(), // data_size | 336 buffer_access->mapped_size(), // data_size |
319 base::SharedMemory::NULLHandle(), // handle | 337 base::SharedMemory::NULLHandle(), // handle |
320 0u, // shared_memory_offset | 338 0u, // shared_memory_offset |
321 timestamp); // timestamp | 339 timestamp); // timestamp |
322 frame->metadata()->MergeMetadataFrom(&additional_metadata); | 340 frame->metadata()->MergeMetadataFrom(&additional_metadata); |
323 frame->metadata()->SetDouble(media::VideoFrameMetadata::FRAME_RATE, | 341 frame->metadata()->SetDouble(media::VideoFrameMetadata::FRAME_RATE, |
324 format.frame_rate); | 342 format.frame_rate); |
325 frame->metadata()->SetTimeTicks(media::VideoFrameMetadata::REFERENCE_TIME, | 343 frame->metadata()->SetTimeTicks(media::VideoFrameMetadata::REFERENCE_TIME, |
326 reference_time); | 344 reference_time); |
327 | 345 |
328 receiver_->OnIncomingCapturedVideoFrame(std::move(buffer), std::move(frame)); | 346 receiver_->OnIncomingCapturedVideoFrame(std::move(buffer), std::move(frame)); |
329 } | 347 } |
330 | 348 |
331 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> | 349 media::VideoCaptureDevice::Client::Buffer |
332 VideoCaptureDeviceClient::ResurrectLastOutputBuffer( | 350 VideoCaptureDeviceClient::ResurrectLastOutputBuffer( |
333 const gfx::Size& dimensions, | 351 const gfx::Size& dimensions, |
334 media::VideoPixelFormat format, | 352 media::VideoPixelFormat format, |
335 media::VideoPixelStorage storage, | 353 media::VideoPixelStorage storage, |
336 int new_frame_feedback_id) { | 354 int new_frame_feedback_id) { |
337 const int buffer_id = | 355 const int buffer_id = |
338 buffer_pool_->ResurrectLastForProducer(dimensions, format, storage); | 356 buffer_pool_->ResurrectLastForProducer(dimensions, format, storage); |
339 if (buffer_id == VideoCaptureBufferPool::kInvalidId) | 357 if (buffer_id == VideoCaptureBufferPool::kInvalidId) |
340 return nullptr; | 358 return Buffer(); |
341 return base::WrapUnique<Buffer>( | 359 return MakeBufferStruct(buffer_pool_, buffer_id, new_frame_feedback_id); |
342 new AutoReleaseBuffer(buffer_pool_, buffer_id, new_frame_feedback_id)); | |
343 } | 360 } |
344 | 361 |
345 void VideoCaptureDeviceClient::OnError( | 362 void VideoCaptureDeviceClient::OnError( |
346 const tracked_objects::Location& from_here, | 363 const tracked_objects::Location& from_here, |
347 const std::string& reason) { | 364 const std::string& reason) { |
348 const std::string log_message = base::StringPrintf( | 365 const std::string log_message = base::StringPrintf( |
349 "error@ %s, %s, OS message: %s", from_here.ToString().c_str(), | 366 "error@ %s, %s, OS message: %s", from_here.ToString().c_str(), |
350 reason.c_str(), | 367 reason.c_str(), |
351 logging::SystemErrorCodeToString(logging::GetLastSystemErrorCode()) | 368 logging::SystemErrorCodeToString(logging::GetLastSystemErrorCode()) |
352 .c_str()); | 369 .c_str()); |
353 DLOG(ERROR) << log_message; | 370 DLOG(ERROR) << log_message; |
354 OnLog(log_message); | 371 OnLog(log_message); |
355 receiver_->OnError(); | 372 receiver_->OnError(); |
356 } | 373 } |
357 | 374 |
358 void VideoCaptureDeviceClient::OnLog(const std::string& message) { | 375 void VideoCaptureDeviceClient::OnLog(const std::string& message) { |
359 receiver_->OnLog(message); | 376 receiver_->OnLog(message); |
360 } | 377 } |
361 | 378 |
362 double VideoCaptureDeviceClient::GetBufferPoolUtilization() const { | 379 double VideoCaptureDeviceClient::GetBufferPoolUtilization() const { |
363 return buffer_pool_->GetBufferPoolUtilization(); | 380 return buffer_pool_->GetBufferPoolUtilization(); |
364 } | 381 } |
365 | 382 |
366 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> | 383 void VideoCaptureDeviceClient::InitializeI420PlanePointers( |
367 VideoCaptureDeviceClient::ReserveI420OutputBuffer( | |
368 const gfx::Size& dimensions, | 384 const gfx::Size& dimensions, |
369 media::VideoPixelStorage storage, | 385 uint8_t* const data, |
370 int frame_feedback_id, | |
371 uint8_t** y_plane_data, | 386 uint8_t** y_plane_data, |
372 uint8_t** u_plane_data, | 387 uint8_t** u_plane_data, |
373 uint8_t** v_plane_data) { | 388 uint8_t** v_plane_data) { |
374 DCHECK(storage == media::PIXEL_STORAGE_CPU); | |
375 DCHECK(dimensions.height()); | 389 DCHECK(dimensions.height()); |
376 DCHECK(dimensions.width()); | 390 DCHECK(dimensions.width()); |
377 | 391 |
378 const media::VideoPixelFormat format = media::PIXEL_FORMAT_I420; | 392 const media::VideoPixelFormat format = media::PIXEL_FORMAT_I420; |
379 std::unique_ptr<Buffer> buffer(ReserveOutputBuffer( | |
380 dimensions, media::PIXEL_FORMAT_I420, storage, frame_feedback_id)); | |
381 if (!buffer) | |
382 return std::unique_ptr<Buffer>(); | |
383 // TODO(emircan): See http://crbug.com/521068, move this pointer | 393 // TODO(emircan): See http://crbug.com/521068, move this pointer |
384 // arithmetic inside Buffer::data() when this bug is resolved. | 394 // arithmetic inside Buffer::data() when this bug is resolved. |
385 *y_plane_data = reinterpret_cast<uint8_t*>(buffer->data()); | 395 *y_plane_data = data; |
386 *u_plane_data = | 396 *u_plane_data = |
387 *y_plane_data + | 397 *y_plane_data + |
388 VideoFrame::PlaneSize(format, VideoFrame::kYPlane, dimensions).GetArea(); | 398 VideoFrame::PlaneSize(format, VideoFrame::kYPlane, dimensions).GetArea(); |
389 *v_plane_data = | 399 *v_plane_data = |
390 *u_plane_data + | 400 *u_plane_data + |
391 VideoFrame::PlaneSize(format, VideoFrame::kUPlane, dimensions).GetArea(); | 401 VideoFrame::PlaneSize(format, VideoFrame::kUPlane, dimensions).GetArea(); |
392 return buffer; | |
393 } | 402 } |
394 | 403 |
395 void VideoCaptureDeviceClient::OnIncomingCapturedY16Data( | 404 void VideoCaptureDeviceClient::OnIncomingCapturedY16Data( |
396 const uint8_t* data, | 405 const uint8_t* data, |
397 int length, | 406 int length, |
398 const VideoCaptureFormat& format, | 407 const VideoCaptureFormat& format, |
399 base::TimeTicks reference_time, | 408 base::TimeTicks reference_time, |
400 base::TimeDelta timestamp, | 409 base::TimeDelta timestamp, |
401 int frame_feedback_id) { | 410 int frame_feedback_id) { |
402 std::unique_ptr<Buffer> buffer( | 411 Buffer buffer = |
403 ReserveOutputBuffer(format.frame_size, media::PIXEL_FORMAT_Y16, | 412 ReserveOutputBuffer(format.frame_size, media::PIXEL_FORMAT_Y16, |
404 media::PIXEL_STORAGE_CPU, frame_feedback_id)); | 413 media::PIXEL_STORAGE_CPU, frame_feedback_id); |
405 // The input |length| can be greater than the required buffer size because of | 414 // The input |length| can be greater than the required buffer size because of |
406 // paddings and/or alignments, but it cannot be smaller. | 415 // paddings and/or alignments, but it cannot be smaller. |
407 DCHECK_GE(static_cast<size_t>(length), format.ImageAllocationSize()); | 416 DCHECK_GE(static_cast<size_t>(length), format.ImageAllocationSize()); |
408 #if DCHECK_IS_ON() | 417 #if DCHECK_IS_ON() |
409 dropped_frame_counter_ = buffer.get() ? 0 : dropped_frame_counter_ + 1; | 418 dropped_frame_counter_ = buffer.is_valid() ? 0 : dropped_frame_counter_ + 1; |
410 if (dropped_frame_counter_ >= kMaxDroppedFrames) | 419 if (dropped_frame_counter_ >= kMaxDroppedFrames) |
411 OnError(FROM_HERE, "Too many frames dropped"); | 420 OnError(FROM_HERE, "Too many frames dropped"); |
412 #endif | 421 #endif |
413 // Failed to reserve output buffer, so drop the frame. | 422 // Failed to reserve output buffer, so drop the frame. |
414 if (!buffer.get()) | 423 if (!buffer.is_valid()) |
415 return; | 424 return; |
416 memcpy(buffer->data(), data, length); | 425 auto buffer_access = buffer.handle_provider()->GetHandleForInProcessAccess(); |
| 426 memcpy(buffer_access->data(), data, length); |
417 const VideoCaptureFormat output_format = | 427 const VideoCaptureFormat output_format = |
418 VideoCaptureFormat(format.frame_size, format.frame_rate, | 428 VideoCaptureFormat(format.frame_size, format.frame_rate, |
419 media::PIXEL_FORMAT_Y16, media::PIXEL_STORAGE_CPU); | 429 media::PIXEL_FORMAT_Y16, media::PIXEL_STORAGE_CPU); |
420 OnIncomingCapturedBuffer(std::move(buffer), output_format, reference_time, | 430 OnIncomingCapturedBuffer(std::move(buffer), output_format, reference_time, |
421 timestamp); | 431 timestamp); |
422 } | 432 } |
423 | 433 |
424 } // namespace media | 434 } // namespace media |
OLD | NEW |