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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
64 | 64 |
65 void AutomaticTrackSelection::performAutomaticTextTrackSelection(const TrackGrou p& group) | 65 void AutomaticTrackSelection::performAutomaticTextTrackSelection(const TrackGrou p& group) |
66 { | 66 { |
67 ASSERT(group.tracks.size()); | 67 ASSERT(group.tracks.size()); |
68 | 68 |
69 // First, find the track in the group that should be enabled (if any). | 69 // First, find the track in the group that should be enabled (if any). |
70 WillBeHeapVector<RefPtrWillBeMember<TextTrack>> currentlyEnabledTracks; | 70 WillBeHeapVector<RefPtrWillBeMember<TextTrack>> currentlyEnabledTracks; |
71 RefPtrWillBeRawPtr<TextTrack> trackToEnable = nullptr; | 71 RefPtrWillBeRawPtr<TextTrack> trackToEnable = nullptr; |
72 RefPtrWillBeRawPtr<TextTrack> defaultTrack = nullptr; | 72 RefPtrWillBeRawPtr<TextTrack> defaultTrack = nullptr; |
73 RefPtrWillBeRawPtr<TextTrack> fallbackTrack = nullptr; | 73 RefPtrWillBeRawPtr<TextTrack> fallbackTrack = nullptr; |
74 int highestTrackScore = 0; | 74 RefPtrWillBeRawPtr<TextTrack> preferredCaptionTrack = nullptr; |
75 RefPtrWillBeRawPtr<TextTrack> preferredSubtitleTrack = nullptr; | |
76 | |
77 int highestCaptionTrackScore = 0; | |
fs
2015/06/09 16:03:57
I'd think it would be possible to just use the val
srivats
2015/06/10 19:55:15
I had to split the scores for track kinds to handl
fs
2015/06/11 10:46:05
I'm a little uncomfortable with the increasing num
| |
78 int highestSubtitleTrackScore = 0; | |
79 int highestDefaultTrackScore = 0; | |
80 | |
75 for (size_t i = 0; i < group.tracks.size(); ++i) { | 81 for (size_t i = 0; i < group.tracks.size(); ++i) { |
76 RefPtrWillBeRawPtr<TextTrack> textTrack = group.tracks[i]; | 82 RefPtrWillBeRawPtr<TextTrack> textTrack = group.tracks[i]; |
77 | 83 |
78 if (m_configuration.disableCurrentlyEnabledTracks && textTrack->mode() = = TextTrack::showingKeyword()) | 84 if (m_configuration.disableCurrentlyEnabledTracks && textTrack->mode() = = TextTrack::showingKeyword()) |
79 currentlyEnabledTracks.append(textTrack); | 85 currentlyEnabledTracks.append(textTrack); |
80 | 86 |
81 int trackScore = textTrackSelectionScore(*textTrack); | 87 int trackScore = textTrackSelectionScore(*textTrack); |
82 if (trackScore) { | 88 if (trackScore) { |
83 // * If the text track kind is { [subtitles or captions] [descriptio ns] } and the user has indicated an interest in having a | 89 // * 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 | 90 // 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 | 91 // 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 | 92 // 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. | 93 // Let the text track mode be showing. |
92 if (trackScore > highestTrackScore) { | 94 |
93 highestTrackScore = trackScore; | 95 if (textTrack->kind() == TextTrack::subtitlesKeyword() && trackScore > highestSubtitleTrackScore) { |
94 trackToEnable = textTrack; | 96 preferredSubtitleTrack = textTrack; |
97 highestSubtitleTrackScore = trackScore; | |
98 } else if (textTrack->kind() == TextTrack::captionsKeyword() && trac kScore > highestCaptionTrackScore) { | |
99 preferredCaptionTrack = textTrack; | |
100 highestCaptionTrackScore = trackScore; | |
95 } | 101 } |
96 | 102 |
97 if (!defaultTrack && textTrack->isDefault()) | 103 if (textTrack->isDefault() && trackScore > highestDefaultTrackScore) { |
104 highestDefaultTrackScore = trackScore; | |
98 defaultTrack = textTrack; | 105 defaultTrack = textTrack; |
99 if (!defaultTrack && !fallbackTrack) | 106 } |
100 fallbackTrack = textTrack; | 107 fallbackTrack = textTrack; |
101 } else if (!group.visibleTrack && !defaultTrack && textTrack->isDefault( )) { | 108 } 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 | 109 // * 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 | 110 // 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. | 111 // Let the text track mode be showing by default. |
105 defaultTrack = textTrack; | 112 defaultTrack = textTrack; |
106 } | 113 } |
107 } | 114 } |
108 | 115 |
116 if (m_configuration.textTrackKindUserPreference == TextTrackKindUserPreferen ce::Default && defaultTrack) { | |
fs
2015/06/09 16:03:57
I think this might be better suited as a switch.
srivats
2015/06/10 19:55:15
Agreed. I'll change it.
| |
117 trackToEnable = defaultTrack; | |
118 } else if (m_configuration.textTrackKindUserPreference == TextTrackKindUserP reference::Subtitles && preferredSubtitleTrack) { | |
119 trackToEnable = preferredSubtitleTrack; | |
120 } else if (m_configuration.textTrackKindUserPreference == TextTrackKindUserP reference::Captions) { | |
121 // When the user prefers captions, display a caption track if present in user's preferred language. | |
122 // If no captions track exists in the user's preferred language or a sub title track | |
123 // exists in a language with a higher score, display the subtitle track. | |
124 if (highestCaptionTrackScore >= highestSubtitleTrackScore && preferredCa ptionTrack) | |
125 trackToEnable = preferredCaptionTrack; | |
126 else if (preferredSubtitleTrack) | |
127 trackToEnable = preferredSubtitleTrack; | |
128 } | |
129 | |
109 if (!trackToEnable && defaultTrack) | 130 if (!trackToEnable && defaultTrack) |
110 trackToEnable = defaultTrack; | 131 trackToEnable = defaultTrack; |
111 | 132 |
112 // If no track matches the user's preferred language and non was marked 'def ault', enable the first track | 133 // If no track matches the user's preferred language and none was marked 'de fault', enable the first track |
113 // because the user has explicitly stated a preference for this kind of trac k. | 134 // because the user has explicitly stated a preference for this kind of trac k. |
114 if (!fallbackTrack && m_configuration.forceEnableSubtitleOrCaptionTrack && g roup.kind == TrackGroup::CaptionsAndSubtitles) | 135 if (!trackToEnable && m_configuration.forceEnableSubtitleOrCaptionTrack && g roup.kind == TrackGroup::CaptionsAndSubtitles) { |
115 fallbackTrack = group.tracks[0]; | 136 trackToEnable = fallbackTrack ? fallbackTrack : group.tracks[0]; |
116 | 137 } |
117 if (!trackToEnable && fallbackTrack) | |
118 trackToEnable = fallbackTrack; | |
119 | 138 |
120 if (currentlyEnabledTracks.size()) { | 139 if (currentlyEnabledTracks.size()) { |
121 for (size_t i = 0; i < currentlyEnabledTracks.size(); ++i) { | 140 for (size_t i = 0; i < currentlyEnabledTracks.size(); ++i) { |
122 RefPtrWillBeRawPtr<TextTrack> textTrack = currentlyEnabledTracks[i]; | 141 RefPtrWillBeRawPtr<TextTrack> textTrack = currentlyEnabledTracks[i]; |
123 if (textTrack != trackToEnable) | 142 if (textTrack != trackToEnable) |
124 textTrack->setMode(TextTrack::disabledKeyword()); | 143 textTrack->setMode(TextTrack::disabledKeyword()); |
125 } | 144 } |
126 } | 145 } |
127 | 146 |
128 if (trackToEnable) | 147 if (trackToEnable) |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 performAutomaticTextTrackSelection(captionAndSubtitleTracks); | 215 performAutomaticTextTrackSelection(captionAndSubtitleTracks); |
197 if (descriptionTracks.tracks.size()) | 216 if (descriptionTracks.tracks.size()) |
198 performAutomaticTextTrackSelection(descriptionTracks); | 217 performAutomaticTextTrackSelection(descriptionTracks); |
199 if (chapterTracks.tracks.size()) | 218 if (chapterTracks.tracks.size()) |
200 performAutomaticTextTrackSelection(chapterTracks); | 219 performAutomaticTextTrackSelection(chapterTracks); |
201 if (metadataTracks.tracks.size()) | 220 if (metadataTracks.tracks.size()) |
202 enableDefaultMetadataTextTracks(metadataTracks); | 221 enableDefaultMetadataTextTracks(metadataTracks); |
203 } | 222 } |
204 | 223 |
205 } // namespace blink | 224 } // namespace blink |
OLD | NEW |