Christian Fremerey | c1d0754 | 2019-01-14 18:46:22 | [diff] [blame] | 1 | // Copyright 2019 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_SOURCE_PROVIDER_IMPL_H_ |
| 6 | #define SERVICES_VIDEO_CAPTURE_VIDEO_SOURCE_PROVIDER_IMPL_H_ |
| 7 | |
| 8 | #include <map> |
| 9 | |
Christian Fremerey | 2940d5e | 2019-03-25 19:58:10 | [diff] [blame] | 10 | #include "mojo/public/cpp/bindings/binding_set.h" |
Christian Fremerey | c1d0754 | 2019-01-14 18:46:22 | [diff] [blame] | 11 | #include "services/video_capture/device_factory.h" |
| 12 | #include "services/video_capture/public/mojom/video_source_provider.mojom.h" |
| 13 | |
| 14 | namespace video_capture { |
| 15 | |
| 16 | class VideoSourceImpl; |
| 17 | |
| 18 | class VideoSourceProviderImpl : public mojom::VideoSourceProvider { |
| 19 | public: |
Christian Fremerey | 2940d5e | 2019-03-25 19:58:10 | [diff] [blame] | 20 | VideoSourceProviderImpl( |
| 21 | DeviceFactory* device_factory, |
| 22 | base::RepeatingClosure on_last_client_disconnected_cb); |
Christian Fremerey | c1d0754 | 2019-01-14 18:46:22 | [diff] [blame] | 23 | ~VideoSourceProviderImpl() override; |
| 24 | |
Christian Fremerey | 2940d5e | 2019-03-25 19:58:10 | [diff] [blame] | 25 | void AddClient(mojom::VideoSourceProviderRequest request); |
Christian Fremerey | c1d0754 | 2019-01-14 18:46:22 | [diff] [blame] | 26 | |
| 27 | // mojom::VideoSourceProvider implementation. |
| 28 | void GetSourceInfos(GetSourceInfosCallback callback) override; |
| 29 | void GetVideoSource(const std::string& device_id, |
| 30 | mojom::VideoSourceRequest source_request) override; |
| 31 | void AddSharedMemoryVirtualDevice( |
| 32 | const media::VideoCaptureDeviceInfo& device_info, |
| 33 | mojom::ProducerPtr producer, |
| 34 | bool send_buffer_handles_to_producer_as_raw_file_descriptors, |
| 35 | mojom::SharedMemoryVirtualDeviceRequest virtual_device) override; |
| 36 | void AddTextureVirtualDevice( |
| 37 | const media::VideoCaptureDeviceInfo& device_info, |
| 38 | mojom::TextureVirtualDeviceRequest virtual_device) override; |
Christian Fremerey | 00025a37 | 2019-03-05 22:53:11 | [diff] [blame] | 39 | void RegisterVirtualDevicesChangedObserver( |
| 40 | mojom::DevicesChangedObserverPtr observer, |
| 41 | bool raise_event_if_virtual_devices_already_present) override; |
Christian Fremerey | 2940d5e | 2019-03-25 19:58:10 | [diff] [blame] | 42 | void Close(CloseCallback callback) override; |
Christian Fremerey | c1d0754 | 2019-01-14 18:46:22 | [diff] [blame] | 43 | |
| 44 | private: |
Christian Fremerey | 2940d5e | 2019-03-25 19:58:10 | [diff] [blame] | 45 | void OnClientDisconnected(); |
| 46 | void OnClientDisconnectedOrClosed(); |
Christian Fremerey | c1d0754 | 2019-01-14 18:46:22 | [diff] [blame] | 47 | void OnVideoSourceLastClientDisconnected(const std::string& device_id); |
| 48 | |
| 49 | DeviceFactory* const device_factory_; |
Christian Fremerey | 2940d5e | 2019-03-25 19:58:10 | [diff] [blame] | 50 | base::RepeatingClosure on_last_client_disconnected_cb_; |
| 51 | int client_count_ = 0; |
| 52 | int closed_but_not_yet_disconnected_client_count_ = 0; |
| 53 | mojo::BindingSet<mojom::VideoSourceProvider> bindings_; |
Christian Fremerey | c1d0754 | 2019-01-14 18:46:22 | [diff] [blame] | 54 | std::unique_ptr<service_manager::ServiceContextRef> service_ref_; |
| 55 | std::map<std::string, std::unique_ptr<VideoSourceImpl>> sources_; |
| 56 | DISALLOW_COPY_AND_ASSIGN(VideoSourceProviderImpl); |
| 57 | }; |
| 58 | |
| 59 | } // namespace video_capture |
| 60 | |
| 61 | #endif // SERVICES_VIDEO_CAPTURE_VIDEO_SOURCE_PROVIDER_IMPL_H_ |