| 1 | /* |
| 2 | * Copyright (C) 2011 Ericsson AB. All rights reserved. |
| 3 | * Copyright (C) 2012 Google Inc. All rights reserved. |
| 4 | * Copyright (C) 2013-2018 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 "MediaStreamRequest.h" |
| 39 | #include "RealtimeMediaSource.h" |
| 40 | #include "RealtimeMediaSourceFactory.h" |
| 41 | #include "RealtimeMediaSourceSupportedConstraints.h" |
| 42 | #include <wtf/Function.h> |
| 43 | #include <wtf/RefPtr.h> |
| 44 | #include <wtf/text/WTFString.h> |
| 45 | |
| 46 | namespace WebCore { |
| 47 | |
| 48 | class CaptureDevice; |
| 49 | class CaptureDeviceManager; |
| 50 | class RealtimeMediaSourceSettings; |
| 51 | class RealtimeMediaSourceSupportedConstraints; |
| 52 | class TrackSourceInfo; |
| 53 | |
| 54 | struct MediaConstraints; |
| 55 | |
| 56 | class RealtimeMediaSourceCenter { |
| 57 | public: |
| 58 | ~RealtimeMediaSourceCenter(); |
| 59 | |
| 60 | WEBCORE_EXPORT static RealtimeMediaSourceCenter& singleton(); |
| 61 | |
| 62 | using ValidConstraintsHandler = WTF::Function<void(Vector<CaptureDevice>&& audioDeviceUIDs, Vector<CaptureDevice>&& videoDeviceUIDs, String&&)>; |
| 63 | using InvalidConstraintsHandler = WTF::Function<void(const String& invalidConstraint)>; |
| 64 | WEBCORE_EXPORT void validateRequestConstraints(ValidConstraintsHandler&&, InvalidConstraintsHandler&&, const MediaStreamRequest&, String&&); |
| 65 | |
| 66 | using NewMediaStreamHandler = WTF::Function<void(RefPtr<MediaStreamPrivate>&&)>; |
| 67 | void createMediaStream(NewMediaStreamHandler&&, String&&, CaptureDevice&& audioDevice, CaptureDevice&& videoDevice, const MediaStreamRequest&); |
| 68 | |
| 69 | WEBCORE_EXPORT Vector<CaptureDevice> getMediaStreamDevices(); |
| 70 | |
| 71 | const RealtimeMediaSourceSupportedConstraints& supportedConstraints() { return m_supportedConstraints; } |
| 72 | |
| 73 | WEBCORE_EXPORT AudioCaptureFactory& audioCaptureFactory(); |
| 74 | WEBCORE_EXPORT void setAudioCaptureFactory(AudioCaptureFactory&); |
| 75 | WEBCORE_EXPORT void unsetAudioCaptureFactory(AudioCaptureFactory&); |
| 76 | |
| 77 | WEBCORE_EXPORT VideoCaptureFactory& videoCaptureFactory(); |
| 78 | WEBCORE_EXPORT void setVideoCaptureFactory(VideoCaptureFactory&); |
| 79 | WEBCORE_EXPORT void unsetVideoCaptureFactory(VideoCaptureFactory&); |
| 80 | |
| 81 | WEBCORE_EXPORT DisplayCaptureFactory& displayCaptureFactory(); |
| 82 | WEBCORE_EXPORT void setDisplayCaptureFactory(DisplayCaptureFactory&); |
| 83 | WEBCORE_EXPORT void unsetDisplayCaptureFactory(DisplayCaptureFactory&); |
| 84 | |
| 85 | WEBCORE_EXPORT String hashStringWithSalt(const String& id, const String& hashSalt); |
| 86 | |
| 87 | WEBCORE_EXPORT void setDevicesChangedObserver(std::function<void()>&&); |
| 88 | |
| 89 | void setVideoCapturePageState(bool, bool); |
| 90 | |
| 91 | void captureDevicesChanged(); |
| 92 | |
| 93 | private: |
| 94 | RealtimeMediaSourceCenter(); |
| 95 | friend class NeverDestroyed<RealtimeMediaSourceCenter>; |
| 96 | |
| 97 | AudioCaptureFactory& defaultAudioCaptureFactory(); |
| 98 | VideoCaptureFactory& defaultVideoCaptureFactory(); |
| 99 | DisplayCaptureFactory& defaultDisplayCaptureFactory(); |
| 100 | |
| 101 | struct DeviceInfo { |
| 102 | unsigned fitnessScore; |
| 103 | CaptureDevice device; |
| 104 | }; |
| 105 | |
| 106 | void getDisplayMediaDevices(const MediaStreamRequest&, Vector<DeviceInfo>&, String&); |
| 107 | void getUserMediaDevices(const MediaStreamRequest&, String&&, Vector<DeviceInfo>& audioDevices, Vector<DeviceInfo>& videoDevices, String&); |
| 108 | |
| 109 | RealtimeMediaSourceSupportedConstraints m_supportedConstraints; |
| 110 | |
| 111 | WTF::Function<void()> m_deviceChangedObserver; |
| 112 | |
| 113 | AudioCaptureFactory* m_audioCaptureFactoryOverride { nullptr }; |
| 114 | VideoCaptureFactory* m_videoCaptureFactoryOverride { nullptr }; |
| 115 | DisplayCaptureFactory* m_displayCaptureFactoryOverride { nullptr }; |
| 116 | }; |
| 117 | |
| 118 | } // namespace WebCore |
| 119 | |
| 120 | #endif // ENABLE(MEDIA_STREAM) |
| 121 | |
| 122 | |