blob: 468ae6d9ed0280034654292febc6fc48b092d258 [file] [log] [blame]
Christian Fremereyc1d07542019-01-14 18:46:221// 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 Fremerey2940d5e2019-03-25 19:58:1010#include "mojo/public/cpp/bindings/binding_set.h"
Christian Fremereyc1d07542019-01-14 18:46:2211#include "services/video_capture/device_factory.h"
12#include "services/video_capture/public/mojom/video_source_provider.mojom.h"
13
14namespace video_capture {
15
16class VideoSourceImpl;
17
18class VideoSourceProviderImpl : public mojom::VideoSourceProvider {
19 public:
Christian Fremerey2940d5e2019-03-25 19:58:1020 VideoSourceProviderImpl(
21 DeviceFactory* device_factory,
22 base::RepeatingClosure on_last_client_disconnected_cb);
Christian Fremereyc1d07542019-01-14 18:46:2223 ~VideoSourceProviderImpl() override;
24
Christian Fremerey2940d5e2019-03-25 19:58:1025 void AddClient(mojom::VideoSourceProviderRequest request);
Christian Fremereyc1d07542019-01-14 18:46:2226
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 Fremerey00025a372019-03-05 22:53:1139 void RegisterVirtualDevicesChangedObserver(
40 mojom::DevicesChangedObserverPtr observer,
41 bool raise_event_if_virtual_devices_already_present) override;
Christian Fremerey2940d5e2019-03-25 19:58:1042 void Close(CloseCallback callback) override;
Christian Fremereyc1d07542019-01-14 18:46:2243
44 private:
Christian Fremerey2940d5e2019-03-25 19:58:1045 void OnClientDisconnected();
46 void OnClientDisconnectedOrClosed();
Christian Fremereyc1d07542019-01-14 18:46:2247 void OnVideoSourceLastClientDisconnected(const std::string& device_id);
48
49 DeviceFactory* const device_factory_;
Christian Fremerey2940d5e2019-03-25 19:58:1050 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 Fremereyc1d07542019-01-14 18:46:2254 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_