Changeset 246644 in webkit
- Timestamp:
- Jun 20, 2019, 11:55:32 AM (7 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 17 edited
- 2 copied
-
LayoutTests/ChangeLog (modified) (1 diff)
-
LayoutTests/fast/mediastream/mediastreamtrack-video-clone-expected.txt (added)
-
LayoutTests/fast/mediastream/mediastreamtrack-video-clone.html (added)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/Headers.cmake (modified) (1 diff)
-
Source/WebCore/Sources.txt (modified) (1 diff)
-
Source/WebCore/WebCore.xcodeproj/project.pbxproj (modified) (6 diffs)
-
Source/WebCore/platform/mediastream/MediaStreamTrackPrivate.cpp (modified) (2 diffs)
-
Source/WebCore/platform/mediastream/RealtimeMediaSource.h (modified) (3 diffs)
-
Source/WebCore/platform/mediastream/RealtimeVideoCaptureSource.cpp (copied) (copied from trunk/Source/WebCore/platform/mediastream/RealtimeVideoSource.cpp ) (20 diffs)
-
Source/WebCore/platform/mediastream/RealtimeVideoCaptureSource.h (copied) (copied from trunk/Source/WebCore/platform/mediastream/RealtimeVideoSource.h ) (3 diffs)
-
Source/WebCore/platform/mediastream/RealtimeVideoSource.cpp (modified) (2 diffs)
-
Source/WebCore/platform/mediastream/RealtimeVideoSource.h (modified) (2 diffs)
-
Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoCaptureSource.cpp (modified) (2 diffs)
-
Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoCaptureSource.h (modified) (1 diff)
-
Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.h (modified) (3 diffs)
-
Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.mm (modified) (3 diffs)
-
Source/WebCore/platform/mediastream/mac/MockRealtimeVideoSourceMac.h (modified) (1 diff)
-
Source/WebCore/platform/mediastream/mac/MockRealtimeVideoSourceMac.mm (modified) (2 diffs)
-
Source/WebCore/platform/mock/MockRealtimeVideoSource.cpp (modified) (4 diffs)
-
Source/WebCore/platform/mock/MockRealtimeVideoSource.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r246642 r246644 1 2019-06-20 Youenn Fablet <youenn@apple.com> 2 3 Changing settings of a MediaStreamTrack clone should not alter the settings of the original track 4 https://bugs.webkit.org/show_bug.cgi?id=198840 5 6 Reviewed by Eric Carlson. 7 8 * fast/mediastream/mediastreamtrack-video-clone-expected.txt: Added. 9 * fast/mediastream/mediastreamtrack-video-clone.html: Added. 10 1 11 2019-06-20 Russell Epstein <russell_e@apple.com> 2 12 -
trunk/Source/WebCore/ChangeLog
r246643 r246644 1 2019-06-20 Youenn Fablet <youenn@apple.com> 2 3 Changing settings of a MediaStreamTrack clone should not alter the settings of the original track 4 https://bugs.webkit.org/show_bug.cgi?id=198840 5 6 Reviewed by Eric Carlson. 7 8 Rename RealtimeVideoSource in RealtimeVideoCaptureSource. 9 Introduce RealtimeVideoSource as a class wrapping RealtimeVideoCaptureSource. 10 Its goal is to be able to have independent settings from its underlying RealtimeVideoCaptureSource. 11 It can also adapt size based on its settings if different than its RealtimeVideoCaptureSource. 12 Apply this wrapping for AV video sources as well as mock video sources. 13 Test: fast/mediastream/mediastreamtrack-video-clone.html 14 15 * Sources.txt: 16 * WebCore.xcodeproj/project.pbxproj: 17 * platform/mediastream/MediaStreamTrackPrivate.cpp: 18 (WebCore::MediaStreamTrackPrivate::clone): 19 * platform/mediastream/RealtimeMediaSource.h: 20 * platform/mediastream/RealtimeVideoCaptureSource.cpp: Added. 21 (WebCore::RealtimeVideoCaptureSource::RealtimeVideoCaptureSource): 22 (WebCore::RealtimeVideoCaptureSource::~RealtimeVideoCaptureSource): 23 (WebCore::RealtimeVideoCaptureSource::prepareToProduceData): 24 (WebCore::RealtimeVideoCaptureSource::presets): 25 (WebCore::RealtimeVideoCaptureSource::setSupportedPresets): 26 (WebCore::RealtimeVideoCaptureSource::standardVideoSizes): 27 (WebCore::updateMinMax): 28 (WebCore::RealtimeVideoCaptureSource::updateCapabilities): 29 (WebCore::RealtimeVideoCaptureSource::supportsSizeAndFrameRate): 30 (WebCore::RealtimeVideoCaptureSource::frameRateRangeIncludesRate): 31 (WebCore::RealtimeVideoCaptureSource::presetSupportsFrameRate): 32 (WebCore::RealtimeVideoCaptureSource::supportsCaptureSize): 33 (WebCore::RealtimeVideoCaptureSource::shouldUsePreset): 34 (WebCore::RealtimeVideoCaptureSource::bestSupportedSizeAndFrameRate): 35 (WebCore::RealtimeVideoCaptureSource::setSizeAndFrameRate): 36 (WebCore::RealtimeVideoCaptureSource::adaptVideoSample): 37 (WebCore::RealtimeVideoCaptureSource::dispatchMediaSampleToObservers): 38 (WebCore::RealtimeVideoCaptureSource::clientUpdatedSizeAndFrameRate): 39 (WebCore::SizeAndFrameRate::toJSONObject const): 40 (WebCore::SizeAndFrameRate::toJSONString const): 41 * platform/mediastream/RealtimeVideoCaptureSource.h: Added. 42 (WebCore::RealtimeVideoCaptureSource::sampleRotation const): 43 (WebCore::RealtimeVideoCaptureSource::prefersPreset): 44 (WebCore::RealtimeVideoCaptureSource::setFrameRateWithPreset): 45 (WebCore::RealtimeVideoCaptureSource::canResizeVideoFrames const): 46 (WebCore::RealtimeVideoCaptureSource::setDefaultSize): 47 (WebCore::RealtimeVideoCaptureSource::observedFrameRate const): 48 (WTF::LogArgument<WebCore::SizeAndFrameRate>::toString): 49 * platform/mediastream/RealtimeVideoSource.cpp: 50 (WebCore::RealtimeVideoSource::RealtimeVideoSource): 51 (WebCore::m_source): 52 (WebCore::RealtimeVideoSource::~RealtimeVideoSource): 53 (WebCore::RealtimeVideoSource::startProducingData): 54 (WebCore::RealtimeVideoSource::stopProducingData): 55 (WebCore::RealtimeVideoSource::supportsSizeAndFrameRate): 56 (WebCore::RealtimeVideoSource::setSizeAndFrameRate): 57 (WebCore::RealtimeVideoSource::sourceMutedChanged): 58 (WebCore::RealtimeVideoSource::sourceSettingsChanged): 59 (WebCore::RealtimeVideoSource::preventSourceFromStopping): 60 (WebCore::RealtimeVideoSource::sourceStopped): 61 (WebCore::RealtimeVideoSource::videoSampleAvailable): 62 (WebCore::RealtimeVideoSource::clone): 63 * platform/mediastream/RealtimeVideoSource.h: 64 * platform/mediastream/gstreamer/GStreamerVideoCaptureSource.cpp: 65 (WebCore::GStreamerVideoCaptureSource::GStreamerVideoCaptureSource): 66 * platform/mediastream/gstreamer/GStreamerVideoCaptureSource.h: 67 * platform/mediastream/mac/AVVideoCaptureSource.h: 68 * platform/mediastream/mac/AVVideoCaptureSource.mm: 69 (WebCore::AVVideoCaptureSource::create): 70 (WebCore::AVVideoCaptureSource::AVVideoCaptureSource): 71 * platform/mediastream/mac/MockRealtimeVideoSourceMac.h: 72 * platform/mediastream/mac/MockRealtimeVideoSourceMac.mm: 73 (WebCore::MockRealtimeVideoSource::create): 74 * platform/mock/MockRealtimeVideoSource.cpp: 75 (WebCore::MockRealtimeVideoSource::create): 76 (WebCore::MockRealtimeVideoSource::MockRealtimeVideoSource): 77 (WebCore::MockRealtimeVideoSource::supportsSizeAndFrameRate): 78 (WebCore::MockRealtimeVideoSource::setSizeAndFrameRate): 79 * platform/mock/MockRealtimeVideoSource.h: 80 1 81 2019-06-20 Saam Barati <sbarati@apple.com> 2 82 -
trunk/Source/WebCore/Headers.cmake
r246388 r246644 1146 1146 platform/mediastream/RealtimeMediaSourceSettings.h 1147 1147 platform/mediastream/RealtimeMediaSourceSupportedConstraints.h 1148 platform/mediastream/RealtimeVideoCaptureSource.h 1148 1149 platform/mediastream/RealtimeVideoSource.h 1149 1150 platform/mediastream/VideoPreset.h -
trunk/Source/WebCore/Sources.txt
r246631 r246644 1873 1873 platform/mediastream/RealtimeOutgoingAudioSource.cpp 1874 1874 platform/mediastream/RealtimeOutgoingVideoSource.cpp 1875 platform/mediastream/RealtimeVideoCaptureSource.cpp 1875 1876 platform/mediastream/RealtimeVideoSource.cpp 1876 1877 -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r246631 r246644 113 113 07277E5317D018CC0015534D /* JSMediaStreamTrack.h in Headers */ = {isa = PBXBuildFile; fileRef = 07277E4717D018CC0015534D /* JSMediaStreamTrack.h */; }; 114 114 07277E5517D018CC0015534D /* JSMediaStreamTrackEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 07277E4917D018CC0015534D /* JSMediaStreamTrackEvent.h */; }; 115 072880D12010F1F60071B255 /* RealtimeVideo Source.h in Headers */ = {isa = PBXBuildFile; fileRef = 072880D02010EED70071B255 /* RealtimeVideoSource.h */; settings = {ATTRIBUTES = (Private, ); }; };115 072880D12010F1F60071B255 /* RealtimeVideoCaptureSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 072880D02010EED70071B255 /* RealtimeVideoCaptureSource.h */; settings = {ATTRIBUTES = (Private, ); }; }; 116 116 072A70401D6E8F6200DF0AFC /* OverconstrainedErrorEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 072A703E1D6E8F6200DF0AFC /* OverconstrainedErrorEvent.h */; }; 117 117 072AE1E5183C0741000A5988 /* PluginReplacement.h in Headers */ = {isa = PBXBuildFile; fileRef = 072AE1DF183C0741000A5988 /* PluginReplacement.h */; settings = {ATTRIBUTES = (Private, ); }; }; … … 1118 1118 41B28B3D1F860EF300FB52AC /* LibWebRTCProviderCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = 41B28B361F860BD000FB52AC /* LibWebRTCProviderCocoa.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1119 1119 41B2A6261EF1BF6D002B9D7A /* WebAudioSourceProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 41B2A6251EF1BF60002B9D7A /* WebAudioSourceProvider.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1120 41BF204922BA7BE80004F812 /* RealtimeVideoSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 41BF204022B947160004F812 /* RealtimeVideoSource.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1120 1121 41C760B10EDE03D300C1655F /* ScriptState.h in Headers */ = {isa = PBXBuildFile; fileRef = 41C760B00EDE03D300C1655F /* ScriptState.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1121 1122 41D015CA0F4B5C71004A662F /* ContentType.h in Headers */ = {isa = PBXBuildFile; fileRef = 41D015C80F4B5C71004A662F /* ContentType.h */; settings = {ATTRIBUTES = (Private, ); }; }; … … 5382 5383 07277E4917D018CC0015534D /* JSMediaStreamTrackEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSMediaStreamTrackEvent.h; sourceTree = "<group>"; }; 5383 5384 072847E216EBC5B00043CFA4 /* PlatformTextTrack.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PlatformTextTrack.h; sourceTree = "<group>"; }; 5384 072880CE2010EED60071B255 /* RealtimeVideo Source.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RealtimeVideoSource.cpp; sourceTree = "<group>"; };5385 072880D02010EED70071B255 /* RealtimeVideo Source.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RealtimeVideoSource.h; sourceTree = "<group>"; };5385 072880CE2010EED60071B255 /* RealtimeVideoCaptureSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RealtimeVideoCaptureSource.cpp; sourceTree = "<group>"; }; 5386 072880D02010EED70071B255 /* RealtimeVideoCaptureSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RealtimeVideoCaptureSource.h; sourceTree = "<group>"; }; 5386 5387 072A703E1D6E8F6200DF0AFC /* OverconstrainedErrorEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OverconstrainedErrorEvent.h; sourceTree = "<group>"; }; 5387 5388 072A703F1D6E8F6200DF0AFC /* OverconstrainedErrorEvent.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = OverconstrainedErrorEvent.idl; sourceTree = "<group>"; }; … … 7389 7390 41B459DA1F4CADB90000F6FD /* ReadableStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReadableStream.h; sourceTree = "<group>"; }; 7390 7391 41B459ED1F55EBC70000F6FD /* ReadableStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ReadableStream.cpp; sourceTree = "<group>"; }; 7392 41BF204022B947160004F812 /* RealtimeVideoSource.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RealtimeVideoSource.h; sourceTree = "<group>"; }; 7393 41BF204222B947170004F812 /* RealtimeVideoSource.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = RealtimeVideoSource.cpp; sourceTree = "<group>"; }; 7391 7394 41C760B00EDE03D300C1655F /* ScriptState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptState.h; sourceTree = "<group>"; }; 7392 7395 41C7E1051E6A54360027B4DE /* CanvasCaptureMediaStreamTrack.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CanvasCaptureMediaStreamTrack.cpp; sourceTree = "<group>"; }; … … 15850 15853 5CDD833B1E4324BB00621E92 /* RealtimeOutgoingVideoSource.cpp */, 15851 15854 5CDD833C1E4324BB00621E92 /* RealtimeOutgoingVideoSource.h */, 15852 072880CE2010EED60071B255 /* RealtimeVideoSource.cpp */, 15853 072880D02010EED70071B255 /* RealtimeVideoSource.h */, 15855 072880CE2010EED60071B255 /* RealtimeVideoCaptureSource.cpp */, 15856 072880D02010EED70071B255 /* RealtimeVideoCaptureSource.h */, 15857 41BF204222B947170004F812 /* RealtimeVideoSource.cpp */, 15858 41BF204022B947160004F812 /* RealtimeVideoSource.h */, 15854 15859 3135910C1E7DDCB600F30630 /* RTCBundlePolicy.h */, 15855 15860 07221BA217CF0AD400848E51 /* RTCDataChannelHandler.h */, … … 31072 31077 41103AAC1E39791000769F03 /* RealtimeOutgoingAudioSource.h in Headers */, 31073 31078 41103AAC1E39791000769F14 /* RealtimeOutgoingAudioSourceCocoa.h in Headers */, 31074 072880D12010F1F60071B255 /* RealtimeVideoSource.h in Headers */, 31079 072880D12010F1F60071B255 /* RealtimeVideoCaptureSource.h in Headers */, 31080 41BF204922BA7BE80004F812 /* RealtimeVideoSource.h in Headers */, 31075 31081 91B952241F58A58F00931DC2 /* RecordingSwizzleTypes.h in Headers */, 31076 31082 BC4368E80C226E32005EFB5F /* Rect.h in Headers */, -
trunk/Source/WebCore/platform/mediastream/MediaStreamTrackPrivate.cpp
r246436 r246644 156 156 Ref<MediaStreamTrackPrivate> MediaStreamTrackPrivate::clone() 157 157 { 158 auto clonedMediaStreamTrackPrivate = create(m_logger.copyRef(), m_source .copyRef());158 auto clonedMediaStreamTrackPrivate = create(m_logger.copyRef(), m_source->clone()); 159 159 160 160 clonedMediaStreamTrackPrivate->m_isEnabled = this->m_isEnabled; … … 162 162 clonedMediaStreamTrackPrivate->m_contentHint = this->m_contentHint; 163 163 clonedMediaStreamTrackPrivate->updateReadyState(); 164 165 if (isProducingData()) 166 clonedMediaStreamTrackPrivate->startProducingData(); 164 167 165 168 return clonedMediaStreamTrackPrivate; -
trunk/Source/WebCore/platform/mediastream/RealtimeMediaSource.h
r243033 r246644 97 97 virtual ~RealtimeMediaSource() = default; 98 98 99 virtual Ref<RealtimeMediaSource> clone() { return *this; } 100 99 101 const String& hashedId() const; 100 102 String deviceIDHashSalt() const; … … 225 227 void audioSamplesAvailable(const MediaTime&, const PlatformAudioData&, const AudioStreamDescription&, size_t); 226 228 229 void forEachObserver(const WTF::Function<void(Observer&)>&) const; 230 227 231 private: 228 232 virtual void startProducingData() { } … … 231 235 232 236 virtual void hasEnded() { } 233 234 void forEachObserver(const WTF::Function<void(Observer&)>&) const;235 237 236 238 #if !RELEASE_LOG_DISABLED -
trunk/Source/WebCore/platform/mediastream/RealtimeVideoCaptureSource.cpp
r246643 r246644 25 25 26 26 #include "config.h" 27 #include "RealtimeVideo Source.h"27 #include "RealtimeVideoCaptureSource.h" 28 28 29 29 #if ENABLE(MEDIA_STREAM) … … 41 41 namespace WebCore { 42 42 43 RealtimeVideo Source::RealtimeVideoSource(String&& name, String&& id, String&& hashSalt)43 RealtimeVideoCaptureSource::RealtimeVideoCaptureSource(String&& name, String&& id, String&& hashSalt) 44 44 : RealtimeMediaSource(Type::Video, WTFMove(name), WTFMove(id), WTFMove(hashSalt)) 45 45 { 46 46 } 47 47 48 RealtimeVideo Source::~RealtimeVideoSource()48 RealtimeVideoCaptureSource::~RealtimeVideoCaptureSource() 49 49 { 50 50 #if PLATFORM(IOS_FAMILY) … … 53 53 } 54 54 55 void RealtimeVideo Source::prepareToProduceData()55 void RealtimeVideoCaptureSource::prepareToProduceData() 56 56 { 57 57 ASSERT(frameRate()); … … 65 65 } 66 66 67 const Vector<Ref<VideoPreset>>& RealtimeVideo Source::presets()67 const Vector<Ref<VideoPreset>>& RealtimeVideoCaptureSource::presets() 68 68 { 69 69 if (m_presets.isEmpty()) … … 74 74 } 75 75 76 void RealtimeVideo Source::setSupportedPresets(Vector<VideoPresetData>&& presetData)76 void RealtimeVideoCaptureSource::setSupportedPresets(Vector<VideoPresetData>&& presetData) 77 77 { 78 78 Vector<Ref<VideoPreset>> presets; … … 84 84 } 85 85 86 void RealtimeVideo Source::setSupportedPresets(const Vector<Ref<VideoPreset>>& presets)86 void RealtimeVideoCaptureSource::setSupportedPresets(const Vector<Ref<VideoPreset>>& presets) 87 87 { 88 88 m_presets = WTF::map(presets, [](auto& preset) { … … 98 98 } 99 99 100 const Vector<IntSize>& RealtimeVideo Source::standardVideoSizes()100 const Vector<IntSize>& RealtimeVideoCaptureSource::standardVideoSizes() 101 101 { 102 102 static const auto sizes = makeNeverDestroyed([] { … … 153 153 } 154 154 155 void RealtimeVideo Source::updateCapabilities(RealtimeMediaSourceCapabilities& capabilities)155 void RealtimeVideoCaptureSource::updateCapabilities(RealtimeMediaSourceCapabilities& capabilities) 156 156 { 157 157 ASSERT(!presets().isEmpty()); … … 180 180 minimumWidth = 1; 181 181 minimumHeight = 1; 182 for (auto& size : standardVideoSizes()) {183 if (size.width() < minimumWidth || size.height() < minimumHeight)184 minimumAspectRatio = std::min(minimumAspectRatio, static_cast<double>(size.width()) / size.height());185 }186 182 } 187 183 … … 192 188 } 193 189 194 bool RealtimeVideo Source::supportsSizeAndFrameRate(Optional<int> width, Optional<int> height, Optional<double> frameRate)190 bool RealtimeVideoCaptureSource::supportsSizeAndFrameRate(Optional<int> width, Optional<int> height, Optional<double> frameRate) 195 191 { 196 192 if (!width && !height && !frameRate) … … 200 196 } 201 197 202 bool RealtimeVideo Source::frameRateRangeIncludesRate(const FrameRateRange& range, double frameRate)198 bool RealtimeVideoCaptureSource::frameRateRangeIncludesRate(const FrameRateRange& range, double frameRate) 203 199 { 204 200 const double epsilon = 0.001; … … 206 202 } 207 203 208 bool RealtimeVideo Source::presetSupportsFrameRate(RefPtr<VideoPreset> preset, double frameRate)204 bool RealtimeVideoCaptureSource::presetSupportsFrameRate(RefPtr<VideoPreset> preset, double frameRate) 209 205 { 210 206 for (const auto& range : preset->frameRateRanges) { … … 216 212 } 217 213 218 bool RealtimeVideo Source::supportsCaptureSize(Optional<int> width, Optional<int> height, const Function<bool(const IntSize&)>&& function)214 bool RealtimeVideoCaptureSource::supportsCaptureSize(Optional<int> width, Optional<int> height, const Function<bool(const IntSize&)>&& function) 219 215 { 220 216 if (width && height) … … 238 234 } 239 235 240 bool RealtimeVideo Source::shouldUsePreset(VideoPreset& current, VideoPreset& candidate)236 bool RealtimeVideoCaptureSource::shouldUsePreset(VideoPreset& current, VideoPreset& candidate) 241 237 { 242 238 return candidate.size.width() <= current.size.width() && candidate.size.height() <= current.size.height() && prefersPreset(candidate); 243 239 } 244 240 245 Optional<RealtimeVideo Source::CaptureSizeAndFrameRate> RealtimeVideoSource::bestSupportedSizeAndFrameRate(Optional<int> requestedWidth, Optional<int> requestedHeight, Optional<double> requestedFrameRate)241 Optional<RealtimeVideoCaptureSource::CaptureSizeAndFrameRate> RealtimeVideoCaptureSource::bestSupportedSizeAndFrameRate(Optional<int> requestedWidth, Optional<int> requestedHeight, Optional<double> requestedFrameRate) 246 242 { 247 243 if (!requestedWidth && !requestedHeight && !requestedFrameRate) … … 359 355 } 360 356 361 void RealtimeVideo Source::setSizeAndFrameRate(Optional<int> width, Optional<int> height, Optional<double> frameRate)357 void RealtimeVideoCaptureSource::setSizeAndFrameRate(Optional<int> width, Optional<int> height, Optional<double> frameRate) 362 358 { 363 359 ALWAYS_LOG_IF(loggerPtr(), LOGIDENTIFIER, SizeAndFrameRate { width, height, frameRate }); … … 369 365 } 370 366 371 Optional<RealtimeVideo Source::CaptureSizeAndFrameRate> match = bestSupportedSizeAndFrameRate(width, height, frameRate);367 Optional<RealtimeVideoCaptureSource::CaptureSizeAndFrameRate> match = bestSupportedSizeAndFrameRate(width, height, frameRate); 372 368 ASSERT(match); 373 369 if (!match) … … 381 377 } 382 378 383 void RealtimeVideoSource::dispatchMediaSampleToObservers(MediaSample& sample)379 RefPtr<MediaSample> RealtimeVideoCaptureSource::adaptVideoSample(MediaSample& sample) 384 380 { 385 381 MediaTime sampleTime = sample.outputPresentationTime(); … … 398 394 399 395 auto mediaSample = makeRefPtr(&sample); 396 400 397 #if PLATFORM(COCOA) 401 398 if (!isRemote()) { … … 410 407 if (!mediaSample) { 411 408 ASSERT_NOT_REACHED(); 412 return ;409 return nullptr; 413 410 } 414 411 } … … 417 414 #endif 418 415 419 videoSampleAvailable(mediaSample.releaseNonNull()); 416 return mediaSample.releaseNonNull(); 417 } 418 419 void RealtimeVideoCaptureSource::dispatchMediaSampleToObservers(MediaSample& sample) 420 { 421 if (auto mediaSample = adaptVideoSample(sample)) 422 videoSampleAvailable(*mediaSample); 423 } 424 425 void RealtimeVideoCaptureSource::clientUpdatedSizeAndFrameRate(Optional<int> width, Optional<int> height, Optional<double> frameRate) 426 { 427 // FIXME: We only change settings if capture resolution is below requested one. We should get the best preset for all clients. 428 auto& settings = this->settings(); 429 if (width && *width < static_cast<int>(settings.width())) 430 width = { }; 431 if (height && *height < static_cast<int>(settings.height())) 432 height = { }; 433 434 // FIXME: handle frameRate potential increase. 435 if (!width && !height) 436 return; 437 438 auto match = bestSupportedSizeAndFrameRate(width, height, frameRate); 439 ERROR_LOG_IF(loggerPtr() && !match, LOGIDENTIFIER, "unable to find a preset that would match the size and frame rate"); 440 if (!match) 441 return; 442 443 setFrameRateWithPreset(match->requestedFrameRate, match->encodingPreset); 444 setSize(match->encodingPreset->size); 445 setFrameRate(match->requestedFrameRate); 420 446 } 421 447 -
trunk/Source/WebCore/platform/mediastream/RealtimeVideoCaptureSource.h
r246643 r246644 39 39 class ImageTransferSessionVT; 40 40 41 class RealtimeVideo Source : public RealtimeMediaSource {41 class RealtimeVideoCaptureSource : public RealtimeMediaSource { 42 42 public: 43 virtual ~RealtimeVideoSource(); 43 virtual ~RealtimeVideoCaptureSource(); 44 45 void clientUpdatedSizeAndFrameRate(Optional<int> width, Optional<int> height, Optional<double> frameRate); 46 47 bool supportsSizeAndFrameRate(Optional<int> width, Optional<int> height, Optional<double>) override; 48 virtual void generatePresets() = 0; 49 virtual MediaSample::VideoRotation sampleRotation() const { return MediaSample::VideoRotation::None; } 44 50 45 51 protected: 46 RealtimeVideo Source(String&& name, String&& id, String&& hashSalt);52 RealtimeVideoCaptureSource(String&& name, String&& id, String&& hashSalt); 47 53 48 54 void prepareToProduceData(); 49 bool supportsSizeAndFrameRate(Optional<int> width, Optional<int> height, Optional<double>) override;50 55 void setSizeAndFrameRate(Optional<int> width, Optional<int> height, Optional<double>) override; 51 56 52 virtual void generatePresets() = 0;53 57 virtual bool prefersPreset(VideoPreset&) { return true; } 54 58 virtual void setFrameRateWithPreset(double, RefPtr<VideoPreset>) { }; … … 70 74 void dispatchMediaSampleToObservers(MediaSample&); 71 75 const Vector<IntSize>& standardVideoSizes(); 76 RefPtr<MediaSample> adaptVideoSample(MediaSample&); 72 77 73 78 private: … … 82 87 83 88 #if !RELEASE_LOG_DISABLED 84 const char* logClassName() const override { return "RealtimeVideo Source"; }89 const char* logClassName() const override { return "RealtimeVideoCaptureSource"; } 85 90 #endif 86 91 -
trunk/Source/WebCore/platform/mediastream/RealtimeVideoSource.cpp
r246049 r246644 1 1 /* 2 * Copyright (C) 201 8-2019 Apple Inc. All rights reserved.2 * Copyright (C) 2019 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 28 28 29 29 #if ENABLE(MEDIA_STREAM) 30 #include "CaptureDevice.h"31 #include "Logging.h"32 #include "RealtimeMediaSourceCenter.h"33 #include "RealtimeMediaSourceSettings.h"34 #include "RemoteVideoSample.h"35 #include <wtf/JSONValues.h>36 37 #if PLATFORM(COCOA)38 #include "ImageTransferSessionVT.h"39 #endif40 30 41 31 namespace WebCore { 42 32 43 RealtimeVideoSource::RealtimeVideoSource(String&& name, String&& id, String&& hashSalt) 44 : RealtimeMediaSource(Type::Video, WTFMove(name), WTFMove(id), WTFMove(hashSalt)) 33 RealtimeVideoSource::RealtimeVideoSource(Ref<RealtimeVideoCaptureSource>&& source) 34 : RealtimeVideoCaptureSource(String { source->name() }, String { source->persistentID() }, String { source->deviceIDHashSalt() }) 35 , m_source(WTFMove(source)) 45 36 { 37 m_source->addObserver(*this); 38 m_currentSettings = m_source->settings(); 46 39 } 47 40 48 41 RealtimeVideoSource::~RealtimeVideoSource() 49 42 { 50 #if PLATFORM(IOS_FAMILY) 51 RealtimeMediaSourceCenter::singleton().videoCaptureFactory().unsetActiveSource(*this); 52 #endif 43 m_source->removeObserver(*this); 53 44 } 54 45 55 void RealtimeVideoSource:: prepareToProduceData()46 void RealtimeVideoSource::startProducingData() 56 47 { 57 ASSERT(frameRate()); 58 59 #if PLATFORM(IOS_FAMILY) 60 RealtimeMediaSourceCenter::singleton().videoCaptureFactory().setActiveSource(*this); 61 #endif 62 63 if (size().isEmpty() && !m_defaultSize.isEmpty()) 64 setSize(m_defaultSize); 48 m_source->start(); 65 49 } 66 50 67 const Vector<Ref<VideoPreset>>& RealtimeVideoSource::presets()51 void RealtimeVideoSource::stopProducingData() 68 52 { 69 if (m_presets.isEmpty()) 70 generatePresets(); 71 72 ASSERT(!m_presets.isEmpty()); 73 return m_presets; 74 } 75 76 void RealtimeVideoSource::setSupportedPresets(Vector<VideoPresetData>&& presetData) 77 { 78 Vector<Ref<VideoPreset>> presets; 79 80 for (auto& data : presetData) 81 presets.append(VideoPreset::create(WTFMove(data))); 82 83 setSupportedPresets(WTFMove(presets)); 84 } 85 86 void RealtimeVideoSource::setSupportedPresets(const Vector<Ref<VideoPreset>>& presets) 87 { 88 m_presets = WTF::map(presets, [](auto& preset) { 89 return preset.copyRef(); 90 }); 91 92 for (auto& preset : m_presets) { 93 std::sort(preset->frameRateRanges.begin(), preset->frameRateRanges.end(), 94 [&] (const auto& a, const auto& b) -> bool { 95 return a.minimum < b.minimum; 96 }); 97 } 98 } 99 100 const Vector<IntSize>& RealtimeVideoSource::standardVideoSizes() 101 { 102 static const auto sizes = makeNeverDestroyed([] { 103 static IntSize videoSizes[] = { 104 { 112, 112 }, 105 { 160, 160 }, 106 { 160, 120 }, // 4:3, QQVGA 107 { 176, 144 }, // 4:3, QCIF 108 { 192, 192 }, 109 { 192, 112 }, // 16:9 110 { 192, 144 }, // 3:4 111 { 240, 240 }, 112 { 240, 160 }, // 3:2, HQVGA 113 { 320, 320 }, 114 { 320, 180 }, // 16:9 115 { 320, 240 }, // 4:3, QVGA 116 { 352, 288 }, // CIF 117 { 480, 272 }, // 16:9 118 { 480, 360 }, // 4:3 119 { 480, 480 }, 120 { 640, 640 }, 121 { 640, 360 }, // 16:9, 360p nHD 122 { 640, 480 }, // 4:3 123 { 720, 720 }, 124 { 800, 600 }, // 4:3, SVGA 125 { 960, 540 }, // 16:9, qHD 126 { 1024, 600 }, // 16:9, WSVGA 127 { 1024, 768 }, // 4:3, XGA 128 { 1280, 960 }, // 4:3 129 { 1280, 1024 }, // 5:4, SXGA 130 { 1280, 720 }, // 16:9, WXGA 131 { 1366, 768 }, // 16:9, HD 132 { 1600, 1200}, // 4:3, UXGA 133 { 1920, 1080 }, // 16:9, 1080p FHD 134 { 2560, 1440 }, // 16:9, QHD 135 { 2592, 1936 }, 136 { 3264, 2448 }, // 3:4 137 { 3840, 2160 }, // 16:9, 4K UHD 138 }; 139 Vector<IntSize> sizes; 140 for (auto& size : videoSizes) 141 sizes.append(size); 142 143 return sizes; 144 }()); 145 146 return sizes.get(); 147 } 148 template <typename ValueType> 149 static void updateMinMax(ValueType& min, ValueType& max, ValueType value) 150 { 151 min = std::min<ValueType>(min, value); 152 max = std::max<ValueType>(max, value); 153 } 154 155 void RealtimeVideoSource::updateCapabilities(RealtimeMediaSourceCapabilities& capabilities) 156 { 157 ASSERT(!presets().isEmpty()); 158 159 int minimumWidth = std::numeric_limits<int>::max(); 160 int maximumWidth = 0; 161 int minimumHeight = std::numeric_limits<int>::max(); 162 int maximumHeight = 0; 163 double minimumAspectRatio = std::numeric_limits<double>::max(); 164 double maximumAspectRatio = 0; 165 double minimumFrameRate = std::numeric_limits<double>::max(); 166 double maximumFrameRate = 0; 167 for (const auto& preset : presets()) { 168 const auto& size = preset->size; 169 updateMinMax(minimumWidth, maximumWidth, size.width()); 170 updateMinMax(minimumHeight, maximumHeight, size.height()); 171 updateMinMax(minimumAspectRatio, maximumAspectRatio, static_cast<double>(size.width()) / size.height()); 172 173 for (const auto& rate : preset->frameRateRanges) { 174 updateMinMax(minimumFrameRate, maximumFrameRate, rate.minimum); 175 updateMinMax(minimumFrameRate, maximumFrameRate, rate.maximum); 176 } 177 } 178 179 if (canResizeVideoFrames()) { 180 minimumWidth = 1; 181 minimumHeight = 1; 182 for (auto& size : standardVideoSizes()) { 183 if (size.width() < minimumWidth || size.height() < minimumHeight) 184 minimumAspectRatio = std::min(minimumAspectRatio, static_cast<double>(size.width()) / size.height()); 185 } 186 } 187 188 capabilities.setWidth({ minimumWidth, maximumWidth }); 189 capabilities.setHeight({ minimumHeight, maximumHeight }); 190 capabilities.setAspectRatio({ minimumAspectRatio, maximumAspectRatio }); 191 capabilities.setFrameRate({ minimumFrameRate, maximumFrameRate }); 53 m_source->stop(); 192 54 } 193 55 194 56 bool RealtimeVideoSource::supportsSizeAndFrameRate(Optional<int> width, Optional<int> height, Optional<double> frameRate) 195 57 { 196 if (!width && !height && !frameRate) 197 return true; 198 199 return !!bestSupportedSizeAndFrameRate(width, height, frameRate); 200 } 201 202 bool RealtimeVideoSource::frameRateRangeIncludesRate(const FrameRateRange& range, double frameRate) 203 { 204 const double epsilon = 0.001; 205 return frameRate + epsilon >= range.minimum && frameRate - epsilon <= range.maximum; 206 } 207 208 bool RealtimeVideoSource::presetSupportsFrameRate(RefPtr<VideoPreset> preset, double frameRate) 209 { 210 for (const auto& range : preset->frameRateRanges) { 211 if (frameRateRangeIncludesRate(range, frameRate)) 212 return true; 213 } 214 215 return false; 216 } 217 218 bool RealtimeVideoSource::supportsCaptureSize(Optional<int> width, Optional<int> height, const Function<bool(const IntSize&)>&& function) 219 { 220 if (width && height) 221 return function({ width.value(), height.value() }); 222 223 if (width) { 224 for (auto& size : standardVideoSizes()) { 225 if (width.value() == size.width() && function({ size.width(), size.height() })) 226 return true; 227 } 228 229 return false; 230 } 231 232 for (auto& size : standardVideoSizes()) { 233 if (height.value() == size.height() && function({ size.width(), size.height() })) 234 return true; 235 } 236 237 return false; 238 } 239 240 bool RealtimeVideoSource::shouldUsePreset(VideoPreset& current, VideoPreset& candidate) 241 { 242 return candidate.size.width() <= current.size.width() && candidate.size.height() <= current.size.height() && prefersPreset(candidate); 243 } 244 245 Optional<RealtimeVideoSource::CaptureSizeAndFrameRate> RealtimeVideoSource::bestSupportedSizeAndFrameRate(Optional<int> requestedWidth, Optional<int> requestedHeight, Optional<double> requestedFrameRate) 246 { 247 if (!requestedWidth && !requestedHeight && !requestedFrameRate) 248 return { }; 249 250 if (!requestedWidth && !requestedHeight && !size().isEmpty()) { 251 requestedWidth = size().width(); 252 requestedHeight = size().height(); 253 } 254 if (!requestedFrameRate) 255 requestedFrameRate = frameRate(); 256 257 CaptureSizeAndFrameRate result; 258 RefPtr<VideoPreset> exactSizePreset; 259 RefPtr<VideoPreset> aspectRatioPreset; 260 IntSize aspectRatioMatchSize; 261 RefPtr<VideoPreset> resizePreset; 262 IntSize resizeSize; 263 264 for (const auto& preset : presets()) { 265 const auto& presetSize = preset->size; 266 267 if (!presetSupportsFrameRate(&preset.get(), requestedFrameRate.value())) 268 continue; 269 270 if (!requestedWidth && !requestedHeight) { 271 result.requestedFrameRate = requestedFrameRate.value(); 272 return result; 273 } 274 275 // Don't look at presets smaller than the requested resolution because we never want to resize larger. 276 if ((requestedWidth && presetSize.width() < requestedWidth.value()) || (requestedHeight && presetSize.height() < requestedHeight.value())) 277 continue; 278 279 auto lookForExactSizeMatch = [&] (const IntSize& size) -> bool { 280 return preset->size == size; 281 }; 282 if (supportsCaptureSize(requestedWidth, requestedHeight, WTFMove(lookForExactSizeMatch))) { 283 if (!exactSizePreset || prefersPreset(preset)) 284 exactSizePreset = &preset.get(); 285 continue; 286 } 287 288 IntSize encodingSize; 289 auto lookForAspectRatioMatch = [this, &preset, &encodingSize] (const IntSize& size) -> bool { 290 auto aspectRatio = [] (const IntSize size) -> double { 291 return size.width() / static_cast<double>(size.height()); 292 }; 293 if (std::abs(aspectRatio(preset->size) - aspectRatio(size)) > 10e-7 || !canResizeVideoFrames()) 294 return false; 295 296 encodingSize = size; 297 return true; 298 }; 299 if (supportsCaptureSize(requestedWidth, requestedHeight, WTFMove(lookForAspectRatioMatch))) { 300 if (!aspectRatioPreset || shouldUsePreset(*aspectRatioPreset, preset)) { 301 aspectRatioPreset = &preset.get(); 302 aspectRatioMatchSize = encodingSize; 303 } 304 } 305 306 if (exactSizePreset || aspectRatioPreset) 307 continue; 308 309 if ((requestedWidth && requestedWidth.value() > preset->size.width()) || (requestedHeight && requestedHeight.value() > preset->size.height())) 310 continue; 311 312 if (requestedWidth && requestedHeight) { 313 if (!resizePreset || shouldUsePreset(*resizePreset, preset)) { 314 resizePreset = &preset.get(); 315 resizeSize = { requestedWidth.value(), requestedHeight.value() }; 316 } 317 } else { 318 for (auto& standardSize : standardVideoSizes()) { 319 if (standardSize.width() > preset->size.width() || standardSize.height() > preset->size.height()) 320 break; 321 if ((requestedWidth && requestedWidth.value() != standardSize.width()) || (requestedHeight && requestedHeight.value() != standardSize.height())) 322 continue; 323 324 if (!resizePreset || shouldUsePreset(*resizePreset, preset)) { 325 resizePreset = &preset.get(); 326 resizeSize = standardSize; 327 } 328 } 329 330 if (!resizePreset || shouldUsePreset(*resizePreset, preset)) { 331 resizePreset = &preset.get(); 332 if (requestedWidth) 333 resizeSize = { requestedWidth.value(), requestedWidth.value() * preset->size.height() / preset->size.width()}; 334 else 335 resizeSize = { requestedHeight.value() * preset->size.width() / preset->size.height(), requestedHeight.value() }; 336 } 337 } 338 } 339 340 if (!exactSizePreset && !aspectRatioPreset && !resizePreset) 341 return { }; 342 343 result.requestedFrameRate = requestedFrameRate.value(); 344 if (exactSizePreset) { 345 result.encodingPreset = exactSizePreset; 346 result.requestedSize = exactSizePreset->size; 347 return result; 348 } 349 350 if (aspectRatioPreset) { 351 result.encodingPreset = aspectRatioPreset; 352 result.requestedSize = aspectRatioMatchSize; 353 return result; 354 } 355 356 result.encodingPreset = resizePreset; 357 result.requestedSize = resizeSize; 358 return result; 58 return m_source->supportsSizeAndFrameRate(width, height, frameRate); 359 59 } 360 60 361 61 void RealtimeVideoSource::setSizeAndFrameRate(Optional<int> width, Optional<int> height, Optional<double> frameRate) 362 62 { 363 ALWAYS_LOG_IF(loggerPtr(), LOGIDENTIFIER, SizeAndFrameRate { width, height, frameRate }); 364 365 auto size = this->size(); 366 if (!width && !height && !size.isEmpty()) { 367 width = size.width(); 368 height = size.height(); 63 if (!width && !height) { 64 width = size().width(); 65 height = size().height(); 369 66 } 370 67 371 Optional<RealtimeVideoSource::CaptureSizeAndFrameRate> match = bestSupportedSizeAndFrameRate(width, height, frameRate); 372 ASSERT(match); 373 if (!match) 68 m_source->clientUpdatedSizeAndFrameRate(width, height, frameRate); 69 auto sourceSize = m_source->size(); 70 ASSERT(sourceSize.height()); 71 ASSERT(sourceSize.width()); 72 73 if (!width) 74 width = sourceSize.width() * height.value() / sourceSize.height(); 75 m_currentSettings.setWidth(*width); 76 77 if (!height) 78 height = sourceSize.height() * width.value() / sourceSize.width(); 79 m_currentSettings.setHeight(*height); 80 81 if (frameRate) 82 m_currentSettings.setFrameRate(static_cast<float>(*frameRate)); 83 84 RealtimeMediaSource::setSizeAndFrameRate(width, height, frameRate); 85 } 86 87 void RealtimeVideoSource::sourceMutedChanged() 88 { 89 notifyMutedChange(m_source->muted()); 90 } 91 92 void RealtimeVideoSource::sourceSettingsChanged() 93 { 94 auto rotation = m_source->sampleRotation(); 95 if (rotation == MediaSample::VideoRotation::Left || rotation == MediaSample::VideoRotation::Right) { 96 auto size = this->size(); 97 size = size.transposedSize(); 98 m_currentSettings.setWidth(size.width()); 99 m_currentSettings.setHeight(size.height()); 100 } 101 102 forEachObserver([&](auto& observer) { 103 observer.sourceSettingsChanged(); 104 }); 105 } 106 107 bool RealtimeVideoSource::preventSourceFromStopping() 108 { 109 if (!isProducingData()) 110 return false; 111 112 bool hasObserverPreventingStopping = false; 113 forEachObserver([&](auto& observer) { 114 if (observer.preventSourceFromStopping()) 115 hasObserverPreventingStopping = true; 116 }); 117 return hasObserverPreventingStopping; 118 } 119 120 void RealtimeVideoSource::sourceStopped() 121 { 122 if (m_source->captureDidFail()) { 123 captureFailed(); 124 return; 125 } 126 stop(); 127 forEachObserver([](auto& observer) { 128 observer.sourceStopped(); 129 }); 130 } 131 132 void RealtimeVideoSource::videoSampleAvailable(MediaSample& sample) 133 { 134 if (!isProducingData()) 374 135 return; 375 136 376 setFrameRateWithPreset(match->requestedFrameRate, match->encodingPreset); 377 378 if (!match->requestedSize.isEmpty()) 379 setSize(match->requestedSize); 380 setFrameRate(match->requestedFrameRate); 137 if (auto mediaSample = adaptVideoSample(sample)) 138 RealtimeMediaSource::videoSampleAvailable(*mediaSample); 381 139 } 382 140 383 void RealtimeVideoSource::dispatchMediaSampleToObservers(MediaSample& sample)141 Ref<RealtimeMediaSource> RealtimeVideoSource::clone() 384 142 { 385 MediaTime sampleTime = sample.outputPresentationTime(); 386 if (!sampleTime || !sampleTime.isValid()) 387 sampleTime = sample.presentationTime(); 143 auto source = create(m_source.copyRef()); 144 source->m_currentSettings = m_currentSettings; 388 145 389 auto frameTime = sampleTime.toDouble(); 390 m_observedFrameTimeStamps.append(frameTime); 391 m_observedFrameTimeStamps.removeAllMatching([&](auto time) { 392 return time <= frameTime - 2; 393 }); 394 395 auto interval = m_observedFrameTimeStamps.last() - m_observedFrameTimeStamps.first(); 396 if (interval > 1) 397 m_observedFrameRate = (m_observedFrameTimeStamps.size() / interval); 398 399 auto mediaSample = makeRefPtr(&sample); 400 #if PLATFORM(COCOA) 401 if (!isRemote()) { 402 auto size = this->size(); 403 if (!size.isEmpty() && size != expandedIntSize(sample.presentationSize())) { 404 405 if (!m_imageTransferSession || m_imageTransferSession->pixelFormat() != sample.videoPixelFormat()) 406 m_imageTransferSession = ImageTransferSessionVT::create(sample.videoPixelFormat()); 407 408 if (m_imageTransferSession) { 409 mediaSample = m_imageTransferSession->convertMediaSample(sample, size); 410 if (!mediaSample) { 411 ASSERT_NOT_REACHED(); 412 return; 413 } 414 } 415 } 416 } 417 #endif 418 419 videoSampleAvailable(mediaSample.releaseNonNull()); 146 return source; 420 147 } 421 422 #if !RELEASE_LOG_DISABLED423 Ref<JSON::Object> SizeAndFrameRate::toJSONObject() const424 {425 auto object = JSON::Object::create();426 427 object->setDouble("width"_s, width ? width.value() : 0);428 object->setDouble("height"_s, height ? height.value() : 0);429 object->setDouble("frameRate"_s, frameRate ? frameRate.value() : 0);430 431 return object;432 }433 434 String SizeAndFrameRate::toJSONString() const435 {436 return toJSONObject()->toJSONString();437 }438 #endif439 148 440 149 } // namespace WebCore -
trunk/Source/WebCore/platform/mediastream/RealtimeVideoSource.h
r245296 r246644 1 1 /* 2 * Copyright (C) 201 8-2019 Apple Inc. All rights reserved.2 * Copyright (C) 2019 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 28 28 #if ENABLE(MEDIA_STREAM) 29 29 30 #include "ImageBuffer.h" 31 #include "MediaSample.h" 32 #include "RealtimeMediaSource.h" 33 #include "VideoPreset.h" 34 #include <wtf/Lock.h> 35 #include <wtf/RunLoop.h> 30 #include "RealtimeVideoCaptureSource.h" 36 31 37 32 namespace WebCore { 38 33 39 class ImageTransferSessionVT; 40 41 class RealtimeVideoSource : public RealtimeMediaSource { 34 // FIXME: Make RealtimeVideoSource derive from RealtimeMediaSource directly. 35 class RealtimeVideoSource final : public RealtimeVideoCaptureSource, public RealtimeMediaSource::Observer { 42 36 public: 43 virtual ~RealtimeVideoSource(); 44 45 protected: 46 RealtimeVideoSource(String&& name, String&& id, String&& hashSalt); 47 48 void prepareToProduceData(); 49 bool supportsSizeAndFrameRate(Optional<int> width, Optional<int> height, Optional<double>) override; 50 void setSizeAndFrameRate(Optional<int> width, Optional<int> height, Optional<double>) override; 51 52 virtual void generatePresets() = 0; 53 virtual bool prefersPreset(VideoPreset&) { return true; } 54 virtual void setFrameRateWithPreset(double, RefPtr<VideoPreset>) { }; 55 virtual bool canResizeVideoFrames() const { return false; } 56 bool shouldUsePreset(VideoPreset& current, VideoPreset& candidate); 57 58 void setSupportedPresets(const Vector<Ref<VideoPreset>>&); 59 void setSupportedPresets(Vector<VideoPresetData>&&); 60 const Vector<Ref<VideoPreset>>& presets(); 61 62 bool frameRateRangeIncludesRate(const FrameRateRange&, double); 63 64 void updateCapabilities(RealtimeMediaSourceCapabilities&); 65 66 void setDefaultSize(const IntSize& size) { m_defaultSize = size; } 67 68 double observedFrameRate() const { return m_observedFrameRate; } 69 70 void dispatchMediaSampleToObservers(MediaSample&); 71 const Vector<IntSize>& standardVideoSizes(); 37 static Ref<RealtimeVideoSource> create(Ref<RealtimeVideoCaptureSource>&& source) { return adoptRef(*new RealtimeVideoSource(WTFMove(source))); } 72 38 73 39 private: 74 struct CaptureSizeAndFrameRate { 75 RefPtr<VideoPreset> encodingPreset; 76 IntSize requestedSize; 77 double requestedFrameRate { 0 }; 78 }; 79 bool supportsCaptureSize(Optional<int>, Optional<int>, const Function<bool(const IntSize&)>&&); 80 Optional<CaptureSizeAndFrameRate> bestSupportedSizeAndFrameRate(Optional<int> width, Optional<int> height, Optional<double>); 81 bool presetSupportsFrameRate(RefPtr<VideoPreset>, double); 40 explicit RealtimeVideoSource(Ref<RealtimeVideoCaptureSource>&&); 41 ~RealtimeVideoSource(); 82 42 83 #if !RELEASE_LOG_DISABLED 84 const char* logClassName() const override { return "RealtimeVideoSource"; } 85 #endif 43 // RealtimeVideoCaptureSource 44 void startProducingData() final; 45 void stopProducingData() final; 46 bool supportsSizeAndFrameRate(Optional<int> width, Optional<int> height, Optional<double> frameRate) final; 47 void setSizeAndFrameRate(Optional<int> width, Optional<int> height, Optional<double> frameRate) final; 48 Ref<RealtimeMediaSource> clone() final; 86 49 87 Vector<Ref<VideoPreset>> m_presets; 88 Deque<double> m_observedFrameTimeStamps; 89 double m_observedFrameRate { 0 }; 90 IntSize m_defaultSize; 91 #if PLATFORM(COCOA) 92 std::unique_ptr<ImageTransferSessionVT> m_imageTransferSession; 93 #endif 94 }; 50 const RealtimeMediaSourceCapabilities& capabilities() final { return m_source->capabilities(); } 51 const RealtimeMediaSourceSettings& settings() final { return m_currentSettings; } 52 void generatePresets() final { m_source->generatePresets(); } 53 bool isCaptureSource() const final { return m_source->isCaptureSource(); } 54 CaptureDevice::DeviceType deviceType() const final { return m_source->deviceType(); } 55 void monitorOrientation(OrientationNotifier& notifier) final { m_source->monitorOrientation(notifier); } 56 bool interrupted() const final { return m_source->interrupted(); } 95 57 96 struct SizeAndFrameRate { 97 Optional<int> width; 98 Optional<int> height; 99 Optional<double> frameRate; 58 // Observer 59 void sourceMutedChanged() final; 60 void sourceSettingsChanged() final; 61 void sourceStopped() final; 62 bool preventSourceFromStopping() final; 63 void videoSampleAvailable(MediaSample&) final; 100 64 101 String toJSONString() const;102 Re f<JSON::Object> toJSONObject() const;65 Ref<RealtimeVideoCaptureSource> m_source; 66 RealtimeMediaSourceSettings m_currentSettings; 103 67 }; 104 68 105 69 } // namespace WebCore 106 70 107 namespace WTF {108 template<typename Type> struct LogArgument;109 template <>110 struct LogArgument<WebCore::SizeAndFrameRate> {111 static String toString(const WebCore::SizeAndFrameRate& size)112 {113 return size.toJSONString();114 }115 };116 }; // namespace WTF117 118 71 #endif // ENABLE(MEDIA_STREAM) 119 72 -
trunk/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoCaptureSource.cpp
r241587 r246644 127 127 128 128 GStreamerVideoCaptureSource::GStreamerVideoCaptureSource(String&& deviceID, String&& name, String&& hashSalt, const gchar *source_factory) 129 : RealtimeVideo Source(WTFMove(deviceID), WTFMove(name), WTFMove(hashSalt))129 : RealtimeVideoCaptureSource(WTFMove(deviceID), WTFMove(name), WTFMove(hashSalt)) 130 130 , m_capturer(std::make_unique<GStreamerVideoCapturer>(source_factory)) 131 131 { … … 134 134 135 135 GStreamerVideoCaptureSource::GStreamerVideoCaptureSource(GStreamerCaptureDevice device, String&& hashSalt) 136 : RealtimeVideo Source(String { device.persistentId() }, String { device.label() }, WTFMove(hashSalt))136 : RealtimeVideoCaptureSource(String { device.persistentId() }, String { device.label() }, WTFMove(hashSalt)) 137 137 , m_capturer(std::make_unique<GStreamerVideoCapturer>(device)) 138 138 { -
trunk/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoCaptureSource.h
r239925 r246644 25 25 #include "CaptureDevice.h" 26 26 #include "GStreamerVideoCapturer.h" 27 #include "RealtimeVideo Source.h"27 #include "RealtimeVideoCaptureSource.h" 28 28 29 29 namespace WebCore { 30 30 31 class GStreamerVideoCaptureSource : public RealtimeVideo Source {31 class GStreamerVideoCaptureSource : public RealtimeVideoCaptureSource { 32 32 public: 33 33 static CaptureSourceOrError create(String&& deviceID, String&& hashSalt, const MediaConstraints*); -
trunk/Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.h
r245296 r246644 30 30 #include "IntSizeHash.h" 31 31 #include "OrientationNotifier.h" 32 #include "RealtimeVideo Source.h"32 #include "RealtimeVideoCaptureSource.h" 33 33 #include <wtf/Lock.h> 34 34 #include <wtf/text/StringHash.h> … … 52 52 class ImageTransferSessionVT; 53 53 54 class AVVideoCaptureSource : public RealtimeVideo Source, private OrientationNotifier::Observer {54 class AVVideoCaptureSource : public RealtimeVideoCaptureSource, private OrientationNotifier::Observer { 55 55 public: 56 56 static CaptureSourceOrError create(String&& id, String&& hashSalt, const MediaConstraints*); … … 92 92 bool interrupted() const final; 93 93 94 MediaSample::VideoRotation sampleRotation() const final { return m_sampleRotation; } 94 95 void setFrameRateWithPreset(double, RefPtr<VideoPreset>) final; 95 96 bool prefersPreset(VideoPreset&) final; -
trunk/Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.mm
r246489 r246644 38 38 #import "RealtimeMediaSourceCenter.h" 39 39 #import "RealtimeMediaSourceSettings.h" 40 #import "RealtimeVideoSource.h" 40 41 #import "RealtimeVideoUtilities.h" 41 42 #import <AVFoundation/AVCaptureDevice.h> … … 122 123 } 123 124 124 return CaptureSourceOrError( WTFMove(source));125 return CaptureSourceOrError(RealtimeVideoSource::create(WTFMove(source))); 125 126 } 126 127 127 128 AVVideoCaptureSource::AVVideoCaptureSource(AVCaptureDevice* device, String&& id, String&& hashSalt) 128 : RealtimeVideo Source(device.localizedName, WTFMove(id), WTFMove(hashSalt))129 : RealtimeVideoCaptureSource(device.localizedName, WTFMove(id), WTFMove(hashSalt)) 129 130 , m_objcObserver(adoptNS([[WebCoreAVVideoCaptureSourceObserver alloc] initWithCallback:this])) 130 131 , m_device(device) … … 638 639 } 639 640 640 641 641 } // namespace WebCore 642 642 -
trunk/Source/WebCore/platform/mediastream/mac/MockRealtimeVideoSourceMac.h
r237236 r246644 60 60 void orientationChanged(int orientation) final; 61 61 void monitorOrientation(OrientationNotifier&) final; 62 MediaSample::VideoRotation sampleRotation() const final { return m_deviceOrientation; } 62 63 63 64 MediaSample::VideoRotation m_deviceOrientation { MediaSample::VideoRotation::None }; -
trunk/Source/WebCore/platform/mediastream/mac/MockRealtimeVideoSourceMac.mm
r244704 r246644 42 42 #import "PlatformLayer.h" 43 43 #import "RealtimeMediaSourceSettings.h" 44 #import "RealtimeVideoSource.h" 44 45 #import "RealtimeVideoUtilities.h" 45 46 #import <QuartzCore/CALayer.h> … … 67 68 return { }; 68 69 69 return CaptureSourceOrError( WTFMove(source));70 return CaptureSourceOrError(RealtimeVideoSource::create(WTFMove(source))); 70 71 } 71 72 -
trunk/Source/WebCore/platform/mock/MockRealtimeVideoSource.cpp
r245296 r246644 43 43 #include "PlatformLayer.h" 44 44 #include "RealtimeMediaSourceSettings.h" 45 #include "RealtimeVideoSource.h" 45 46 #include <math.h> 46 47 #include <wtf/UUID.h> … … 63 64 return { }; 64 65 65 return CaptureSourceOrError( WTFMove(source));66 return CaptureSourceOrError(RealtimeVideoSource::create(WTFMove(source))); 66 67 } 67 68 #endif 68 69 69 70 MockRealtimeVideoSource::MockRealtimeVideoSource(String&& deviceID, String&& name, String&& hashSalt) 70 : RealtimeVideo Source(WTFMove(name), WTFMove(deviceID), WTFMove(hashSalt))71 : RealtimeVideoCaptureSource(WTFMove(name), WTFMove(deviceID), WTFMove(hashSalt)) 71 72 , m_emitFrameTimer(RunLoop::current(), this, &MockRealtimeVideoSource::generateFrame) 72 73 { … … 98 99 // because of the RealtimeVideoSource inheritance. 99 100 if (mockCamera()) 100 return RealtimeVideo Source::supportsSizeAndFrameRate(width, height, rate);101 return RealtimeVideoCaptureSource::supportsSizeAndFrameRate(width, height, rate); 101 102 102 103 return RealtimeMediaSource::supportsSizeAndFrameRate(width, height, rate); … … 108 109 // because of the RealtimeVideoSource inheritance. 109 110 if (mockCamera()) { 110 RealtimeVideo Source::setSizeAndFrameRate(width, height, rate);111 RealtimeVideoCaptureSource::setSizeAndFrameRate(width, height, rate); 111 112 return; 112 113 } -
trunk/Source/WebCore/platform/mock/MockRealtimeVideoSource.h
r245296 r246644 38 38 #include "MockMediaDevice.h" 39 39 #include "RealtimeMediaSourceFactory.h" 40 #include "RealtimeVideo Source.h"40 #include "RealtimeVideoCaptureSource.h" 41 41 #include <wtf/RunLoop.h> 42 42 … … 46 46 class GraphicsContext; 47 47 48 class MockRealtimeVideoSource : public RealtimeVideo Source {48 class MockRealtimeVideoSource : public RealtimeVideoCaptureSource { 49 49 public: 50 50
Note:
See TracChangeset
for help on using the changeset viewer.