| // Copyright 2017 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #ifndef SERVICES_VIDEO_CAPTURE_VIRTUAL_DEVICE_ENABLED_DEVICE_FACTORY_H_ |
| #define SERVICES_VIDEO_CAPTURE_VIRTUAL_DEVICE_ENABLED_DEVICE_FACTORY_H_ |
| |
| #include <map> |
| #include <utility> |
| |
| #include "mojo/public/cpp/bindings/pending_receiver.h" |
| #include "mojo/public/cpp/bindings/pending_remote.h" |
| #include "mojo/public/cpp/bindings/remote.h" |
| #include "services/video_capture/device_factory.h" |
| #include "services/video_capture/public/mojom/device.mojom.h" |
| #include "services/video_capture/public/mojom/devices_changed_observer.mojom.h" |
| #include "services/video_capture/public/mojom/virtual_device.mojom.h" |
| |
| namespace video_capture { |
| |
| // Decorator that adds support for virtual devices to a given DeviceFactory. |
| class VirtualDeviceEnabledDeviceFactory : public DeviceFactory { |
| public: |
| explicit VirtualDeviceEnabledDeviceFactory( |
| std::unique_ptr<DeviceFactory> factory); |
| ~VirtualDeviceEnabledDeviceFactory() override; |
| |
| // DeviceFactory implementation. |
| void GetDeviceInfos(GetDeviceInfosCallback callback) override; |
| void CreateDevice(const std::string& device_id, |
| mojo::PendingReceiver<mojom::Device> device_receiver, |
| CreateDeviceCallback callback) override; |
| void AddSharedMemoryVirtualDevice( |
| const media::VideoCaptureDeviceInfo& device_info, |
| mojo::PendingRemote<mojom::Producer> producer, |
| bool send_buffer_handles_to_producer_as_raw_file_descriptors, |
| mojo::PendingReceiver<mojom::SharedMemoryVirtualDevice> |
| virtual_device_receiver) override; |
| void AddTextureVirtualDevice( |
| const media::VideoCaptureDeviceInfo& device_info, |
| mojo::PendingReceiver<mojom::TextureVirtualDevice> |
| virtual_device_receiver) override; |
| void RegisterVirtualDevicesChangedObserver( |
| mojo::PendingRemote<mojom::DevicesChangedObserver> observer, |
| bool raise_event_if_virtual_devices_already_present) override; |
| |
| private: |
| class VirtualDeviceEntry; |
| |
| void OnGetDeviceInfos( |
| GetDeviceInfosCallback callback, |
| const std::vector<media::VideoCaptureDeviceInfo>& device_infos); |
| |
| void OnVirtualDeviceProducerConnectionErrorOrClose( |
| const std::string& device_id); |
| void OnVirtualDeviceConsumerConnectionErrorOrClose( |
| const std::string& device_id); |
| void EmitDevicesChangedEvent(); |
| void OnDevicesChangedObserverDisconnected( |
| mojom::DevicesChangedObserver* observer); |
| |
| std::map<std::string, VirtualDeviceEntry> virtual_devices_by_id_; |
| const std::unique_ptr<DeviceFactory> device_factory_; |
| std::vector<mojo::Remote<mojom::DevicesChangedObserver>> |
| devices_changed_observers_; |
| |
| base::WeakPtrFactory<VirtualDeviceEnabledDeviceFactory> weak_factory_{this}; |
| DISALLOW_COPY_AND_ASSIGN(VirtualDeviceEnabledDeviceFactory); |
| }; |
| |
| } // namespace video_capture |
| |
| #endif // SERVICES_VIDEO_CAPTURE_VIRTUAL_DEVICE_ENABLED_DEVICE_FACTORY_H_ |