[Mac] Add support for VideoTrack to MediaPlayerPrivateAVFObjC
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 1 Oct 2013 18:24:06 +0000 (18:24 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 1 Oct 2013 18:24:06 +0000 (18:24 +0000)
https://bugs.webkit.org/show_bug.cgi?id=122122

Reviewed by Eric Carlson.

Source/WebCore:

Test: media/track/video-track.html

Refactor the methods which query AVAssetTrack and AVPlayerItemTrack into an Impl class, and
use that class to reset the properties of both AudioTrackAVFObjC and the new VideoTrackAVFObjC.

Add new files to project:
* WebCore.xcodeproj/project.pbxproj:

Add the new implementation class, shared by AudioTrackAVFObjC and VideoTrackAVFObjC:
* platform/graphics/avfoundation/AVTrackPrivateAVFObjCImpl.h: Added.
(WebCore::AVTrackPrivateAVFObjCImpl::create): Simple factory.
(WebCore::AVTrackPrivateAVFObjCImpl::playerItemTrack): Simple getter.
* platform/graphics/avfoundation/AVTrackPrivateAVFObjCImpl.mm: Added.
(WebCore::AVTrackPrivateAVFObjCImpl::AVTrackPrivateAVFObjCImpl): Simple constructor.
(WebCore::AVTrackPrivateAVFObjCImpl::enabled): Pass to AVPlayerItemTrack.
(WebCore::AVTrackPrivateAVFObjCImpl::setEnabled): Ditto.
(WebCore::AVTrackPrivateAVFObjCImpl::audioKind): Distinguish between Alternative and Main content.
(WebCore::AVTrackPrivateAVFObjCImpl::videoKind): Distinguish between Alternative, Main, Caption,
    and Description content.
(WebCore::AVTrackPrivateAVFObjCImpl::id): Pass to AVAssetTrack.
(WebCore::AVTrackPrivateAVFObjCImpl::label): Retrieve the Title metadata in the user's preferred
    language.
(WebCore::AVTrackPrivateAVFObjCImpl::language): Pass to languageForAVAssetTrack.
(WebCore::AVTrackPrivateAVFObjCImpl::languageForAVAssetTrack): Moved from AudioTrackPrivateAVFObjC.
* platform/graphics/avfoundation/VideoTrackPrivateAVF.h: Copied from Source/WebCore/platform/graphics/avfoundation/AudioTrackPrivateAVF.h.
(WebCore::VideoTrackPrivateAVF::kind): Simple getter.
(WebCore::VideoTrackPrivateAVF::id): Ditto.
(WebCore::VideoTrackPrivateAVF::label): Ditto.
(WebCore::VideoTrackPrivateAVF::language): Ditto.
(WebCore::VideoTrackPrivateAVF::setKind): Simple setter.
(WebCore::VideoTrackPrivateAVF::setId): Ditto.
(WebCore::VideoTrackPrivateAVF::setLabel): Ditto.
(WebCore::VideoTrackPrivateAVF::setLanguage): Ditto.
(WebCore::VideoTrackPrivateAVF::VideoTrackPrivateAVF): Simple constructor.
* platform/graphics/avfoundation/objc/AudioTrackPrivateAVFObjC.h:
* platform/graphics/avfoundation/objc/AudioTrackPrivateAVFObjC.mm:
(WebCore::AudioTrackPrivateAVFObjC::AudioTrackPrivateAVFObjC): Create a AVTrackPrivateAVFObjCImpl.
(WebCore::AudioTrackPrivateAVFObjC::resetPropertiesFromTrack): Retrieve properties from m_impl.
(WebCore::AudioTrackPrivateAVFObjC::setPlayerItemTrack): Create a new AVTrackPrivateAVFObjCImpl.
(WebCore::AudioTrackPrivateAVFObjC::playerItemTrack): Pass to m_impl.
(WebCore::AudioTrackPrivateAVFObjC::setEnabled): Ditto.
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::MediaPlayerPrivateAVFoundationObjC::tracksChanged): Refactor implementation into
    template method determineChangedTracksFromNewTracksAndOldItems().
(WebCore::determineChangedTracksFromNewTracksAndOldItems): Refactored.
(WebCore::MediaPlayerPrivateAVFoundationObjC::updateAudioTracks): Pass to determineChangedTracksFromNewTracksAndOldItems.
(WebCore::MediaPlayerPrivateAVFoundationObjC::updateVideoTracks): Ditto.
(WebCore::MediaPlayerPrivateAVFoundationObjC::languageOfPrimaryAudioTrack): Changed class hosting
    languageForAVAssetTrack.
* platform/graphics/avfoundation/objc/VideoTrackPrivateAVFObjC.cpp: Added.
(WebCore::VideoTrackPrivateAVFObjC::VideoTrackPrivateAVFObjC): Create a AVTrackPrivateAVFObjCImpl.
(WebCore::VideoTrackPrivateAVFObjC::resetPropertiesFromTrack): Retrieve properties from m_impl.
(WebCore::VideoTrackPrivateAVFObjC::setPlayerItemTrack): Create a new AVTrackPrivateAVFObjCImpl.
(WebCore::VideoTrackPrivateAVFObjC::playerItemTrack): Pass to m_impl.
(WebCore::VideoTrackPrivateAVFObjC::setSelected): Ditto.
* platform/graphics/avfoundation/objc/VideoTrackPrivateAVFObjC.h: Added.
(WebCore::VideoTrackPrivateAVFObjC::create): Simple factory.

LayoutTests:

* media/track/video-track-expected.txt: Added.
* media/track/video-track.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@156722 268f45cc-cd09-0410-ab3c-d52691b4dbfc

14 files changed:
LayoutTests/ChangeLog
LayoutTests/media/track/video-track-expected.txt [new file with mode: 0644]
LayoutTests/media/track/video-track.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/platform/graphics/avfoundation/AVTrackPrivateAVFObjCImpl.h [new file with mode: 0644]
Source/WebCore/platform/graphics/avfoundation/AVTrackPrivateAVFObjCImpl.mm [new file with mode: 0644]
Source/WebCore/platform/graphics/avfoundation/VideoTrackPrivateAVF.h [new file with mode: 0644]
Source/WebCore/platform/graphics/avfoundation/objc/AudioTrackPrivateAVFObjC.h
Source/WebCore/platform/graphics/avfoundation/objc/AudioTrackPrivateAVFObjC.mm
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm
Source/WebCore/platform/graphics/avfoundation/objc/VideoTrackPrivateAVFObjC.cpp [new file with mode: 0644]
Source/WebCore/platform/graphics/avfoundation/objc/VideoTrackPrivateAVFObjC.h [new file with mode: 0644]

index e4967d0..91b9170 100644 (file)
@@ -1,3 +1,13 @@
+2013-09-30  Jer Noble  <jer.noble@apple.com>
+
+        [Mac] Add support for VideoTrack to MediaPlayerPrivateAVFObjC
+        https://bugs.webkit.org/show_bug.cgi?id=122122
+
+        Reviewed by Eric Carlson.
+
+        * media/track/video-track-expected.txt: Added.
+        * media/track/video-track.html: Added.
+
 2013-10-01  Myles C. Maxfield  <mmaxfield@apple.com>
 
         Center misspelling dots across width of word
diff --git a/LayoutTests/media/track/video-track-expected.txt b/LayoutTests/media/track/video-track-expected.txt
new file mode 100644 (file)
index 0000000..7632ee0
--- /dev/null
@@ -0,0 +1,16 @@
+In-band video tracks.
+
+EVENT(addtrack)
+EXPECTED (event.track == 'video.videoTracks[0]') OK
+
+EVENT(canplaythrough)
+
+** Check initial in-band track states
+EXPECTED (video.videoTracks.length == '1') OK
+
+** Unload video file, check track count
+RUN(video.src = '')
+EXPECTED (video.videoTracks.length == '0') OK
+
+END OF TEST
+
diff --git a/LayoutTests/media/track/video-track.html b/LayoutTests/media/track/video-track.html
new file mode 100644 (file)
index 0000000..b9cd130
--- /dev/null
@@ -0,0 +1,53 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+        <script src=../media-file.js></script>
+        <script src=../video-test.js></script>
+        <script>
+
+            var addtrackEventCount = 0;
+
+            function trackAdded(event)
+            {
+                consoleWrite("EVENT(" + event.type + ")");
+                compareTracks("event.track", "video.videoTracks[" + addtrackEventCount + "]");
+                ++addtrackEventCount;
+                consoleWrite("");
+            }
+
+            function compareTracks(track1, track2)
+            {
+                var equal = (eval(track1) == eval(track2));
+                reportExpected(equal, track1, "==", track2, track1);
+            }
+
+            function canplaythrough()
+            {
+                consoleWrite("<br><i>** Check initial in-band track states<" + "/i>");
+                testExpected("video.videoTracks.length", 1);
+
+                consoleWrite("<br><i>** Unload video file, check track count<" + "/i>");
+                run("video.src = ''");
+                testExpected("video.videoTracks.length", 0);
+
+                consoleWrite("");
+                endTest();
+            }
+
+            function setup()
+            {
+                findMediaElement();
+                video.videoTracks.addEventListener("addtrack", trackAdded);
+                video.src = findMediaFile('video', '../content/test');
+                waitForEvent('canplaythrough', canplaythrough);
+            }
+
+        </script>
+    </head>
+    <body onload="setup()">
+        <video controls></video>
+        <p>In-band video tracks.</p>
+    </body>
+</html>
index 55f2644..70b54ab 100644 (file)
@@ -1,3 +1,69 @@
+2013-09-30  Jer Noble  <jer.noble@apple.com>
+
+        [Mac] Add support for VideoTrack to MediaPlayerPrivateAVFObjC
+        https://bugs.webkit.org/show_bug.cgi?id=122122
+
+        Reviewed by Eric Carlson.
+
+        Test: media/track/video-track.html
+
+        Refactor the methods which query AVAssetTrack and AVPlayerItemTrack into an Impl class, and
+        use that class to reset the properties of both AudioTrackAVFObjC and the new VideoTrackAVFObjC.
+
+        Add new files to project:
+        * WebCore.xcodeproj/project.pbxproj:
+
+        Add the new implementation class, shared by AudioTrackAVFObjC and VideoTrackAVFObjC:
+        * platform/graphics/avfoundation/AVTrackPrivateAVFObjCImpl.h: Added.
+        (WebCore::AVTrackPrivateAVFObjCImpl::create): Simple factory.
+        (WebCore::AVTrackPrivateAVFObjCImpl::playerItemTrack): Simple getter.
+        * platform/graphics/avfoundation/AVTrackPrivateAVFObjCImpl.mm: Added.
+        (WebCore::AVTrackPrivateAVFObjCImpl::AVTrackPrivateAVFObjCImpl): Simple constructor.
+        (WebCore::AVTrackPrivateAVFObjCImpl::enabled): Pass to AVPlayerItemTrack.
+        (WebCore::AVTrackPrivateAVFObjCImpl::setEnabled): Ditto.
+        (WebCore::AVTrackPrivateAVFObjCImpl::audioKind): Distinguish between Alternative and Main content.
+        (WebCore::AVTrackPrivateAVFObjCImpl::videoKind): Distinguish between Alternative, Main, Caption,
+            and Description content.
+        (WebCore::AVTrackPrivateAVFObjCImpl::id): Pass to AVAssetTrack.
+        (WebCore::AVTrackPrivateAVFObjCImpl::label): Retrieve the Title metadata in the user's preferred
+            language.
+        (WebCore::AVTrackPrivateAVFObjCImpl::language): Pass to languageForAVAssetTrack.
+        (WebCore::AVTrackPrivateAVFObjCImpl::languageForAVAssetTrack): Moved from AudioTrackPrivateAVFObjC.
+        * platform/graphics/avfoundation/VideoTrackPrivateAVF.h: Copied from Source/WebCore/platform/graphics/avfoundation/AudioTrackPrivateAVF.h.
+        (WebCore::VideoTrackPrivateAVF::kind): Simple getter.
+        (WebCore::VideoTrackPrivateAVF::id): Ditto.
+        (WebCore::VideoTrackPrivateAVF::label): Ditto.
+        (WebCore::VideoTrackPrivateAVF::language): Ditto.
+        (WebCore::VideoTrackPrivateAVF::setKind): Simple setter.
+        (WebCore::VideoTrackPrivateAVF::setId): Ditto.
+        (WebCore::VideoTrackPrivateAVF::setLabel): Ditto.
+        (WebCore::VideoTrackPrivateAVF::setLanguage): Ditto.
+        (WebCore::VideoTrackPrivateAVF::VideoTrackPrivateAVF): Simple constructor.
+        * platform/graphics/avfoundation/objc/AudioTrackPrivateAVFObjC.h:
+        * platform/graphics/avfoundation/objc/AudioTrackPrivateAVFObjC.mm:
+        (WebCore::AudioTrackPrivateAVFObjC::AudioTrackPrivateAVFObjC): Create a AVTrackPrivateAVFObjCImpl.
+        (WebCore::AudioTrackPrivateAVFObjC::resetPropertiesFromTrack): Retrieve properties from m_impl.
+        (WebCore::AudioTrackPrivateAVFObjC::setPlayerItemTrack): Create a new AVTrackPrivateAVFObjCImpl.
+        (WebCore::AudioTrackPrivateAVFObjC::playerItemTrack): Pass to m_impl.
+        (WebCore::AudioTrackPrivateAVFObjC::setEnabled): Ditto.
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::tracksChanged): Refactor implementation into
+            template method determineChangedTracksFromNewTracksAndOldItems().
+        (WebCore::determineChangedTracksFromNewTracksAndOldItems): Refactored.
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::updateAudioTracks): Pass to determineChangedTracksFromNewTracksAndOldItems.
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::updateVideoTracks): Ditto.
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::languageOfPrimaryAudioTrack): Changed class hosting
+            languageForAVAssetTrack.
+        * platform/graphics/avfoundation/objc/VideoTrackPrivateAVFObjC.cpp: Added.
+        (WebCore::VideoTrackPrivateAVFObjC::VideoTrackPrivateAVFObjC): Create a AVTrackPrivateAVFObjCImpl.
+        (WebCore::VideoTrackPrivateAVFObjC::resetPropertiesFromTrack): Retrieve properties from m_impl.
+        (WebCore::VideoTrackPrivateAVFObjC::setPlayerItemTrack): Create a new AVTrackPrivateAVFObjCImpl.
+        (WebCore::VideoTrackPrivateAVFObjC::playerItemTrack): Pass to m_impl.
+        (WebCore::VideoTrackPrivateAVFObjC::setSelected): Ditto.
+        * platform/graphics/avfoundation/objc/VideoTrackPrivateAVFObjC.h: Added.
+        (WebCore::VideoTrackPrivateAVFObjC::create): Simple factory.
+
 2013-10-01  Andreas Kling  <akling@apple.com>
 
         Leaf EventTarget subclasses should be FINAL.
index 9699160..c7a1afb 100644 (file)
                CD1E7347167BC78E009A885D /* TextTrackRepresentation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD1E7346167BC78E009A885D /* TextTrackRepresentation.cpp */; };
                CD27F6E51457685A0078207D /* JSMediaController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD27F6E2145767580078207D /* JSMediaController.cpp */; };
                CD27F6E7145770D30078207D /* MediaController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD27F6E6145770D30078207D /* MediaController.cpp */; };
+               CD336F6117F9F64700DDDCD0 /* AVTrackPrivateAVFObjCImpl.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD336F5F17F9F64700DDDCD0 /* AVTrackPrivateAVFObjCImpl.mm */; };
+               CD336F6217F9F64700DDDCD0 /* AVTrackPrivateAVFObjCImpl.h in Headers */ = {isa = PBXBuildFile; fileRef = CD336F6017F9F64700DDDCD0 /* AVTrackPrivateAVFObjCImpl.h */; };
+               CD336F6417FA0A4D00DDDCD0 /* VideoTrackPrivateAVF.h in Headers */ = {isa = PBXBuildFile; fileRef = CD336F6317FA0A4D00DDDCD0 /* VideoTrackPrivateAVF.h */; };
+               CD336F6717FA0AC600DDDCD0 /* VideoTrackPrivateAVFObjC.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD336F6517FA0AC600DDDCD0 /* VideoTrackPrivateAVFObjC.cpp */; };
+               CD336F6817FA0AC600DDDCD0 /* VideoTrackPrivateAVFObjC.h in Headers */ = {isa = PBXBuildFile; fileRef = CD336F6617FA0AC600DDDCD0 /* VideoTrackPrivateAVFObjC.h */; };
                CD37B39815C1B971006DC898 /* DiagnosticLoggingKeys.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD37B37415C1A7E1006DC898 /* DiagnosticLoggingKeys.cpp */; };
                CD3A495217A9C8C600274E42 /* MediaSourceBase.h in Headers */ = {isa = PBXBuildFile; fileRef = CD3A495117A9C8B600274E42 /* MediaSourceBase.h */; };
                CD3A495417A9CC9000274E42 /* MediaSourceBase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD3A495017A9C8B600274E42 /* MediaSourceBase.cpp */; };
                CD27F6E3145767580078207D /* JSMediaController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSMediaController.h; sourceTree = "<group>"; };
                CD27F6E4145767870078207D /* MediaController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaController.h; sourceTree = "<group>"; };
                CD27F6E6145770D30078207D /* MediaController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MediaController.cpp; sourceTree = "<group>"; };
+               CD336F5F17F9F64700DDDCD0 /* AVTrackPrivateAVFObjCImpl.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AVTrackPrivateAVFObjCImpl.mm; sourceTree = "<group>"; };
+               CD336F6017F9F64700DDDCD0 /* AVTrackPrivateAVFObjCImpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AVTrackPrivateAVFObjCImpl.h; sourceTree = "<group>"; };
+               CD336F6317FA0A4D00DDDCD0 /* VideoTrackPrivateAVF.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VideoTrackPrivateAVF.h; sourceTree = "<group>"; };
+               CD336F6517FA0AC600DDDCD0 /* VideoTrackPrivateAVFObjC.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = VideoTrackPrivateAVFObjC.cpp; path = objc/VideoTrackPrivateAVFObjC.cpp; sourceTree = "<group>"; };
+               CD336F6617FA0AC600DDDCD0 /* VideoTrackPrivateAVFObjC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VideoTrackPrivateAVFObjC.h; path = objc/VideoTrackPrivateAVFObjC.h; sourceTree = "<group>"; };
                CD37B37415C1A7E1006DC898 /* DiagnosticLoggingKeys.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DiagnosticLoggingKeys.cpp; sourceTree = "<group>"; };
                CD37B37515C1A7E1006DC898 /* DiagnosticLoggingKeys.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DiagnosticLoggingKeys.h; sourceTree = "<group>"; };
                CD3A495017A9C8B600274E42 /* MediaSourceBase.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = MediaSourceBase.cpp; sourceTree = "<group>"; };
                                07B442D5166C70B000556CAD /* InbandTextTrackPrivateAVF.h */,
                                076F0D0912B8192700C26AA4 /* MediaPlayerPrivateAVFoundation.cpp */,
                                076F0D0A12B8192700C26AA4 /* MediaPlayerPrivateAVFoundation.h */,
+                               CD336F6317FA0A4D00DDDCD0 /* VideoTrackPrivateAVF.h */,
                        );
                        path = avfoundation;
                        sourceTree = "<group>";
                DF9AFD6F13FC31B00015FEB7 /* objc */ = {
                        isa = PBXGroup;
                        children = (
+                               CD336F5F17F9F64700DDDCD0 /* AVTrackPrivateAVFObjCImpl.mm */,
+                               CD336F6017F9F64700DDDCD0 /* AVTrackPrivateAVFObjCImpl.h */,
                                CDE3A85517F6020400C5BE20 /* AudioTrackPrivateAVFObjC.mm */,
                                CDE3A85617F6020400C5BE20 /* AudioTrackPrivateAVFObjC.h */,
                                07AA6B69166D019500D45671 /* InbandTextTrackPrivateAVFObjC.h */,
                                DF9AFD7113FC31D80015FEB7 /* MediaPlayerPrivateAVFoundationObjC.mm */,
                                CD7E05201651A84100C1201F /* WebCoreAVFResourceLoader.h */,
                                CD7E05211651A84100C1201F /* WebCoreAVFResourceLoader.mm */,
+                               CD336F6517FA0AC600DDDCD0 /* VideoTrackPrivateAVFObjC.cpp */,
+                               CD336F6617FA0AC600DDDCD0 /* VideoTrackPrivateAVFObjC.h */,
                        );
                        name = objc;
                        sourceTree = "<group>";
                                8485227E1190162C006EDC7F /* JSSVGVKernElement.h in Headers */,
                                078E092017D14D1C00420AA1 /* RTCDTMFSender.h in Headers */,
                                71DCB7021568197600862271 /* JSSVGZoomAndPan.h in Headers */,
+                               CD336F6417FA0A4D00DDDCD0 /* VideoTrackPrivateAVF.h in Headers */,
                                B2FA3E190AB75A6F000E5AC4 /* JSSVGZoomEvent.h in Headers */,
                                65DF320409D1CC60000BE325 /* JSText.h in Headers */,
                                933A14B90B7D1D5200A53FFD /* JSTextEvent.h in Headers */,
                                9746AF2C14F4DDE6003E7A70 /* PositionCallback.h in Headers */,
                                9746AF2E14F4DDE6003E7A70 /* PositionError.h in Headers */,
                                9746AF3014F4DDE6003E7A70 /* PositionErrorCallback.h in Headers */,
+                               CD336F6817FA0AC600DDDCD0 /* VideoTrackPrivateAVFObjC.h in Headers */,
                                37919C240B7D188600A56998 /* PositionIterator.h in Headers */,
                                9746AF3214F4DDE6003E7A70 /* PositionOptions.h in Headers */,
                                C0F2A44113869AAB0066C534 /* preprocessor.pm in Headers */,
                                A136A00D1134DBD200CC8D50 /* XMLHttpRequestProgressEventThrottle.h in Headers */,
                                BCDFD48E0E305290009D10AD /* XMLHttpRequestUpload.h in Headers */,
                                A833C80D0A2CF25600D57664 /* XMLNames.h in Headers */,
+                               CD336F6217F9F64700DDDCD0 /* AVTrackPrivateAVFObjCImpl.h in Headers */,
                                E15A36D71104572000B7B639 /* XMLNSNames.h in Headers */,
                                1ACE53EB0A8D18E70022947D /* XMLSerializer.h in Headers */,
                                5905ADC01302F3CE00F116DF /* XMLTreeViewer.h in Headers */,
                                1A494BFA0A122F4400FDAFC1 /* JSHTMLElement.cpp in Sources */,
                                07969DB117D14151007FF842 /* JSRTCDTMFToneChangeEvent.cpp in Sources */,
                                BC5823F50C0A98DF0053F1B5 /* JSHTMLElementCustom.cpp in Sources */,
+                               CD336F6717FA0AC600DDDCD0 /* VideoTrackPrivateAVFObjC.cpp in Sources */,
                                938E65F709F0985D008A48EC /* JSHTMLElementWrapperFactory.cpp in Sources */,
                                BC6D44EC0C07F2ED0072D2C9 /* JSHTMLEmbedElement.cpp in Sources */,
                                BC6D44BE0C07EFB60072D2C9 /* JSHTMLEmbedElementCustom.cpp in Sources */,
                                5DA5E0FC102B953800088CF9 /* JSWebSocket.cpp in Sources */,
                                65DF320509D1CC60000BE325 /* JSWheelEvent.cpp in Sources */,
                                E1C8BE5D0E8BD15A0064CB7D /* JSWorker.cpp in Sources */,
+                               CD336F6117F9F64700DDDCD0 /* AVTrackPrivateAVFObjCImpl.mm in Sources */,
                                E1CA5CBC0E8CDCAF00E8EF90 /* JSWorkerCustom.cpp in Sources */,
                                E182568F0EF2B02D00933242 /* JSWorkerGlobalScope.cpp in Sources */,
                                E1C36D340EB0A094007410BC /* JSWorkerGlobalScopeBase.cpp in Sources */,
diff --git a/Source/WebCore/platform/graphics/avfoundation/AVTrackPrivateAVFObjCImpl.h b/Source/WebCore/platform/graphics/avfoundation/AVTrackPrivateAVFObjCImpl.h
new file mode 100644 (file)
index 0000000..953aa04
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#ifndef AVTrackPrivateAVFObjCImpl_h
+#define AVTrackPrivateAVFObjCImpl_h
+
+#if ENABLE(VIDEO_TRACK)
+
+#include "AudioTrackPrivate.h"
+#include "VideoTrackPrivate.h"
+#include <wtf/OwnPtr.h>
+#include <wtf/RetainPtr.h>
+
+OBJC_CLASS AVAssetTrack;
+OBJC_CLASS AVPlayerItemTrack;
+
+namespace WebCore {
+
+class AVTrackPrivateAVFObjCImpl {
+public:
+    static OwnPtr<AVTrackPrivateAVFObjCImpl> create(AVPlayerItemTrack* track)
+    {
+        return createOwned<AVTrackPrivateAVFObjCImpl>(track);
+    }
+    AVTrackPrivateAVFObjCImpl(AVPlayerItemTrack*);
+
+    AVPlayerItemTrack* playerItemTrack() const { return m_playerItemTrack.get(); }
+
+    bool enabled() const;
+    void setEnabled(bool);
+
+    AudioTrackPrivate::Kind audioKind() const;
+    VideoTrackPrivate::Kind videoKind() const;
+
+    AtomicString id() const;
+    AtomicString label() const;
+    AtomicString language() const;
+
+    static String languageForAVAssetTrack(AVAssetTrack*);
+
+private:
+    RetainPtr<AVPlayerItemTrack> m_playerItemTrack;
+};
+
+}
+
+#endif // ENABLE(VIDEO_TRACK)
+
+#endif
diff --git a/Source/WebCore/platform/graphics/avfoundation/AVTrackPrivateAVFObjCImpl.mm b/Source/WebCore/platform/graphics/avfoundation/AVTrackPrivateAVFObjCImpl.mm
new file mode 100644 (file)
index 0000000..9978c63
--- /dev/null
@@ -0,0 +1,146 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#include "config.h"
+#include "AVTrackPrivateAVFObjCImpl.h"
+
+#if ENABLE(VIDEO_TRACK)
+
+#import "SoftLinking.h"
+#import <objc/runtime.h>
+#import <AVFoundation/AVAssetTrack.h>
+#import <AVFoundation/AVPlayerItemTrack.h>
+#import <AVFoundation/AVMetadataItem.h>
+
+SOFT_LINK_FRAMEWORK_OPTIONAL(AVFoundation)
+
+SOFT_LINK_CLASS(AVFoundation, AVAssetTrack)
+SOFT_LINK_CLASS(AVFoundation, AVPlayerItemTrack)
+SOFT_LINK_CLASS(AVFoundation, AVMetadataItem)
+
+SOFT_LINK_POINTER_OPTIONAL(AVFoundation, AVMediaCharacteristicIsMainProgramContent, NSString *)
+SOFT_LINK_POINTER_OPTIONAL(AVFoundation, AVMediaCharacteristicDescribesVideoForAccessibility, NSString *)
+SOFT_LINK_POINTER_OPTIONAL(AVFoundation, AVMediaCharacteristicIsAuxiliaryContent, NSString *)
+SOFT_LINK_POINTER_OPTIONAL(AVFoundation, AVMediaCharacteristicTranscribesSpokenDialogForAccessibility, NSString *)
+SOFT_LINK_POINTER_OPTIONAL(AVFoundation, AVMetadataCommonKeyTitle, NSString *)
+SOFT_LINK_POINTER_OPTIONAL(AVFoundation, AVMetadataKeySpaceCommon, NSString *)
+
+#define AVMetadataItem getAVMetadataItemClass()
+
+#define AVMediaCharacteristicIsMainProgramContent getAVMediaCharacteristicIsMainProgramContent()
+#define AVMediaCharacteristicDescribesVideoForAccessibility getAVMediaCharacteristicDescribesVideoForAccessibility()
+#define AVMediaCharacteristicIsAuxiliaryContent getAVMediaCharacteristicIsAuxiliaryContent()
+#define AVMediaCharacteristicTranscribesSpokenDialogForAccessibility getAVMediaCharacteristicTranscribesSpokenDialogForAccessibility()
+#define AVMetadataCommonKeyTitle getAVMetadataCommonKeyTitle()
+#define AVMetadataKeySpaceCommon getAVMetadataKeySpaceCommon()
+
+namespace WebCore {
+
+AVTrackPrivateAVFObjCImpl::AVTrackPrivateAVFObjCImpl(AVPlayerItemTrack* track)
+    : m_playerItemTrack(track)
+{
+}
+
+bool AVTrackPrivateAVFObjCImpl::enabled() const
+{
+    return [m_playerItemTrack.get() isEnabled];
+}
+
+void AVTrackPrivateAVFObjCImpl::setEnabled(bool enabled)
+{
+    [m_playerItemTrack.get() setEnabled:enabled];
+}
+
+AudioTrackPrivate::Kind AVTrackPrivateAVFObjCImpl::audioKind() const
+{
+    AVAssetTrack* assetTrack = [m_playerItemTrack.get() assetTrack];
+    if ([assetTrack hasMediaCharacteristic:AVMediaCharacteristicIsAuxiliaryContent])
+        return AudioTrackPrivate::Alternative;
+    else if ([assetTrack hasMediaCharacteristic:AVMediaCharacteristicIsMainProgramContent])
+        return AudioTrackPrivate::Main;
+    return AudioTrackPrivate::None;
+}
+
+VideoTrackPrivate::Kind AVTrackPrivateAVFObjCImpl::videoKind() const
+{
+    AVAssetTrack* assetTrack = [m_playerItemTrack.get() assetTrack];
+    if ([assetTrack hasMediaCharacteristic:AVMediaCharacteristicDescribesVideoForAccessibility])
+        return VideoTrackPrivate::Sign;
+    else if ([assetTrack hasMediaCharacteristic:AVMediaCharacteristicTranscribesSpokenDialogForAccessibility])
+        return VideoTrackPrivate::Captions;
+    else if ([assetTrack hasMediaCharacteristic:AVMediaCharacteristicIsAuxiliaryContent])
+        return VideoTrackPrivate::Alternative;
+    else if ([assetTrack hasMediaCharacteristic:AVMediaCharacteristicIsMainProgramContent])
+        return VideoTrackPrivate::Main;
+    return VideoTrackPrivate::None;
+}
+
+AtomicString AVTrackPrivateAVFObjCImpl::id() const
+{
+    return String::format("%d", [[m_playerItemTrack.get() assetTrack] trackID]);
+}
+
+AtomicString AVTrackPrivateAVFObjCImpl::label() const
+{
+    NSArray *titles = [AVMetadataItem metadataItemsFromArray:[[m_playerItemTrack.get() assetTrack] commonMetadata] withKey:AVMetadataCommonKeyTitle keySpace:AVMetadataKeySpaceCommon];
+    if (![titles count])
+        return emptyAtom;
+
+    // If possible, return a title in one of the user's preferred languages.
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080
+    NSArray *titlesForPreferredLanguages = [AVMetadataItem metadataItemsFromArray:titles filteredAndSortedAccordingToPreferredLanguages:[NSLocale preferredLanguages]];
+#else
+    NSArray *titlesForPreferredLanguages = [AVMetadataItem metadataItemsFromArray:titles withLocale:[NSLocale currentLocale]];
+#endif
+    if ([titlesForPreferredLanguages count])
+        return [[titlesForPreferredLanguages objectAtIndex:0] stringValue];
+    return [[titles objectAtIndex:0] stringValue];
+}
+
+AtomicString AVTrackPrivateAVFObjCImpl::language() const
+{
+    return languageForAVAssetTrack([m_playerItemTrack.get() assetTrack]);
+}
+
+String AVTrackPrivateAVFObjCImpl::languageForAVAssetTrack(AVAssetTrack* track)
+{
+    NSString *language = [track extendedLanguageTag];
+
+    // If the language code is stored as a QuickTime 5-bit packed code there aren't enough bits for a full
+    // RFC 4646 language tag so extendedLanguageTag returns NULL. In this case languageCode will return the
+    // ISO 639-2/T language code so check it.
+    if (!language)
+        language = [track languageCode];
+
+    // Some legacy tracks have "und" as a language, treat that the same as no language at all.
+    if (!language || [language isEqualToString:@"und"])
+        return emptyString();
+
+    return language;
+}
+
+}
+
+#endif // ENABLE(VIDEO_TRACK)
diff --git a/Source/WebCore/platform/graphics/avfoundation/VideoTrackPrivateAVF.h b/Source/WebCore/platform/graphics/avfoundation/VideoTrackPrivateAVF.h
new file mode 100644 (file)
index 0000000..6350439
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef VideoTrackPrivateAVF_h
+#define VideoTrackPrivateAVF_h
+
+#if ENABLE(VIDEO_TRACK)
+
+#include "VideoTrackPrivate.h"
+
+namespace WebCore {
+
+class VideoTrackPrivateAVF : public VideoTrackPrivate {
+    WTF_MAKE_NONCOPYABLE(VideoTrackPrivateAVF)
+public:
+
+    virtual Kind kind() const OVERRIDE { return m_kind; }
+    virtual AtomicString id() const OVERRIDE { return m_id; }
+    virtual AtomicString label() const OVERRIDE { return m_label; }
+    virtual AtomicString language() const OVERRIDE { return m_language; }
+
+protected:
+    void setKind(Kind kind) { m_kind = kind; }
+    void setId(AtomicString newId) { m_id = newId; }
+    void setLabel(AtomicString label) { m_label = label; }
+    void setLanguage(AtomicString language) { m_language = language; }
+
+    Kind m_kind;
+    AtomicString m_id;
+    AtomicString m_label;
+    AtomicString m_language;
+
+    VideoTrackPrivateAVF()
+        : m_kind(None)
+    {
+    }
+};
+
+}
+
+#endif // ENABLE(VIDEO_TRACK)
+
+#endif // VideoTrackPrivateAVF_h
index 4c41cd7..7eea8c5 100644 (file)
 #if ENABLE(VIDEO_TRACK)
 
 #include "AudioTrackPrivateAVF.h"
-#include <wtf/RetainPtr.h>
+#include <wtf/OwnPtr.h>
 
-OBJC_CLASS AVAssetTrack;
 OBJC_CLASS AVPlayerItemTrack;
 
 namespace WebCore {
 
+class AVTrackPrivateAVFObjCImpl;
+
 class AudioTrackPrivateAVFObjC : public AudioTrackPrivateAVF {
     WTF_MAKE_NONCOPYABLE(AudioTrackPrivateAVFObjC)
 public:
@@ -47,16 +48,13 @@ public:
     virtual void setEnabled(bool);
 
     void setPlayerItemTrack(AVPlayerItemTrack*);
-    AVPlayerItemTrack* playerItemTrack() { return m_playerItemTrack.get(); }
-
-    static String languageForAVAssetTrack(AVAssetTrack*);
+    AVPlayerItemTrack* playerItemTrack();
 
 private:
     AudioTrackPrivateAVFObjC(AVPlayerItemTrack*);
 
     void resetPropertiesFromTrack();
-
-    RetainPtr<AVPlayerItemTrack> m_playerItemTrack;
+    OwnPtr<AVTrackPrivateAVFObjCImpl> m_impl;
 };
 
 }
index aed6319..6b47175 100644 (file)
 
 #import "config.h"
 #import "AudioTrackPrivateAVFObjC.h"
+#import "AVTrackPrivateAVFObjCImpl.h"
 
 #if ENABLE(VIDEO_TRACK)
 
-#import "SoftLinking.h"
-#import <objc/runtime.h>
-#import <AVFoundation/AVAssetTrack.h>
-#import <AVFoundation/AVPlayerItemTrack.h>
-#import <AVFoundation/AVMetadataItem.h>
-
-SOFT_LINK_FRAMEWORK_OPTIONAL(AVFoundation)
-
-SOFT_LINK_CLASS(AVFoundation, AVAssetTrack)
-SOFT_LINK_CLASS(AVFoundation, AVPlayerItemTrack)
-SOFT_LINK_CLASS(AVFoundation, AVMetadataItem)
-
-SOFT_LINK_POINTER(AVFoundation, AVMetadataCommonKeyTitle, NSString *)
-SOFT_LINK_POINTER(AVFoundation, AVMetadataKeySpaceCommon, NSString *)
-
-#define AVMetadataItem getAVMetadataItemClass()
-
-#define AVMetadataCommonKeyTitle getAVMetadataCommonKeyTitle()
-#define AVMetadataKeySpaceCommon getAVMetadataKeySpaceCommon()
-
-#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080
-
-SOFT_LINK_POINTER(AVFoundation, AVMediaCharacteristicIsMainProgramContent, NSString *)
-SOFT_LINK_POINTER(AVFoundation, AVMediaCharacteristicDescribesVideoForAccessibility, NSString *)
-SOFT_LINK_POINTER(AVFoundation, AVMediaCharacteristicIsAuxiliaryContent, NSString *)
-SOFT_LINK_POINTER(AVFoundation, AVMediaCharacteristicTranscribesSpokenDialogForAccessibility, NSString *)
-
-#define AVMediaCharacteristicIsMainProgramContent getAVMediaCharacteristicIsMainProgramContent()
-#define AVMediaCharacteristicDescribesVideoForAccessibility getAVMediaCharacteristicDescribesVideoForAccessibility()
-#define AVMediaCharacteristicIsAuxiliaryContent getAVMediaCharacteristicIsAuxiliaryContent()
-#define AVMediaCharacteristicTranscribesSpokenDialogForAccessibility getAVMediaCharacteristicTranscribesSpokenDialogForAccessibility()
-
-#else
-
-#define AVMediaCharacteristicIsMainProgramContent @"public.main-program-content"
-#define AVMediaCharacteristicDescribesVideoForAccessibility @"public.accessibility.describes-video"
-#define AVMediaCharacteristicIsAuxiliaryContent @"public.auxiliary-content"
-#define AVMediaCharacteristicTranscribesSpokenDialogForAccessibility @"public.accessibility.transcribes-spoken-dialog"
-
-#endif
-
 namespace WebCore {
 
 AudioTrackPrivateAVFObjC::AudioTrackPrivateAVFObjC(AVPlayerItemTrack* track)
-    : m_playerItemTrack(track)
+    : m_impl(AVTrackPrivateAVFObjCImpl::create(track))
 {
     resetPropertiesFromTrack();
 }
 
 void AudioTrackPrivateAVFObjC::resetPropertiesFromTrack()
 {
-    AVAssetTrack* assetTrack = [m_playerItemTrack.get() assetTrack];
-    if (!assetTrack) {
-        setEnabled(false);
-        setKind(None);
-        setId(emptyAtom);
-        setLabel(emptyAtom);
-        setLanguage(emptyAtom);
-        return;
-    }
-
-    setEnabled([m_playerItemTrack.get() isEnabled]);
-    setId(String::format("%d", [assetTrack trackID]));
-
-    if ([assetTrack hasMediaCharacteristic:AVMediaCharacteristicDescribesVideoForAccessibility])
-        setKind(Description);
-    else if ([assetTrack hasMediaCharacteristic:AVMediaCharacteristicTranscribesSpokenDialogForAccessibility])
-        setKind(Translation);
-    else if ([assetTrack hasMediaCharacteristic:AVMediaCharacteristicIsAuxiliaryContent])
-        setKind(Alternative);
-    else if ([assetTrack hasMediaCharacteristic:AVMediaCharacteristicIsMainProgramContent])
-        setKind(Main);
-    else
-        setKind(None);
-
-    NSArray *titles = [AVMetadataItem metadataItemsFromArray:[assetTrack commonMetadata] withKey:AVMetadataCommonKeyTitle keySpace:AVMetadataKeySpaceCommon];
-    if ([titles count]) {
-        // If possible, return a title in one of the user's preferred languages.
-#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080
-        NSArray *titlesForPreferredLanguages = [AVMetadataItem metadataItemsFromArray:titles filteredAndSortedAccordingToPreferredLanguages:[NSLocale preferredLanguages]];
-#else
-        NSArray *titlesForPreferredLanguages = [AVMetadataItem metadataItemsFromArray:titles withLocale:[NSLocale currentLocale]];
-#endif
-        if ([titlesForPreferredLanguages count])
-            setLabel([[titlesForPreferredLanguages objectAtIndex:0] stringValue]);
-        else
-            setLabel([[titles objectAtIndex:0] stringValue]);
-    }
-
-    setLanguage(languageForAVAssetTrack(assetTrack));
+    setEnabled(m_impl->enabled());
+    setKind(m_impl->audioKind());
+    setId(m_impl->id());
+    setLabel(m_impl->label());
+    setLanguage(m_impl->language());
 }
 
 void AudioTrackPrivateAVFObjC::setPlayerItemTrack(AVPlayerItemTrack *track)
 {
-    m_playerItemTrack = track;
+    m_impl = AVTrackPrivateAVFObjCImpl::create(track);
     resetPropertiesFromTrack();
 }
 
-void AudioTrackPrivateAVFObjC::setEnabled(bool enabled)
+AVPlayerItemTrack* AudioTrackPrivateAVFObjC::playerItemTrack()
 {
-    AudioTrackPrivateAVF::setEnabled(enabled);
-    [m_playerItemTrack.get() setEnabled:enabled];
+    return m_impl->playerItemTrack();
 }
 
-String AudioTrackPrivateAVFObjC::languageForAVAssetTrack(AVAssetTrack* track)
+void AudioTrackPrivateAVFObjC::setEnabled(bool enabled)
 {
-    NSString *language = [track extendedLanguageTag];
-
-    // If the language code is stored as a QuickTime 5-bit packed code there aren't enough bits for a full
-    // RFC 4646 language tag so extendedLanguageTag returns NULL. In this case languageCode will return the
-    // ISO 639-2/T language code so check it.
-    if (!language)
-        language = [track languageCode];
-
-    // Some legacy tracks have "und" as a language, treat that the same as no language at all.
-    if (!language || [language isEqualToString:@"und"])
-        return emptyString();
-
-    return language;
+    AudioTrackPrivateAVF::setEnabled(enabled);
+    m_impl->setEnabled(enabled);
 }
 
 }
index fb0b44c..66f3d2c 100644 (file)
@@ -60,6 +60,7 @@ namespace WebCore {
 class WebCoreAVFResourceLoader;
 class InbandTextTrackPrivateAVFObjC;
 class AudioTrackPrivateAVFObjC;
+class VideoTrackPrivateAVFObjC;
 
 class MediaPlayerPrivateAVFoundationObjC : public MediaPlayerPrivateAVFoundation {
 public:
@@ -185,6 +186,11 @@ private:
     void processLegacyClosedCaptionsTracks();
 #endif
 
+#if ENABLE(VIDEO_TRACK)
+    void updateAudioTracks();
+    void updateVideoTracks();
+#endif
+
     RetainPtr<AVURLAsset> m_avAsset;
     RetainPtr<AVPlayer> m_avPlayer;
     RetainPtr<AVPlayerItem> m_avPlayerItem;
@@ -218,6 +224,7 @@ private:
 
 #if ENABLE(VIDEO_TRACK)
     Vector<RefPtr<AudioTrackPrivateAVFObjC>> m_audioTracks;
+    Vector<RefPtr<VideoTrackPrivateAVFObjC>> m_videoTracks;
 #endif
 
     InbandTextTrackPrivateAVF* m_currentTrack;
index 7762f07..11fb357 100644 (file)
@@ -30,6 +30,7 @@
 #import "MediaPlayerPrivateAVFoundationObjC.h"
 
 #import "AudioTrackPrivateAVFObjC.h"
+#import "AVTrackPrivateAVFObjCImpl.h"
 #import "BlockExceptions.h"
 #import "ExceptionCodePlaceholder.h"
 #import "FloatConversion.h"
@@ -44,6 +45,7 @@
 #import "SoftLinking.h"
 #import "TimeRanges.h"
 #import "UUID.h"
+#import "VideoTrackPrivateAVFObjC.h"
 #import "WebCoreAVFResourceLoader.h"
 #import "WebCoreSystemInterface.h"
 #import <objc/runtime.h>
@@ -1052,43 +1054,8 @@ void MediaPlayerPrivateAVFoundationObjC::tracksChanged()
 
 
 #if ENABLE(VIDEO_TRACK)
-        RetainPtr<NSSet> audioTracks = adoptNS([[NSSet alloc] initWithArray:[tracks objectsAtIndexes:[tracks indexesOfObjectsPassingTest:^(id track, NSUInteger, BOOL*){
-            return [[[track assetTrack] mediaType] isEqualToString:AVMediaTypeAudio];
-        }]]]);
-        RetainPtr<NSMutableSet> oldAudioTracks = adoptNS([[NSMutableSet alloc] initWithCapacity:m_audioTracks.size()]);
-
-        typedef Vector<RefPtr<AudioTrackPrivateAVFObjC> > AudioTrackVector;
-        for (AudioTrackVector::iterator i = m_audioTracks.begin(); i != m_audioTracks.end(); ++i)
-            [oldAudioTracks.get() addObject:(*i)->playerItemTrack()];
-
-        RetainPtr<NSMutableSet> removedAVAudioTracks = adoptNS([oldAudioTracks.get() mutableCopy]);
-        [removedAVAudioTracks.get() minusSet:audioTracks.get()];
-
-        RetainPtr<NSMutableSet> addedAVAudioTracks = adoptNS([audioTracks.get() mutableCopy]);
-        [addedAVAudioTracks.get() minusSet:oldAudioTracks.get()];
-
-        AudioTrackVector replacementAudioTracks;
-        AudioTrackVector addedAudioTracks;
-        AudioTrackVector removedAudioTracks;
-        for (AudioTrackVector::iterator i = m_audioTracks.begin(); i != m_audioTracks.end(); ++i) {
-            if ([removedAVAudioTracks containsObject:(*i)->playerItemTrack()])
-                removedAudioTracks.append(*i);
-            else
-                replacementAudioTracks.append(*i);
-        }
-
-        for (AVPlayerItemTrack* playerItemTrack in addedAVAudioTracks.get())
-            addedAudioTracks.append(AudioTrackPrivateAVFObjC::create(playerItemTrack));
-
-        replacementAudioTracks.appendVector(addedAudioTracks);
-
-        m_audioTracks.swap(replacementAudioTracks);
-
-        for (AudioTrackVector::iterator i = removedAudioTracks.begin(); i != removedAudioTracks.end(); ++i)
-            player()->removeAudioTrack(*i);
-
-        for (AudioTrackVector::iterator i = addedAudioTracks.begin(); i != addedAudioTracks.end(); ++i)
-            player()->addAudioTrack(*i);
+        updateAudioTracks();
+        updateVideoTracks();
 #endif
     }
 
@@ -1121,6 +1088,59 @@ void MediaPlayerPrivateAVFoundationObjC::tracksChanged()
     setDelayCharacteristicsChangedNotification(false);
 }
 
+#if ENABLE(VIDEO_TRACK)
+template <typename RefT, typename PassRefT>
+void determineChangedTracksFromNewTracksAndOldItems(NSArray* tracks, NSString* trackType, Vector<RefT>& oldItems, RefT (*itemFactory)(AVPlayerItemTrack*), MediaPlayer* player, void (MediaPlayer::*addedFunction)(PassRefT), void (MediaPlayer::*removedFunction)(PassRefT))
+{
+    RetainPtr<NSSet> newTracks = adoptNS([[NSSet alloc] initWithArray:[tracks objectsAtIndexes:[tracks indexesOfObjectsPassingTest:^(id track, NSUInteger, BOOL*){
+        return [[[track assetTrack] mediaType] isEqualToString:trackType];
+    }]]]);
+    RetainPtr<NSMutableSet> oldTracks = adoptNS([[NSMutableSet alloc] initWithCapacity:oldItems.size()]);
+
+    typedef Vector<RefT> ItemVector;
+    for (auto i = oldItems.begin(); i != oldItems.end(); ++i)
+        [oldTracks addObject:(*i)->playerItemTrack()];
+
+    RetainPtr<NSMutableSet> removedTracks = adoptNS([oldTracks mutableCopy]);
+    [removedTracks minusSet:newTracks.get()];
+
+    RetainPtr<NSMutableSet> addedTracks = adoptNS([newTracks mutableCopy]);
+    [addedTracks minusSet:oldTracks.get()];
+
+    ItemVector replacementItems;
+    ItemVector addedItems;
+    ItemVector removedItems;
+    for (auto i = oldItems.begin(); i != oldItems.end(); ++i) {
+        if ([removedTracks containsObject:(*i)->playerItemTrack()])
+            removedItems.append(*i);
+        else
+            replacementItems.append(*i);
+    }
+
+    for (AVPlayerItemTrack* track in addedTracks.get())
+        addedItems.append(itemFactory(track));
+
+    replacementItems.appendVector(addedItems);
+    oldItems.swap(replacementItems);
+
+    for (auto i = removedItems.begin(); i != removedItems.end(); ++i)
+        (player->*removedFunction)(*i);
+
+    for (auto i = addedItems.begin(); i != addedItems.end(); ++i)
+        (player->*addedFunction)(*i);
+}
+
+void MediaPlayerPrivateAVFoundationObjC::updateAudioTracks()
+{
+    determineChangedTracksFromNewTracksAndOldItems([m_avPlayerItem tracks], AVMediaTypeAudio, m_audioTracks, &AudioTrackPrivateAVFObjC::create, player(), &MediaPlayer::removeAudioTrack, &MediaPlayer::addAudioTrack);
+}
+
+void MediaPlayerPrivateAVFoundationObjC::updateVideoTracks()
+{
+    determineChangedTracksFromNewTracksAndOldItems([m_avPlayerItem tracks], AVMediaTypeVideo, m_videoTracks, &VideoTrackPrivateAVFObjC::create, player(), &MediaPlayer::removeVideoTrack, &MediaPlayer::addVideoTrack);
+}
+#endif // ENABLE(VIDEO_TRACK)
+
 void MediaPlayerPrivateAVFoundationObjC::sizeChanged()
 {
     if (!m_avAsset)
@@ -1567,7 +1587,7 @@ String MediaPlayerPrivateAVFoundationObjC::languageOfPrimaryAudioTrack() const
     }
 
     AVAssetTrack *track = [tracks objectAtIndex:0];
-    m_languageOfPrimaryAudioTrack = AudioTrackPrivateAVFObjC::languageForAVAssetTrack(track);
+    m_languageOfPrimaryAudioTrack = AVTrackPrivateAVFObjCImpl::languageForAVAssetTrack(track);
 
 #if !LOG_DISABLED
     if (m_languageOfPrimaryAudioTrack == emptyString())
diff --git a/Source/WebCore/platform/graphics/avfoundation/objc/VideoTrackPrivateAVFObjC.cpp b/Source/WebCore/platform/graphics/avfoundation/objc/VideoTrackPrivateAVFObjC.cpp
new file mode 100644 (file)
index 0000000..412206c
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "VideoTrackPrivateAVFObjC.h"
+#import "AVTrackPrivateAVFObjCImpl.h"
+
+#if ENABLE(VIDEO_TRACK)
+
+namespace WebCore {
+
+VideoTrackPrivateAVFObjC::VideoTrackPrivateAVFObjC(AVPlayerItemTrack* track)
+: m_impl(AVTrackPrivateAVFObjCImpl::create(track))
+{
+    resetPropertiesFromTrack();
+}
+
+void VideoTrackPrivateAVFObjC::resetPropertiesFromTrack()
+{
+    setSelected(m_impl->enabled());
+    setKind(m_impl->videoKind());
+    setId(m_impl->id());
+    setLabel(m_impl->label());
+    setLanguage(m_impl->language());
+}
+
+void VideoTrackPrivateAVFObjC::setPlayerItemTrack(AVPlayerItemTrack *track)
+{
+    m_impl = AVTrackPrivateAVFObjCImpl::create(track);
+    resetPropertiesFromTrack();
+}
+
+AVPlayerItemTrack* VideoTrackPrivateAVFObjC::playerItemTrack()
+{
+    return m_impl->playerItemTrack();
+}
+
+void VideoTrackPrivateAVFObjC::setSelected(bool enabled)
+{
+    VideoTrackPrivateAVF::setSelected(enabled);
+    m_impl->setEnabled(enabled);
+}
+    
+}
+
+#endif
+
diff --git a/Source/WebCore/platform/graphics/avfoundation/objc/VideoTrackPrivateAVFObjC.h b/Source/WebCore/platform/graphics/avfoundation/objc/VideoTrackPrivateAVFObjC.h
new file mode 100644 (file)
index 0000000..b916e06
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef VideoTrackPrivateAVFObjC_h
+#define VideoTrackPrivateAVFObjC_h
+
+#if ENABLE(VIDEO_TRACK)
+
+#include "VideoTrackPrivateAVF.h"
+#include <wtf/OwnPtr.h>
+
+OBJC_CLASS AVPlayerItemTrack;
+
+namespace WebCore {
+
+class AVTrackPrivateAVFObjCImpl;
+
+class VideoTrackPrivateAVFObjC FINAL : public VideoTrackPrivateAVF {
+    WTF_MAKE_NONCOPYABLE(VideoTrackPrivateAVFObjC)
+public:
+    static RefPtr<VideoTrackPrivateAVFObjC> create(AVPlayerItemTrack* track)
+    {
+        return adoptRef(new VideoTrackPrivateAVFObjC(track));
+    }
+
+    virtual void setSelected(bool) OVERRIDE;
+
+    void setPlayerItemTrack(AVPlayerItemTrack*);
+    AVPlayerItemTrack* playerItemTrack();
+
+private:
+    VideoTrackPrivateAVFObjC(AVPlayerItemTrack*);
+
+    void resetPropertiesFromTrack();
+    OwnPtr<AVTrackPrivateAVFObjCImpl> m_impl;
+};
+
+}
+
+#endif // ENABLE(VIDEO_TRACK)
+
+#endif // VideoTrackPrivateAVFObjC_h