Simplify RealtimeMediaSource data production and state
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 16 May 2017 02:45:28 +0000 (02:45 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 16 May 2017 02:45:28 +0000 (02:45 +0000)
https://bugs.webkit.org/show_bug.cgi?id=171999

Patch by Youenn Fablet <youenn@apple.com> on 2017-05-15
Reviewed by Eric Carlson.

Source/WebCore:

RealtimeMediaSource takes 3 booleans:
- m_isProducingData tells whether data is produced or not. In the case of capturing, it tells whether capture
  happens.
- m_muted/m_enabled allows JS or WebKit level to start/stop the source.

Changed MediaStream capture state computation so that capture is reported as follows:
- m_isProducing is true, capture is happenning and is active
- m_muted is true, capture is happening but is inactive.

Except in the case of WebRTC incoming sources, for which sources may be created as muted as per the spec,
all sources are unmuted, enabled and not producing data when created.

RealtimeMediaSource is now activable either by calling start/stop or by calling setMuted/setEnabled.
This in turns will set the boolean values accordingly and will call the underlying
startProducingData/stopProducingData methods doing the actual stuff.

Removing from all RealtimeMediaSource subclasses the handling of producing data.
Making more methods non-virtual/member fields private to simplify the model.

* Modules/mediastream/CanvasCaptureMediaStreamTrack.cpp:
(WebCore::CanvasCaptureMediaStreamTrack::Source::create):
(WebCore::CanvasCaptureMediaStreamTrack::Source::startProducingData):
(WebCore::CanvasCaptureMediaStreamTrack::Source::stopProducingData):
(WebCore::CanvasCaptureMediaStreamTrack::Source::canvasDestroyed):
(WebCore::CanvasCaptureMediaStreamTrack::Source::captureCanvas):
* Modules/mediastream/CanvasCaptureMediaStreamTrack.h:
* Modules/mediastream/MediaStream.cpp:
(WebCore::MediaStream::mediaState):
* platform/mediastream/MediaStreamTrackPrivate.h:
(WebCore::MediaStreamTrackPrivate::startProducingData):
(WebCore::MediaStreamTrackPrivate::stopProducingData):
* platform/mediastream/RealtimeMediaSource.cpp:
(WebCore::RealtimeMediaSource::setMuted):
(WebCore::RealtimeMediaSource::notifyMutedChange):
(WebCore::RealtimeMediaSource::setEnabled):
(WebCore::RealtimeMediaSource::start):
(WebCore::RealtimeMediaSource::stop):
(WebCore::RealtimeMediaSource::requestStop):
(WebCore::RealtimeMediaSource::reset): Deleted.
* platform/mediastream/RealtimeMediaSource.h:
* platform/mediastream/mac/AVMediaCaptureSource.h:
* platform/mediastream/mac/AVMediaCaptureSource.mm:
(WebCore::AVMediaCaptureSource::AVMediaCaptureSource):
(WebCore::AVMediaCaptureSource::captureSessionIsRunningDidChange):
(WebCore::AVMediaCaptureSource::reset): Deleted.
(WebCore::AVMediaCaptureSource::isProducingData): Deleted.
* platform/mediastream/mac/CoreAudioCaptureSource.cpp:
(WebCore::CoreAudioCaptureSource::CoreAudioCaptureSource):
(WebCore::CoreAudioCaptureSource::startProducingData):
(WebCore::CoreAudioCaptureSource::stopProducingData):
(WebCore::CoreAudioCaptureSource::audioSourceProvider):
* platform/mediastream/mac/CoreAudioCaptureSource.h:
* platform/mediastream/mac/MockRealtimeAudioSourceMac.mm:
(WebCore::MockRealtimeAudioSourceMac::render):
(WebCore::MockRealtimeAudioSource::createMuted): Deleted.
* platform/mediastream/mac/MockRealtimeVideoSourceMac.mm:
(WebCore::MockRealtimeVideoSource::createMuted): Deleted.
* platform/mediastream/mac/RealtimeIncomingAudioSource.cpp:
(WebCore::RealtimeIncomingAudioSource::create):
(WebCore::RealtimeIncomingAudioSource::RealtimeIncomingAudioSource):
(WebCore::RealtimeIncomingAudioSource::~RealtimeIncomingAudioSource):
(WebCore::RealtimeIncomingAudioSource::startProducingData):
(WebCore::RealtimeIncomingAudioSource::stopProducingData):
(WebCore::RealtimeIncomingAudioSource::setSourceTrack):
* platform/mediastream/mac/RealtimeIncomingAudioSource.h:
* platform/mediastream/mac/RealtimeIncomingVideoSource.cpp:
(WebCore::RealtimeIncomingVideoSource::create):
(WebCore::RealtimeIncomingVideoSource::RealtimeIncomingVideoSource):
(WebCore::RealtimeIncomingVideoSource::startProducingData):
(WebCore::RealtimeIncomingVideoSource::setSourceTrack):
(WebCore::RealtimeIncomingVideoSource::stopProducingData):
(WebCore::RealtimeIncomingVideoSource::OnFrame):
* platform/mediastream/mac/RealtimeIncomingVideoSource.h:
* platform/mediastream/mac/WebAudioSourceProviderAVFObjC.mm:
(WebCore::WebAudioSourceProviderAVFObjC::setClient):
* platform/mock/MockMediaEndpoint.cpp:
(WebCore::MockMediaEndpoint::createMutedRemoteSource):
(WebCore::MockMediaEndpoint::unmuteTimerFired):
* platform/mock/MockRealtimeAudioSource.cpp:
(WebCore::MockRealtimeAudioSource::createMuted):
(WebCore::MockRealtimeAudioSource::startProducingData):
(WebCore::MockRealtimeAudioSource::stopProducingData):
* platform/mock/MockRealtimeAudioSource.h:
* platform/mock/MockRealtimeMediaSource.cpp:
(WebCore::MockRealtimeMediaSource::startProducingData): Deleted.
(WebCore::MockRealtimeMediaSource::stopProducingData): Deleted.
* platform/mock/MockRealtimeMediaSource.h:
* platform/mock/MockRealtimeVideoSource.cpp:
(WebCore::MockRealtimeVideoSource::createMuted):
(WebCore::MockRealtimeVideoSource::startProducingData):
(WebCore::MockRealtimeVideoSource::stopProducingData):
(WebCore::MockRealtimeVideoSource::generateFrame):
* platform/mock/MockRealtimeVideoSource.h:

Source/WebKit2:

* UIProcess/Cocoa/UserMediaCaptureManagerProxy.cpp:
(WebKit::UserMediaCaptureManagerProxy::startProducingData):
(WebKit::UserMediaCaptureManagerProxy::stopProducingData):
* WebProcess/cocoa/UserMediaCaptureManager.cpp:

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

30 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Modules/mediastream/CanvasCaptureMediaStreamTrack.cpp
Source/WebCore/Modules/mediastream/CanvasCaptureMediaStreamTrack.h
Source/WebCore/Modules/mediastream/MediaStream.cpp
Source/WebCore/platform/mediastream/MediaStreamTrackPrivate.h
Source/WebCore/platform/mediastream/RealtimeMediaSource.cpp
Source/WebCore/platform/mediastream/RealtimeMediaSource.h
Source/WebCore/platform/mediastream/mac/AVMediaCaptureSource.h
Source/WebCore/platform/mediastream/mac/AVMediaCaptureSource.mm
Source/WebCore/platform/mediastream/mac/CoreAudioCaptureSource.cpp
Source/WebCore/platform/mediastream/mac/CoreAudioCaptureSource.h
Source/WebCore/platform/mediastream/mac/MockRealtimeAudioSourceMac.mm
Source/WebCore/platform/mediastream/mac/MockRealtimeVideoSourceMac.mm
Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSource.cpp
Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSource.h
Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSource.cpp
Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSource.h
Source/WebCore/platform/mediastream/mac/WebAudioSourceProviderAVFObjC.mm
Source/WebCore/platform/mediastream/openwebrtc/MediaEndpointOwr.cpp
Source/WebCore/platform/mediastream/openwebrtc/RealtimeMediaSourceOwr.h
Source/WebCore/platform/mock/MockMediaEndpoint.cpp
Source/WebCore/platform/mock/MockRealtimeAudioSource.cpp
Source/WebCore/platform/mock/MockRealtimeAudioSource.h
Source/WebCore/platform/mock/MockRealtimeMediaSource.cpp
Source/WebCore/platform/mock/MockRealtimeMediaSource.h
Source/WebCore/platform/mock/MockRealtimeVideoSource.cpp
Source/WebCore/platform/mock/MockRealtimeVideoSource.h
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/Cocoa/UserMediaCaptureManagerProxy.cpp
Source/WebKit2/WebProcess/cocoa/UserMediaCaptureManager.cpp

index 6558dd6..ba3e76f 100644 (file)
@@ -1,3 +1,104 @@
+2017-05-15  Youenn Fablet  <youenn@apple.com>
+
+        Simplify RealtimeMediaSource data production and state
+        https://bugs.webkit.org/show_bug.cgi?id=171999
+
+        Reviewed by Eric Carlson.
+
+        RealtimeMediaSource takes 3 booleans:
+        - m_isProducingData tells whether data is produced or not. In the case of capturing, it tells whether capture
+          happens.
+        - m_muted/m_enabled allows JS or WebKit level to start/stop the source.
+
+        Changed MediaStream capture state computation so that capture is reported as follows:
+        - m_isProducing is true, capture is happenning and is active
+        - m_muted is true, capture is happening but is inactive.
+
+        Except in the case of WebRTC incoming sources, for which sources may be created as muted as per the spec,
+        all sources are unmuted, enabled and not producing data when created.
+
+        RealtimeMediaSource is now activable either by calling start/stop or by calling setMuted/setEnabled.
+        This in turns will set the boolean values accordingly and will call the underlying
+        startProducingData/stopProducingData methods doing the actual stuff.
+
+        Removing from all RealtimeMediaSource subclasses the handling of producing data.
+        Making more methods non-virtual/member fields private to simplify the model.
+
+        * Modules/mediastream/CanvasCaptureMediaStreamTrack.cpp:
+        (WebCore::CanvasCaptureMediaStreamTrack::Source::create):
+        (WebCore::CanvasCaptureMediaStreamTrack::Source::startProducingData):
+        (WebCore::CanvasCaptureMediaStreamTrack::Source::stopProducingData):
+        (WebCore::CanvasCaptureMediaStreamTrack::Source::canvasDestroyed):
+        (WebCore::CanvasCaptureMediaStreamTrack::Source::captureCanvas):
+        * Modules/mediastream/CanvasCaptureMediaStreamTrack.h:
+        * Modules/mediastream/MediaStream.cpp:
+        (WebCore::MediaStream::mediaState):
+        * platform/mediastream/MediaStreamTrackPrivate.h:
+        (WebCore::MediaStreamTrackPrivate::startProducingData):
+        (WebCore::MediaStreamTrackPrivate::stopProducingData):
+        * platform/mediastream/RealtimeMediaSource.cpp:
+        (WebCore::RealtimeMediaSource::setMuted):
+        (WebCore::RealtimeMediaSource::notifyMutedChange):
+        (WebCore::RealtimeMediaSource::setEnabled):
+        (WebCore::RealtimeMediaSource::start):
+        (WebCore::RealtimeMediaSource::stop):
+        (WebCore::RealtimeMediaSource::requestStop):
+        (WebCore::RealtimeMediaSource::reset): Deleted.
+        * platform/mediastream/RealtimeMediaSource.h:
+        * platform/mediastream/mac/AVMediaCaptureSource.h:
+        * platform/mediastream/mac/AVMediaCaptureSource.mm:
+        (WebCore::AVMediaCaptureSource::AVMediaCaptureSource):
+        (WebCore::AVMediaCaptureSource::captureSessionIsRunningDidChange):
+        (WebCore::AVMediaCaptureSource::reset): Deleted.
+        (WebCore::AVMediaCaptureSource::isProducingData): Deleted.
+        * platform/mediastream/mac/CoreAudioCaptureSource.cpp:
+        (WebCore::CoreAudioCaptureSource::CoreAudioCaptureSource):
+        (WebCore::CoreAudioCaptureSource::startProducingData):
+        (WebCore::CoreAudioCaptureSource::stopProducingData):
+        (WebCore::CoreAudioCaptureSource::audioSourceProvider):
+        * platform/mediastream/mac/CoreAudioCaptureSource.h:
+        * platform/mediastream/mac/MockRealtimeAudioSourceMac.mm:
+        (WebCore::MockRealtimeAudioSourceMac::render):
+        (WebCore::MockRealtimeAudioSource::createMuted): Deleted.
+        * platform/mediastream/mac/MockRealtimeVideoSourceMac.mm:
+        (WebCore::MockRealtimeVideoSource::createMuted): Deleted.
+        * platform/mediastream/mac/RealtimeIncomingAudioSource.cpp:
+        (WebCore::RealtimeIncomingAudioSource::create):
+        (WebCore::RealtimeIncomingAudioSource::RealtimeIncomingAudioSource):
+        (WebCore::RealtimeIncomingAudioSource::~RealtimeIncomingAudioSource):
+        (WebCore::RealtimeIncomingAudioSource::startProducingData):
+        (WebCore::RealtimeIncomingAudioSource::stopProducingData):
+        (WebCore::RealtimeIncomingAudioSource::setSourceTrack):
+        * platform/mediastream/mac/RealtimeIncomingAudioSource.h:
+        * platform/mediastream/mac/RealtimeIncomingVideoSource.cpp:
+        (WebCore::RealtimeIncomingVideoSource::create):
+        (WebCore::RealtimeIncomingVideoSource::RealtimeIncomingVideoSource):
+        (WebCore::RealtimeIncomingVideoSource::startProducingData):
+        (WebCore::RealtimeIncomingVideoSource::setSourceTrack):
+        (WebCore::RealtimeIncomingVideoSource::stopProducingData):
+        (WebCore::RealtimeIncomingVideoSource::OnFrame):
+        * platform/mediastream/mac/RealtimeIncomingVideoSource.h:
+        * platform/mediastream/mac/WebAudioSourceProviderAVFObjC.mm:
+        (WebCore::WebAudioSourceProviderAVFObjC::setClient):
+        * platform/mock/MockMediaEndpoint.cpp:
+        (WebCore::MockMediaEndpoint::createMutedRemoteSource):
+        (WebCore::MockMediaEndpoint::unmuteTimerFired):
+        * platform/mock/MockRealtimeAudioSource.cpp:
+        (WebCore::MockRealtimeAudioSource::createMuted):
+        (WebCore::MockRealtimeAudioSource::startProducingData):
+        (WebCore::MockRealtimeAudioSource::stopProducingData):
+        * platform/mock/MockRealtimeAudioSource.h:
+        * platform/mock/MockRealtimeMediaSource.cpp:
+        (WebCore::MockRealtimeMediaSource::startProducingData): Deleted.
+        (WebCore::MockRealtimeMediaSource::stopProducingData): Deleted.
+        * platform/mock/MockRealtimeMediaSource.h:
+        * platform/mock/MockRealtimeVideoSource.cpp:
+        (WebCore::MockRealtimeVideoSource::createMuted):
+        (WebCore::MockRealtimeVideoSource::startProducingData):
+        (WebCore::MockRealtimeVideoSource::stopProducingData):
+        (WebCore::MockRealtimeVideoSource::generateFrame):
+        * platform/mock/MockRealtimeVideoSource.h:
+
 2017-05-15  Myles C. Maxfield  <mmaxfield@apple.com>
 
         Migrate Font constructor from bools to enums
index 3f7b2c1..5e05c3e 100644 (file)
@@ -48,7 +48,7 @@ CanvasCaptureMediaStreamTrack::CanvasCaptureMediaStreamTrack(ScriptExecutionCont
 Ref<CanvasCaptureMediaStreamTrack::Source> CanvasCaptureMediaStreamTrack::Source::create(HTMLCanvasElement& canvas, std::optional<double>&& frameRequestRate)
 {
     auto source = adoptRef(*new Source(canvas, WTFMove(frameRequestRate)));
-    source->startProducingData();
+    source->start();
 
     callOnMainThread([source = source.copyRef()] {
         if (!source->m_canvas)
@@ -76,10 +76,6 @@ CanvasCaptureMediaStreamTrack::Source::Source(HTMLCanvasElement& canvas, std::op
 
 void CanvasCaptureMediaStreamTrack::Source::startProducingData()
 {
-    if (m_isProducingData)
-        return;
-    m_isProducingData = true;
-
     if (!m_canvas)
         return;
     m_canvas->addObserver(*this);
@@ -93,10 +89,6 @@ void CanvasCaptureMediaStreamTrack::Source::startProducingData()
 
 void CanvasCaptureMediaStreamTrack::Source::stopProducingData()
 {
-    if (!m_isProducingData)
-        return;
-    m_isProducingData = false;
-
     m_requestFrameTimer.stop();
 
     if (!m_canvas)
@@ -113,7 +105,7 @@ void CanvasCaptureMediaStreamTrack::Source::canvasDestroyed(HTMLCanvasElement& c
 {
     ASSERT_UNUSED(canvas, m_canvas == &canvas);
 
-    stopProducingData();
+    stop();
     m_canvas = nullptr;
 }
 
@@ -150,7 +142,7 @@ void CanvasCaptureMediaStreamTrack::Source::captureCanvas()
 {
     ASSERT(m_canvas);
 
-    if (!m_isProducingData)
+    if (!isProducingData())
         return;
 
     if (m_frameRequestRate) {
index ad25ade..ce077cd 100644 (file)
@@ -62,7 +62,6 @@ private:
         // RealtimeMediaSource API
         void startProducingData() final;
         void stopProducingData()  final;
-        bool isProducingData() const { return m_isProducingData; }
         const RealtimeMediaSourceCapabilities& capabilities() const final { return RealtimeMediaSourceCapabilities::emptyCapabilities(); }
         const RealtimeMediaSourceSettings& settings() const final { return m_settings; }
         bool applySize(const IntSize&) final { return true; }
@@ -70,7 +69,6 @@ private:
         void captureCanvas();
         void requestFrameTimerFired();
 
-        bool m_isProducingData { false };
         bool m_shouldEmitFrame { true };
         std::optional<double> m_frameRequestRate;
         Timer m_requestFrameTimer;
index 80be5ff..60b7222 100644 (file)
@@ -346,7 +346,7 @@ MediaProducer::MediaStateFlags MediaStream::mediaState() const
         if (m_private->hasCaptureAudioSource()) {
             if (m_private->muted())
                 state |= HasMutedAudioCaptureDevice;
-            else if (m_isProducingData)
+            else if (m_isProducingData && m_private->isProducingData())
                 state |= HasActiveAudioCaptureDevice;
         }
     }
@@ -356,7 +356,7 @@ MediaProducer::MediaStateFlags MediaStream::mediaState() const
         if (m_private->hasCaptureVideoSource()) {
             if (m_private->muted())
                 state |= HasMutedVideoCaptureDevice;
-            else if (m_isProducingData)
+            else if (m_isProducingData && m_private->isProducingData())
                 state |= HasActiveVideoCaptureDevice;
         }
     }
index 5e2046a..aed3791 100644 (file)
@@ -62,8 +62,8 @@ public:
 
     bool ended() const { return m_isEnded; }
 
-    void startProducingData() { m_source->startProducingData(); }
-    void stopProducingData() { m_source->stopProducingData(); }
+    void startProducingData() { m_source->start(); }
+    void stopProducingData() { m_source->stop(); }
     bool isProducingData() { return m_source->isProducingData(); }
 
     bool isIsolated() const { return m_source->isIsolated(); }
index 1f49931..f3c1201 100644 (file)
@@ -60,21 +60,15 @@ RealtimeMediaSource::RealtimeMediaSource(const String& id, Type type, const Stri
     m_suppressNotifications = false;
 }
 
-void RealtimeMediaSource::reset()
-{
-    m_stopped = false;
-    m_muted = false;
-}
-
 void RealtimeMediaSource::addObserver(RealtimeMediaSource::Observer& observer)
 {
-    m_observers.append(&observer);
+    m_observers.append(observer);
 }
 
 void RealtimeMediaSource::removeObserver(RealtimeMediaSource::Observer& observer)
 {
-    m_observers.removeFirstMatching([&observer](auto* anObserver) {
-        return anObserver == &observer;
+    m_observers.removeFirstMatching([&observer](auto anObserver) {
+        return &anObserver.get() == &observer;
     });
 
     if (!m_observers.size())
@@ -83,39 +77,39 @@ void RealtimeMediaSource::removeObserver(RealtimeMediaSource::Observer& observer
 
 void RealtimeMediaSource::setMuted(bool muted)
 {
-    if (m_stopped || m_muted == muted)
+    if (muted)
+        stop();
+    else
+        start();
+
+    notifyMutedChange(muted);
+}
+
+void RealtimeMediaSource::notifyMutedChange(bool muted)
+{
+    if (m_muted == muted)
         return;
 
     m_muted = muted;
 
-    if (muted) {
-        // FIXME: We need to figure out how to guarantee that at least one black video frame is
-        // emitted after being muted.
-        stopProducingData();
-    } else
-        startProducingData();
-
     notifyMutedObservers();
 }
 
 void RealtimeMediaSource::notifyMutedObservers() const
 {
-    for (auto& observer : m_observers)
-        observer->sourceMutedChanged();
+    for (Observer& observer : m_observers)
+        observer.sourceMutedChanged();
 }
 
 void RealtimeMediaSource::setEnabled(bool enabled)
 {
-    if (m_stopped || m_enabled == enabled)
+    if (m_enabled == enabled)
         return;
 
     m_enabled = enabled;
 
-    if (m_stopped)
-        return;
-
-    for (auto& observer : m_observers)
-        observer->sourceEnabledChanged();
+    for (Observer& observer : m_observers)
+        observer.sourceEnabledChanged();
 }
 
 void RealtimeMediaSource::settingsDidChange()
@@ -129,49 +123,57 @@ void RealtimeMediaSource::settingsDidChange()
 
     scheduleDeferredTask([this] {
         m_pendingSettingsDidChangeNotification = false;
-        for (auto& observer : m_observers)
-            observer->sourceSettingsChanged();
+        for (Observer& observer : m_observers)
+            observer.sourceSettingsChanged();
     });
 }
 
 void RealtimeMediaSource::videoSampleAvailable(MediaSample& mediaSample)
 {
-    ASSERT(isMainThread());
-    for (const auto& observer : m_observers)
-        observer->videoSampleAvailable(mediaSample);
+    for (Observer& observer : m_observers)
+        observer.videoSampleAvailable(mediaSample);
 }
 
 void RealtimeMediaSource::audioSamplesAvailable(const MediaTime& time, const PlatformAudioData& audioData, const AudioStreamDescription& description, size_t numberOfFrames)
 {
-    for (const auto& observer : m_observers)
-        observer->audioSamplesAvailable(time, audioData, description, numberOfFrames);
+    for (Observer& observer : m_observers)
+        observer.audioSamplesAvailable(time, audioData, description, numberOfFrames);
 }
 
-void RealtimeMediaSource::stop(Observer* callingObserver)
+void RealtimeMediaSource::start()
 {
-    if (stopped())
+    if (m_isProducingData)
         return;
 
-    m_stopped = true;
+    m_isProducingData = true;
+    startProducingData();
+}
 
-    for (const auto& observer : m_observers) {
-        if (observer != callingObserver)
-            observer->sourceStopped();
-    }
+void RealtimeMediaSource::stop()
+{
+    if (!m_isProducingData)
+        return;
 
+    m_isProducingData = false;
     stopProducingData();
 }
 
 void RealtimeMediaSource::requestStop(Observer* callingObserver)
 {
-    if (stopped())
+    if (!m_isProducingData)
         return;
 
-    for (const auto& observer : m_observers) {
-        if (observer->preventSourceFromStopping())
+    for (Observer& observer : m_observers) {
+        if (observer.preventSourceFromStopping())
             return;
     }
-    stop(callingObserver);
+
+    stop();
+
+    for (Observer& observer : m_observers) {
+        if (&observer != callingObserver)
+            observer.sourceStopped();
+    }
 }
 
 bool RealtimeMediaSource::supportsSizeAndFrameRate(std::optional<int>, std::optional<int>, std::optional<double>)
index c1bf672..bcf3a97 100644 (file)
@@ -127,60 +127,30 @@ public:
     const String& id() const { return m_id; }
 
     const String& persistentID() const { return m_persistentID; }
-    virtual void setPersistentID(const String& persistentID) { m_persistentID = persistentID; }
+    virtual void setPersistentID(String&& persistentID) { m_persistentID = WTFMove(persistentID); }
 
     enum class Type { None, Audio, Video };
     Type type() const { return m_type; }
 
-    virtual const String& name() const { return m_name; }
-    virtual void setName(const String& name) { m_name = name; }
-    
-    virtual unsigned fitnessScore() const { return m_fitnessScore; }
-
-    virtual const RealtimeMediaSourceCapabilities& capabilities() const = 0;
-    virtual const RealtimeMediaSourceSettings& settings() const = 0;
-
-    using SuccessHandler = std::function<void()>;
-    using FailureHandler = std::function<void(const String& badConstraint, const String& errorString)>;
-    virtual void applyConstraints(const MediaConstraints&, SuccessHandler&&, FailureHandler&&);
-    std::optional<std::pair<String, String>> applyConstraints(const MediaConstraints&);
-
-    virtual bool supportsConstraints(const MediaConstraints&, String&);
-    virtual bool supportsConstraint(const MediaConstraint&) const;
-
-    virtual void settingsDidChange();
+    bool isProducingData() const { return m_isProducingData; }
+    void start();
+    void stop();
+    void requestStop(Observer* callingObserver = nullptr);
 
-    virtual bool isIsolated() const { return false; }
-    
-    void videoSampleAvailable(MediaSample&);
-    void audioSamplesAvailable(const MediaTime&, const PlatformAudioData&, const AudioStreamDescription&, size_t);
+    bool muted() const { return m_muted; }
+    void setMuted(bool);
     
-    bool stopped() const { return m_stopped; }
-
-    virtual bool muted() const { return m_muted; }
-    virtual void setMuted(bool);
+    bool enabled() const { return m_enabled; }
+    void setEnabled(bool);
 
-    virtual bool enabled() const { return m_enabled; }
-    virtual void setEnabled(bool);
-
-    virtual bool isCaptureSource() const { return false; }
-
-    virtual void monitorOrientation(OrientationNotifier&) { }
+    const String& name() const { return m_name; }
+    void setName(const String& name) { m_name = name; }
     
+    unsigned fitnessScore() const { return m_fitnessScore; }
+
     WEBCORE_EXPORT void addObserver(Observer&);
     WEBCORE_EXPORT void removeObserver(Observer&);
 
-    virtual void startProducingData() { }
-    virtual void stopProducingData() { }
-    virtual bool isProducingData() const { return false; }
-
-    void stop(Observer* callingObserver = nullptr);
-    void requestStop(Observer* callingObserver = nullptr);
-
-    virtual void reset();
-
-    virtual AudioSourceProvider* audioSourceProvider() { return nullptr; }
-
     void setWidth(int);
     void setHeight(int);
     const IntSize& size() const { return m_size; }
@@ -214,6 +184,27 @@ public:
     void setEchoCancellation(bool);
     virtual bool applyEchoCancellation(bool) { return false; }
 
+    virtual const RealtimeMediaSourceCapabilities& capabilities() const = 0;
+    virtual const RealtimeMediaSourceSettings& settings() const = 0;
+
+    using SuccessHandler = std::function<void()>;
+    using FailureHandler = std::function<void(const String& badConstraint, const String& errorString)>;
+    virtual void applyConstraints(const MediaConstraints&, SuccessHandler&&, FailureHandler&&);
+    std::optional<std::pair<String, String>> applyConstraints(const MediaConstraints&);
+
+    virtual bool supportsConstraints(const MediaConstraints&, String&);
+    virtual bool supportsConstraint(const MediaConstraint&) const;
+
+    virtual void settingsDidChange();
+
+    virtual bool isIsolated() const { return false; }
+
+    virtual bool isCaptureSource() const { return false; }
+
+    virtual void monitorOrientation(OrientationNotifier&) { }
+
+    virtual AudioSourceProvider* audioSourceProvider() { return nullptr; }
+
 protected:
     RealtimeMediaSource(const String& id, Type, const String& name);
 
@@ -231,26 +222,31 @@ protected:
     virtual void applyConstraints(const FlattenedConstraint&);
     virtual void applySizeAndFrameRate(std::optional<int> width, std::optional<int> height, std::optional<double>);
 
-    const Vector<Observer*> observers() const { return m_observers; }
-
     void notifyMutedObservers() const;
+    void notifyMutedChange(bool muted);
 
     void initializeVolume(double volume) { m_volume = volume; }
     void initializeSampleRate(int sampleRate) { m_sampleRate = sampleRate; }
     void initializeEchoCancellation(bool echoCancellation) { m_echoCancellation = echoCancellation; }
 
-    bool m_muted { false };
-    bool m_enabled { true };
-
+    void videoSampleAvailable(MediaSample&);
+    void audioSamplesAvailable(const MediaTime&, const PlatformAudioData&, const AudioStreamDescription&, size_t);
+    
 private:
     WeakPtr<RealtimeMediaSource> createWeakPtr() { return m_weakPtrFactory.createWeakPtr(); }
 
+    virtual void startProducingData() { }
+    virtual void stopProducingData() { }
+
+    bool m_muted { false };
+    bool m_enabled { true };
+
     WeakPtrFactory<RealtimeMediaSource> m_weakPtrFactory;
     String m_id;
     String m_persistentID;
     Type m_type;
     String m_name;
-    Vector<Observer*> m_observers;
+    Vector<std::reference_wrapper<Observer>> m_observers;
     IntSize m_size;
     double m_frameRate { 30 };
     double m_aspectRatio { 0 };
@@ -261,9 +257,9 @@ private:
     RealtimeMediaSourceSettings::VideoFacingMode m_facingMode { RealtimeMediaSourceSettings::User};
 
     bool m_echoCancellation { false };
-    bool m_stopped { false };
     bool m_pendingSettingsDidChangeNotification { false };
     bool m_suppressNotifications { true };
+    bool m_isProducingData { false };
 };
 
 struct CaptureSourceOrError {
index f849010..71501c0 100644 (file)
@@ -68,7 +68,6 @@ public:
 
     void startProducingData() final;
     void stopProducingData() final;
-    bool isProducingData() const final;
 
 protected:
     AVMediaCaptureSource(AVCaptureDevice*, const AtomicString&, RealtimeMediaSource::Type);
@@ -91,7 +90,6 @@ protected:
 
 private:
     void setupSession();
-    void reset() final;
 
     void beginConfiguration() final;
     void commitConfiguration() final;
index 122bdb8..565bd98 100644 (file)
@@ -148,8 +148,7 @@ AVMediaCaptureSource::AVMediaCaptureSource(AVCaptureDeviceTypedef* device, const
     static_assert(static_cast<int>(InterruptionReason::AudioInUse) == AVCaptureSessionInterruptionReasonAudioDeviceInUseByAnotherClient, "InterruptionReason::AudioInUse is not AVCaptureSessionInterruptionReasonAudioDeviceInUseByAnotherClient as expected");
 #endif
     
-    setPersistentID(device.uniqueID);
-    setMuted(true);
+    setPersistentID(String(device.uniqueID));
 }
 
 AVMediaCaptureSource::~AVMediaCaptureSource()
@@ -262,17 +261,6 @@ void AVMediaCaptureSource::setupSession()
     [m_session commitConfiguration];
 }
 
-void AVMediaCaptureSource::reset()
-{
-    RealtimeMediaSource::reset();
-    m_isRunning = false;
-    for (NSString *keyName in sessionKVOProperties())
-        [m_session removeObserver:m_objcObserver.get() forKeyPath:keyName];
-
-    shutdownCaptureSession();
-    m_session = nullptr;
-}
-
 void AVMediaCaptureSource::captureSessionIsRunningDidChange(bool state)
 {
     scheduleDeferredTask([this, state] {
@@ -280,19 +268,10 @@ void AVMediaCaptureSource::captureSessionIsRunningDidChange(bool state)
             return;
 
         m_isRunning = state;
-        if (m_muted == !m_isRunning)
-            return;
-
-        m_muted = !m_isRunning;
-        notifyMutedObservers();
+        notifyMutedChange(!m_isRunning);
     });
 }
 
-bool AVMediaCaptureSource::isProducingData() const
-{
-    return m_isRunning;
-}
-
 #if PLATFORM(IOS)
 void AVMediaCaptureSource::captureSessionRuntimeError(RetainPtr<NSError> error)
 {
index 8af81fb..6728cb1 100644 (file)
@@ -648,8 +648,6 @@ CoreAudioCaptureSource::CoreAudioCaptureSource(const String& deviceID, const Str
     : RealtimeMediaSource(deviceID, RealtimeMediaSource::Type::Audio, label)
     , m_captureDeviceID(persistentID)
 {
-    m_muted = true;
-
     auto& unit = CoreAudioSharedUnit::singleton();
 
     initializeEchoCancellation(unit.enableEchoCancellation());
@@ -680,20 +678,11 @@ void CoreAudioCaptureSource::removeEchoCancellationSource(AudioSampleDataSource&
 
 void CoreAudioCaptureSource::startProducingData()
 {
-    if (m_isProducingData)
-        return;
-
 #if PLATFORM(IOS)
     coreAudioCaptureSourceFactory().setActiveSource(*this);
 #endif
 
     CoreAudioSharedUnit::singleton().startProducingData();
-    m_isProducingData = CoreAudioSharedUnit::singleton().isProducingData();
-
-    if (!m_isProducingData)
-        return;
-
-    m_muted = false;
 
     if (m_audioSourceProvider)
         m_audioSourceProvider->prepare(&CoreAudioSharedUnit::singleton().microphoneFormat().streamDescription());
@@ -701,12 +690,7 @@ void CoreAudioCaptureSource::startProducingData()
 
 void CoreAudioCaptureSource::stopProducingData()
 {
-    if (!m_isProducingData)
-        return;
-
     CoreAudioSharedUnit::singleton().stopProducingData();
-    m_isProducingData = false;
-    m_muted = true;
 
     if (m_audioSourceProvider)
         m_audioSourceProvider->unprepare();
@@ -756,7 +740,7 @@ AudioSourceProvider* CoreAudioCaptureSource::audioSourceProvider()
 {
     if (!m_audioSourceProvider) {
         m_audioSourceProvider = WebAudioSourceProviderAVFObjC::create(*this);
-        if (m_isProducingData)
+        if (isProducingData())
             m_audioSourceProvider->prepare(&CoreAudioSharedUnit::singleton().microphoneFormat().streamDescription());
     }
 
index 81dfd76..263adbd 100644 (file)
@@ -80,7 +80,6 @@ private:
     bool isCaptureSource() const final { return true; }
     void startProducingData() final;
     void stopProducingData() final;
-    bool isProducingData() const final { return m_isProducingData; }
 
     bool applyVolume(double) final { return true; }
     bool applySampleRate(int) final;
@@ -93,7 +92,6 @@ private:
 
     uint32_t m_captureDeviceID { 0 };
 
-    bool m_isProducingData { false };
     bool m_isSuspended { false };
 
     mutable std::optional<RealtimeMediaSourceCapabilities> m_capabilities;
index b0f283b..ec2f408 100644 (file)
@@ -107,13 +107,6 @@ MockRealtimeAudioSourceMac::~MockRealtimeAudioSourceMac()
     }
 }
 
-RefPtr<MockRealtimeAudioSource> MockRealtimeAudioSource::createMuted(const String& name)
-{
-    auto source = adoptRef(new MockRealtimeAudioSource(name));
-    source->m_muted = true;
-    return source;
-}
-
 void MockRealtimeAudioSourceMac::emitSampleBuffers(uint32_t frameCount)
 {
     ASSERT(m_formatDescription);
@@ -158,7 +151,7 @@ void MockRealtimeAudioSourceMac::render(double delta)
         uint32_t bipBopCount = std::min(frameCount, bipBopRemain);
         for (auto& audioBuffer : m_audioBufferList->buffers()) {
             audioBuffer.mDataByteSize = frameCount * m_streamFormat.mBytesPerFrame;
-            if (!m_muted && m_enabled) {
+            if (!muted() && enabled()) {
                 memcpy(audioBuffer.mData, &m_bipBopBuffer[bipBopStart], sizeof(Float32) * bipBopCount);
                 addHum(HumVolume, HumFrequency, sampleRate(), m_samplesRendered, static_cast<float*>(audioBuffer.mData), bipBopCount);
             } else
index ad45656..00b3a7e 100644 (file)
@@ -65,13 +65,6 @@ MockRealtimeVideoSourceMac::MockRealtimeVideoSourceMac(const String& name)
 {
 }
 
-RefPtr<MockRealtimeVideoSource> MockRealtimeVideoSource::createMuted(const String& name)
-{
-    auto source = adoptRef(new MockRealtimeVideoSource(name));
-    source->m_muted = true;
-    return source;
-}
-
 RetainPtr<CMSampleBufferRef> MockRealtimeVideoSourceMac::CMSampleBufferFromPixelBuffer(CVPixelBufferRef pixelBuffer)
 {
     if (!pixelBuffer)
index a4f9b38..ac82c66 100644 (file)
@@ -47,7 +47,7 @@ namespace WebCore {
 Ref<RealtimeIncomingAudioSource> RealtimeIncomingAudioSource::create(rtc::scoped_refptr<webrtc::AudioTrackInterface>&& audioTrack, String&& audioTrackId)
 {
     auto source = adoptRef(*new RealtimeIncomingAudioSource(WTFMove(audioTrack), WTFMove(audioTrackId)));
-    source->startProducingData();
+    source->start();
     return source;
 }
 
@@ -55,6 +55,7 @@ RealtimeIncomingAudioSource::RealtimeIncomingAudioSource(rtc::scoped_refptr<webr
     : RealtimeMediaSource(WTFMove(audioTrackId), RealtimeMediaSource::Type::Audio, String())
     , m_audioTrack(WTFMove(audioTrack))
 {
+    notifyMutedChange(!m_audioTrack);
 }
 
 RealtimeIncomingAudioSource::~RealtimeIncomingAudioSource()
@@ -63,7 +64,7 @@ RealtimeIncomingAudioSource::~RealtimeIncomingAudioSource()
         m_audioSourceProvider->unprepare();
         m_audioSourceProvider = nullptr;
     }
-    stopProducingData();
+    stop();
 }
 
 
@@ -112,20 +113,12 @@ void RealtimeIncomingAudioSource::OnData(const void* audioData, int bitsPerSampl
 
 void RealtimeIncomingAudioSource::startProducingData()
 {
-    if (m_isProducingData)
-        return;
-
-    m_isProducingData = true;
     if (m_audioTrack)
         m_audioTrack->AddSink(this);
 }
 
 void RealtimeIncomingAudioSource::stopProducingData()
 {
-    if (!m_isProducingData)
-        return;
-
-    m_isProducingData = false;
     if (m_audioTrack)
         m_audioTrack->RemoveSink(this);
 }
@@ -136,7 +129,8 @@ void RealtimeIncomingAudioSource::setSourceTrack(rtc::scoped_refptr<webrtc::Audi
     ASSERT(track);
 
     m_audioTrack = WTFMove(track);
-    if (m_isProducingData)
+    notifyMutedChange(!m_audioTrack);
+    if (isProducingData())
         m_audioTrack->AddSink(this);
 }
 
index 852ce97..625e3d9 100644 (file)
@@ -67,14 +67,11 @@ private:
     MediaConstraints& constraints() { return *m_constraints.get(); }
     RealtimeMediaSourceSupportedConstraints& supportedConstraints();
 
-    bool isProducingData() const final { return m_isProducingData; }
-
     AudioSourceProvider* audioSourceProvider() final;
 
     RealtimeMediaSourceSettings m_currentSettings;
     RealtimeMediaSourceSupportedConstraints m_supportedConstraints;
     RefPtr<MediaConstraints> m_constraints;
-    bool m_isProducingData { false };
     rtc::scoped_refptr<webrtc::AudioTrackInterface> m_audioTrack;
 
     RefPtr<WebAudioSourceProviderAVFObjC> m_audioSourceProvider;
index f5096fb..14f8e18 100644 (file)
@@ -58,7 +58,7 @@ Ref<RealtimeIncomingVideoSource> RealtimeIncomingVideoSource::create(rtc::scoped
     PixelBufferConformerCV conformer(conformerOptions.get());
 
     auto source = adoptRef(*new RealtimeIncomingVideoSource(WTFMove(videoTrack), WTFMove(trackId), conformerOptions.get()));
-    source->startProducingData();
+    source->start();
     return source;
 }
 
@@ -67,17 +67,13 @@ RealtimeIncomingVideoSource::RealtimeIncomingVideoSource(rtc::scoped_refptr<webr
     , m_videoTrack(WTFMove(videoTrack))
     , m_conformer(conformerOptions)
 {
-    m_muted = !m_videoTrack;
     m_currentSettings.setWidth(640);
     m_currentSettings.setHeight(480);
+    notifyMutedChange(!m_videoTrack);
 }
 
 void RealtimeIncomingVideoSource::startProducingData()
 {
-    if (m_isProducingData)
-        return;
-
-    m_isProducingData = true;
     if (m_videoTrack)
         m_videoTrack->AddOrUpdateSink(this, rtc::VideoSinkWants());
 }
@@ -87,18 +83,14 @@ void RealtimeIncomingVideoSource::setSourceTrack(rtc::scoped_refptr<webrtc::Vide
     ASSERT(!m_videoTrack);
     ASSERT(track);
 
-    m_muted = false;
-    m_videoTrack = track;
-    if (m_isProducingData)
+    m_videoTrack = WTFMove(track);
+    notifyMutedChange(!m_videoTrack);
+    if (isProducingData())
         m_videoTrack->AddOrUpdateSink(this, rtc::VideoSinkWants());
 }
 
 void RealtimeIncomingVideoSource::stopProducingData()
 {
-    if (!m_isProducingData)
-        return;
-
-    m_isProducingData = false;
     if (m_videoTrack)
         m_videoTrack->RemoveSink(this);
 }
@@ -133,7 +125,7 @@ CVPixelBufferRef RealtimeIncomingVideoSource::pixelBufferFromVideoFrame(const we
 
 void RealtimeIncomingVideoSource::OnFrame(const webrtc::VideoFrame& frame)
 {
-    if (!m_isProducingData)
+    if (!isProducingData())
         return;
 
     auto pixelBuffer = pixelBufferFromVideoFrame(frame);
index 42f926f..d4a3f43 100644 (file)
@@ -66,7 +66,6 @@ private:
 
     void processNewSample(CMSampleBufferRef, unsigned, unsigned, MediaSample::VideoRotation);
 
-    bool isProducingData() const final { return m_isProducingData && m_buffer; }
     bool applySize(const IntSize&) final { return true; }
 
     // rtc::VideoSinkInterface
@@ -78,7 +77,6 @@ private:
     RealtimeMediaSourceSettings m_currentSettings;
     RealtimeMediaSourceSupportedConstraints m_supportedConstraints;
     RefPtr<MediaConstraints> m_constraints;
-    bool m_isProducingData { false };
     rtc::scoped_refptr<webrtc::VideoTrackInterface> m_videoTrack;
     RetainPtr<CMSampleBufferRef> m_buffer;
     PixelBufferConformerCV m_conformer;
index 94ec25e..d3aa968 100644 (file)
@@ -109,7 +109,7 @@ void WebAudioSourceProviderAVFObjC::setClient(AudioSourceProviderClient* client)
     if (m_client && !m_connected) {
         m_connected = true;
         m_captureSource->addObserver(*this);
-        m_captureSource->startProducingData();
+        m_captureSource->start();
     } else if (!m_client && m_connected) {
         m_captureSource->removeObserver(*this);
         m_connected = false;
index 615ec9e..8a58486 100644 (file)
@@ -485,7 +485,7 @@ void MediaEndpointOwr::unmuteRemoteSource(const String& mid, OwrMediaSource* rea
         return;
     }
 
-    if (!remoteSource->stopped())
+    if (remoteSource->isProducingData())
         remoteSource->swapOutShallowSource(*realSource);
 }
 
index 3ae3762..7cfbf78 100644 (file)
@@ -55,7 +55,7 @@ RealtimeMediaSourceOwr(OwrMediaSource* mediaSource, const String& id, RealtimeMe
     , m_mediaSource(mediaSource)
     {
         if (!mediaSource)
-            m_muted = true;
+            notifyMutedChange(true);
     }
 
 RealtimeMediaSourceOwr(const String& id, RealtimeMediaSource::Type type, const String& name)
index c47e75b..375ce7d 100644 (file)
@@ -208,7 +208,7 @@ Ref<RealtimeMediaSource> MockMediaEndpoint::createMutedRemoteSource(const String
     }
 
     m_mutedRemoteSources.set(mid, source);
-    return *source;
+    return source.releaseNonNull();
 }
 
 void MockMediaEndpoint::replaceSendSource(RealtimeMediaSource& newSource, const String& mid)
@@ -334,7 +334,7 @@ void MockMediaEndpoint::unmuteRemoteSourcesByMid()
 
 void MockMediaEndpoint::unmuteTimerFired()
 {
-    RefPtr<RealtimeMediaSource> source = m_mutedRemoteSources.get(m_midsOfSourcesToUnmute.takeLast());
+    auto* source = m_mutedRemoteSources.get(m_midsOfSourcesToUnmute.takeLast());
     if (source)
         source->setMuted(false);
 
index 581be29..c85d9ce 100644 (file)
@@ -65,14 +65,14 @@ CaptureSourceOrError MockRealtimeAudioSource::create(const String& name, const M
 
     return CaptureSourceOrError(WTFMove(source));
 }
+#endif
 
-RefPtr<MockRealtimeAudioSource> MockRealtimeAudioSource::createMuted(const String& name)
+Ref<MockRealtimeAudioSource> MockRealtimeAudioSource::createMuted(const String& name)
 {
-    auto source = adoptRef(new MockRealtimeAudioSource(name));
-    source->m_muted = true;
+    auto source = adoptRef(*new MockRealtimeAudioSource(name));
+    source->notifyMutedChange(true);
     return source;
 }
-#endif
 
 static MockRealtimeAudioSourceFactory& mockAudioCaptureSourceFactory()
 {
@@ -121,11 +121,6 @@ void MockRealtimeAudioSource::initializeSupportedConstraints(RealtimeMediaSource
 
 void MockRealtimeAudioSource::startProducingData()
 {
-    if (m_isProducingData)
-        return;
-
-    m_isProducingData = true;
-
 #if PLATFORM(IOS)
     mockAudioCaptureSourceFactory().setActiveSource(*this);
 #endif
@@ -133,20 +128,12 @@ void MockRealtimeAudioSource::startProducingData()
     if (!sampleRate())
         setSampleRate(!deviceIndex() ? 44100 : 48000);
 
-    MockRealtimeMediaSource::startProducingData();
-
     m_startTime = monotonicallyIncreasingTime();
     m_timer.startRepeating(renderInterval());
 }
 
 void MockRealtimeAudioSource::stopProducingData()
 {
-    if (!m_isProducingData)
-        return;
-
-    m_isProducingData = false;
-
-    MockRealtimeMediaSource::stopProducingData();
     m_timer.stop();
     m_elapsedTime += monotonicallyIncreasingTime() - m_startTime;
     m_startTime = NAN;
index 67ee59e..3a19fa0 100644 (file)
@@ -43,7 +43,7 @@ class MockRealtimeAudioSource : public MockRealtimeMediaSource {
 public:
 
     static CaptureSourceOrError create(const String&, const MediaConstraints*);
-    static RefPtr<MockRealtimeAudioSource> createMuted(const String& name);
+    static Ref<MockRealtimeAudioSource> createMuted(const String& name);
 
     static AudioCaptureFactory& factory();
 
@@ -54,7 +54,6 @@ protected:
 
     void startProducingData() final;
     void stopProducingData() final;
-    bool isProducingData() const final { return m_isProducingData; }
 
     virtual void render(double) { }
 
@@ -80,7 +79,6 @@ private:
     double m_startTime { NAN };
     double m_lastRenderTime { NAN };
     double m_elapsedTime { 0 };
-    bool m_isProducingData { false };
 };
 
 } // namespace WebCore
index 76723ae..440bb98 100644 (file)
@@ -80,11 +80,11 @@ MockRealtimeMediaSource::MockRealtimeMediaSource(const String& id, RealtimeMedia
     switch (type) {
     case RealtimeMediaSource::Type::Audio:
         m_deviceIndex = name == audioDevices()[0].label() ? 0 : 1;
-        setPersistentID(audioDevices()[m_deviceIndex].persistentId());
+        setPersistentID(String(audioDevices()[m_deviceIndex].persistentId()));
         return;
     case RealtimeMediaSource::Type::Video:
         m_deviceIndex = name == videoDevices()[0].label() ? 0 : 1;
-        setPersistentID(videoDevices()[m_deviceIndex].persistentId());
+        setPersistentID(String(videoDevices()[m_deviceIndex].persistentId()));
         return;
     case RealtimeMediaSource::Type::None:
         ASSERT_NOT_REACHED();
@@ -132,18 +132,6 @@ RealtimeMediaSourceSupportedConstraints& MockRealtimeMediaSource::supportedConst
     return m_supportedConstraints;
 }
 
-void MockRealtimeMediaSource::startProducingData()
-{
-    m_isProducingData = true;
-    setMuted(false);
-}
-
-void MockRealtimeMediaSource::stopProducingData()
-{
-    m_isProducingData = false;
-    setMuted(true);
-}
-
 } // namespace WebCore
 
 #endif // ENABLE(MEDIA_STREAM)
index 9a5ad1d..506e482 100644 (file)
@@ -65,9 +65,6 @@ protected:
     virtual void initializeSupportedConstraints(RealtimeMediaSourceSupportedConstraints&) = 0;
 #endif
 
-    void startProducingData() override;
-    void stopProducingData() override;
-
     const RealtimeMediaSourceCapabilities& capabilities() const override;
     const RealtimeMediaSourceSettings& settings() const override;
 
@@ -84,14 +81,11 @@ private:
     void initializeSettings();
 #endif
 
-    bool isProducingData() const override { return m_isProducingData; }
-
     RealtimeMediaSourceSettings m_currentSettings;
     RealtimeMediaSourceSupportedConstraints m_supportedConstraints;
     std::unique_ptr<RealtimeMediaSourceCapabilities> m_capabilities;
     RefPtr<MediaConstraints> m_constraints;
     unsigned m_deviceIndex { 0 };
-    bool m_isProducingData { false };
 };
 
 } // namespace WebCore
index 0f17919..2ad7ab3 100644 (file)
@@ -72,14 +72,14 @@ CaptureSourceOrError MockRealtimeVideoSource::create(const String& name, const M
 
     return CaptureSourceOrError(WTFMove(source));
 }
+#endif
 
-RefPtr<MockRealtimeVideoSource> MockRealtimeVideoSource::createMuted(const String& name)
+Ref<MockRealtimeVideoSource> MockRealtimeVideoSource::createMuted(const String& name)
 {
-    auto source = adoptRef(new MockRealtimeVideoSource(name));
-    source->m_muted = true;
+    auto source = adoptRef(*new MockRealtimeVideoSource(name));
+    source->notifyMutedChange(true);
     return source;
 }
-#endif
 
 static MockRealtimeVideoSourceFactory& mockVideoCaptureSourceFactory()
 {
@@ -112,16 +112,10 @@ MockRealtimeVideoSource::~MockRealtimeVideoSource()
 
 void MockRealtimeVideoSource::startProducingData()
 {
-    if (m_isProducingData)
-        return;
-    
-    m_isProducingData = true;
-    
 #if PLATFORM(IOS)
     mockVideoCaptureSourceFactory().setActiveSource(*this);
 #endif
 
-    MockRealtimeMediaSource::startProducingData();
     if (size().isEmpty()) {
         setWidth(640);
         setHeight(480);
@@ -133,12 +127,6 @@ void MockRealtimeVideoSource::startProducingData()
 
 void MockRealtimeVideoSource::stopProducingData()
 {
-    if (!m_isProducingData)
-        return;
-    
-    m_isProducingData = false;
-    
-    MockRealtimeMediaSource::stopProducingData();
     m_timer.stop();
     m_elapsedTime += monotonicallyIncreasingTime() - m_startTime;
     m_startTime = NAN;
@@ -384,7 +372,7 @@ void MockRealtimeVideoSource::generateFrame()
     FloatRect frameRect(FloatPoint(), size);
     context.fillRect(FloatRect(FloatPoint(), size), !deviceIndex() ? Color::black : Color::darkGray);
 
-    if (!m_muted && m_enabled) {
+    if (!muted() && enabled()) {
         drawText(context);
         drawAnimation(context);
         drawBoxes(context);
index c439add..c7568e2 100644 (file)
@@ -47,7 +47,7 @@ class MockRealtimeVideoSource : public MockRealtimeMediaSource {
 public:
 
     static CaptureSourceOrError create(const String&, const MediaConstraints*);
-    static RefPtr<MockRealtimeVideoSource> createMuted(const String& name);
+    static Ref<MockRealtimeVideoSource> createMuted(const String& name);
 
     static VideoCaptureFactory& factory();
 
@@ -69,7 +69,6 @@ private:
 
     void startProducingData() final;
     void stopProducingData() final;
-    bool isProducingData() const final { return m_isProducingData; }
 
     void drawAnimation(GraphicsContext&);
     void drawText(GraphicsContext&);
@@ -103,7 +102,6 @@ private:
     unsigned m_frameNumber { 0 };
 
     RunLoop::Timer<MockRealtimeVideoSource> m_timer;
-    bool m_isProducingData { false };
 };
 
 } // namespace WebCore
index 9b3faf1..f3a6df4 100644 (file)
@@ -1,3 +1,15 @@
+2017-05-15  Youenn Fablet  <youenn@apple.com>
+
+        Simplify RealtimeMediaSource data production and state
+        https://bugs.webkit.org/show_bug.cgi?id=171999
+
+        Reviewed by Eric Carlson.
+
+        * UIProcess/Cocoa/UserMediaCaptureManagerProxy.cpp:
+        (WebKit::UserMediaCaptureManagerProxy::startProducingData):
+        (WebKit::UserMediaCaptureManagerProxy::stopProducingData):
+        * WebProcess/cocoa/UserMediaCaptureManager.cpp:
+
 2017-05-15  Brent Fulgham  <bfulgham@apple.com>
 
         Correct typo (part of r216790).
index 6cdba1f..ee812d9 100644 (file)
@@ -154,14 +154,14 @@ void UserMediaCaptureManagerProxy::startProducingData(uint64_t id)
 {
     auto iter = m_proxies.find(id);
     if (iter != m_proxies.end())
-        iter->value->source().startProducingData();
+        iter->value->source().start();
 }
 
 void UserMediaCaptureManagerProxy::stopProducingData(uint64_t id)
 {
     auto iter = m_proxies.find(id);
     if (iter != m_proxies.end())
-        iter->value->source().stopProducingData();
+        iter->value->source().stop();
 }
 
 void UserMediaCaptureManagerProxy::capabilities(uint64_t id, WebCore::RealtimeMediaSourceCapabilities& capabilities)
index 3e35c27..8d56cb2 100644 (file)
@@ -110,8 +110,7 @@ public:
         WebAudioBufferList audioData(m_description, numberOfFrames);
         m_ringBuffer.fetch(audioData.list(), numberOfFrames, time.timeValue());
 
-        for (auto* observer : observers())
-            observer->audioSamplesAvailable(time, audioData, m_description, numberOfFrames);
+        RealtimeMediaSource::audioSamplesAvailable(time, audioData, m_description, numberOfFrames);
     }
 
     void applyConstraintsSucceeded(const WebCore::RealtimeMediaSourceSettings& settings)
@@ -127,24 +126,6 @@ public:
         callbacks.failureHandler(failedConstraint, errorMessage);
     }
 
-    void setMuted(bool muted) final
-    {
-        if (m_muted == muted)
-            return;
-
-        m_muted = muted;
-        m_manager.setMuted(m_id, m_muted);
-    }
-
-    void setEnabled(bool enabled) final
-    {
-        if (m_enabled == enabled)
-            return;
-
-        m_enabled = enabled;
-        m_manager.setEnabled(m_id, m_enabled);
-    }
-
 private:
     void startProducingData() final { m_manager.startProducingData(m_id); }
     void stopProducingData() final { m_manager.stopProducingData(m_id); }