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

Unified Diff: media/base/ranges.h

Issue 10558011: Fix ChunkDemuxer so it properly outputs buffered ranges. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address more CR comments and added an end of stream test case. Created 8 years, 6 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 | « no previous file | media/base/ranges_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/ranges.h
diff --git a/media/base/ranges.h b/media/base/ranges.h
index c412b259b8ced5e73b434f4a99196c0f836c6e0c..1117ae58b8db86321df815f07f1646d996f3a299 100644
--- a/media/base/ranges.h
+++ b/media/base/ranges.h
@@ -5,6 +5,7 @@
#ifndef MEDIA_BASE_RANGES_H_
#define MEDIA_BASE_RANGES_H_
+#include <algorithm>
#include <ostream>
#include <vector>
@@ -36,6 +37,9 @@ class Ranges {
// Clear all ranges.
void clear();
+ // Computes the intersection between this range and |other|.
+ Ranges<T> IntersectionWith(const Ranges<T>& other);
+
private:
// Disjoint, in increasing order of start.
std::vector<std::pair<T, T> > ranges_;
@@ -115,6 +119,30 @@ void Ranges<T>::clear() {
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 | « no previous file | media/base/ranges_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698