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

Side by Side Diff: Source/core/html/HTMLMediaElement.cpp

Issue 891733002: Don't collect 'other tracks' in HTMLMediaElement::configureTextTracks (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/html/HTMLMediaElement.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved. 2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 { 673 {
674 #if LOG_MEDIA_EVENTS 674 #if LOG_MEDIA_EVENTS
675 WTF_LOG(Media, "HTMLMediaElement::scheduleEvent(%p) - scheduling '%s'", this , event->type().ascii().data()); 675 WTF_LOG(Media, "HTMLMediaElement::scheduleEvent(%p) - scheduling '%s'", this , event->type().ascii().data());
676 #endif 676 #endif
677 m_asyncEventQueue->enqueueEvent(event); 677 m_asyncEventQueue->enqueueEvent(event);
678 } 678 }
679 679
680 void HTMLMediaElement::loadTimerFired(Timer<HTMLMediaElement>*) 680 void HTMLMediaElement::loadTimerFired(Timer<HTMLMediaElement>*)
681 { 681 {
682 if (m_pendingActionFlags & LoadTextTrackResource) 682 if (m_pendingActionFlags & LoadTextTrackResource)
683 configureTextTracks(); 683 honorUserPreferencesForAutomaticTextTrackSelection();
684 684
685 if (m_pendingActionFlags & LoadMediaResource) { 685 if (m_pendingActionFlags & LoadMediaResource) {
686 if (m_loadState == LoadingFromSourceElement) 686 if (m_loadState == LoadingFromSourceElement)
687 loadNextSourceChild(); 687 loadNextSourceChild();
688 else 688 else
689 loadInternal(); 689 loadInternal();
690 } 690 }
691 691
692 m_pendingActionFlags = 0; 692 m_pendingActionFlags = 0;
693 } 693 }
(...skipping 1978 matching lines...) Expand 10 before | Expand all | Expand 10 after
2672 // as follows, based on the type of the media resource: 2672 // as follows, based on the type of the media resource:
2673 // 5. Populate the new text track's list of cues with the cues parsed so far , folllowing the guidelines for exposing 2673 // 5. Populate the new text track's list of cues with the cues parsed so far , folllowing the guidelines for exposing
2674 // cues, and begin updating it dynamically as necessary. 2674 // cues, and begin updating it dynamically as necessary.
2675 // - Thess are all done by the media engine. 2675 // - Thess are all done by the media engine.
2676 2676
2677 // 6. Set the new text track's readiness state to loaded. 2677 // 6. Set the new text track's readiness state to loaded.
2678 textTrack->setReadinessState(TextTrack::Loaded); 2678 textTrack->setReadinessState(TextTrack::Loaded);
2679 2679
2680 // 7. Set the new text track's mode to the mode consistent with the user's p references and the requirements of 2680 // 7. Set the new text track's mode to the mode consistent with the user's p references and the requirements of
2681 // the relevant specification for the data. 2681 // the relevant specification for the data.
2682 // - This will happen in configureTextTracks() 2682 // - This will happen in honorUserPreferencesForAutomaticTextTrackSelection ()
2683 scheduleDelayedAction(LoadTextTrackResource); 2683 scheduleDelayedAction(LoadTextTrackResource);
2684 2684
2685 // 8. Add the new text track to the media element's list of text tracks. 2685 // 8. Add the new text track to the media element's list of text tracks.
2686 // 9. Fire an event with the name addtrack, that does not bubble and is not cancelable, and that uses the TrackEvent 2686 // 9. Fire an event with the name addtrack, that does not bubble and is not cancelable, and that uses the TrackEvent
2687 // interface, with the track attribute initialized to the text track's TextT rack object, at the media element's 2687 // interface, with the track attribute initialized to the text track's TextT rack object, at the media element's
2688 // textTracks attribute's TextTrackList object. 2688 // textTracks attribute's TextTrackList object.
2689 addTextTrack(textTrack.get()); 2689 addTextTrack(textTrack.get());
2690 } 2690 }
2691 2691
2692 void HTMLMediaElement::mediaPlayerDidRemoveTextTrack(WebInbandTextTrack* webTrac k) 2692 void HTMLMediaElement::mediaPlayerDidRemoveTextTrack(WebInbandTextTrack* webTrac k)
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
2845 } 2845 }
2846 2846
2847 static int textTrackSelectionScore(const TextTrack& track) 2847 static int textTrackSelectionScore(const TextTrack& track)
2848 { 2848 {
2849 if (track.kind() != TextTrack::captionsKeyword() && track.kind() != TextTrac k::subtitlesKeyword()) 2849 if (track.kind() != TextTrack::captionsKeyword() && track.kind() != TextTrac k::subtitlesKeyword())
2850 return 0; 2850 return 0;
2851 2851
2852 return textTrackLanguageSelectionScore(track); 2852 return textTrackLanguageSelectionScore(track);
2853 } 2853 }
2854 2854
2855 void HTMLMediaElement::configureTextTrackGroup(const TrackGroup& group) 2855 void HTMLMediaElement::performAutomaticTextTrackSelection(const TrackGroup& grou p)
2856 { 2856 {
2857 ASSERT(group.tracks.size()); 2857 ASSERT(group.tracks.size());
2858 2858
2859 WTF_LOG(Media, "HTMLMediaElement::configureTextTrackGroup(%p, %d)", this, gr oup.kind); 2859 WTF_LOG(Media, "HTMLMediaElement::configureTextTrackGroup(%p, %d)", this, gr oup.kind);
2860 2860
2861 // First, find the track in the group that should be enabled (if any). 2861 // First, find the track in the group that should be enabled (if any).
2862 WillBeHeapVector<RefPtrWillBeMember<TextTrack>> currentlyEnabledTracks; 2862 WillBeHeapVector<RefPtrWillBeMember<TextTrack>> currentlyEnabledTracks;
2863 RefPtrWillBeRawPtr<TextTrack> trackToEnable = nullptr; 2863 RefPtrWillBeRawPtr<TextTrack> trackToEnable = nullptr;
2864 RefPtrWillBeRawPtr<TextTrack> defaultTrack = nullptr; 2864 RefPtrWillBeRawPtr<TextTrack> defaultTrack = nullptr;
2865 RefPtrWillBeRawPtr<TextTrack> fallbackTrack = nullptr; 2865 RefPtrWillBeRawPtr<TextTrack> fallbackTrack = nullptr;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
2914 RefPtrWillBeRawPtr<TextTrack> textTrack = currentlyEnabledTracks[i]; 2914 RefPtrWillBeRawPtr<TextTrack> textTrack = currentlyEnabledTracks[i];
2915 if (textTrack != trackToEnable) 2915 if (textTrack != trackToEnable)
2916 textTrack->setMode(TextTrack::disabledKeyword()); 2916 textTrack->setMode(TextTrack::disabledKeyword());
2917 } 2917 }
2918 } 2918 }
2919 2919
2920 if (trackToEnable) 2920 if (trackToEnable)
2921 trackToEnable->setMode(TextTrack::showingKeyword()); 2921 trackToEnable->setMode(TextTrack::showingKeyword());
2922 } 2922 }
2923 2923
2924 void HTMLMediaElement::configureMetadataTextTrackGroup(const TrackGroup& group) 2924 void HTMLMediaElement::enableDefaultMetadataTextTracks(const TrackGroup& group)
2925 { 2925 {
2926 ASSERT(group.tracks.size()); 2926 ASSERT(group.tracks.size());
2927 2927
2928 // https://html.spec.whatwg.org/multipage/embedded-content.html#honor-user-p references-for-automatic-text-track-selection 2928 // https://html.spec.whatwg.org/multipage/embedded-content.html#honor-user-p references-for-automatic-text-track-selection
2929 2929
2930 // 4. If there are any text tracks in the media element's list of text 2930 // 4. If there are any text tracks in the media element's list of text
2931 // tracks whose text track kind is metadata that correspond to track 2931 // tracks whose text track kind is metadata that correspond to track
2932 // elements with a default attribute set whose text track mode is set to 2932 // elements with a default attribute set whose text track mode is set to
2933 // disabled, then set the text track mode of all such tracks to hidden 2933 // disabled, then set the text track mode of all such tracks to hidden
2934 for (auto& textTrack : group.tracks) { 2934 for (auto& textTrack : group.tracks) {
2935 if (textTrack->mode() != TextTrack::disabledKeyword()) 2935 if (textTrack->mode() != TextTrack::disabledKeyword())
2936 continue; 2936 continue;
2937 if (!textTrack->isDefault()) 2937 if (!textTrack->isDefault())
2938 continue; 2938 continue;
2939 textTrack->setMode(TextTrack::hiddenKeyword()); 2939 textTrack->setMode(TextTrack::hiddenKeyword());
2940 } 2940 }
2941 } 2941 }
2942 2942
2943 void HTMLMediaElement::configureTextTracks() 2943 void HTMLMediaElement::honorUserPreferencesForAutomaticTextTrackSelection()
2944 { 2944 {
2945 TrackGroup captionAndSubtitleTracks(TrackGroup::CaptionsAndSubtitles); 2945 TrackGroup captionAndSubtitleTracks(TrackGroup::CaptionsAndSubtitles);
2946 TrackGroup descriptionTracks(TrackGroup::Description); 2946 TrackGroup descriptionTracks(TrackGroup::Description);
2947 TrackGroup chapterTracks(TrackGroup::Chapter); 2947 TrackGroup chapterTracks(TrackGroup::Chapter);
2948 TrackGroup metadataTracks(TrackGroup::Metadata); 2948 TrackGroup metadataTracks(TrackGroup::Metadata);
2949 TrackGroup otherTracks(TrackGroup::Other);
2950 2949
2951 if (!m_textTracks) 2950 if (!m_textTracks)
2952 return; 2951 return;
2953 2952
2954 for (size_t i = 0; i < m_textTracks->length(); ++i) { 2953 for (size_t i = 0; i < m_textTracks->length(); ++i) {
2955 RefPtrWillBeRawPtr<TextTrack> textTrack = m_textTracks->item(i); 2954 RefPtrWillBeRawPtr<TextTrack> textTrack = m_textTracks->item(i);
2956 if (!textTrack) 2955 if (!textTrack)
2957 continue; 2956 continue;
2958 2957
2959 String kind = textTrack->kind(); 2958 String kind = textTrack->kind();
2960 TrackGroup* currentGroup; 2959 TrackGroup* currentGroup;
2961 if (kind == TextTrack::subtitlesKeyword() || kind == TextTrack::captions Keyword()) 2960 if (kind == TextTrack::subtitlesKeyword() || kind == TextTrack::captions Keyword()) {
2962 currentGroup = &captionAndSubtitleTracks; 2961 currentGroup = &captionAndSubtitleTracks;
2963 else if (kind == TextTrack::descriptionsKeyword()) 2962 } else if (kind == TextTrack::descriptionsKeyword()) {
2964 currentGroup = &descriptionTracks; 2963 currentGroup = &descriptionTracks;
2965 else if (kind == TextTrack::chaptersKeyword()) 2964 } else if (kind == TextTrack::chaptersKeyword()) {
2966 currentGroup = &chapterTracks; 2965 currentGroup = &chapterTracks;
2967 else if (kind == TextTrack::metadataKeyword()) 2966 } else {
2967 ASSERT(kind == TextTrack::metadataKeyword());
2968 currentGroup = &metadataTracks; 2968 currentGroup = &metadataTracks;
2969 else 2969 }
2970 currentGroup = &otherTracks;
2971 2970
2972 if (!currentGroup->visibleTrack && textTrack->mode() == TextTrack::showi ngKeyword()) 2971 if (!currentGroup->visibleTrack && textTrack->mode() == TextTrack::showi ngKeyword())
2973 currentGroup->visibleTrack = textTrack; 2972 currentGroup->visibleTrack = textTrack;
2974 if (!currentGroup->defaultTrack && textTrack->isDefault()) 2973 if (!currentGroup->defaultTrack && textTrack->isDefault())
2975 currentGroup->defaultTrack = textTrack; 2974 currentGroup->defaultTrack = textTrack;
2976 2975
2977 // Do not add this track to the group if it has already been automatical ly configured 2976 // Do not add this track to the group if it has already been automatical ly configured
2978 // as we only want to call configureTextTrack once per track so that add ing another 2977 // as we only want to perform selection once per track so that adding an other track
2979 // track after the initial configuration doesn't reconfigure every track - only those 2978 // after the initial configuration doesn't reconfigure every track - onl y those that
2980 // that should be changed by the new addition. For example all metadata tracks are 2979 // should be changed by the new addition. For example all metadata track s are
2981 // disabled by default, and we don't want a track that has been enabled by script 2980 // disabled by default, and we don't want a track that has been enabled by script
2982 // to be disabled automatically when a new metadata track is added later . 2981 // to be disabled automatically when a new metadata track is added later .
2983 if (textTrack->hasBeenConfigured()) 2982 if (textTrack->hasBeenConfigured())
2984 continue; 2983 continue;
2985 2984
2986 if (textTrack->language().length()) 2985 if (textTrack->language().length())
2987 currentGroup->hasSrcLang = true; 2986 currentGroup->hasSrcLang = true;
2988 currentGroup->tracks.append(textTrack); 2987 currentGroup->tracks.append(textTrack);
2989 } 2988 }
2990 2989
2991 if (captionAndSubtitleTracks.tracks.size()) 2990 if (captionAndSubtitleTracks.tracks.size())
2992 configureTextTrackGroup(captionAndSubtitleTracks); 2991 performAutomaticTextTrackSelection(captionAndSubtitleTracks);
2993 if (descriptionTracks.tracks.size()) 2992 if (descriptionTracks.tracks.size())
2994 configureTextTrackGroup(descriptionTracks); 2993 performAutomaticTextTrackSelection(descriptionTracks);
2995 if (chapterTracks.tracks.size()) 2994 if (chapterTracks.tracks.size())
2996 configureTextTrackGroup(chapterTracks); 2995 performAutomaticTextTrackSelection(chapterTracks);
2997 if (metadataTracks.tracks.size()) 2996 if (metadataTracks.tracks.size())
2998 configureMetadataTextTrackGroup(metadataTracks); 2997 enableDefaultMetadataTextTracks(metadataTracks);
2999 if (otherTracks.tracks.size())
3000 configureTextTrackGroup(otherTracks);
3001 2998
3002 textTracksChanged(); 2999 textTracksChanged();
3003 } 3000 }
3004 3001
3005 bool HTMLMediaElement::havePotentialSourceChild() 3002 bool HTMLMediaElement::havePotentialSourceChild()
3006 { 3003 {
3007 // Stash the current <source> node and next nodes so we can restore them aft er checking 3004 // Stash the current <source> node and next nodes so we can restore them aft er checking
3008 // to see there is another potential. 3005 // to see there is another potential.
3009 RefPtrWillBeRawPtr<HTMLSourceElement> currentSourceNode = m_currentSourceNod e; 3006 RefPtrWillBeRawPtr<HTMLSourceElement> currentSourceNode = m_currentSourceNod e;
3010 RefPtrWillBeRawPtr<Node> nextNode = m_nextChildNodeToConsider; 3007 RefPtrWillBeRawPtr<Node> nextNode = m_nextChildNodeToConsider;
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after
3716 { 3713 {
3717 WTF_LOG(Media, "HTMLMediaElement::setClosedCaptionsVisible(%p, %s)", this, b oolString(closedCaptionVisible)); 3714 WTF_LOG(Media, "HTMLMediaElement::setClosedCaptionsVisible(%p, %s)", this, b oolString(closedCaptionVisible));
3718 3715
3719 if (!m_player || !hasClosedCaptions()) 3716 if (!m_player || !hasClosedCaptions())
3720 return; 3717 return;
3721 3718
3722 m_closedCaptionsVisible = closedCaptionVisible; 3719 m_closedCaptionsVisible = closedCaptionVisible;
3723 3720
3724 markCaptionAndSubtitleTracksAsUnconfigured(); 3721 markCaptionAndSubtitleTracksAsUnconfigured();
3725 m_processingPreferenceChange = true; 3722 m_processingPreferenceChange = true;
3726 configureTextTracks(); 3723 honorUserPreferencesForAutomaticTextTrackSelection();
3727 m_processingPreferenceChange = false; 3724 m_processingPreferenceChange = false;
3728 3725
3729 updateTextTrackDisplay(); 3726 updateTextTrackDisplay();
3730 } 3727 }
3731 3728
3732 unsigned HTMLMediaElement::webkitAudioDecodedByteCount() const 3729 unsigned HTMLMediaElement::webkitAudioDecodedByteCount() const
3733 { 3730 {
3734 if (!webMediaPlayer()) 3731 if (!webMediaPlayer())
3735 return 0; 3732 return 0;
3736 return webMediaPlayer()->audioDecodedByteCount(); 3733 return webMediaPlayer()->audioDecodedByteCount();
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
3844 3841
3845 updateActiveTextTrackCues(currentTime()); 3842 updateActiveTextTrackCues(currentTime());
3846 updateTextTrackDisplay(); 3843 updateTextTrackDisplay();
3847 } 3844 }
3848 3845
3849 void HTMLMediaElement::markCaptionAndSubtitleTracksAsUnconfigured() 3846 void HTMLMediaElement::markCaptionAndSubtitleTracksAsUnconfigured()
3850 { 3847 {
3851 if (!m_textTracks) 3848 if (!m_textTracks)
3852 return; 3849 return;
3853 3850
3854 // Mark all tracks as not "configured" so that configureTextTracks() 3851 // Mark all tracks as not "configured" so that
3855 // will reconsider which tracks to display in light of new user preferences 3852 // honorUserPreferencesForAutomaticTextTrackSelection() will reconsider
3856 // (e.g. default tracks should not be displayed if the user has turned off 3853 // which tracks to display in light of new user preferences (e.g. default
3857 // captions and non-default tracks should be displayed based on language 3854 // tracks should not be displayed if the user has turned off captions and
3858 // preferences if the user has turned captions on). 3855 // non-default tracks should be displayed based on language preferences if
3856 // the user has turned captions on).
3859 for (unsigned i = 0; i < m_textTracks->length(); ++i) { 3857 for (unsigned i = 0; i < m_textTracks->length(); ++i) {
3860 RefPtrWillBeRawPtr<TextTrack> textTrack = m_textTracks->item(i); 3858 RefPtrWillBeRawPtr<TextTrack> textTrack = m_textTracks->item(i);
3861 String kind = textTrack->kind(); 3859 String kind = textTrack->kind();
3862 3860
3863 if (kind == TextTrack::subtitlesKeyword() || kind == TextTrack::captions Keyword()) 3861 if (kind == TextTrack::subtitlesKeyword() || kind == TextTrack::captions Keyword())
3864 textTrack->setHasBeenConfigured(false); 3862 textTrack->setHasBeenConfigured(false);
3865 } 3863 }
3866 } 3864 }
3867 3865
3868 void* HTMLMediaElement::preDispatchEventHandler(Event* event) 3866 void* HTMLMediaElement::preDispatchEventHandler(Event* event)
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
4113 4111
4114 #if ENABLE(WEB_AUDIO) 4112 #if ENABLE(WEB_AUDIO)
4115 void HTMLMediaElement::clearWeakMembers(Visitor* visitor) 4113 void HTMLMediaElement::clearWeakMembers(Visitor* visitor)
4116 { 4114 {
4117 if (!visitor->isAlive(m_audioSourceNode) && audioSourceProvider()) 4115 if (!visitor->isAlive(m_audioSourceNode) && audioSourceProvider())
4118 audioSourceProvider()->setClient(nullptr); 4116 audioSourceProvider()->setClient(nullptr);
4119 } 4117 }
4120 #endif 4118 #endif
4121 4119
4122 } 4120 }
OLDNEW
« no previous file with comments | « Source/core/html/HTMLMediaElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698