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 #ifndef SERVICES_VIDEO_CAPTURE_DEVICE_FACTORY_MEDIA_TO_MOJO_ADAPTER_H_ | 5 #ifndef SERVICES_VIDEO_CAPTURE_DEVICE_FACTORY_MEDIA_TO_MOJO_ADAPTER_H_ |
6 #define SERVICES_VIDEO_CAPTURE_DEVICE_FACTORY_MEDIA_TO_MOJO_ADAPTER_H_ | 6 #define SERVICES_VIDEO_CAPTURE_DEVICE_FACTORY_MEDIA_TO_MOJO_ADAPTER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "media/capture/video/video_capture_device_client.h" | 10 #include "media/capture/video/video_capture_device_client.h" |
11 #include "media/capture/video/video_capture_device_factory.h" | 11 #include "media/capture/video/video_capture_system.h" |
12 #include "mojo/public/cpp/bindings/binding.h" | 12 #include "mojo/public/cpp/bindings/binding.h" |
13 #include "services/video_capture/public/interfaces/device_factory.mojom.h" | 13 #include "services/video_capture/public/interfaces/device_factory.mojom.h" |
14 | 14 |
15 namespace video_capture { | 15 namespace video_capture { |
16 | 16 |
17 class DeviceMediaToMojoAdapter; | 17 class DeviceMediaToMojoAdapter; |
18 | 18 |
19 // Wraps a media::VideoCaptureDeviceFactory and exposes its functionality | 19 // Wraps a media::VideoCaptureSystem and exposes its functionality through the |
20 // through the mojom::DeviceFactory interface. | 20 // mojom::DeviceFactory interface. Keeps track of device instances that have |
21 // Keeps track of device instances that have been created to ensure that | 21 // been created to ensure that it does not create more than one instance of the |
22 // it does not create more than one instance of the same | 22 // same media::VideoCaptureDevice at the same time. |
23 // media::VideoCaptureDevice at the same time. | |
24 class DeviceFactoryMediaToMojoAdapter : public mojom::DeviceFactory { | 23 class DeviceFactoryMediaToMojoAdapter : public mojom::DeviceFactory { |
25 public: | 24 public: |
26 DeviceFactoryMediaToMojoAdapter( | 25 DeviceFactoryMediaToMojoAdapter( |
27 std::unique_ptr<media::VideoCaptureDeviceFactory> device_factory, | 26 std::unique_ptr<media::VideoCaptureSystem> capture_system, |
28 const media::VideoCaptureJpegDecoderFactoryCB& | 27 const media::VideoCaptureJpegDecoderFactoryCB& |
29 jpeg_decoder_factory_callback); | 28 jpeg_decoder_factory_callback); |
30 ~DeviceFactoryMediaToMojoAdapter() override; | 29 ~DeviceFactoryMediaToMojoAdapter() override; |
31 | 30 |
32 // mojom::DeviceFactory: | 31 // mojom::DeviceFactory: |
33 void GetDeviceInfos(const GetDeviceInfosCallback& callback) override; | 32 void GetDeviceInfos(const GetDeviceInfosCallback& callback) override; |
34 void CreateDevice(const std::string& device_id, | 33 void CreateDevice(const std::string& device_id, |
35 mojom::DeviceRequest device_request, | 34 mojom::DeviceRequest device_request, |
36 const CreateDeviceCallback& callback) override; | 35 const CreateDeviceCallback& callback) override; |
37 | 36 |
38 private: | 37 private: |
39 struct ActiveDeviceEntry { | 38 struct ActiveDeviceEntry { |
40 ActiveDeviceEntry(); | 39 ActiveDeviceEntry(); |
41 ~ActiveDeviceEntry(); | 40 ~ActiveDeviceEntry(); |
42 ActiveDeviceEntry(ActiveDeviceEntry&& other); | 41 ActiveDeviceEntry(ActiveDeviceEntry&& other); |
43 ActiveDeviceEntry& operator=(ActiveDeviceEntry&& other); | 42 ActiveDeviceEntry& operator=(ActiveDeviceEntry&& other); |
44 | 43 |
45 std::unique_ptr<DeviceMediaToMojoAdapter> device; | 44 std::unique_ptr<DeviceMediaToMojoAdapter> device; |
46 // TODO(chfremer) Use mojo::Binding<> directly instead of unique_ptr<> when | 45 // TODO(chfremer) Use mojo::Binding<> directly instead of unique_ptr<> when |
47 // mojo::Binding<> supports move operators. | 46 // mojo::Binding<> supports move operators. |
48 // https://crbug.com/644314 | 47 // https://crbug.com/644314 |
49 std::unique_ptr<mojo::Binding<mojom::Device>> binding; | 48 std::unique_ptr<mojo::Binding<mojom::Device>> binding; |
50 }; | 49 }; |
51 | 50 |
52 void OnClientConnectionErrorOrClose(const std::string& device_id); | 51 void OnClientConnectionErrorOrClose(const std::string& device_id); |
53 | 52 |
54 // Returns false if no descriptor found. | 53 const std::unique_ptr<media::VideoCaptureSystem> capture_system_; |
55 bool LookupDescriptorFromId(const std::string& device_id, | |
56 media::VideoCaptureDeviceDescriptor* descriptor); | |
57 | |
58 const std::unique_ptr<media::VideoCaptureDeviceFactory> device_factory_; | |
59 const media::VideoCaptureJpegDecoderFactoryCB jpeg_decoder_factory_callback_; | 54 const media::VideoCaptureJpegDecoderFactoryCB jpeg_decoder_factory_callback_; |
60 std::map<std::string, ActiveDeviceEntry> active_devices_by_id_; | 55 std::map<std::string, ActiveDeviceEntry> active_devices_by_id_; |
61 }; | 56 }; |
62 | 57 |
63 } // namespace video_capture | 58 } // namespace video_capture |
64 | 59 |
65 #endif // SERVICES_VIDEO_CAPTURE_DEVICE_FACTORY_MEDIA_TO_MOJO_ADAPTER_H_ | 60 #endif // SERVICES_VIDEO_CAPTURE_DEVICE_FACTORY_MEDIA_TO_MOJO_ADAPTER_H_ |
OLD | NEW |