3aadd246d3307b3b99ba53b6490965603b8ddc5b
[WebKit-https.git] / Source / WebCore / platform / mediastream / RealtimeMediaSourceSettings.cpp
1 /*
2  * Copyright (C) 2013-2015 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
38 namespace WebCore {
39
40 String RealtimeMediaSourceSettings::facingMode(RealtimeMediaSourceSettings::VideoFacingMode mode)
41 {
42     static const NeverDestroyed<String> values[] = {
43         MAKE_STATIC_STRING_IMPL("unknown"),
44         MAKE_STATIC_STRING_IMPL("user"),
45         MAKE_STATIC_STRING_IMPL("environment"),
46         MAKE_STATIC_STRING_IMPL("left"),
47         MAKE_STATIC_STRING_IMPL("right"),
48     };
49     static_assert(static_cast<size_t>(RealtimeMediaSourceSettings::VideoFacingMode::Unknown) == 0, "RealtimeMediaSourceSettings::VideoFacingMode::Unknown is not 0 as expected");
50     static_assert(static_cast<size_t>(RealtimeMediaSourceSettings::VideoFacingMode::User) == 1, "RealtimeMediaSourceSettings::VideoFacingMode::User is not 1 as expected");
51     static_assert(static_cast<size_t>(RealtimeMediaSourceSettings::VideoFacingMode::Environment) == 2, "RealtimeMediaSourceSettings::VideoFacingMode::Environment is not 2 as expected");
52     static_assert(static_cast<size_t>(RealtimeMediaSourceSettings::VideoFacingMode::Left) == 3, "RealtimeMediaSourceSettings::VideoFacingMode::Left is not 3 as expected");
53     static_assert(static_cast<size_t>(RealtimeMediaSourceSettings::VideoFacingMode::Right) == 4, "RealtimeMediaSourceSettings::VideoFacingMode::Right is not 4 as expected");
54     ASSERT(static_cast<size_t>(mode) < WTF_ARRAY_LENGTH(values));
55     return values[static_cast<size_t>(mode)];
56 }
57
58 RealtimeMediaSourceSettings::VideoFacingMode RealtimeMediaSourceSettings::videoFacingModeEnum(const String& mode)
59 {
60     if (mode == "user")
61         return RealtimeMediaSourceSettings::VideoFacingMode::User;
62     if (mode == "environment")
63         return RealtimeMediaSourceSettings::VideoFacingMode::Environment;
64     if (mode == "left")
65         return RealtimeMediaSourceSettings::VideoFacingMode::Left;
66     if (mode == "right")
67         return RealtimeMediaSourceSettings::VideoFacingMode::Right;
68
69     return RealtimeMediaSourceSettings::Unknown;
70 }
71
72 OptionSet<RealtimeMediaSourceSettings::Flag> RealtimeMediaSourceSettings::difference(const RealtimeMediaSourceSettings& that) const
73 {
74     OptionSet<RealtimeMediaSourceSettings::Flag> difference;
75
76     if (width() != that.width())
77         difference.add(RealtimeMediaSourceSettings::Width);
78     if (height() != that.height())
79         difference.add(RealtimeMediaSourceSettings::Height);
80     if (aspectRatio() != that.aspectRatio())
81         difference.add(RealtimeMediaSourceSettings::AspectRatio);
82     if (frameRate() != that.frameRate())
83         difference.add(RealtimeMediaSourceSettings::FrameRate);
84     if (facingMode() != that.facingMode())
85         difference.add(RealtimeMediaSourceSettings::FacingMode);
86     if (volume() != that.volume())
87         difference.add(RealtimeMediaSourceSettings::Volume);
88     if (sampleRate() != that.sampleRate())
89         difference.add(RealtimeMediaSourceSettings::SampleRate);
90     if (sampleSize() != that.sampleSize())
91         difference.add(RealtimeMediaSourceSettings::SampleSize);
92     if (echoCancellation() != that.echoCancellation())
93         difference.add(RealtimeMediaSourceSettings::EchoCancellation);
94     if (deviceId() != that.deviceId())
95         difference.add(RealtimeMediaSourceSettings::DeviceId);
96     if (groupId() != that.groupId())
97         difference.add(RealtimeMediaSourceSettings::GroupId);
98     if (label() != that.label())
99         difference.add(RealtimeMediaSourceSettings::Label);
100     if (displaySurface() != that.displaySurface())
101         difference.add(RealtimeMediaSourceSettings::DisplaySurface);
102     if (logicalSurface() != that.logicalSurface())
103         difference.add(RealtimeMediaSourceSettings::LogicalSurface);
104
105     return difference;
106 }
107
108
109 } // namespace WebCore
110
111 #endif // ENABLE(MEDIA_STREAM)