OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/html/track/CueTimeline.h" | 5 #include "core/html/track/CueTimeline.h" |
6 | 6 |
7 #include "core/events/Event.h" | 7 #include "core/events/Event.h" |
8 #include "core/html/HTMLMediaElement.h" | 8 #include "core/html/HTMLMediaElement.h" |
9 #include "core/html/HTMLTrackElement.h" | 9 #include "core/html/HTMLTrackElement.h" |
10 #include "core/html/track/LoadableTextTrack.h" | 10 #include "core/html/track/LoadableTextTrack.h" |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 // end times are less than or equal to the current playback position. | 164 // end times are less than or equal to the current playback position. |
165 // Otherwise, let missed cues be an empty list. | 165 // Otherwise, let missed cues be an empty list. |
166 if (lastTime >= 0 && lastSeekTime < movieTime) { | 166 if (lastTime >= 0 && lastSeekTime < movieTime) { |
167 CueList potentiallySkippedCues = | 167 CueList potentiallySkippedCues = |
168 m_cueTree.allOverlaps(m_cueTree.createInterval(lastTime, movieTime)); | 168 m_cueTree.allOverlaps(m_cueTree.createInterval(lastTime, movieTime)); |
169 | 169 |
170 for (CueInterval cue : potentiallySkippedCues) { | 170 for (CueInterval cue : potentiallySkippedCues) { |
171 // Consider cues that may have been missed since the last seek time. | 171 // Consider cues that may have been missed since the last seek time. |
172 if (cue.low() > std::max(lastSeekTime, lastTime) && | 172 if (cue.low() > std::max(lastSeekTime, lastTime) && |
173 cue.high() < movieTime) | 173 cue.high() < movieTime) |
174 missedCues.append(cue); | 174 missedCues.push_back(cue); |
175 } | 175 } |
176 } | 176 } |
177 | 177 |
178 m_lastUpdateTime = movieTime; | 178 m_lastUpdateTime = movieTime; |
179 | 179 |
180 // 5 - If the time was reached through the usual monotonic increase of the | 180 // 5 - If the time was reached through the usual monotonic increase of the |
181 // current playback position during normal playback, and if the user agent | 181 // current playback position during normal playback, and if the user agent |
182 // has not fired a timeupdate event at the element in the past 15 to 250ms | 182 // has not fired a timeupdate event at the element in the past 15 to 250ms |
183 // and is not still running event handlers for such an event, then the user | 183 // and is not still running event handlers for such an event, then the user |
184 // agent must queue a task to fire a simple event named timeupdate at the | 184 // agent must queue a task to fire a simple event named timeupdate at the |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 // list will be associated with a text track, a text track cue, and a time, | 238 // list will be associated with a text track, a text track cue, and a time, |
239 // which are used to sort the list before the tasks are queued. | 239 // which are used to sort the list before the tasks are queued. |
240 HeapVector<std::pair<double, Member<TextTrackCue>>> eventTasks; | 240 HeapVector<std::pair<double, Member<TextTrackCue>>> eventTasks; |
241 | 241 |
242 // 8 - Let affected tracks be a list of text tracks, initially empty. | 242 // 8 - Let affected tracks be a list of text tracks, initially empty. |
243 HeapVector<Member<TextTrack>> affectedTracks; | 243 HeapVector<Member<TextTrack>> affectedTracks; |
244 | 244 |
245 for (const auto& missedCue : missedCues) { | 245 for (const auto& missedCue : missedCues) { |
246 // 9 - For each text track cue in missed cues, prepare an event named enter | 246 // 9 - For each text track cue in missed cues, prepare an event named enter |
247 // for the TextTrackCue object with the text track cue start time. | 247 // for the TextTrackCue object with the text track cue start time. |
248 eventTasks.append( | 248 eventTasks.push_back( |
249 std::make_pair(missedCue.data()->startTime(), missedCue.data())); | 249 std::make_pair(missedCue.data()->startTime(), missedCue.data())); |
250 | 250 |
251 // 10 - For each text track [...] in missed cues, prepare an event | 251 // 10 - For each text track [...] in missed cues, prepare an event |
252 // named exit for the TextTrackCue object with the with the later of | 252 // named exit for the TextTrackCue object with the with the later of |
253 // the text track cue end time and the text track cue start time. | 253 // the text track cue end time and the text track cue start time. |
254 | 254 |
255 // Note: An explicit task is added only if the cue is NOT a zero or | 255 // Note: An explicit task is added only if the cue is NOT a zero or |
256 // negative length cue. Otherwise, the need for an exit event is | 256 // negative length cue. Otherwise, the need for an exit event is |
257 // checked when these tasks are actually queued below. This doesn't | 257 // checked when these tasks are actually queued below. This doesn't |
258 // affect sorting events before dispatch either, because the exit | 258 // affect sorting events before dispatch either, because the exit |
259 // event has the same time as the enter event. | 259 // event has the same time as the enter event. |
260 if (missedCue.data()->startTime() < missedCue.data()->endTime()) { | 260 if (missedCue.data()->startTime() < missedCue.data()->endTime()) { |
261 eventTasks.append( | 261 eventTasks.push_back( |
262 std::make_pair(missedCue.data()->endTime(), missedCue.data())); | 262 std::make_pair(missedCue.data()->endTime(), missedCue.data())); |
263 } | 263 } |
264 } | 264 } |
265 | 265 |
266 for (const auto& previousCue : previousCues) { | 266 for (const auto& previousCue : previousCues) { |
267 // 10 - For each text track cue in other cues that has its text | 267 // 10 - For each text track cue in other cues that has its text |
268 // track cue active flag set prepare an event named exit for the | 268 // track cue active flag set prepare an event named exit for the |
269 // TextTrackCue object with the text track cue end time. | 269 // TextTrackCue object with the text track cue end time. |
270 if (!currentCues.contains(previousCue)) { | 270 if (!currentCues.contains(previousCue)) { |
271 eventTasks.append( | 271 eventTasks.push_back( |
272 std::make_pair(previousCue.data()->endTime(), previousCue.data())); | 272 std::make_pair(previousCue.data()->endTime(), previousCue.data())); |
273 } | 273 } |
274 } | 274 } |
275 | 275 |
276 for (const auto& currentCue : currentCues) { | 276 for (const auto& currentCue : currentCues) { |
277 // 11 - For each text track cue in current cues that does not have its | 277 // 11 - For each text track cue in current cues that does not have its |
278 // text track cue active flag set, prepare an event named enter for the | 278 // text track cue active flag set, prepare an event named enter for the |
279 // TextTrackCue object with the text track cue start time. | 279 // TextTrackCue object with the text track cue start time. |
280 if (!previousCues.contains(currentCue)) { | 280 if (!previousCues.contains(currentCue)) { |
281 eventTasks.append( | 281 eventTasks.push_back( |
282 std::make_pair(currentCue.data()->startTime(), currentCue.data())); | 282 std::make_pair(currentCue.data()->startTime(), currentCue.data())); |
283 } | 283 } |
284 } | 284 } |
285 | 285 |
286 // 12 - Sort the tasks in events in ascending time order (tasks with earlier | 286 // 12 - Sort the tasks in events in ascending time order (tasks with earlier |
287 // times first). | 287 // times first). |
288 nonCopyingSort(eventTasks.begin(), eventTasks.end(), eventTimeCueCompare); | 288 nonCopyingSort(eventTasks.begin(), eventTasks.end(), eventTimeCueCompare); |
289 | 289 |
290 for (const auto& task : eventTasks) { | 290 for (const auto& task : eventTasks) { |
291 if (!affectedTracks.contains(task.second->track())) | 291 if (!affectedTracks.contains(task.second->track())) |
292 affectedTracks.append(task.second->track()); | 292 affectedTracks.push_back(task.second->track()); |
293 | 293 |
294 // 13 - Queue each task in events, in list order. | 294 // 13 - Queue each task in events, in list order. |
295 | 295 |
296 // Each event in eventTasks may be either an enterEvent or an exitEvent, | 296 // Each event in eventTasks may be either an enterEvent or an exitEvent, |
297 // depending on the time that is associated with the event. This | 297 // depending on the time that is associated with the event. This |
298 // correctly identifies the type of the event, if the startTime is | 298 // correctly identifies the type of the event, if the startTime is |
299 // less than the endTime in the cue. | 299 // less than the endTime in the cue. |
300 if (task.second->startTime() >= task.second->endTime()) { | 300 if (task.second->startTime() >= task.second->endTime()) { |
301 mediaElement.scheduleEvent( | 301 mediaElement.scheduleEvent( |
302 createEventWithTarget(EventTypeNames::enter, task.second.get())); | 302 createEventWithTarget(EventTypeNames::enter, task.second.get())); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 --m_ignoreUpdate; | 362 --m_ignoreUpdate; |
363 if (!m_ignoreUpdate) | 363 if (!m_ignoreUpdate) |
364 updateActiveCues(mediaElement().currentTime()); | 364 updateActiveCues(mediaElement().currentTime()); |
365 } | 365 } |
366 | 366 |
367 DEFINE_TRACE(CueTimeline) { | 367 DEFINE_TRACE(CueTimeline) { |
368 visitor->trace(m_mediaElement); | 368 visitor->trace(m_mediaElement); |
369 } | 369 } |
370 | 370 |
371 } // namespace blink | 371 } // namespace blink |
OLD | NEW |