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

Unified Diff: media/base/ranges.h

Issue 10704142: Merge 143765 - Ensure media's buffered ranges always have a range that includes currentTime. (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1180/src/
Patch Set: Created 8 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/base/pipeline_unittest.cc ('k') | media/filters/chunk_demuxer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/ranges.h
===================================================================
--- media/base/ranges.h (revision 145962)
+++ media/base/ranges.h (working copy)
@@ -10,6 +10,7 @@
#include "base/basictypes.h"
#include "base/logging.h"
+#include "base/time.h"
#include "media/base/media_export.h"
namespace media {
@@ -36,7 +37,13 @@
// Clear all ranges.
void clear();
+ // Computes the intersection between this range and |other|.
+ Ranges<T> IntersectionWith(const Ranges<T>& other);
+
private:
+ // Wrapper around DCHECK_LT allowing comparisons of operator<<'able T's.
+ void DCheckLT(const T& lhs, const T& rhs) const;
+
// Disjoint, in increasing order of start.
std::vector<std::pair<T, T> > ranges_;
};
@@ -50,7 +57,7 @@
if (start == end) // Nothing to be done with empty ranges.
return ranges_.size();
- DCHECK(start < end);
+ DCheckLT(start, end);
size_t i;
// Walk along the array of ranges until |start| is no longer larger than the
// current interval's end.
@@ -95,7 +102,16 @@
return ranges_.size();
}
+template<>
+void Ranges<base::TimeDelta>::DCheckLT(const base::TimeDelta& lhs,
+ const base::TimeDelta& rhs) const;
+
template<class T>
+void Ranges<T>::DCheckLT(const T& lhs, const T& rhs) const {
+ DCHECK_LT(lhs, rhs);
+}
+
+template<class T>
size_t Ranges<T>::size() const {
return ranges_.size();
}
@@ -115,6 +131,30 @@
ranges_.clear();
}
+template<class T>
+Ranges<T> Ranges<T>::IntersectionWith(const Ranges<T>& other) {
+ Ranges<T> result;
+
+ size_t i = 0;
+ size_t j = 0;
+
+ while (i < size() && j < other.size()) {
+ T max_start = std::max(start(i), other.start(j));
+ T min_end = std::min(end(i), other.end(j));
+
+ // Add an intersection range to the result if the ranges overlap.
+ if (max_start < min_end)
+ result.Add(max_start, min_end);
+
+ if (end(i) < other.end(j))
+ ++i;
+ else
+ ++j;
+ }
+
+ return result;
+}
+
} // namespace media
#endif // MEDIA_BASE_RANGES_H_
« no previous file with comments | « media/base/pipeline_unittest.cc ('k') | media/filters/chunk_demuxer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698