| 1 | /* |
| 2 | * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 | * Copyright (C) 2013-2108 Apple Inc. All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 15 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 18 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 21 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 22 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 | */ |
| 26 | |
| 27 | #pragma once |
| 28 | |
| 29 | #if ENABLE(MEDIA_STREAM) |
| 30 | |
| 31 | #include "CaptureDeviceManager.h" |
| 32 | #include "MockMediaDevice.h" |
| 33 | #include "MockRealtimeAudioSource.h" |
| 34 | #include "MockRealtimeVideoSource.h" |
| 35 | #include "RealtimeMediaSourceCenter.h" |
| 36 | |
| 37 | namespace WebCore { |
| 38 | |
| 39 | class MockRealtimeMediaSourceCenter { |
| 40 | public: |
| 41 | WEBCORE_EXPORT static MockRealtimeMediaSourceCenter& singleton(); |
| 42 | |
| 43 | WEBCORE_EXPORT static void setMockRealtimeMediaSourceCenterEnabled(bool); |
| 44 | WEBCORE_EXPORT static bool mockRealtimeMediaSourceCenterEnabled(); |
| 45 | |
| 46 | WEBCORE_EXPORT static void setDevices(Vector<MockMediaDevice>&&); |
| 47 | WEBCORE_EXPORT static void addDevice(const MockMediaDevice&); |
| 48 | WEBCORE_EXPORT static void removeDevice(const String& persistentId); |
| 49 | WEBCORE_EXPORT static void resetDevices(); |
| 50 | |
| 51 | void setMockAudioCaptureEnabled(bool isEnabled) { m_isMockAudioCaptureEnabled = isEnabled; } |
| 52 | void setMockVideoCaptureEnabled(bool isEnabled) { m_isMockVideoCaptureEnabled = isEnabled; } |
| 53 | void setMockDisplayCaptureEnabled(bool isEnabled) { m_isMockDisplayCaptureEnabled = isEnabled; } |
| 54 | |
| 55 | static Vector<CaptureDevice>& audioDevices(); |
| 56 | static Vector<CaptureDevice>& videoDevices(); |
| 57 | static Vector<CaptureDevice>& displayDevices(); |
| 58 | |
| 59 | static Optional<MockMediaDevice> mockDeviceWithPersistentID(const String&); |
| 60 | static Optional<CaptureDevice> captureDeviceWithPersistentID(CaptureDevice::DeviceType, const String&); |
| 61 | |
| 62 | CaptureDeviceManager& audioCaptureDeviceManager() { return m_audioCaptureDeviceManager; } |
| 63 | CaptureDeviceManager& videoCaptureDeviceManager() { return m_videoCaptureDeviceManager; } |
| 64 | CaptureDeviceManager& displayCaptureDeviceManager() { return m_displayCaptureDeviceManager; } |
| 65 | |
| 66 | private: |
| 67 | MockRealtimeMediaSourceCenter() = default; |
| 68 | friend NeverDestroyed<MockRealtimeMediaSourceCenter>; |
| 69 | |
| 70 | AudioCaptureFactory& audioCaptureFactory(); |
| 71 | VideoCaptureFactory& videoCaptureFactory(); |
| 72 | DisplayCaptureFactory& displayCaptureFactory(); |
| 73 | |
| 74 | class MockAudioCaptureDeviceManager final : public CaptureDeviceManager { |
| 75 | private: |
| 76 | const Vector<CaptureDevice>& captureDevices() final { return MockRealtimeMediaSourceCenter::audioDevices(); } |
| 77 | Optional<CaptureDevice> captureDeviceWithPersistentID(CaptureDevice::DeviceType type, const String& id) final { return MockRealtimeMediaSourceCenter::captureDeviceWithPersistentID(type, id); } |
| 78 | }; |
| 79 | class MockVideoCaptureDeviceManager final : public CaptureDeviceManager { |
| 80 | private: |
| 81 | const Vector<CaptureDevice>& captureDevices() final { return MockRealtimeMediaSourceCenter::videoDevices(); } |
| 82 | Optional<CaptureDevice> captureDeviceWithPersistentID(CaptureDevice::DeviceType type, const String& id) final { return MockRealtimeMediaSourceCenter::captureDeviceWithPersistentID(type, id); } |
| 83 | }; |
| 84 | class MockDisplayCaptureDeviceManager final : public CaptureDeviceManager { |
| 85 | private: |
| 86 | const Vector<CaptureDevice>& captureDevices() final { return MockRealtimeMediaSourceCenter::displayDevices(); } |
| 87 | Optional<CaptureDevice> captureDeviceWithPersistentID(CaptureDevice::DeviceType type, const String& id) final { return MockRealtimeMediaSourceCenter::captureDeviceWithPersistentID(type, id); } |
| 88 | }; |
| 89 | |
| 90 | MockAudioCaptureDeviceManager m_audioCaptureDeviceManager; |
| 91 | MockVideoCaptureDeviceManager m_videoCaptureDeviceManager; |
| 92 | MockDisplayCaptureDeviceManager m_displayCaptureDeviceManager; |
| 93 | |
| 94 | bool m_isMockAudioCaptureEnabled { true }; |
| 95 | bool m_isMockVideoCaptureEnabled { true }; |
| 96 | bool m_isMockDisplayCaptureEnabled { true }; |
| 97 | }; |
| 98 | |
| 99 | } |
| 100 | |
| 101 | #endif // MockRealtimeMediaSourceCenter_h |
| 102 | |