1 | /* |
2 | * Copyright (C) 2012-2017 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #include "config.h" |
27 | #include "InbandTextTrack.h" |
28 | |
29 | #if ENABLE(VIDEO_TRACK) |
30 | |
31 | #include "HTMLMediaElement.h" |
32 | #include "InbandDataTextTrack.h" |
33 | #include "InbandGenericTextTrack.h" |
34 | #include "InbandTextTrackPrivate.h" |
35 | #include "InbandWebVTTTextTrack.h" |
36 | #include <wtf/IsoMallocInlines.h> |
37 | |
38 | namespace WebCore { |
39 | |
40 | WTF_MAKE_ISO_ALLOCATED_IMPL(InbandTextTrack); |
41 | |
42 | Ref<InbandTextTrack> InbandTextTrack::create(ScriptExecutionContext& context, TextTrackClient& client, InbandTextTrackPrivate& trackPrivate) |
43 | { |
44 | switch (trackPrivate.cueFormat()) { |
45 | case InbandTextTrackPrivate::Data: |
46 | return InbandDataTextTrack::create(context, client, trackPrivate); |
47 | case InbandTextTrackPrivate::Generic: |
48 | return InbandGenericTextTrack::create(context, client, trackPrivate); |
49 | case InbandTextTrackPrivate::WebVTT: |
50 | return InbandWebVTTTextTrack::create(context, client, trackPrivate); |
51 | } |
52 | ASSERT_NOT_REACHED(); |
53 | return InbandDataTextTrack::create(context, client, trackPrivate); |
54 | } |
55 | |
56 | InbandTextTrack::InbandTextTrack(ScriptExecutionContext& context, TextTrackClient& client, InbandTextTrackPrivate& trackPrivate) |
57 | : TextTrack(&context, &client, emptyAtom(), trackPrivate.id(), trackPrivate.label(), trackPrivate.language(), InBand) |
58 | , m_private(trackPrivate) |
59 | { |
60 | #if !RELEASE_LOG_DISABLED |
61 | m_private->setLogger(logger(), logIdentifier()); |
62 | #endif |
63 | m_private->setClient(this); |
64 | updateKindFromPrivate(); |
65 | } |
66 | |
67 | InbandTextTrack::~InbandTextTrack() |
68 | { |
69 | m_private->setClient(nullptr); |
70 | } |
71 | |
72 | void InbandTextTrack::setPrivate(InbandTextTrackPrivate& trackPrivate) |
73 | { |
74 | if (m_private.ptr() == &trackPrivate) |
75 | return; |
76 | |
77 | m_private->setClient(nullptr); |
78 | m_private = trackPrivate; |
79 | m_private->setClient(this); |
80 | |
81 | setModeInternal(mode()); |
82 | updateKindFromPrivate(); |
83 | } |
84 | |
85 | void InbandTextTrack::setMode(Mode mode) |
86 | { |
87 | TextTrack::setMode(mode); |
88 | setModeInternal(mode); |
89 | } |
90 | |
91 | static inline InbandTextTrackPrivate::Mode toPrivate(TextTrack::Mode mode) |
92 | { |
93 | switch (mode) { |
94 | case TextTrack::Mode::Disabled: |
95 | return InbandTextTrackPrivate::Disabled; |
96 | case TextTrack::Mode::Hidden: |
97 | return InbandTextTrackPrivate::Hidden; |
98 | case TextTrack::Mode::Showing: |
99 | return InbandTextTrackPrivate::Showing; |
100 | } |
101 | ASSERT_NOT_REACHED(); |
102 | return InbandTextTrackPrivate::Disabled; |
103 | } |
104 | |
105 | void InbandTextTrack::setModeInternal(Mode mode) |
106 | { |
107 | m_private->setMode(toPrivate(mode)); |
108 | } |
109 | |
110 | bool InbandTextTrack::isClosedCaptions() const |
111 | { |
112 | return m_private->isClosedCaptions(); |
113 | } |
114 | |
115 | bool InbandTextTrack::isSDH() const |
116 | { |
117 | return m_private->isSDH(); |
118 | } |
119 | |
120 | bool InbandTextTrack::containsOnlyForcedSubtitles() const |
121 | { |
122 | return m_private->containsOnlyForcedSubtitles(); |
123 | } |
124 | |
125 | bool InbandTextTrack::isMainProgramContent() const |
126 | { |
127 | return m_private->isMainProgramContent(); |
128 | } |
129 | |
130 | bool InbandTextTrack::isEasyToRead() const |
131 | { |
132 | return m_private->isEasyToRead(); |
133 | } |
134 | |
135 | size_t InbandTextTrack::inbandTrackIndex() |
136 | { |
137 | return m_private->trackIndex(); |
138 | } |
139 | |
140 | AtomicString InbandTextTrack::inBandMetadataTrackDispatchType() const |
141 | { |
142 | return m_private->inBandMetadataTrackDispatchType(); |
143 | } |
144 | |
145 | void InbandTextTrack::idChanged(const AtomicString& id) |
146 | { |
147 | setId(id); |
148 | } |
149 | |
150 | void InbandTextTrack::labelChanged(const AtomicString& label) |
151 | { |
152 | setLabel(label); |
153 | } |
154 | |
155 | void InbandTextTrack::languageChanged(const AtomicString& language) |
156 | { |
157 | setLanguage(language); |
158 | } |
159 | |
160 | void InbandTextTrack::willRemove() |
161 | { |
162 | auto element = makeRefPtr(mediaElement()); |
163 | if (!element) |
164 | return; |
165 | element->removeTextTrack(*this); |
166 | } |
167 | |
168 | void InbandTextTrack::updateKindFromPrivate() |
169 | { |
170 | switch (m_private->kind()) { |
171 | case InbandTextTrackPrivate::Subtitles: |
172 | setKind(Kind::Subtitles); |
173 | return; |
174 | case InbandTextTrackPrivate::Captions: |
175 | setKind(Kind::Captions); |
176 | return; |
177 | case InbandTextTrackPrivate::Descriptions: |
178 | setKind(Kind::Descriptions); |
179 | return; |
180 | case InbandTextTrackPrivate::Chapters: |
181 | setKind(Kind::Chapters); |
182 | return; |
183 | case InbandTextTrackPrivate::Metadata: |
184 | setKind(Kind::Metadata); |
185 | return; |
186 | case InbandTextTrackPrivate::Forced: |
187 | setKind(Kind::Forced); |
188 | return; |
189 | case InbandTextTrackPrivate::None: |
190 | break; |
191 | } |
192 | ASSERT_NOT_REACHED(); |
193 | } |
194 | |
195 | MediaTime InbandTextTrack::startTimeVariance() const |
196 | { |
197 | return m_private->startTimeVariance(); |
198 | } |
199 | |
200 | void InbandTextTrack::setMediaElement(HTMLMediaElement* element) |
201 | { |
202 | TrackBase::setMediaElement(element); |
203 | #if !RELEASE_LOG_DISABLED |
204 | m_private->setLogger(logger(), logIdentifier()); |
205 | #endif |
206 | } |
207 | |
208 | |
209 | } // namespace WebCore |
210 | |
211 | #endif |
212 | |