fake_video_source_provider.h 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Copyright 2022 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. #ifndef ASH_CAPTURE_MODE_FAKE_VIDEO_SOURCE_PROVIDER_H_
  5. #define ASH_CAPTURE_MODE_FAKE_VIDEO_SOURCE_PROVIDER_H_
  6. #include <memory>
  7. #include <string>
  8. #include "ash/capture_mode/fake_camera_device.h"
  9. #include "base/callback_forward.h"
  10. #include "media/base/video_facing.h"
  11. #include "media/capture/video/video_capture_device_info.h"
  12. #include "mojo/public/cpp/bindings/pending_receiver.h"
  13. #include "mojo/public/cpp/bindings/receiver.h"
  14. #include "services/video_capture/public/mojom/video_source_provider.mojom.h"
  15. namespace ash {
  16. // Defines a fake implementation of the `VideoSourceProvider` mojo interface
  17. // for testing the interaction with the video capture service.
  18. class FakeVideoSourceProvider
  19. : public video_capture::mojom::VideoSourceProvider {
  20. public:
  21. FakeVideoSourceProvider();
  22. FakeVideoSourceProvider(const FakeVideoSourceProvider&) = delete;
  23. FakeVideoSourceProvider& operator=(const FakeVideoSourceProvider&) = delete;
  24. ~FakeVideoSourceProvider() override;
  25. void set_on_replied_with_source_infos(base::OnceClosure callback) {
  26. on_replied_with_source_infos_ = std::move(callback);
  27. }
  28. void Bind(mojo::PendingReceiver<video_capture::mojom::VideoSourceProvider>
  29. pending_receiver);
  30. // Simulates a fatal error on the camera device whose `device_id` is given.
  31. void TriggerFatalErrorOnCamera(const std::string& device_id);
  32. // Simulate connecting and disconnecting a camera device with the given
  33. // `device_id`, `display_name` and `model_id`.
  34. void AddFakeCamera(const std::string& device_id,
  35. const std::string& display_name,
  36. const std::string& model_id,
  37. media::VideoFacingMode camera_facing_mode);
  38. void AddFakeCameraWithoutNotifying(const std::string& device_id,
  39. const std::string& display_name,
  40. const std::string& model_id,
  41. media::VideoFacingMode camera_facing_mode);
  42. void RemoveFakeCamera(const std::string& device_id);
  43. void RemoveFakeCameraWithoutNotifying(const std::string& device_id);
  44. // video_capture::mojom::VideoSourceProvider:
  45. void GetSourceInfos(GetSourceInfosCallback callback) override;
  46. void GetVideoSource(
  47. const std::string& source_id,
  48. mojo::PendingReceiver<video_capture::mojom::VideoSource> stream) override;
  49. void AddSharedMemoryVirtualDevice(
  50. const media::VideoCaptureDeviceInfo& device_info,
  51. mojo::PendingRemote<video_capture::mojom::Producer> producer,
  52. bool send_buffer_handles_to_producer_as_raw_file_descriptors,
  53. mojo::PendingReceiver<video_capture::mojom::SharedMemoryVirtualDevice>
  54. virtual_device_receiver) override {}
  55. void AddTextureVirtualDevice(
  56. const media::VideoCaptureDeviceInfo& device_info,
  57. mojo::PendingReceiver<video_capture::mojom::TextureVirtualDevice>
  58. virtual_device_receiver) override {}
  59. void RegisterVirtualDevicesChangedObserver(
  60. mojo::PendingRemote<video_capture::mojom::DevicesChangedObserver>
  61. observer,
  62. bool raise_event_if_virtual_devices_already_present) override {}
  63. void Close(CloseCallback callback) override {}
  64. private:
  65. mojo::Receiver<video_capture::mojom::VideoSourceProvider> receiver_{this};
  66. base::flat_map</*device_id=*/std::string, std::unique_ptr<FakeCameraDevice>>
  67. devices_map_;
  68. // A callback that's triggered after this source provider replies back to its
  69. // client in GetSourceInfos().
  70. base::OnceClosure on_replied_with_source_infos_;
  71. };
  72. } // namespace ash
  73. #endif // ASH_CAPTURE_MODE_FAKE_VIDEO_SOURCE_PROVIDER_H_