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

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: Changed everything to use media::Ranges. 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') | media/base/ranges_unittest.cc » ('J')
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..fb8c476cb01a2904466d36be1851f0ccfea79a15 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,35 @@ void Ranges<T>::clear() {
ranges_.clear();
}
+template<class T>
+Ranges<T> Ranges<T>::IntersectionWith(const Ranges<T>& other) {
+ Ranges<T> result;
+
+ if (!size() || !other.size())
Ami GONE FROM CHROMIUM 2012/06/19 17:40:37 Unnecessary?
acolwell GONE FROM CHROMIUM 2012/06/19 19:50:15 Done.
+ return 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)) {
Ami GONE FROM CHROMIUM 2012/06/19 17:40:37 l.140-146 would be shorter and clearer, IMO, as: i
acolwell GONE FROM CHROMIUM 2012/06/19 19:50:15 Done.
+ i++;
+ continue;
+ }
+
+ j++;
+ }
+
+ return result;
+}
+
} // namespace media
#endif // MEDIA_BASE_RANGES_H_
« no previous file with comments | « no previous file | media/base/ranges_unittest.cc » ('j') | media/base/ranges_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698