Diff
Modified: trunk/Source/WebCore/CMakeLists.txt (223405 => 223406)
--- trunk/Source/WebCore/CMakeLists.txt 2017-10-16 13:40:52 UTC (rev 223405)
+++ trunk/Source/WebCore/CMakeLists.txt 2017-10-16 14:44:52 UTC (rev 223406)
@@ -2539,9 +2539,11 @@
platform/mediastream/RealtimeMediaSourceSupportedConstraints.cpp
platform/mediastream/RTCIceCandidateDescriptor.cpp
platform/mediastream/RTCSessionDescriptionDescriptor.cpp
+ platform/mediastream/RealtimeIncomingVideoSource.cpp
platform/mediastream/RealtimeMediaSource.cpp
platform/mediastream/RealtimeMediaSourceCenter.cpp
platform/mediastream/RealtimeMediaSourceSettings.cpp
+ platform/mediastream/RealtimeOutgoingVideoSource.cpp
platform/mediastream/libwebrtc/LibWebRTCProvider.cpp
Modified: trunk/Source/WebCore/ChangeLog (223405 => 223406)
--- trunk/Source/WebCore/ChangeLog 2017-10-16 13:40:52 UTC (rev 223405)
+++ trunk/Source/WebCore/ChangeLog 2017-10-16 14:44:52 UTC (rev 223406)
@@ -1,3 +1,29 @@
+2017-10-16 Alejandro G. Castro <[email protected]>
+
+ Make RealtimeIncomingVideoSources and RealtimeOutgoingVideoSources port agnostic
+ https://bugs.webkit.org/show_bug.cgi?id=177869
+
+ Reviewed by Youenn Fablet.
+
+ Refactor the RealtimeIncomingVideoSource and RealtimeOutgoingVideoSource classes,
+ move the cocoa specific code to a different class. This way we can use them from
+ other ports.
+
+ No new functionality, just a refactor.
+
+ * CMakeLists.txt:
+ * WebCore.xcodeproj/project.pbxproj:
+ * platform/mediastream/RealtimeIncomingVideoSource.cpp: Moved from Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSource.h. Just the port agnostic parts.
+ * platform/mediastream/RealtimeIncomingVideoSource.h: Moved from Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSource.h. DItto
+ * platform/mediastream/RealtimeOutgoingVideoSource.cpp: Moved from Source/WebCore/platform/mediastream/mac/RealtimeOutgoingVideoSource.cpp. Ditto
+ * platform/mediastream/RealtimeOutgoingVideoSource.h: Moved from Source/WebCore/platform/mediastream/mac/RealtimeOutgoingVideoSource.h. Ditto
+ * platform/mediastream/mac/RealtimeIncomingVideoSourceMac.cpp: Added, it adds the Cocoa specific parts from Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSource.cpp.
+ (WebCore::RealtimeIncomingVideoSource::create): Moved this function from the base class, it allows avoiding the include.
+ * platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.h: Added, cocoa dependent code from Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSource.h.
+ (WebCore::RealtimeOutgoingVideoSource::create): Moved this funtion from the base class, now we can use the Cocoa create without including it in the base class.
+ * platform/mediastream/mac/RealtimeOutgoingVideoSourceCocoa.cpp: Added, cocoa dependent code.
+ * platform/mediastream/mac/RealtimeOutgoingVideoSourceCocoa.h: Added, cocoa dependent code.
+
2017-10-16 Manuel Rego Casasnovas <[email protected]>
Don't use intrinsic width if our container's width is zero
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (223405 => 223406)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2017-10-16 13:40:52 UTC (rev 223405)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2017-10-16 14:44:52 UTC (rev 223406)
@@ -2742,7 +2742,9 @@
5CD9F5671AA0F74200DA45FF /* DFABytecodeCompiler.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C39305F1AA0F6A90029C816 /* DFABytecodeCompiler.h */; settings = {ATTRIBUTES = (Private, ); }; };
5CD9F5681AA0F74600DA45FF /* DFABytecodeInterpreter.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C3930611AA0F6A90029C816 /* DFABytecodeInterpreter.h */; settings = {ATTRIBUTES = (Private, ); }; };
5CDD833D1E4324D900621E92 /* RealtimeOutgoingVideoSource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5CDD833B1E4324BB00621E92 /* RealtimeOutgoingVideoSource.cpp */; };
+ 5CDD833D1E4324D900621B83 /* RealtimeOutgoingVideoSourceCocoa.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5CDD833B1E4324BB00621B83 /* RealtimeOutgoingVideoSourceCocoa.cpp */; };
5CDD833E1E4324DC00621E92 /* RealtimeIncomingVideoSource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5CDD83391E4324BB00621E92 /* RealtimeIncomingVideoSource.cpp */; };
+ 5CDD833E1E4324DC00621E83 /* RealtimeIncomingVideoSourceCocoa.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5CDD83391E4324BB00621E83 /* RealtimeIncomingVideoSourceCocoa.cpp */; };
5CDD83641E4325A000621E92 /* LibWebRTCDataChannelHandler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5CDD833F1E43253D00621E92 /* LibWebRTCDataChannelHandler.cpp */; };
5CDFA6C81AA4F2DA00EA8746 /* ContentExtensionActions.h in Headers */ = {isa = PBXBuildFile; fileRef = 5CDFA6C71AA4F2DA00EA8746 /* ContentExtensionActions.h */; settings = {ATTRIBUTES = (Private, ); }; };
5CE5D9AB1DB89A0300CE7A8D /* JSTextDecoder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5CE5D9A71DB899FC00CE7A8D /* JSTextDecoder.cpp */; };
@@ -10691,8 +10693,12 @@
5CBC8DAB1AAA302200E1C803 /* MediaAccessibilitySoftLink.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaAccessibilitySoftLink.h; sourceTree = "<group>"; };
5CDD83391E4324BB00621E92 /* RealtimeIncomingVideoSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RealtimeIncomingVideoSource.cpp; sourceTree = "<group>"; };
5CDD833A1E4324BB00621E92 /* RealtimeIncomingVideoSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RealtimeIncomingVideoSource.h; sourceTree = "<group>"; };
+ 5CDD83391E4324BB00621E83 /* RealtimeIncomingVideoSourceCocoa.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RealtimeIncomingVideoSourceCocoa.cpp; sourceTree = "<group>"; };
+ 5CDD833A1E4324BB00621E83 /* RealtimeIncomingVideoSourceCocoa.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RealtimeIncomingVideoSourceCocoa.h; sourceTree = "<group>"; };
5CDD833B1E4324BB00621E92 /* RealtimeOutgoingVideoSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RealtimeOutgoingVideoSource.cpp; sourceTree = "<group>"; };
5CDD833C1E4324BB00621E92 /* RealtimeOutgoingVideoSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RealtimeOutgoingVideoSource.h; sourceTree = "<group>"; };
+ 5CDD833B1E4324BB00621B83 /* RealtimeOutgoingVideoSourceCocoa.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RealtimeOutgoingVideoSourceCocoa.cpp; sourceTree = "<group>"; };
+ 5CDD833C1E4324BB00621B83 /* RealtimeOutgoingVideoSourceCocoa.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RealtimeOutgoingVideoSourceCocoa.h; sourceTree = "<group>"; };
5CDD833F1E43253D00621E92 /* LibWebRTCDataChannelHandler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = LibWebRTCDataChannelHandler.cpp; path = libwebrtc/LibWebRTCDataChannelHandler.cpp; sourceTree = "<group>"; };
5CDD83401E43253D00621E92 /* LibWebRTCDataChannelHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LibWebRTCDataChannelHandler.h; path = libwebrtc/LibWebRTCDataChannelHandler.h; sourceTree = "<group>"; };
5CDFA6C71AA4F2DA00EA8746 /* ContentExtensionActions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContentExtensionActions.h; sourceTree = "<group>"; };
@@ -16550,6 +16556,8 @@
07FFDE66181AED420072D409 /* MediaStreamTrackPrivate.cpp */,
07FFDE67181AED420072D409 /* MediaStreamTrackPrivate.h */,
5EBB89381C77BDA400C65D41 /* PeerMediaDescription.h */,
+ 5CDD83391E4324BB00621E92 /* RealtimeIncomingVideoSource.cpp */,
+ 5CDD833A1E4324BB00621E92 /* RealtimeIncomingVideoSource.h */,
4A4F656B1AA997F100E38CDD /* RealtimeMediaSource.cpp */,
4A4F656C1AA997F100E38CDD /* RealtimeMediaSource.h */,
4A4F656D1AA997F100E38CDD /* RealtimeMediaSourceCapabilities.h */,
@@ -16559,6 +16567,8 @@
4A4F656F1AA997F100E38CDD /* RealtimeMediaSourceSettings.h */,
2EC41DE21C0410A300D294FE /* RealtimeMediaSourceSupportedConstraints.cpp */,
07C1C0E41BFB60ED00BD2256 /* RealtimeMediaSourceSupportedConstraints.h */,
+ 5CDD833B1E4324BB00621E92 /* RealtimeOutgoingVideoSource.cpp */,
+ 5CDD833C1E4324BB00621E92 /* RealtimeOutgoingVideoSource.h */,
3135910C1E7DDCB600F30630 /* RTCBundlePolicy.h */,
07221BA217CF0AD400848E51 /* RTCDataChannelHandler.h */,
07221BA317CF0AD400848E51 /* RTCDataChannelHandlerClient.h */,
@@ -16609,14 +16619,14 @@
07EE76EE1BEA619800F89133 /* MockRealtimeVideoSourceMac.mm */,
41103AAA1E39790A00769F03 /* RealtimeIncomingAudioSource.cpp */,
41103AA91E39790A00769F03 /* RealtimeIncomingAudioSource.h */,
- 5CDD83391E4324BB00621E92 /* RealtimeIncomingVideoSource.cpp */,
- 5CDD833A1E4324BB00621E92 /* RealtimeIncomingVideoSource.h */,
+ 5CDD83391E4324BB00621E83 /* RealtimeIncomingVideoSourceCocoa.cpp */,
+ 5CDD833A1E4324BB00621E83 /* RealtimeIncomingVideoSourceCocoa.h */,
4A0FFAA31AAF5EF60062803B /* RealtimeMediaSourceCenterMac.cpp */,
4A0FFAA41AAF5EF60062803B /* RealtimeMediaSourceCenterMac.h */,
41103AA71E39790A00769F03 /* RealtimeOutgoingAudioSource.cpp */,
41103AA81E39790A00769F03 /* RealtimeOutgoingAudioSource.h */,
- 5CDD833B1E4324BB00621E92 /* RealtimeOutgoingVideoSource.cpp */,
- 5CDD833C1E4324BB00621E92 /* RealtimeOutgoingVideoSource.h */,
+ 5CDD833B1E4324BB00621B83 /* RealtimeOutgoingVideoSourceCocoa.cpp */,
+ 5CDD833C1E4324BB00621B83 /* RealtimeOutgoingVideoSourceCocoa.h */,
07D6373E1BB0B11300256CE9 /* WebAudioSourceProviderAVFObjC.h */,
07D6373F1BB0B11300256CE9 /* WebAudioSourceProviderAVFObjC.mm */,
);
@@ -33729,6 +33739,7 @@
FD31603B12B0267600C1A359 /* RealtimeAnalyser.cpp in Sources */,
41103AAE1E39791000769F03 /* RealtimeIncomingAudioSource.cpp in Sources */,
5CDD833E1E4324DC00621E92 /* RealtimeIncomingVideoSource.cpp in Sources */,
+ 5CDD833E1E4324DC00621E83 /* RealtimeIncomingVideoSourceCocoa.cpp in Sources */,
4A4F65701AA997F100E38CDD /* RealtimeMediaSource.cpp in Sources */,
4A0FFAA11AAF5EA20062803B /* RealtimeMediaSourceCenter.cpp in Sources */,
4A0FFAA51AAF5EF60062803B /* RealtimeMediaSourceCenterMac.cpp in Sources */,
@@ -33736,6 +33747,7 @@
2EC41DE41C0410A300D294FE /* RealtimeMediaSourceSupportedConstraints.cpp in Sources */,
41103AAB1E39791000769F03 /* RealtimeOutgoingAudioSource.cpp in Sources */,
5CDD833D1E4324D900621E92 /* RealtimeOutgoingVideoSource.cpp in Sources */,
+ 5CDD833D1E4324D900621B83 /* RealtimeOutgoingVideoSourceCocoa.cpp in Sources */,
FD45A95A175D417100C21EC8 /* RectangleShape.cpp in Sources */,
BCAB418113E356E800D8AAF3 /* Region.cpp in Sources */,
A578F4401DE0B634003DFC6A /* RejectedPromiseTracker.cpp in Sources */,
Added: trunk/Source/WebCore/platform/mediastream/RealtimeIncomingVideoSource.cpp (0 => 223406)
--- trunk/Source/WebCore/platform/mediastream/RealtimeIncomingVideoSource.cpp (rev 0)
+++ trunk/Source/WebCore/platform/mediastream/RealtimeIncomingVideoSource.cpp 2017-10-16 14:44:52 UTC (rev 223406)
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name of Google Inc. nor the names of its contributors
+ * may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "RealtimeIncomingVideoSource.h"
+
+#if USE(LIBWEBRTC)
+
+#include "Logging.h"
+
+namespace WebCore {
+
+RealtimeIncomingVideoSource::RealtimeIncomingVideoSource(rtc::scoped_refptr<webrtc::VideoTrackInterface>&& videoTrack, String&& videoTrackId)
+ : RealtimeMediaSource(WTFMove(videoTrackId), RealtimeMediaSource::Type::Video, String())
+ , m_videoTrack(WTFMove(videoTrack))
+{
+ m_currentSettings.setWidth(640);
+ m_currentSettings.setHeight(480);
+ notifyMutedChange(!m_videoTrack);
+}
+
+void RealtimeIncomingVideoSource::startProducingData()
+{
+ if (m_videoTrack)
+ m_videoTrack->AddOrUpdateSink(this, rtc::VideoSinkWants());
+}
+
+void RealtimeIncomingVideoSource::setSourceTrack(rtc::scoped_refptr<webrtc::VideoTrackInterface>&& track)
+{
+ ASSERT(!m_videoTrack);
+ ASSERT(track);
+
+ m_videoTrack = WTFMove(track);
+ notifyMutedChange(!m_videoTrack);
+ if (isProducingData())
+ m_videoTrack->AddOrUpdateSink(this, rtc::VideoSinkWants());
+}
+
+void RealtimeIncomingVideoSource::stopProducingData()
+{
+ if (m_videoTrack)
+ m_videoTrack->RemoveSink(this);
+}
+
+const RealtimeMediaSourceCapabilities& RealtimeIncomingVideoSource::capabilities() const
+{
+ return RealtimeMediaSourceCapabilities::emptyCapabilities();
+}
+
+const RealtimeMediaSourceSettings& RealtimeIncomingVideoSource::settings() const
+{
+ return m_currentSettings;
+}
+
+} // namespace WebCore
+
+#endif // USE(LIBWEBRTC)
Copied: trunk/Source/WebCore/platform/mediastream/RealtimeIncomingVideoSource.h (from rev 223389, trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSource.h) (0 => 223406)
--- trunk/Source/WebCore/platform/mediastream/RealtimeIncomingVideoSource.h (rev 0)
+++ trunk/Source/WebCore/platform/mediastream/RealtimeIncomingVideoSource.h 2017-10-16 14:44:52 UTC (rev 223406)
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name of Ericsson nor the names of its contributors
+ * may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if USE(LIBWEBRTC)
+
+#include "LibWebRTCMacros.h"
+#include "RealtimeMediaSource.h"
+#include <webrtc/api/mediastreaminterface.h>
+#include <wtf/RetainPtr.h>
+
+namespace WebCore {
+
+class CaptureDevice;
+
+class RealtimeIncomingVideoSource : public RealtimeMediaSource, private rtc::VideoSinkInterface<webrtc::VideoFrame> {
+public:
+ static Ref<RealtimeIncomingVideoSource> create(rtc::scoped_refptr<webrtc::VideoTrackInterface>&&, String&&);
+ ~RealtimeIncomingVideoSource() { stopProducingData(); }
+
+ void setSourceTrack(rtc::scoped_refptr<webrtc::VideoTrackInterface>&&);
+
+protected:
+ RealtimeIncomingVideoSource(rtc::scoped_refptr<webrtc::VideoTrackInterface>&&, String&&);
+
+ RealtimeMediaSourceSettings m_currentSettings;
+
+private:
+ // RealtimeMediaSource API
+ void startProducingData() final;
+ void stopProducingData() final;
+
+ const RealtimeMediaSourceCapabilities& capabilities() const final;
+ const RealtimeMediaSourceSettings& settings() const final;
+
+ bool applySize(const IntSize&) final { return true; }
+
+ rtc::scoped_refptr<webrtc::VideoTrackInterface> m_videoTrack;
+};
+
+} // namespace WebCore
+
+#endif // USE(LIBWEBRTC)
Copied: trunk/Source/WebCore/platform/mediastream/RealtimeOutgoingVideoSource.cpp (from rev 223389, trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingVideoSource.cpp) (0 => 223406)
--- trunk/Source/WebCore/platform/mediastream/RealtimeOutgoingVideoSource.cpp (rev 0)
+++ trunk/Source/WebCore/platform/mediastream/RealtimeOutgoingVideoSource.cpp 2017-10-16 14:44:52 UTC (rev 223406)
@@ -0,0 +1,188 @@
+/*
+ * Copyright (C) 2017 Apple Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted, provided that the following conditions
+ * are required to be met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Inc. nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. AND ITS CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "RealtimeOutgoingVideoSource.h"
+
+#if USE(LIBWEBRTC)
+
+#include "Logging.h"
+#include <webrtc/api/video/i420_buffer.h>
+#include <webrtc/common_video/libyuv/include/webrtc_libyuv.h>
+#include <wtf/CurrentTime.h>
+#include <wtf/MainThread.h>
+
+namespace WebCore {
+
+RealtimeOutgoingVideoSource::RealtimeOutgoingVideoSource(Ref<MediaStreamTrackPrivate>&& videoSource)
+ : m_videoSource(WTFMove(videoSource))
+ , m_blackFrameTimer(*this, &RealtimeOutgoingVideoSource::sendOneBlackFrame)
+{
+ m_videoSource->addObserver(*this);
+ initializeFromSource();
+}
+
+bool RealtimeOutgoingVideoSource::setSource(Ref<MediaStreamTrackPrivate>&& newSource)
+{
+ if (!m_initialSettings)
+ m_initialSettings = m_videoSource->source().settings();
+
+ m_videoSource->removeObserver(*this);
+ m_videoSource = WTFMove(newSource);
+ m_videoSource->addObserver(*this);
+
+ initializeFromSource();
+
+ return true;
+}
+
+void RealtimeOutgoingVideoSource::stop()
+{
+ m_videoSource->removeObserver(*this);
+ m_blackFrameTimer.stop();
+ m_isStopped = true;
+}
+
+void RealtimeOutgoingVideoSource::updateBlackFramesSending()
+{
+ if (!m_muted && m_enabled) {
+ if (m_blackFrameTimer.isActive())
+ m_blackFrameTimer.stop();
+ return;
+ }
+
+ sendBlackFramesIfNeeded();
+}
+
+void RealtimeOutgoingVideoSource::sourceMutedChanged()
+{
+ ASSERT(m_muted != m_videoSource->muted());
+
+ m_muted = m_videoSource->muted();
+
+ updateBlackFramesSending();
+}
+
+void RealtimeOutgoingVideoSource::sourceEnabledChanged()
+{
+ ASSERT(m_enabled != m_videoSource->enabled());
+
+ m_enabled = m_videoSource->enabled();
+
+ updateBlackFramesSending();
+}
+
+void RealtimeOutgoingVideoSource::initializeFromSource()
+{
+ const auto& settings = m_videoSource->source().settings();
+ m_width = settings.width();
+ m_height = settings.height();
+
+ m_muted = m_videoSource->muted();
+ m_enabled = m_videoSource->enabled();
+
+ updateBlackFramesSending();
+}
+
+void RealtimeOutgoingVideoSource::AddOrUpdateSink(rtc::VideoSinkInterface<webrtc::VideoFrame>* sink, const rtc::VideoSinkWants& sinkWants)
+{
+ ASSERT(!sinkWants.black_frames);
+
+ if (sinkWants.rotation_applied)
+ m_shouldApplyRotation = true;
+
+ if (!m_sinks.contains(sink))
+ m_sinks.append(sink);
+
+ callOnMainThread([protectedThis = makeRef(*this)]() {
+ protectedThis->sendBlackFramesIfNeeded();
+ });
+}
+
+void RealtimeOutgoingVideoSource::RemoveSink(rtc::VideoSinkInterface<webrtc::VideoFrame>* sink)
+{
+ m_sinks.removeFirst(sink);
+
+ if (m_sinks.size())
+ return;
+
+ callOnMainThread([protectedThis = makeRef(*this)]() {
+ if (protectedThis->m_blackFrameTimer.isActive())
+ protectedThis->m_blackFrameTimer.stop();
+ });
+}
+
+void RealtimeOutgoingVideoSource::sendBlackFramesIfNeeded()
+{
+ if (m_blackFrameTimer.isActive())
+ return;
+
+ if (!m_sinks.size())
+ return;
+
+ if (!m_muted && m_enabled)
+ return;
+
+ if (!m_width || !m_height)
+ return;
+
+ if (!m_blackFrame) {
+ auto width = m_width;
+ auto height = m_height;
+ if (m_shouldApplyRotation && (m_currentRotation == webrtc::kVideoRotation_0 || m_currentRotation == webrtc::kVideoRotation_90))
+ std::swap(width, height);
+ auto frame = m_bufferPool.CreateBuffer(width, height);
+ ASSERT(frame);
+ if (!frame) {
+ RELEASE_LOG(WebRTC, "RealtimeOutgoingVideoSource::sendBlackFramesIfNeeded unable to send black frames");
+ return;
+ }
+ webrtc::I420Buffer::SetBlack(frame.get());
+ m_blackFrame = WTFMove(frame);
+ }
+ sendOneBlackFrame();
+ m_blackFrameTimer.startRepeating(1_s);
+}
+
+void RealtimeOutgoingVideoSource::sendOneBlackFrame()
+{
+ RELEASE_LOG(MediaStream, "RealtimeOutgoingVideoSource::sendOneBlackFrame");
+ sendFrame(rtc::scoped_refptr<webrtc::VideoFrameBuffer>(m_blackFrame));
+}
+
+void RealtimeOutgoingVideoSource::sendFrame(rtc::scoped_refptr<webrtc::VideoFrameBuffer>&& buffer)
+{
+ int64_t timestampMicroSeconds = monotonicallyIncreasingTimeMS() * 1000;
+ webrtc::VideoFrame frame(buffer, m_shouldApplyRotation ? webrtc::kVideoRotation_0 : m_currentRotation, timestampMicroSeconds);
+ for (auto* sink : m_sinks)
+ sink->OnFrame(frame);
+}
+
+} // namespace WebCore
+
+#endif // USE(LIBWEBRTC)
Copied: trunk/Source/WebCore/platform/mediastream/RealtimeOutgoingVideoSource.h (from rev 223389, trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingVideoSource.h) (0 => 223406)
--- trunk/Source/WebCore/platform/mediastream/RealtimeOutgoingVideoSource.h (rev 0)
+++ trunk/Source/WebCore/platform/mediastream/RealtimeOutgoingVideoSource.h 2017-10-16 14:44:52 UTC (rev 223406)
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2017 Apple Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted, provided that the following conditions
+ * are required to be met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Inc. nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. AND ITS CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if USE(LIBWEBRTC)
+
+#include "LibWebRTCMacros.h"
+#include "MediaStreamTrackPrivate.h"
+#include <Timer.h>
+#include <webrtc/api/mediastreaminterface.h>
+#include <webrtc/base/optional.h>
+#include <webrtc/common_video/include/i420_buffer_pool.h>
+#include <webrtc/media/base/videosinkinterface.h>
+#include <wtf/Optional.h>
+#include <wtf/ThreadSafeRefCounted.h>
+
+namespace WebCore {
+
+class RealtimeOutgoingVideoSource : public ThreadSafeRefCounted<RealtimeOutgoingVideoSource>, public webrtc::VideoTrackSourceInterface, private MediaStreamTrackPrivate::Observer {
+public:
+ static Ref<RealtimeOutgoingVideoSource> create(Ref<MediaStreamTrackPrivate>&& videoSource);
+ ~RealtimeOutgoingVideoSource() { stop(); }
+
+ void stop();
+ bool setSource(Ref<MediaStreamTrackPrivate>&&);
+ MediaStreamTrackPrivate& source() const { return m_videoSource.get(); }
+
+ int AddRef() const final { ref(); return refCount(); }
+ int Release() const final { deref(); return refCount(); }
+
+ void setApplyRotation(bool shouldApplyRotation) { m_shouldApplyRotation = shouldApplyRotation; }
+
+protected:
+ explicit RealtimeOutgoingVideoSource(Ref<MediaStreamTrackPrivate>&&);
+
+ void sendFrame(rtc::scoped_refptr<webrtc::VideoFrameBuffer>&&);
+
+ Vector<rtc::VideoSinkInterface<webrtc::VideoFrame>*> m_sinks;
+ webrtc::I420BufferPool m_bufferPool;
+
+ bool m_enabled { true };
+ bool m_muted { false };
+ uint32_t m_width { 0 };
+ uint32_t m_height { 0 };
+ bool m_shouldApplyRotation { false };
+ webrtc::VideoRotation m_currentRotation { webrtc::kVideoRotation_0 };
+
+private:
+ void sendBlackFramesIfNeeded();
+ void sendOneBlackFrame();
+ void initializeFromSource();
+ void updateBlackFramesSending();
+
+ // Notifier API
+ void RegisterObserver(webrtc::ObserverInterface*) final { }
+ void UnregisterObserver(webrtc::ObserverInterface*) final { }
+
+ // VideoTrackSourceInterface API
+ bool is_screencast() const final { return false; }
+ rtc::Optional<bool> needs_denoising() const final { return rtc::Optional<bool>(); }
+ bool GetStats(Stats*) final { return false; };
+
+ // MediaSourceInterface API
+ SourceState state() const final { return SourceState(); }
+ bool remote() const final { return true; }
+
+ // rtc::VideoSourceInterface<webrtc::VideoFrame> API
+ void AddOrUpdateSink(rtc::VideoSinkInterface<webrtc::VideoFrame>*, const rtc::VideoSinkWants&) final;
+ void RemoveSink(rtc::VideoSinkInterface<webrtc::VideoFrame>*) final;
+
+ void sourceMutedChanged();
+ void sourceEnabledChanged();
+
+ // MediaStreamTrackPrivate::Observer API
+ void trackMutedChanged(MediaStreamTrackPrivate&) final { sourceMutedChanged(); }
+ void trackEnabledChanged(MediaStreamTrackPrivate&) final { sourceEnabledChanged(); }
+ void trackSettingsChanged(MediaStreamTrackPrivate&) final { initializeFromSource(); }
+ void sampleBufferUpdated(MediaStreamTrackPrivate&, MediaSample&) override { }
+ void trackEnded(MediaStreamTrackPrivate&) final { }
+
+ Ref<MediaStreamTrackPrivate> m_videoSource;
+ std::optional<RealtimeMediaSourceSettings> m_initialSettings;
+ bool m_isStopped { false };
+ Timer m_blackFrameTimer;
+ rtc::scoped_refptr<webrtc::VideoFrameBuffer> m_blackFrame;
+};
+
+} // namespace WebCore
+
+#endif // USE(LIBWEBRTC)
Deleted: trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSource.cpp (223405 => 223406)
--- trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSource.cpp 2017-10-16 13:40:52 UTC (rev 223405)
+++ trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSource.cpp 2017-10-16 14:44:52 UTC (rev 223406)
@@ -1,206 +0,0 @@
-/*
- * Copyright (C) 2017 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Google Inc. nor the names of its contributors
- * may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "RealtimeIncomingVideoSource.h"
-
-#if USE(LIBWEBRTC)
-
-#include "Logging.h"
-#include "MediaSampleAVFObjC.h"
-#include <webrtc/sdk/objc/Framework/Classes/Video/corevideo_frame_buffer.h>
-
-#include "CoreMediaSoftLink.h"
-#include "CoreVideoSoftLink.h"
-
-namespace WebCore {
-
-Ref<RealtimeIncomingVideoSource> RealtimeIncomingVideoSource::create(rtc::scoped_refptr<webrtc::VideoTrackInterface>&& videoTrack, String&& trackId)
-{
- auto source = adoptRef(*new RealtimeIncomingVideoSource(WTFMove(videoTrack), WTFMove(trackId)));
- source->start();
- return source;
-}
-
-RealtimeIncomingVideoSource::RealtimeIncomingVideoSource(rtc::scoped_refptr<webrtc::VideoTrackInterface>&& videoTrack, String&& videoTrackId)
- : RealtimeMediaSource(WTFMove(videoTrackId), RealtimeMediaSource::Type::Video, String())
- , m_videoTrack(WTFMove(videoTrack))
-{
- m_currentSettings.setWidth(640);
- m_currentSettings.setHeight(480);
- notifyMutedChange(!m_videoTrack);
-}
-
-void RealtimeIncomingVideoSource::startProducingData()
-{
- if (m_videoTrack)
- m_videoTrack->AddOrUpdateSink(this, rtc::VideoSinkWants());
-}
-
-void RealtimeIncomingVideoSource::setSourceTrack(rtc::scoped_refptr<webrtc::VideoTrackInterface>&& track)
-{
- ASSERT(!m_videoTrack);
- ASSERT(track);
-
- m_videoTrack = WTFMove(track);
- notifyMutedChange(!m_videoTrack);
- if (isProducingData())
- m_videoTrack->AddOrUpdateSink(this, rtc::VideoSinkWants());
-}
-
-void RealtimeIncomingVideoSource::stopProducingData()
-{
- if (m_videoTrack)
- m_videoTrack->RemoveSink(this);
-}
-
-CVPixelBufferRef RealtimeIncomingVideoSource::pixelBufferFromVideoFrame(const webrtc::VideoFrame& frame)
-{
- if (muted()) {
- if (!m_blackFrame || m_blackFrameWidth != frame.width() || m_blackFrameHeight != frame.height()) {
- CVPixelBufferRef pixelBuffer = nullptr;
- auto status = CVPixelBufferCreate(kCFAllocatorDefault, frame.width(), frame.height(), kCVPixelFormatType_420YpCbCr8Planar, nullptr, &pixelBuffer);
- ASSERT_UNUSED(status, status == noErr);
-
- m_blackFrame = pixelBuffer;
- m_blackFrameWidth = frame.width();
- m_blackFrameHeight = frame.height();
-
- status = CVPixelBufferLockBaseAddress(pixelBuffer, 0);
- ASSERT(status == noErr);
- void* data = ""
- size_t yLength = frame.width() * frame.height();
- memset(data, 0, yLength);
- memset(static_cast<uint8_t*>(data) + yLength, 128, yLength / 2);
-
- status = CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
- ASSERT(!status);
- }
- return m_blackFrame.get();
- }
- auto buffer = frame.video_frame_buffer();
- ASSERT(buffer->type() == webrtc::VideoFrameBuffer::Type::kNative);
- return static_cast<webrtc::CoreVideoFrameBuffer&>(*buffer).pixel_buffer();
-}
-
-void RealtimeIncomingVideoSource::OnFrame(const webrtc::VideoFrame& frame)
-{
- if (!isProducingData())
- return;
-
-#if !RELEASE_LOG_DISABLED
- if (!(++m_numberOfFrames % 30))
- RELEASE_LOG(MediaStream, "RealtimeIncomingVideoSource::OnFrame %zu frame", m_numberOfFrames);
-#endif
-
- auto pixelBuffer = pixelBufferFromVideoFrame(frame);
-
- // FIXME: Convert timing information from VideoFrame to CMSampleTimingInfo.
- // For the moment, we will pretend that frames should be rendered asap.
- CMSampleTimingInfo timingInfo;
- timingInfo.presentationTimeStamp = kCMTimeInvalid;
- timingInfo.decodeTimeStamp = kCMTimeInvalid;
- timingInfo.duration = kCMTimeInvalid;
-
- CMVideoFormatDescriptionRef formatDescription;
- OSStatus ostatus = CMVideoFormatDescriptionCreateForImageBuffer(kCFAllocatorDefault, (CVImageBufferRef)pixelBuffer, &formatDescription);
- if (ostatus != noErr) {
- LOG_ERROR("Failed to initialize CMVideoFormatDescription: %d", static_cast<int>(ostatus));
- return;
- }
-
- CMSampleBufferRef sampleBuffer;
- ostatus = CMSampleBufferCreateReadyWithImageBuffer(kCFAllocatorDefault, (CVImageBufferRef)pixelBuffer, formatDescription, &timingInfo, &sampleBuffer);
- if (ostatus != noErr) {
- LOG_ERROR("Failed to create the sample buffer: %d", static_cast<int>(ostatus));
- return;
- }
- CFRelease(formatDescription);
-
- auto sample = adoptCF(sampleBuffer);
-
- CFArrayRef attachmentsArray = CMSampleBufferGetSampleAttachmentsArray(sampleBuffer, true);
- for (CFIndex i = 0; i < CFArrayGetCount(attachmentsArray); ++i) {
- CFMutableDictionaryRef attachments = (CFMutableDictionaryRef)CFArrayGetValueAtIndex(attachmentsArray, i);
- CFDictionarySetValue(attachments, kCMSampleAttachmentKey_DisplayImmediately, kCFBooleanTrue);
- }
-
- unsigned width = frame.width();
- unsigned height = frame.height();
-
- MediaSample::VideoRotation rotation;
- switch (frame.rotation()) {
- case webrtc::kVideoRotation_0:
- rotation = MediaSample::VideoRotation::None;
- break;
- case webrtc::kVideoRotation_180:
- rotation = MediaSample::VideoRotation::UpsideDown;
- break;
- case webrtc::kVideoRotation_90:
- rotation = MediaSample::VideoRotation::Right;
- std::swap(width, height);
- break;
- case webrtc::kVideoRotation_270:
- rotation = MediaSample::VideoRotation::Left;
- std::swap(width, height);
- break;
- }
-
- RefPtr<RealtimeIncomingVideoSource> protectedThis(this);
- callOnMainThread([protectedThis = WTFMove(protectedThis), sample = WTFMove(sample), width, height, rotation] {
- protectedThis->processNewSample(sample.get(), width, height, rotation);
- });
-}
-
-void RealtimeIncomingVideoSource::processNewSample(CMSampleBufferRef sample, unsigned width, unsigned height, MediaSample::VideoRotation rotation)
-{
- m_buffer = sample;
- if (width != m_currentSettings.width() || height != m_currentSettings.height()) {
- m_currentSettings.setWidth(width);
- m_currentSettings.setHeight(height);
- settingsDidChange();
- }
-
- videoSampleAvailable(MediaSampleAVFObjC::create(sample, rotation));
-}
-
-const RealtimeMediaSourceCapabilities& RealtimeIncomingVideoSource::capabilities() const
-{
- return RealtimeMediaSourceCapabilities::emptyCapabilities();
-}
-
-const RealtimeMediaSourceSettings& RealtimeIncomingVideoSource::settings() const
-{
- return m_currentSettings;
-}
-
-} // namespace WebCore
-
-#endif // USE(LIBWEBRTC)
Deleted: trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSource.h (223405 => 223406)
--- trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSource.h 2017-10-16 13:40:52 UTC (rev 223405)
+++ trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSource.h 2017-10-16 14:44:52 UTC (rev 223406)
@@ -1,86 +0,0 @@
-/*
- * Copyright (C) 2017 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Ericsson nor the names of its contributors
- * may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#pragma once
-
-#if USE(LIBWEBRTC)
-
-#include "LibWebRTCMacros.h"
-#include "RealtimeMediaSource.h"
-#include <webrtc/api/mediastreaminterface.h>
-#include <wtf/RetainPtr.h>
-
-using CMSampleBufferRef = struct opaqueCMSampleBuffer*;
-using CVPixelBufferRef = struct __CVBuffer*;
-
-namespace WebCore {
-
-class CaptureDevice;
-
-class RealtimeIncomingVideoSource final : public RealtimeMediaSource, private rtc::VideoSinkInterface<webrtc::VideoFrame> {
-public:
- static Ref<RealtimeIncomingVideoSource> create(rtc::scoped_refptr<webrtc::VideoTrackInterface>&&, String&&);
- ~RealtimeIncomingVideoSource() { stopProducingData(); }
-
- void setSourceTrack(rtc::scoped_refptr<webrtc::VideoTrackInterface>&&);
-
-private:
- RealtimeIncomingVideoSource(rtc::scoped_refptr<webrtc::VideoTrackInterface>&&, String&&);
-
- // RealtimeMediaSource API
- void startProducingData() final;
- void stopProducingData() final;
-
- const RealtimeMediaSourceCapabilities& capabilities() const final;
- const RealtimeMediaSourceSettings& settings() const final;
-
- void processNewSample(CMSampleBufferRef, unsigned, unsigned, MediaSample::VideoRotation);
-
- bool applySize(const IntSize&) final { return true; }
-
- // rtc::VideoSinkInterface
- void OnFrame(const webrtc::VideoFrame&) final;
-
- CVPixelBufferRef pixelBufferFromVideoFrame(const webrtc::VideoFrame&);
-
- RealtimeMediaSourceSettings m_currentSettings;
- rtc::scoped_refptr<webrtc::VideoTrackInterface> m_videoTrack;
- RetainPtr<CMSampleBufferRef> m_buffer;
- RetainPtr<CVPixelBufferRef> m_blackFrame;
- int m_blackFrameWidth { 0 };
- int m_blackFrameHeight { 0 };
-#if !RELEASE_LOG_DISABLED
- size_t m_numberOfFrames { 0 };
-#endif
-};
-
-} // namespace WebCore
-
-#endif // USE(LIBWEBRTC)
Copied: trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.cpp (from rev 223389, trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSource.cpp) (0 => 223406)
--- trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.cpp (rev 0)
+++ trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.cpp 2017-10-16 14:44:52 UTC (rev 223406)
@@ -0,0 +1,171 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "RealtimeIncomingVideoSourceCocoa.h"
+
+#if USE(LIBWEBRTC)
+
+#include "Logging.h"
+#include "MediaSampleAVFObjC.h"
+#include <webrtc/sdk/objc/Framework/Classes/Video/corevideo_frame_buffer.h>
+
+#include "CoreMediaSoftLink.h"
+#include "CoreVideoSoftLink.h"
+
+namespace WebCore {
+
+Ref<RealtimeIncomingVideoSource> RealtimeIncomingVideoSource::create(rtc::scoped_refptr<webrtc::VideoTrackInterface>&& videoTrack, String&& trackId)
+{
+ auto source = RealtimeIncomingVideoSourceCocoa::create(WTFMove(videoTrack), WTFMove(trackId));
+ source->start();
+ return WTFMove(source);
+}
+
+Ref<RealtimeIncomingVideoSourceCocoa> RealtimeIncomingVideoSourceCocoa::create(rtc::scoped_refptr<webrtc::VideoTrackInterface>&& videoTrack, String&& trackId)
+{
+ return adoptRef(*new RealtimeIncomingVideoSourceCocoa(WTFMove(videoTrack), WTFMove(trackId)));
+}
+
+RealtimeIncomingVideoSourceCocoa::RealtimeIncomingVideoSourceCocoa(rtc::scoped_refptr<webrtc::VideoTrackInterface>&& videoTrack, String&& videoTrackId)
+ : RealtimeIncomingVideoSource(WTFMove(videoTrack), WTFMove(videoTrackId))
+{
+}
+
+CVPixelBufferRef RealtimeIncomingVideoSourceCocoa::pixelBufferFromVideoFrame(const webrtc::VideoFrame& frame)
+{
+ if (muted()) {
+ if (!m_blackFrame || m_blackFrameWidth != frame.width() || m_blackFrameHeight != frame.height()) {
+ CVPixelBufferRef pixelBuffer = nullptr;
+ auto status = CVPixelBufferCreate(kCFAllocatorDefault, frame.width(), frame.height(), kCVPixelFormatType_420YpCbCr8Planar, nullptr, &pixelBuffer);
+ ASSERT_UNUSED(status, status == noErr);
+
+ m_blackFrame = pixelBuffer;
+ m_blackFrameWidth = frame.width();
+ m_blackFrameHeight = frame.height();
+
+ status = CVPixelBufferLockBaseAddress(pixelBuffer, 0);
+ ASSERT(status == noErr);
+ void* data = ""
+ size_t yLength = frame.width() * frame.height();
+ memset(data, 0, yLength);
+ memset(static_cast<uint8_t*>(data) + yLength, 128, yLength / 2);
+
+ status = CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
+ ASSERT(!status);
+ }
+ return m_blackFrame.get();
+ }
+ auto buffer = frame.video_frame_buffer();
+ ASSERT(buffer->type() == webrtc::VideoFrameBuffer::Type::kNative);
+ return static_cast<webrtc::CoreVideoFrameBuffer&>(*buffer).pixel_buffer();
+}
+
+void RealtimeIncomingVideoSourceCocoa::OnFrame(const webrtc::VideoFrame& frame)
+{
+ if (!isProducingData())
+ return;
+
+#if !RELEASE_LOG_DISABLED
+ if (!(++m_numberOfFrames % 30))
+ RELEASE_LOG(MediaStream, "RealtimeIncomingVideoSourceCocoa::OnFrame %zu frame", m_numberOfFrames);
+#endif
+
+ auto pixelBuffer = pixelBufferFromVideoFrame(frame);
+
+ // FIXME: Convert timing information from VideoFrame to CMSampleTimingInfo.
+ // For the moment, we will pretend that frames should be rendered asap.
+ CMSampleTimingInfo timingInfo;
+ timingInfo.presentationTimeStamp = kCMTimeInvalid;
+ timingInfo.decodeTimeStamp = kCMTimeInvalid;
+ timingInfo.duration = kCMTimeInvalid;
+
+ CMVideoFormatDescriptionRef formatDescription;
+ OSStatus ostatus = CMVideoFormatDescriptionCreateForImageBuffer(kCFAllocatorDefault, (CVImageBufferRef)pixelBuffer, &formatDescription);
+ if (ostatus != noErr) {
+ LOG_ERROR("Failed to initialize CMVideoFormatDescription: %d", static_cast<int>(ostatus));
+ return;
+ }
+
+ CMSampleBufferRef sampleBuffer;
+ ostatus = CMSampleBufferCreateReadyWithImageBuffer(kCFAllocatorDefault, (CVImageBufferRef)pixelBuffer, formatDescription, &timingInfo, &sampleBuffer);
+ if (ostatus != noErr) {
+ LOG_ERROR("Failed to create the sample buffer: %d", static_cast<int>(ostatus));
+ return;
+ }
+ CFRelease(formatDescription);
+
+ auto sample = adoptCF(sampleBuffer);
+
+ CFArrayRef attachmentsArray = CMSampleBufferGetSampleAttachmentsArray(sampleBuffer, true);
+ for (CFIndex i = 0; i < CFArrayGetCount(attachmentsArray); ++i) {
+ CFMutableDictionaryRef attachments = (CFMutableDictionaryRef)CFArrayGetValueAtIndex(attachmentsArray, i);
+ CFDictionarySetValue(attachments, kCMSampleAttachmentKey_DisplayImmediately, kCFBooleanTrue);
+ }
+
+ unsigned width = frame.width();
+ unsigned height = frame.height();
+
+ MediaSample::VideoRotation rotation;
+ switch (frame.rotation()) {
+ case webrtc::kVideoRotation_0:
+ rotation = MediaSample::VideoRotation::None;
+ break;
+ case webrtc::kVideoRotation_180:
+ rotation = MediaSample::VideoRotation::UpsideDown;
+ break;
+ case webrtc::kVideoRotation_90:
+ rotation = MediaSample::VideoRotation::Right;
+ std::swap(width, height);
+ break;
+ case webrtc::kVideoRotation_270:
+ rotation = MediaSample::VideoRotation::Left;
+ std::swap(width, height);
+ break;
+ }
+
+ RefPtr<RealtimeIncomingVideoSourceCocoa> protectedThis(this);
+ callOnMainThread([protectedThis = makeRef(*this), sample = WTFMove(sample), width, height, rotation] {
+ protectedThis->processNewSample(sample.get(), width, height, rotation);
+ });
+}
+
+void RealtimeIncomingVideoSourceCocoa::processNewSample(CMSampleBufferRef sample, unsigned width, unsigned height, MediaSample::VideoRotation rotation)
+{
+ m_buffer = sample;
+ if (width != m_currentSettings.width() || height != m_currentSettings.height()) {
+ m_currentSettings.setWidth(width);
+ m_currentSettings.setHeight(height);
+ settingsDidChange();
+ }
+
+ videoSampleAvailable(MediaSampleAVFObjC::create(sample, rotation));
+}
+
+} // namespace WebCore
+
+#endif // USE(LIBWEBRTC)
Copied: trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.h (from rev 223389, trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSource.h) (0 => 223406)
--- trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.h (rev 0)
+++ trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.h 2017-10-16 14:44:52 UTC (rev 223406)
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if USE(LIBWEBRTC)
+
+#include "RealtimeIncomingVideoSource.h"
+
+using CMSampleBufferRef = struct opaqueCMSampleBuffer*;
+using CVPixelBufferRef = struct __CVBuffer*;
+
+namespace WebCore {
+
+class RealtimeIncomingVideoSourceCocoa final : public RealtimeIncomingVideoSource {
+public:
+ static Ref<RealtimeIncomingVideoSourceCocoa> create(rtc::scoped_refptr<webrtc::VideoTrackInterface>&&, String&&);
+
+private:
+ RealtimeIncomingVideoSourceCocoa(rtc::scoped_refptr<webrtc::VideoTrackInterface>&&, String&&);
+ void processNewSample(CMSampleBufferRef, unsigned, unsigned, MediaSample::VideoRotation);
+ CVPixelBufferRef pixelBufferFromVideoFrame(const webrtc::VideoFrame&);
+
+ // rtc::VideoSinkInterface
+ void OnFrame(const webrtc::VideoFrame&) final;
+
+ RetainPtr<CMSampleBufferRef> m_buffer;
+ RetainPtr<CVPixelBufferRef> m_blackFrame;
+ int m_blackFrameWidth { 0 };
+ int m_blackFrameHeight { 0 };
+#if !RELEASE_LOG_DISABLED
+ size_t m_numberOfFrames { 0 };
+#endif
+};
+
+} // namespace WebCore
+
+#endif // USE(LIBWEBRTC)
Deleted: trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingVideoSource.cpp (223405 => 223406)
--- trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingVideoSource.cpp 2017-10-16 13:40:52 UTC (rev 223405)
+++ trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingVideoSource.cpp 2017-10-16 14:44:52 UTC (rev 223406)
@@ -1,266 +0,0 @@
-/*
- * Copyright (C) 2017 Apple Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted, provided that the following conditions
- * are required to be met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Apple Inc. nor the names of
- * its contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS "AS IS" AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL APPLE INC. AND ITS CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "RealtimeOutgoingVideoSource.h"
-
-#if USE(LIBWEBRTC)
-
-#include "Logging.h"
-#include <webrtc/api/video/i420_buffer.h>
-#include <webrtc/common_video/libyuv/include/webrtc_libyuv.h>
-#include <webrtc/sdk/objc/Framework/Classes/Video/corevideo_frame_buffer.h>
-#include <wtf/CurrentTime.h>
-#include <wtf/MainThread.h>
-
-#include "CoreMediaSoftLink.h"
-#include "CoreVideoSoftLink.h"
-
-namespace WebCore {
-
-RealtimeOutgoingVideoSource::RealtimeOutgoingVideoSource(Ref<MediaStreamTrackPrivate>&& videoSource)
- : m_videoSource(WTFMove(videoSource))
- , m_blackFrameTimer(*this, &RealtimeOutgoingVideoSource::sendOneBlackFrame)
-{
- m_videoSource->addObserver(*this);
- initializeFromSource();
-}
-
-bool RealtimeOutgoingVideoSource::setSource(Ref<MediaStreamTrackPrivate>&& newSource)
-{
- if (!m_initialSettings)
- m_initialSettings = m_videoSource->source().settings();
-
- m_videoSource->removeObserver(*this);
- m_videoSource = WTFMove(newSource);
- m_videoSource->addObserver(*this);
-
- initializeFromSource();
-
- return true;
-}
-
-void RealtimeOutgoingVideoSource::stop()
-{
- m_videoSource->removeObserver(*this);
- m_blackFrameTimer.stop();
- m_isStopped = true;
-}
-
-void RealtimeOutgoingVideoSource::updateBlackFramesSending()
-{
- if (!m_muted && m_enabled) {
- if (m_blackFrameTimer.isActive())
- m_blackFrameTimer.stop();
- return;
- }
-
- sendBlackFramesIfNeeded();
-}
-
-void RealtimeOutgoingVideoSource::sourceMutedChanged()
-{
- ASSERT(m_muted != m_videoSource->muted());
-
- m_muted = m_videoSource->muted();
-
- updateBlackFramesSending();
-}
-
-void RealtimeOutgoingVideoSource::sourceEnabledChanged()
-{
- ASSERT(m_enabled != m_videoSource->enabled());
-
- m_enabled = m_videoSource->enabled();
-
- updateBlackFramesSending();
-}
-
-void RealtimeOutgoingVideoSource::initializeFromSource()
-{
- const auto& settings = m_videoSource->source().settings();
- m_width = settings.width();
- m_height = settings.height();
-
- m_muted = m_videoSource->muted();
- m_enabled = m_videoSource->enabled();
-
- updateBlackFramesSending();
-}
-
-bool RealtimeOutgoingVideoSource::GetStats(Stats*)
-{
- return false;
-}
-
-void RealtimeOutgoingVideoSource::AddOrUpdateSink(rtc::VideoSinkInterface<webrtc::VideoFrame>* sink, const rtc::VideoSinkWants& sinkWants)
-{
- ASSERT(!sinkWants.black_frames);
-
- if (sinkWants.rotation_applied)
- m_shouldApplyRotation = true;
-
- if (!m_sinks.contains(sink))
- m_sinks.append(sink);
-
- callOnMainThread([protectedThis = makeRef(*this)]() {
- protectedThis->sendBlackFramesIfNeeded();
- });
-}
-
-void RealtimeOutgoingVideoSource::RemoveSink(rtc::VideoSinkInterface<webrtc::VideoFrame>* sink)
-{
- m_sinks.removeFirst(sink);
-
- if (m_sinks.size())
- return;
-
- callOnMainThread([protectedThis = makeRef(*this)]() {
- if (protectedThis->m_blackFrameTimer.isActive())
- protectedThis->m_blackFrameTimer.stop();
- });
-}
-
-void RealtimeOutgoingVideoSource::sendBlackFramesIfNeeded()
-{
- if (m_blackFrameTimer.isActive())
- return;
-
- if (!m_sinks.size())
- return;
-
- if (!m_muted && m_enabled)
- return;
-
- if (!m_width || !m_height)
- return;
-
- if (!m_blackFrame) {
- auto width = m_width;
- auto height = m_height;
- if (m_shouldApplyRotation && (m_currentRotation == webrtc::kVideoRotation_0 || m_currentRotation == webrtc::kVideoRotation_90))
- std::swap(width, height);
- auto frame = m_bufferPool.CreateBuffer(width, height);
- ASSERT(frame);
- if (!frame) {
- RELEASE_LOG(WebRTC, "RealtimeOutgoingVideoSource::sendBlackFramesIfNeeded unable to send black frames");
- return;
- }
- webrtc::I420Buffer::SetBlack(frame.get());
- m_blackFrame = WTFMove(frame);
- }
- sendOneBlackFrame();
- m_blackFrameTimer.startRepeating(1_s);
-}
-
-void RealtimeOutgoingVideoSource::sendOneBlackFrame()
-{
- RELEASE_LOG(MediaStream, "RealtimeOutgoingVideoSource::sendOneBlackFrame");
- sendFrame(rtc::scoped_refptr<webrtc::VideoFrameBuffer>(m_blackFrame));
-}
-
-void RealtimeOutgoingVideoSource::sendFrame(rtc::scoped_refptr<webrtc::VideoFrameBuffer>&& buffer)
-{
- int64_t timestampMicroSeconds = monotonicallyIncreasingTimeMS() * 1000;
- webrtc::VideoFrame frame(buffer, m_shouldApplyRotation ? webrtc::kVideoRotation_0 : m_currentRotation, timestampMicroSeconds);
- for (auto* sink : m_sinks)
- sink->OnFrame(frame);
-}
-
-void RealtimeOutgoingVideoSource::videoSampleAvailable(MediaSample& sample)
-{
- if (!m_sinks.size())
- return;
-
- if (m_muted || !m_enabled)
- return;
-
-#if !RELEASE_LOG_DISABLED
- if (!(++m_numberOfFrames % 30))
- RELEASE_LOG(MediaStream, "RealtimeOutgoingVideoSource::sendFrame %zu frame", m_numberOfFrames);
-#endif
-
- switch (sample.videoRotation()) {
- case MediaSample::VideoRotation::None:
- m_currentRotation = webrtc::kVideoRotation_0;
- break;
- case MediaSample::VideoRotation::UpsideDown:
- m_currentRotation = webrtc::kVideoRotation_180;
- break;
- case MediaSample::VideoRotation::Right:
- m_currentRotation = webrtc::kVideoRotation_90;
- break;
- case MediaSample::VideoRotation::Left:
- m_currentRotation = webrtc::kVideoRotation_270;
- break;
- }
-
- ASSERT(sample.platformSample().type == PlatformSample::CMSampleBufferType);
- auto pixelBuffer = static_cast<CVPixelBufferRef>(CMSampleBufferGetImageBuffer(sample.platformSample().sample.cmSampleBuffer));
- auto pixelFormatType = CVPixelBufferGetPixelFormatType(pixelBuffer);
-
- if (pixelFormatType == kCVPixelFormatType_420YpCbCr8Planar || pixelFormatType == kCVPixelFormatType_420YpCbCr8BiPlanarFullRange) {
- rtc::scoped_refptr<webrtc::VideoFrameBuffer> buffer = new rtc::RefCountedObject<webrtc::CoreVideoFrameBuffer>(pixelBuffer);
- if (m_shouldApplyRotation && m_currentRotation != webrtc::kVideoRotation_0) {
- // FIXME: We should make AVVideoCaptureSource handle the rotation whenever possible.
- // This implementation is inefficient, we should rotate on the CMSampleBuffer directly instead of doing this double allocation.
- auto rotatedBuffer = buffer->ToI420();
- ASSERT(rotatedBuffer);
- buffer = webrtc::I420Buffer::Rotate(*rotatedBuffer, m_currentRotation);
- }
- sendFrame(WTFMove(buffer));
- return;
- }
-
- CVPixelBufferLockBaseAddress(pixelBuffer, 0);
- auto* source = reinterpret_cast<uint8_t*>(CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 0));
-
- ASSERT(m_width);
- ASSERT(m_height);
-
- auto newBuffer = m_bufferPool.CreateBuffer(m_width, m_height);
- ASSERT(newBuffer);
- if (!newBuffer) {
- RELEASE_LOG(WebRTC, "RealtimeOutgoingVideoSource::videoSampleAvailable unable to allocate buffer for conversion to YUV");
- return;
- }
- if (pixelFormatType == kCVPixelFormatType_32BGRA)
- webrtc::ConvertToI420(webrtc::VideoType::kARGB, source, 0, 0, m_width, m_height, 0, webrtc::kVideoRotation_0, newBuffer);
- else {
- ASSERT(pixelFormatType == kCVPixelFormatType_32ARGB);
- webrtc::ConvertToI420(webrtc::VideoType::kBGRA, source, 0, 0, m_width, m_height, 0, webrtc::kVideoRotation_0, newBuffer);
- }
- CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
- if (m_shouldApplyRotation && m_currentRotation != webrtc::kVideoRotation_0)
- newBuffer = webrtc::I420Buffer::Rotate(*newBuffer, m_currentRotation);
- sendFrame(WTFMove(newBuffer));
-}
-
-} // namespace WebCore
-
-#endif // USE(LIBWEBRTC)
Deleted: trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingVideoSource.h (223405 => 223406)
--- trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingVideoSource.h 2017-10-16 13:40:52 UTC (rev 223405)
+++ trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingVideoSource.h 2017-10-16 14:44:52 UTC (rev 223406)
@@ -1,116 +0,0 @@
-/*
- * Copyright (C) 2017 Apple Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted, provided that the following conditions
- * are required to be met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Apple Inc. nor the names of
- * its contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS "AS IS" AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL APPLE INC. AND ITS CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#pragma once
-
-#if USE(LIBWEBRTC)
-
-#include "LibWebRTCMacros.h"
-#include "MediaStreamTrackPrivate.h"
-#include <Timer.h>
-#include <webrtc/api/mediastreaminterface.h>
-#include <webrtc/base/optional.h>
-#include <webrtc/common_video/include/i420_buffer_pool.h>
-#include <webrtc/media/base/videosinkinterface.h>
-#include <wtf/Optional.h>
-#include <wtf/ThreadSafeRefCounted.h>
-
-namespace WebCore {
-
-class RealtimeOutgoingVideoSource final : public ThreadSafeRefCounted<RealtimeOutgoingVideoSource>, public webrtc::VideoTrackSourceInterface, private MediaStreamTrackPrivate::Observer {
-public:
- static Ref<RealtimeOutgoingVideoSource> create(Ref<MediaStreamTrackPrivate>&& videoSource) { return adoptRef(*new RealtimeOutgoingVideoSource(WTFMove(videoSource))); }
- ~RealtimeOutgoingVideoSource() { stop(); }
-
- void stop();
- bool setSource(Ref<MediaStreamTrackPrivate>&&);
- MediaStreamTrackPrivate& source() const { return m_videoSource.get(); }
-
- int AddRef() const final { ref(); return refCount(); }
- int Release() const final { deref(); return refCount(); }
-
- void setApplyRotation(bool shouldApplyRotation) { m_shouldApplyRotation = shouldApplyRotation; }
-
-private:
- RealtimeOutgoingVideoSource(Ref<MediaStreamTrackPrivate>&&);
-
- void sendFrame(rtc::scoped_refptr<webrtc::VideoFrameBuffer>&&);
- void sendBlackFramesIfNeeded();
- void sendOneBlackFrame();
- void initializeFromSource();
- void updateBlackFramesSending();
-
- // Notifier API
- void RegisterObserver(webrtc::ObserverInterface*) final { }
- void UnregisterObserver(webrtc::ObserverInterface*) final { }
-
- // VideoTrackSourceInterface API
- bool is_screencast() const final { return false; }
- rtc::Optional<bool> needs_denoising() const final { return rtc::Optional<bool>(); }
- bool GetStats(Stats*) final;
-
- // MediaSourceInterface API
- SourceState state() const final { return SourceState(); }
- bool remote() const final { return true; }
-
- // rtc::VideoSourceInterface<webrtc::VideoFrame> API
- void AddOrUpdateSink(rtc::VideoSinkInterface<webrtc::VideoFrame>*, const rtc::VideoSinkWants&) final;
- void RemoveSink(rtc::VideoSinkInterface<webrtc::VideoFrame>*) final;
-
- void sourceMutedChanged();
- void sourceEnabledChanged();
- void videoSampleAvailable(MediaSample&);
-
- // MediaStreamTrackPrivate::Observer API
- void trackMutedChanged(MediaStreamTrackPrivate&) final { sourceMutedChanged(); }
- void trackEnabledChanged(MediaStreamTrackPrivate&) final { sourceEnabledChanged(); }
- void trackSettingsChanged(MediaStreamTrackPrivate&) final { initializeFromSource(); }
- void sampleBufferUpdated(MediaStreamTrackPrivate&, MediaSample& sample) final { videoSampleAvailable(sample); }
- void trackEnded(MediaStreamTrackPrivate&) final { }
-
- Vector<rtc::VideoSinkInterface<webrtc::VideoFrame>*> m_sinks;
- webrtc::I420BufferPool m_bufferPool;
- Ref<MediaStreamTrackPrivate> m_videoSource;
- bool m_enabled { true };
- bool m_muted { false };
- std::optional<RealtimeMediaSourceSettings> m_initialSettings;
- webrtc::VideoRotation m_currentRotation { webrtc::kVideoRotation_0 };
- uint32_t m_width { 0 };
- uint32_t m_height { 0 };
- bool m_isStopped { false };
- Timer m_blackFrameTimer;
- rtc::scoped_refptr<webrtc::VideoFrameBuffer> m_blackFrame;
- bool m_shouldApplyRotation { false };
-#if !RELEASE_LOG_DISABLED
- size_t m_numberOfFrames { 0 };
-#endif
-};
-
-} // namespace WebCore
-
-#endif // USE(LIBWEBRTC)
Added: trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingVideoSourceCocoa.cpp (0 => 223406)
--- trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingVideoSourceCocoa.cpp (rev 0)
+++ trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingVideoSourceCocoa.cpp 2017-10-16 14:44:52 UTC (rev 223406)
@@ -0,0 +1,128 @@
+/*
+ * Copyright (C) 2017 Apple Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted, provided that the following conditions
+ * are required to be met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. AND ITS CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "RealtimeOutgoingVideoSourceCocoa.h"
+
+#if USE(LIBWEBRTC)
+
+#include "Logging.h"
+#include <webrtc/api/video/i420_buffer.h>
+#include <webrtc/common_video/libyuv/include/webrtc_libyuv.h>
+#include <webrtc/sdk/objc/Framework/Classes/Video/corevideo_frame_buffer.h>
+
+#include "CoreMediaSoftLink.h"
+#include "CoreVideoSoftLink.h"
+
+namespace WebCore {
+
+Ref<RealtimeOutgoingVideoSource> RealtimeOutgoingVideoSource::create(Ref<MediaStreamTrackPrivate>&& videoSource)
+{
+ return RealtimeOutgoingVideoSourceCocoa::create(WTFMove(videoSource));
+}
+
+Ref<RealtimeOutgoingVideoSourceCocoa> RealtimeOutgoingVideoSourceCocoa::create(Ref<MediaStreamTrackPrivate>&& videoSource)
+{
+ return adoptRef(*new RealtimeOutgoingVideoSourceCocoa(WTFMove(videoSource)));
+}
+
+RealtimeOutgoingVideoSourceCocoa::RealtimeOutgoingVideoSourceCocoa(Ref<MediaStreamTrackPrivate>&& videoSource)
+ : RealtimeOutgoingVideoSource(WTFMove(videoSource))
+{
+}
+
+void RealtimeOutgoingVideoSourceCocoa::sampleBufferUpdated(MediaStreamTrackPrivate&, MediaSample& sample)
+{
+ if (!m_sinks.size())
+ return;
+
+ if (m_muted || !m_enabled)
+ return;
+
+#if !RELEASE_LOG_DISABLED
+ if (!(++m_numberOfFrames % 30))
+ RELEASE_LOG(MediaStream, "RealtimeOutgoingVideoSourceCocoa::sendFrame %zu frame", m_numberOfFrames);
+#endif
+
+ switch (sample.videoRotation()) {
+ case MediaSample::VideoRotation::None:
+ m_currentRotation = webrtc::kVideoRotation_0;
+ break;
+ case MediaSample::VideoRotation::UpsideDown:
+ m_currentRotation = webrtc::kVideoRotation_180;
+ break;
+ case MediaSample::VideoRotation::Right:
+ m_currentRotation = webrtc::kVideoRotation_90;
+ break;
+ case MediaSample::VideoRotation::Left:
+ m_currentRotation = webrtc::kVideoRotation_270;
+ break;
+ }
+
+ ASSERT(sample.platformSample().type == PlatformSample::CMSampleBufferType);
+ auto pixelBuffer = static_cast<CVPixelBufferRef>(CMSampleBufferGetImageBuffer(sample.platformSample().sample.cmSampleBuffer));
+ auto pixelFormatType = CVPixelBufferGetPixelFormatType(pixelBuffer);
+
+ if (pixelFormatType == kCVPixelFormatType_420YpCbCr8Planar || pixelFormatType == kCVPixelFormatType_420YpCbCr8BiPlanarFullRange) {
+ rtc::scoped_refptr<webrtc::VideoFrameBuffer> buffer = new rtc::RefCountedObject<webrtc::CoreVideoFrameBuffer>(pixelBuffer);
+ if (m_shouldApplyRotation && m_currentRotation != webrtc::kVideoRotation_0) {
+ // FIXME: We should make AVVideoCaptureSource handle the rotation whenever possible.
+ // This implementation is inefficient, we should rotate on the CMSampleBuffer directly instead of doing this double allocation.
+ auto rotatedBuffer = buffer->ToI420();
+ ASSERT(rotatedBuffer);
+ buffer = webrtc::I420Buffer::Rotate(*rotatedBuffer, m_currentRotation);
+ }
+ sendFrame(WTFMove(buffer));
+ return;
+ }
+
+ CVPixelBufferLockBaseAddress(pixelBuffer, 0);
+ auto* source = reinterpret_cast<uint8_t*>(CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 0));
+
+ ASSERT(m_width);
+ ASSERT(m_height);
+
+ auto newBuffer = m_bufferPool.CreateBuffer(m_width, m_height);
+ ASSERT(newBuffer);
+ if (!newBuffer) {
+ RELEASE_LOG(WebRTC, "RealtimeOutgoingVideoSourceCocoa::videoSampleAvailable unable to allocate buffer for conversion to YUV");
+ return;
+ }
+ if (pixelFormatType == kCVPixelFormatType_32BGRA)
+ webrtc::ConvertToI420(webrtc::VideoType::kARGB, source, 0, 0, m_width, m_height, 0, webrtc::kVideoRotation_0, newBuffer);
+ else {
+ ASSERT(pixelFormatType == kCVPixelFormatType_32ARGB);
+ webrtc::ConvertToI420(webrtc::VideoType::kBGRA, source, 0, 0, m_width, m_height, 0, webrtc::kVideoRotation_0, newBuffer);
+ }
+ CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
+ if (m_shouldApplyRotation && m_currentRotation != webrtc::kVideoRotation_0)
+ newBuffer = webrtc::I420Buffer::Rotate(*newBuffer, m_currentRotation);
+ sendFrame(WTFMove(newBuffer));
+}
+
+
+} // namespace WebCore
+
+#endif // USE(LIBWEBRTC)
Added: trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingVideoSourceCocoa.h (0 => 223406)
--- trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingVideoSourceCocoa.h (rev 0)
+++ trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingVideoSourceCocoa.h 2017-10-16 14:44:52 UTC (rev 223406)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2017 Apple Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted, provided that the following conditions
+ * are required to be met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. AND ITS CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if USE(LIBWEBRTC)
+
+#include "RealtimeOutgoingVideoSource.h"
+
+namespace WebCore {
+
+class RealtimeOutgoingVideoSourceCocoa final : public RealtimeOutgoingVideoSource {
+public:
+ static Ref<RealtimeOutgoingVideoSourceCocoa> create(Ref<MediaStreamTrackPrivate>&&);
+
+private:
+ explicit RealtimeOutgoingVideoSourceCocoa(Ref<MediaStreamTrackPrivate>&&);
+
+ // MediaStreamTrackPrivate::Observer API
+ void sampleBufferUpdated(MediaStreamTrackPrivate&, MediaSample&) final;
+
+#if !RELEASE_LOG_DISABLED
+ size_t m_numberOfFrames { 0 };
+#endif
+};
+
+} // namespace WebCore
+
+#endif // USE(LIBWEBRTC)