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 "config.h" | 5 #include "config.h" |
6 #include "core/html/track/AutomaticTrackSelection.h" | 6 #include "core/html/track/AutomaticTrackSelection.h" |
7 | 7 |
8 #include "core/html/track/TextTrack.h" | 8 #include "core/html/track/TextTrack.h" |
9 #include "core/html/track/TextTrackList.h" | 9 #include "core/html/track/TextTrackList.h" |
10 #include "platform/Language.h" | 10 #include "platform/Language.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 return 0; | 55 return 0; |
56 | 56 |
57 return textTrackLanguageSelectionScore(track); | 57 return textTrackLanguageSelectionScore(track); |
58 } | 58 } |
59 | 59 |
60 AutomaticTrackSelection::AutomaticTrackSelection(const Configuration& configurat
ion) | 60 AutomaticTrackSelection::AutomaticTrackSelection(const Configuration& configurat
ion) |
61 : m_configuration(configuration) | 61 : m_configuration(configuration) |
62 { | 62 { |
63 } | 63 } |
64 | 64 |
| 65 const AtomicString& AutomaticTrackSelection::preferredTrackKind() const |
| 66 { |
| 67 if (m_configuration.textTrackKindUserPreference == TextTrackKindUserPreferen
ce::Subtitles) |
| 68 return TextTrack::subtitlesKeyword(); |
| 69 if (m_configuration.textTrackKindUserPreference == TextTrackKindUserPreferen
ce::Captions) |
| 70 return TextTrack::captionsKeyword(); |
| 71 return nullAtom; |
| 72 } |
| 73 |
65 void AutomaticTrackSelection::performAutomaticTextTrackSelection(const TrackGrou
p& group) | 74 void AutomaticTrackSelection::performAutomaticTextTrackSelection(const TrackGrou
p& group) |
66 { | 75 { |
67 ASSERT(group.tracks.size()); | 76 ASSERT(group.tracks.size()); |
68 | 77 |
69 // First, find the track in the group that should be enabled (if any). | 78 // First, find the track in the group that should be enabled (if any). |
70 WillBeHeapVector<RefPtrWillBeMember<TextTrack>> currentlyEnabledTracks; | 79 WillBeHeapVector<RefPtrWillBeMember<TextTrack>> currentlyEnabledTracks; |
71 RefPtrWillBeRawPtr<TextTrack> trackToEnable = nullptr; | 80 RefPtrWillBeRawPtr<TextTrack> trackToEnable = nullptr; |
72 RefPtrWillBeRawPtr<TextTrack> defaultTrack = nullptr; | 81 RefPtrWillBeRawPtr<TextTrack> defaultTrack = nullptr; |
| 82 RefPtrWillBeRawPtr<TextTrack> preferredTrack = nullptr; |
73 RefPtrWillBeRawPtr<TextTrack> fallbackTrack = nullptr; | 83 RefPtrWillBeRawPtr<TextTrack> fallbackTrack = nullptr; |
| 84 |
74 int highestTrackScore = 0; | 85 int highestTrackScore = 0; |
| 86 |
75 for (size_t i = 0; i < group.tracks.size(); ++i) { | 87 for (size_t i = 0; i < group.tracks.size(); ++i) { |
76 RefPtrWillBeRawPtr<TextTrack> textTrack = group.tracks[i]; | 88 RefPtrWillBeRawPtr<TextTrack> textTrack = group.tracks[i]; |
77 | 89 |
78 if (m_configuration.disableCurrentlyEnabledTracks && textTrack->mode() =
= TextTrack::showingKeyword()) | 90 if (m_configuration.disableCurrentlyEnabledTracks && textTrack->mode() =
= TextTrack::showingKeyword()) |
79 currentlyEnabledTracks.append(textTrack); | 91 currentlyEnabledTracks.append(textTrack); |
80 | 92 |
81 int trackScore = textTrackSelectionScore(*textTrack); | 93 int trackScore = textTrackSelectionScore(*textTrack); |
| 94 |
| 95 if (textTrack->kind() == preferredTrackKind()) |
| 96 trackScore += 1; |
82 if (trackScore) { | 97 if (trackScore) { |
83 // * If the text track kind is { [subtitles or captions] [descriptio
ns] } and the user has indicated an interest in having a | 98 // * If the text track kind is subtitles or captions and the user ha
s indicated an interest in having a |
84 // track with this text track kind, text track language, and text tr
ack label enabled, and there is no | 99 // track with this text track kind, text track language, and text tr
ack label enabled, and there is no |
85 // other text track in the media element's list of text tracks with
a text track kind of either subtitles | 100 // other text track in the media element's list of text tracks with
a text track kind of either subtitles |
86 // or captions whose text track mode is showing | 101 // or captions whose text track mode is showing |
87 // ... | |
88 // * If the text track kind is chapters and the text track language
is one that the user agent has reason | |
89 // to believe is appropriate for the user, and there is no other tex
t track in the media element's list of | |
90 // text tracks with a text track kind of chapters whose text track m
ode is showing | |
91 // Let the text track mode be showing. | 102 // Let the text track mode be showing. |
92 if (trackScore > highestTrackScore) { | 103 if (trackScore > highestTrackScore) { |
| 104 preferredTrack = textTrack; |
93 highestTrackScore = trackScore; | 105 highestTrackScore = trackScore; |
94 trackToEnable = textTrack; | |
95 } | 106 } |
96 | |
97 if (!defaultTrack && textTrack->isDefault()) | 107 if (!defaultTrack && textTrack->isDefault()) |
98 defaultTrack = textTrack; | 108 defaultTrack = textTrack; |
99 if (!defaultTrack && !fallbackTrack) | 109 |
| 110 if (!fallbackTrack) |
100 fallbackTrack = textTrack; | 111 fallbackTrack = textTrack; |
101 } else if (!group.visibleTrack && !defaultTrack && textTrack->isDefault(
)) { | 112 } else if (!group.visibleTrack && !defaultTrack && textTrack->isDefault(
)) { |
102 // * If the track element has a default attribute specified, and the
re is no other text track in the media | 113 // * If the track element has a default attribute specified, and the
re is no other text track in the media |
103 // element's list of text tracks whose text track mode is showing or
showing by default | 114 // element's list of text tracks whose text track mode is showing or
showing by default |
104 // Let the text track mode be showing by default. | 115 // Let the text track mode be showing by default. |
105 defaultTrack = textTrack; | 116 defaultTrack = textTrack; |
106 } | 117 } |
107 } | 118 } |
108 | 119 |
| 120 if (m_configuration.textTrackKindUserPreference != TextTrackKindUserPreferen
ce::Default) |
| 121 trackToEnable = preferredTrack; |
| 122 |
109 if (!trackToEnable && defaultTrack) | 123 if (!trackToEnable && defaultTrack) |
110 trackToEnable = defaultTrack; | 124 trackToEnable = defaultTrack; |
111 | 125 |
112 // If no track matches the user's preferred language and non was marked 'def
ault', enable the first track | 126 if (!trackToEnable && m_configuration.forceEnableSubtitleOrCaptionTrack && g
roup.kind == TrackGroup::CaptionsAndSubtitles) |
113 // because the user has explicitly stated a preference for this kind of trac
k. | 127 trackToEnable = fallbackTrack ? fallbackTrack : group.tracks[0]; |
114 if (!fallbackTrack && m_configuration.forceEnableSubtitleOrCaptionTrack && g
roup.kind == TrackGroup::CaptionsAndSubtitles) | |
115 fallbackTrack = group.tracks[0]; | |
116 | |
117 if (!trackToEnable && fallbackTrack) | |
118 trackToEnable = fallbackTrack; | |
119 | 128 |
120 if (currentlyEnabledTracks.size()) { | 129 if (currentlyEnabledTracks.size()) { |
121 for (size_t i = 0; i < currentlyEnabledTracks.size(); ++i) { | 130 for (size_t i = 0; i < currentlyEnabledTracks.size(); ++i) { |
122 RefPtrWillBeRawPtr<TextTrack> textTrack = currentlyEnabledTracks[i]; | 131 RefPtrWillBeRawPtr<TextTrack> textTrack = currentlyEnabledTracks[i]; |
123 if (textTrack != trackToEnable) | 132 if (textTrack != trackToEnable) |
124 textTrack->setMode(TextTrack::disabledKeyword()); | 133 textTrack->setMode(TextTrack::disabledKeyword()); |
125 } | 134 } |
126 } | 135 } |
127 | 136 |
128 if (trackToEnable) | 137 if (trackToEnable) |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 performAutomaticTextTrackSelection(captionAndSubtitleTracks); | 205 performAutomaticTextTrackSelection(captionAndSubtitleTracks); |
197 if (descriptionTracks.tracks.size()) | 206 if (descriptionTracks.tracks.size()) |
198 performAutomaticTextTrackSelection(descriptionTracks); | 207 performAutomaticTextTrackSelection(descriptionTracks); |
199 if (chapterTracks.tracks.size()) | 208 if (chapterTracks.tracks.size()) |
200 performAutomaticTextTrackSelection(chapterTracks); | 209 performAutomaticTextTrackSelection(chapterTracks); |
201 if (metadataTracks.tracks.size()) | 210 if (metadataTracks.tracks.size()) |
202 enableDefaultMetadataTextTracks(metadataTracks); | 211 enableDefaultMetadataTextTracks(metadataTracks); |
203 } | 212 } |
204 | 213 |
205 } // namespace blink | 214 } // namespace blink |
OLD | NEW |