2 * Copyright (C) 2013 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
29 #if ENABLE(MEDIA_SOURCE)
32 #include <wtf/MediaTime.h>
33 #include <wtf/RefPtr.h>
40 class PresentationOrderSampleMap {
41 friend class SampleMap;
43 typedef std::map<MediaTime, RefPtr<MediaSample>> MapType;
44 typedef MapType::iterator iterator;
45 typedef MapType::reverse_iterator reverse_iterator;
46 typedef std::pair<iterator, iterator> iterator_range;
48 iterator begin() { return m_samples.begin(); }
49 iterator end() { return m_samples.end(); }
50 reverse_iterator rbegin() { return m_samples.rbegin(); }
51 reverse_iterator rend() { return m_samples.rend(); }
53 iterator findSampleWithPresentationTime(const MediaTime&);
54 iterator findSampleContainingPresentationTime(const MediaTime&);
55 iterator findSampleOnOrAfterPresentationTime(const MediaTime&);
56 reverse_iterator reverseFindSampleContainingPresentationTime(const MediaTime&);
57 reverse_iterator reverseFindSampleBeforePresentationTime(const MediaTime&);
58 iterator_range findSamplesBetweenPresentationTimes(const MediaTime&, const MediaTime&);
59 iterator_range findSamplesWithinPresentationRange(const MediaTime&, const MediaTime&);
60 iterator_range findSamplesWithinPresentationRangeFromEnd(const MediaTime&, const MediaTime&);
66 class DecodeOrderSampleMap {
67 friend class SampleMap;
69 typedef std::pair<MediaTime, MediaTime> KeyType;
70 typedef std::map<KeyType, RefPtr<MediaSample>> MapType;
71 typedef MapType::iterator iterator;
72 typedef MapType::reverse_iterator reverse_iterator;
73 typedef std::pair<reverse_iterator, reverse_iterator> reverse_iterator_range;
75 iterator begin() { return m_samples.begin(); }
76 iterator end() { return m_samples.end(); }
77 reverse_iterator rbegin() { return m_samples.rbegin(); }
78 reverse_iterator rend() { return m_samples.rend(); }
80 iterator findSampleWithDecodeKey(const KeyType&);
81 reverse_iterator reverseFindSampleWithDecodeKey(const KeyType&);
82 reverse_iterator findSyncSamplePriorToPresentationTime(const MediaTime&, const MediaTime& threshold = MediaTime::positiveInfiniteTime());
83 reverse_iterator findSyncSamplePriorToDecodeIterator(reverse_iterator);
84 iterator findSyncSampleAfterPresentationTime(const MediaTime&, const MediaTime& threshold = MediaTime::positiveInfiniteTime());
85 iterator findSyncSampleAfterDecodeIterator(iterator);
86 reverse_iterator_range findDependentSamples(MediaSample*);
90 PresentationOrderSampleMap m_presentationOrder;
102 void addSample(MediaSample&);
103 void removeSample(MediaSample*);
104 size_t sizeInBytes() const { return m_totalSize; }
107 void addRange(I begin, I end);
109 DecodeOrderSampleMap& decodeOrder() { return m_decodeOrder; }
110 const DecodeOrderSampleMap& decodeOrder() const { return m_decodeOrder; }
111 PresentationOrderSampleMap& presentationOrder() { return m_decodeOrder.m_presentationOrder; }
112 const PresentationOrderSampleMap& presentationOrder() const { return m_decodeOrder.m_presentationOrder; }
115 DecodeOrderSampleMap m_decodeOrder;
120 void SampleMap::addRange(I begin, I end)
122 for (I iter = begin; iter != end; ++iter)
123 addSample(*iter->second);
130 #endif // SampleMap_h