Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Side by Side Diff: Source/core/html/track/AutomaticTrackSelection.cpp

Issue 1118613002: Hook up Android closed captions 'enabled' setting to Blink (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Prioritize language over kind in auto track selection Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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()
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 textTrack->setMode(TextTrack::disabledKeyword());
fs 2015/07/07 08:22:05 Nit: Restore this test.
srivats 2015/07/07 18:44:49 Done.
124 textTrack->setMode(TextTrack::disabledKeyword());
125 } 133 }
126 } 134 }
127 135
128 if (trackToEnable) 136 if (trackToEnable)
129 trackToEnable->setMode(TextTrack::showingKeyword()); 137 trackToEnable->setMode(TextTrack::showingKeyword());
130 } 138 }
131 139
132 void AutomaticTrackSelection::enableDefaultMetadataTextTracks(const TrackGroup& group) 140 void AutomaticTrackSelection::enableDefaultMetadataTextTracks(const TrackGroup& group)
133 { 141 {
134 ASSERT(group.tracks.size()); 142 ASSERT(group.tracks.size());
(...skipping 20 matching lines...) Expand all
155 TrackGroup chapterTracks(TrackGroup::Chapter); 163 TrackGroup chapterTracks(TrackGroup::Chapter);
156 TrackGroup metadataTracks(TrackGroup::Metadata); 164 TrackGroup metadataTracks(TrackGroup::Metadata);
157 165
158 for (size_t i = 0; i < textTracks.length(); ++i) { 166 for (size_t i = 0; i < textTracks.length(); ++i) {
159 RefPtrWillBeRawPtr<TextTrack> textTrack = textTracks.item(i); 167 RefPtrWillBeRawPtr<TextTrack> textTrack = textTracks.item(i);
160 if (!textTrack) 168 if (!textTrack)
161 continue; 169 continue;
162 170
163 String kind = textTrack->kind(); 171 String kind = textTrack->kind();
164 TrackGroup* currentGroup; 172 TrackGroup* currentGroup;
165 if (kind == TextTrack::subtitlesKeyword() || kind == TextTrack::captions Keyword()) { 173 if (kind == TextTrack::captionsKeyword() || kind == TextTrack::subtitles Keyword()) {
fs 2015/07/07 08:22:05 Nit: Restore this.
srivats 2015/07/07 18:44:49 Done.
166 currentGroup = &captionAndSubtitleTracks; 174 currentGroup = &captionAndSubtitleTracks;
167 } else if (kind == TextTrack::descriptionsKeyword()) { 175 } else if (kind == TextTrack::descriptionsKeyword()) {
168 currentGroup = &descriptionTracks; 176 currentGroup = &descriptionTracks;
169 } else if (kind == TextTrack::chaptersKeyword()) { 177 } else if (kind == TextTrack::chaptersKeyword()) {
170 currentGroup = &chapterTracks; 178 currentGroup = &chapterTracks;
171 } else { 179 } else {
172 ASSERT(kind == TextTrack::metadataKeyword()); 180 ASSERT(kind == TextTrack::metadataKeyword());
173 currentGroup = &metadataTracks; 181 currentGroup = &metadataTracks;
174 } 182 }
175 183
(...skipping 20 matching lines...) Expand all
196 performAutomaticTextTrackSelection(captionAndSubtitleTracks); 204 performAutomaticTextTrackSelection(captionAndSubtitleTracks);
197 if (descriptionTracks.tracks.size()) 205 if (descriptionTracks.tracks.size())
198 performAutomaticTextTrackSelection(descriptionTracks); 206 performAutomaticTextTrackSelection(descriptionTracks);
199 if (chapterTracks.tracks.size()) 207 if (chapterTracks.tracks.size())
200 performAutomaticTextTrackSelection(chapterTracks); 208 performAutomaticTextTrackSelection(chapterTracks);
201 if (metadataTracks.tracks.size()) 209 if (metadataTracks.tracks.size())
202 enableDefaultMetadataTextTracks(metadataTracks); 210 enableDefaultMetadataTextTracks(metadataTracks);
203 } 211 }
204 212
205 } // namespace blink 213 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698