1 | /* |
2 | * Copyright (C) 2015-2018 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * |
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 |
12 | * in the documentation and/or other materials provided with the |
13 | * distribution. |
14 | * 3. Neither the name of Ericsson nor the names of its contributors |
15 | * may be used to endorse or promote products derived from this |
16 | * software without specific prior written permission. |
17 | * |
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | */ |
30 | |
31 | #ifndef MockRealtimeVideoSource_h |
32 | #define MockRealtimeVideoSource_h |
33 | |
34 | #if ENABLE(MEDIA_STREAM) |
35 | |
36 | #include "FontCascade.h" |
37 | #include "ImageBuffer.h" |
38 | #include "MockMediaDevice.h" |
39 | #include "RealtimeMediaSourceFactory.h" |
40 | #include "RealtimeVideoSource.h" |
41 | #include <wtf/RunLoop.h> |
42 | |
43 | namespace WebCore { |
44 | |
45 | class FloatRect; |
46 | class GraphicsContext; |
47 | |
48 | class MockRealtimeVideoSource : public RealtimeVideoSource { |
49 | public: |
50 | |
51 | static CaptureSourceOrError create(String&& deviceID, String&& name, String&& hashSalt, const MediaConstraints*); |
52 | |
53 | protected: |
54 | MockRealtimeVideoSource(String&& deviceID, String&& name, String&& hashSalt); |
55 | |
56 | virtual void updateSampleBuffer() = 0; |
57 | |
58 | void setCurrentFrame(MediaSample&); |
59 | ImageBuffer* imageBuffer() const; |
60 | |
61 | Seconds elapsedTime(); |
62 | void settingsDidChange(OptionSet<RealtimeMediaSourceSettings::Flag>) override; |
63 | |
64 | private: |
65 | const RealtimeMediaSourceCapabilities& capabilities() final; |
66 | const RealtimeMediaSourceSettings& settings() final; |
67 | |
68 | void startProducingData() final; |
69 | void stopProducingData() final; |
70 | bool isCaptureSource() const final { return true; } |
71 | CaptureDevice::DeviceType deviceType() const final { return CaptureDevice::DeviceType::Camera; } |
72 | bool supportsSizeAndFrameRate(Optional<int> width, Optional<int> height, Optional<double>) final; |
73 | void setSizeAndFrameRate(Optional<int> width, Optional<int> height, Optional<double>) final; |
74 | void setFrameRateWithPreset(double, RefPtr<VideoPreset>) final; |
75 | IntSize captureSize() const; |
76 | |
77 | void generatePresets() final; |
78 | |
79 | void drawAnimation(GraphicsContext&); |
80 | void drawText(GraphicsContext&); |
81 | void drawBoxes(GraphicsContext&); |
82 | |
83 | void generateFrame(); |
84 | void startCaptureTimer(); |
85 | |
86 | void delaySamples(Seconds) override; |
87 | |
88 | bool mockCamera() const { return WTF::holds_alternative<MockCameraProperties>(m_device.properties); } |
89 | bool mockDisplay() const { return WTF::holds_alternative<MockDisplayProperties>(m_device.properties); } |
90 | bool mockScreen() const { return mockDisplayType(CaptureDevice::DeviceType::Screen); } |
91 | bool mockWindow() const { return mockDisplayType(CaptureDevice::DeviceType::Window); } |
92 | bool mockDisplayType(CaptureDevice::DeviceType) const; |
93 | |
94 | float m_baseFontSize { 0 }; |
95 | float m_bipBopFontSize { 0 }; |
96 | float m_statsFontSize { 0 }; |
97 | |
98 | mutable std::unique_ptr<ImageBuffer> m_imageBuffer; |
99 | |
100 | Path m_path; |
101 | DashArray m_dashWidths; |
102 | |
103 | MonotonicTime m_startTime { MonotonicTime::nan() }; |
104 | Seconds m_elapsedTime { 0_s }; |
105 | MonotonicTime m_delayUntil; |
106 | |
107 | unsigned { 0 }; |
108 | RunLoop::Timer<MockRealtimeVideoSource> m_emitFrameTimer; |
109 | Optional<RealtimeMediaSourceCapabilities> m_capabilities; |
110 | Optional<RealtimeMediaSourceSettings> m_currentSettings; |
111 | RealtimeMediaSourceSupportedConstraints m_supportedConstraints; |
112 | Color m_fillColor { Color::black }; |
113 | MockMediaDevice m_device; |
114 | RefPtr<VideoPreset> m_preset; |
115 | }; |
116 | |
117 | } // namespace WebCore |
118 | |
119 | #endif // ENABLE(MEDIA_STREAM) |
120 | |
121 | #endif // MockRealtimeVideoSource_h |
122 | |