Unreviewed, reverting r261856.
authorjacob_uphoff@apple.com <jacob_uphoff@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 19 May 2020 23:35:58 +0000 (23:35 +0000)
committerjacob_uphoff@apple.com <jacob_uphoff@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 19 May 2020 23:35:58 +0000 (23:35 +0000)
This caused internal assertion failures.

Reverted changeset:

"Allow calling VideoSampleObserver::videoSampleAvailable from
a background thread"
https://bugs.webkit.org/show_bug.cgi?id=212024
https://trac.webkit.org/changeset/261856

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261893 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/MediaSample.h
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm
Source/WebCore/platform/mediastream/RealtimeMediaSource.cpp
Source/WebCore/platform/mediastream/RealtimeMediaSource.h
Source/WebCore/platform/mediastream/mac/MockRealtimeVideoSourceMac.h
Source/WebCore/platform/mediastream/mac/MockRealtimeVideoSourceMac.mm
Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.h
Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.mm

index b1d2739..4e5355a 100644 (file)
@@ -1,3 +1,16 @@
+2020-05-19  Jacob Uphoff  <jacob_uphoff@apple.com>
+
+        Unreviewed, reverting r261856.
+
+        This caused internal assertion failures.
+
+        Reverted changeset:
+
+        "Allow calling VideoSampleObserver::videoSampleAvailable from
+        a background thread"
+        https://bugs.webkit.org/show_bug.cgi?id=212024
+        https://trac.webkit.org/changeset/261856
+
 2020-05-19  David Kilzer  <ddkilzer@apple.com>
 
         IDBRequestData and IDBClient::TransactionOperation should initialize IndexedDB::IndexRecordType field
index ecd334e..1e44279 100644 (file)
@@ -30,7 +30,7 @@
 #include <JavaScriptCore/TypedArrays.h>
 #include <wtf/EnumTraits.h>
 #include <wtf/MediaTime.h>
-#include <wtf/ThreadSafeRefCounted.h>
+#include <wtf/RefCounted.h>
 #include <wtf/text/AtomString.h>
 
 typedef struct opaqueCMSampleBuffer *CMSampleBufferRef;
@@ -54,7 +54,7 @@ struct PlatformSample {
     } sample;
 };
 
-class MediaSample : public ThreadSafeRefCounted<MediaSample> {
+class MediaSample : public RefCounted<MediaSample> {
 public:
     virtual ~MediaSample() = default;
 
index e06d6b3..9663079 100644 (file)
@@ -139,6 +139,7 @@ private:
 
     MediaTime calculateTimelineOffset(const MediaSample&, double);
     
+    void enqueueVideoSample(MediaSample&);
     void enqueueCorrectedVideoSample(MediaSample&);
     void requestNotificationWhenReadyForVideoData();
 
index 9b7b43a..01992a5 100644 (file)
@@ -141,7 +141,6 @@ MediaPlayerPrivateMediaStreamAVFObjC::MediaPlayerPrivateMediaStreamAVFObjC(Media
     , m_videoLayerManager(makeUnique<VideoLayerManagerObjC>(m_logger, m_logIdentifier))
 {
     INFO_LOG(LOGIDENTIFIER);
-    // MediaPlayerPrivateMediaStreamAVFObjC::videoSampleAvailable expects a weak pointer to be created in the constructor.
     m_boundsChangeListener = adoptNS([[WebRootSampleBufferBoundsChangeListener alloc] initWithCallback:[this, weakThis = makeWeakPtr(this)] {
         if (!weakThis)
             return;
@@ -282,16 +281,8 @@ void MediaPlayerPrivateMediaStreamAVFObjC::enqueueCorrectedVideoSample(MediaSamp
     }
 }
 
-void MediaPlayerPrivateMediaStreamAVFObjC::videoSampleAvailable(MediaSample& sample)
+void MediaPlayerPrivateMediaStreamAVFObjC::enqueueVideoSample(MediaSample& sample)
 {
-    if (!isMainThread()) {
-        callOnMainThread([weakThis = makeWeakPtr(this), sample = makeRef(sample)]() mutable {
-            if (weakThis)
-                weakThis->videoSampleAvailable(sample.get());
-        });
-        return;
-    }
-
     if (!m_imagePainter.mediaSample || m_displayMode != PausedImage) {
         m_imagePainter.mediaSample = &sample;
         m_imagePainter.cgImage = nullptr;
@@ -744,6 +735,14 @@ void MediaPlayerPrivateMediaStreamAVFObjC::didRemoveTrack(MediaStreamTrackPrivat
     updateTracks();
 }
 
+void MediaPlayerPrivateMediaStreamAVFObjC::videoSampleAvailable(MediaSample& mediaSample)
+{
+    if (streamTime().toDouble() < 0)
+        return;
+
+    enqueueVideoSample(mediaSample);
+}
+
 void MediaPlayerPrivateMediaStreamAVFObjC::readyStateChanged(MediaStreamTrackPrivate&)
 {
     scheduleDeferredTask([this] {
index 869ef2f..f7d9096 100644 (file)
@@ -187,6 +187,8 @@ void RealtimeMediaSource::updateHasStartedProducingData()
 
 void RealtimeMediaSource::videoSampleAvailable(MediaSample& mediaSample)
 {
+    // FIXME: Migrate RealtimeMediaSource clients to non main thread processing.
+    ASSERT(isMainThread());
 #if !RELEASE_LOG_DISABLED
     ++m_frameCount;
 
@@ -964,11 +966,8 @@ void RealtimeMediaSource::setIntrinsicSize(const IntSize& size)
     auto currentSize = this->size();
     m_intrinsicSize = size;
 
-    if (currentSize != this->size()) {
-        scheduleDeferredTask([this] {
-            notifySettingsDidChangeObservers({ RealtimeMediaSourceSettings::Flag::Width, RealtimeMediaSourceSettings::Flag::Height });
-        });
-    }
+    if (currentSize != this->size())
+        notifySettingsDidChangeObservers({ RealtimeMediaSourceSettings::Flag::Width, RealtimeMediaSourceSettings::Flag::Height });
 }
 
 const IntSize RealtimeMediaSource::intrinsicSize() const
index 35fdf42..1db8114 100644 (file)
@@ -102,8 +102,7 @@ public:
     public:
         virtual ~VideoSampleObserver() = default;
 
-        // May be called on a background thread.
-        virtual void videoSampleAvailable(MediaSample&) = 0;
+        virtual void videoSampleAvailable(MediaSample&) { }
     };
 
     virtual ~RealtimeMediaSource() = default;
@@ -279,9 +278,7 @@ private:
     mutable RecursiveLock m_videoSampleObserversLock;
     HashSet<VideoSampleObserver*> m_videoSampleObservers;
 
-    // Set on the main thread from constraints.
     IntSize m_size;
-    // Set on sample generation thread.
     IntSize m_intrinsicSize;
     double m_frameRate { 30 };
     double m_aspectRatio { 0 };
index 95cf35c..81ed997 100644 (file)
@@ -34,7 +34,6 @@
 
 #include "MockRealtimeVideoSource.h"
 #include "PixelBufferConformerCV.h"
-#include <wtf/WorkQueue.h>
 
 typedef struct __CVBuffer *CVBufferRef;
 typedef CVBufferRef CVImageBufferRef;
@@ -61,7 +60,6 @@ private:
 
     std::unique_ptr<ImageTransferSessionVT> m_imageTransferSession;
     IntSize m_presetSize;
-    Ref<WorkQueue> m_workQueue;
 };
 
 } // namespace WebCore
index 3f6cb6e..b84e0b0 100644 (file)
@@ -78,7 +78,6 @@ Ref<MockRealtimeVideoSource> MockRealtimeVideoSourceMac::createForMockDisplayCap
 
 MockRealtimeVideoSourceMac::MockRealtimeVideoSourceMac(String&& deviceID, String&& name, String&& hashSalt)
     : MockRealtimeVideoSource(WTFMove(deviceID), WTFMove(name), WTFMove(hashSalt))
-    , m_workQueue(WorkQueue::create("MockRealtimeVideoSource Render Queue", WorkQueue::Type::Serial, WorkQueue::QOS::UserInteractive))
 {
 }
 
@@ -96,9 +95,7 @@ void MockRealtimeVideoSourceMac::updateSampleBuffer()
     if (!sampleBuffer)
         return;
 
-    m_workQueue->dispatch([this, protectedThis = makeRef(*this), sampleBuffer = WTFMove(sampleBuffer)]() mutable {
-        dispatchMediaSampleToObservers(*sampleBuffer);
-    });
+    dispatchMediaSampleToObservers(*sampleBuffer);
 }
 
 } // namespace WebCore
index f5523d3..786b550 100644 (file)
@@ -43,6 +43,7 @@ public:
 
 private:
     RealtimeIncomingVideoSourceCocoa(rtc::scoped_refptr<webrtc::VideoTrackInterface>&&, String&&);
+    void processNewSample(CMSampleBufferRef, unsigned, unsigned, MediaSample::VideoRotation);
     RetainPtr<CVPixelBufferRef> pixelBufferFromVideoFrame(const webrtc::VideoFrame&);
     CVPixelBufferPoolRef pixelBufferPool(size_t width, size_t height);
 
index ee9836b..e80ecc0 100644 (file)
@@ -193,8 +193,18 @@ void RealtimeIncomingVideoSourceCocoa::OnFrame(const webrtc::VideoFrame& frame)
         break;
     }
 
-    setIntrinsicSize(IntSize(width, height));
-    videoSampleAvailable(MediaSampleAVFObjC::create(sample.get(), rotation));
+    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)
+{
+    auto size = this->size();
+    if (WTF::safeCast<int>(width) != size.width() || WTF::safeCast<int>(height) != size.height())
+        setIntrinsicSize(IntSize(width, height));
+
+    videoSampleAvailable(MediaSampleAVFObjC::create(sample, rotation));
 }
 
 } // namespace WebCore