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

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

Issue 2735083002: [Mojo Video Capture] Add test coverage for accelerated jpeg decoding (Closed)
Patch Set: Removed OnStoppedUsingGpuDecode() event. Created 3 years, 9 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 const int buffer_id_; 96 const int buffer_id_;
97 }; 97 };
98 98
99 VideoCaptureDeviceClient::VideoCaptureDeviceClient( 99 VideoCaptureDeviceClient::VideoCaptureDeviceClient(
100 std::unique_ptr<VideoFrameReceiver> receiver, 100 std::unique_ptr<VideoFrameReceiver> receiver,
101 scoped_refptr<VideoCaptureBufferPool> buffer_pool, 101 scoped_refptr<VideoCaptureBufferPool> buffer_pool,
102 const VideoCaptureJpegDecoderFactoryCB& jpeg_decoder_factory) 102 const VideoCaptureJpegDecoderFactoryCB& jpeg_decoder_factory)
103 : receiver_(std::move(receiver)), 103 : receiver_(std::move(receiver)),
104 jpeg_decoder_factory_callback_(jpeg_decoder_factory), 104 jpeg_decoder_factory_callback_(jpeg_decoder_factory),
105 external_jpeg_decoder_initialized_(false), 105 external_jpeg_decoder_initialized_(false),
106 using_external_jpeg_decoder_(false),
106 buffer_pool_(std::move(buffer_pool)), 107 buffer_pool_(std::move(buffer_pool)),
107 last_captured_pixel_format_(media::PIXEL_FORMAT_UNKNOWN) {} 108 last_captured_pixel_format_(media::PIXEL_FORMAT_UNKNOWN) {}
108 109
109 VideoCaptureDeviceClient::~VideoCaptureDeviceClient() { 110 VideoCaptureDeviceClient::~VideoCaptureDeviceClient() {
110 // This should be on the platform auxiliary thread since 111 // This should be on the platform auxiliary thread since
111 // |external_jpeg_decoder_| need to be destructed on the same thread as 112 // |external_jpeg_decoder_| need to be destructed on the same thread as
112 // OnIncomingCapturedData. 113 // OnIncomingCapturedData.
113 114
114 for (int buffer_id : buffer_ids_known_by_receiver_) 115 for (int buffer_id : buffer_ids_known_by_receiver_)
115 receiver_->OnBufferRetired(buffer_id); 116 receiver_->OnBufferRetired(buffer_id);
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 DCHECK_GE(static_cast<size_t>(length), format.ImageAllocationSize()); 275 DCHECK_GE(static_cast<size_t>(length), format.ImageAllocationSize());
275 276
276 if (external_jpeg_decoder_) { 277 if (external_jpeg_decoder_) {
277 const VideoCaptureJpegDecoder::STATUS status = 278 const VideoCaptureJpegDecoder::STATUS status =
278 external_jpeg_decoder_->GetStatus(); 279 external_jpeg_decoder_->GetStatus();
279 if (status == VideoCaptureJpegDecoder::FAILED) { 280 if (status == VideoCaptureJpegDecoder::FAILED) {
280 external_jpeg_decoder_.reset(); 281 external_jpeg_decoder_.reset();
281 } else if (status == VideoCaptureJpegDecoder::INIT_PASSED && 282 } else if (status == VideoCaptureJpegDecoder::INIT_PASSED &&
282 format.pixel_format == media::PIXEL_FORMAT_MJPEG && 283 format.pixel_format == media::PIXEL_FORMAT_MJPEG &&
283 rotation == 0 && !flip) { 284 rotation == 0 && !flip) {
285 OnUsingExternalJpegDecoder();
284 external_jpeg_decoder_->DecodeCapturedData( 286 external_jpeg_decoder_->DecodeCapturedData(
285 data, length, format, reference_time, timestamp, std::move(buffer)); 287 data, length, format, reference_time, timestamp, std::move(buffer));
286 return; 288 return;
287 } 289 }
288 } 290 }
289 291
290 if (libyuv::ConvertToI420( 292 if (libyuv::ConvertToI420(
291 data, length, y_plane_data, yplane_stride, u_plane_data, 293 data, length, y_plane_data, yplane_stride, u_plane_data,
292 uv_plane_stride, v_plane_data, uv_plane_stride, crop_x, crop_y, 294 uv_plane_stride, v_plane_data, uv_plane_stride, crop_x, crop_y,
293 format.frame_size.width(), 295 format.frame_size.width(),
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 if (entry_iter != buffer_ids_known_by_receiver_.end()) { 331 if (entry_iter != buffer_ids_known_by_receiver_.end()) {
330 buffer_ids_known_by_receiver_.erase(entry_iter); 332 buffer_ids_known_by_receiver_.erase(entry_iter);
331 receiver_->OnBufferRetired(buffer_id_to_drop); 333 receiver_->OnBufferRetired(buffer_id_to_drop);
332 } 334 }
333 } 335 }
334 if (buffer_id == VideoCaptureBufferPool::kInvalidId) 336 if (buffer_id == VideoCaptureBufferPool::kInvalidId)
335 return Buffer(); 337 return Buffer();
336 338
337 if (!base::ContainsValue(buffer_ids_known_by_receiver_, buffer_id)) { 339 if (!base::ContainsValue(buffer_ids_known_by_receiver_, buffer_id)) {
338 receiver_->OnNewBufferHandle( 340 receiver_->OnNewBufferHandle(
339 buffer_id, 341 buffer_id, base::MakeUnique<BufferPoolBufferHandleProvider>(
340 base::MakeUnique<BufferPoolBufferHandleProvider>(buffer_pool_, 342 buffer_pool_, buffer_id));
341 buffer_id));
342 buffer_ids_known_by_receiver_.push_back(buffer_id); 343 buffer_ids_known_by_receiver_.push_back(buffer_id);
343 } 344 }
344 345
345 return MakeBufferStruct(buffer_pool_, buffer_id, frame_feedback_id); 346 return MakeBufferStruct(buffer_pool_, buffer_id, frame_feedback_id);
346 } 347 }
347 348
348 void VideoCaptureDeviceClient::OnIncomingCapturedBuffer( 349 void VideoCaptureDeviceClient::OnIncomingCapturedBuffer(
349 Buffer buffer, 350 Buffer buffer,
350 const VideoCaptureFormat& format, 351 const VideoCaptureFormat& format,
351 base::TimeTicks reference_time, 352 base::TimeTicks reference_time,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 } 420 }
420 421
421 void VideoCaptureDeviceClient::OnStarted() { 422 void VideoCaptureDeviceClient::OnStarted() {
422 receiver_->OnStarted(); 423 receiver_->OnStarted();
423 } 424 }
424 425
425 double VideoCaptureDeviceClient::GetBufferPoolUtilization() const { 426 double VideoCaptureDeviceClient::GetBufferPoolUtilization() const {
426 return buffer_pool_->GetBufferPoolUtilization(); 427 return buffer_pool_->GetBufferPoolUtilization();
427 } 428 }
428 429
430 void VideoCaptureDeviceClient::OnUsingExternalJpegDecoder() {
431 if (using_external_jpeg_decoder_)
432 return;
433 using_external_jpeg_decoder_ = true;
434 receiver_->OnStartedUsingGpuDecode();
435 }
436
429 void VideoCaptureDeviceClient::InitializeI420PlanePointers( 437 void VideoCaptureDeviceClient::InitializeI420PlanePointers(
430 const gfx::Size& dimensions, 438 const gfx::Size& dimensions,
431 uint8_t* const data, 439 uint8_t* const data,
432 uint8_t** y_plane_data, 440 uint8_t** y_plane_data,
433 uint8_t** u_plane_data, 441 uint8_t** u_plane_data,
434 uint8_t** v_plane_data) { 442 uint8_t** v_plane_data) {
435 DCHECK(dimensions.height()); 443 DCHECK(dimensions.height());
436 DCHECK(dimensions.width()); 444 DCHECK(dimensions.width());
437 445
438 const media::VideoPixelFormat format = media::PIXEL_FORMAT_I420; 446 const media::VideoPixelFormat format = media::PIXEL_FORMAT_I420;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 auto buffer_access = buffer.handle_provider->GetHandleForInProcessAccess(); 479 auto buffer_access = buffer.handle_provider->GetHandleForInProcessAccess();
472 memcpy(buffer_access->data(), data, length); 480 memcpy(buffer_access->data(), data, length);
473 const VideoCaptureFormat output_format = 481 const VideoCaptureFormat output_format =
474 VideoCaptureFormat(format.frame_size, format.frame_rate, 482 VideoCaptureFormat(format.frame_size, format.frame_rate,
475 media::PIXEL_FORMAT_Y16, media::PIXEL_STORAGE_CPU); 483 media::PIXEL_FORMAT_Y16, media::PIXEL_STORAGE_CPU);
476 OnIncomingCapturedBuffer(std::move(buffer), output_format, reference_time, 484 OnIncomingCapturedBuffer(std::move(buffer), output_format, reference_time,
477 timestamp); 485 timestamp);
478 } 486 }
479 487
480 } // namespace media 488 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698