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 video_capture { | 14 namespace video_capture { |
15 | 15 |
16 DeviceMediaToMojoAdapter::DeviceMediaToMojoAdapter( | 16 DeviceMediaToMojoAdapter::DeviceMediaToMojoAdapter( |
17 std::unique_ptr<media::VideoCaptureDevice> device, | 17 std::unique_ptr<media::VideoCaptureDevice> device, |
18 const media::VideoCaptureJpegDecoderFactoryCB& | 18 const media::VideoCaptureJpegDecoderFactoryCB& |
19 jpeg_decoder_factory_callback) | 19 jpeg_decoder_factory_callback) |
20 : device_(std::move(device)), | 20 : device_(std::move(device)), |
21 jpeg_decoder_factory_callback_(jpeg_decoder_factory_callback), | 21 jpeg_decoder_factory_callback_(jpeg_decoder_factory_callback), |
22 device_running_(false) {} | 22 device_running_(false) {} |
23 | 23 |
24 DeviceMediaToMojoAdapter::~DeviceMediaToMojoAdapter() { | 24 DeviceMediaToMojoAdapter::~DeviceMediaToMojoAdapter() { |
25 Stop(); | 25 Stop(); |
26 } | 26 } |
27 | 27 |
28 void DeviceMediaToMojoAdapter::Start(const CaptureSettings& requested_settings, | 28 void DeviceMediaToMojoAdapter::Start( |
29 mojom::ReceiverPtr receiver) { | 29 const media::VideoCaptureParams& requested_settings, |
30 media::VideoCaptureParams params; | 30 mojom::ReceiverPtr receiver) { |
31 requested_settings.ConvertToMediaVideoCaptureParams(¶ms); | |
32 receiver.set_connection_error_handler( | 31 receiver.set_connection_error_handler( |
33 base::Bind(&DeviceMediaToMojoAdapter::OnClientConnectionErrorOrClose, | 32 base::Bind(&DeviceMediaToMojoAdapter::OnClientConnectionErrorOrClose, |
34 base::Unretained(this))); | 33 base::Unretained(this))); |
35 | 34 |
36 auto media_receiver = | 35 auto media_receiver = |
37 base::MakeUnique<ReceiverMojoToMediaAdapter>(std::move(receiver)); | 36 base::MakeUnique<ReceiverMojoToMediaAdapter>(std::move(receiver)); |
38 | 37 |
39 // Create a dedicated buffer pool for the device usage session. | 38 // Create a dedicated buffer pool for the device usage session. |
40 const int kMaxBufferCount = 2; | 39 const int kMaxBufferCount = 2; |
41 auto buffer_tracker_factory = | 40 auto buffer_tracker_factory = |
42 base::MakeUnique<media::VideoCaptureBufferTrackerFactoryImpl>(); | 41 base::MakeUnique<media::VideoCaptureBufferTrackerFactoryImpl>(); |
43 scoped_refptr<media::VideoCaptureBufferPool> buffer_pool( | 42 scoped_refptr<media::VideoCaptureBufferPool> buffer_pool( |
44 new media::VideoCaptureBufferPoolImpl(std::move(buffer_tracker_factory), | 43 new media::VideoCaptureBufferPoolImpl(std::move(buffer_tracker_factory), |
45 kMaxBufferCount)); | 44 kMaxBufferCount)); |
46 | 45 |
47 auto device_client = base::MakeUnique<media::VideoCaptureDeviceClient>( | 46 auto device_client = base::MakeUnique<media::VideoCaptureDeviceClient>( |
48 std::move(media_receiver), buffer_pool, jpeg_decoder_factory_callback_); | 47 std::move(media_receiver), buffer_pool, jpeg_decoder_factory_callback_); |
49 | 48 |
50 device_->AllocateAndStart(params, std::move(device_client)); | 49 device_->AllocateAndStart(requested_settings, std::move(device_client)); |
51 device_running_ = true; | 50 device_running_ = true; |
52 } | 51 } |
53 | 52 |
54 void DeviceMediaToMojoAdapter::Stop() { | 53 void DeviceMediaToMojoAdapter::Stop() { |
55 if (device_running_ == false) | 54 if (device_running_ == false) |
56 return; | 55 return; |
57 device_->StopAndDeAllocate(); | 56 device_->StopAndDeAllocate(); |
58 device_running_ = false; | 57 device_running_ = false; |
59 } | 58 } |
60 | 59 |
61 void DeviceMediaToMojoAdapter::OnClientConnectionErrorOrClose() { | 60 void DeviceMediaToMojoAdapter::OnClientConnectionErrorOrClose() { |
62 Stop(); | 61 Stop(); |
63 } | 62 } |
64 | 63 |
65 } // namespace video_capture | 64 } // namespace video_capture |
OLD | NEW |