1 | /* |
2 | * Copyright (C) 2013-2019 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 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #if ENABLE(MEDIA_STREAM) |
29 | |
30 | #include "RealtimeMediaSourceSupportedConstraints.h" |
31 | #include <wtf/OptionSet.h> |
32 | #include <wtf/RefCounted.h> |
33 | #include <wtf/Vector.h> |
34 | #include <wtf/text/AtomicString.h> |
35 | |
36 | namespace WebCore { |
37 | |
38 | class RealtimeMediaSourceSettings { |
39 | public: |
40 | enum VideoFacingMode { Unknown, User, Environment, Left, Right }; |
41 | |
42 | static String facingMode(RealtimeMediaSourceSettings::VideoFacingMode); |
43 | static RealtimeMediaSourceSettings::VideoFacingMode videoFacingModeEnum(const String&); |
44 | |
45 | enum Flag { |
46 | Width = 1 << 0, |
47 | Height = 1 << 1, |
48 | AspectRatio = 1 << 2, |
49 | FrameRate = 1 << 3, |
50 | FacingMode = 1 << 4, |
51 | Volume = 1 << 5, |
52 | SampleRate = 1 << 6, |
53 | SampleSize = 1 << 7, |
54 | EchoCancellation = 1 << 8, |
55 | DeviceId = 1 << 9, |
56 | GroupId = 1 << 10, |
57 | Label = 1 << 11, |
58 | DisplaySurface = 1 << 12, |
59 | LogicalSurface = 1 << 13, |
60 | }; |
61 | |
62 | static constexpr OptionSet<Flag> allFlags() { return { Width, Height, AspectRatio, FrameRate, FacingMode, Volume, SampleRate, SampleSize, EchoCancellation, DeviceId, GroupId, Label, DisplaySurface, LogicalSurface }; } |
63 | |
64 | WEBCORE_EXPORT OptionSet<RealtimeMediaSourceSettings::Flag> difference(const RealtimeMediaSourceSettings&) const; |
65 | |
66 | explicit RealtimeMediaSourceSettings() = default; |
67 | |
68 | bool supportsWidth() const { return m_supportedConstraints.supportsWidth(); } |
69 | uint32_t width() const { return m_width; } |
70 | void setWidth(uint32_t width) { m_width = width; } |
71 | |
72 | bool supportsHeight() const { return m_supportedConstraints.supportsHeight(); } |
73 | uint32_t height() const { return m_height; } |
74 | void setHeight(uint32_t height) { m_height = height; } |
75 | |
76 | bool supportsAspectRatio() const { return m_supportedConstraints.supportsAspectRatio(); } |
77 | float aspectRatio() const { return m_aspectRatio; } |
78 | void setAspectRatio(float aspectRatio) { m_aspectRatio = aspectRatio; } |
79 | |
80 | bool supportsFrameRate() const { return m_supportedConstraints.supportsFrameRate(); } |
81 | float frameRate() const { return m_frameRate; } |
82 | void setFrameRate(float frameRate) { m_frameRate = frameRate; } |
83 | |
84 | bool supportsFacingMode() const { return m_supportedConstraints.supportsFacingMode(); } |
85 | VideoFacingMode facingMode() const { return m_facingMode; } |
86 | void setFacingMode(VideoFacingMode facingMode) { m_facingMode = facingMode; } |
87 | |
88 | bool supportsVolume() const { return m_supportedConstraints.supportsVolume(); } |
89 | double volume() const { return m_volume; } |
90 | void setVolume(double volume) { m_volume = volume; } |
91 | |
92 | bool supportsSampleRate() const { return m_supportedConstraints.supportsSampleRate(); } |
93 | uint32_t sampleRate() const { return m_sampleRate; } |
94 | void setSampleRate(uint32_t sampleRate) { m_sampleRate = sampleRate; } |
95 | |
96 | bool supportsSampleSize() const { return m_supportedConstraints.supportsSampleSize(); } |
97 | uint32_t sampleSize() const { return m_sampleSize; } |
98 | void setSampleSize(uint32_t sampleSize) { m_sampleSize = sampleSize; } |
99 | |
100 | bool supportsEchoCancellation() const { return m_supportedConstraints.supportsEchoCancellation(); } |
101 | bool echoCancellation() const { return m_echoCancellation; } |
102 | void setEchoCancellation(bool echoCancellation) { m_echoCancellation = echoCancellation; } |
103 | |
104 | bool supportsDeviceId() const { return m_supportedConstraints.supportsDeviceId(); } |
105 | const AtomicString& deviceId() const { return m_deviceId; } |
106 | void setDeviceId(const AtomicString& deviceId) { m_deviceId = deviceId; } |
107 | |
108 | bool supportsGroupId() const { return m_supportedConstraints.supportsGroupId(); } |
109 | const AtomicString& groupId() const { return m_groupId; } |
110 | void setGroupId(const AtomicString& groupId) { m_groupId = groupId; } |
111 | |
112 | enum class DisplaySurfaceType { |
113 | Monitor, |
114 | Window, |
115 | Application, |
116 | Browser, |
117 | Invalid, |
118 | }; |
119 | |
120 | bool supportsDisplaySurface() const { return m_supportedConstraints.supportsDisplaySurface(); } |
121 | DisplaySurfaceType displaySurface() const { return m_displaySurface; } |
122 | void setDisplaySurface(DisplaySurfaceType displaySurface) { m_displaySurface = displaySurface; } |
123 | |
124 | bool supportsLogicalSurface() const { return m_supportedConstraints.supportsLogicalSurface(); } |
125 | bool logicalSurface() const { return m_logicalSurface; } |
126 | void setLogicalSurface(bool logicalSurface) { m_logicalSurface = logicalSurface; } |
127 | |
128 | const RealtimeMediaSourceSupportedConstraints& supportedConstraints() const { return m_supportedConstraints; } |
129 | void setSupportedConstraints(const RealtimeMediaSourceSupportedConstraints& supportedConstraints) { m_supportedConstraints = supportedConstraints; } |
130 | |
131 | const AtomicString& label() const { return m_label; } |
132 | void setLabel(const AtomicString& label) { m_label = label; } |
133 | |
134 | template<class Encoder> void encode(Encoder&) const; |
135 | template<class Decoder> static bool decode(Decoder&, RealtimeMediaSourceSettings&); |
136 | |
137 | static String convertFlagsToString(const OptionSet<RealtimeMediaSourceSettings::Flag>); |
138 | |
139 | private: |
140 | uint32_t m_width { 0 }; |
141 | uint32_t m_height { 0 }; |
142 | float m_aspectRatio { 0 }; |
143 | float m_frameRate { 0 }; |
144 | VideoFacingMode m_facingMode { Unknown }; |
145 | double m_volume { 0 }; |
146 | uint32_t m_sampleRate { 0 }; |
147 | uint32_t m_sampleSize { 0 }; |
148 | bool m_echoCancellation { 0 }; |
149 | |
150 | AtomicString m_deviceId; |
151 | AtomicString m_groupId; |
152 | AtomicString m_label; |
153 | |
154 | DisplaySurfaceType m_displaySurface { DisplaySurfaceType::Invalid }; |
155 | bool m_logicalSurface { 0 }; |
156 | |
157 | RealtimeMediaSourceSupportedConstraints m_supportedConstraints; |
158 | }; |
159 | |
160 | template<class Encoder> |
161 | void RealtimeMediaSourceSettings::encode(Encoder& encoder) const |
162 | { |
163 | encoder << m_width |
164 | << m_height |
165 | << m_aspectRatio |
166 | << m_frameRate |
167 | << m_volume |
168 | << m_sampleRate |
169 | << m_sampleSize |
170 | << m_echoCancellation |
171 | << m_deviceId |
172 | << m_groupId |
173 | << m_label |
174 | << m_supportedConstraints; |
175 | encoder.encodeEnum(m_facingMode); |
176 | } |
177 | |
178 | template<class Decoder> |
179 | bool RealtimeMediaSourceSettings::decode(Decoder& decoder, RealtimeMediaSourceSettings& settings) |
180 | { |
181 | return decoder.decode(settings.m_width) |
182 | && decoder.decode(settings.m_height) |
183 | && decoder.decode(settings.m_aspectRatio) |
184 | && decoder.decode(settings.m_frameRate) |
185 | && decoder.decode(settings.m_volume) |
186 | && decoder.decode(settings.m_sampleRate) |
187 | && decoder.decode(settings.m_sampleSize) |
188 | && decoder.decode(settings.m_echoCancellation) |
189 | && decoder.decode(settings.m_deviceId) |
190 | && decoder.decode(settings.m_groupId) |
191 | && decoder.decode(settings.m_label) |
192 | && decoder.decode(settings.m_supportedConstraints) |
193 | && decoder.decodeEnum(settings.m_facingMode); |
194 | } |
195 | |
196 | String convertEnumerationToString(RealtimeMediaSourceSettings::VideoFacingMode); |
197 | |
198 | } // namespace WebCore |
199 | |
200 | namespace WTF { |
201 | |
202 | template <> struct EnumTraits<WebCore::RealtimeMediaSourceSettings::VideoFacingMode> { |
203 | using values = EnumValues< |
204 | WebCore::RealtimeMediaSourceSettings::VideoFacingMode, |
205 | WebCore::RealtimeMediaSourceSettings::VideoFacingMode::Unknown, |
206 | WebCore::RealtimeMediaSourceSettings::VideoFacingMode::User, |
207 | WebCore::RealtimeMediaSourceSettings::VideoFacingMode::Environment, |
208 | WebCore::RealtimeMediaSourceSettings::VideoFacingMode::Left, |
209 | WebCore::RealtimeMediaSourceSettings::VideoFacingMode::Right |
210 | >; |
211 | }; |
212 | |
213 | template<typename Type> |
214 | struct LogArgument; |
215 | |
216 | template <> |
217 | struct LogArgument<WebCore::RealtimeMediaSourceSettings::VideoFacingMode> { |
218 | static String toString(const WebCore::RealtimeMediaSourceSettings::VideoFacingMode mode) |
219 | { |
220 | return convertEnumerationToString(mode); |
221 | } |
222 | }; |
223 | |
224 | template <> |
225 | struct LogArgument<OptionSet<WebCore::RealtimeMediaSourceSettings::Flag>> { |
226 | static String toString(const OptionSet<WebCore::RealtimeMediaSourceSettings::Flag> flags) |
227 | { |
228 | return WebCore::RealtimeMediaSourceSettings::convertFlagsToString(flags); |
229 | } |
230 | }; |
231 | |
232 | }; // namespace WTF |
233 | |
234 | #endif |
235 | |