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

Unified 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: Updated automatic track selection logic Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: Source/core/html/track/AutomaticTrackSelection.cpp
diff --git a/Source/core/html/track/AutomaticTrackSelection.cpp b/Source/core/html/track/AutomaticTrackSelection.cpp
index 925a3bea2e6ab542bdcb36d668a97a59d13ab080..d5a29b9d4c5149a28db72a5b85ca8eede975d493 100644
--- a/Source/core/html/track/AutomaticTrackSelection.cpp
+++ b/Source/core/html/track/AutomaticTrackSelection.cpp
@@ -71,7 +71,13 @@ void AutomaticTrackSelection::performAutomaticTextTrackSelection(const TrackGrou
RefPtrWillBeRawPtr<TextTrack> trackToEnable = nullptr;
RefPtrWillBeRawPtr<TextTrack> defaultTrack = nullptr;
RefPtrWillBeRawPtr<TextTrack> fallbackTrack = nullptr;
- int highestTrackScore = 0;
+ RefPtrWillBeRawPtr<TextTrack> preferredCaptionTrack = nullptr;
+ RefPtrWillBeRawPtr<TextTrack> preferredSubtitleTrack = nullptr;
+
+ 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
+ int highestSubtitleTrackScore = 0;
+ int highestDefaultTrackScore = 0;
+
for (size_t i = 0; i < group.tracks.size(); ++i) {
RefPtrWillBeRawPtr<TextTrack> textTrack = group.tracks[i];
@@ -80,24 +86,25 @@ void AutomaticTrackSelection::performAutomaticTextTrackSelection(const TrackGrou
int trackScore = textTrackSelectionScore(*textTrack);
if (trackScore) {
- // * If the text track kind is { [subtitles or captions] [descriptions] } and the user has indicated an interest in having a
+ // * If the text track kind is subtitles or captions and the user has indicated an interest in having a
// track with this text track kind, text track language, and text track label enabled, and there is no
// other text track in the media element's list of text tracks with a text track kind of either subtitles
// or captions whose text track mode is showing
- // ...
- // * If the text track kind is chapters and the text track language is one that the user agent has reason
- // to believe is appropriate for the user, and there is no other text track in the media element's list of
- // text tracks with a text track kind of chapters whose text track mode is showing
// Let the text track mode be showing.
- if (trackScore > highestTrackScore) {
- highestTrackScore = trackScore;
- trackToEnable = textTrack;
+
+ if (textTrack->kind() == TextTrack::subtitlesKeyword() && trackScore > highestSubtitleTrackScore) {
+ preferredSubtitleTrack = textTrack;
+ highestSubtitleTrackScore = trackScore;
+ } else if (textTrack->kind() == TextTrack::captionsKeyword() && trackScore > highestCaptionTrackScore) {
+ preferredCaptionTrack = textTrack;
+ highestCaptionTrackScore = trackScore;
}
- if (!defaultTrack && textTrack->isDefault())
+ if (textTrack->isDefault() && trackScore > highestDefaultTrackScore) {
+ highestDefaultTrackScore = trackScore;
defaultTrack = textTrack;
- if (!defaultTrack && !fallbackTrack)
- fallbackTrack = textTrack;
+ }
+ fallbackTrack = textTrack;
} else if (!group.visibleTrack && !defaultTrack && textTrack->isDefault()) {
// * If the track element has a default attribute specified, and there is no other text track in the media
// element's list of text tracks whose text track mode is showing or showing by default
@@ -106,16 +113,28 @@ void AutomaticTrackSelection::performAutomaticTextTrackSelection(const TrackGrou
}
}
+ if (m_configuration.textTrackKindUserPreference == TextTrackKindUserPreference::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.
+ trackToEnable = defaultTrack;
+ } else if (m_configuration.textTrackKindUserPreference == TextTrackKindUserPreference::Subtitles && preferredSubtitleTrack) {
+ trackToEnable = preferredSubtitleTrack;
+ } else if (m_configuration.textTrackKindUserPreference == TextTrackKindUserPreference::Captions) {
+ // When the user prefers captions, display a caption track if present in user's preferred language.
+ // If no captions track exists in the user's preferred language or a subtitle track
+ // exists in a language with a higher score, display the subtitle track.
+ if (highestCaptionTrackScore >= highestSubtitleTrackScore && preferredCaptionTrack)
+ trackToEnable = preferredCaptionTrack;
+ else if (preferredSubtitleTrack)
+ trackToEnable = preferredSubtitleTrack;
+ }
+
if (!trackToEnable && defaultTrack)
trackToEnable = defaultTrack;
- // If no track matches the user's preferred language and non was marked 'default', enable the first track
+ // If no track matches the user's preferred language and none was marked 'default', enable the first track
// because the user has explicitly stated a preference for this kind of track.
- if (!fallbackTrack && m_configuration.forceEnableSubtitleOrCaptionTrack && group.kind == TrackGroup::CaptionsAndSubtitles)
- fallbackTrack = group.tracks[0];
-
- if (!trackToEnable && fallbackTrack)
- trackToEnable = fallbackTrack;
+ if (!trackToEnable && m_configuration.forceEnableSubtitleOrCaptionTrack && group.kind == TrackGroup::CaptionsAndSubtitles) {
+ trackToEnable = fallbackTrack ? fallbackTrack : group.tracks[0];
+ }
if (currentlyEnabledTracks.size()) {
for (size_t i = 0; i < currentlyEnabledTracks.size(); ++i) {
« no previous file with comments | « Source/core/html/track/AutomaticTrackSelection.h ('k') | Source/core/html/track/TextTrackKindUserPreference.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698