Changeset 260561 in webkit
- Timestamp:
- Apr 23, 2020 1:59:31 AM (4 years ago)
- Location:
- trunk
- Files:
-
- 9 added
- 15 edited
- 4 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r260559 r260561 1 2020-04-23 Youenn Fablet <youenn@apple.com> 2 3 getDisplayMedia is not respecting aspect ratio with max constraints 4 https://bugs.webkit.org/show_bug.cgi?id=210858 5 6 Reviewed by Eric Carlson. 7 8 * fast/mediastream/getDisplayMedia-max-constraints-expected.txt: Added. 9 * fast/mediastream/getDisplayMedia-max-constraints.html: Added. 10 * fast/mediastream/getDisplayMedia-max-constraints1-expected.txt: Added. 11 * fast/mediastream/getDisplayMedia-max-constraints1.html: Added. 12 * fast/mediastream/getDisplayMedia-max-constraints2-expected.txt: Added. 13 * fast/mediastream/getDisplayMedia-max-constraints2.html: Added. 14 * fast/mediastream/getDisplayMedia-max-constraints3-expected.txt: Added. 15 * fast/mediastream/getDisplayMedia-max-constraints3.html: Added. 16 * fast/mediastream/resources/getDisplayMedia-utils.js: Added. 17 (async callGetDisplayMedia): 18 (async waitForHeight): 19 (async waitForWidth): 20 * platform/ios/TestExpectations: 21 Skip new tests as getDisplayMedia is not supported on iOS. 22 1 23 2020-04-23 Diego Pino Garcia <dpino@igalia.com> 2 24 -
trunk/LayoutTests/fast/mediastream/constraint-intrinsic-size.html
r253033 r260561 6 6 <script src="../../resources/testharness.js"></script> 7 7 <script src="../../resources/testharnessreport.js"></script> 8 <script src="resources/getDisplayMedia-utils.js"></script> 8 9 </head> 9 10 <body> 10 11 11 12 <script> 12 if (window.internals)13 window.internals.settings.setScreenCaptureEnabled(true);14 15 function callGetDisplayMedia(options)16 {17 let promise;18 window.internals.withUserGesture(() => {19 promise = navigator.mediaDevices.getDisplayMedia(options);20 });21 return promise;22 }23 24 13 let defaultWidth; 25 14 let defaultHeight; -
trunk/LayoutTests/platform/ios/TestExpectations
r260388 r260561 2896 2896 # screen capture not supported on iOS. 2897 2897 fast/mediastream/screencapture-user-gesture.html [ Skip ] 2898 fast/mediastream/getDisplayMedia-max-constraints1.html [ Skip ] 2899 fast/mediastream/getDisplayMedia-max-constraints2.html [ Skip ] 2900 fast/mediastream/getDisplayMedia-max-constraints3.html [ Skip ] 2898 2901 2899 2902 webkit.org/b/177401 webrtc/captureCanvas-webrtc.html [ Pass Timeout Failure ] -
trunk/Source/WebCore/ChangeLog
r260557 r260561 1 2020-04-23 Youenn Fablet <youenn@apple.com> 2 3 getDisplayMedia is not respecting aspect ratio with max constraints 4 https://bugs.webkit.org/show_bug.cgi?id=210858 5 6 Reviewed by Eric Carlson. 7 8 Add computation of exact frame size to respect aspect ratio in DisplayCaptureSourceCocoa::updateFrameSize. 9 Refactor code to have one source class DisplayCaptureSourceCocoa and specific capturer for screen and window. 10 This simplifies code and allows reusing DisplayCaptureSourceCocoa with a mock capturer. 11 Update mock code to use DisplayCaptureSourceCocoa. 12 13 Tests: fast/mediastream/getDisplayMedia-max-constraints.html 14 fast/mediastream/getDisplayMedia-max-constraints1.html 15 fast/mediastream/getDisplayMedia-max-constraints2.html 16 fast/mediastream/getDisplayMedia-max-constraints3.html 17 18 * SourcesCocoa.txt: 19 * WebCore.xcodeproj/project.pbxproj: 20 * platform/mediastream/mac/DisplayCaptureManagerCocoa.cpp: 21 (WebCore::DisplayCaptureManagerCocoa::updateDisplayCaptureDevices): 22 (WebCore::DisplayCaptureManagerCocoa::updateWindowCaptureDevices): 23 (WebCore::DisplayCaptureManagerCocoa::screenCaptureDeviceWithPersistentID): 24 (WebCore::DisplayCaptureManagerCocoa::windowCaptureDeviceWithPersistentID): 25 * platform/mediastream/mac/DisplayCaptureSourceCocoa.cpp: 26 (WebCore::DisplayCaptureSourceCocoa::create): 27 (WebCore::DisplayCaptureSourceCocoa::DisplayCaptureSourceCocoa): 28 (WebCore::DisplayCaptureSourceCocoa::~DisplayCaptureSourceCocoa): 29 (WebCore::DisplayCaptureSourceCocoa::capabilities): 30 (WebCore::DisplayCaptureSourceCocoa::settings): 31 (WebCore::DisplayCaptureSourceCocoa::startProducingData): 32 (WebCore::DisplayCaptureSourceCocoa::stopProducingData): 33 (WebCore::DisplayCaptureSourceCocoa::updateFrameSize): 34 (WebCore::DisplayCaptureSourceCocoa::emitFrame): 35 (WebCore::DisplayCaptureSourceCocoa::Capturer::setLogger): 36 (WebCore::DisplayCaptureSourceCocoa::Capturer::logChannel const): 37 * platform/mediastream/mac/DisplayCaptureSourceCocoa.h: 38 * platform/mediastream/mac/MockRealtimeVideoSourceMac.h: 39 * platform/mediastream/mac/MockRealtimeVideoSourceMac.mm: 40 (WebCore::MockRealtimeVideoSourceMac::createForMockDisplayCapturer): 41 * platform/mediastream/mac/RealtimeMediaSourceCenterMac.cpp: 42 * platform/mediastream/mac/ScreenDisplayCapturerMac.h: Added. 43 * platform/mediastream/mac/ScreenDisplayCapturerMac.mm: Added. 44 (WebCore::ScreenDisplayCapturerMac::create): 45 (WebCore::ScreenDisplayCapturerMac::ScreenDisplayCapturerMac): 46 (WebCore::ScreenDisplayCapturerMac::~ScreenDisplayCapturerMac): 47 (WebCore::ScreenDisplayCapturerMac::createDisplayStream): 48 (WebCore::ScreenDisplayCapturerMac::start): 49 (WebCore::ScreenDisplayCapturerMac::stop): 50 (WebCore::ScreenDisplayCapturerMac::generateFrame): 51 (WebCore::ScreenDisplayCapturerMac::startDisplayStream): 52 (WebCore::ScreenDisplayCapturerMac::commitConfiguration): 53 (WebCore::ScreenDisplayCapturerMac::displayWasReconfigured): 54 (WebCore::ScreenDisplayCapturerMac::displayReconfigurationCallBack): 55 (WebCore::ScreenDisplayCapturerMac::newFrame): 56 (WebCore::ScreenDisplayCapturerMac::screenCaptureDeviceWithPersistentID): 57 (WebCore::ScreenDisplayCapturerMac::screenCaptureDevices): 58 * platform/mediastream/mac/WindowDisplayCapturerMac.h: Added. 59 * platform/mediastream/mac/WindowDisplayCapturerMac.mm: ddedAdded. 60 (WebCore::WindowDisplayCapturerMac::create): 61 (WebCore::WindowDisplayCapturerMac::WindowDisplayCapturerMac): 62 (WebCore::WindowDisplayCapturerMac::windowImage): 63 (WebCore::WindowDisplayCapturerMac::generateFrame): 64 (WebCore::WindowDisplayCapturerMac::windowCaptureDeviceWithPersistentID): 65 (WebCore::WindowDisplayCapturerMac::windowCaptureDevices): 66 * platform/mock/MockRealtimeMediaSourceCenter.cpp: 67 (WebCore::MockDisplayCapturer::MockDisplayCapturer): 68 (WebCore::MockDisplayCapturer::start): 69 (WebCore::MockDisplayCapturer::generateFrame): 70 * platform/mock/MockRealtimeVideoSource.h: 71 (isType): 72 1 73 2020-04-22 Simon Fraser <simon.fraser@apple.com> 2 74 -
trunk/Source/WebCore/SourcesCocoa.txt
r260102 r260561 571 571 platform/mediastream/mac/RealtimeOutgoingVideoSourceCocoa.cpp 572 572 platform/mediastream/mac/RealtimeVideoUtilities.mm 573 platform/mediastream/mac/ScreenDisplayCapture SourceMac.mm574 platform/mediastream/mac/WindowDisplayCapture SourceMac.mm573 platform/mediastream/mac/ScreenDisplayCapturerMac.mm 574 platform/mediastream/mac/WindowDisplayCapturerMac.mm 575 575 576 576 platform/audio/mac/AudioSampleDataSource.mm -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r260505 r260561 216 216 07CE77D516712A6A00C55A47 /* InbandTextTrackPrivateClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 07CE77D416712A6A00C55A47 /* InbandTextTrackPrivateClient.h */; settings = {ATTRIBUTES = (Private, ); }; }; 217 217 07D12F5C23DE543F0080997D /* ISOVTTCue.h in Headers */ = {isa = PBXBuildFile; fileRef = CD871C651FB52B6700F0B965 /* ISOVTTCue.h */; settings = {ATTRIBUTES = (Private, ); }; }; 218 07D60928214C5BFD00E7396C /* WindowDisplayCaptureSourceMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 07D60926214C5BFC00E7396C /* WindowDisplayCaptureSourceMac.h */; };219 218 07D637401BB0B11300256CE9 /* WebAudioSourceProviderAVFObjC.h in Headers */ = {isa = PBXBuildFile; fileRef = 07D6373E1BB0B11300256CE9 /* WebAudioSourceProviderAVFObjC.h */; settings = {ATTRIBUTES = (Private, ); }; }; 220 219 07D6A4F41BED5F8800174146 /* MockRealtimeAudioSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 07D6A4F21BED5F8800174146 /* MockRealtimeAudioSource.h */; settings = {ATTRIBUTES = (Private, ); }; }; … … 5455 5454 0709D7941AE55A29004E42F8 /* WebMediaSessionManagerClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebMediaSessionManagerClient.h; sourceTree = "<group>"; }; 5456 5455 0709FC4D1025DEE30059CDBA /* AccessibilitySlider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AccessibilitySlider.h; sourceTree = "<group>"; }; 5457 070A9F5E1FFECC70003DF649 /* ScreenDisplayCaptureSourceMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScreenDisplayCaptureSourceMac.h; sourceTree = "<group>"; };5458 070A9F601FFECC71003DF649 /* ScreenDisplayCaptureSourceMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ScreenDisplayCaptureSourceMac.mm; sourceTree = "<group>"; };5459 5456 070DD8F50F01868000727DEB /* mediaControls.css */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = mediaControls.css; sourceTree = "<group>"; }; 5460 5457 070E09181875ED93003A1D3C /* PlatformMediaSession.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformMediaSession.h; sourceTree = "<group>"; }; … … 5668 5665 07C8AD121D073D630087C5CE /* AVAssetMIMETypeCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AVAssetMIMETypeCache.h; sourceTree = "<group>"; }; 5669 5666 07CE77D416712A6A00C55A47 /* InbandTextTrackPrivateClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InbandTextTrackPrivateClient.h; sourceTree = "<group>"; }; 5670 07D60924214C5BFB00E7396C /* WindowDisplayCaptureSourceMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WindowDisplayCaptureSourceMac.mm; sourceTree = "<group>"; };5671 07D60926214C5BFC00E7396C /* WindowDisplayCaptureSourceMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WindowDisplayCaptureSourceMac.h; sourceTree = "<group>"; };5672 5667 07D6373E1BB0B11300256CE9 /* WebAudioSourceProviderAVFObjC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebAudioSourceProviderAVFObjC.h; sourceTree = "<group>"; }; 5673 5668 07D6373F1BB0B11300256CE9 /* WebAudioSourceProviderAVFObjC.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebAudioSourceProviderAVFObjC.mm; sourceTree = "<group>"; }; … … 7450 7445 416E0B37209BC3C2004A95D9 /* FetchIdentifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FetchIdentifier.h; sourceTree = "<group>"; }; 7451 7446 416E29A5102FA962007FC14E /* WorkerReportingProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WorkerReportingProxy.h; sourceTree = "<group>"; }; 7447 416F807924509F3200B68F02 /* WindowDisplayCapturerMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WindowDisplayCapturerMac.h; sourceTree = "<group>"; }; 7448 416F807A24509F3200B68F02 /* ScreenDisplayCapturerMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ScreenDisplayCapturerMac.mm; sourceTree = "<group>"; }; 7449 416F807B24509F3300B68F02 /* WindowDisplayCapturerMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WindowDisplayCapturerMac.mm; sourceTree = "<group>"; }; 7450 416F807C24509F3300B68F02 /* ScreenDisplayCapturerMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScreenDisplayCapturerMac.h; sourceTree = "<group>"; }; 7452 7451 416FD25D240EE1AE006661D8 /* NowPlayingInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NowPlayingInfo.h; sourceTree = "<group>"; }; 7453 7452 4170A2E91D8C0CC000318452 /* JSDOMWrapper.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDOMWrapper.cpp; sourceTree = "<group>"; }; … … 16540 16539 41D1938F2152C561006F14CA /* RealtimeVideoUtilities.h */, 16541 16540 4158649F23BF7B9300A0A61E /* RealtimeVideoUtilities.mm */, 16542 070A9F5E1FFECC70003DF649 /* ScreenDisplayCaptureSourceMac.h */,16543 070A9F601FFECC71003DF649 /* ScreenDisplayCaptureSourceMac.mm */,16541 416F807C24509F3300B68F02 /* ScreenDisplayCapturerMac.h */, 16542 416F807A24509F3200B68F02 /* ScreenDisplayCapturerMac.mm */, 16544 16543 07D6373E1BB0B11300256CE9 /* WebAudioSourceProviderAVFObjC.h */, 16545 16544 07D6373F1BB0B11300256CE9 /* WebAudioSourceProviderAVFObjC.mm */, 16546 07D60926214C5BFC00E7396C /* WindowDisplayCaptureSourceMac.h */,16547 07D60924214C5BFB00E7396C /* WindowDisplayCaptureSourceMac.mm */,16545 416F807924509F3200B68F02 /* WindowDisplayCapturerMac.h */, 16546 416F807B24509F3300B68F02 /* WindowDisplayCapturerMac.mm */, 16548 16547 ); 16549 16548 path = mac; … … 33568 33567 939B02EF0EA2DBC400C54570 /* WidthIterator.h in Headers */, 33569 33568 0F15ED5C1B7EC7C500EDDFEB /* WillChangeData.h in Headers */, 33570 07D60928214C5BFD00E7396C /* WindowDisplayCaptureSourceMac.h in Headers */,33571 33569 9B27FC60234D9ADB00394A46 /* WindowEventLoop.h in Headers */, 33572 33570 BC8243E90D0CFD7500460C8F /* WindowFeatures.h in Headers */, -
trunk/Source/WebCore/platform/mediastream/RealtimeMediaSourceFactory.h
r260013 r260561 90 90 }; 91 91 92 class DisplayCaptureFactory { 92 class DisplayCaptureFactory 93 #if PLATFORM(IOS_FAMILY) 94 : public SingleSourceFactory 95 #endif 96 { 93 97 public: 94 98 virtual ~DisplayCaptureFactory() = default; -
trunk/Source/WebCore/platform/mediastream/mac/DisplayCaptureManagerCocoa.cpp
r239840 r260561 34 34 35 35 #if PLATFORM(MAC) 36 #include "ScreenDisplayCapture SourceMac.h"37 #include "WindowDisplayCapture SourceMac.h"36 #include "ScreenDisplayCapturerMac.h" 37 #include "WindowDisplayCapturerMac.h" 38 38 #include <CoreGraphics/CGDirectDisplay.h> 39 39 #endif … … 62 62 { 63 63 #if PLATFORM(MAC) 64 ScreenDisplayCapture SourceMac::screenCaptureDevices(m_devices);64 ScreenDisplayCapturerMac::screenCaptureDevices(m_devices); 65 65 #endif 66 66 } … … 69 69 { 70 70 #if PLATFORM(MAC) 71 WindowDisplayCapture SourceMac::windowCaptureDevices(m_devices);71 WindowDisplayCapturerMac::windowCaptureDevices(m_devices); 72 72 #endif 73 73 } … … 76 76 { 77 77 #if PLATFORM(MAC) 78 return ScreenDisplayCapture SourceMac::screenCaptureDeviceWithPersistentID(deviceID);78 return ScreenDisplayCapturerMac::screenCaptureDeviceWithPersistentID(deviceID); 79 79 #else 80 80 UNUSED_PARAM(deviceID); … … 86 86 { 87 87 #if PLATFORM(MAC) 88 return WindowDisplayCapture SourceMac::windowCaptureDeviceWithPersistentID(deviceID);88 return WindowDisplayCapturerMac::windowCaptureDeviceWithPersistentID(deviceID); 89 89 #else 90 90 UNUSED_PARAM(deviceID); -
trunk/Source/WebCore/platform/mediastream/mac/DisplayCaptureSourceCocoa.cpp
r253275 r260561 54 54 using namespace PAL; 55 55 56 DisplayCaptureSourceCocoa::DisplayCaptureSourceCocoa(String&& name) 56 CaptureSourceOrError DisplayCaptureSourceCocoa::create(const CaptureDevice& device, const MediaConstraints* constraints) 57 { 58 #if PLATFORM(MAC) 59 switch (device.type()) { 60 case CaptureDevice::DeviceType::Screen: 61 return create(ScreenDisplayCapturerMac::create(device.persistentId()), device, constraints); 62 case CaptureDevice::DeviceType::Window: 63 return create(WindowDisplayCapturerMac::create(device.persistentId()), device, constraints); 64 case CaptureDevice::DeviceType::Microphone: 65 case CaptureDevice::DeviceType::Camera: 66 case CaptureDevice::DeviceType::Unknown: 67 ASSERT_NOT_REACHED(); 68 break; 69 } 70 #else 71 UNUSED_PARAM(device); 72 UNUSED_PARAM(constraints); 73 #endif 74 return { }; 75 } 76 77 CaptureSourceOrError DisplayCaptureSourceCocoa::create(Expected<UniqueRef<Capturer>, String>&& capturer, const CaptureDevice& device, const MediaConstraints* constraints) 78 { 79 if (!capturer.has_value()) 80 return CaptureSourceOrError { WTFMove(capturer.error()) }; 81 82 auto source = adoptRef(*new DisplayCaptureSourceCocoa(WTFMove(capturer.value()), String { device.label() })); 83 if (constraints) { 84 auto result = source->applyConstraints(*constraints); 85 if (result) 86 return WTFMove(result.value().badConstraint); 87 } 88 89 return CaptureSourceOrError(WTFMove(source)); 90 } 91 92 DisplayCaptureSourceCocoa::DisplayCaptureSourceCocoa(UniqueRef<Capturer>&& capturer, String&& name) 57 93 : RealtimeMediaSource(Type::Video, WTFMove(name)) 94 , m_capturer(WTFMove(capturer)) 58 95 , m_timer(RunLoop::current(), this, &DisplayCaptureSourceCocoa::emitFrame) 59 96 { … … 63 100 { 64 101 #if PLATFORM(IOS_FAMILY) 65 RealtimeMediaSourceCenter::singleton(). videoCaptureFactory().unsetActiveSource(*this);102 RealtimeMediaSourceCenter::singleton().displayCaptureFactory().unsetActiveSource(*this); 66 103 #endif 67 104 } … … 73 110 74 111 // FIXME: what should these be? 75 capabilities.setWidth(CapabilityValueOrRange( 72, 2880));76 capabilities.setHeight(CapabilityValueOrRange( 45, 1800));112 capabilities.setWidth(CapabilityValueOrRange(1, 3840)); 113 capabilities.setHeight(CapabilityValueOrRange(1, 2160)); 77 114 capabilities.setFrameRate(CapabilityValueOrRange(.01, 30.0)); 78 115 … … 92 129 settings.setHeight(size.height()); 93 130 94 settings.setDisplaySurface( surfaceType());131 settings.setDisplaySurface(m_capturer->surfaceType()); 95 132 settings.setLogicalSurface(false); 96 133 … … 123 160 { 124 161 #if PLATFORM(IOS_FAMILY) 125 RealtimeMediaSourceCenter::singleton(). videoCaptureFactory().setActiveSource(*this);162 RealtimeMediaSourceCenter::singleton().displayCaptureFactory().setActiveSource(*this); 126 163 #endif 127 164 128 165 m_startTime = MonotonicTime::now(); 129 166 m_timer.startRepeating(1_s / frameRate()); 167 168 if (!m_capturer->start(frameRate())) 169 captureFailed(); 130 170 } 131 171 … … 135 175 m_elapsedTime += MonotonicTime::now() - m_startTime; 136 176 m_startTime = MonotonicTime::nan(); 177 178 m_capturer->stop(); 137 179 } 138 180 … … 145 187 } 146 188 147 IntSize DisplayCaptureSourceCocoa::frameSize() const 148 { 149 IntSize frameSize = size(); 150 if (frameSize.isEmpty()) 151 return intrinsicSize(); 152 153 return frameSize; 189 // We keep the aspect ratio of the intrinsic size for the frame size as getDisplayMedia allows max constraints only. 190 void DisplayCaptureSourceCocoa::updateFrameSize() 191 { 192 auto intrinsicSize = this->intrinsicSize(); 193 194 auto frameSize = size(); 195 if (!frameSize.height()) 196 frameSize.setHeight(intrinsicSize.height()); 197 if (!frameSize.width()) 198 frameSize.setWidth(intrinsicSize.width()); 199 200 auto maxHeight = std::min(frameSize.height(), intrinsicSize.height()); 201 auto maxWidth = std::min(frameSize.width(), intrinsicSize.width()); 202 203 auto heightForMaxWidth = maxWidth * intrinsicSize.height() / intrinsicSize.width(); 204 auto widthForMaxHeight = maxHeight * intrinsicSize.width() / intrinsicSize.height(); 205 206 if (heightForMaxWidth <= maxHeight) { 207 setSize({ maxWidth, heightForMaxWidth }); 208 return; 209 } 210 if (widthForMaxHeight <= maxWidth) { 211 setSize({ widthForMaxHeight, maxHeight }); 212 return; 213 } 214 setSize(intrinsicSize); 154 215 } 155 216 … … 165 226 auto sampleTime = MediaTime::createWithDouble((elapsedTime() + 100_ms).seconds()); 166 227 167 auto frame = generateFrame();228 auto frame = m_capturer->generateFrame(); 168 229 auto imageSize = WTF::switchOn(frame, 169 230 [](RetainPtr<IOSurfaceRef> surface) -> IntSize { … … 185 246 return; 186 247 187 setIntrinsicSize(imageSize); 188 189 auto mediaSampleSize = frameSize(); 190 191 RefPtr<MediaSample> sample = WTF::switchOn(frame, 192 [this, sampleTime, mediaSampleSize](RetainPtr<IOSurfaceRef> surface) -> RefPtr<MediaSample> { 248 if (intrinsicSize() != imageSize) { 249 setIntrinsicSize(imageSize); 250 updateFrameSize(); 251 } 252 253 auto sample = WTF::switchOn(frame, 254 [this, sampleTime](RetainPtr<IOSurfaceRef> surface) -> RefPtr<MediaSample> { 193 255 if (!surface) 194 256 return nullptr; 195 257 196 return m_imageTransferSession->createMediaSample(surface.get(), sampleTime, mediaSampleSize);258 return m_imageTransferSession->createMediaSample(surface.get(), sampleTime, size()); 197 259 }, 198 [this, sampleTime , mediaSampleSize](RetainPtr<CGImageRef> image) -> RefPtr<MediaSample> {260 [this, sampleTime](RetainPtr<CGImageRef> image) -> RefPtr<MediaSample> { 199 261 if (!image) 200 262 return nullptr; 201 263 202 return m_imageTransferSession->createMediaSample(image.get(), sampleTime, mediaSampleSize);264 return m_imageTransferSession->createMediaSample(image.get(), sampleTime, size()); 203 265 } 204 266 ); … … 213 275 } 214 276 277 #if !RELEASE_LOG_DISABLED 278 void DisplayCaptureSourceCocoa::Capturer::setLogger(const Logger& newLogger, const void* newLogIdentifier) 279 { 280 m_logger = &newLogger; 281 m_logIdentifier = newLogIdentifier; 282 } 283 284 WTFLogChannel& DisplayCaptureSourceCocoa::Capturer::logChannel() const 285 { 286 return LogWebRTC; 287 } 288 #endif 289 215 290 } // namespace WebCore 216 291 -
trunk/Source/WebCore/platform/mediastream/mac/DisplayCaptureSourceCocoa.h
r239427 r260561 34 34 #include <wtf/RefPtr.h> 35 35 #include <wtf/RunLoop.h> 36 #include <wtf/UniqueRef.h> 36 37 #include <wtf/text/WTFString.h> 37 38 … … 50 51 class PixelBufferConformerCV; 51 52 52 class DisplayCaptureSourceCocoa : public RealtimeMediaSource {53 class DisplayCaptureSourceCocoa final : public RealtimeMediaSource { 53 54 public: 55 using DisplayFrameType = WTF::Variant<RetainPtr<CGImageRef>, RetainPtr<IOSurfaceRef>>; 56 class Capturer 57 #if !RELEASE_LOG_DISABLED 58 : public LoggerHelper 59 #endif 60 { 61 WTF_MAKE_FAST_ALLOCATED; 62 public: 63 virtual ~Capturer() = default; 54 64 55 protected: 56 DisplayCaptureSourceCocoa(String&& name); 57 virtual ~DisplayCaptureSourceCocoa(); 65 virtual bool start(float frameRate) = 0; 66 virtual void stop() = 0; 67 virtual DisplayFrameType generateFrame() = 0; 68 virtual CaptureDevice::DeviceType deviceType() const = 0; 69 virtual RealtimeMediaSourceSettings::DisplaySurfaceType surfaceType() const = 0; 70 virtual void commitConfiguration(float frameRate) = 0; 58 71 59 using DisplayFrameType = WTF::Variant<RetainPtr<CGImageRef>, RetainPtr<IOSurfaceRef>>; 60 virtual DisplayFrameType generateFrame() = 0; 72 #if !RELEASE_LOG_DISABLED 73 virtual void setLogger(const Logger&, const void*); 74 const Logger* loggerPtr() const { return m_logger.get(); } 75 const Logger& logger() const final { ASSERT(m_logger); return *m_logger.get(); } 76 const void* logIdentifier() const final { return m_logIdentifier; } 77 WTFLogChannel& logChannel() const final; 78 #endif 61 79 62 virtual RealtimeMediaSourceSettings::DisplaySurfaceType surfaceType() const = 0; 80 private: 81 #if !RELEASE_LOG_DISABLED 82 RefPtr<const Logger> m_logger; 83 const void* m_logIdentifier; 84 #endif 85 }; 63 86 64 void startProducingData() override;65 void stopProducingData() override;87 static CaptureSourceOrError create(const CaptureDevice&, const MediaConstraints*); 88 static CaptureSourceOrError create(Expected<UniqueRef<Capturer>, String>&&, const CaptureDevice&, const MediaConstraints*); 66 89 67 90 Seconds elapsedTime(); 68 69 void settingsDidChange(OptionSet<RealtimeMediaSourceSettings::Flag>) override; 70 71 IntSize frameSize() const; 91 void updateFrameSize(); 72 92 73 93 private: 94 DisplayCaptureSourceCocoa(UniqueRef<Capturer>&&, String&& name); 95 ~DisplayCaptureSourceCocoa(); 74 96 97 void startProducingData() final; 98 void stopProducingData() final; 99 void settingsDidChange(OptionSet<RealtimeMediaSourceSettings::Flag>) final; 75 100 bool isCaptureSource() const final { return true; } 76 77 101 const RealtimeMediaSourceCapabilities& capabilities() final; 78 102 const RealtimeMediaSourceSettings& settings() final; 103 CaptureDevice::DeviceType deviceType() const { return m_capturer->deviceType(); } 104 void commitConfiguration() final { return m_capturer->commitConfiguration(frameRate()); } 105 106 #if !RELEASE_LOG_DISABLED 107 const char* logClassName() const final { return "DisplayCaptureSourceCocoa"; } 108 #endif 79 109 80 110 void emitFrame(); 81 111 112 UniqueRef<Capturer> m_capturer; 82 113 Optional<RealtimeMediaSourceCapabilities> m_capabilities; 83 114 Optional<RealtimeMediaSourceSettings> m_currentSettings; -
trunk/Source/WebCore/platform/mediastream/mac/MockRealtimeVideoSourceMac.h
r247165 r260561 47 47 class MockRealtimeVideoSourceMac final : public MockRealtimeVideoSource { 48 48 public: 49 virtual ~MockRealtimeVideoSourceMac() = default; 49 static Ref<MockRealtimeVideoSource> createForMockDisplayCapturer(String&& deviceID, String&& name, String&& hashSalt); 50 51 ~MockRealtimeVideoSourceMac() = default; 50 52 51 53 private: -
trunk/Source/WebCore/platform/mediastream/mac/MockRealtimeVideoSourceMac.mm
r254259 r260561 72 72 } 73 73 74 Ref<MockRealtimeVideoSource> MockRealtimeVideoSourceMac::createForMockDisplayCapturer(String&& deviceID, String&& name, String&& hashSalt) 75 { 76 return adoptRef(*new MockRealtimeVideoSourceMac(WTFMove(deviceID), WTFMove(name), WTFMove(hashSalt))); 77 } 78 74 79 MockRealtimeVideoSourceMac::MockRealtimeVideoSourceMac(String&& deviceID, String&& name, String&& hashSalt) 75 80 : MockRealtimeVideoSource(WTFMove(deviceID), WTFMove(name), WTFMove(hashSalt)) -
trunk/Source/WebCore/platform/mediastream/mac/RealtimeMediaSourceCenterMac.cpp
r251041 r260561 39 39 #include "Logging.h" 40 40 #include "MediaStreamPrivate.h" 41 #include "ScreenDisplayCapture SourceMac.h"42 #include "WindowDisplayCapture SourceMac.h"41 #include "ScreenDisplayCapturerMac.h" 42 #include "WindowDisplayCapturerMac.h" 43 43 #include <wtf/MainThread.h> 44 44 … … 73 73 UNUSED_PARAM(constraints); 74 74 #endif 75 switch (device.type()) {76 case CaptureDevice::DeviceType::Screen:77 75 #if PLATFORM(MAC) 78 return ScreenDisplayCaptureSourceMac::create(String { device.persistentId() }, constraints); 76 return DisplayCaptureSourceCocoa::create(device, constraints); 77 #else 78 return { }; 79 79 #endif 80 case CaptureDevice::DeviceType::Window:81 #if PLATFORM(MAC)82 return WindowDisplayCaptureSourceMac::create(String { device.persistentId() }, constraints);83 #endif84 case CaptureDevice::DeviceType::Microphone:85 case CaptureDevice::DeviceType::Camera:86 case CaptureDevice::DeviceType::Unknown:87 ASSERT_NOT_REACHED();88 break;89 }90 91 return { };92 80 } 93 81 private: -
trunk/Source/WebCore/platform/mediastream/mac/ScreenDisplayCapturerMac.h
r260560 r260561 40 40 namespace WebCore { 41 41 42 class ScreenDisplayCapture SourceMac : public DisplayCaptureSourceCocoa{42 class ScreenDisplayCapturerMac final : public DisplayCaptureSourceCocoa::Capturer, public CanMakeWeakPtr<ScreenDisplayCapturerMac> { 43 43 public: 44 static CaptureSourceOrError create(String&&, const MediaConstraints*); 44 static Expected<UniqueRef<DisplayCaptureSourceCocoa::Capturer>, String> create(const String&); 45 46 explicit ScreenDisplayCapturerMac(uint32_t); 47 ~ScreenDisplayCapturerMac(); 45 48 46 49 static Optional<CaptureDevice> screenCaptureDeviceWithPersistentID(const String&); … … 48 51 49 52 private: 50 ScreenDisplayCaptureSourceMac(uint32_t, String&&);51 virtual ~ScreenDisplayCaptureSourceMac();52 53 53 static void displayReconfigurationCallBack(CGDirectDisplayID, CGDisplayChangeSummaryFlags, void*); 54 54 55 void displayWasReconfigured(CGDirectDisplayID, CGDisplayChangeSummaryFlags); 56 55 // DisplayCaptureSourceCocoa::Capturer 56 bool start(float frameRate) final; 57 void stop() final; 57 58 DisplayCaptureSourceCocoa::DisplayFrameType generateFrame() final; 58 59 RealtimeMediaSourceSettings::DisplaySurfaceType surfaceType() const final { return RealtimeMediaSourceSettings::DisplaySurfaceType::Monitor; } 60 void commitConfiguration(float frameRate) final; 61 CaptureDevice::DeviceType deviceType() const final { return CaptureDevice::DeviceType::Screen; } 62 #if !RELEASE_LOG_DISABLED 63 const char* logClassName() const final { return "ScreenDisplayCapturerMac"; } 64 #endif 59 65 60 void startProducingData() final; 61 void stopProducingData() final; 62 void commitConfiguration() final; 63 CaptureDevice::DeviceType deviceType() const final { return CaptureDevice::DeviceType::Screen; } 64 65 bool createDisplayStream(); 66 void startDisplayStream(); 67 68 #if !RELEASE_LOG_DISABLED 69 const char* logClassName() const override { return "ScreenDisplayCaptureSourceMac"; } 70 #endif 66 void displayWasReconfigured(CGDirectDisplayID, CGDisplayChangeSummaryFlags); 67 bool createDisplayStream(float frameRate); 68 bool startDisplayStream(float frameRate); 71 69 72 70 class DisplaySurface { -
trunk/Source/WebCore/platform/mediastream/mac/ScreenDisplayCapturerMac.mm
r260560 r260561 24 24 */ 25 25 26 #i mport"config.h"27 #i mport "ScreenDisplayCaptureSourceMac.h"26 #include "config.h" 27 #include "ScreenDisplayCapturerMac.h" 28 28 29 29 #if ENABLE(MEDIA_STREAM) && PLATFORM(MAC) … … 54 54 auto err = CGGetActiveDisplayList(0, nullptr, &displayCount); 55 55 if (err) { 56 RELEASE_LOG( Media, "CGGetActiveDisplayList() returned error %d when trying to get display count", static_cast<int>(err));56 RELEASE_LOG(WebRTC, "CGGetActiveDisplayList() returned error %d when trying to get display count", static_cast<int>(err)); 57 57 return WTF::nullopt; 58 58 } 59 59 60 60 if (!displayCount) { 61 RELEASE_LOG( Media, "CGGetActiveDisplayList() returned a display count of 0");61 RELEASE_LOG(WebRTC, "CGGetActiveDisplayList() returned a display count of 0"); 62 62 return WTF::nullopt; 63 63 } … … 66 66 err = CGGetActiveDisplayList(displayCount, activeDisplays.data(), &displayCount); 67 67 if (err) { 68 RELEASE_LOG( Media, "CGGetActiveDisplayList() returned error %d when trying to get the active display list", static_cast<int>(err));68 RELEASE_LOG(WebRTC, "CGGetActiveDisplayList() returned error %d when trying to get the active display list", static_cast<int>(err)); 69 69 return WTF::nullopt; 70 70 } … … 79 79 } 80 80 81 CaptureSourceOrError ScreenDisplayCaptureSourceMac::create(String&& deviceID, const MediaConstraints* constraints)81 Expected<UniqueRef<DisplayCaptureSourceCocoa::Capturer>, String> ScreenDisplayCapturerMac::create(const String& deviceID) 82 82 { 83 83 bool ok; 84 84 auto displayID = deviceID.toUIntStrict(&ok); 85 if (!ok) { 86 RELEASE_LOG(Media, "ScreenDisplayCaptureSourceMac::create: Display ID does not convert to 32-bit integer"); 87 return { }; 88 } 85 if (!ok) 86 return makeUnexpected("Invalid display device ID"_s); 89 87 90 88 auto actualDisplayID = updateDisplayID(displayID); 91 89 if (!actualDisplayID) 92 return { }; 93 94 auto source = adoptRef(*new ScreenDisplayCaptureSourceMac(actualDisplayID.value(), "Screen"_s)); // FIXME: figure out what title to use 95 if (constraints && source->applyConstraints(*constraints)) 96 return { }; 97 98 return CaptureSourceOrError(WTFMove(source)); 99 } 100 101 ScreenDisplayCaptureSourceMac::ScreenDisplayCaptureSourceMac(uint32_t displayID, String&& title) 102 : DisplayCaptureSourceCocoa(WTFMove(title)) 103 , m_displayID(displayID) 104 { 105 } 106 107 ScreenDisplayCaptureSourceMac::~ScreenDisplayCaptureSourceMac() 90 return makeUnexpected("Invalid display ID"_s); 91 92 return UniqueRef<DisplayCaptureSourceCocoa::Capturer>(makeUniqueRef<ScreenDisplayCapturerMac>(actualDisplayID.value())); 93 } 94 95 ScreenDisplayCapturerMac::ScreenDisplayCapturerMac(uint32_t displayID) 96 : m_displayID(displayID) 97 { 98 } 99 100 ScreenDisplayCapturerMac::~ScreenDisplayCapturerMac() 108 101 { 109 102 if (m_observingDisplayChanges) … … 113 106 } 114 107 115 bool ScreenDisplayCapture SourceMac::createDisplayStream()108 bool ScreenDisplayCapturerMac::createDisplayStream(float frameRate) 116 109 { 117 110 static const int screenQueueMaximumLength = 6; … … 122 115 if (!actualDisplayID) { 123 116 ERROR_LOG_IF(loggerPtr(), LOGIDENTIFIER, "invalid display ID: ", m_displayID); 124 captureFailed();125 117 return false; 126 118 } … … 138 130 if (!screenWidth || !screenHeight) { 139 131 ERROR_LOG_IF(loggerPtr(), LOGIDENTIFIER, "unable to get screen width/height"); 140 captureFailed();141 132 return false; 142 133 } 143 setIntrinsicSize(IntSize(screenWidth, screenHeight));144 134 145 135 if (!m_captureQueue) 146 m_captureQueue = adoptOSObject(dispatch_queue_create("ScreenDisplayCapture SourceMac Capture Queue", DISPATCH_QUEUE_SERIAL));136 m_captureQueue = adoptOSObject(dispatch_queue_create("ScreenDisplayCapturerMac Capture Queue", DISPATCH_QUEUE_SERIAL)); 147 137 148 138 NSDictionary* streamOptions = @{ 149 (__bridge NSString *)kCGDisplayStreamMinimumFrameTime : @(1 / frameRate ()),139 (__bridge NSString *)kCGDisplayStreamMinimumFrameTime : @(1 / frameRate), 150 140 (__bridge NSString *)kCGDisplayStreamQueueDepth : @(screenQueueMaximumLength), 151 141 (__bridge NSString *)kCGDisplayStreamColorSpace : (__bridge id)sRGBColorSpaceRef(), … … 174 164 if (!m_displayStream) { 175 165 ERROR_LOG_IF(loggerPtr(), LOGIDENTIFIER, "CGDisplayStreamCreate failed"); 176 captureFailed();177 166 return false; 178 167 } … … 187 176 } 188 177 189 void ScreenDisplayCaptureSourceMac::startProducingData()178 bool ScreenDisplayCapturerMac::start(float frameRate) 190 179 { 191 180 ALWAYS_LOG_IF(loggerPtr(), LOGIDENTIFIER); 192 DisplayCaptureSourceCocoa::startProducingData();193 181 194 182 if (m_isRunning) 195 return ;196 197 startDisplayStream();198 } 199 200 void ScreenDisplayCapture SourceMac::stopProducingData()183 return true; 184 185 return startDisplayStream(frameRate); 186 } 187 188 void ScreenDisplayCapturerMac::stop() 201 189 { 202 190 ALWAYS_LOG_IF(loggerPtr(), LOGIDENTIFIER); 203 DisplayCaptureSourceCocoa::stopProducingData();204 191 205 192 if (!m_isRunning) … … 212 199 } 213 200 214 DisplayCaptureSourceCocoa::DisplayFrameType ScreenDisplayCapture SourceMac::generateFrame()201 DisplayCaptureSourceCocoa::DisplayFrameType ScreenDisplayCapturerMac::generateFrame() 215 202 { 216 203 return DisplayCaptureSourceCocoa::DisplayFrameType { RetainPtr<IOSurfaceRef> { m_currentFrame.ioSurface() } }; 217 204 } 218 205 219 void ScreenDisplayCaptureSourceMac::startDisplayStream()206 bool ScreenDisplayCapturerMac::startDisplayStream(float frameRate) 220 207 { 221 208 auto actualDisplayID = updateDisplayID(m_displayID); 222 209 if (!actualDisplayID) 223 return ;210 return false; 224 211 225 212 if (m_displayID != actualDisplayID.value()) { … … 228 215 } 229 216 230 if (!m_displayStream && !createDisplayStream( ))231 return ;217 if (!m_displayStream && !createDisplayStream(frameRate)) 218 return false; 232 219 233 220 auto err = CGDisplayStreamStart(m_displayStream.get()); 234 221 if (err) { 235 222 ERROR_LOG_IF(loggerPtr(), LOGIDENTIFIER, "CGDisplayStreamStart failed with error ", static_cast<int>(err)); 236 captureFailed(); 237 return; 223 return false; 238 224 } 239 225 240 226 m_isRunning = true; 241 } 242 243 void ScreenDisplayCaptureSourceMac::commitConfiguration() 227 return true; 228 } 229 230 void ScreenDisplayCapturerMac::commitConfiguration(float frameRate) 244 231 { 245 232 if (m_isRunning && !m_displayStream) 246 startDisplayStream( );247 } 248 249 void ScreenDisplayCapture SourceMac::displayWasReconfigured(CGDirectDisplayID, CGDisplayChangeSummaryFlags)233 startDisplayStream(frameRate); 234 } 235 236 void ScreenDisplayCapturerMac::displayWasReconfigured(CGDirectDisplayID, CGDisplayChangeSummaryFlags) 250 237 { 251 238 // FIXME: implement! 252 239 } 253 240 254 void ScreenDisplayCapture SourceMac::displayReconfigurationCallBack(CGDirectDisplayID display, CGDisplayChangeSummaryFlags flags, void *userInfo)241 void ScreenDisplayCapturerMac::displayReconfigurationCallBack(CGDirectDisplayID display, CGDisplayChangeSummaryFlags flags, void *userInfo) 255 242 { 256 243 if (userInfo) 257 reinterpret_cast<ScreenDisplayCapture SourceMac *>(userInfo)->displayWasReconfigured(display, flags);258 } 259 260 void ScreenDisplayCapture SourceMac::newFrame(CGDisplayStreamFrameStatus status, DisplaySurface&& newFrame)244 reinterpret_cast<ScreenDisplayCapturerMac *>(userInfo)->displayWasReconfigured(display, flags); 245 } 246 247 void ScreenDisplayCapturerMac::newFrame(CGDisplayStreamFrameStatus status, DisplaySurface&& newFrame) 261 248 { 262 249 switch (status) { … … 268 255 269 256 case kCGDisplayStreamFrameStatusFrameBlank: 270 RELEASE_LOG( Media, "ScreenDisplayCaptureSourceMac::frameAvailable: kCGDisplayStreamFrameStatusFrameBlank");257 RELEASE_LOG(WebRTC, "ScreenDisplayCapturerMac::frameAvailable: kCGDisplayStreamFrameStatusFrameBlank"); 271 258 break; 272 259 273 260 case kCGDisplayStreamFrameStatusStopped: 274 RELEASE_LOG( Media, "ScreenDisplayCaptureSourceMac::frameAvailable: kCGDisplayStreamFrameStatusStopped");261 RELEASE_LOG(WebRTC, "ScreenDisplayCapturerMac::frameAvailable: kCGDisplayStreamFrameStatusStopped"); 275 262 break; 276 263 } … … 279 266 } 280 267 281 Optional<CaptureDevice> ScreenDisplayCapture SourceMac::screenCaptureDeviceWithPersistentID(const String& deviceID)268 Optional<CaptureDevice> ScreenDisplayCapturerMac::screenCaptureDeviceWithPersistentID(const String& deviceID) 282 269 { 283 270 bool ok; 284 271 auto displayID = deviceID.toUIntStrict(&ok); 285 272 if (!ok) { 286 RELEASE_LOG( Media, "ScreenDisplayCaptureSourceMac::screenCaptureDeviceWithPersistentID: display ID does not convert to 32-bit integer");273 RELEASE_LOG(WebRTC, "ScreenDisplayCapturerMac::screenCaptureDeviceWithPersistentID: display ID does not convert to 32-bit integer"); 287 274 return WTF::nullopt; 288 275 } … … 298 285 } 299 286 300 void ScreenDisplayCapture SourceMac::screenCaptureDevices(Vector<CaptureDevice>& displays)287 void ScreenDisplayCapturerMac::screenCaptureDevices(Vector<CaptureDevice>& displays) 301 288 { 302 289 auto screenID = displayID([NSScreen mainScreen]); … … 311 298 auto err = CGGetActiveDisplayList(0, nullptr, &displayCount); 312 299 if (err) { 313 RELEASE_LOG( Media, "CGGetActiveDisplayList() returned error %d when trying to get display count", (int)err);300 RELEASE_LOG(WebRTC, "CGGetActiveDisplayList() returned error %d when trying to get display count", (int)err); 314 301 return; 315 302 } 316 303 317 304 if (!displayCount) { 318 RELEASE_LOG( Media, "CGGetActiveDisplayList() returned a display count of 0");305 RELEASE_LOG(WebRTC, "CGGetActiveDisplayList() returned a display count of 0"); 319 306 return; 320 307 } … … 323 310 err = CGGetActiveDisplayList(displayCount, activeDisplays.data(), &displayCount); 324 311 if (err) { 325 RELEASE_LOG( Media, "CGGetActiveDisplayList() returned error %d when trying to get the active display list", (int)err);312 RELEASE_LOG(WebRTC, "CGGetActiveDisplayList() returned error %d when trying to get the active display list", (int)err); 326 313 return; 327 314 } -
trunk/Source/WebCore/platform/mediastream/mac/WindowDisplayCapturerMac.h
r260560 r260561 39 39 class PixelBufferConformerCV; 40 40 41 class WindowDisplayCapture SourceMac : public DisplayCaptureSourceCocoa{41 class WindowDisplayCapturerMac final : public DisplayCaptureSourceCocoa::Capturer { 42 42 public: 43 static CaptureSourceOrError create(String&&, const MediaConstraints*); 43 static Expected<UniqueRef<DisplayCaptureSourceCocoa::Capturer>, String> create(const String&); 44 45 explicit WindowDisplayCapturerMac(uint32_t); 46 virtual ~WindowDisplayCapturerMac() = default; 44 47 45 48 static Optional<CaptureDevice> windowCaptureDeviceWithPersistentID(const String&); … … 47 50 48 51 private: 49 WindowDisplayCaptureSourceMac(uint32_t, String&&);50 virtual ~WindowDisplayCaptureSourceMac() = default;51 52 // DisplayCaptureSourceCocoa::Capturer 53 bool start(float) final { return true; } 54 void stop() final { } 52 55 DisplayCaptureSourceCocoa::DisplayFrameType generateFrame() final; 53 56 RealtimeMediaSourceSettings::DisplaySurfaceType surfaceType() const final { return RealtimeMediaSourceSettings::DisplaySurfaceType::Window; } 54 57 CaptureDevice::DeviceType deviceType() const final { return CaptureDevice::DeviceType::Window; } 58 void commitConfiguration(float) final { } 59 #if !RELEASE_LOG_DISABLED 60 const char* logClassName() const final { return "WindowDisplayCapturerMac"; } 61 #endif 55 62 56 63 RetainPtr<CGImageRef> windowImage(); -
trunk/Source/WebCore/platform/mediastream/mac/WindowDisplayCapturerMac.mm
r260560 r260561 25 25 26 26 #import "config.h" 27 #import "WindowDisplayCapture SourceMac.h"27 #import "WindowDisplayCapturerMac.h" 28 28 29 29 #if ENABLE(MEDIA_STREAM) && PLATFORM(MAC) … … 38 38 #import "PlatformLayer.h" 39 39 #import "RealtimeMediaSourceSettings.h" 40 #import <pal/cf/CoreMediaSoftLink.h>41 40 #import <pal/spi/cg/CoreGraphicsSPI.h> 42 41 #import <wtf/cf/TypeCastsCF.h> 43 42 43 #import <pal/cf/CoreMediaSoftLink.h> 44 44 #import "CoreVideoSoftLink.h" 45 45 … … 53 53 auto windows = adoptCF(CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID)); 54 54 if (!windows) { 55 RELEASE_LOG( Media, "CGWindowListCopyWindowInfo returned NULL");55 RELEASE_LOG(WebRTC, "CGWindowListCopyWindowInfo returned NULL"); 56 56 return false; 57 57 } … … 103 103 } 104 104 105 CaptureSourceOrError WindowDisplayCaptureSourceMac::create(String&& windowID, const MediaConstraints* constraints)105 Expected<UniqueRef<DisplayCaptureSourceCocoa::Capturer>, String> WindowDisplayCapturerMac::create(const String& deviceID) 106 106 { 107 107 bool ok; 108 auto actualID = windowID.toUIntStrict(&ok); 109 if (!ok) { 110 RELEASE_LOG(Media, "WindowDisplayCaptureSourceMac::create: window ID does not convert to 32-bit integer"); 111 return { }; 112 } 108 auto displayID = deviceID.toUIntStrict(&ok); 109 if (!ok) 110 return makeUnexpected("Invalid window device ID"_s); 113 111 114 auto windowInfo = windowDescription(actualID); 115 if (!windowInfo) { 116 RELEASE_LOG(Media, "WindowDisplayCaptureSourceMac::create: invalid window ID"); 117 return { }; 118 } 112 auto windowInfo = windowDescription(displayID); 113 if (!windowInfo) 114 return makeUnexpected("Invalid window ID"_s); 119 115 120 auto source = adoptRef(*new WindowDisplayCaptureSourceMac(actualID, checked_cf_cast<CFStringRef>(CFDictionaryGetValue(windowInfo.get(), kCGWindowName)))); 121 if (constraints && source->applyConstraints(*constraints)) 122 return { }; 123 124 return CaptureSourceOrError(WTFMove(source)); 116 return UniqueRef<DisplayCaptureSourceCocoa::Capturer>(makeUniqueRef<WindowDisplayCapturerMac>(displayID)); 125 117 } 126 118 127 WindowDisplayCaptureSourceMac::WindowDisplayCaptureSourceMac(uint32_t windowID, String&& title) 128 : DisplayCaptureSourceCocoa(WTFMove(title)) 129 , m_windowID(windowID) 119 WindowDisplayCapturerMac::WindowDisplayCapturerMac(uint32_t windowID) 120 : m_windowID(windowID) 130 121 { 131 122 } 132 123 133 RetainPtr<CGImageRef> WindowDisplayCapture SourceMac::windowImage()124 RetainPtr<CGImageRef> WindowDisplayCapturerMac::windowImage() 134 125 { 135 126 auto image = adoptCF(CGWindowListCreateImage(CGRectNull, kCGWindowListOptionIncludingWindow, m_windowID, kCGWindowImageBoundsIgnoreFraming | kCGWindowImageShouldBeOpaque)); 136 127 if (!image) 137 RELEASE_LOG( Media, "WindowDisplayCaptureSourceMac::windowImage: failed to capture window image");128 RELEASE_LOG(WebRTC, "WindowDisplayCapturerMac::windowImage: failed to capture window image"); 138 129 139 130 return image; 140 131 } 141 132 142 DisplayCaptureSourceCocoa::DisplayFrameType WindowDisplayCapture SourceMac::generateFrame()133 DisplayCaptureSourceCocoa::DisplayFrameType WindowDisplayCapturerMac::generateFrame() 143 134 { 144 135 return DisplayCaptureSourceCocoa::DisplayFrameType { RetainPtr<CGImageRef> { windowImage() } }; 145 136 } 146 137 147 Optional<CaptureDevice> WindowDisplayCapture SourceMac::windowCaptureDeviceWithPersistentID(const String& idString)138 Optional<CaptureDevice> WindowDisplayCapturerMac::windowCaptureDeviceWithPersistentID(const String& idString) 148 139 { 149 140 bool ok; 150 141 auto windowID = idString.toUIntStrict(&ok); 151 142 if (!ok) { 152 RELEASE_LOG( Media, "WindowDisplayCaptureSourceMac::windowCaptureDeviceWithPersistentID: window ID does not convert to 32-bit integer");143 RELEASE_LOG(WebRTC, "WindowDisplayCapturerMac::windowCaptureDeviceWithPersistentID: window ID does not convert to 32-bit integer"); 153 144 return WTF::nullopt; 154 145 } … … 163 154 164 155 })) { 165 RELEASE_LOG( Media, "WindowDisplayCaptureSourceMac::windowCaptureDeviceWithPersistentID: window ID is not valid");156 RELEASE_LOG(WebRTC, "WindowDisplayCapturerMac::windowCaptureDeviceWithPersistentID: window ID is not valid"); 166 157 return WTF::nullopt; 167 158 } … … 173 164 } 174 165 175 void WindowDisplayCapture SourceMac::windowCaptureDevices(Vector<CaptureDevice>& windows)166 void WindowDisplayCapturerMac::windowCaptureDevices(Vector<CaptureDevice>& windows) 176 167 { 177 168 anyOfCGWindow([&] (CFDictionaryRef, int id, const String& title) mutable { -
trunk/Source/WebCore/platform/mock/MockRealtimeMediaSourceCenter.cpp
r260013 r260561 44 44 #if PLATFORM(COCOA) 45 45 #include "CoreAudioCaptureSource.h" 46 #include "DisplayCaptureSourceCocoa.h" 47 #include "MockRealtimeVideoSourceMac.h" 46 48 #endif 47 49 … … 111 113 }; 112 114 115 #if PLATFORM(MAC) 116 class MockDisplayCapturer final : public DisplayCaptureSourceCocoa::Capturer { 117 public: 118 explicit MockDisplayCapturer(const CaptureDevice&); 119 120 private: 121 bool start(float) final; 122 void stop() final { m_source->stop(); } 123 DisplayCaptureSourceCocoa::DisplayFrameType generateFrame() final; 124 RealtimeMediaSourceSettings::DisplaySurfaceType surfaceType() const final { return RealtimeMediaSourceSettings::DisplaySurfaceType::Monitor; } 125 void commitConfiguration(float) final { } 126 CaptureDevice::DeviceType deviceType() const final { return CaptureDevice::DeviceType::Screen; } 127 #if !RELEASE_LOG_DISABLED 128 const char* logClassName() const final { return "MockDisplayCapturer"; } 129 #endif 130 131 Ref<MockRealtimeVideoSource> m_source; 132 }; 133 134 MockDisplayCapturer::MockDisplayCapturer(const CaptureDevice& device) 135 : m_source(MockRealtimeVideoSourceMac::createForMockDisplayCapturer(String { device.persistentId() }, String { device.label() }, String { })) 136 { 137 } 138 139 bool MockDisplayCapturer::start(float) 140 { 141 m_source->start(); 142 return true; 143 } 144 145 DisplayCaptureSourceCocoa::DisplayFrameType MockDisplayCapturer::generateFrame() 146 { 147 if (auto* imageBuffer = m_source->imageBuffer()) 148 return imageBuffer->copyNativeImage(); 149 return { }; 150 } 151 #endif 152 113 153 class MockRealtimeDisplaySourceFactory : public DisplayCaptureFactory { 114 154 public: … … 116 156 { 117 157 if (!MockRealtimeMediaSourceCenter::captureDeviceWithPersistentID(device.type(), device.persistentId())) 118 return { "Unable to find mock 158 return { "Unable to find mock display device with given persistentID"_s }; 119 159 120 160 switch (device.type()) { 121 161 case CaptureDevice::DeviceType::Screen: 122 162 case CaptureDevice::DeviceType::Window: 163 #if PLATFORM(MAC) 164 return DisplayCaptureSourceCocoa::create(UniqueRef<DisplayCaptureSourceCocoa::Capturer>(makeUniqueRef<MockDisplayCapturer>(device)), device, constraints); 165 #else 123 166 return MockRealtimeVideoSource::create(String { device.persistentId() }, String { device.label() }, String { }, constraints); 167 #endif 124 168 break; 125 169 case CaptureDevice::DeviceType::Microphone: -
trunk/Source/WebCore/platform/mock/MockRealtimeVideoSource.h
r253368 r260561 49 49 class MockRealtimeVideoSource : public RealtimeVideoCaptureSource, private OrientationNotifier::Observer { 50 50 public: 51 static CaptureSourceOrError create(String&& deviceID, String&& name, String&& hashSalt, const MediaConstraints*); 51 52 52 static CaptureSourceOrError create(String&& deviceID, String&& name, String&& hashSalt, const MediaConstraints*);53 ImageBuffer* imageBuffer() const; 53 54 54 55 protected: … … 58 59 59 60 void setCurrentFrame(MediaSample&); 60 ImageBuffer* imageBuffer() const;61 61 62 62 Seconds elapsedTime(); … … 126 126 } // namespace WebCore 127 127 128 SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::MockRealtimeVideoSource) 129 static bool isType(const WebCore::RealtimeMediaSource& source) { return source.isCaptureSource() && source.isMockSource() && (source.deviceType() == WebCore::CaptureDevice::DeviceType::Camera || source.deviceType() == WebCore::CaptureDevice::DeviceType::Screen || source.deviceType() == WebCore::CaptureDevice::DeviceType::Window); } 130 SPECIALIZE_TYPE_TRAITS_END() 131 128 132 #endif // ENABLE(MEDIA_STREAM) 129 133
Note: See TracChangeset
for help on using the changeset viewer.