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/video_capture_device_factory_impl.h" | 5 #include "services/video_capture/video_capture_device_factory_impl.h" |
6 | 6 |
7 #include <sstream> | 7 #include <sstream> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
11 #include "media/capture/video/fake_video_capture_device.h" | 11 #include "media/capture/video/fake_video_capture_device.h" |
12 #include "services/video_capture/device_mock_to_media_adapter.h" | 12 #include "services/video_capture/device_mock_to_media_adapter.h" |
13 | 13 |
14 namespace video_capture { | 14 namespace video_capture { |
15 | 15 |
16 VideoCaptureDeviceFactoryImpl::DeviceEntry::DeviceEntry( | 16 VideoCaptureDeviceFactoryImpl::DeviceEntry::DeviceEntry( |
17 mojom::VideoCaptureDeviceDescriptorPtr descriptor, | 17 const media::VideoCaptureDeviceDescriptor& descriptor, |
18 std::unique_ptr<VideoCaptureDeviceProxyImpl> bindable_target) | 18 std::unique_ptr<VideoCaptureDeviceProxyImpl> bindable_target) |
19 : descriptor_(std::move(descriptor)), | 19 : descriptor_(std::move(descriptor)), |
20 binding_(base::MakeUnique<mojo::Binding<mojom::VideoCaptureDeviceProxy>>( | 20 binding_(base::MakeUnique<mojo::Binding<mojom::VideoCaptureDeviceProxy>>( |
21 bindable_target.get())) { | 21 bindable_target.get())) { |
22 device_proxy_ = std::move(bindable_target); | 22 device_proxy_ = std::move(bindable_target); |
23 } | 23 } |
24 | 24 |
25 VideoCaptureDeviceFactoryImpl::DeviceEntry::~DeviceEntry() = default; | 25 VideoCaptureDeviceFactoryImpl::DeviceEntry::~DeviceEntry() = default; |
26 | 26 |
27 VideoCaptureDeviceFactoryImpl::DeviceEntry::DeviceEntry( | 27 VideoCaptureDeviceFactoryImpl::DeviceEntry::DeviceEntry( |
28 VideoCaptureDeviceFactoryImpl::DeviceEntry&& other) = default; | 28 VideoCaptureDeviceFactoryImpl::DeviceEntry&& other) = default; |
29 | 29 |
30 VideoCaptureDeviceFactoryImpl::DeviceEntry& | 30 VideoCaptureDeviceFactoryImpl::DeviceEntry& |
31 VideoCaptureDeviceFactoryImpl::DeviceEntry::operator=( | 31 VideoCaptureDeviceFactoryImpl::DeviceEntry::operator=( |
32 VideoCaptureDeviceFactoryImpl::DeviceEntry&& other) = default; | 32 VideoCaptureDeviceFactoryImpl::DeviceEntry&& other) = default; |
33 | 33 |
34 mojom::VideoCaptureDeviceDescriptorPtr | 34 const media::VideoCaptureDeviceDescriptor& |
35 VideoCaptureDeviceFactoryImpl::DeviceEntry::MakeDescriptorCopy() const { | 35 VideoCaptureDeviceFactoryImpl::DeviceEntry::descriptor() const { |
36 return descriptor_.Clone(); | 36 return descriptor_; |
37 } | 37 } |
38 | 38 |
39 bool VideoCaptureDeviceFactoryImpl::DeviceEntry::DescriptorEquals( | 39 bool VideoCaptureDeviceFactoryImpl::DeviceEntry::DescriptorEquals( |
40 const mojom::VideoCaptureDeviceDescriptorPtr& other) const { | 40 const media::VideoCaptureDeviceDescriptor& other) const { |
41 return descriptor_.Equals(other); | 41 return descriptor_ == other; |
42 } | 42 } |
43 | 43 |
44 bool VideoCaptureDeviceFactoryImpl::DeviceEntry::is_bound() const { | 44 bool VideoCaptureDeviceFactoryImpl::DeviceEntry::is_bound() const { |
45 return binding_->is_bound(); | 45 return binding_->is_bound(); |
46 } | 46 } |
47 | 47 |
48 void VideoCaptureDeviceFactoryImpl::DeviceEntry::Bind( | 48 void VideoCaptureDeviceFactoryImpl::DeviceEntry::Bind( |
49 mojom::VideoCaptureDeviceProxyRequest request) { | 49 mojom::VideoCaptureDeviceProxyRequest request) { |
50 binding_->Bind(std::move(request)); | 50 binding_->Bind(std::move(request)); |
51 binding_->set_connection_error_handler(base::Bind( | 51 binding_->set_connection_error_handler(base::Bind( |
(...skipping 12 matching lines...) Expand all Loading... |
64 | 64 |
65 VideoCaptureDeviceFactoryImpl::VideoCaptureDeviceFactoryImpl( | 65 VideoCaptureDeviceFactoryImpl::VideoCaptureDeviceFactoryImpl( |
66 const media::VideoCaptureJpegDecoderFactoryCB& | 66 const media::VideoCaptureJpegDecoderFactoryCB& |
67 jpeg_decoder_factory_callback) | 67 jpeg_decoder_factory_callback) |
68 : jpeg_decoder_factory_callback_(jpeg_decoder_factory_callback) {} | 68 : jpeg_decoder_factory_callback_(jpeg_decoder_factory_callback) {} |
69 | 69 |
70 VideoCaptureDeviceFactoryImpl::~VideoCaptureDeviceFactoryImpl() = default; | 70 VideoCaptureDeviceFactoryImpl::~VideoCaptureDeviceFactoryImpl() = default; |
71 | 71 |
72 void VideoCaptureDeviceFactoryImpl::AddMojoDevice( | 72 void VideoCaptureDeviceFactoryImpl::AddMojoDevice( |
73 std::unique_ptr<VideoCaptureDeviceProxyImpl> device, | 73 std::unique_ptr<VideoCaptureDeviceProxyImpl> device, |
74 mojom::VideoCaptureDeviceDescriptorPtr descriptor) { | 74 const media::VideoCaptureDeviceDescriptor& descriptor) { |
75 devices_.emplace_back(std::move(descriptor), std::move(device)); | 75 devices_.emplace_back(std::move(descriptor), std::move(device)); |
76 } | 76 } |
77 | 77 |
78 void VideoCaptureDeviceFactoryImpl::AddMediaDevice( | 78 void VideoCaptureDeviceFactoryImpl::AddMediaDevice( |
79 std::unique_ptr<media::VideoCaptureDevice> device, | 79 std::unique_ptr<media::VideoCaptureDevice> device, |
80 mojom::VideoCaptureDeviceDescriptorPtr descriptor) { | 80 const media::VideoCaptureDeviceDescriptor& descriptor) { |
81 AddMojoDevice(base::MakeUnique<VideoCaptureDeviceProxyImpl>( | 81 AddMojoDevice(base::MakeUnique<VideoCaptureDeviceProxyImpl>( |
82 std::move(device), jpeg_decoder_factory_callback_), | 82 std::move(device), jpeg_decoder_factory_callback_), |
83 std::move(descriptor)); | 83 std::move(descriptor)); |
84 } | 84 } |
85 | 85 |
86 void VideoCaptureDeviceFactoryImpl::AddMockDevice( | 86 void VideoCaptureDeviceFactoryImpl::AddMockDevice( |
87 mojom::MockVideoCaptureDevicePtr device, | 87 mojom::MockVideoCaptureDevicePtr device, |
88 mojom::VideoCaptureDeviceDescriptorPtr descriptor) { | 88 const media::VideoCaptureDeviceDescriptor& descriptor) { |
89 AddMediaDevice(base::MakeUnique<DeviceMockToMediaAdapter>(std::move(device)), | 89 AddMediaDevice(base::MakeUnique<DeviceMockToMediaAdapter>(std::move(device)), |
90 std::move(descriptor)); | 90 std::move(descriptor)); |
91 } | 91 } |
92 | 92 |
93 void VideoCaptureDeviceFactoryImpl::EnumerateDeviceDescriptors( | 93 void VideoCaptureDeviceFactoryImpl::EnumerateDeviceDescriptors( |
94 const EnumerateDeviceDescriptorsCallback& callback) { | 94 const EnumerateDeviceDescriptorsCallback& callback) { |
95 std::vector<mojom::VideoCaptureDeviceDescriptorPtr> descriptors; | 95 std::vector<media::VideoCaptureDeviceDescriptor> descriptors; |
96 for (const auto& entry : devices_) | 96 for (const auto& entry : devices_) |
97 descriptors.push_back(entry.MakeDescriptorCopy()); | 97 descriptors.push_back(entry.descriptor()); |
98 callback.Run(std::move(descriptors)); | 98 callback.Run(std::move(descriptors)); |
99 } | 99 } |
100 | 100 |
101 void VideoCaptureDeviceFactoryImpl::GetSupportedFormats( | 101 void VideoCaptureDeviceFactoryImpl::GetSupportedFormats( |
102 mojom::VideoCaptureDeviceDescriptorPtr device_descriptor, | 102 const media::VideoCaptureDeviceDescriptor& device_descriptor, |
103 const GetSupportedFormatsCallback& callback) { | 103 const GetSupportedFormatsCallback& callback) { |
104 NOTIMPLEMENTED(); | 104 NOTIMPLEMENTED(); |
105 } | 105 } |
106 | 106 |
107 void VideoCaptureDeviceFactoryImpl::CreateDeviceProxy( | 107 void VideoCaptureDeviceFactoryImpl::CreateDeviceProxy( |
108 mojom::VideoCaptureDeviceDescriptorPtr device_descriptor, | 108 const media::VideoCaptureDeviceDescriptor& device_descriptor, |
109 mojom::VideoCaptureDeviceProxyRequest proxy_request, | 109 mojom::VideoCaptureDeviceProxyRequest proxy_request, |
110 const CreateDeviceProxyCallback& callback) { | 110 const CreateDeviceProxyCallback& callback) { |
111 for (auto& entry : devices_) { | 111 for (auto& entry : devices_) { |
112 if (entry.DescriptorEquals(device_descriptor)) { | 112 if (entry.DescriptorEquals(device_descriptor)) { |
113 if (entry.is_bound()) | 113 if (entry.is_bound()) |
114 entry.Unbind(); | 114 entry.Unbind(); |
115 entry.Bind(std::move(proxy_request)); | 115 entry.Bind(std::move(proxy_request)); |
116 callback.Run(mojom::DeviceAccessResultCode::SUCCESS); | 116 callback.Run(mojom::DeviceAccessResultCode::SUCCESS); |
117 return; | 117 return; |
118 } | 118 } |
119 } | 119 } |
120 callback.Run(mojom::DeviceAccessResultCode::ERROR_DEVICE_NOT_FOUND); | 120 callback.Run(mojom::DeviceAccessResultCode::ERROR_DEVICE_NOT_FOUND); |
121 } | 121 } |
122 | 122 |
123 } // namespace video_capture | 123 } // namespace video_capture |
OLD | NEW |