Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(498)

Side by Side Diff: media/base/ranges.h

Issue 10829108: Cap sourceBuffered() on duration and truncate duration on EoS (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase ToT Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/base/demuxer_stream.h ('k') | media/filters/chunk_demuxer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MEDIA_BASE_RANGES_H_ 5 #ifndef MEDIA_BASE_RANGES_H_
6 #define MEDIA_BASE_RANGES_H_ 6 #define MEDIA_BASE_RANGES_H_
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <ostream> 9 #include <ostream>
10 #include <vector> 10 #include <vector>
(...skipping 21 matching lines...) Expand all
32 size_t size() const; 32 size_t size() const;
33 33
34 // Return the "i"'th range's start & end (0-based). 34 // Return the "i"'th range's start & end (0-based).
35 T start(int i) const; 35 T start(int i) const;
36 T end(int i) const; 36 T end(int i) const;
37 37
38 // Clear all ranges. 38 // Clear all ranges.
39 void clear(); 39 void clear();
40 40
41 // Computes the intersection between this range and |other|. 41 // Computes the intersection between this range and |other|.
42 Ranges<T> IntersectionWith(const Ranges<T>& other); 42 Ranges<T> IntersectionWith(const Ranges<T>& other) const;
43 43
44 private: 44 private:
45 // Wrapper around DCHECK_LT allowing comparisons of operator<<'able T's. 45 // Wrapper around DCHECK_LT allowing comparisons of operator<<'able T's.
46 void DCheckLT(const T& lhs, const T& rhs) const; 46 void DCheckLT(const T& lhs, const T& rhs) const;
47 47
48 // Disjoint, in increasing order of start. 48 // Disjoint, in increasing order of start.
49 std::vector<std::pair<T, T> > ranges_; 49 std::vector<std::pair<T, T> > ranges_;
50 }; 50 };
51 51
52 ////////////////////////////////////////////////////////////////////// 52 //////////////////////////////////////////////////////////////////////
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 T Ranges<T>::end(int i) const { 126 T Ranges<T>::end(int i) const {
127 return ranges_[i].second; 127 return ranges_[i].second;
128 } 128 }
129 129
130 template<class T> 130 template<class T>
131 void Ranges<T>::clear() { 131 void Ranges<T>::clear() {
132 ranges_.clear(); 132 ranges_.clear();
133 } 133 }
134 134
135 template<class T> 135 template<class T>
136 Ranges<T> Ranges<T>::IntersectionWith(const Ranges<T>& other) { 136 Ranges<T> Ranges<T>::IntersectionWith(const Ranges<T>& other) const {
137 Ranges<T> result; 137 Ranges<T> result;
138 138
139 size_t i = 0; 139 size_t i = 0;
140 size_t j = 0; 140 size_t j = 0;
141 141
142 while (i < size() && j < other.size()) { 142 while (i < size() && j < other.size()) {
143 T max_start = std::max(start(i), other.start(j)); 143 T max_start = std::max(start(i), other.start(j));
144 T min_end = std::min(end(i), other.end(j)); 144 T min_end = std::min(end(i), other.end(j));
145 145
146 // Add an intersection range to the result if the ranges overlap. 146 // Add an intersection range to the result if the ranges overlap.
147 if (max_start < min_end) 147 if (max_start < min_end)
148 result.Add(max_start, min_end); 148 result.Add(max_start, min_end);
149 149
150 if (end(i) < other.end(j)) 150 if (end(i) < other.end(j))
151 ++i; 151 ++i;
152 else 152 else
153 ++j; 153 ++j;
154 } 154 }
155 155
156 return result; 156 return result;
157 } 157 }
158 158
159 } // namespace media 159 } // namespace media
160 160
161 #endif // MEDIA_BASE_RANGES_H_ 161 #endif // MEDIA_BASE_RANGES_H_
OLDNEW
« no previous file with comments | « media/base/demuxer_stream.h ('k') | media/filters/chunk_demuxer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698