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

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: 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 }
291 OnNotUsingExternalJpegDecoder();
289 292
290 if (libyuv::ConvertToI420( 293 if (libyuv::ConvertToI420(
291 data, length, y_plane_data, yplane_stride, u_plane_data, 294 data, length, y_plane_data, yplane_stride, u_plane_data,
292 uv_plane_stride, v_plane_data, uv_plane_stride, crop_x, crop_y, 295 uv_plane_stride, v_plane_data, uv_plane_stride, crop_x, crop_y,
293 format.frame_size.width(), 296 format.frame_size.width(),
294 (flip ? -1 : 1) * format.frame_size.height(), new_unrotated_width, 297 (flip ? -1 : 1) * format.frame_size.height(), new_unrotated_width,
295 new_unrotated_height, rotation_mode, origin_colorspace) != 0) { 298 new_unrotated_height, rotation_mode, origin_colorspace) != 0) {
296 DLOG(WARNING) << "Failed to convert buffer's pixel format to I420 from " 299 DLOG(WARNING) << "Failed to convert buffer's pixel format to I420 from "
297 << media::VideoPixelFormatToString(format.pixel_format); 300 << media::VideoPixelFormatToString(format.pixel_format);
298 return; 301 return;
(...skipping 30 matching lines...) Expand all
329 if (entry_iter != buffer_ids_known_by_receiver_.end()) { 332 if (entry_iter != buffer_ids_known_by_receiver_.end()) {
330 buffer_ids_known_by_receiver_.erase(entry_iter); 333 buffer_ids_known_by_receiver_.erase(entry_iter);
331 receiver_->OnBufferRetired(buffer_id_to_drop); 334 receiver_->OnBufferRetired(buffer_id_to_drop);
332 } 335 }
333 } 336 }
334 if (buffer_id == VideoCaptureBufferPool::kInvalidId) 337 if (buffer_id == VideoCaptureBufferPool::kInvalidId)
335 return Buffer(); 338 return Buffer();
336 339
337 if (!base::ContainsValue(buffer_ids_known_by_receiver_, buffer_id)) { 340 if (!base::ContainsValue(buffer_ids_known_by_receiver_, buffer_id)) {
338 receiver_->OnNewBufferHandle( 341 receiver_->OnNewBufferHandle(
339 buffer_id, 342 buffer_id, base::MakeUnique<BufferPoolBufferHandleProvider>(
340 base::MakeUnique<BufferPoolBufferHandleProvider>(buffer_pool_, 343 buffer_pool_, buffer_id));
341 buffer_id));
342 buffer_ids_known_by_receiver_.push_back(buffer_id); 344 buffer_ids_known_by_receiver_.push_back(buffer_id);
343 } 345 }
344 346
345 return MakeBufferStruct(buffer_pool_, buffer_id, frame_feedback_id); 347 return MakeBufferStruct(buffer_pool_, buffer_id, frame_feedback_id);
346 } 348 }
347 349
348 void VideoCaptureDeviceClient::OnIncomingCapturedBuffer( 350 void VideoCaptureDeviceClient::OnIncomingCapturedBuffer(
349 Buffer buffer, 351 Buffer buffer,
350 const VideoCaptureFormat& format, 352 const VideoCaptureFormat& format,
351 base::TimeTicks reference_time, 353 base::TimeTicks reference_time,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 } 421 }
420 422
421 void VideoCaptureDeviceClient::OnStarted() { 423 void VideoCaptureDeviceClient::OnStarted() {
422 receiver_->OnStarted(); 424 receiver_->OnStarted();
423 } 425 }
424 426
425 double VideoCaptureDeviceClient::GetBufferPoolUtilization() const { 427 double VideoCaptureDeviceClient::GetBufferPoolUtilization() const {
426 return buffer_pool_->GetBufferPoolUtilization(); 428 return buffer_pool_->GetBufferPoolUtilization();
427 } 429 }
428 430
431 void VideoCaptureDeviceClient::OnUsingExternalJpegDecoder() {
432 if (using_external_jpeg_decoder_)
433 return;
434 using_external_jpeg_decoder_ = true;
435 receiver_->OnStartedUsingGpuDecode();
436 }
437
438 void VideoCaptureDeviceClient::OnNotUsingExternalJpegDecoder() {
439 if (!using_external_jpeg_decoder_)
440 return;
441 using_external_jpeg_decoder_ = false;
442 receiver_->OnStoppedUsingGpuDecode();
443 }
444
429 void VideoCaptureDeviceClient::InitializeI420PlanePointers( 445 void VideoCaptureDeviceClient::InitializeI420PlanePointers(
430 const gfx::Size& dimensions, 446 const gfx::Size& dimensions,
431 uint8_t* const data, 447 uint8_t* const data,
432 uint8_t** y_plane_data, 448 uint8_t** y_plane_data,
433 uint8_t** u_plane_data, 449 uint8_t** u_plane_data,
434 uint8_t** v_plane_data) { 450 uint8_t** v_plane_data) {
435 DCHECK(dimensions.height()); 451 DCHECK(dimensions.height());
436 DCHECK(dimensions.width()); 452 DCHECK(dimensions.width());
437 453
438 const media::VideoPixelFormat format = media::PIXEL_FORMAT_I420; 454 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(); 487 auto buffer_access = buffer.handle_provider->GetHandleForInProcessAccess();
472 memcpy(buffer_access->data(), data, length); 488 memcpy(buffer_access->data(), data, length);
473 const VideoCaptureFormat output_format = 489 const VideoCaptureFormat output_format =
474 VideoCaptureFormat(format.frame_size, format.frame_rate, 490 VideoCaptureFormat(format.frame_size, format.frame_rate,
475 media::PIXEL_FORMAT_Y16, media::PIXEL_STORAGE_CPU); 491 media::PIXEL_FORMAT_Y16, media::PIXEL_STORAGE_CPU);
476 OnIncomingCapturedBuffer(std::move(buffer), output_format, reference_time, 492 OnIncomingCapturedBuffer(std::move(buffer), output_format, reference_time,
477 timestamp); 493 timestamp);
478 } 494 }
479 495
480 } // namespace media 496 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698