Commit 876b8519 authored by jer.noble@apple.com's avatar jer.noble@apple.com

[Mac] Add AudioTrack support to MediaPlayerPrivateAVFObC.

https://bugs.webkit.org/show_bug.cgi?id=122043

Reviewed by Eric Carlson.

Source/WebCore:

Test: media/track/audio-track.html

Add a new class AudioTrackPrivateAVF and subclass AudioTrackPrivateAVFObjC
which are backed by a AVPlayerItemTrack. Create one of these tracks when
we are notified that the list of available tracks has changed.

* WebCore.xcodeproj/project.pbxproj:
* html/track/AudioTrack.cpp:
(WebCore::AudioTrack::setEnabled): Pass through to the AudioTrackPrivate
    so that the underlying media track can be (dis|en)abled.
* platform/graphics/avfoundation/AudioTrackPrivateAVF.h: Added.
(WebCore::AudioTrackPrivateAVF::kind): Simple getter.
(WebCore::AudioTrackPrivateAVF::id): Ditto.
(WebCore::AudioTrackPrivateAVF::label): Ditto.
(WebCore::AudioTrackPrivateAVF::language): Ditto.
(WebCore::AudioTrackPrivateAVF::setKind): Simple Setter.
(WebCore::AudioTrackPrivateAVF::setId): Ditto.
(WebCore::AudioTrackPrivateAVF::setLabel): Ditto.
(WebCore::AudioTrackPrivateAVF::setLanguage): Ditto.
(WebCore::AudioTrackPrivateAVF::AudioTrackPrivateAVF): Simple constructor.
* platform/graphics/avfoundation/objc/AudioTrackPrivateAVFObjC.h: Added.
(WebCore::AudioTrackPrivateAVFObjC::create): Simple factory.
(WebCore::AudioTrackPrivateAVFObjC::playerItemTrack): Simple getter.
* platform/graphics/avfoundation/objc/AudioTrackPrivateAVFObjC.mm: Added.
(WebCore::AudioTrackPrivateAVFObjC::AudioTrackPrivateAVFObjC): Call resetPropertiesFromTrack.
(WebCore::AudioTrackPrivateAVFObjC::resetPropertiesFromTrack): Fill out the values from
    the associated AVPlayerItemTrack and its AVAssetTrack.
(WebCore::AudioTrackPrivateAVFObjC::setPlayerItemTrack): Call resetPropertiesFromTrack.
(WebCore::AudioTrackPrivateAVFObjC::setEnabled): (En|Dis)able the AVPlayerItemTrack.
(WebCore::AudioTrackPrivateAVFObjC::languageForAVAssetTrack): Refactored from
    MediaPlayerPrivateAVFoundationObjC::languageOfPrimaryAudioTrack.
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::MediaPlayerPrivateAVFoundationObjC::tracksChanged): Determine which tracks
    have been added or removed and notify the clients accordingly.
(WebCore::MediaPlayerPrivateAVFoundationObjC::languageOfPrimaryAudioTrack): Refactor into
    AudioTrackPrivateAVFObjC::languageForAVAssetTrack.

LayoutTests:

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

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@156652 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent b17ffdd5
2013-09-27 Jer Noble <jer.noble@apple.com>
[Mac] Add AudioTrack support to MediaPlayerPrivateAVFObC.
https://bugs.webkit.org/show_bug.cgi?id=122043
Reviewed by Eric Carlson.
* media/track/audio-track-expected.txt: Added.
* media/track/audio-track.html: Added.
2013-09-30 Robert Plociennik <r.plociennik@samsung.com>
[EFL] Added passing expectation for fast/forms/textarea-metrics.html
In-band audio tracks.
EVENT(addtrack)
EXPECTED (event.track == 'video.audioTracks[0]') OK
EVENT(canplaythrough)
** Check initial in-band track states
EXPECTED (video.audioTracks.length == '1') OK
** Unload video file, check track count
RUN(video.src = '')
EXPECTED (video.audioTracks.length == '0') OK
END OF TEST
<!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.audioTracks[" + 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.audioTracks.length", 1);
consoleWrite("<br><i>** Unload video file, check track count<" + "/i>");
run("video.src = ''");
testExpected("video.audioTracks.length", 0);
consoleWrite("");
endTest();
}
function setup()
{
findMediaElement();
video.audioTracks.addEventListener("addtrack", trackAdded);
video.src = findMediaFile('audio', '../content/silence');
waitForEvent('canplaythrough', canplaythrough);
}
</script>
</head>
<body onload="setup()">
<video controls></video>
<p>In-band audio tracks.</p>
</body>
</html>
2013-09-27 Jer Noble <jer.noble@apple.com>
[Mac] Add AudioTrack support to MediaPlayerPrivateAVFObC.
https://bugs.webkit.org/show_bug.cgi?id=122043
Reviewed by Eric Carlson.
Test: media/track/audio-track.html
Add a new class AudioTrackPrivateAVF and subclass AudioTrackPrivateAVFObjC
which are backed by a AVPlayerItemTrack. Create one of these tracks when
we are notified that the list of available tracks has changed.
* WebCore.xcodeproj/project.pbxproj:
* html/track/AudioTrack.cpp:
(WebCore::AudioTrack::setEnabled): Pass through to the AudioTrackPrivate
so that the underlying media track can be (dis|en)abled.
* platform/graphics/avfoundation/AudioTrackPrivateAVF.h: Added.
(WebCore::AudioTrackPrivateAVF::kind): Simple getter.
(WebCore::AudioTrackPrivateAVF::id): Ditto.
(WebCore::AudioTrackPrivateAVF::label): Ditto.
(WebCore::AudioTrackPrivateAVF::language): Ditto.
(WebCore::AudioTrackPrivateAVF::setKind): Simple Setter.
(WebCore::AudioTrackPrivateAVF::setId): Ditto.
(WebCore::AudioTrackPrivateAVF::setLabel): Ditto.
(WebCore::AudioTrackPrivateAVF::setLanguage): Ditto.
(WebCore::AudioTrackPrivateAVF::AudioTrackPrivateAVF): Simple constructor.
* platform/graphics/avfoundation/objc/AudioTrackPrivateAVFObjC.h: Added.
(WebCore::AudioTrackPrivateAVFObjC::create): Simple factory.
(WebCore::AudioTrackPrivateAVFObjC::playerItemTrack): Simple getter.
* platform/graphics/avfoundation/objc/AudioTrackPrivateAVFObjC.mm: Added.
(WebCore::AudioTrackPrivateAVFObjC::AudioTrackPrivateAVFObjC): Call resetPropertiesFromTrack.
(WebCore::AudioTrackPrivateAVFObjC::resetPropertiesFromTrack): Fill out the values from
the associated AVPlayerItemTrack and its AVAssetTrack.
(WebCore::AudioTrackPrivateAVFObjC::setPlayerItemTrack): Call resetPropertiesFromTrack.
(WebCore::AudioTrackPrivateAVFObjC::setEnabled): (En|Dis)able the AVPlayerItemTrack.
(WebCore::AudioTrackPrivateAVFObjC::languageForAVAssetTrack): Refactored from
MediaPlayerPrivateAVFoundationObjC::languageOfPrimaryAudioTrack.
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::MediaPlayerPrivateAVFoundationObjC::tracksChanged): Determine which tracks
have been added or removed and notify the clients accordingly.
(WebCore::MediaPlayerPrivateAVFoundationObjC::languageOfPrimaryAudioTrack): Refactor into
AudioTrackPrivateAVFObjC::languageForAVAssetTrack.
2013-09-30 Gyuyoung Kim <gyuyoung.kim@samsung.com>
Generate toCSSCalcValue instead of using manual cast function
......@@ -5383,6 +5383,9 @@
CDC69DDA16371FD4007C38DF /* WebCoreFullScreenPlaceholderView.h in Headers */ = {isa = PBXBuildFile; fileRef = CDC69DD816371FD3007C38DF /* WebCoreFullScreenPlaceholderView.h */; settings = {ATTRIBUTES = (Private, ); }; };
CDC69DDB16371FD4007C38DF /* WebCoreFullScreenPlaceholderView.mm in Sources */ = {isa = PBXBuildFile; fileRef = CDC69DD916371FD3007C38DF /* WebCoreFullScreenPlaceholderView.mm */; };
CDD525D7145B6DD0008D204D /* JSHTMLMediaElementCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDF65CCC145B6AFE00C4C7AA /* JSHTMLMediaElementCustom.cpp */; };
CDE3A85417F5FCE600C5BE20 /* AudioTrackPrivateAVF.h in Headers */ = {isa = PBXBuildFile; fileRef = CDE3A85217F5FCE600C5BE20 /* AudioTrackPrivateAVF.h */; };
CDE3A85717F6020400C5BE20 /* AudioTrackPrivateAVFObjC.mm in Sources */ = {isa = PBXBuildFile; fileRef = CDE3A85517F6020400C5BE20 /* AudioTrackPrivateAVFObjC.mm */; };
CDE3A85817F6020400C5BE20 /* AudioTrackPrivateAVFObjC.h in Headers */ = {isa = PBXBuildFile; fileRef = CDE3A85617F6020400C5BE20 /* AudioTrackPrivateAVFObjC.h */; };
CDEA763014608A53008B31F1 /* PlatformClockCA.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDEA762E146084DE008B31F1 /* PlatformClockCA.cpp */; };
CDEA76341460B56F008B31F1 /* ClockGeneric.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDEA76321460AE29008B31F1 /* ClockGeneric.cpp */; };
CDEA76351460B71A008B31F1 /* Clock.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDEA76331460B462008B31F1 /* Clock.cpp */; };
......@@ -12341,6 +12344,9 @@
CDC69DD916371FD3007C38DF /* WebCoreFullScreenPlaceholderView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebCoreFullScreenPlaceholderView.mm; sourceTree = "<group>"; };
CDCE5CD014633BC900D47CCA /* EventTargetFactory.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = EventTargetFactory.in; sourceTree = "<group>"; };
CDD1E525167BA56400CE820B /* TextTrackRepresentation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextTrackRepresentation.h; sourceTree = "<group>"; };
CDE3A85217F5FCE600C5BE20 /* AudioTrackPrivateAVF.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AudioTrackPrivateAVF.h; sourceTree = "<group>"; };
CDE3A85517F6020400C5BE20 /* AudioTrackPrivateAVFObjC.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = AudioTrackPrivateAVFObjC.mm; path = objc/AudioTrackPrivateAVFObjC.mm; sourceTree = "<group>"; };
CDE3A85617F6020400C5BE20 /* AudioTrackPrivateAVFObjC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AudioTrackPrivateAVFObjC.h; path = objc/AudioTrackPrivateAVFObjC.h; sourceTree = "<group>"; };
CDE6560E17CA6E7600526BA7 /* mediaControlsApple.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; path = mediaControlsApple.js; sourceTree = "<group>"; };
CDEA762C14608224008B31F1 /* Clock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Clock.h; sourceTree = "<group>"; };
CDEA762E146084DE008B31F1 /* PlatformClockCA.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PlatformClockCA.cpp; sourceTree = "<group>"; };
......@@ -13481,6 +13487,7 @@
isa = PBXGroup;
children = (
DF9AFD6F13FC31B00015FEB7 /* objc */,
CDE3A85217F5FCE600C5BE20 /* AudioTrackPrivateAVF.h */,
07B442D4166C70B000556CAD /* InbandTextTrackPrivateAVF.cpp */,
07B442D5166C70B000556CAD /* InbandTextTrackPrivateAVF.h */,
076F0D0912B8192700C26AA4 /* MediaPlayerPrivateAVFoundation.cpp */,
......@@ -20087,6 +20094,8 @@
DF9AFD6F13FC31B00015FEB7 /* objc */ = {
isa = PBXGroup;
children = (
CDE3A85517F6020400C5BE20 /* AudioTrackPrivateAVFObjC.mm */,
CDE3A85617F6020400C5BE20 /* AudioTrackPrivateAVFObjC.h */,
07AA6B69166D019500D45671 /* InbandTextTrackPrivateAVFObjC.h */,
07AA6B6A166D019500D45671 /* InbandTextTrackPrivateAVFObjC.mm */,
07367DDD172CA67F00D861B9 /* InbandTextTrackPrivateLegacyAVFObjC.h */,
......@@ -21580,6 +21589,7 @@
CE08C3D2152B599A0021B8C2 /* AlternativeTextController.h in Headers */,
CE7B2DB31586ABAD0098B3FA /* AlternativeTextUIController.h in Headers */,
FD31603E12B0267600C1A359 /* AnalyserNode.h in Headers */,
CDE3A85817F6020400C5BE20 /* AudioTrackPrivateAVFObjC.h in Headers */,
490707E71219C04300D90E51 /* ANGLEWebKitBridge.h in Headers */,
49E912AB0EFAC906009D0CAF /* Animation.h in Headers */,
316FE1120E6E1DA700BF6088 /* AnimationBase.h in Headers */,
......@@ -24243,6 +24253,7 @@
656581FE09D1508D000E61D7 /* SVGElementFactory.h in Headers */,
B22279BA0D00BF220071B782 /* SVGElementInstance.h in Headers */,
B22279BD0D00BF220071B782 /* SVGElementInstanceList.h in Headers */,
CDE3A85417F5FCE600C5BE20 /* AudioTrackPrivateAVF.h in Headers */,
081AA8DA1111237E002AB06E /* SVGElementRareData.h in Headers */,
B22279C00D00BF220071B782 /* SVGEllipseElement.h in Headers */,
B22279C20D00BF220071B782 /* SVGException.h in Headers */,
......@@ -27398,6 +27409,7 @@
B22279A70D00BF220071B782 /* SVGCursorElement.cpp in Sources */,
B22279AD0D00BF220071B782 /* SVGDefsElement.cpp in Sources */,
B22279B00D00BF220071B782 /* SVGDescElement.cpp in Sources */,
CDE3A85717F6020400C5BE20 /* AudioTrackPrivateAVFObjC.mm in Sources */,
B22279B30D00BF220071B782 /* SVGDocument.cpp in Sources */,
B28C6A270D00C44800334AA4 /* SVGDocumentExtensions.cpp in Sources */,
B22279B60D00BF220071B782 /* SVGElement.cpp in Sources */,
......@@ -146,6 +146,8 @@ void AudioTrack::setEnabled(const bool enabled)
m_enabled = enabled;
m_private->setEnabled(enabled);
if (m_client)
m_client->audioTrackEnabledChanged(this);
}
......
/*
* 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 AudioTrackPrivateAVF_h
#define AudioTrackPrivateAVF_h
#if ENABLE(VIDEO_TRACK)
#include "AudioTrackPrivate.h"
namespace WebCore {
class AudioTrackPrivateAVF : public AudioTrackPrivate {
WTF_MAKE_NONCOPYABLE(AudioTrackPrivateAVF)
public:
virtual Kind kind() const { return m_kind; }
virtual AtomicString id() const { return m_id; }
virtual AtomicString label() const { return m_label; }
virtual AtomicString language() const { 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;
AudioTrackPrivateAVF()
: m_kind(None)
{
}
};
}
#endif // ENABLE(VIDEO_TRACK)
#endif // AudioTrackPrivateAVF_h
/*
* 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 AudioTrackPrivateAVFObjC_h
#define AudioTrackPrivateAVFObjC_h
#if ENABLE(VIDEO_TRACK)
#include "AudioTrackPrivateAVF.h"
#include <wtf/RetainPtr.h>
OBJC_CLASS AVAssetTrack;
OBJC_CLASS AVPlayerItemTrack;
namespace WebCore {
class AudioTrackPrivateAVFObjC : public AudioTrackPrivateAVF {
WTF_MAKE_NONCOPYABLE(AudioTrackPrivateAVFObjC)
public:
static RefPtr<AudioTrackPrivateAVFObjC> create(AVPlayerItemTrack* track)
{
return adoptRef(new AudioTrackPrivateAVFObjC(track));
}
virtual void setEnabled(bool);
void setPlayerItemTrack(AVPlayerItemTrack*);
AVPlayerItemTrack* playerItemTrack() { return m_playerItemTrack.get(); }
static String languageForAVAssetTrack(AVAssetTrack*);
private:
AudioTrackPrivateAVFObjC(AVPlayerItemTrack*);
void resetPropertiesFromTrack();
RetainPtr<AVPlayerItemTrack> m_playerItemTrack;
};
}
#endif // ENABLE(VIDEO_TRACK)
#endif // AudioTrackPrivateAVFObjC_h
/*
* 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 "AudioTrackPrivateAVFObjC.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, AVMediaCharacteristicIsMainProgramContent, NSString *)
SOFT_LINK_POINTER(AVFoundation, AVMediaCharacteristicDescribesVideoForAccessibility, NSString *)
SOFT_LINK_POINTER(AVFoundation, AVMediaCharacteristicIsAuxiliaryContent, NSString *)
SOFT_LINK_POINTER(AVFoundation, AVMediaCharacteristicTranscribesSpokenDialogForAccessibility, NSString *)
SOFT_LINK_POINTER(AVFoundation, AVMetadataCommonKeyTitle, NSString *)
SOFT_LINK_POINTER(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 {
AudioTrackPrivateAVFObjC::AudioTrackPrivateAVFObjC(AVPlayerItemTrack* track)
: m_playerItemTrack(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.
NSArray *titlesForPreferredLanguages = [AVMetadataItem metadataItemsFromArray:titles filteredAndSortedAccordingToPreferredLanguages:[NSLocale preferredLanguages]];
if ([titlesForPreferredLanguages count])
setLabel([[titlesForPreferredLanguages objectAtIndex:0] stringValue]);
else
setLabel([[titles objectAtIndex:0] stringValue]);
}
setLanguage(languageForAVAssetTrack(assetTrack));
}
void AudioTrackPrivateAVFObjC::setPlayerItemTrack(AVPlayerItemTrack *track)
{
m_playerItemTrack = track;
resetPropertiesFromTrack();
}
void AudioTrackPrivateAVFObjC::setEnabled(bool enabled)
{
AudioTrackPrivateAVF::setEnabled(enabled);
[m_playerItemTrack.get() setEnabled:enabled];
}
String AudioTrackPrivateAVFObjC::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
......@@ -59,6 +59,7 @@ namespace WebCore {
class WebCoreAVFResourceLoader;
class InbandTextTrackPrivateAVFObjC;
class AudioTrackPrivateAVFObjC;
class MediaPlayerPrivateAVFoundationObjC : public MediaPlayerPrivateAVFoundation {
public:
......@@ -214,7 +215,11 @@ private:
#if HAVE(AVFOUNDATION_MEDIA_SELECTION_GROUP) && HAVE(AVFOUNDATION_LEGIBLE_OUTPUT_SUPPORT)
RetainPtr<AVPlayerItemLegibleOutput> m_legibleOutput;
#endif
#if ENABLE(VIDEO_TRACK)
Vector<RefPtr<AudioTrackPrivateAVFObjC>> m_audioTracks;
#endif
InbandTextTrackPrivateAVF* m_currentTrack;
};
......
......@@ -29,6 +29,7 @@
#import "MediaPlayerPrivateAVFoundationObjC.h"
#import "AudioTrackPrivateAVFObjC.h"
#import "BlockExceptions.h"
#import "ExceptionCodePlaceholder.h"
#import "FloatConversion.h"
......@@ -1048,6 +1049,47 @@ void MediaPlayerPrivateAVFoundationObjC::tracksChanged()
}
setHasVideo(hasVideo);
setHasAudio(hasAudio);
#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);
#endif
}
#if HAVE(AVFOUNDATION_MEDIA_SELECTION_GROUP)
......@@ -1525,23 +1567,15 @@ String MediaPlayerPrivateAVFoundationObjC::languageOfPrimaryAudioTrack() const
}
AVAssetTrack *track = [tracks objectAtIndex:0];
NSString *language = [track extendedLanguageTag];
m_languageOfPrimaryAudioTrack = AudioTrackPrivateAVFObjC::languageForAVAssetTrack(track);
// 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"]) {
m_languageOfPrimaryAudioTrack = language;
#if !LOG_DISABLED
if (m_languageOfPrimaryAudioTrack == emptyString())
LOG(Media, "MediaPlayerPrivateAVFoundationObjC::languageOfPrimaryAudioTrack(%p) - single audio track has no language, returning emptyString()", this);
else
LOG(Media, "MediaPlayerPrivateAVFoundationObjC::languageOfPrimaryAudioTrack(%p) - returning language of single audio track: %s", this, m_languageOfPrimaryAudioTrack.utf8().data());
return m_languageOfPrimaryAudioTrack;
}
#endif
LOG(Media, "MediaPlayerPrivateAVFoundationObjC::languageOfPrimaryAudioTrack(%p) - single audio track has no language, returning emptyString()", this);
m_languageOfPrimaryAudioTrack = emptyString();
return m_languageOfPrimaryAudioTrack;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment