OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef SERVICES_VIDEO_CAPTURE_VIDEO_CAPTURE_DEVICE_FACTORY_IMPL_H_ | |
6 #define SERVICES_VIDEO_CAPTURE_VIDEO_CAPTURE_DEVICE_FACTORY_IMPL_H_ | |
7 | |
8 #include <vector> | |
9 | |
10 #include "mojo/public/cpp/bindings/binding.h" | |
11 #include "services/video_capture/public/interfaces/mock_video_capture_device.moj
om.h" | |
12 #include "services/video_capture/public/interfaces/video_capture_device_factory.
mojom.h" | |
13 #include "services/video_capture/video_capture_device_proxy_impl.h" | |
14 | |
15 namespace video_capture { | |
16 | |
17 class VideoCaptureDeviceFactoryImpl : public mojom::VideoCaptureDeviceFactory { | |
18 public: | |
19 VideoCaptureDeviceFactoryImpl(const media::VideoCaptureJpegDecoderFactoryCB& | |
20 jpeg_decoder_factory_callback); | |
21 ~VideoCaptureDeviceFactoryImpl() override; | |
22 | |
23 void AddMojoDevice(std::unique_ptr<VideoCaptureDeviceProxyImpl> device, | |
24 const media::VideoCaptureDeviceDescriptor& descriptor); | |
25 | |
26 void AddMediaDevice(std::unique_ptr<media::VideoCaptureDevice> device, | |
27 const media::VideoCaptureDeviceDescriptor& descriptor); | |
28 | |
29 void AddMockDevice(mojom::MockVideoCaptureDevicePtr device, | |
30 const media::VideoCaptureDeviceDescriptor& descriptor); | |
31 | |
32 // mojom::VideoCaptureDeviceFactory: | |
33 void EnumerateDeviceDescriptors( | |
34 const EnumerateDeviceDescriptorsCallback& callback) override; | |
35 void GetSupportedFormats( | |
36 const media::VideoCaptureDeviceDescriptor& device_descriptor, | |
37 const GetSupportedFormatsCallback& callback) override; | |
38 void CreateDeviceProxy( | |
39 const media::VideoCaptureDeviceDescriptor& device_descriptor, | |
40 mojom::VideoCaptureDeviceProxyRequest proxy_request, | |
41 const CreateDeviceProxyCallback& callback) override; | |
42 | |
43 private: | |
44 // We use a std::vector of structs with the |descriptor| field as a unique | |
45 // keys. We do it this way instead of using a std::map because Mojo-generated | |
46 // structs (here VideoCaptureDeviceDescriptor) do not (yet) generate a | |
47 // comparison operator, and we do not want to provide a custom one. The | |
48 // performance penalty of linear-time lookup should be minimal assuming that | |
49 // the number of capture devices is typically small. | |
50 class DeviceEntry { | |
51 public: | |
52 DeviceEntry(const media::VideoCaptureDeviceDescriptor& descriptor, | |
53 std::unique_ptr<VideoCaptureDeviceProxyImpl> bindable_target); | |
54 ~DeviceEntry(); | |
55 DeviceEntry(DeviceEntry&& other); | |
56 DeviceEntry& operator=(DeviceEntry&& other); | |
57 | |
58 const media::VideoCaptureDeviceDescriptor& descriptor() const; | |
59 bool DescriptorEquals( | |
60 const media::VideoCaptureDeviceDescriptor& other) const; | |
61 bool is_bound() const; | |
62 void Bind(mojom::VideoCaptureDeviceProxyRequest request); | |
63 void Unbind(); | |
64 | |
65 void OnConnectionErrorOrClose(); | |
66 | |
67 private: | |
68 media::VideoCaptureDeviceDescriptor descriptor_; | |
69 std::unique_ptr<VideoCaptureDeviceProxyImpl> device_proxy_; | |
70 // TODO(chfremer) Use mojo::Binding<> directly instead of unique_ptr<> when | |
71 // mojo::Binding<> supports move operators. | |
72 // https://crbug.com/644314 | |
73 std::unique_ptr<mojo::Binding<mojom::VideoCaptureDeviceProxy>> binding_; | |
74 | |
75 DISALLOW_COPY_AND_ASSIGN(DeviceEntry); | |
76 }; | |
77 | |
78 std::vector<DeviceEntry> devices_; | |
79 media::VideoCaptureJpegDecoderFactoryCB jpeg_decoder_factory_callback_; | |
80 }; | |
81 | |
82 } // namespace video_capture | |
83 | |
84 #endif // SERVICES_VIDEO_CAPTURE_VIDEO_CAPTURE_DEVICE_FACTORY_IMPL_H_ | |
OLD | NEW |