Index: media/base/text_ranges.h |
diff --git a/media/base/text_ranges.h b/media/base/text_ranges.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..fe35d73ee3be1aaac57f0bb7a6387fcca5782d5a |
--- /dev/null |
+++ b/media/base/text_ranges.h |
@@ -0,0 +1,87 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef MEDIA_BASE_TEXT_RANGES_H_ |
+#define MEDIA_BASE_TEXT_RANGES_H_ |
+ |
+#include <map> |
+ |
+#include "base/macros.h" |
+#include "base/time/time.h" |
+#include "media/base/media_export.h" |
+ |
+namespace media { |
+ |
+class MEDIA_EXPORT TextRanges { |
+ public: |
+ TextRanges(); |
+ |
+ // Reset the current range pointer, such that we bind to a new range |
+ // (either one that exists already, or one that is freshly-created) |
+ // during the next AddCue(). |
+ void Reset(); |
+ |
+ // Given a cue with starting timestamp |start_time|, add its start |
+ // time to the time ranges. (Note that following a Reset(), cue |
+ // times are assumed to be monotonically increasing.) If this time |
+ // has already been added to the time ranges, then AddCue() returns |
+ // false and clients should not push the cue downstream. Otherwise, |
+ // the time is added to the time ranges and AddCue() returns true, |
+ // meaning that the cue should be pushed downstream. |
+ bool AddCue(base::TimeDelta start_time); |
+ |
+ // Returns a count of the number of time ranges, intended for use by |
+ // the unit test module to vet proper time range merge behavior. |
+ size_t RangeCountForTesting() const; |
+ |
+ private: |
+ // Describes a range of times for cues that have already been |
+ // pushed downstream. |
+ struct Range { |
acolwell GONE FROM CHROMIUM
2014/02/07 01:44:18
Convert this to class. Make all the methods public
Matthew Heaney (Chromium)
2014/02/07 03:24:35
Done.
|
+ // Initialize last_time count. |
+ void ResetCount(base::TimeDelta start_time); |
+ |
+ // Set last_time and associated counts. |
+ void SetLastTime(base::TimeDelta start_time); |
+ |
+ // Adjust time range state to mark the cue as having been seen, |
+ // returning true if we have not seen |start_time| already and |
+ // false otherwise. |
+ bool AddCue(base::TimeDelta start_time); |
+ |
+ // The last timestamp of this range. |
+ base::TimeDelta last_time; |
+ |
+ // The number of cues we have detected so far, for this range, |
+ // whose timestamp matches last_time. |
+ int max_count; |
+ |
+ // The number of cues we have seen since the most recent Reset(), |
+ // whose timestamp matches last_time. |
+ int count; |
+ }; |
+ |
+ typedef std::map<base::TimeDelta, Range> RangeMap; |
+ |
+ // NewRange() is used to create a new time range when AddCue() is |
+ // called immediately following a Reset(), and no existing time |
+ // range contains the indicated |start_time| of the cue. |
+ void NewRange(base::TimeDelta start_time); |
+ |
+ // Coalesce curr_range with the range that immediately follows. |
+ void Merge(Range& curr_range, RangeMap::iterator next_range_itr); |
+ |
+ // The collection of time ranges, each of which is bounded |
+ // (inclusive) by the key and Range::last_time. |
+ RangeMap range_map_; |
+ |
+ // The time range to which we bind following a Reset(). |
+ RangeMap::iterator curr_range_itr_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(TextRanges); |
+}; |
+ |
+} // namespace media |
+ |
+#endif // MEDIA_BASE_TEXT_RANGES_H_ |