blob: cbfc68db7e8299959f0658c99c24a13aa09983c9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
// Copyright 2015 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 THIRD_PARTY_BLINK_RENDERER_CORE_HTML_TRACK_CUE_TIMELINE_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_HTML_TRACK_CUE_TIMELINE_H_
#include "third_party/blink/renderer/core/html/track/text_track_cue.h"
#include "third_party/blink/renderer/core/html/track/vtt/vtt_cue.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/wtf/pod_interval_tree.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"
namespace blink {
class HTMLMediaElement;
class TextTrackCueList;
// TODO(Oilpan): This needs to be PODIntervalTree<double, Member<TextTrackCue>>.
// However, it is not easy to move PODIntervalTree to the heap (for a
// C++-template reason) so we leave it as a raw pointer at the moment. This is
// safe because CueTimeline and TextTrackCue are guaranteed to die at the same
// time when the owner HTMLMediaElement dies. Thus the raw TextTrackCue* cannot
// become stale pointers.
typedef WTF::PODIntervalTree<double, TextTrackCue*> CueIntervalTree;
typedef CueIntervalTree::IntervalType CueInterval;
typedef Vector<CueInterval> CueList;
// This class manages the timeline and rendering updates of cues associated
// with TextTracks. Owned by a HTMLMediaElement.
class CueTimeline final : public GarbageCollected<CueTimeline> {
public:
CueTimeline(HTMLMediaElement&);
void AddCues(TextTrack*, const TextTrackCueList*);
void AddCue(TextTrack*, TextTrackCue*);
void RemoveCues(TextTrack*, const TextTrackCueList*);
void RemoveCue(TextTrack*, TextTrackCue*);
void HideCues(TextTrack*, const TextTrackCueList*);
void UpdateActiveCues(double);
bool IgnoreUpdateRequests() const { return ignore_update_ > 0; }
void BeginIgnoringUpdateRequests();
void EndIgnoringUpdateRequests();
const CueList& CurrentlyActiveCues() const { return currently_active_cues_; }
void Trace(Visitor*);
private:
HTMLMediaElement& MediaElement() const { return *media_element_; }
void AddCueInternal(TextTrackCue*);
void RemoveCueInternal(TextTrackCue*);
Member<HTMLMediaElement> media_element_;
CueIntervalTree cue_tree_;
CueList currently_active_cues_;
double last_update_time_;
int ignore_update_;
};
class TrackDisplayUpdateScope {
STACK_ALLOCATED();
public:
TrackDisplayUpdateScope(CueTimeline& cue_timeline)
: cue_timeline_(&cue_timeline) {
cue_timeline_->BeginIgnoringUpdateRequests();
}
~TrackDisplayUpdateScope() {
DCHECK(cue_timeline_);
cue_timeline_->EndIgnoringUpdateRequests();
}
private:
CueTimeline* cue_timeline_;
};
} // namespace blink
namespace WTF {
#ifndef NDEBUG
// Template specializations required by PodIntervalTree in debug mode.
template <>
struct ValueToString<blink::TextTrackCue*> {
static String ToString(blink::TextTrackCue* const& cue) {
return cue->ToString();
}
};
#endif
}
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_HTML_TRACK_CUE_TIMELINE_H_
|