Modified: trunk/Source/WebCore/ChangeLog (170240 => 170241)
--- trunk/Source/WebCore/ChangeLog 2014-06-21 14:55:48 UTC (rev 170240)
+++ trunk/Source/WebCore/ChangeLog 2014-06-21 14:59:07 UTC (rev 170241)
@@ -1,3 +1,25 @@
+2014-06-21 Jer Noble <jer.no...@apple.com>
+
+ [Mac] Create and attach the AVPlayerLayer to the AVPlayer immediately if the media element is <video>.
+ https://bugs.webkit.org/show_bug.cgi?id=134131
+
+ Reviewed by Eric Carlson.
+
+ The AVPlayer uses the presence of an AVPlayerLayer to decide which alternate to display in the case of
+ HLS streams with audio-only alternates. To give the AVPlayer the most information with which to make its
+ decision, always create and attach an AVPlayerLayer before attaching an AVPlayerItem to the AVPlayerLayer.
+ In addition, retrieve the <video> element bounds and create an AVPlayerLayer with a matching size, so that
+ the AVPlayer can choose an alternate with the correct dimensions.
+
+ * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
+ * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
+ (WebCore::MediaPlayerPrivateAVFoundationObjC::MediaPlayerPrivateAVFoundationObjC):
+ (WebCore::MediaPlayerPrivateAVFoundationObjC::hasLayerRenderer):
+ (WebCore::MediaPlayerPrivateAVFoundationObjC::createVideoLayer):
+ (WebCore::MediaPlayerPrivateAVFoundationObjC::createAVPlayerLayer):
+ (WebCore::MediaPlayerPrivateAVFoundationObjC::createAVPlayer):
+ (WebCore::MediaPlayerPrivateAVFoundationObjC::platformLayer):
+
2014-06-21 Jeremy Jones <jere...@apple.com>
Implement ios -[WAKWindow convertBaseToScreen:]
Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h (170240 => 170241)
--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h 2014-06-21 14:55:48 UTC (rev 170240)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h 2014-06-21 14:59:07 UTC (rev 170241)
@@ -170,6 +170,7 @@
virtual void createAVPlayer();
virtual void createAVPlayerItem();
+ virtual void createAVPlayerLayer();
virtual void createAVAssetForURL(const String& url);
virtual MediaPlayerPrivateAVFoundation::ItemStatus playerItemStatus() const;
virtual MediaPlayerPrivateAVFoundation::AssetStatus assetStatus() const;
@@ -335,6 +336,7 @@
bool m_cachedHasEnabledAudio;
bool m_shouldBufferData;
bool m_cachedIsReadyForDisplay;
+ bool m_haveBeenAskedToCreateLayer;
#if ENABLE(IOS_AIRPLAY)
mutable bool m_allowsWirelessVideoPlayback;
#endif
Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm (170240 => 170241)
--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm 2014-06-21 14:55:48 UTC (rev 170240)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm 2014-06-21 14:59:07 UTC (rev 170241)
@@ -388,6 +388,7 @@
, m_cachedHasEnabledAudio(false)
, m_shouldBufferData(true)
, m_cachedIsReadyForDisplay(false)
+ , m_haveBeenAskedToCreateLayer(false)
#if ENABLE(IOS_AIRPLAY)
, m_allowsWirelessVideoPlayback(true)
#endif
@@ -478,7 +479,7 @@
bool MediaPlayerPrivateAVFoundationObjC::hasLayerRenderer() const
{
- return m_videoLayer;
+ return m_haveBeenAskedToCreateLayer;
}
bool MediaPlayerPrivateAVFoundationObjC::hasContextRenderer() const
@@ -536,7 +537,7 @@
void MediaPlayerPrivateAVFoundationObjC::createVideoLayer()
{
- if (!m_avPlayer || m_videoLayer)
+ if (!m_avPlayer || m_haveBeenAskedToCreateLayer)
return;
auto weakThis = createWeakPtr();
@@ -544,27 +545,40 @@
if (!weakThis)
return;
- if (!m_avPlayer || m_videoLayer)
+ if (!m_avPlayer || m_haveBeenAskedToCreateLayer)
return;
+ m_haveBeenAskedToCreateLayer = true;
- m_videoLayer = adoptNS([[AVPlayerLayer alloc] init]);
- [m_videoLayer.get() setPlayer:m_avPlayer.get()];
- [m_videoLayer.get() setBackgroundColor:cachedCGColor(Color::black, ColorSpaceDeviceRGB)];
+ if (!m_videoLayer)
+ createAVPlayerLayer();
+
+ player()->mediaPlayerClient()->mediaPlayerRenderingModeChanged(player());
+ });
+}
+
+void MediaPlayerPrivateAVFoundationObjC::createAVPlayerLayer()
+{
+ if (!m_avPlayer)
+ return;
+
+ m_videoLayer = adoptNS([[AVPlayerLayer alloc] init]);
+ [m_videoLayer setPlayer:m_avPlayer.get()];
+ [m_videoLayer setBackgroundColor:cachedCGColor(Color::black, ColorSpaceDeviceRGB)];
#ifndef NDEBUG
- [m_videoLayer.get() setName:@"MediaPlayerPrivate AVPlayerLayer"];
+ [m_videoLayer setName:@"MediaPlayerPrivate AVPlayerLayer"];
#endif
- [m_videoLayer.get() addObserver:m_objcObserver.get() forKeyPath:@"readyForDisplay" options:NSKeyValueObservingOptionNew context:(void *)MediaPlayerAVFoundationObservationContextAVPlayerLayer];
- updateVideoLayerGravity();
- LOG(Media, "MediaPlayerPrivateAVFoundationObjC::createVideoLayer(%p) - returning %p", this, m_videoLayer.get());
+ [m_videoLayer addObserver:m_objcObserver.get() forKeyPath:@"readyForDisplay" options:NSKeyValueObservingOptionNew context:(void *)MediaPlayerAVFoundationObservationContextAVPlayerLayer];
+ updateVideoLayerGravity();
+ IntSize defaultSize = player()->mediaPlayerClient() ? player()->mediaPlayerClient()->mediaPlayerContentBoxRect().pixelSnappedSize() : IntSize();
+ [m_videoLayer setFrame:CGRectMake(0, 0, defaultSize.width(), defaultSize.height())];
+ LOG(Media, "MediaPlayerPrivateAVFoundationObjC::createVideoLayer(%p) - returning %p", this, m_videoLayer.get());
#if PLATFORM(IOS)
- if (m_videoFullscreenLayer) {
- [m_videoLayer setFrame:CGRectMake(0, 0, m_videoFullscreenFrame.width(), m_videoFullscreenFrame.height())];
- [m_videoFullscreenLayer insertSublayer:m_videoLayer.get() atIndex:0];
- }
+ if (m_videoFullscreenLayer) {
+ [m_videoLayer setFrame:CGRectMake(0, 0, m_videoFullscreenFrame.width(), m_videoFullscreenFrame.height())];
+ [m_videoFullscreenLayer insertSublayer:m_videoLayer.get() atIndex:0];
+ }
#endif
- player()->mediaPlayerClient()->mediaPlayerRenderingModeChanged(player());
- });
}
void MediaPlayerPrivateAVFoundationObjC::destroyVideoLayer()
@@ -747,6 +761,9 @@
[m_avPlayer.get() setAllowsExternalPlayback:m_allowsWirelessVideoPlayback];
#endif
+ if (player()->mediaPlayerClient() && player()->mediaPlayerClient()->mediaPlayerIsVideo())
+ createAVPlayerLayer();
+
if (m_avPlayerItem)
[m_avPlayer.get() replaceCurrentItemWithPlayerItem:m_avPlayerItem.get()];
@@ -874,7 +891,7 @@
PlatformLayer* MediaPlayerPrivateAVFoundationObjC::platformLayer() const
{
- return m_videoLayer.get();
+ return m_haveBeenAskedToCreateLayer ? m_videoLayer.get() : nullptr;
}
#if PLATFORM(IOS)