[MSE] Add per-track signalling between SourceBuffer and SourceBufferPrivate.
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 18 Dec 2013 06:49:50 +0000 (06:49 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 18 Dec 2013 06:49:50 +0000 (06:49 +0000)
https://bugs.webkit.org/show_bug.cgi?id=125899

Reviewed by Eric Carlson.

To accommodate the future addition of audio support to MSE in the Mac
port, add the concept of trackIDs to the communication between
SourceBuffer and SourceBufferPrivate.

The following virtual methods  now take a trackID parameter:
* platform/graphics/SourceBufferPrivate.h:
(WebCore::SourceBufferPrivate::isReadyForMoreSamples):
(WebCore::SourceBufferPrivate::stopAskingForMoreSamples):
(WebCore::SourceBufferPrivate::notifyClientWhenReadyForMoreSamples):
* platform/graphics/SourceBufferPrivateClient.h:
(WebCore::SourceBufferPrivateClient::sourceBufferPrivateDidBecomeReadyForMoreSamples):

Update overridden methods in subclasses:
* Modules/mediasource/SourceBuffer.cpp:
(WebCore::SourceBuffer::sourceBufferPrivateDidBecomeReadyForMoreSamples):
* Modules/mediasource/SourceBuffer.h:
* platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h:
* platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm:
(WebCore::SourceBufferPrivateAVFObjC::trackDidChangeEnabled):
(WebCore::SourceBufferPrivateAVFObjC::isReadyForMoreSamples):
* platform/mock/mediasource/MockSourceBufferPrivate.h:

Change the logic in provideMediaData to update a single TrackBuffer
rather than iterating over all of them:
* Modules/mediasource/SourceBuffer.cpp:
(WebCore::SourceBuffer::sourceBufferPrivateSeekToTime):
(WebCore::SourceBuffer::appendBufferTimerFired):
(WebCore::SourceBuffer::provideMediaData):

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

Source/WebCore/ChangeLog
Source/WebCore/Modules/mediasource/SourceBuffer.cpp
Source/WebCore/Modules/mediasource/SourceBuffer.h
Source/WebCore/platform/graphics/SourceBufferPrivate.h
Source/WebCore/platform/graphics/SourceBufferPrivateClient.h
Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h
Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm
Source/WebCore/platform/mock/mediasource/MockSourceBufferPrivate.h

index 25179a1..c7f9fb8 100644 (file)
@@ -1,3 +1,39 @@
+2013-12-17  Jer Noble  <jer.noble@apple.com>
+
+        [MSE] Add per-track signalling between SourceBuffer and SourceBufferPrivate.
+        https://bugs.webkit.org/show_bug.cgi?id=125899
+
+        Reviewed by Eric Carlson.
+
+        To accommodate the future addition of audio support to MSE in the Mac
+        port, add the concept of trackIDs to the communication between
+        SourceBuffer and SourceBufferPrivate.
+
+        The following virtual methods  now take a trackID parameter:
+        * platform/graphics/SourceBufferPrivate.h:
+        (WebCore::SourceBufferPrivate::isReadyForMoreSamples):
+        (WebCore::SourceBufferPrivate::stopAskingForMoreSamples):
+        (WebCore::SourceBufferPrivate::notifyClientWhenReadyForMoreSamples):
+        * platform/graphics/SourceBufferPrivateClient.h:
+        (WebCore::SourceBufferPrivateClient::sourceBufferPrivateDidBecomeReadyForMoreSamples):
+
+        Update overridden methods in subclasses:
+        * Modules/mediasource/SourceBuffer.cpp:
+        (WebCore::SourceBuffer::sourceBufferPrivateDidBecomeReadyForMoreSamples):
+        * Modules/mediasource/SourceBuffer.h:
+        * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h:
+        * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm:
+        (WebCore::SourceBufferPrivateAVFObjC::trackDidChangeEnabled):
+        (WebCore::SourceBufferPrivateAVFObjC::isReadyForMoreSamples):
+        * platform/mock/mediasource/MockSourceBufferPrivate.h:
+
+        Change the logic in provideMediaData to update a single TrackBuffer
+        rather than iterating over all of them:
+        * Modules/mediasource/SourceBuffer.cpp:
+        (WebCore::SourceBuffer::sourceBufferPrivateSeekToTime):
+        (WebCore::SourceBuffer::appendBufferTimerFired):
+        (WebCore::SourceBuffer::provideMediaData):
+
 2013-12-17  Joseph Pecoraro  <pecoraro@apple.com>
 
         Web Inspector: Remove InspectorAgent::hasFrontend
index 532e9b0..e5049ed 100644 (file)
@@ -286,9 +286,9 @@ void SourceBuffer::sourceBufferPrivateSeekToTime(SourceBufferPrivate*, const Med
         trackBuffer.decodeQueue.clear();
         for (auto iter = currentSampleDTSIterator; iter != trackBuffer.samples.decodeEnd(); ++iter)
             trackBuffer.decodeQueue.insert(*iter);
-    }
 
-    provideMediaData();   
+        provideMediaData(trackBuffer, trackID);
+    }
 }
 
 MediaTime SourceBuffer::sourceBufferPrivateFastSeekTimeForMediaTime(SourceBufferPrivate*, const MediaTime& targetTime, const MediaTime& negativeThreshold, const MediaTime& positiveThreshold)
@@ -454,7 +454,8 @@ void SourceBuffer::appendBufferTimerFired(Timer<SourceBuffer>*)
     scheduleEvent(eventNames().updateendEvent);
 
     m_source->monitorSourceBuffers();
-    provideMediaData();
+    for (auto iter = m_trackBufferMap.begin(), end = m_trackBufferMap.end(); iter != end; ++iter)
+        provideMediaData(iter->value, iter->key);
 }
 
 const AtomicString& SourceBuffer::decodeError()
@@ -1123,39 +1124,38 @@ void SourceBuffer::textTrackKindChanged(TextTrack* track)
         m_source->mediaElement()->textTrackKindChanged(track);
 }
 
-void SourceBuffer::sourceBufferPrivateDidBecomeReadyForMoreSamples(SourceBufferPrivate*)
+void SourceBuffer::sourceBufferPrivateDidBecomeReadyForMoreSamples(SourceBufferPrivate*, AtomicString trackID)
 {
     LOG(Media, "SourceBuffer::sourceBufferPrivateDidBecomeReadyForMoreSamples(%p)", this);
-    provideMediaData();
+    auto it = m_trackBufferMap.find(trackID);
+    if (it == m_trackBufferMap.end())
+        return;
+
+    provideMediaData(it->value, trackID);
 }
 
-void SourceBuffer::provideMediaData()
+void SourceBuffer::provideMediaData(TrackBuffer& trackBuffer, AtomicString trackID)
 {
-    if (!m_private->isReadyForMoreSamples())
-        return;
-
 #if !LOG_DISABLED
     unsigned enqueuedSamples = 0;
 #endif
 
-    for (auto it = m_trackBufferMap.begin(), end = m_trackBufferMap.end(); it != end; ++it) {
-        TrackBuffer& trackBuffer = it->value;
-        AtomicString trackID = it->key;
-        auto sampleIt = trackBuffer.decodeQueue.begin();
-        for (auto sampleEnd = trackBuffer.decodeQueue.end(); sampleIt != sampleEnd; ++sampleIt) {
-            if (!m_private->isReadyForMoreSamples())
-                break;
-
-            RefPtr<MediaSample> sample = sampleIt->second;
-            trackBuffer.lastEnqueuedPresentationTime = sample->presentationTime();
-            m_private->enqueueSample(sample.release(), trackID);
+    auto sampleIt = trackBuffer.decodeQueue.begin();
+    for (auto sampleEnd = trackBuffer.decodeQueue.end(); sampleIt != sampleEnd; ++sampleIt) {
+        if (!m_private->isReadyForMoreSamples(trackID)) {
+            m_private->notifyClientWhenReadyForMoreSamples(trackID);
+            break;
+        }
+
+        RefPtr<MediaSample> sample = sampleIt->second;
+        trackBuffer.lastEnqueuedPresentationTime = sample->presentationTime();
+        m_private->enqueueSample(sample.release(), trackID);
 #if !LOG_DISABLED
-            ++enqueuedSamples;
+        ++enqueuedSamples;
 #endif
 
-        }
-        trackBuffer.decodeQueue.erase(trackBuffer.decodeQueue.begin(), sampleIt);
     }
+    trackBuffer.decodeQueue.erase(trackBuffer.decodeQueue.begin(), sampleIt);
 
     LOG(Media, "SourceBuffer::provideMediaData(%p) - Enqueued %u samples", this, enqueuedSamples);
 }
index d22cda1..b85351e 100644 (file)
@@ -108,7 +108,7 @@ private:
     virtual void sourceBufferPrivateDidReceiveSample(SourceBufferPrivate*, PassRefPtr<MediaSample>) OVERRIDE;
     virtual bool sourceBufferPrivateHasAudio(const SourceBufferPrivate*) const OVERRIDE;
     virtual bool sourceBufferPrivateHasVideo(const SourceBufferPrivate*) const OVERRIDE;
-    virtual void sourceBufferPrivateDidBecomeReadyForMoreSamples(SourceBufferPrivate*) OVERRIDE;
+    virtual void sourceBufferPrivateDidBecomeReadyForMoreSamples(SourceBufferPrivate*, AtomicString trackID) OVERRIDE;
     virtual void sourceBufferPrivateSeekToTime(SourceBufferPrivate*, const MediaTime&);
     virtual MediaTime sourceBufferPrivateFastSeekTimeForMediaTime(SourceBufferPrivate*, const MediaTime&, const MediaTime& negativeThreshold, const MediaTime& positiveThreshold);
 
@@ -140,7 +140,8 @@ private:
 
     bool validateInitializationSegment(const InitializationSegment&);
 
-    void provideMediaData();
+    struct TrackBuffer;
+    void provideMediaData(TrackBuffer&, AtomicString trackID);
     void didDropSample();
 
     RefPtr<SourceBufferPrivate> m_private;
@@ -163,7 +164,6 @@ private:
     MediaTime m_timestampOffset;
     MediaTime m_highestPresentationEndTimestamp;
 
-    struct TrackBuffer;
     HashMap<AtomicString, TrackBuffer> m_trackBufferMap;
     bool m_receivedFirstInitializationSegment;
     RefPtr<TimeRanges> m_buffered;
index e1b6c79..c405b96 100644 (file)
@@ -65,8 +65,10 @@ public:
 
     virtual void flushAndEnqueueNonDisplayingSamples(Vector<RefPtr<MediaSample>>, AtomicString) { }
     virtual void enqueueSample(PassRefPtr<MediaSample>, AtomicString) { }
-    virtual bool isReadyForMoreSamples() { return false; }
+    virtual bool isReadyForMoreSamples(AtomicString) { return false; }
     virtual void setActive(bool) { }
+    virtual void stopAskingForMoreSamples(AtomicString) { }
+    virtual void notifyClientWhenReadyForMoreSamples(AtomicString) { }
 };
 
 }
index bbe64a8..2ae008d 100644 (file)
@@ -73,11 +73,10 @@ public:
     virtual bool sourceBufferPrivateHasAudio(const SourceBufferPrivate*) const = 0;
     virtual bool sourceBufferPrivateHasVideo(const SourceBufferPrivate*) const = 0;
 
-    virtual void sourceBufferPrivateDidBecomeReadyForMoreSamples(SourceBufferPrivate*) = 0;
+    virtual void sourceBufferPrivateDidBecomeReadyForMoreSamples(SourceBufferPrivate*, AtomicString trackID) = 0;
 
     virtual MediaTime sourceBufferPrivateFastSeekTimeForMediaTime(SourceBufferPrivate*, const MediaTime& time, const MediaTime&, const MediaTime&) { return time; }
     virtual void sourceBufferPrivateSeekToTime(SourceBufferPrivate*, const MediaTime&) { };
-
 };
 
 }
index 2e23fa4..a2db3b5 100644 (file)
@@ -92,7 +92,7 @@ private:
     virtual bool isFull() OVERRIDE;
     virtual void flushAndEnqueueNonDisplayingSamples(Vector<RefPtr<MediaSample>>, AtomicString trackID) OVERRIDE;
     virtual void enqueueSample(PassRefPtr<MediaSample>, AtomicString trackID) OVERRIDE;
-    virtual bool isReadyForMoreSamples() OVERRIDE;
+    virtual bool isReadyForMoreSamples(AtomicString trackID) OVERRIDE;
     virtual void setActive(bool) OVERRIDE;
 
     Vector<RefPtr<VideoTrackPrivate>> m_videoTracks;
index c3bc762..edfabc8 100644 (file)
@@ -469,7 +469,7 @@ void SourceBufferPrivateAVFObjC::trackDidChangeEnabled(VideoTrackPrivateMediaSou
             m_displayLayer = [[getAVSampleBufferDisplayLayerClass() alloc] init];
             [m_displayLayer requestMediaDataWhenReadyOnQueue:dispatch_get_main_queue() usingBlock:^{
                 if (m_client)
-                    m_client->sourceBufferPrivateDidBecomeReadyForMoreSamples(this);
+                    m_client->sourceBufferPrivateDidBecomeReadyForMoreSamples(this, AtomicString::number(trackID));
             }];
             if (m_mediaSource)
                 m_mediaSource->player()->addDisplayLayer(m_displayLayer.get());
@@ -538,8 +538,9 @@ void SourceBufferPrivateAVFObjC::enqueueSample(PassRefPtr<MediaSample> prpMediaS
         m_mediaSource->player()->setHasAvailableVideoFrame(true);
 }
 
-bool SourceBufferPrivateAVFObjC::isReadyForMoreSamples()
+bool SourceBufferPrivateAVFObjC::isReadyForMoreSamples(AtomicString trackID)
 {
+    UNUSED_PARAM(trackID);
     return [m_displayLayer isReadyForMoreMediaData];
 }
 
index 06d2f44..97330de 100644 (file)
@@ -73,7 +73,7 @@ private:
 
     virtual void flushAndEnqueueNonDisplayingSamples(Vector<RefPtr<MediaSample>>, AtomicString) OVERRIDE { }
     virtual void enqueueSample(PassRefPtr<MediaSample>, AtomicString) OVERRIDE;
-    virtual bool isReadyForMoreSamples() OVERRIDE { return true; }
+    virtual bool isReadyForMoreSamples(AtomicString) OVERRIDE { return true; }
     virtual void setActive(bool) OVERRIDE;
 
     void didReceiveInitializationSegment(const MockInitializationBox&);