Title: [170484] trunk/Source/WebCore
Revision
170484
Author
jer.no...@apple.com
Date
2014-06-26 11:17:36 -0700 (Thu, 26 Jun 2014)

Log Message

[MSE] Refactoring: Differentiate between SampleMap decode and presentation order methods
https://bugs.webkit.org/show_bug.cgi?id=134349

Reviewed by Geoffrey Garen.

Refactor SampleMap to clarify the distinction between methods which return decode-order
iterators and ones which retun presentation-order iterators.

Add two classes, PresentationOrderSampleMap and DecodeOrderSampleMap, to contain the actual
MediaTime-to-Sample maps, and move the methods returning presentation-order and decode-order
iterators to each, respectively.  Rename the {presentation,decode}{Begin,End}() methods to
begin() and end() so the objects can be used in C++11 for-loops.

Update all the call sites in SourceBuffer to use the new ordered objects.

* Modules/mediasource/SampleMap.cpp:
(WebCore::SampleIsLessThanMediaTimeComparator::operator()): Use new ordered objects.
(WebCore::SampleIsGreaterThanMediaTimeComparator::operator()): Ditto.
(WebCore::SampleMap::clear): Ditto.
(WebCore::SampleMap::addSample): Ditto.
(WebCore::SampleMap::removeSample): Ditto.
(WebCore::PresentationOrderSampleMap::findSampleContainingPresentationTime): Renamed from SampleMap version.
(WebCore::PresentationOrderSampleMap::findSampleAfterPresentationTime): Ditto.
(WebCore::DecodeOrderSampleMap::findSampleWithDecodeTime): Ditto.
(WebCore::PresentationOrderSampleMap::reverseFindSampleContainingPresentationTime): Ditto.
(WebCore::PresentationOrderSampleMap::reverseFindSampleBeforePresentationTime): Ditto.
(WebCore::DecodeOrderSampleMap::reverseFindSampleWithDecodeTime): Ditto.
(WebCore::DecodeOrderSampleMap::findSyncSamplePriorToPresentationTime): Ditto.
(WebCore::DecodeOrderSampleMap::findSyncSamplePriorToDecodeIterator): Ditto.
(WebCore::DecodeOrderSampleMap::findSyncSampleAfterPresentationTime): Ditto.
(WebCore::DecodeOrderSampleMap::findSyncSampleAfterDecodeIterator): Ditto.
(WebCore::PresentationOrderSampleMap::findSamplesBetweenPresentationTimes): Ditto.
(WebCore::PresentationOrderSampleMap::findSamplesWithinPresentationRange): Ditto.
(WebCore::DecodeOrderSampleMap::findDependentSamples): Ditto.
* Modules/mediasource/SampleMap.h:
(WebCore::PresentationOrderSampleMap::begin): Renamed from presentationBegin().
(WebCore::PresentationOrderSampleMap::end): Renamed from presentationEnd().
(WebCore::PresentationOrderSampleMap::rbegin): Renamed from reversePresentationBegin().
(WebCore::PresentationOrderSampleMap::rend): Renamed from reversePresentationEnd().
(WebCore::DecodeOrderSampleMap::begin): Renamed from decodeBegin().
(WebCore::DecodeOrderSampleMap::end): Renamed from decodeEnd().
(WebCore::DecodeOrderSampleMap::rbegin): Renamed from reverseDecodeBegin().
(WebCore::DecodeOrderSampleMap::rend): Renamed from reverseDecodeEnd().
(WebCore::SampleMap::SampleMap): Create new ordered objects.
(WebCore::SampleMap::sizeInBytes): Use new ordered objects.
(WebCore::SampleMap::decodeOrder): Simple accessor.
(WebCore::SampleMap::presentationOrder): Simple accessor.
* Modules/mediasource/SourceBuffer.cpp:
(WebCore::SourceBuffer::sourceBufferPrivateSeekToTime): Use new ordered objects.
(WebCore::SourceBuffer::sourceBufferPrivateFastSeekTimeForMediaTime): Ditto.
(WebCore::SourceBuffer::removeCodedFrames): Ditto.
(WebCore::SourceBuffer::sourceBufferPrivateDidReceiveSample): Ditto.
(WebCore::SourceBuffer::bufferedSamplesForTrackID): Ditto.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (170483 => 170484)


--- trunk/Source/WebCore/ChangeLog	2014-06-26 17:22:00 UTC (rev 170483)
+++ trunk/Source/WebCore/ChangeLog	2014-06-26 18:17:36 UTC (rev 170484)
@@ -1,3 +1,59 @@
+2014-06-26  Jer Noble  <jer.no...@apple.com>
+
+        [MSE] Refactoring: Differentiate between SampleMap decode and presentation order methods
+        https://bugs.webkit.org/show_bug.cgi?id=134349
+
+        Reviewed by Geoffrey Garen.
+
+        Refactor SampleMap to clarify the distinction between methods which return decode-order
+        iterators and ones which retun presentation-order iterators.
+
+        Add two classes, PresentationOrderSampleMap and DecodeOrderSampleMap, to contain the actual
+        MediaTime-to-Sample maps, and move the methods returning presentation-order and decode-order
+        iterators to each, respectively.  Rename the {presentation,decode}{Begin,End}() methods to
+        begin() and end() so the objects can be used in C++11 for-loops.
+
+        Update all the call sites in SourceBuffer to use the new ordered objects.
+
+        * Modules/mediasource/SampleMap.cpp:
+        (WebCore::SampleIsLessThanMediaTimeComparator::operator()): Use new ordered objects.
+        (WebCore::SampleIsGreaterThanMediaTimeComparator::operator()): Ditto.
+        (WebCore::SampleMap::clear): Ditto.
+        (WebCore::SampleMap::addSample): Ditto.
+        (WebCore::SampleMap::removeSample): Ditto.
+        (WebCore::PresentationOrderSampleMap::findSampleContainingPresentationTime): Renamed from SampleMap version.
+        (WebCore::PresentationOrderSampleMap::findSampleAfterPresentationTime): Ditto.
+        (WebCore::DecodeOrderSampleMap::findSampleWithDecodeTime): Ditto.
+        (WebCore::PresentationOrderSampleMap::reverseFindSampleContainingPresentationTime): Ditto.
+        (WebCore::PresentationOrderSampleMap::reverseFindSampleBeforePresentationTime): Ditto.
+        (WebCore::DecodeOrderSampleMap::reverseFindSampleWithDecodeTime): Ditto.
+        (WebCore::DecodeOrderSampleMap::findSyncSamplePriorToPresentationTime): Ditto.
+        (WebCore::DecodeOrderSampleMap::findSyncSamplePriorToDecodeIterator): Ditto.
+        (WebCore::DecodeOrderSampleMap::findSyncSampleAfterPresentationTime): Ditto.
+        (WebCore::DecodeOrderSampleMap::findSyncSampleAfterDecodeIterator): Ditto.
+        (WebCore::PresentationOrderSampleMap::findSamplesBetweenPresentationTimes): Ditto.
+        (WebCore::PresentationOrderSampleMap::findSamplesWithinPresentationRange): Ditto.
+        (WebCore::DecodeOrderSampleMap::findDependentSamples): Ditto.
+        * Modules/mediasource/SampleMap.h:
+        (WebCore::PresentationOrderSampleMap::begin): Renamed from presentationBegin().
+        (WebCore::PresentationOrderSampleMap::end): Renamed from presentationEnd().
+        (WebCore::PresentationOrderSampleMap::rbegin): Renamed from reversePresentationBegin().
+        (WebCore::PresentationOrderSampleMap::rend): Renamed from reversePresentationEnd().
+        (WebCore::DecodeOrderSampleMap::begin): Renamed from decodeBegin().
+        (WebCore::DecodeOrderSampleMap::end): Renamed from decodeEnd().
+        (WebCore::DecodeOrderSampleMap::rbegin): Renamed from reverseDecodeBegin().
+        (WebCore::DecodeOrderSampleMap::rend): Renamed from reverseDecodeEnd().
+        (WebCore::SampleMap::SampleMap): Create new ordered objects.
+        (WebCore::SampleMap::sizeInBytes): Use new ordered objects.
+        (WebCore::SampleMap::decodeOrder): Simple accessor.
+        (WebCore::SampleMap::presentationOrder): Simple accessor.
+        * Modules/mediasource/SourceBuffer.cpp:
+        (WebCore::SourceBuffer::sourceBufferPrivateSeekToTime): Use new ordered objects.
+        (WebCore::SourceBuffer::sourceBufferPrivateFastSeekTimeForMediaTime): Ditto.
+        (WebCore::SourceBuffer::removeCodedFrames): Ditto.
+        (WebCore::SourceBuffer::sourceBufferPrivateDidReceiveSample): Ditto.
+        (WebCore::SourceBuffer::bufferedSamplesForTrackID): Ditto.
+
 2014-06-26  Chris Fleizach  <cfleiz...@apple.com>
 
         Add an undo group for each dictated utterance in WebKit

Modified: trunk/Source/WebCore/Modules/mediasource/SampleMap.cpp (170483 => 170484)


--- trunk/Source/WebCore/Modules/mediasource/SampleMap.cpp	2014-06-26 17:22:00 UTC (rev 170483)
+++ trunk/Source/WebCore/Modules/mediasource/SampleMap.cpp	2014-06-26 18:17:36 UTC (rev 170484)
@@ -32,28 +32,32 @@
 
 namespace WebCore {
 
+template <typename M>
 class SampleIsLessThanMediaTimeComparator {
 public:
-    bool operator()(const SampleMap::MapType::value_type& value, const MediaTime& time)
+    typedef typename M::value_type value_type;
+    bool operator()(const value_type& value, const MediaTime& time)
     {
         MediaTime presentationEndTime = value.second->presentationTime() + value.second->duration();
         return presentationEndTime <= time;
     }
-    bool operator()(const MediaTime& time, const SampleMap::MapType::value_type& value)
+    bool operator()(const MediaTime& time, const value_type& value)
     {
         MediaTime presentationStartTime = value.second->presentationTime();
         return time < presentationStartTime;
     }
 };
 
+template <typename M>
 class SampleIsGreaterThanMediaTimeComparator {
 public:
-    bool operator()(const SampleMap::MapType::value_type& value, const MediaTime& time)
+    typedef typename M::value_type value_type;
+    bool operator()(const value_type& value, const MediaTime& time)
     {
         MediaTime presentationStartTime = value.second->presentationTime();
         return presentationStartTime > time;
     }
-    bool operator()(const MediaTime& time, const SampleMap::MapType::value_type& value)
+    bool operator()(const MediaTime& time, const value_type& value)
     {
         MediaTime presentationEndTime = value.second->presentationTime() + value.second->duration();
         return time >= presentationEndTime;
@@ -94,8 +98,8 @@
 
 void SampleMap::clear()
 {
-    m_presentationSamples.clear();
-    m_decodeSamples.clear();
+    presentationOrder().m_samples.clear();
+    decodeOrder().m_samples.clear();
     m_totalSize = 0;
 }
 
@@ -103,8 +107,8 @@
 {
     RefPtr<MediaSample> sample = prpSample;
     ASSERT(sample);
-    m_presentationSamples.insert(MapType::value_type(sample->presentationTime(), sample));
-    m_decodeSamples.insert(MapType::value_type(sample->decodeTime(), sample));
+    presentationOrder().m_samples.insert(PresentationOrderSampleMap::MapType::value_type(sample->presentationTime(), sample));
+    decodeOrder().m_samples.insert(DecodeOrderSampleMap::MapType::value_type(sample->decodeTime(), sample));
 
     m_totalSize += sample->sizeInBytes();
 }
@@ -112,107 +116,107 @@
 void SampleMap::removeSample(MediaSample* sample)
 {
     ASSERT(sample);
-    m_presentationSamples.erase(sample->presentationTime());
-    m_decodeSamples.erase(sample->decodeTime());
+    presentationOrder().m_samples.erase(sample->presentationTime());
+    decodeOrder().m_samples.erase(sample->decodeTime());
 
     m_totalSize -= sample->sizeInBytes();
 }
 
-SampleMap::iterator SampleMap::findSampleContainingPresentationTime(const MediaTime& time)
+PresentationOrderSampleMap::iterator PresentationOrderSampleMap::findSampleContainingPresentationTime(const MediaTime& time)
 {
-    auto range = std::equal_range(presentationBegin(), presentationEnd(), time, SampleIsLessThanMediaTimeComparator());
+    auto range = std::equal_range(begin(), end(), time, SampleIsLessThanMediaTimeComparator<MapType>());
     if (range.first == range.second)
-        return presentationEnd();
+        return end();
     return range.first;
 }
 
-SampleMap::iterator SampleMap::findSampleAfterPresentationTime(const MediaTime& time)
+PresentationOrderSampleMap::iterator PresentationOrderSampleMap::findSampleAfterPresentationTime(const MediaTime& time)
 {
-    return std::lower_bound(presentationBegin(), presentationEnd(), time, SampleIsLessThanMediaTimeComparator());
+    return std::lower_bound(begin(), end(), time, SampleIsLessThanMediaTimeComparator<MapType>());
 }
 
-SampleMap::iterator SampleMap::findSampleWithDecodeTime(const MediaTime& time)
+DecodeOrderSampleMap::iterator DecodeOrderSampleMap::findSampleWithDecodeTime(const MediaTime& time)
 {
-    return m_decodeSamples.find(time);
+    return m_samples.find(time);
 }
 
-SampleMap::reverse_iterator SampleMap::reverseFindSampleContainingPresentationTime(const MediaTime& time)
+PresentationOrderSampleMap::reverse_iterator PresentationOrderSampleMap::reverseFindSampleContainingPresentationTime(const MediaTime& time)
 {
-    auto range = std::equal_range(reversePresentationBegin(), reversePresentationEnd(), time, SampleIsGreaterThanMediaTimeComparator());
+    auto range = std::equal_range(rbegin(), rend(), time, SampleIsGreaterThanMediaTimeComparator<MapType>());
     if (range.first == range.second)
-        return reversePresentationEnd();
+        return rend();
     return range.first;
 }
 
-SampleMap::reverse_iterator SampleMap::reverseFindSampleBeforePresentationTime(const MediaTime& time)
+PresentationOrderSampleMap::reverse_iterator PresentationOrderSampleMap::reverseFindSampleBeforePresentationTime(const MediaTime& time)
 {
-    return std::lower_bound(reversePresentationBegin(), reversePresentationEnd(), time, SampleIsGreaterThanMediaTimeComparator());
+    return std::lower_bound(rbegin(), rend(), time, SampleIsGreaterThanMediaTimeComparator<MapType>());
 }
 
-SampleMap::reverse_iterator SampleMap::reverseFindSampleWithDecodeTime(const MediaTime& time)
+DecodeOrderSampleMap::reverse_iterator DecodeOrderSampleMap::reverseFindSampleWithDecodeTime(const MediaTime& time)
 {
-    SampleMap::iterator found = findSampleWithDecodeTime(time);
-    if (found == decodeEnd())
-        return reverseDecodeEnd();
+    DecodeOrderSampleMap::iterator found = findSampleWithDecodeTime(time);
+    if (found == end())
+        return rend();
     return --reverse_iterator(found);
 }
 
-SampleMap::reverse_iterator SampleMap::findSyncSamplePriorToPresentationTime(const MediaTime& time, const MediaTime& threshold)
+DecodeOrderSampleMap::reverse_iterator DecodeOrderSampleMap::findSyncSamplePriorToPresentationTime(const MediaTime& time, const MediaTime& threshold)
 {
-    reverse_iterator reverseCurrentSamplePTS = reverseFindSampleBeforePresentationTime(time);
-    if (reverseCurrentSamplePTS == reversePresentationEnd())
-        return reverseDecodeEnd();
+    PresentationOrderSampleMap::reverse_iterator reverseCurrentSamplePTS = m_presentationOrder.reverseFindSampleBeforePresentationTime(time);
+    if (reverseCurrentSamplePTS == m_presentationOrder.rend())
+        return rend();
 
     reverse_iterator reverseCurrentSampleDTS = reverseFindSampleWithDecodeTime(reverseCurrentSamplePTS->second->decodeTime());
 
     reverse_iterator foundSample = findSyncSamplePriorToDecodeIterator(reverseCurrentSampleDTS);
-    if (foundSample == reverseDecodeEnd())
-        return reverseDecodeEnd();
+    if (foundSample == rend())
+        return rend();
     if (foundSample->second->presentationTime() < time - threshold)
-        return reverseDecodeEnd();
+        return rend();
     return foundSample;
 }
 
-SampleMap::reverse_iterator SampleMap::findSyncSamplePriorToDecodeIterator(reverse_iterator iterator)
+DecodeOrderSampleMap::reverse_iterator DecodeOrderSampleMap::findSyncSamplePriorToDecodeIterator(reverse_iterator iterator)
 {
-    return std::find_if(iterator, reverseDecodeEnd(), SampleIsRandomAccess());
+    return std::find_if(iterator, rend(), SampleIsRandomAccess());
 }
 
-SampleMap::iterator SampleMap::findSyncSampleAfterPresentationTime(const MediaTime& time, const MediaTime& threshold)
+DecodeOrderSampleMap::iterator DecodeOrderSampleMap::findSyncSampleAfterPresentationTime(const MediaTime& time, const MediaTime& threshold)
 {
-    iterator currentSamplePTS = findSampleAfterPresentationTime(time);
-    if (currentSamplePTS == presentationEnd())
-        return decodeEnd();
+    PresentationOrderSampleMap::iterator currentSamplePTS = m_presentationOrder.findSampleAfterPresentationTime(time);
+    if (currentSamplePTS == m_presentationOrder.end())
+        return end();
 
     iterator currentSampleDTS = findSampleWithDecodeTime(currentSamplePTS->second->decodeTime());
     
     MediaTime upperBound = time + threshold;
-    iterator foundSample = std::find_if(currentSampleDTS, decodeEnd(), SampleIsRandomAccess());
-    if (foundSample == decodeEnd())
-        return decodeEnd();
+    iterator foundSample = std::find_if(currentSampleDTS, end(), SampleIsRandomAccess());
+    if (foundSample == end())
+        return end();
     if (foundSample->second->presentationTime() > upperBound)
-        return decodeEnd();
+        return end();
     return foundSample;
 }
 
-SampleMap::iterator SampleMap::findSyncSampleAfterDecodeIterator(iterator currentSampleDTS)
+DecodeOrderSampleMap::iterator DecodeOrderSampleMap::findSyncSampleAfterDecodeIterator(iterator currentSampleDTS)
 {
-    return std::find_if(currentSampleDTS, decodeEnd(), SampleIsRandomAccess());
+    return std::find_if(currentSampleDTS, end(), SampleIsRandomAccess());
 }
 
-SampleMap::iterator_range SampleMap::findSamplesBetweenPresentationTimes(const MediaTime& begin, const MediaTime& end)
+PresentationOrderSampleMap::iterator_range PresentationOrderSampleMap::findSamplesBetweenPresentationTimes(const MediaTime& beginTime, const MediaTime& endTime)
 {
-    std::pair<MediaTime, MediaTime> range(begin, end);
-    return std::equal_range(presentationBegin(), presentationEnd(), range, SamplePresentationTimeIsInsideRangeComparator());
+    std::pair<MediaTime, MediaTime> range(beginTime, endTime);
+    return std::equal_range(begin(), end(), range, SamplePresentationTimeIsInsideRangeComparator());
 }
 
-SampleMap::iterator_range SampleMap::findSamplesWithinPresentationRange(const MediaTime& begin, const MediaTime& end)
+PresentationOrderSampleMap::iterator_range PresentationOrderSampleMap::findSamplesWithinPresentationRange(const MediaTime& beginTime, const MediaTime& endTime)
 {
-    std::pair<MediaTime, MediaTime> range(begin, end);
-    return std::equal_range(presentationBegin(), presentationEnd(), range, SamplePresentationTimeIsWithinRangeComparator());
+    std::pair<MediaTime, MediaTime> range(beginTime, endTime);
+    return std::equal_range(begin(), end(), range, SamplePresentationTimeIsWithinRangeComparator());
 }
 
-SampleMap::reverse_iterator_range SampleMap::findDependentSamples(MediaSample* sample)
+DecodeOrderSampleMap::reverse_iterator_range DecodeOrderSampleMap::findDependentSamples(MediaSample* sample)
 {
     ASSERT(sample);
     reverse_iterator currentDecodeIter = reverseFindSampleWithDecodeTime(sample->decodeTime());

Modified: trunk/Source/WebCore/Modules/mediasource/SampleMap.h (170483 => 170484)


--- trunk/Source/WebCore/Modules/mediasource/SampleMap.h	2014-06-26 17:22:00 UTC (rev 170483)
+++ trunk/Source/WebCore/Modules/mediasource/SampleMap.h	2014-06-26 18:17:36 UTC (rev 170484)
@@ -29,21 +29,66 @@
 #if ENABLE(MEDIA_SOURCE)
 
 #include <map>
-#include <wtf/MediaTime.h>
+#include <wtf/MediaTimeHash.h>
 #include <wtf/RefPtr.h>
 
 namespace WebCore {
 
 class MediaSample;
+class SampleMap;
 
-class SampleMap {
+class PresentationOrderSampleMap {
+    friend class SampleMap;
 public:
     typedef std::map<MediaTime, RefPtr<MediaSample>> MapType;
     typedef MapType::iterator iterator;
     typedef MapType::reverse_iterator reverse_iterator;
     typedef std::pair<iterator, iterator> iterator_range;
+
+    iterator begin() { return m_samples.begin(); }
+    iterator end() { return m_samples.end(); }
+    reverse_iterator rbegin() { return m_samples.rbegin(); }
+    reverse_iterator rend() { return m_samples.rend(); }
+
+    iterator findSampleContainingPresentationTime(const MediaTime&);
+    iterator findSampleAfterPresentationTime(const MediaTime&);
+    reverse_iterator reverseFindSampleContainingPresentationTime(const MediaTime&);
+    reverse_iterator reverseFindSampleBeforePresentationTime(const MediaTime&);
+    iterator_range findSamplesBetweenPresentationTimes(const MediaTime&, const MediaTime&);
+    iterator_range findSamplesWithinPresentationRange(const MediaTime&, const MediaTime&);
+
+private:
+    MapType m_samples;
+};
+
+class DecodeOrderSampleMap {
+    friend class SampleMap;
+public:
+    typedef std::map<MediaTime, RefPtr<MediaSample>> MapType;
+    typedef MapType::iterator iterator;
+    typedef MapType::reverse_iterator reverse_iterator;
     typedef std::pair<reverse_iterator, reverse_iterator> reverse_iterator_range;
 
+    iterator begin() { return m_samples.begin(); }
+    iterator end() { return m_samples.end(); }
+    reverse_iterator rbegin() { return m_samples.rbegin(); }
+    reverse_iterator rend() { return m_samples.rend(); }
+
+    iterator findSampleWithDecodeTime(const MediaTime&);
+    reverse_iterator reverseFindSampleWithDecodeTime(const MediaTime&);
+    reverse_iterator findSyncSamplePriorToPresentationTime(const MediaTime&, const MediaTime& threshold = MediaTime::positiveInfiniteTime());
+    reverse_iterator findSyncSamplePriorToDecodeIterator(reverse_iterator);
+    iterator findSyncSampleAfterPresentationTime(const MediaTime&, const MediaTime& threshold = MediaTime::positiveInfiniteTime());
+    iterator findSyncSampleAfterDecodeIterator(iterator);
+    reverse_iterator_range findDependentSamples(MediaSample*);
+
+private:
+    MapType m_samples;
+    PresentationOrderSampleMap m_presentationOrder;
+};
+
+class SampleMap {
+public:
     SampleMap()
         : m_totalSize(0)
     {
@@ -54,33 +99,11 @@
     void removeSample(MediaSample*);
     size_t sizeInBytes() const { return m_totalSize; }
 
-    iterator presentationBegin() { return m_presentationSamples.begin(); }
-    iterator presentationEnd() { return m_presentationSamples.end(); }
-    iterator decodeBegin() { return m_decodeSamples.begin(); }
-    iterator decodeEnd() { return m_decodeSamples.end(); }
-    reverse_iterator reversePresentationBegin() { return m_presentationSamples.rbegin(); }
-    reverse_iterator reversePresentationEnd() { return m_presentationSamples.rend(); }
-    reverse_iterator reverseDecodeBegin() { return m_decodeSamples.rbegin(); }
-    reverse_iterator reverseDecodeEnd() { return m_decodeSamples.rend(); }
+    DecodeOrderSampleMap& decodeOrder() { return m_decodeOrder; }
+    PresentationOrderSampleMap& presentationOrder() { return m_decodeOrder.m_presentationOrder; }
 
-    iterator findSampleContainingPresentationTime(const MediaTime&);
-    iterator findSampleAfterPresentationTime(const MediaTime&);
-    iterator findSampleWithDecodeTime(const MediaTime&);
-    reverse_iterator reverseFindSampleContainingPresentationTime(const MediaTime&);
-    reverse_iterator reverseFindSampleBeforePresentationTime(const MediaTime&);
-    reverse_iterator reverseFindSampleWithDecodeTime(const MediaTime&);
-    reverse_iterator findSyncSamplePriorToPresentationTime(const MediaTime&, const MediaTime& threshold = MediaTime::positiveInfiniteTime());
-    reverse_iterator findSyncSamplePriorToDecodeIterator(reverse_iterator);
-    iterator findSyncSampleAfterPresentationTime(const MediaTime&, const MediaTime& threshold = MediaTime::positiveInfiniteTime());
-    iterator findSyncSampleAfterDecodeIterator(iterator);
-
-    iterator_range findSamplesBetweenPresentationTimes(const MediaTime&, const MediaTime&);
-    iterator_range findSamplesWithinPresentationRange(const MediaTime&, const MediaTime&);
-    reverse_iterator_range findDependentSamples(MediaSample*);
-    
 private:
-    MapType m_presentationSamples;
-    MapType m_decodeSamples;
+    DecodeOrderSampleMap m_decodeOrder;
     size_t m_totalSize;
 };
 

Modified: trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp (170483 => 170484)


--- trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp	2014-06-26 17:22:00 UTC (rev 170483)
+++ trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp	2014-06-26 18:17:36 UTC (rev 170484)
@@ -74,7 +74,7 @@
     bool needRandomAccessFlag;
     bool enabled;
     SampleMap samples;
-    SampleMap::MapType decodeQueue;
+    DecodeOrderSampleMap::MapType decodeQueue;
     RefPtr<MediaDescription> description;
 
     TrackBuffer()
@@ -316,9 +316,9 @@
         AtomicString trackID = trackBufferIterator->key;
 
         // Find the sample which contains the current presentation time.
-        auto currentSamplePTSIterator = trackBuffer.samples.findSampleContainingPresentationTime(time);
+        auto currentSamplePTSIterator = trackBuffer.samples.presentationOrder().findSampleContainingPresentationTime(time);
 
-        if (currentSamplePTSIterator == trackBuffer.samples.presentationEnd()) {
+        if (currentSamplePTSIterator == trackBuffer.samples.presentationOrder().end()) {
             trackBuffer.decodeQueue.clear();
             m_private->flushAndEnqueueNonDisplayingSamples(Vector<RefPtr<MediaSample>>(), trackID);
             continue;
@@ -326,12 +326,12 @@
 
         // Seach backward for the previous sync sample.
         MediaTime currentSampleDecodeTime = currentSamplePTSIterator->second->decodeTime();
-        auto currentSampleDTSIterator = trackBuffer.samples.findSampleWithDecodeTime(currentSampleDecodeTime);
-        ASSERT(currentSampleDTSIterator != trackBuffer.samples.decodeEnd());
+        auto currentSampleDTSIterator = trackBuffer.samples.decodeOrder().findSampleWithDecodeTime(currentSampleDecodeTime);
+        ASSERT(currentSampleDTSIterator != trackBuffer.samples.decodeOrder().end());
 
-        auto reverseCurrentSampleIter = --SampleMap::reverse_iterator(currentSampleDTSIterator);
-        auto reverseLastSyncSampleIter = trackBuffer.samples.findSyncSamplePriorToDecodeIterator(reverseCurrentSampleIter);
-        if (reverseLastSyncSampleIter == trackBuffer.samples.reverseDecodeEnd()) {
+        auto reverseCurrentSampleIter = --DecodeOrderSampleMap::reverse_iterator(currentSampleDTSIterator);
+        auto reverseLastSyncSampleIter = trackBuffer.samples.decodeOrder().findSyncSamplePriorToDecodeIterator(reverseCurrentSampleIter);
+        if (reverseLastSyncSampleIter == trackBuffer.samples.decodeOrder().rend()) {
             trackBuffer.decodeQueue.clear();
             m_private->flushAndEnqueueNonDisplayingSamples(Vector<RefPtr<MediaSample>>(), trackID);
             continue;
@@ -345,7 +345,7 @@
 
         // Fill the decode queue with the remaining samples.
         trackBuffer.decodeQueue.clear();
-        for (auto iter = currentSampleDTSIterator; iter != trackBuffer.samples.decodeEnd(); ++iter)
+        for (auto iter = currentSampleDTSIterator; iter != trackBuffer.samples.decodeOrder().end(); ++iter)
             trackBuffer.decodeQueue.insert(*iter);
 
         provideMediaData(trackBuffer, trackID);
@@ -364,10 +364,10 @@
         TrackBuffer& trackBuffer = trackBufferIterator->value;
 
         // Find the sample which contains the target time time.
-        auto futureSyncSampleIterator = trackBuffer.samples.findSyncSampleAfterPresentationTime(targetTime, positiveThreshold);
-        auto pastSyncSampleIterator = trackBuffer.samples.findSyncSamplePriorToPresentationTime(targetTime, negativeThreshold);
-        auto upperBound = trackBuffer.samples.decodeEnd();
-        auto lowerBound = trackBuffer.samples.reverseDecodeEnd();
+        auto futureSyncSampleIterator = trackBuffer.samples.decodeOrder().findSyncSampleAfterPresentationTime(targetTime, positiveThreshold);
+        auto pastSyncSampleIterator = trackBuffer.samples.decodeOrder().findSyncSamplePriorToPresentationTime(targetTime, negativeThreshold);
+        auto upperBound = trackBuffer.samples.decodeOrder().end();
+        auto lowerBound = trackBuffer.samples.decodeOrder().rend();
 
         if (futureSyncSampleIterator == upperBound && pastSyncSampleIterator == lowerBound)
             continue;
@@ -562,16 +562,16 @@
         // 3.2 If this track buffer has a random access point timestamp that is greater than or equal to end, then update
         // remove end timestamp to that random access point timestamp.
         // NOTE: findSyncSampleAfterPresentationTime will return the next sync sample on or after the presentation time
-        // or decodeEnd() if no sync sample exists after that presentation time.
-        SampleMap::iterator removeDecodeEnd = trackBuffer.samples.findSyncSampleAfterPresentationTime(end);
+        // or decodeOrder().end() if no sync sample exists after that presentation time.
+        DecodeOrderSampleMap::iterator removeDecodeEnd = trackBuffer.samples.decodeOrder().findSyncSampleAfterPresentationTime(end);
 
         // 3.3 Remove all media data, from this track buffer, that contain starting timestamps greater than or equal to
         // start and less than the remove end timestamp.
         // NOTE: frames must be removed in decode order, so that all dependant frames between the frame to be removed
         // and the next sync sample frame are removed.
-        SampleMap::iterator removePresentaionStart = trackBuffer.samples.findSampleAfterPresentationTime(start);
-        SampleMap::iterator removeDecodeStart = trackBuffer.samples.findSampleWithDecodeTime(removePresentaionStart->second->decodeTime());
-        SampleMap::MapType erasedSamples(removeDecodeStart, removeDecodeEnd);
+        PresentationOrderSampleMap::iterator removePresentaionStart = trackBuffer.samples.presentationOrder().findSampleAfterPresentationTime(start);
+        DecodeOrderSampleMap::iterator removeDecodeStart = trackBuffer.samples.decodeOrder().findSampleWithDecodeTime(removePresentaionStart->second->decodeTime());
+        DecodeOrderSampleMap::MapType erasedSamples(removeDecodeStart, removeDecodeEnd);
         RefPtr<TimeRanges> erasedRanges = TimeRanges::create();
         MediaTime microsecond(1, 1000000);
         for (auto erasedIt : erasedSamples) {
@@ -1089,15 +1089,15 @@
         // 1.13 Let spliced timed text frame be an unset variable for holding timed text splice information
         // FIXME: Add support for sample splicing.
 
-        SampleMap::MapType erasedSamples;
+        DecodeOrderSampleMap::MapType erasedSamples;
         MediaTime microsecond(1, 1000000);
 
         // 1.14 If last decode timestamp for track buffer is unset and presentation timestamp falls
         // falls within the presentation interval of a coded frame in track buffer, then run the
         // following steps:
         if (trackBuffer.lastDecodeTimestamp.isInvalid()) {
-            auto iter = trackBuffer.samples.findSampleContainingPresentationTime(presentationTimestamp);
-            if (iter != trackBuffer.samples.presentationEnd()) {
+            auto iter = trackBuffer.samples.presentationOrder().findSampleContainingPresentationTime(presentationTimestamp);
+            if (iter != trackBuffer.samples.presentationOrder().end()) {
                 // 1.14.1 Let overlapped frame be the coded frame in track buffer that matches the condition above.
                 RefPtr<MediaSample> overlappedFrame = iter->second;
 
@@ -1133,8 +1133,8 @@
         if (trackBuffer.highestPresentationTimestamp.isInvalid()) {
             // Remove all coded frames from track buffer that have a presentation timestamp greater than or
             // equal to presentation timestamp and less than frame end timestamp.
-            auto iter_pair = trackBuffer.samples.findSamplesBetweenPresentationTimes(presentationTimestamp, frameEndTimestamp);
-            if (iter_pair.first != trackBuffer.samples.presentationEnd())
+            auto iter_pair = trackBuffer.samples.presentationOrder().findSamplesBetweenPresentationTimes(presentationTimestamp, frameEndTimestamp);
+            if (iter_pair.first != trackBuffer.samples.presentationOrder().end())
                 erasedSamples.insert(iter_pair.first, iter_pair.second);
         }
 
@@ -1142,13 +1142,13 @@
         if (trackBuffer.highestPresentationTimestamp.isValid() && trackBuffer.highestPresentationTimestamp <= presentationTimestamp) {
             // Remove all coded frames from track buffer that have a presentation timestamp greater than highest
             // presentation timestamp and less than or equal to frame end timestamp.
-            auto iter_pair = trackBuffer.samples.findSamplesWithinPresentationRange(trackBuffer.highestPresentationTimestamp, frameEndTimestamp);
-            if (iter_pair.first != trackBuffer.samples.presentationEnd())
+            auto iter_pair = trackBuffer.samples.presentationOrder().findSamplesWithinPresentationRange(trackBuffer.highestPresentationTimestamp, frameEndTimestamp);
+            if (iter_pair.first != trackBuffer.samples.presentationOrder().end())
                 erasedSamples.insert(iter_pair.first, iter_pair.second);
         }
 
         // 1.16 Remove decoding dependencies of the coded frames removed in the previous step:
-        SampleMap::MapType dependentSamples;
+        DecodeOrderSampleMap::MapType dependentSamples;
         if (!erasedSamples.empty()) {
             // If detailed information about decoding dependencies is available:
             // FIXME: Add support for detailed dependency information
@@ -1156,8 +1156,8 @@
             // Otherwise: Remove all coded frames between the coded frames removed in the previous step
             // and the next random access point after those removed frames.
             for (auto erasedIt = erasedSamples.begin(), end = erasedSamples.end(); erasedIt != end; ++erasedIt) {
-                auto currentDecodeIter = trackBuffer.samples.findSampleWithDecodeTime(erasedIt->second->decodeTime());
-                auto nextSyncIter = trackBuffer.samples.findSyncSampleAfterDecodeIterator(currentDecodeIter);
+                auto currentDecodeIter = trackBuffer.samples.decodeOrder().findSampleWithDecodeTime(erasedIt->second->decodeTime());
+                auto nextSyncIter = trackBuffer.samples.decodeOrder().findSyncSampleAfterDecodeIterator(currentDecodeIter);
                 dependentSamples.insert(currentDecodeIter, nextSyncIter);
             }
 
@@ -1190,7 +1190,7 @@
         // Otherwise:
         // Add the coded frame with the presentation timestamp, decode timestamp, and frame duration to the track buffer.
         trackBuffer.samples.addSample(sample);
-        trackBuffer.decodeQueue.insert(SampleMap::MapType::value_type(decodeTimestamp, sample));
+        trackBuffer.decodeQueue.insert(DecodeOrderSampleMap::MapType::value_type(decodeTimestamp, sample));
 
         // 1.18 Set last decode timestamp for track buffer to decode timestamp.
         trackBuffer.lastDecodeTimestamp = decodeTimestamp;
@@ -1479,8 +1479,8 @@
 
     TrackBuffer& trackBuffer = it->value;
     Vector<String> sampleDescriptions;
-    for (auto sampleIter = trackBuffer.samples.decodeBegin(); sampleIter != trackBuffer.samples.decodeEnd(); ++sampleIter)
-        sampleDescriptions.append(toString(*sampleIter->second));
+    for (auto& pair : trackBuffer.samples.decodeOrder())
+        sampleDescriptions.append(toString(*pair.second));
 
     return sampleDescriptions;
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to