Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef MEDIA_BASE_TEXT_RANGES_H_ | |
| 6 #define MEDIA_BASE_TEXT_RANGES_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 #include "base/time/time.h" | |
| 12 #include "media/base/media_export.h" | |
| 13 | |
| 14 namespace media { | |
| 15 | |
| 16 class MEDIA_EXPORT TextRanges { | |
|
acolwell GONE FROM CHROMIUM
2014/02/07 18:30:52
nit: Add class comment. Probably something around
Matthew Heaney (Chromium)
2014/02/07 18:49:07
Done.
| |
| 17 public: | |
| 18 TextRanges(); | |
| 19 | |
| 20 // Reset the current range pointer, such that we bind to a new range | |
| 21 // (either one that exists already, or one that is freshly-created) | |
| 22 // during the next AddCue(). | |
| 23 void Reset(); | |
| 24 | |
| 25 // Given a cue with starting timestamp |start_time|, add its start | |
| 26 // time to the time ranges. (Note that following a Reset(), cue | |
| 27 // times are assumed to be monotonically increasing.) If this time | |
| 28 // has already been added to the time ranges, then AddCue() returns | |
| 29 // false and clients should not push the cue downstream. Otherwise, | |
| 30 // the time is added to the time ranges and AddCue() returns true, | |
| 31 // meaning that the cue should be pushed downstream. | |
| 32 bool AddCue(base::TimeDelta start_time); | |
| 33 | |
| 34 // Returns a count of the number of time ranges, intended for use by | |
| 35 // the unit test module to vet proper time range merge behavior. | |
| 36 size_t RangeCountForTesting() const; | |
| 37 | |
| 38 private: | |
| 39 // Describes a range of times for cues that have already been | |
| 40 // pushed downstream. | |
| 41 class Range { | |
| 42 public: | |
| 43 // Initialize last_time count. | |
| 44 void ResetCount(base::TimeDelta start_time); | |
| 45 | |
| 46 // Set last_time and associated counts. | |
| 47 void SetLastTime(base::TimeDelta last_time); | |
| 48 | |
| 49 // Adjust time range state to mark the cue as having been seen, | |
| 50 // returning true if we have not seen |start_time| already and | |
| 51 // false otherwise. | |
| 52 bool AddCue(base::TimeDelta start_time); | |
| 53 | |
| 54 // Returns the value of the last time in the range. | |
| 55 base::TimeDelta last_time() const; | |
| 56 | |
| 57 private: | |
| 58 // The last timestamp of this range. | |
| 59 base::TimeDelta last_time_; | |
| 60 | |
| 61 // The number of cues we have detected so far, for this range, | |
| 62 // whose timestamp matches last_time. | |
| 63 int max_count_; | |
| 64 | |
| 65 // The number of cues we have seen since the most recent Reset(), | |
| 66 // whose timestamp matches last_time. | |
| 67 int count_; | |
| 68 }; | |
| 69 | |
| 70 typedef std::map<base::TimeDelta, Range> RangeMap; | |
| 71 | |
| 72 // NewRange() is used to create a new time range when AddCue() is | |
| 73 // called immediately following a Reset(), and no existing time | |
| 74 // range contains the indicated |start_time| of the cue. | |
| 75 void NewRange(base::TimeDelta start_time); | |
| 76 | |
| 77 // Coalesce curr_range with the range that immediately follows. | |
| 78 void Merge(Range& curr_range, const RangeMap::iterator& next_range_itr); | |
| 79 | |
| 80 // The collection of time ranges, each of which is bounded | |
| 81 // (inclusive) by the key and Range::last_time. | |
| 82 RangeMap range_map_; | |
| 83 | |
| 84 // The time range to which we bind following a Reset(). | |
| 85 RangeMap::iterator curr_range_itr_; | |
| 86 | |
| 87 DISALLOW_COPY_AND_ASSIGN(TextRanges); | |
| 88 }; | |
| 89 | |
| 90 } // namespace media | |
| 91 | |
| 92 #endif // MEDIA_BASE_TEXT_RANGES_H_ | |
| OLD | NEW |