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