| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2009, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2009, 2010 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 return m_ranges[index].m_end; | 125 return m_ranges[index].m_end; |
| 126 } | 126 } |
| 127 | 127 |
| 128 void TimeRanges::add(double start, double end) { | 128 void TimeRanges::add(double start, double end) { |
| 129 DCHECK_LE(start, end); | 129 DCHECK_LE(start, end); |
| 130 unsigned overlappingArcIndex; | 130 unsigned overlappingArcIndex; |
| 131 Range addedRange(start, end); | 131 Range addedRange(start, end); |
| 132 | 132 |
| 133 // For each present range check if we need to: | 133 // For each present range check if we need to: |
| 134 // - merge with the added range, in case we are overlapping or contiguous | 134 // - merge with the added range, in case we are overlapping or contiguous |
| 135 // - Need to insert in place, we we are completely, not overlapping and not co
ntiguous | 135 // - Need to insert in place, we we are completely, not overlapping and not |
| 136 // in between two ranges. | 136 // contiguous in between two ranges. |
| 137 // | 137 // |
| 138 // TODO: Given that we assume that ranges are correctly ordered, this could be
optimized. | 138 // TODO: Given that we assume that ranges are correctly ordered, this could be |
| 139 // optimized. |
| 139 | 140 |
| 140 for (overlappingArcIndex = 0; overlappingArcIndex < m_ranges.size(); | 141 for (overlappingArcIndex = 0; overlappingArcIndex < m_ranges.size(); |
| 141 overlappingArcIndex++) { | 142 overlappingArcIndex++) { |
| 142 if (addedRange.isOverlappingRange(m_ranges[overlappingArcIndex]) || | 143 if (addedRange.isOverlappingRange(m_ranges[overlappingArcIndex]) || |
| 143 addedRange.isContiguousWithRange(m_ranges[overlappingArcIndex])) { | 144 addedRange.isContiguousWithRange(m_ranges[overlappingArcIndex])) { |
| 144 // We need to merge the addedRange and that range. | 145 // We need to merge the addedRange and that range. |
| 145 addedRange = addedRange.unionWithOverlappingOrContiguousRange( | 146 addedRange = addedRange.unionWithOverlappingOrContiguousRange( |
| 146 m_ranges[overlappingArcIndex]); | 147 m_ranges[overlappingArcIndex]); |
| 147 m_ranges.remove(overlappingArcIndex); | 148 m_ranges.remove(overlappingArcIndex); |
| 148 overlappingArcIndex--; | 149 overlappingArcIndex--; |
| 149 } else { | 150 } else { |
| 150 // Check the case for which there is no more to do | 151 // Check the case for which there is no more to do |
| 151 if (!overlappingArcIndex) { | 152 if (!overlappingArcIndex) { |
| 152 if (addedRange.isBeforeRange(m_ranges[0])) { | 153 if (addedRange.isBeforeRange(m_ranges[0])) { |
| 153 // First index, and we are completely before that range (and not conti
guous, nor overlapping). | 154 // First index, and we are completely before that range (and not |
| 154 // We just need to be inserted here. | 155 // contiguous, nor overlapping). We just need to be inserted here. |
| 155 break; | 156 break; |
| 156 } | 157 } |
| 157 } else { | 158 } else { |
| 158 if (m_ranges[overlappingArcIndex - 1].isBeforeRange(addedRange) && | 159 if (m_ranges[overlappingArcIndex - 1].isBeforeRange(addedRange) && |
| 159 addedRange.isBeforeRange(m_ranges[overlappingArcIndex])) { | 160 addedRange.isBeforeRange(m_ranges[overlappingArcIndex])) { |
| 160 // We are exactly after the current previous range, and before the cur
rent range, while | 161 // We are exactly after the current previous range, and before the |
| 161 // not overlapping with none of them. Insert here. | 162 // current range, while not overlapping with none of them. Insert |
| 163 // here. |
| 162 break; | 164 break; |
| 163 } | 165 } |
| 164 } | 166 } |
| 165 } | 167 } |
| 166 } | 168 } |
| 167 | 169 |
| 168 // Now that we are sure we don't overlap with any range, just add it. | 170 // Now that we are sure we don't overlap with any range, just add it. |
| 169 m_ranges.insert(overlappingArcIndex, addedRange); | 171 m_ranges.insert(overlappingArcIndex, addedRange); |
| 170 } | 172 } |
| 171 | 173 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 200 if (delta < bestDelta || | 202 if (delta < bestDelta || |
| 201 (delta == bestDelta && | 203 (delta == bestDelta && |
| 202 std::abs(currentPlaybackPosition - match) < | 204 std::abs(currentPlaybackPosition - match) < |
| 203 std::abs(currentPlaybackPosition - bestMatch))) { | 205 std::abs(currentPlaybackPosition - bestMatch))) { |
| 204 bestDelta = delta; | 206 bestDelta = delta; |
| 205 bestMatch = match; | 207 bestMatch = match; |
| 206 } | 208 } |
| 207 } | 209 } |
| 208 return bestMatch; | 210 return bestMatch; |
| 209 } | 211 } |
| OLD | NEW |