Title: [149005] trunk/Source/WebCore
Revision
149005
Author
[email protected]
Date
2013-04-23 16:35:12 -0700 (Tue, 23 Apr 2013)

Log Message

[Mac] forced subtitle track should change when audio track language changes
https://bugs.webkit.org/show_bug.cgi?id=115043

Reviewed by Jer Noble.

No new tests, it isn't possible to test this automatically because there is currently no way
to enable/disable audio tracks.

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::configureTextTrackGroup): Set m_forcedOrAutomaticSubtitleTrackLanguage.
(WebCore::HTMLMediaElement::mediaPlayerCharacteristicChanged):  Call markCaptionAndSubtitleTracksAsUnconfigured
    after a delay if the language of the primary audio track changes.
(WebCore::HTMLMediaElement::setClosedCaptionsVisible): markCaptionAndSubtitleTracksAsUnconfigured API change.
(WebCore::HTMLMediaElement::markCaptionAndSubtitleTracksAsUnconfigured): Take parameter to allow
    the reconfiguration to happen after a delay to avoid doing it during a callback from the
    media engine. Clear the ConfigureTextTracks bit in m_pendingActionFlags to cancel any pending 
    asynch configuration.
* html/HTMLMediaElement.h:

* page/CaptionUserPreferencesMac.mm:
(WebCore::CaptionUserPreferencesMac::textTrackSelectionScore): Clean up logic.

* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::MediaPlayerPrivateAVFoundationObjC::tracksChanged): Call characteristicChanged when
    the primary audio track language changes.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (149004 => 149005)


--- trunk/Source/WebCore/ChangeLog	2013-04-23 23:02:08 UTC (rev 149004)
+++ trunk/Source/WebCore/ChangeLog	2013-04-23 23:35:12 UTC (rev 149005)
@@ -1,3 +1,31 @@
+2013-04-23  Eric Carlson  <[email protected]>
+
+        [Mac] forced subtitle track should change when audio track language changes
+        https://bugs.webkit.org/show_bug.cgi?id=115043
+
+        Reviewed by Jer Noble.
+
+        No new tests, it isn't possible to test this automatically because there is currently no way
+        to enable/disable audio tracks.
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::configureTextTrackGroup): Set m_forcedOrAutomaticSubtitleTrackLanguage.
+        (WebCore::HTMLMediaElement::mediaPlayerCharacteristicChanged):  Call markCaptionAndSubtitleTracksAsUnconfigured
+            after a delay if the language of the primary audio track changes.
+        (WebCore::HTMLMediaElement::setClosedCaptionsVisible): markCaptionAndSubtitleTracksAsUnconfigured API change.
+        (WebCore::HTMLMediaElement::markCaptionAndSubtitleTracksAsUnconfigured): Take parameter to allow
+            the reconfiguration to happen after a delay to avoid doing it during a callback from the
+            media engine. Clear the ConfigureTextTracks bit in m_pendingActionFlags to cancel any pending 
+            asynch configuration.
+        * html/HTMLMediaElement.h:
+
+        * page/CaptionUserPreferencesMac.mm:
+        (WebCore::CaptionUserPreferencesMac::textTrackSelectionScore): Clean up logic.
+
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::tracksChanged): Call characteristicChanged when
+            the primary audio track language changes.
+
 2013-04-23  Hans Muller  <[email protected]>
 
         [CSS Exclusions] Improve ExclusionPolygon smart pointer safety

Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (149004 => 149005)


--- trunk/Source/WebCore/html/HTMLMediaElement.cpp	2013-04-23 23:02:08 UTC (rev 149004)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp	2013-04-23 23:35:12 UTC (rev 149005)
@@ -3193,6 +3193,9 @@
 
         int trackScore = captionPreferences ? captionPreferences->textTrackSelectionScore(textTrack.get(), this) : 0;
         if (trackScore) {
+
+            LOG(Media, "HTMLMediaElement::configureTextTrackGroup -  '%s' track with language '%s' has score %i", String(textTrack->kind()).utf8().data(), String(textTrack->language()).utf8().data(), trackScore);
+
             // * If the text track kind is { [subtitles or captions] [descriptions] } 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
@@ -3236,6 +3239,11 @@
     if (!trackToEnable && fallbackTrack)
         trackToEnable = fallbackTrack;
 
+    if (!defaultTrack && trackToEnable && trackToEnable != fallbackTrack && m_captionDisplayMode != CaptionUserPreferences::AlwaysOn)
+        m_forcedOrAutomaticSubtitleTrackLanguage = trackToEnable->language();
+    else
+        m_forcedOrAutomaticSubtitleTrackLanguage = emptyString();
+    
     if (currentlyEnabledTracks.size()) {
         for (size_t i = 0; i < currentlyEnabledTracks.size(); ++i) {
             RefPtr<TextTrack> textTrack = currentlyEnabledTracks[i];
@@ -3792,6 +3800,12 @@
     LOG(Media, "HTMLMediaElement::mediaPlayerCharacteristicChanged");
     
     beginProcessingMediaPlayerCallback();
+
+#if ENABLE(VIDEO_TRACK)
+    if (m_forcedOrAutomaticSubtitleTrackLanguage != m_player->languageOfPrimaryAudioTrack())
+        markCaptionAndSubtitleTracksAsUnconfigured(AfterDelay);
+#endif
+
     if (hasMediaControls())
         mediaControls()->reset();
     if (renderer())
@@ -4415,8 +4429,7 @@
 
 #if ENABLE(VIDEO_TRACK)
     if (RuntimeEnabledFeatures::webkitVideoTrackEnabled()) {
-        m_processingPreferenceChange = true;
-        markCaptionAndSubtitleTracksAsUnconfigured();
+        markCaptionAndSubtitleTracksAsUnconfigured(Immediately);
         updateTextTrackDisplay();
     }
 #else
@@ -4635,7 +4648,7 @@
     setClosedCaptionsVisible(m_captionDisplayMode == CaptionUserPreferences::AlwaysOn);
 }
 
-void HTMLMediaElement::markCaptionAndSubtitleTracksAsUnconfigured()
+void HTMLMediaElement::markCaptionAndSubtitleTracksAsUnconfigured(ReconfigureMode mode)
 {
     if (!m_textTracks)
         return;
@@ -4655,7 +4668,13 @@
         if (kind == TextTrack::subtitlesKeyword() || kind == TextTrack::captionsKeyword())
             textTrack->setHasBeenConfigured(false);
     }
-    configureTextTracks();
+
+    m_processingPreferenceChange = true;
+    m_pendingActionFlags &= ~ConfigureTextTracks;
+    if (mode == Immediately)
+        configureTextTracks();
+    else
+        scheduleDelayedAction(ConfigureTextTracks);
 }
 
 #endif

Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (149004 => 149005)


--- trunk/Source/WebCore/html/HTMLMediaElement.h	2013-04-23 23:02:08 UTC (rev 149004)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h	2013-04-23 23:35:12 UTC (rev 149005)
@@ -548,7 +548,11 @@
     void updateActiveTextTrackCues(double);
     HTMLTrackElement* showingTrackWithSameKind(HTMLTrackElement*) const;
 
-    void markCaptionAndSubtitleTracksAsUnconfigured();
+    enum ReconfigureMode {
+        Immediately,
+        AfterDelay,
+    };
+    void markCaptionAndSubtitleTracksAsUnconfigured(ReconfigureMode);
     virtual void captionPreferencesChanged() OVERRIDE;
 #endif
 
@@ -718,6 +722,8 @@
     bool m_tracksAreReady : 1;
     bool m_haveVisibleTextTrack : 1;
     bool m_processingPreferenceChange : 1;
+
+    String m_forcedOrAutomaticSubtitleTrackLanguage;
     float m_lastTextTrackUpdateTime;
 
     CaptionUserPreferences::CaptionDisplayMode m_captionDisplayMode;

Modified: trunk/Source/WebCore/page/CaptionUserPreferencesMac.mm (149004 => 149005)


--- trunk/Source/WebCore/page/CaptionUserPreferencesMac.mm	2013-04-23 23:02:08 UTC (rev 149004)
+++ trunk/Source/WebCore/page/CaptionUserPreferencesMac.mm	2013-04-23 23:35:12 UTC (rev 149005)
@@ -625,12 +625,15 @@
         return 0;
     if (!track->isMainProgramContent())
         return 0;
-    if (displayMode == ForcedOnly && !track->containsOnlyForcedSubtitles())
+
+    bool trackHasOnlyForcedSubtitles = track->containsOnlyForcedSubtitles();
+    if ((trackHasOnlyForcedSubtitles && displayMode != ForcedOnly)
+        || (!trackHasOnlyForcedSubtitles && displayMode == ForcedOnly))
         return 0;
 
     Vector<String> userPreferredCaptionLanguages = preferredLanguages();
 
-    if (displayMode == Automatic || track->containsOnlyForcedSubtitles()) {
+    if (displayMode == Automatic || trackHasOnlyForcedSubtitles) {
 
         if (!mediaElement || !mediaElement->player())
             return 0;
@@ -651,7 +654,14 @@
         if (audioTrackLanguage.isEmpty())
             return 0;
 
-        if (displayMode == Automatic) {
+        if (trackHasOnlyForcedSubtitles) {
+            languageList.append(audioTrackLanguage);
+            size_t offset = indexOfBestMatchingLanguageInList(textTrackLanguage, languageList);
+
+            // Only consider a forced-only track if it IS in the same language as the primary audio track.
+            if (offset)
+                return 0;
+        } else {
             languageList.append(defaultLanguage());
 
             // Only enable a text track if the current audio track is NOT in the user's preferred language ...
@@ -663,13 +673,6 @@
             offset = indexOfBestMatchingLanguageInList(textTrackLanguage, languageList);
             if (offset)
                 return 0;
-        } else {
-            languageList.append(audioTrackLanguage);
-            size_t offset = indexOfBestMatchingLanguageInList(textTrackLanguage, languageList);
-
-            // Only consider a forced-only track if it IS in the same language as the primary audio track.
-            if (offset)
-                return 0;
         }
 
         userPreferredCaptionLanguages = languageList;

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm (149004 => 149005)


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm	2013-04-23 23:02:08 UTC (rev 149004)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm	2013-04-23 23:35:12 UTC (rev 149005)
@@ -973,6 +973,7 @@
 
 void MediaPlayerPrivateAVFoundationObjC::tracksChanged()
 {
+    String primaryAudioTrackLanguage = m_languageOfPrimaryAudioTrack;
     m_languageOfPrimaryAudioTrack = String();
 
     if (!m_avAsset)
@@ -1026,6 +1027,9 @@
         this, boolString(hasVideo()), boolString(hasAudio()), boolString(hasClosedCaptions()));
 
     sizeChanged();
+
+    if (!primaryAudioTrackLanguage.isNull() && primaryAudioTrackLanguage != languageOfPrimaryAudioTrack())
+        player()->characteristicChanged();
 }
 
 void MediaPlayerPrivateAVFoundationObjC::sizeChanged()
@@ -1494,6 +1498,7 @@
                 @"playbackBufferFull",
                 @"playbackBufferEmpty",
                 @"duration",
+                @"hasEnabledAudio",
                 nil];
     }
     return keys;
@@ -1574,6 +1579,8 @@
             m_callback->scheduleMainThreadNotification(MediaPlayerPrivateAVFoundation::Notification::ItemSeekableTimeRangesChanged);
         else if ([keyPath isEqualToString:@"tracks"])
             m_callback->scheduleMainThreadNotification(MediaPlayerPrivateAVFoundation::Notification::ItemTracksChanged);
+        else if ([keyPath isEqualToString:@"hasEnabledAudio"])
+            m_callback->scheduleMainThreadNotification(MediaPlayerPrivateAVFoundation::Notification::ItemTracksChanged);
         else if ([keyPath isEqualToString:@"presentationSize"])
             m_callback->scheduleMainThreadNotification(MediaPlayerPrivateAVFoundation::Notification::ItemPresentationSizeChanged);
         else if ([keyPath isEqualToString:@"duration"])
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to