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

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

Issue 2772963002: Reland [Mojo Video Capture] Add test coverage for accelerated jpeg decoding (Closed)
Patch Set: Rebase to March 30 Created 3 years, 8 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 buffer_pool_(std::move(buffer_pool)), 106 buffer_pool_(std::move(buffer_pool)),
107 last_captured_pixel_format_(media::PIXEL_FORMAT_UNKNOWN) {} 107 last_captured_pixel_format_(media::PIXEL_FORMAT_UNKNOWN) {
108 on_started_using_gpu_cb_ =
109 base::Bind(&VideoFrameReceiver::OnStartedUsingGpuDecode,
110 base::Unretained(receiver_.get()));
111 }
108 112
109 VideoCaptureDeviceClient::~VideoCaptureDeviceClient() { 113 VideoCaptureDeviceClient::~VideoCaptureDeviceClient() {
110 // This should be on the platform auxiliary thread since 114 // This should be on the platform auxiliary thread since
111 // |external_jpeg_decoder_| need to be destructed on the same thread as 115 // |external_jpeg_decoder_| need to be destructed on the same thread as
112 // OnIncomingCapturedData. 116 // OnIncomingCapturedData.
113 117
114 for (int buffer_id : buffer_ids_known_by_receiver_) 118 for (int buffer_id : buffer_ids_known_by_receiver_)
115 receiver_->OnBufferRetired(buffer_id); 119 receiver_->OnBufferRetired(buffer_id);
116 } 120 }
117 121
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 DCHECK_GE(static_cast<size_t>(length), format.ImageAllocationSize()); 278 DCHECK_GE(static_cast<size_t>(length), format.ImageAllocationSize());
275 279
276 if (external_jpeg_decoder_) { 280 if (external_jpeg_decoder_) {
277 const VideoCaptureJpegDecoder::STATUS status = 281 const VideoCaptureJpegDecoder::STATUS status =
278 external_jpeg_decoder_->GetStatus(); 282 external_jpeg_decoder_->GetStatus();
279 if (status == VideoCaptureJpegDecoder::FAILED) { 283 if (status == VideoCaptureJpegDecoder::FAILED) {
280 external_jpeg_decoder_.reset(); 284 external_jpeg_decoder_.reset();
281 } else if (status == VideoCaptureJpegDecoder::INIT_PASSED && 285 } else if (status == VideoCaptureJpegDecoder::INIT_PASSED &&
282 format.pixel_format == media::PIXEL_FORMAT_MJPEG && 286 format.pixel_format == media::PIXEL_FORMAT_MJPEG &&
283 rotation == 0 && !flip) { 287 rotation == 0 && !flip) {
288 if (on_started_using_gpu_cb_)
289 std::move(on_started_using_gpu_cb_).Run();
284 external_jpeg_decoder_->DecodeCapturedData( 290 external_jpeg_decoder_->DecodeCapturedData(
285 data, length, format, reference_time, timestamp, std::move(buffer)); 291 data, length, format, reference_time, timestamp, std::move(buffer));
286 return; 292 return;
287 } 293 }
288 } 294 }
289 295
290 if (libyuv::ConvertToI420( 296 if (libyuv::ConvertToI420(
291 data, length, y_plane_data, yplane_stride, u_plane_data, 297 data, length, y_plane_data, yplane_stride, u_plane_data,
292 uv_plane_stride, v_plane_data, uv_plane_stride, crop_x, crop_y, 298 uv_plane_stride, v_plane_data, uv_plane_stride, crop_x, crop_y,
293 format.frame_size.width(), 299 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()) { 335 if (entry_iter != buffer_ids_known_by_receiver_.end()) {
330 buffer_ids_known_by_receiver_.erase(entry_iter); 336 buffer_ids_known_by_receiver_.erase(entry_iter);
331 receiver_->OnBufferRetired(buffer_id_to_drop); 337 receiver_->OnBufferRetired(buffer_id_to_drop);
332 } 338 }
333 } 339 }
334 if (buffer_id == VideoCaptureBufferPool::kInvalidId) 340 if (buffer_id == VideoCaptureBufferPool::kInvalidId)
335 return Buffer(); 341 return Buffer();
336 342
337 if (!base::ContainsValue(buffer_ids_known_by_receiver_, buffer_id)) { 343 if (!base::ContainsValue(buffer_ids_known_by_receiver_, buffer_id)) {
338 receiver_->OnNewBufferHandle( 344 receiver_->OnNewBufferHandle(
339 buffer_id, 345 buffer_id, base::MakeUnique<BufferPoolBufferHandleProvider>(
340 base::MakeUnique<BufferPoolBufferHandleProvider>(buffer_pool_, 346 buffer_pool_, buffer_id));
341 buffer_id));
342 buffer_ids_known_by_receiver_.push_back(buffer_id); 347 buffer_ids_known_by_receiver_.push_back(buffer_id);
343 } 348 }
344 349
345 return MakeBufferStruct(buffer_pool_, buffer_id, frame_feedback_id); 350 return MakeBufferStruct(buffer_pool_, buffer_id, frame_feedback_id);
346 } 351 }
347 352
348 void VideoCaptureDeviceClient::OnIncomingCapturedBuffer( 353 void VideoCaptureDeviceClient::OnIncomingCapturedBuffer(
349 Buffer buffer, 354 Buffer buffer,
350 const VideoCaptureFormat& format, 355 const VideoCaptureFormat& format,
351 base::TimeTicks reference_time, 356 base::TimeTicks reference_time,
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 auto buffer_access = buffer.handle_provider->GetHandleForInProcessAccess(); 476 auto buffer_access = buffer.handle_provider->GetHandleForInProcessAccess();
472 memcpy(buffer_access->data(), data, length); 477 memcpy(buffer_access->data(), data, length);
473 const VideoCaptureFormat output_format = 478 const VideoCaptureFormat output_format =
474 VideoCaptureFormat(format.frame_size, format.frame_rate, 479 VideoCaptureFormat(format.frame_size, format.frame_rate,
475 media::PIXEL_FORMAT_Y16, media::PIXEL_STORAGE_CPU); 480 media::PIXEL_FORMAT_Y16, media::PIXEL_STORAGE_CPU);
476 OnIncomingCapturedBuffer(std::move(buffer), output_format, reference_time, 481 OnIncomingCapturedBuffer(std::move(buffer), output_format, reference_time,
477 timestamp); 482 timestamp);
478 } 483 }
479 484
480 } // namespace media 485 } // namespace media
OLDNEW
« no previous file with comments | « media/capture/video/video_capture_device_client.h ('k') | media/capture/video/video_capture_device_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698