OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "services/video_capture/device_media_to_mojo_adapter.h" | 5 #include "services/video_capture/device_media_to_mojo_adapter.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "media/capture/video/video_capture_buffer_pool_impl.h" | 9 #include "media/capture/video/video_capture_buffer_pool_impl.h" |
10 #include "media/capture/video/video_capture_buffer_tracker_factory_impl.h" | 10 #include "media/capture/video/video_capture_buffer_tracker_factory_impl.h" |
11 #include "media/capture/video/video_capture_jpeg_decoder.h" | 11 #include "media/capture/video/video_capture_jpeg_decoder.h" |
12 #include "services/video_capture/receiver_mojo_to_media_adapter.h" | 12 #include "services/video_capture/receiver_mojo_to_media_adapter.h" |
13 | 13 |
14 namespace { | |
15 static const int kMaxBufferCount = 3; | |
emircan
2017/04/19 18:16:48
Add a comment.
chfremer
2017/04/19 23:03:37
Done.
| |
16 } | |
17 | |
14 namespace video_capture { | 18 namespace video_capture { |
15 | 19 |
16 DeviceMediaToMojoAdapter::DeviceMediaToMojoAdapter( | 20 DeviceMediaToMojoAdapter::DeviceMediaToMojoAdapter( |
17 std::unique_ptr<media::VideoCaptureDevice> device, | 21 std::unique_ptr<media::VideoCaptureDevice> device, |
18 const media::VideoCaptureJpegDecoderFactoryCB& | 22 const media::VideoCaptureJpegDecoderFactoryCB& |
19 jpeg_decoder_factory_callback) | 23 jpeg_decoder_factory_callback) |
20 : device_(std::move(device)), | 24 : device_(std::move(device)), |
21 jpeg_decoder_factory_callback_(jpeg_decoder_factory_callback), | 25 jpeg_decoder_factory_callback_(jpeg_decoder_factory_callback), |
22 device_running_(false) {} | 26 device_running_(false) {} |
23 | 27 |
24 DeviceMediaToMojoAdapter::~DeviceMediaToMojoAdapter() { | 28 DeviceMediaToMojoAdapter::~DeviceMediaToMojoAdapter() { |
25 Stop(); | 29 if (device_running_) |
30 device_->StopAndDeAllocate(); | |
26 } | 31 } |
27 | 32 |
28 void DeviceMediaToMojoAdapter::Start( | 33 void DeviceMediaToMojoAdapter::Start( |
29 const media::VideoCaptureParams& requested_settings, | 34 const media::VideoCaptureParams& requested_settings, |
30 mojom::ReceiverPtr receiver) { | 35 mojom::ReceiverPtr receiver) { |
31 receiver.set_connection_error_handler( | 36 receiver.set_connection_error_handler( |
32 base::Bind(&DeviceMediaToMojoAdapter::OnClientConnectionErrorOrClose, | 37 base::Bind(&DeviceMediaToMojoAdapter::OnClientConnectionErrorOrClose, |
33 base::Unretained(this))); | 38 base::Unretained(this))); |
34 | 39 |
35 auto media_receiver = | 40 auto media_receiver = |
36 base::MakeUnique<ReceiverMojoToMediaAdapter>(std::move(receiver)); | 41 base::MakeUnique<ReceiverMojoToMediaAdapter>(std::move(receiver)); |
37 | 42 |
38 // Create a dedicated buffer pool for the device usage session. | 43 // Create a dedicated buffer pool for the device usage session. |
39 const int kMaxBufferCount = 2; | |
40 auto buffer_tracker_factory = | 44 auto buffer_tracker_factory = |
41 base::MakeUnique<media::VideoCaptureBufferTrackerFactoryImpl>(); | 45 base::MakeUnique<media::VideoCaptureBufferTrackerFactoryImpl>(); |
42 scoped_refptr<media::VideoCaptureBufferPool> buffer_pool( | 46 scoped_refptr<media::VideoCaptureBufferPool> buffer_pool( |
43 new media::VideoCaptureBufferPoolImpl(std::move(buffer_tracker_factory), | 47 new media::VideoCaptureBufferPoolImpl(std::move(buffer_tracker_factory), |
44 kMaxBufferCount)); | 48 max_buffer_pool_buffer_count())); |
45 | 49 |
46 auto device_client = base::MakeUnique<media::VideoCaptureDeviceClient>( | 50 auto device_client = base::MakeUnique<media::VideoCaptureDeviceClient>( |
47 std::move(media_receiver), buffer_pool, jpeg_decoder_factory_callback_); | 51 std::move(media_receiver), buffer_pool, jpeg_decoder_factory_callback_); |
48 | 52 |
49 device_->AllocateAndStart(requested_settings, std::move(device_client)); | 53 device_->AllocateAndStart(requested_settings, std::move(device_client)); |
50 device_running_ = true; | 54 device_running_ = true; |
51 } | 55 } |
52 | 56 |
57 void DeviceMediaToMojoAdapter::OnReceiverReportingUtilization( | |
58 int32_t frame_feedback_id, | |
59 double utilization) { | |
60 device_->OnUtilizationReport(frame_feedback_id, utilization); | |
61 } | |
62 | |
53 void DeviceMediaToMojoAdapter::Stop() { | 63 void DeviceMediaToMojoAdapter::Stop() { |
54 if (device_running_ == false) | 64 if (device_running_ == false) |
55 return; | 65 return; |
66 device_running_ = false; | |
56 device_->StopAndDeAllocate(); | 67 device_->StopAndDeAllocate(); |
57 device_running_ = false; | |
58 } | 68 } |
59 | 69 |
60 void DeviceMediaToMojoAdapter::OnClientConnectionErrorOrClose() { | 70 void DeviceMediaToMojoAdapter::OnClientConnectionErrorOrClose() { |
61 Stop(); | 71 Stop(); |
62 } | 72 } |
63 | 73 |
74 // static | |
75 int DeviceMediaToMojoAdapter::max_buffer_pool_buffer_count() { | |
76 return kMaxBufferCount; | |
77 } | |
78 | |
64 } // namespace video_capture | 79 } // namespace video_capture |
OLD | NEW |