121a7f17430ece12495473abd405539a7f0f15bb
[WebKit-https.git] / Source / WebCore / platform / mediastream / RealtimeMediaSourceCenter.h
1 /*
2  * Copyright (C) 2011 Ericsson AB. All rights reserved.
3  * Copyright (C) 2012 Google Inc. All rights reserved.
4  * Copyright (C) 2013-2016 Apple Inc. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer
14  *    in the documentation and/or other materials provided with the
15  *    distribution.
16  * 3. Neither the name of Ericsson nor the names of its contributors
17  *    may be used to endorse or promote products derived from this
18  *    software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #pragma once
34
35 #if ENABLE(MEDIA_STREAM)
36
37 #include "ExceptionOr.h"
38 #include "RealtimeMediaSource.h"
39 #include "RealtimeMediaSourceSupportedConstraints.h"
40 #include <wtf/Function.h>
41 #include <wtf/RefPtr.h>
42 #include <wtf/text/WTFString.h>
43
44 namespace WebCore {
45
46 class CaptureDevice;
47 class CaptureDeviceManager;
48 class RealtimeMediaSourceSettings;
49 class RealtimeMediaSourceSupportedConstraints;
50 class TrackSourceInfo;
51
52 struct MediaConstraints;
53     
54 class RealtimeMediaSourceCenter {
55 public:
56     virtual ~RealtimeMediaSourceCenter();
57
58     WEBCORE_EXPORT static RealtimeMediaSourceCenter& singleton();
59     static void setSharedStreamCenterOverride(RealtimeMediaSourceCenter*);
60
61     using ValidConstraintsHandler = WTF::Function<void(Vector<String>&& audioDeviceUIDs, Vector<String>&& videoDeviceUIDs, String&&)>;
62     using InvalidConstraintsHandler = WTF::Function<void(const String& invalidConstraint)>;
63     virtual void validateRequestConstraints(ValidConstraintsHandler&&, InvalidConstraintsHandler&&, const MediaConstraints& audioConstraints, const MediaConstraints& videoConstraints, String&&);
64
65     using NewMediaStreamHandler = std::function<void(RefPtr<MediaStreamPrivate>&&)>;
66     virtual void createMediaStream(NewMediaStreamHandler&&, const String& audioDeviceID, const String& videoDeviceID, const MediaConstraints* audioConstraints, const MediaConstraints* videoConstraints);
67
68     WEBCORE_EXPORT virtual Vector<CaptureDevice> getMediaStreamDevices();
69     
70     const RealtimeMediaSourceSupportedConstraints& supportedConstraints() { return m_supportedConstraints; }
71
72     virtual RealtimeMediaSource::AudioCaptureFactory& defaultAudioFactory() = 0;
73     virtual RealtimeMediaSource::VideoCaptureFactory& defaultVideoFactory() = 0;
74
75     virtual CaptureDeviceManager& defaultAudioCaptureDeviceManager() = 0;
76     virtual CaptureDeviceManager& defaultVideoCaptureDeviceManager() = 0;
77
78     WEBCORE_EXPORT void setAudioFactory(RealtimeMediaSource::AudioCaptureFactory&);
79     WEBCORE_EXPORT void unsetAudioFactory(RealtimeMediaSource::AudioCaptureFactory&);
80     WEBCORE_EXPORT RealtimeMediaSource::AudioCaptureFactory& audioFactory();
81
82     WEBCORE_EXPORT void setVideoFactory(RealtimeMediaSource::VideoCaptureFactory&);
83     WEBCORE_EXPORT void unsetVideoFactory(RealtimeMediaSource::VideoCaptureFactory&);
84     WEBCORE_EXPORT RealtimeMediaSource::VideoCaptureFactory& videoFactory();
85
86     WEBCORE_EXPORT void setAudioCaptureDeviceManager(CaptureDeviceManager&);
87     WEBCORE_EXPORT void unsetAudioCaptureDeviceManager(CaptureDeviceManager&);
88     CaptureDeviceManager& audioCaptureDeviceManager();
89
90     WEBCORE_EXPORT void setVideoCaptureDeviceManager(CaptureDeviceManager&);
91     WEBCORE_EXPORT void unsetVideoCaptureDeviceManager(CaptureDeviceManager&);
92     CaptureDeviceManager& videoCaptureDeviceManager();
93
94     String hashStringWithSalt(const String& id, const String& hashSalt);
95     WEBCORE_EXPORT std::optional<CaptureDevice> captureDeviceWithUniqueID(const String& id, const String& hashSalt);
96     WEBCORE_EXPORT ExceptionOr<void> setDeviceEnabled(const String&, bool);
97
98     using DevicesChangedObserverToken = unsigned;
99     DevicesChangedObserverToken addDevicesChangedObserver(std::function<void()>&&);
100     void removeDevicesChangedObserver(DevicesChangedObserverToken);
101     void captureDevicesChanged();
102
103     void setVisibility(bool isVisible);
104
105 protected:
106     RealtimeMediaSourceCenter();
107
108     static RealtimeMediaSourceCenter& platformCenter();
109     RealtimeMediaSourceSupportedConstraints m_supportedConstraints;
110
111     RealtimeMediaSource::AudioCaptureFactory* m_audioFactory { nullptr };
112     RealtimeMediaSource::VideoCaptureFactory* m_videoFactory { nullptr };
113
114     CaptureDeviceManager* m_audioCaptureDeviceManager { nullptr };
115     CaptureDeviceManager* m_videoCaptureDeviceManager { nullptr };
116 };
117
118 } // namespace WebCore
119
120 #endif // ENABLE(MEDIA_STREAM)
121