Commit 6d19e068 authored by jer.noble@apple.com's avatar jer.noble@apple.com

[Mac][AVF] Allow video and audio tracks to be initialized with an AVAssetTrack.

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

Reviewed by Eric Carlson.

Currently, VideoTrackPrivateAVFObjC and AudioTrackPrivateAVFObjC are initialized with an
AVPlayerItemTrack, but most of its methods use the AVAssetTrack wrapped by the
AVPlayerItemTrack. Allow these objects to be alternatively initialized with an AVAssetTrack.

Add factory methods taking an AVAssetTrack:
* platform/graphics/avfoundation/objc/AudioTrackPrivateAVFObjC.h:
(WebCore::AudioTrackPrivateAVFObjC::create):
* platform/graphics/avfoundation/objc/AudioTrackPrivateAVFObjC.mm:
(WebCore::AudioTrackPrivateAVFObjC::AudioTrackPrivateAVFObjC):
(WebCore::AudioTrackPrivateAVFObjC::setAssetTrack):
(WebCore::AudioTrackPrivateAVFObjC::assetTrack):
* platform/graphics/avfoundation/objc/VideoTrackPrivateAVFObjC.cpp:
(WebCore::VideoTrackPrivateAVFObjC::VideoTrackPrivateAVFObjC):
(WebCore::VideoTrackPrivateAVFObjC::setAssetTrack):
(WebCore::VideoTrackPrivateAVFObjC::assetTrack):
* platform/graphics/avfoundation/objc/VideoTrackPrivateAVFObjC.h:

Use m_assetTrack instead of [m_playerItemTrack assetTrack]:
* platform/graphics/avfoundation/AVTrackPrivateAVFObjCImpl.h:
(WebCore::AVTrackPrivateAVFObjCImpl::assetTrack):
* platform/graphics/avfoundation/AVTrackPrivateAVFObjCImpl.mm:
(WebCore::AVTrackPrivateAVFObjCImpl::AVTrackPrivateAVFObjCImpl):
(WebCore::AVTrackPrivateAVFObjCImpl::enabled):
(WebCore::AVTrackPrivateAVFObjCImpl::setEnabled):
(WebCore::AVTrackPrivateAVFObjCImpl::audioKind):
(WebCore::AVTrackPrivateAVFObjCImpl::videoKind):
(WebCore::AVTrackPrivateAVFObjCImpl::id):
(WebCore::AVTrackPrivateAVFObjCImpl::label):
(WebCore::AVTrackPrivateAVFObjCImpl::language):
(WebCore::AVTrackPrivateAVFObjCImpl::trackID):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@159368 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 9eaea415
2013-11-15 Jer Noble <jer.noble@apple.com>
[Mac][AVF] Allow video and audio tracks to be initialized with an AVAssetTrack.
https://bugs.webkit.org/show_bug.cgi?id=124421
Reviewed by Eric Carlson.
Currently, VideoTrackPrivateAVFObjC and AudioTrackPrivateAVFObjC are initialized with an
AVPlayerItemTrack, but most of its methods use the AVAssetTrack wrapped by the
AVPlayerItemTrack. Allow these objects to be alternatively initialized with an AVAssetTrack.
Add factory methods taking an AVAssetTrack:
* platform/graphics/avfoundation/objc/AudioTrackPrivateAVFObjC.h:
(WebCore::AudioTrackPrivateAVFObjC::create):
* platform/graphics/avfoundation/objc/AudioTrackPrivateAVFObjC.mm:
(WebCore::AudioTrackPrivateAVFObjC::AudioTrackPrivateAVFObjC):
(WebCore::AudioTrackPrivateAVFObjC::setAssetTrack):
(WebCore::AudioTrackPrivateAVFObjC::assetTrack):
* platform/graphics/avfoundation/objc/VideoTrackPrivateAVFObjC.cpp:
(WebCore::VideoTrackPrivateAVFObjC::VideoTrackPrivateAVFObjC):
(WebCore::VideoTrackPrivateAVFObjC::setAssetTrack):
(WebCore::VideoTrackPrivateAVFObjC::assetTrack):
* platform/graphics/avfoundation/objc/VideoTrackPrivateAVFObjC.h:
Use m_assetTrack instead of [m_playerItemTrack assetTrack]:
* platform/graphics/avfoundation/AVTrackPrivateAVFObjCImpl.h:
(WebCore::AVTrackPrivateAVFObjCImpl::assetTrack):
* platform/graphics/avfoundation/AVTrackPrivateAVFObjCImpl.mm:
(WebCore::AVTrackPrivateAVFObjCImpl::AVTrackPrivateAVFObjCImpl):
(WebCore::AVTrackPrivateAVFObjCImpl::enabled):
(WebCore::AVTrackPrivateAVFObjCImpl::setEnabled):
(WebCore::AVTrackPrivateAVFObjCImpl::audioKind):
(WebCore::AVTrackPrivateAVFObjCImpl::videoKind):
(WebCore::AVTrackPrivateAVFObjCImpl::id):
(WebCore::AVTrackPrivateAVFObjCImpl::label):
(WebCore::AVTrackPrivateAVFObjCImpl::language):
(WebCore::AVTrackPrivateAVFObjCImpl::trackID):
2013-11-15 Brady Eidson <beidson@apple.com>
Let IDBDatabaseBackend create IDBTransactionBackend's directly
......
......@@ -41,8 +41,10 @@ namespace WebCore {
class AVTrackPrivateAVFObjCImpl {
public:
explicit AVTrackPrivateAVFObjCImpl(AVPlayerItemTrack*);
explicit AVTrackPrivateAVFObjCImpl(AVAssetTrack*);
AVPlayerItemTrack* playerItemTrack() const { return m_playerItemTrack.get(); }
AVAssetTrack* assetTrack() const { return m_assetTrack.get(); }
bool enabled() const;
void setEnabled(bool);
......@@ -54,10 +56,13 @@ public:
AtomicString label() const;
AtomicString language() const;
int trackID() const;
static String languageForAVAssetTrack(AVAssetTrack*);
private:
RetainPtr<AVPlayerItemTrack> m_playerItemTrack;
RetainPtr<AVAssetTrack> m_assetTrack;
};
}
......
......@@ -60,51 +60,57 @@ namespace WebCore {
AVTrackPrivateAVFObjCImpl::AVTrackPrivateAVFObjCImpl(AVPlayerItemTrack* track)
: m_playerItemTrack(track)
, m_assetTrack([track assetTrack])
{
}
AVTrackPrivateAVFObjCImpl::AVTrackPrivateAVFObjCImpl(AVAssetTrack* track)
: m_assetTrack(track)
{
}
bool AVTrackPrivateAVFObjCImpl::enabled() const
{
return [m_playerItemTrack.get() isEnabled];
ASSERT(m_playerItemTrack);
return [m_playerItemTrack isEnabled];
}
void AVTrackPrivateAVFObjCImpl::setEnabled(bool enabled)
{
[m_playerItemTrack.get() setEnabled:enabled];
ASSERT(m_playerItemTrack);
[m_playerItemTrack setEnabled:enabled];
}
AudioTrackPrivate::Kind AVTrackPrivateAVFObjCImpl::audioKind() const
{
AVAssetTrack* assetTrack = [m_playerItemTrack.get() assetTrack];
if ([assetTrack hasMediaCharacteristic:AVMediaCharacteristicIsAuxiliaryContent])
if ([m_assetTrack hasMediaCharacteristic:AVMediaCharacteristicIsAuxiliaryContent])
return AudioTrackPrivate::Alternative;
else if ([assetTrack hasMediaCharacteristic:AVMediaCharacteristicIsMainProgramContent])
else if ([m_assetTrack hasMediaCharacteristic:AVMediaCharacteristicIsMainProgramContent])
return AudioTrackPrivate::Main;
return AudioTrackPrivate::None;
}
VideoTrackPrivate::Kind AVTrackPrivateAVFObjCImpl::videoKind() const
{
AVAssetTrack* assetTrack = [m_playerItemTrack.get() assetTrack];
if ([assetTrack hasMediaCharacteristic:AVMediaCharacteristicDescribesVideoForAccessibility])
if ([m_assetTrack hasMediaCharacteristic:AVMediaCharacteristicDescribesVideoForAccessibility])
return VideoTrackPrivate::Sign;
else if ([assetTrack hasMediaCharacteristic:AVMediaCharacteristicTranscribesSpokenDialogForAccessibility])
else if ([m_assetTrack hasMediaCharacteristic:AVMediaCharacteristicTranscribesSpokenDialogForAccessibility])
return VideoTrackPrivate::Captions;
else if ([assetTrack hasMediaCharacteristic:AVMediaCharacteristicIsAuxiliaryContent])
else if ([m_assetTrack hasMediaCharacteristic:AVMediaCharacteristicIsAuxiliaryContent])
return VideoTrackPrivate::Alternative;
else if ([assetTrack hasMediaCharacteristic:AVMediaCharacteristicIsMainProgramContent])
else if ([m_assetTrack hasMediaCharacteristic:AVMediaCharacteristicIsMainProgramContent])
return VideoTrackPrivate::Main;
return VideoTrackPrivate::None;
}
AtomicString AVTrackPrivateAVFObjCImpl::id() const
{
return String::format("%d", [[m_playerItemTrack.get() assetTrack] trackID]);
return String::format("%d", [m_assetTrack trackID]);
}
AtomicString AVTrackPrivateAVFObjCImpl::label() const
{
NSArray *titles = [AVMetadataItem metadataItemsFromArray:[[m_playerItemTrack.get() assetTrack] commonMetadata] withKey:AVMetadataCommonKeyTitle keySpace:AVMetadataKeySpaceCommon];
NSArray *titles = [AVMetadataItem metadataItemsFromArray:[m_assetTrack commonMetadata] withKey:AVMetadataCommonKeyTitle keySpace:AVMetadataKeySpaceCommon];
if (![titles count])
return emptyAtom;
......@@ -121,7 +127,7 @@ AtomicString AVTrackPrivateAVFObjCImpl::label() const
AtomicString AVTrackPrivateAVFObjCImpl::language() const
{
return languageForAVAssetTrack([m_playerItemTrack.get() assetTrack]);
return languageForAVAssetTrack(m_assetTrack.get());
}
String AVTrackPrivateAVFObjCImpl::languageForAVAssetTrack(AVAssetTrack* track)
......@@ -141,6 +147,11 @@ String AVTrackPrivateAVFObjCImpl::languageForAVAssetTrack(AVAssetTrack* track)
return language;
}
int AVTrackPrivateAVFObjCImpl::trackID() const
{
return [m_assetTrack trackID];
}
}
#endif // ENABLE(VIDEO_TRACK)
......@@ -32,6 +32,7 @@
#include <wtf/OwnPtr.h>
OBJC_CLASS AVPlayerItemTrack;
OBJC_CLASS AVAssetTrack;
namespace WebCore {
......@@ -45,13 +46,22 @@ public:
return adoptRef(new AudioTrackPrivateAVFObjC(track));
}
static RefPtr<AudioTrackPrivateAVFObjC> create(AVAssetTrack* track)
{
return adoptRef(new AudioTrackPrivateAVFObjC(track));
}
virtual void setEnabled(bool);
void setPlayerItemTrack(AVPlayerItemTrack*);
AVPlayerItemTrack* playerItemTrack();
void setAssetTrack(AVAssetTrack*);
AVAssetTrack* assetTrack();
private:
AudioTrackPrivateAVFObjC(AVPlayerItemTrack*);
AudioTrackPrivateAVFObjC(AVAssetTrack*);
void resetPropertiesFromTrack();
std::unique_ptr<AVTrackPrivateAVFObjCImpl> m_impl;
......
......@@ -57,6 +57,23 @@ AVPlayerItemTrack* AudioTrackPrivateAVFObjC::playerItemTrack()
return m_impl->playerItemTrack();
}
AudioTrackPrivateAVFObjC::AudioTrackPrivateAVFObjC(AVAssetTrack* track)
: m_impl(std::make_unique<AVTrackPrivateAVFObjCImpl>(track))
{
resetPropertiesFromTrack();
}
void AudioTrackPrivateAVFObjC::setAssetTrack(AVAssetTrack *track)
{
m_impl = std::make_unique<AVTrackPrivateAVFObjCImpl>(track);
resetPropertiesFromTrack();
}
AVAssetTrack* AudioTrackPrivateAVFObjC::assetTrack()
{
return m_impl->assetTrack();
}
void AudioTrackPrivateAVFObjC::setEnabled(bool enabled)
{
AudioTrackPrivateAVF::setEnabled(enabled);
......
......@@ -37,6 +37,12 @@ VideoTrackPrivateAVFObjC::VideoTrackPrivateAVFObjC(AVPlayerItemTrack* track)
resetPropertiesFromTrack();
}
VideoTrackPrivateAVFObjC::VideoTrackPrivateAVFObjC(AVAssetTrack* track)
: m_impl(std::make_unique<AVTrackPrivateAVFObjCImpl>(track))
{
resetPropertiesFromTrack();
}
void VideoTrackPrivateAVFObjC::resetPropertiesFromTrack()
{
setSelected(m_impl->enabled());
......@@ -57,6 +63,17 @@ AVPlayerItemTrack* VideoTrackPrivateAVFObjC::playerItemTrack()
return m_impl->playerItemTrack();
}
void VideoTrackPrivateAVFObjC::setAssetTrack(AVAssetTrack *track)
{
m_impl = std::make_unique<AVTrackPrivateAVFObjCImpl>(track);
resetPropertiesFromTrack();
}
AVAssetTrack* VideoTrackPrivateAVFObjC::assetTrack()
{
return m_impl->assetTrack();
}
void VideoTrackPrivateAVFObjC::setSelected(bool enabled)
{
VideoTrackPrivateAVF::setSelected(enabled);
......
......@@ -29,8 +29,8 @@
#if ENABLE(VIDEO_TRACK)
#include "VideoTrackPrivateAVF.h"
#include <wtf/OwnPtr.h>
OBJC_CLASS AVAssetTrack;
OBJC_CLASS AVPlayerItemTrack;
namespace WebCore {
......@@ -45,13 +45,22 @@ public:
return adoptRef(new VideoTrackPrivateAVFObjC(track));
}
static RefPtr<VideoTrackPrivateAVFObjC> create(AVAssetTrack* track)
{
return adoptRef(new VideoTrackPrivateAVFObjC(track));
}
virtual void setSelected(bool) OVERRIDE;
void setPlayerItemTrack(AVPlayerItemTrack*);
AVPlayerItemTrack* playerItemTrack();
void setAssetTrack(AVAssetTrack*);
AVAssetTrack* assetTrack();
private:
explicit VideoTrackPrivateAVFObjC(AVPlayerItemTrack*);
explicit VideoTrackPrivateAVFObjC(AVAssetTrack*);
void resetPropertiesFromTrack();
std::unique_ptr<AVTrackPrivateAVFObjCImpl> m_impl;
......
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