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 { | |
| 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 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.
| |
| 42 // Initialize last_time count. | |
| 43 void ResetCount(base::TimeDelta start_time); | |
| 44 | |
| 45 // Set last_time and associated counts. | |
| 46 void SetLastTime(base::TimeDelta start_time); | |
| 47 | |
| 48 // Adjust time range state to mark the cue as having been seen, | |
| 49 // returning true if we have not seen |start_time| already and | |
| 50 // false otherwise. | |
| 51 bool AddCue(base::TimeDelta start_time); | |
| 52 | |
| 53 // The last timestamp of this range. | |
| 54 base::TimeDelta last_time; | |
| 55 | |
| 56 // The number of cues we have detected so far, for this range, | |
| 57 // whose timestamp matches last_time. | |
| 58 int max_count; | |
| 59 | |
| 60 // The number of cues we have seen since the most recent Reset(), | |
| 61 // whose timestamp matches last_time. | |
| 62 int count; | |
| 63 }; | |
| 64 | |
| 65 typedef std::map<base::TimeDelta, Range> RangeMap; | |
| 66 | |
| 67 // NewRange() is used to create a new time range when AddCue() is | |
| 68 // called immediately following a Reset(), and no existing time | |
| 69 // range contains the indicated |start_time| of the cue. | |
| 70 void NewRange(base::TimeDelta start_time); | |
| 71 | |
| 72 // Coalesce curr_range with the range that immediately follows. | |
| 73 void Merge(Range& curr_range, RangeMap::iterator next_range_itr); | |
| 74 | |
| 75 // The collection of time ranges, each of which is bounded | |
| 76 // (inclusive) by the key and Range::last_time. | |
| 77 RangeMap range_map_; | |
| 78 | |
| 79 // The time range to which we bind following a Reset(). | |
| 80 RangeMap::iterator curr_range_itr_; | |
| 81 | |
| 82 DISALLOW_COPY_AND_ASSIGN(TextRanges); | |
| 83 }; | |
| 84 | |
| 85 } // namespace media | |
| 86 | |
| 87 #endif // MEDIA_BASE_TEXT_RANGES_H_ | |
| OLD | NEW |