Local audio-only stream will not trigger playback to begin
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 21 Feb 2017 02:35:35 +0000 (02:35 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 21 Feb 2017 02:35:35 +0000 (02:35 +0000)
https://bugs.webkit.org/show_bug.cgi?id=168412

Reviewed by Youenn Fablet.

Source/WebCore:

Test: fast/mediastream/local-audio-playing-event.html

With video-bearing streams, the first video sample emitted from the stream causes the
readyState to move from HAVE_NOTHING to HAVE_ENOUGH_DATA. Wire up this same behavior for
audio-bearing streams. Add a MediaStreamTrackPrivate::Observer callback method
audioSamplesAvailable(), which gets passed up to MediaPlayerPrivateMediaStreamAVFObjC.
Because this callback may be (and probably will be) called on a background thread, run the
updateReadyState() task in a scheduledDeferredTask().

* platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h:
* platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm:
(WebCore::MediaPlayerPrivateMediaStreamAVFObjC::audioSamplesAvailable):
(WebCore::MediaPlayerPrivateMediaStreamAVFObjC::updateTracks):
* platform/mediastream/MediaStreamTrackPrivate.cpp:
(WebCore::MediaStreamTrackPrivate::audioSamplesAvailable):
* platform/mediastream/MediaStreamTrackPrivate.h:
(WebCore::MediaStreamTrackPrivate::Observer::audioSamplesAvailable):

LayoutTests:

* fast/mediastream/local-audio-playing-event-expected.txt: Added.
* fast/mediastream/local-audio-playing-event.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/mediastream/local-audio-playing-event-expected.txt [new file with mode: 0644]
LayoutTests/fast/mediastream/local-audio-playing-event.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm
Source/WebCore/platform/mediastream/MediaStreamTrackPrivate.cpp
Source/WebCore/platform/mediastream/MediaStreamTrackPrivate.h

index bc2cb40..4f51065 100644 (file)
@@ -1,3 +1,13 @@
+2017-02-20  Jer Noble  <jer.noble@apple.com>
+
+        Local audio-only stream will not trigger playback to begin
+        https://bugs.webkit.org/show_bug.cgi?id=168412
+
+        Reviewed by Youenn Fablet.
+
+        * fast/mediastream/local-audio-playing-event-expected.txt: Added.
+        * fast/mediastream/local-audio-playing-event.html: Added.
+
 2017-02-20  Zalan Bujtas  <zalan@apple.com>
 
         Simple line layout: Implement absoluteQuadsForRange.
diff --git a/LayoutTests/fast/mediastream/local-audio-playing-event-expected.txt b/LayoutTests/fast/mediastream/local-audio-playing-event-expected.txt
new file mode 100644 (file)
index 0000000..714564f
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Local audio playback fires playing event 
+
diff --git a/LayoutTests/fast/mediastream/local-audio-playing-event.html b/LayoutTests/fast/mediastream/local-audio-playing-event.html
new file mode 100644 (file)
index 0000000..ac7bb30
--- /dev/null
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <meta charset="utf-8">
+    <title>Testing local audio capture playback causes "playing" event to fire</title>
+    <script src="../../resources/testharness.js"></script>
+    <script src="../../resources/testharnessreport.js"></script>
+</head>
+<body>
+    <audio id="audio" autoplay></audio>
+    <script>
+    if (window.testRunner)
+        testRunner.setUserMediaPermission(true);
+
+    var audio = document.getElementById('audio');
+
+    promise_test((test) => {
+        return navigator.mediaDevices.getUserMedia({audio: true}).then((stream) => {
+            audio.srcObject = stream;
+            var eventWatcher = new EventWatcher(test, audio, 'playing');
+            return eventWatcher.wait_for('playing');
+        });
+    }, 'Local audio playback fires playing event');
+    </script>
+</body>
+</html>
index 1117385..0156329 100644 (file)
@@ -1,3 +1,28 @@
+2017-02-20  Jer Noble  <jer.noble@apple.com>
+
+        Local audio-only stream will not trigger playback to begin
+        https://bugs.webkit.org/show_bug.cgi?id=168412
+
+        Reviewed by Youenn Fablet.
+
+        Test: fast/mediastream/local-audio-playing-event.html
+
+        With video-bearing streams, the first video sample emitted from the stream causes the
+        readyState to move from HAVE_NOTHING to HAVE_ENOUGH_DATA. Wire up this same behavior for
+        audio-bearing streams. Add a MediaStreamTrackPrivate::Observer callback method
+        audioSamplesAvailable(), which gets passed up to MediaPlayerPrivateMediaStreamAVFObjC.
+        Because this callback may be (and probably will be) called on a background thread, run the
+        updateReadyState() task in a scheduledDeferredTask().
+
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h:
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm:
+        (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::audioSamplesAvailable):
+        (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::updateTracks):
+        * platform/mediastream/MediaStreamTrackPrivate.cpp:
+        (WebCore::MediaStreamTrackPrivate::audioSamplesAvailable):
+        * platform/mediastream/MediaStreamTrackPrivate.h:
+        (WebCore::MediaStreamTrackPrivate::Observer::audioSamplesAvailable):
+
 2017-02-20  Zalan Bujtas  <zalan@apple.com>
 
         Simple line layout: Implement absoluteQuadsForRange.
index 4da92b2..c669e72 100644 (file)
@@ -190,6 +190,7 @@ private:
     void trackSettingsChanged(MediaStreamTrackPrivate&) override { };
     void trackEnabledChanged(MediaStreamTrackPrivate&) override { };
     void sampleBufferUpdated(MediaStreamTrackPrivate&, MediaSample&) override;
+    void audioSamplesAvailable(MediaStreamTrackPrivate&) override;
 
 #if PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE)
     void setVideoFullscreenLayer(PlatformLayer*, std::function<void()> completionHandler) override;
index 89a6c0d..ff59e68 100644 (file)
@@ -753,6 +753,17 @@ void MediaPlayerPrivateMediaStreamAVFObjC::sampleBufferUpdated(MediaStreamTrackP
     }
 }
 
+void MediaPlayerPrivateMediaStreamAVFObjC::audioSamplesAvailable(MediaStreamTrackPrivate&)
+{
+    if (m_hasReceivedMedia)
+        return;
+    m_hasReceivedMedia = true;
+
+    scheduleDeferredTask([this] {
+        updateReadyState();
+    });
+}
+
 #if PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE)
 void MediaPlayerPrivateMediaStreamAVFObjC::setVideoFullscreenLayer(PlatformLayer *videoFullscreenLayer, std::function<void()> completionHandler)
 {
@@ -851,6 +862,7 @@ void MediaPlayerPrivateMediaStreamAVFObjC::updateTracks()
             m_player->removeAudioTrack(*track);
             break;
         case TrackState::Add:
+            track->streamTrack().addObserver(*this);
             m_player->addAudioTrack(*track);
             break;
         case TrackState::Configure:
index 736c6f4..9936002 100644 (file)
@@ -213,6 +213,12 @@ void MediaStreamTrackPrivate::videoSampleAvailable(MediaSample& mediaSample)
         observer->sampleBufferUpdated(*this, mediaSample);
 }
 
+void MediaStreamTrackPrivate::audioSamplesAvailable(const MediaTime&, const PlatformAudioData&, const AudioStreamDescription&, size_t)
+{
+    for (auto& observer : m_observers)
+        observer->audioSamplesAvailable(*this);
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(MEDIA_STREAM)
index ca0d7c1..cf9b591 100644 (file)
@@ -48,6 +48,7 @@ public:
         virtual void trackSettingsChanged(MediaStreamTrackPrivate&) = 0;
         virtual void trackEnabledChanged(MediaStreamTrackPrivate&) = 0;
         virtual void sampleBufferUpdated(MediaStreamTrackPrivate&, MediaSample&) { };
+        virtual void audioSamplesAvailable(MediaStreamTrackPrivate&) { };
     };
 
     static Ref<MediaStreamTrackPrivate> create(Ref<RealtimeMediaSource>&&);
@@ -102,6 +103,7 @@ private:
     void sourceSettingsChanged() final;
     bool preventSourceFromStopping() final;
     void videoSampleAvailable(MediaSample&) final;
+    void audioSamplesAvailable(const MediaTime&, const PlatformAudioData&, const AudioStreamDescription&, size_t) final;
 
     Vector<Observer*> m_observers;
     Ref<RealtimeMediaSource> m_source;