Changeset 184799 in webkit


Ignore:
Timestamp:
May 22, 2015, 4:15:37 PM (10 years ago)
Author:
jer.noble@apple.com
Message:

[Mac] Audio tracks tagged as 'describes-video' are not automatically selected when that system accessibility option is set.
https://bugs.webkit.org/show_bug.cgi?id=145228

Reviewed by Eric Carlson.

Source/WebCore:

Tests: http/tests/media/hls/hls-accessiblity-describes-video.html

media/accessiblity-describes-video.html

Add support to CaptionUserPreferences to return the user's preferred audio characteristics,
including "public.accessibility.describes-video". When the media accessibility options change,
trigger the HTMLMediaElement to update the list of tracks, and chose a new audio track if
appropriate. Manually filter those tracks matching the requested characteristics in
MediaSelectionGroupAVFObjC. Allow these characteristics to be overrided by Internals for
testing purposes.

  • html/HTMLMediaElement.cpp:

(WebCore::HTMLMediaElement::captionPreferencesChanged): Call tracksChanged().
(WebCore::HTMLMediaElement::mediaPlayerPreferredAudioCharacteristics): Pass through to the page's caption preferences.

  • html/HTMLMediaElement.h:
  • page/CaptionUserPreferences.cpp:

(WebCore::CaptionUserPreferences::setPreferredAudioCharacteristic): Simple setter.
(WebCore::CaptionUserPreferences::preferredAudioCharacteristics): Simple getter.

  • page/CaptionUserPreferences.h:
  • page/CaptionUserPreferencesMediaAF.cpp:

(WebCore::CaptionUserPreferencesMediaAF::~CaptionUserPreferencesMediaAF): Unregister for audio characteristics change notifications.
(WebCore::CaptionUserPreferencesMediaAF::setInterestedInCaptionPreferenceChanges): Register for same.
(WebCore::CaptionUserPreferencesMediaAF::setPreferredAudioCharacteristic): If in testing mode, pass to superclass; otherwise no-op.
(WebCore::CaptionUserPreferencesMediaAF::preferredAudioCharacteristics): If in testing mode, pass to superclass;

otherwise, ask the media accessibility framework.

  • page/CaptionUserPreferencesMediaAF.h:
  • platform/graphics/MediaPlayer.cpp:

(WebCore::MediaPlayer::tracksChanged): Pass through to m_private.
(WebCore::MediaPlayer::preferredAudioCharacteristics): Pass through to HTMLMediaElement.

  • platform/graphics/MediaPlayer.h:

(WebCore::MediaPlayerClient::mediaPlayerPreferredAudioCharacteristics): Added; return empty vector by default.

  • platform/graphics/MediaPlayerPrivate.h:

(WebCore::MediaPlayerPrivateInterface::tracksChanged): Added; no-op by default.

  • platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h:
  • platform/graphics/avfoundation/MediaSelectionGroupAVFObjC.h:
  • platform/graphics/avfoundation/MediaSelectionGroupAVFObjC.mm:

(WebCore::MediaSelectionGroupAVFObjC::create): Added characteristics parameter.
(WebCore::MediaSelectionGroupAVFObjC::MediaSelectionGroupAVFObjC): Ditto.
(WebCore::MediaSelectionGroupAVFObjC::updateOptions): Add an additional filter against the

passed-in characteristics.

  • platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
  • platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:

(WebCore::determineChangedTracksFromNewTracksAndOldItems): Pass the characteristics to the media selection group.
(WebCore::MediaPlayerPrivateAVFoundationObjC::updateAudioTracks): Pass in the user's preferred characteristics.
(WebCore::MediaPlayerPrivateAVFoundationObjC::updateVideoTracks): Pass in an empty vector.

  • testing/Internals.cpp:

(WebCore::Internals::userPreferredAudioCharacteristics): Added; return the current setting.
(WebCore::Internals::setUserPreferredAudioCharacteristic): Added; pass through to CaptionUserPreferences.

  • testing/Internals.h:
  • testing/Internals.idl:

Add soft link macros which account for a possible failure to look up constants.

  • platform/cf/MediaAccessibilitySoftLink.cpp:
  • platform/cf/MediaAccessibilitySoftLink.h:
  • platform/mac/SoftLinking.h:
  • platform/win/SoftLinking.h:

LayoutTests:

  • http/tests/media/hls/hls-accessiblity-describes-video-expected.txt: Added.
  • http/tests/media/hls/hls-accessiblity-describes-video.html: Added.
  • http/tests/media/resources/hls/audio-describes-video.m3u8: Added.
  • http/tests/media/resources/hls/english/description.aac: Added.
  • http/tests/media/resources/hls/english/description.m3u8: Added.
  • media/accessiblity-describes-video-expected.txt: Added.
  • media/accessiblity-describes-video.html: Added.
  • media/content/audio-describes-video.mp4: Added.
  • platform/mac-mavericks/TestExpectations:
Location:
trunk
Files:
9 added
24 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r184776 r184799  
     12015-05-22  Jer Noble  <jer.noble@apple.com>
     2
     3        [Mac] Audio tracks tagged as 'describes-video' are not automatically selected when that system accessibility option is set.
     4        https://bugs.webkit.org/show_bug.cgi?id=145228
     5
     6        Reviewed by Eric Carlson.
     7
     8        * http/tests/media/hls/hls-accessiblity-describes-video-expected.txt: Added.
     9        * http/tests/media/hls/hls-accessiblity-describes-video.html: Added.
     10        * http/tests/media/resources/hls/audio-describes-video.m3u8: Added.
     11        * http/tests/media/resources/hls/english/description.aac: Added.
     12        * http/tests/media/resources/hls/english/description.m3u8: Added.
     13        * media/accessiblity-describes-video-expected.txt: Added.
     14        * media/accessiblity-describes-video.html: Added.
     15        * media/content/audio-describes-video.mp4: Added.
     16        * platform/mac-mavericks/TestExpectations:
     17
    1182015-05-22  Basile Clement  <basile_clement@apple.com>
    219
  • trunk/LayoutTests/platform/mac-mavericks/TestExpectations

    r183942 r184799  
    1010compositing/media-controls-bar-appearance.html [ Skip ]
    1111compositing/media-controls-bar-appearance-big.html [ Skip ]
     12
     13# No support for non-HLS Media Selection Group
     14media/accessiblity-describes-video.html [ Skip ]
  • trunk/Source/WebCore/ChangeLog

    r184796 r184799  
     12015-05-22  Jer Noble  <jer.noble@apple.com>
     2
     3        [Mac] Audio tracks tagged as 'describes-video' are not automatically selected when that system accessibility option is set.
     4        https://bugs.webkit.org/show_bug.cgi?id=145228
     5
     6        Reviewed by Eric Carlson.
     7
     8        Tests: http/tests/media/hls/hls-accessiblity-describes-video.html
     9               media/accessiblity-describes-video.html
     10
     11        Add support to CaptionUserPreferences to return the user's preferred audio characteristics,
     12        including "public.accessibility.describes-video". When the media accessibility options change,
     13        trigger the HTMLMediaElement to update the list of tracks, and chose a new audio track if
     14        appropriate. Manually filter those tracks matching the requested characteristics in
     15        MediaSelectionGroupAVFObjC.  Allow these characteristics to be overrided by Internals for
     16        testing purposes.
     17
     18        * html/HTMLMediaElement.cpp:
     19        (WebCore::HTMLMediaElement::captionPreferencesChanged): Call tracksChanged().
     20        (WebCore::HTMLMediaElement::mediaPlayerPreferredAudioCharacteristics): Pass through to the page's caption preferences.
     21        * html/HTMLMediaElement.h:
     22        * page/CaptionUserPreferences.cpp:
     23        (WebCore::CaptionUserPreferences::setPreferredAudioCharacteristic): Simple setter.
     24        (WebCore::CaptionUserPreferences::preferredAudioCharacteristics): Simple getter.
     25        * page/CaptionUserPreferences.h:
     26        * page/CaptionUserPreferencesMediaAF.cpp:
     27        (WebCore::CaptionUserPreferencesMediaAF::~CaptionUserPreferencesMediaAF): Unregister for audio characteristics change notifications.
     28        (WebCore::CaptionUserPreferencesMediaAF::setInterestedInCaptionPreferenceChanges): Register for same.
     29        (WebCore::CaptionUserPreferencesMediaAF::setPreferredAudioCharacteristic): If in testing mode, pass to superclass; otherwise no-op.
     30        (WebCore::CaptionUserPreferencesMediaAF::preferredAudioCharacteristics): If in testing mode, pass to superclass;
     31            otherwise, ask the media accessibility framework.
     32        * page/CaptionUserPreferencesMediaAF.h:
     33        * platform/graphics/MediaPlayer.cpp:
     34        (WebCore::MediaPlayer::tracksChanged): Pass through to m_private.
     35        (WebCore::MediaPlayer::preferredAudioCharacteristics): Pass through to HTMLMediaElement.
     36        * platform/graphics/MediaPlayer.h:
     37        (WebCore::MediaPlayerClient::mediaPlayerPreferredAudioCharacteristics): Added; return empty vector by default.
     38        * platform/graphics/MediaPlayerPrivate.h:
     39        (WebCore::MediaPlayerPrivateInterface::tracksChanged): Added; no-op by default.
     40        * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h:
     41        * platform/graphics/avfoundation/MediaSelectionGroupAVFObjC.h:
     42        * platform/graphics/avfoundation/MediaSelectionGroupAVFObjC.mm:
     43        (WebCore::MediaSelectionGroupAVFObjC::create): Added characteristics parameter.
     44        (WebCore::MediaSelectionGroupAVFObjC::MediaSelectionGroupAVFObjC): Ditto.
     45        (WebCore::MediaSelectionGroupAVFObjC::updateOptions): Add an additional filter against the
     46            passed-in characteristics.
     47        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
     48        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
     49        (WebCore::determineChangedTracksFromNewTracksAndOldItems): Pass the characteristics to the media selection group.
     50        (WebCore::MediaPlayerPrivateAVFoundationObjC::updateAudioTracks): Pass in the user's preferred characteristics.
     51        (WebCore::MediaPlayerPrivateAVFoundationObjC::updateVideoTracks): Pass in an empty vector.
     52        * testing/Internals.cpp:
     53        (WebCore::Internals::userPreferredAudioCharacteristics): Added; return the current setting.
     54        (WebCore::Internals::setUserPreferredAudioCharacteristic): Added; pass through to CaptionUserPreferences.
     55        * testing/Internals.h:
     56        * testing/Internals.idl:
     57
     58        Add soft link macros which account for a possible failure to look up constants.
     59
     60        * platform/cf/MediaAccessibilitySoftLink.cpp:
     61        * platform/cf/MediaAccessibilitySoftLink.h:
     62        * platform/mac/SoftLinking.h:
     63        * platform/win/SoftLinking.h:
     64
    1652015-05-22  Myles C. Maxfield  <mmaxfield@apple.com>
    266
  • trunk/Source/WebCore/html/HTMLMediaElement.cpp

    r184788 r184799  
    54835483#endif
    54845484
     5485    if (m_player)
     5486        m_player->tracksChanged();
     5487
    54855488    if (!document().page())
    54865489        return;
     
    59155918}
    59165919
     5920Vector<String> HTMLMediaElement::mediaPlayerPreferredAudioCharacteristics() const
     5921{
     5922    Page* page = document().page();
     5923    if (CaptionUserPreferences* captionPreferences = page ? page->group().captionPreferences() : nullptr)
     5924        return captionPreferences->preferredAudioCharacteristics();
     5925    return Vector<String>();
     5926}
     5927
    59175928#if PLATFORM(IOS)
    59185929String HTMLMediaElement::mediaPlayerNetworkInterfaceName() const
  • trunk/Source/WebCore/html/HTMLMediaElement.h

    r184760 r184799  
    571571    virtual void mediaPlayerHandlePlaybackCommand(MediaSession::RemoteControlCommandType command) override { didReceiveRemoteControlCommand(command); }
    572572    virtual String mediaPlayerSourceApplicationIdentifier() const override;
     573    virtual Vector<String> mediaPlayerPreferredAudioCharacteristics() const override;
    573574
    574575#if PLATFORM(IOS)
  • trunk/Source/WebCore/page/CaptionUserPreferences.cpp

    r183676 r184799  
    159159}
    160160
     161void CaptionUserPreferences::setPreferredAudioCharacteristic(const String& characteristic)
     162{
     163    m_userPreferredAudioCharacteristic = characteristic;
     164    notify();
     165}
     166
     167Vector<String> CaptionUserPreferences::preferredAudioCharacteristics() const
     168{
     169    Vector<String> characteristics;
     170    if (!m_userPreferredAudioCharacteristic.isEmpty())
     171        characteristics.append(m_userPreferredAudioCharacteristic);
     172    return characteristics;
     173}
     174
    161175static String trackDisplayName(TextTrack* track)
    162176{
  • trunk/Source/WebCore/page/CaptionUserPreferences.h

    r176459 r184799  
    8080    virtual Vector<String> preferredLanguages() const;
    8181
     82    virtual void setPreferredAudioCharacteristic(const String&);
     83    virtual Vector<String> preferredAudioCharacteristics() const;
     84
    8285    virtual String displayNameForTrack(TextTrack*) const;
    8386    virtual Vector<RefPtr<TextTrack>> sortedTrackListForMenu(TextTrackList*);
     
    105108    Timer m_timer;
    106109    String m_userPreferredLanguage;
     110    String m_userPreferredAudioCharacteristic;
    107111    String m_captionsStyleSheetOverride;
    108112    String m_primaryAudioTrackLanguageOverride;
  • trunk/Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp

    r183705 r184799  
    107107    if (kMAXCaptionAppearanceSettingsChangedNotification)
    108108        CFNotificationCenterRemoveObserver(CFNotificationCenterGetLocalCenter(), this, kMAXCaptionAppearanceSettingsChangedNotification, 0);
     109    if (kMAAudibleMediaSettingsChangedNotification)
     110        CFNotificationCenterRemoveObserver(CFNotificationCenterGetLocalCenter(), this, kMAAudibleMediaSettingsChangedNotification, 0);
    109111#endif
    110112}
     
    192194        return;
    193195
    194     if (!kMAXCaptionAppearanceSettingsChangedNotification)
     196    if (!kMAXCaptionAppearanceSettingsChangedNotification && !canLoad_MediaAccessibility_kMAAudibleMediaSettingsChangedNotification())
    195197        return;
    196198
    197199    m_listeningForPreferenceChanges = true;
    198200    m_registeringForNotification = true;
    199     CFNotificationCenterAddObserver(CFNotificationCenterGetLocalCenter(), this, userCaptionPreferencesChangedNotificationCallback, kMAXCaptionAppearanceSettingsChangedNotification, 0, CFNotificationSuspensionBehaviorCoalesce);
     201
     202    if (kMAXCaptionAppearanceSettingsChangedNotification)
     203        CFNotificationCenterAddObserver(CFNotificationCenterGetLocalCenter(), this, userCaptionPreferencesChangedNotificationCallback, kMAXCaptionAppearanceSettingsChangedNotification, 0, CFNotificationSuspensionBehaviorCoalesce);
     204    if (canLoad_MediaAccessibility_kMAAudibleMediaSettingsChangedNotification())
     205        CFNotificationCenterAddObserver(CFNotificationCenterGetLocalCenter(), this, userCaptionPreferencesChangedNotificationCallback, kMAAudibleMediaSettingsChangedNotification, 0, CFNotificationSuspensionBehaviorCoalesce);
    200206    m_registeringForNotification = false;
    201207
     
    466472
    467473    return userPreferredLanguages;
     474}
     475
     476void CaptionUserPreferencesMediaAF::setPreferredAudioCharacteristic(const String& characteristic)
     477{
     478    if (testingMode() || !MediaAccessibilityLibrary())
     479        CaptionUserPreferences::setPreferredAudioCharacteristic(characteristic);
     480}
     481
     482Vector<String> CaptionUserPreferencesMediaAF::preferredAudioCharacteristics() const
     483{
     484    if (testingMode() || !MediaAccessibilityLibrary() || !canLoad_MediaAccessibility_MAAudibleMediaCopyPreferredCharacteristics())
     485        return CaptionUserPreferences::preferredAudioCharacteristics();
     486
     487    CFIndex characteristicCount = 0;
     488    RetainPtr<CFArrayRef> characteristics = adoptCF(MAAudibleMediaCopyPreferredCharacteristics());
     489    if (characteristics)
     490        characteristicCount = CFArrayGetCount(characteristics.get());
     491
     492    if (!characteristicCount)
     493        return CaptionUserPreferences::preferredAudioCharacteristics();
     494
     495    Vector<String> userPreferredAudioCharacteristics;
     496    userPreferredAudioCharacteristics.reserveCapacity(characteristicCount);
     497    for (CFIndex i = 0; i < characteristicCount; i++)
     498        userPreferredAudioCharacteristics.append(static_cast<CFStringRef>(CFArrayGetValueAtIndex(characteristics.get(), i)));
     499
     500    return userPreferredAudioCharacteristics;
    468501}
    469502#endif // HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK)
  • trunk/Source/WebCore/page/CaptionUserPreferencesMediaAF.h

    r182505 r184799  
    5656    virtual Vector<String> preferredLanguages() const override;
    5757
     58    virtual void setPreferredAudioCharacteristic(const String&) override;
     59    virtual Vector<String> preferredAudioCharacteristics() const override;
     60
    5861    virtual void captionPreferencesChanged() override;
    5962
  • trunk/Source/WebCore/platform/cf/MediaAccessibilitySoftLink.cpp

    r181207 r184799  
    4848SOFT_LINK_FUNCTION_FOR_SOURCE(WebCore, MediaAccessibility, MACaptionAppearanceCopySelectedLanguages, CFArrayRef, (MACaptionAppearanceDomain domain), (domain));
    4949SOFT_LINK_FUNCTION_FOR_SOURCE(WebCore, MediaAccessibility, MACaptionAppearanceCopyPreferredCaptioningMediaCharacteristics,  CFArrayRef, (MACaptionAppearanceDomain domain), (domain));
     50SOFT_LINK_FUNCTION_MAY_FAIL_FOR_SOURCE(WebCore, MediaAccessibility, MAAudibleMediaCopyPreferredCharacteristics, CFArrayRef, (), ());
    5051
    5152SOFT_LINK_CONSTANT_FOR_SOURCE(WebCore, MediaAccessibility, kMAXCaptionAppearanceSettingsChangedNotification, CFStringRef)
     53SOFT_LINK_CONSTANT_MAY_FAIL_FOR_SOURCE(WebCore, MediaAccessibility, kMAAudibleMediaSettingsChangedNotification, CFStringRef)
    5254
    5355#endif // HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK)
  • trunk/Source/WebCore/platform/cf/MediaAccessibilitySoftLink.h

    r181207 r184799  
    6464SOFT_LINK_FUNCTION_FOR_HEADER(WebCore, MediaAccessibility, MACaptionAppearanceCopyPreferredCaptioningMediaCharacteristics,  CFArrayRef, (MACaptionAppearanceDomain domain), (domain));
    6565#define MACaptionAppearanceCopyPreferredCaptioningMediaCharacteristics softLink_MediaAccessibility_MACaptionAppearanceCopyPreferredCaptioningMediaCharacteristics
     66SOFT_LINK_FUNCTION_MAY_FAIL_FOR_HEADER(WebCore, MediaAccessibility, MAAudibleMediaCopyPreferredCharacteristics, CFArrayRef, (), ())
     67#define MAAudibleMediaCopyPreferredCharacteristics softLink_MediaAccessibility_MAAudibleMediaCopyPreferredCharacteristics
    6668
    6769SOFT_LINK_CONSTANT_FOR_HEADER(WebCore, MediaAccessibility, kMAXCaptionAppearanceSettingsChangedNotification, CFStringRef)
    6870#define kMAXCaptionAppearanceSettingsChangedNotification get_MediaAccessibility_kMAXCaptionAppearanceSettingsChangedNotification()
     71SOFT_LINK_CONSTANT_MAY_FAIL_FOR_HEADER(WebCore, MediaAccessibility, kMAAudibleMediaSettingsChangedNotification, CFStringRef)
     72#define kMAAudibleMediaSettingsChangedNotification get_MediaAccessibility_kMAAudibleMediaSettingsChangedNotification()
    6973
    7074#endif // HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK)
  • trunk/Source/WebCore/platform/graphics/MediaPlayer.cpp

    r184760 r184799  
    12421242}
    12431243
     1244void MediaPlayer::tracksChanged()
     1245{
     1246    m_private->tracksChanged();
     1247}
     1248
    12441249#if ENABLE(AVF_CAPTIONS)
    12451250void MediaPlayer::notifyTrackModeChanged()
     
    13581363}
    13591364
     1365Vector<String> MediaPlayer::preferredAudioCharacteristics() const
     1366{
     1367    return m_client.mediaPlayerPreferredAudioCharacteristics();
     1368}
     1369
    13601370void MediaPlayerFactorySupport::callRegisterMediaEngine(MediaEngineRegister registerMediaEngine)
    13611371{
  • trunk/Source/WebCore/platform/graphics/MediaPlayer.h

    r184760 r184799  
    278278    virtual double mediaPlayerRequestedPlaybackRate() const { return 0; }
    279279    virtual MediaPlayerEnums::VideoFullscreenMode mediaPlayerFullscreenMode() const { return MediaPlayerEnums::VideoFullscreenModeNone; }
     280    virtual Vector<String> mediaPlayerPreferredAudioCharacteristics() const { return Vector<String>(); }
    280281};
    281282
     
    559560    void setTextTrackRepresentation(TextTrackRepresentation*);
    560561    void syncTextTrackBounds();
     562    void tracksChanged();
    561563#if ENABLE(AVF_CAPTIONS)
    562564    void notifyTrackModeChanged();
     
    597599    void handlePlaybackCommand(MediaSession::RemoteControlCommandType);
    598600    String sourceApplicationIdentifier() const;
     601    Vector<String> preferredAudioCharacteristics() const;
    599602
    600603private:
  • trunk/Source/WebCore/platform/graphics/MediaPlayerPrivate.h

    r184760 r184799  
    239239    virtual void setTextTrackRepresentation(TextTrackRepresentation*) { }
    240240    virtual void syncTextTrackBounds() { };
     241    virtual void tracksChanged() { };
    241242#endif
    242243
  • trunk/Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h

    r183746 r184799  
    242242
    243243    virtual void beginLoadingMetadata() = 0;
    244     virtual void tracksChanged() = 0;
    245244    virtual void sizeChanged() = 0;
    246245
  • trunk/Source/WebCore/platform/graphics/avfoundation/MediaSelectionGroupAVFObjC.h

    r183234 r184799  
    3636#include <wtf/RefPtr.h>
    3737#include <wtf/RetainPtr.h>
     38#include <wtf/text/WTFString.h>
    3839
    3940OBJC_CLASS AVPlayerItem;
     
    6869class MediaSelectionGroupAVFObjC : public RefCounted<MediaSelectionGroupAVFObjC> {
    6970public:
    70     static PassRefPtr<MediaSelectionGroupAVFObjC> create(AVPlayerItem*, AVMediaSelectionGroup*);
     71    static PassRefPtr<MediaSelectionGroupAVFObjC> create(AVPlayerItem*, AVMediaSelectionGroup*, const Vector<String>& characteristics);
    7172    ~MediaSelectionGroupAVFObjC();
    7273
     
    7475    MediaSelectionOptionAVFObjC* selectedOption() const { return m_selectedOption; }
    7576
    76     void updateOptions();
     77    void updateOptions(const Vector<String>& characteristics);
    7778
    7879    typedef HashMap<AVMediaSelectionOption*, RefPtr<MediaSelectionOptionAVFObjC>> OptionContainer;
     
    8283
    8384private:
    84     MediaSelectionGroupAVFObjC(AVPlayerItem*, AVMediaSelectionGroup*);
     85    MediaSelectionGroupAVFObjC(AVPlayerItem*, AVMediaSelectionGroup*, const Vector<String>& characteristics);
    8586
    8687    void selectionTimerFired();
  • trunk/Source/WebCore/platform/graphics/avfoundation/MediaSelectionGroupAVFObjC.mm

    r179549 r184799  
    4444SOFT_LINK_CLASS(AVFoundation, AVMediaSelectionOption)
    4545
     46#if HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK)
     47#include <MediaAccessibility/MediaAccessibility.h>
     48#include "MediaAccessibilitySoftLink.h"
     49#endif
     50
    4651namespace WebCore {
    4752
     
    8388}
    8489
    85 PassRefPtr<MediaSelectionGroupAVFObjC> MediaSelectionGroupAVFObjC::create(AVPlayerItem *item, AVMediaSelectionGroup *group)
     90PassRefPtr<MediaSelectionGroupAVFObjC> MediaSelectionGroupAVFObjC::create(AVPlayerItem *item, AVMediaSelectionGroup *group, const Vector<String>& characteristics)
    8691{
    87     return adoptRef(new MediaSelectionGroupAVFObjC(item, group));
     92    return adoptRef(new MediaSelectionGroupAVFObjC(item, group, characteristics));
    8893}
    8994
    90 MediaSelectionGroupAVFObjC::MediaSelectionGroupAVFObjC(AVPlayerItem *item, AVMediaSelectionGroup *group)
     95MediaSelectionGroupAVFObjC::MediaSelectionGroupAVFObjC(AVPlayerItem *item, AVMediaSelectionGroup *group, const Vector<String>& characteristics)
    9196    : m_playerItem(item)
    9297    , m_mediaSelectionGroup(group)
    9398    , m_selectionTimer(*this, &MediaSelectionGroupAVFObjC::selectionTimerFired)
    9499{
    95     updateOptions();
     100    updateOptions(characteristics);
    96101}
    97102
     
    102107}
    103108
    104 void MediaSelectionGroupAVFObjC::updateOptions()
     109void MediaSelectionGroupAVFObjC::updateOptions(const Vector<String>& characteristics)
    105110{
    106111    RetainPtr<NSSet> newAVOptions = adoptNS([[NSSet alloc] initWithArray:[getAVMediaSelectionGroupClass() playableMediaSelectionOptionsFromArray:[m_mediaSelectionGroup options]]]);
     
    139144    NSArray* filteredOptions = [getAVMediaSelectionGroupClass() mediaSelectionOptionsFromArray:[m_mediaSelectionGroup options] filteredAndSortedAccordingToPreferredLanguages:nsLanguages.get()];
    140145
     146    if (![filteredOptions count] && characteristics.isEmpty())
     147        return;
     148
     149    // If no options match our language selection, search for matching characteristics across all the group's options
     150    if (![filteredOptions count])
     151        filteredOptions = [m_mediaSelectionGroup options];
     152
     153    RetainPtr<NSMutableArray> nsCharacteristics = adoptNS([[NSMutableArray alloc] initWithCapacity:characteristics.size()]);
     154    for (auto& characteristic : characteristics)
     155        [nsCharacteristics addObject:(NSString *)characteristic];
     156
     157    NSArray* optionsWithCharacteristics = [getAVMediaSelectionGroupClass() mediaSelectionOptionsFromArray:filteredOptions withMediaCharacteristics:nsCharacteristics.get()];
     158    if (optionsWithCharacteristics && [optionsWithCharacteristics count])
     159        filteredOptions = optionsWithCharacteristics;
     160
    141161    if (![filteredOptions count])
    142162        return;
  • trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h

    r184760 r184799  
    296296    virtual URL resolvedURL() const override;
    297297
     298    Vector<String> preferredAudioCharacteristics() const;
     299
    298300    WeakPtrFactory<MediaPlayerPrivateAVFoundationObjC> m_weakPtrFactory;
    299301
  • trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm

    r184788 r184799  
    19821982#if HAVE(AVFOUNDATION_MEDIA_SELECTION_GROUP)
    19831983template <typename RefT, typename PassRefT>
    1984 void determineChangedTracksFromNewTracksAndOldItems(MediaSelectionGroupAVFObjC* group, Vector<RefT>& oldItems, RefT (*itemFactory)(MediaSelectionOptionAVFObjC&), MediaPlayer* player, void (MediaPlayer::*removedFunction)(PassRefT), void (MediaPlayer::*addedFunction)(PassRefT))
    1985 {
    1986     group->updateOptions();
     1984void determineChangedTracksFromNewTracksAndOldItems(MediaSelectionGroupAVFObjC* group, Vector<RefT>& oldItems, const Vector<String>& characteristics, RefT (*itemFactory)(MediaSelectionOptionAVFObjC&), MediaPlayer* player, void (MediaPlayer::*removedFunction)(PassRefT), void (MediaPlayer::*addedFunction)(PassRefT))
     1985{
     1986    group->updateOptions(characteristics);
    19871987
    19881988    // Only add selection options which do not have an associated persistant track.
     
    20512051
    20522052#if HAVE(AVFOUNDATION_MEDIA_SELECTION_GROUP)
     2053    Vector<String> characteristics = player()->preferredAudioCharacteristics();
    20532054    if (!m_audibleGroup) {
    20542055        if (AVMediaSelectionGroupType *group = safeMediaSelectionGroupForAudibleMedia())
    2055             m_audibleGroup = MediaSelectionGroupAVFObjC::create(m_avPlayerItem.get(), group);
     2056            m_audibleGroup = MediaSelectionGroupAVFObjC::create(m_avPlayerItem.get(), group, characteristics);
    20562057    }
    20572058
    20582059    if (m_audibleGroup)
    2059         determineChangedTracksFromNewTracksAndOldItems(m_audibleGroup.get(), m_audioTracks, &AudioTrackPrivateAVFObjC::create, player(), &MediaPlayer::removeAudioTrack, &MediaPlayer::addAudioTrack);
     2060        determineChangedTracksFromNewTracksAndOldItems(m_audibleGroup.get(), m_audioTracks, characteristics, &AudioTrackPrivateAVFObjC::create, player(), &MediaPlayer::removeAudioTrack, &MediaPlayer::addAudioTrack);
    20602061#endif
    20612062
     
    20792080    if (!m_visualGroup) {
    20802081        if (AVMediaSelectionGroupType *group = safeMediaSelectionGroupForVisualMedia())
    2081             m_visualGroup = MediaSelectionGroupAVFObjC::create(m_avPlayerItem.get(), group);
     2082            m_visualGroup = MediaSelectionGroupAVFObjC::create(m_avPlayerItem.get(), group, Vector<String>());
    20822083    }
    20832084
    20842085    if (m_visualGroup)
    2085         determineChangedTracksFromNewTracksAndOldItems(m_visualGroup.get(), m_videoTracks, &VideoTrackPrivateAVFObjC::create, player(), &MediaPlayer::removeVideoTrack, &MediaPlayer::addVideoTrack);
     2086        determineChangedTracksFromNewTracksAndOldItems(m_visualGroup.get(), m_videoTracks, Vector<String>(), &VideoTrackPrivateAVFObjC::create, player(), &MediaPlayer::removeVideoTrack, &MediaPlayer::addVideoTrack);
    20862087#endif
    20872088
  • trunk/Source/WebCore/platform/mac/SoftLinking.h

    r183746 r184799  
    378378    }
    379379
     380#define SOFT_LINK_CONSTANT_MAY_FAIL_FOR_HEADER(functionNamespace, framework, variableName, variableType) \
     381    WTF_EXTERN_C_BEGIN \
     382    extern const variableType variableName; \
     383    WTF_EXTERN_C_END \
     384    namespace functionNamespace { \
     385    bool canLoad_##framework##_##variableName(); \
     386    bool init_##framework##_##variableName(); \
     387    variableType get_##framework##_##variableName(); \
     388    }
     389
     390#define SOFT_LINK_CONSTANT_MAY_FAIL_FOR_SOURCE(functionNamespace, framework, variableName, variableType) \
     391    WTF_EXTERN_C_BEGIN \
     392    extern const variableType variableName; \
     393    WTF_EXTERN_C_END \
     394    namespace functionNamespace { \
     395    static variableType constant##framework##variableName; \
     396    bool init_##framework##_##variableName(); \
     397    bool init_##framework##_##variableName() \
     398    { \
     399        void* constant = dlsym(framework##Library(), #variableName); \
     400        if (!constant) \
     401            return false; \
     402        constant##framework##variableName = *static_cast<variableType*>(constant); \
     403        return true; \
     404    } \
     405    bool canLoad_##framework##_##variableName(); \
     406    bool canLoad_##framework##_##variableName() \
     407    { \
     408        static bool loaded = init_##framework##_##variableName(); \
     409        return loaded; \
     410    } \
     411    variableType get_##framework##_##variableName(); \
     412    variableType get_##framework##_##variableName() \
     413    { \
     414        return constant##framework##variableName; \
     415    } \
     416    }
     417
    380418#define SOFT_LINK_FUNCTION_FOR_HEADER(functionNamespace, framework, functionName, resultType, parameterDeclarations, parameterNames) \
    381419    WTF_EXTERN_C_BEGIN \
     
    404442            RELEASE_ASSERT_WITH_MESSAGE(softLink##framework##functionName, "%s", dlerror()); \
    405443        }); \
     444        return softLink##framework##functionName parameterNames; \
     445    } \
     446    }
     447
     448#define SOFT_LINK_FUNCTION_MAY_FAIL_FOR_HEADER(functionNamespace, framework, functionName, resultType, parameterDeclarations, parameterNames) \
     449    WTF_EXTERN_C_BEGIN \
     450    resultType functionName parameterDeclarations; \
     451    WTF_EXTERN_C_END \
     452    namespace functionNamespace { \
     453    extern resultType (*softLink##framework##functionName) parameterDeclarations; \
     454    bool canLoad_##framework##_##functionName(); \
     455    bool init_##framework##_##functionName(); \
     456    resultType softLink_##framework##_##functionName parameterDeclarations; \
     457    }
     458
     459#define SOFT_LINK_FUNCTION_MAY_FAIL_FOR_SOURCE(functionNamespace, framework, functionName, resultType, parameterDeclarations, parameterNames) \
     460    WTF_EXTERN_C_BEGIN \
     461    resultType functionName parameterDeclarations; \
     462    WTF_EXTERN_C_END \
     463    namespace functionNamespace { \
     464    resultType (*softLink##framework##functionName) parameterDeclarations = 0; \
     465    bool init_##framework##_##functionName(); \
     466    bool init_##framework##_##functionName() \
     467    { \
     468        ASSERT(!softLink##framework##functionName); \
     469        softLink##framework##functionName = (resultType (*) parameterDeclarations) dlsym(framework##Library(), #functionName); \
     470        return !!softLink##framework##functionName; \
     471    } \
     472    \
     473    bool canLoad_##framework##_##functionName(); \
     474    bool canLoad_##framework##_##functionName() \
     475    { \
     476        static bool loaded = init_##framework##_##functionName(); \
     477        return loaded; \
     478    } \
     479    \
     480    resultType softLink_##framework##_##functionName parameterDeclarations; \
     481    resultType softLink_##framework##_##functionName parameterDeclarations \
     482    { \
     483        ASSERT(softLink##framework##functionName); \
    406484        return softLink##framework##functionName parameterNames; \
    407485    } \
  • trunk/Source/WebCore/platform/win/SoftLinking.h

    r181207 r184799  
    227227    }
    228228
     229#define SOFT_LINK_CONSTANT_MAY_FAIL_FOR_HEADER(functionNamespace, framework, variableName, variableType) \
     230    namespace functionNamespace { \
     231    bool canLoad_##framework##_##variableName(); \
     232    bool init_##framework##_##variableName(); \
     233    variableType get_##framework##_##variableName(); \
     234    }
     235
     236#define SOFT_LINK_CONSTANT_MAY_FAIL_FOR_SOURCE(functionNamespace, framework, variableName, variableType) \
     237    namespace functionNamespace { \
     238    static variableType constant##framework##variableName; \
     239    bool init_##framework##_##variableName(); \
     240    bool init_##framework##_##variableName() \
     241    { \
     242        variableType* ptr = reinterpret_cast<variableType*>(SOFT_LINK_GETPROCADDRESS(framework##Library(), #variableName)); \
     243        if (!ptr) \
     244            return false; \
     245        constant##framework##variableName = *ptr; \
     246        return true; \
     247    } \
     248    bool canLoad_##framework##_##variableName(); \
     249    bool canLoad_##framework##_##variableName() \
     250    { \
     251        static bool loaded = init_##framework##_##variableName(); \
     252        return loaded; \
     253    } \
     254    variableType get_##framework##_##variableName(); \
     255    variableType get_##framework##_##variableName() \
     256    { \
     257        return constant##framework##variableName; \
     258    } \
     259    }
     260
    229261#define SOFT_LINK_FUNCTION_FOR_HEADER(functionNamespace, framework, functionName, resultType, parameterDeclarations, parameterNames) \
    230262    namespace functionNamespace { \
     
    248280    }
    249281
     282#define SOFT_LINK_FUNCTION_MAY_FAIL_FOR_HEADER(functionNamespace, framework, functionName, resultType, parameterDeclarations, parameterNames) \
     283    WTF_EXTERN_C_BEGIN \
     284    resultType functionName parameterDeclarations; \
     285    WTF_EXTERN_C_END \
     286    namespace functionNamespace { \
     287    extern resultType (*softLink##framework##functionName) parameterDeclarations; \
     288    bool canLoad_##framework##_##functionName(); \
     289    bool init_##framework##_##functionName(); \
     290    resultType softLink_##framework##_##functionName parameterDeclarations; \
     291    }
     292
     293#define SOFT_LINK_FUNCTION_MAY_FAIL_FOR_SOURCE(functionNamespace, framework, functionName, resultType, parameterDeclarations, parameterNames) \
     294    WTF_EXTERN_C_BEGIN \
     295    resultType functionName parameterDeclarations; \
     296    WTF_EXTERN_C_END \
     297    namespace functionNamespace { \
     298    resultType (*softLink##framework##functionName) parameterDeclarations = 0; \
     299    bool init_##framework##_##functionName(); \
     300    bool init_##framework##_##functionName() \
     301    { \
     302        ASSERT(!softLink##framework##functionName); \
     303        softLink##framework##functionName = reinterpret_cast<resultType (__cdecl*)parameterDeclarations>(SOFT_LINK_GETPROCADDRESS(framework##Library(), #functionName)); \
     304        return !!softLink##framework##functionName; \
     305    } \
     306    \
     307    bool canLoad_##framework##_##functionName(); \
     308    bool canLoad_##framework##_##functionName() \
     309    { \
     310        static bool loaded = init_##framework##_##functionName(); \
     311        return loaded; \
     312    } \
     313    \
     314    resultType softLink_##framework##_##functionName parameterDeclarations; \
     315    resultType softLink_##framework##_##functionName parameterDeclarations \
     316    { \
     317        ASSERT(softLink##framework##functionName); \
     318        return softLink##framework##functionName parameterNames; \
     319    } \
     320    }
     321
    250322#endif // SoftLinking_h
  • trunk/Source/WebCore/testing/Internals.cpp

    r184315 r184799  
    12941294}
    12951295
     1296Vector<String> Internals::userPreferredAudioCharacteristics() const
     1297{
     1298    Document* document = contextDocument();
     1299    if (!document || !document->page())
     1300        return Vector<String>();
     1301    return document->page()->group().captionPreferences()->preferredAudioCharacteristics();
     1302}
     1303
     1304void Internals::setUserPreferredAudioCharacteristic(const String& characteristic)
     1305{
     1306    Document* document = contextDocument();
     1307    if (!document || !document->page())
     1308        return;
     1309    document->page()->group().captionPreferences()->setPreferredAudioCharacteristic(characteristic);
     1310}
     1311
    12961312unsigned Internals::wheelEventHandlerCount(ExceptionCode& ec)
    12971313{
  • trunk/Source/WebCore/testing/Internals.h

    r184315 r184799  
    191191    void setUserPreferredLanguages(const Vector<String>&);
    192192
     193    Vector<String> userPreferredAudioCharacteristics() const;
     194    void setUserPreferredAudioCharacteristic(const String&);
     195
    193196    unsigned wheelEventHandlerCount(ExceptionCode&);
    194197    unsigned touchEventHandlerCount(ExceptionCode&);
  • trunk/Source/WebCore/testing/Internals.idl

    r184315 r184799  
    161161    void setUserPreferredLanguages(sequence<DOMString> languages);
    162162
     163    sequence<DOMString> userPreferredAudioCharacteristics();
     164    void setUserPreferredAudioCharacteristic(DOMString characteristic);
     165
    163166    [RaisesException] unsigned long wheelEventHandlerCount();
    164167    [RaisesException] unsigned long touchEventHandlerCount();
Note: See TracChangeset for help on using the changeset viewer.