[MediaStream] A RealtimeMediaSource should begin producing data automatically
authoreric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 Nov 2015 18:55:07 +0000 (18:55 +0000)
committereric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 Nov 2015 18:55:07 +0000 (18:55 +0000)
https://bugs.webkit.org/show_bug.cgi?id=150851
rdar://problem/23380636

A RealtimeMediaSource should be producing data unless it is muted, which is not under the
control of the application, so a local source should begin producing data as soon as it
is added to a stream. Remove "producing data" and "enabled" observer callbacks because
they don't provide anything that the "muted" callback already provides.

Reviewed by Jer Noble.

* Modules/mediastream/MediaStreamTrack.cpp:
(WebCore::MediaStreamTrack::trackProducingDataChanged): Deleted.
* Modules/mediastream/MediaStreamTrack.h:

* Modules/mediastream/UserMediaRequest.cpp:
(WebCore::UserMediaRequest::didCreateStream): Tell sources to begin producing data.

* platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm:
(WebCore::MediaPlayerPrivateMediaStreamAVFObjC::load): Don't call stream->startProducingData,
  it isn't necessary.
(WebCore::MediaPlayerPrivateMediaStreamAVFObjC::setReadyState): Call characteristicsChanged
  when the readyState changes.

* platform/mediastream/MediaStreamPrivate.cpp:
(WebCore::MediaStreamPrivate::trackProducingDataChanged): Deleted.
* platform/mediastream/MediaStreamPrivate.h:

* platform/mediastream/MediaStreamTrackPrivate.cpp:
(WebCore::MediaStreamTrackPrivate::sourceProducingDataChanged): Deleted.
(WebCore::MediaStreamTrackPrivate::sourceEnabledChanged): Deleted.
* platform/mediastream/MediaStreamTrackPrivate.h:

* platform/mediastream/RealtimeMediaSource.cpp:
(WebCore::RealtimeMediaSource::isProducingDataDidChange): Deleted.
(WebCore::RealtimeMediaSource::setEnabled): Deleted.
* platform/mediastream/RealtimeMediaSource.h:

* platform/mediastream/mac/AVAudioCaptureSource.mm:
(WebCore::AVAudioCaptureSource::captureOutputDidOutputSampleBufferFromConnection): !enabled() -> muted().

* platform/mediastream/mac/AVMediaCaptureSource.mm:
(WebCore::AVMediaCaptureSource::captureSessionIsRunningDidChange): Don't call isProducingDataDidChange..

* platform/mediastream/mac/AVVideoCaptureSource.mm:
(WebCore::AVVideoCaptureSource::processNewFrame): !enabled() -> muted().

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

14 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Modules/mediastream/MediaStreamTrack.cpp
Source/WebCore/Modules/mediastream/MediaStreamTrack.h
Source/WebCore/Modules/mediastream/UserMediaRequest.cpp
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm
Source/WebCore/platform/mediastream/MediaStreamPrivate.cpp
Source/WebCore/platform/mediastream/MediaStreamPrivate.h
Source/WebCore/platform/mediastream/MediaStreamTrackPrivate.cpp
Source/WebCore/platform/mediastream/MediaStreamTrackPrivate.h
Source/WebCore/platform/mediastream/RealtimeMediaSource.cpp
Source/WebCore/platform/mediastream/RealtimeMediaSource.h
Source/WebCore/platform/mediastream/mac/AVAudioCaptureSource.mm
Source/WebCore/platform/mediastream/mac/AVMediaCaptureSource.mm
Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.mm

index fd4b148..f56b488 100644 (file)
@@ -1,3 +1,52 @@
+2015-11-04  Eric Carlson  <eric.carlson@apple.com>
+
+        [MediaStream] A RealtimeMediaSource should begin producing data automatically
+        https://bugs.webkit.org/show_bug.cgi?id=150851
+        rdar://problem/23380636
+
+        A RealtimeMediaSource should be producing data unless it is muted, which is not under the 
+        control of the application, so a local source should begin producing data as soon as it
+        is added to a stream. Remove "producing data" and "enabled" observer callbacks because 
+        they don't provide anything that the "muted" callback already provides.
+        
+        Reviewed by Jer Noble.
+
+        * Modules/mediastream/MediaStreamTrack.cpp:
+        (WebCore::MediaStreamTrack::trackProducingDataChanged): Deleted.
+        * Modules/mediastream/MediaStreamTrack.h:
+
+        * Modules/mediastream/UserMediaRequest.cpp:
+        (WebCore::UserMediaRequest::didCreateStream): Tell sources to begin producing data.
+
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm:
+        (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::load): Don't call stream->startProducingData,
+          it isn't necessary.
+        (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::setReadyState): Call characteristicsChanged 
+          when the readyState changes.
+
+        * platform/mediastream/MediaStreamPrivate.cpp:
+        (WebCore::MediaStreamPrivate::trackProducingDataChanged): Deleted.
+        * platform/mediastream/MediaStreamPrivate.h:
+
+        * platform/mediastream/MediaStreamTrackPrivate.cpp:
+        (WebCore::MediaStreamTrackPrivate::sourceProducingDataChanged): Deleted.
+        (WebCore::MediaStreamTrackPrivate::sourceEnabledChanged): Deleted.
+        * platform/mediastream/MediaStreamTrackPrivate.h:
+
+        * platform/mediastream/RealtimeMediaSource.cpp:
+        (WebCore::RealtimeMediaSource::isProducingDataDidChange): Deleted.
+        (WebCore::RealtimeMediaSource::setEnabled): Deleted.
+        * platform/mediastream/RealtimeMediaSource.h:
+
+        * platform/mediastream/mac/AVAudioCaptureSource.mm:
+        (WebCore::AVAudioCaptureSource::captureOutputDidOutputSampleBufferFromConnection): !enabled() -> muted().
+
+        * platform/mediastream/mac/AVMediaCaptureSource.mm:
+        (WebCore::AVMediaCaptureSource::captureSessionIsRunningDidChange): Don't call isProducingDataDidChange..
+
+        * platform/mediastream/mac/AVVideoCaptureSource.mm:
+        (WebCore::AVVideoCaptureSource::processNewFrame): !enabled() -> muted().
+
 2015-11-04  Jer Noble  <jer.noble@apple.com>
 
         [iOS] <video> elements without audio tracks should not interrupt music
index df896f9..319f836 100644 (file)
@@ -233,11 +233,6 @@ void MediaStreamTrack::trackStatesChanged(MediaStreamTrackPrivate&)
     configureTrackRendering();
 }
 
-void MediaStreamTrack::trackProducingDataChanged(MediaStreamTrackPrivate&)
-{
-    configureTrackRendering();
-}
-
 void MediaStreamTrack::trackEnabledChanged(MediaStreamTrackPrivate&)
 {
     configureTrackRendering();
index d9f2d27..aa08803 100644 (file)
@@ -118,7 +118,6 @@ private:
     void trackEnded(MediaStreamTrackPrivate&) override;
     void trackMutedChanged(MediaStreamTrackPrivate&) override;
     void trackStatesChanged(MediaStreamTrackPrivate&) override;
-    void trackProducingDataChanged(MediaStreamTrackPrivate&) override;
     void trackEnabledChanged(MediaStreamTrackPrivate&) override;
 
     Vector<Observer*> m_observers;
index d3fc3bf..4532365 100644 (file)
@@ -165,12 +165,16 @@ void UserMediaRequest::didCreateStream(PassRefPtr<MediaStreamPrivate> privateStr
     // 4 - Create the MediaStream and pass it to the success callback.
     RefPtr<MediaStream> stream = MediaStream::create(*m_scriptExecutionContext, privateStream);
     if (m_audioConstraints) {
-        for (auto& track : stream->getAudioTracks())
+        for (auto& track : stream->getAudioTracks()) {
             track->applyConstraints(*m_audioConstraints);
+            track->source()->startProducingData();
+        }
     }
     if (m_videoConstraints) {
-        for (auto& track : stream->getVideoTracks())
+        for (auto& track : stream->getVideoTracks()) {
             track->applyConstraints(*m_videoConstraints);
+            track->source()->startProducingData();
+        }
     }
 
     m_promise.resolve(stream);
index e52de69..f580e3e 100644 (file)
@@ -122,7 +122,6 @@ void MediaPlayerPrivateMediaStreamAVFObjC::load(MediaStreamPrivate& stream)
 
     m_mediaStreamPrivate = &stream;
     m_mediaStreamPrivate->addObserver(*this);
-    m_mediaStreamPrivate->startProducingData();
 
     m_previewLayer = nullptr;
     m_ended = !m_mediaStreamPrivate->active();
@@ -453,6 +452,7 @@ void MediaPlayerPrivateMediaStreamAVFObjC::setReadyState(MediaPlayer::ReadyState
         return;
 
     m_readyState = readyState;
+    characteristicsChanged();
 
     m_player->readyStateChanged();
 }
index 8c17880..b053c42 100644 (file)
@@ -273,13 +273,6 @@ void MediaStreamPrivate::trackEnabledChanged(MediaStreamTrackPrivate&)
     });
 }
 
-void MediaStreamPrivate::trackProducingDataChanged(MediaStreamTrackPrivate&)
-{
-    scheduleDeferredTask([this] {
-        characteristicsChanged();
-    });
-}
-
 void MediaStreamPrivate::scheduleDeferredTask(std::function<void()> function)
 {
     ASSERT(function);
index 60e7ba1..3d50e35 100644 (file)
@@ -103,7 +103,6 @@ private:
     void trackEnded(MediaStreamTrackPrivate&) override { }
     void trackMutedChanged(MediaStreamTrackPrivate&) override;
     void trackStatesChanged(MediaStreamTrackPrivate&) override;
-    void trackProducingDataChanged(MediaStreamTrackPrivate&) override;
     void trackEnabledChanged(MediaStreamTrackPrivate&) override;
 
     void characteristicsChanged();
index 6ecb325..6969117 100644 (file)
@@ -178,18 +178,6 @@ void MediaStreamTrackPrivate::sourceStatesChanged()
         observer->trackStatesChanged(*this);
 }
 
-void MediaStreamTrackPrivate::sourceProducingDataChanged()
-{
-    for (auto& observer : m_observers)
-        observer->trackProducingDataChanged(*this);
-}
-
-void MediaStreamTrackPrivate::sourceEnabledChanged()
-{
-    for (auto& observer : m_observers)
-        observer->trackEnabledChanged(*this);
-}
-
 bool MediaStreamTrackPrivate::preventSourceFromStopping()
 {
     return !m_isEnded;
index f7dbea6..c7294d2 100644 (file)
@@ -48,7 +48,6 @@ public:
         virtual void trackEnded(MediaStreamTrackPrivate&) = 0;
         virtual void trackMutedChanged(MediaStreamTrackPrivate&) = 0;
         virtual void trackStatesChanged(MediaStreamTrackPrivate&) = 0;
-        virtual void trackProducingDataChanged(MediaStreamTrackPrivate&) = 0;
         virtual void trackEnabledChanged(MediaStreamTrackPrivate&) = 0;
     };
     
@@ -101,9 +100,7 @@ private:
     void sourceStopped() override final;
     void sourceMutedChanged() override final;
     void sourceStatesChanged() override final;
-    void sourceProducingDataChanged() override final;
     bool preventSourceFromStopping() override final;
-    void sourceEnabledChanged() override final;
 
     Vector<Observer*> m_observers;
     RefPtr<RealtimeMediaSource> m_source;
index 51d915c..ee2182d 100644 (file)
@@ -101,22 +101,6 @@ void RealtimeMediaSource::statesDidChanged()
         observer->sourceStatesChanged();
 }
 
-void RealtimeMediaSource::isProducingDataDidChange()
-{
-    for (auto& observer : m_observers)
-        observer->sourceProducingDataChanged();
-}
-
-void RealtimeMediaSource::setEnabled(bool enabled)
-{
-    if (m_enabled == enabled)
-        return;
-
-    m_enabled = enabled;
-    for (auto& observer : m_observers)
-        observer->sourceEnabledChanged();
-}
-
 bool RealtimeMediaSource::readonly() const
 {
     return m_readonly;
index 4b50063..818fe8c 100644 (file)
@@ -63,8 +63,6 @@ public:
         virtual void sourceStopped() = 0;
         virtual void sourceMutedChanged() = 0;
         virtual void sourceStatesChanged() = 0;
-        virtual void sourceProducingDataChanged() = 0;
-        virtual void sourceEnabledChanged() = 0;
 
         // Observer state queries.
         virtual bool preventSourceFromStopping() = 0;
@@ -101,16 +99,12 @@ public:
     virtual bool remote() const { return m_remote; }
     virtual void setRemote(bool remote) { m_remote = remote; }
 
-    virtual void setEnabled(bool);
-    virtual bool enabled() const { return m_enabled; }
-
     void addObserver(Observer*);
     void removeObserver(Observer*);
 
     virtual void startProducingData() { }
     virtual void stopProducingData() { }
     virtual bool isProducingData() const { return false; }
-    virtual void isProducingDataDidChange();
 
     void stop(Observer* callingObserver = nullptr);
     void requestStop(Observer* callingObserver = nullptr);
@@ -137,7 +131,6 @@ private:
     bool m_muted;
     bool m_readonly;
     bool m_remote;
-    bool m_enabled { true };
     
     unsigned m_fitnessScore;
 };
index b279cb8..f199204 100644 (file)
@@ -164,7 +164,7 @@ static bool operator!=(const AudioStreamBasicDescription& a, const AudioStreamBa
 
 void AVAudioCaptureSource::captureOutputDidOutputSampleBufferFromConnection(AVCaptureOutputType*, CMSampleBufferRef sampleBuffer, AVCaptureConnectionType*)
 {
-    if (!enabled())
+    if (muted())
         return;
 
     CMFormatDescriptionRef formatDescription = CMSampleBufferGetFormatDescription(sampleBuffer);
index 8474c1c..ca74774 100644 (file)
@@ -210,7 +210,6 @@ void AVMediaCaptureSource::captureSessionIsRunningDidChange(bool state)
             return;
 
         m_isRunning = state;
-        isProducingDataDidChange();
     });
 }
 
index cb1cb3b..333d752 100644 (file)
@@ -278,7 +278,7 @@ void AVVideoCaptureSource::processNewFrame(RetainPtr<CMSampleBufferRef> sampleBu
 {
     // Ignore frames delivered when the session is not running, we want to hang onto the last image
     // delivered before it stopped.
-    if (m_lastImage && (!isProducingData() || !enabled()))
+    if (m_lastImage && (!isProducingData() || muted()))
         return;
 
     CMFormatDescriptionRef formatDescription = CMSampleBufferGetFormatDescription(sampleBuffer.get());