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 | * |
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 Google Inc. 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 | #include "config.h" |
32 | |
33 | #if ENABLE(MEDIA_STREAM) |
34 | #include "RealtimeMediaSourceSettings.h" |
35 | |
36 | #include <wtf/NeverDestroyed.h> |
37 | #include <wtf/text/StringBuilder.h> |
38 | |
39 | namespace WebCore { |
40 | |
41 | String RealtimeMediaSourceSettings::facingMode(RealtimeMediaSourceSettings::VideoFacingMode mode) |
42 | { |
43 | static const NeverDestroyed<String> values[] = { |
44 | MAKE_STATIC_STRING_IMPL("unknown" ), |
45 | MAKE_STATIC_STRING_IMPL("user" ), |
46 | MAKE_STATIC_STRING_IMPL("environment" ), |
47 | MAKE_STATIC_STRING_IMPL("left" ), |
48 | MAKE_STATIC_STRING_IMPL("right" ), |
49 | }; |
50 | static_assert(static_cast<size_t>(RealtimeMediaSourceSettings::VideoFacingMode::Unknown) == 0, "RealtimeMediaSourceSettings::VideoFacingMode::Unknown is not 0 as expected" ); |
51 | static_assert(static_cast<size_t>(RealtimeMediaSourceSettings::VideoFacingMode::User) == 1, "RealtimeMediaSourceSettings::VideoFacingMode::User is not 1 as expected" ); |
52 | static_assert(static_cast<size_t>(RealtimeMediaSourceSettings::VideoFacingMode::Environment) == 2, "RealtimeMediaSourceSettings::VideoFacingMode::Environment is not 2 as expected" ); |
53 | static_assert(static_cast<size_t>(RealtimeMediaSourceSettings::VideoFacingMode::Left) == 3, "RealtimeMediaSourceSettings::VideoFacingMode::Left is not 3 as expected" ); |
54 | static_assert(static_cast<size_t>(RealtimeMediaSourceSettings::VideoFacingMode::Right) == 4, "RealtimeMediaSourceSettings::VideoFacingMode::Right is not 4 as expected" ); |
55 | ASSERT(static_cast<size_t>(mode) < WTF_ARRAY_LENGTH(values)); |
56 | return values[static_cast<size_t>(mode)]; |
57 | } |
58 | |
59 | RealtimeMediaSourceSettings::VideoFacingMode RealtimeMediaSourceSettings::videoFacingModeEnum(const String& mode) |
60 | { |
61 | if (mode == "user" ) |
62 | return RealtimeMediaSourceSettings::VideoFacingMode::User; |
63 | if (mode == "environment" ) |
64 | return RealtimeMediaSourceSettings::VideoFacingMode::Environment; |
65 | if (mode == "left" ) |
66 | return RealtimeMediaSourceSettings::VideoFacingMode::Left; |
67 | if (mode == "right" ) |
68 | return RealtimeMediaSourceSettings::VideoFacingMode::Right; |
69 | |
70 | return RealtimeMediaSourceSettings::Unknown; |
71 | } |
72 | |
73 | String RealtimeMediaSourceSettings::convertFlagsToString(const OptionSet<RealtimeMediaSourceSettings::Flag> flags) |
74 | { |
75 | StringBuilder builder; |
76 | |
77 | builder.append("[ " ); |
78 | for (auto flag : flags) { |
79 | if (!builder.isEmpty()) |
80 | builder.append(", " ); |
81 | |
82 | switch (flag) { |
83 | case RealtimeMediaSourceSettings::Width: |
84 | builder.append("Width" ); |
85 | break; |
86 | case RealtimeMediaSourceSettings::Height: |
87 | builder.append("Height" ); |
88 | break; |
89 | case RealtimeMediaSourceSettings::AspectRatio: |
90 | builder.append("AspectRatio" ); |
91 | break; |
92 | case RealtimeMediaSourceSettings::FrameRate: |
93 | builder.append("FrameRate" ); |
94 | break; |
95 | case RealtimeMediaSourceSettings::FacingMode: |
96 | builder.append("FacingMode" ); |
97 | break; |
98 | case RealtimeMediaSourceSettings::Volume: |
99 | builder.append("Volume" ); |
100 | break; |
101 | case RealtimeMediaSourceSettings::SampleRate: |
102 | builder.append("SampleRate" ); |
103 | break; |
104 | case RealtimeMediaSourceSettings::SampleSize: |
105 | builder.append("SampleSize" ); |
106 | break; |
107 | case RealtimeMediaSourceSettings::EchoCancellation: |
108 | builder.append("EchoCancellation" ); |
109 | break; |
110 | case RealtimeMediaSourceSettings::DeviceId: |
111 | builder.append("DeviceId" ); |
112 | break; |
113 | case RealtimeMediaSourceSettings::GroupId: |
114 | builder.append("GroupId" ); |
115 | break; |
116 | case RealtimeMediaSourceSettings::Label: |
117 | builder.append("Label" ); |
118 | break; |
119 | case RealtimeMediaSourceSettings::DisplaySurface: |
120 | builder.append("DisplaySurface" ); |
121 | break; |
122 | case RealtimeMediaSourceSettings::LogicalSurface: |
123 | builder.append("LogicalSurface" ); |
124 | break; |
125 | } |
126 | } |
127 | builder.append(" ]" ); |
128 | |
129 | return builder.toString(); |
130 | } |
131 | |
132 | OptionSet<RealtimeMediaSourceSettings::Flag> RealtimeMediaSourceSettings::difference(const RealtimeMediaSourceSettings& that) const |
133 | { |
134 | OptionSet<RealtimeMediaSourceSettings::Flag> difference; |
135 | |
136 | if (width() != that.width()) |
137 | difference.add(RealtimeMediaSourceSettings::Width); |
138 | if (height() != that.height()) |
139 | difference.add(RealtimeMediaSourceSettings::Height); |
140 | if (aspectRatio() != that.aspectRatio()) |
141 | difference.add(RealtimeMediaSourceSettings::AspectRatio); |
142 | if (frameRate() != that.frameRate()) |
143 | difference.add(RealtimeMediaSourceSettings::FrameRate); |
144 | if (facingMode() != that.facingMode()) |
145 | difference.add(RealtimeMediaSourceSettings::FacingMode); |
146 | if (volume() != that.volume()) |
147 | difference.add(RealtimeMediaSourceSettings::Volume); |
148 | if (sampleRate() != that.sampleRate()) |
149 | difference.add(RealtimeMediaSourceSettings::SampleRate); |
150 | if (sampleSize() != that.sampleSize()) |
151 | difference.add(RealtimeMediaSourceSettings::SampleSize); |
152 | if (echoCancellation() != that.echoCancellation()) |
153 | difference.add(RealtimeMediaSourceSettings::EchoCancellation); |
154 | if (deviceId() != that.deviceId()) |
155 | difference.add(RealtimeMediaSourceSettings::DeviceId); |
156 | if (groupId() != that.groupId()) |
157 | difference.add(RealtimeMediaSourceSettings::GroupId); |
158 | if (label() != that.label()) |
159 | difference.add(RealtimeMediaSourceSettings::Label); |
160 | if (displaySurface() != that.displaySurface()) |
161 | difference.add(RealtimeMediaSourceSettings::DisplaySurface); |
162 | if (logicalSurface() != that.logicalSurface()) |
163 | difference.add(RealtimeMediaSourceSettings::LogicalSurface); |
164 | |
165 | return difference; |
166 | } |
167 | |
168 | String convertEnumerationToString(RealtimeMediaSourceSettings::VideoFacingMode enumerationValue) |
169 | { |
170 | static const NeverDestroyed<String> values[] = { |
171 | MAKE_STATIC_STRING_IMPL("Unknown" ), |
172 | MAKE_STATIC_STRING_IMPL("User" ), |
173 | MAKE_STATIC_STRING_IMPL("Environment" ), |
174 | MAKE_STATIC_STRING_IMPL("Left" ), |
175 | MAKE_STATIC_STRING_IMPL("Right" ), |
176 | }; |
177 | static_assert(static_cast<size_t>(RealtimeMediaSourceSettings::VideoFacingMode::Unknown) == 0, "RealtimeMediaSourceSettings::VideoFacingMode::Unknown is not 0 as expected" ); |
178 | static_assert(static_cast<size_t>(RealtimeMediaSourceSettings::VideoFacingMode::User) == 1, "RealtimeMediaSourceSettings::VideoFacingMode::User is not 1 as expected" ); |
179 | static_assert(static_cast<size_t>(RealtimeMediaSourceSettings::VideoFacingMode::Environment) == 2, "RealtimeMediaSourceSettings::VideoFacingMode::Environment is not 2 as expected" ); |
180 | static_assert(static_cast<size_t>(RealtimeMediaSourceSettings::VideoFacingMode::Left) == 3, "RealtimeMediaSourceSettings::VideoFacingMode::Left is not 3 as expected" ); |
181 | static_assert(static_cast<size_t>(RealtimeMediaSourceSettings::VideoFacingMode::Right) == 4, "RealtimeMediaSourceSettings::VideoFacingMode::Right is not 4 as expected" ); |
182 | ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values)); |
183 | return values[static_cast<size_t>(enumerationValue)]; |
184 | } |
185 | |
186 | } // namespace WebCore |
187 | |
188 | #endif // ENABLE(MEDIA_STREAM) |
189 | |