Modified: trunk/Source/WebCore/platform/graphics/avfoundation/cf/AVFoundationCFSoftLinking.h (174345 => 174346)
--- trunk/Source/WebCore/platform/graphics/avfoundation/cf/AVFoundationCFSoftLinking.h 2014-10-06 16:39:54 UTC (rev 174345)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/cf/AVFoundationCFSoftLinking.h 2014-10-06 17:49:24 UTC (rev 174346)
@@ -302,6 +302,9 @@
SOFT_LINK_DLL_IMPORT(AVFoundationCF, AVCFAssetResourceLoadingRequestGetURLRequest, CFURLRequestRef, __cdecl, (AVCFAssetResourceLoadingRequestRef loadingRequest), (loadingRequest))
#define AVCFAssetResourceLoadingRequestGetURLRequest softLink_AVCFAssetResourceLoadingRequestGetURLRequest
+SOFT_LINK_DLL_IMPORT(AVFoundationCF, AVCFAssetResourceLoadingRequestFinishLoadingWithResponse, void, __cdecl, (AVCFAssetResourceLoadingRequestRef loadingRequest, CFURLResponseRef response, CFDataRef data, CFURLRequestRef redirect), (loadingRequest, response, data, redirect))
+#define AVCFAssetResourceLoadingRequestFinishLoadingWithResponse softLink_AVCFAssetResourceLoadingRequestFinishLoadingWithResponse
+
#endif
// Variables
Modified: trunk/Source/WebCore/platform/graphics/avfoundation/cf/CDMSessionAVFoundationCF.cpp (174345 => 174346)
--- trunk/Source/WebCore/platform/graphics/avfoundation/cf/CDMSessionAVFoundationCF.cpp 2014-10-06 16:39:54 UTC (rev 174345)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/cf/CDMSessionAVFoundationCF.cpp 2014-10-06 17:49:24 UTC (rev 174346)
@@ -85,8 +85,7 @@
userInfo = adoptCF(CFErrorCopyUserInfo(cfError));
if (userInfo) {
- CFErrorRef underlyingError = (CFErrorRef)CFDictionaryGetValue(userInfo.get(), kCFErrorUnderlyingErrorKey);
- if (underlyingError)
+ if (CFErrorRef underlyingError = (CFErrorRef)CFDictionaryGetValue(userInfo.get(), kCFErrorUnderlyingErrorKey))
systemCode = CFErrorGetCode(underlyingError);
}
@@ -113,9 +112,7 @@
RetainPtr<CFMutableDataRef> keyData = adoptCF(CFDataCreateMutable(kCFAllocatorDefault, key->byteLength()));
CFDataAppendBytes(keyData.get(), reinterpret_cast<const UInt8*>(key->baseAddress()), key->byteLength());
- // TODO: AVCFAssetResourceLoadingDataRequestRespondWithData(m_request.get(), keyData.get());
- // TODO: AVCFAssetResourceLoadingRequestFinishedLoading(m_request.get());
- notImplemented();
+ AVCFAssetResourceLoadingRequestFinishLoadingWithResponse(m_request.get(), nullptr, keyData.get(), nullptr);
errorCode = MediaPlayer::NoError;
systemCode = 0;
Modified: trunk/Source/WebCore/platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.cpp (174345 => 174346)
--- trunk/Source/WebCore/platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.cpp 2014-10-06 16:39:54 UTC (rev 174345)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.cpp 2014-10-06 17:49:24 UTC (rev 174346)
@@ -153,6 +153,7 @@
#if ENABLE(ENCRYPTED_MEDIA_V2)
RetainPtr<AVCFAssetResourceLoadingRequestRef> takeRequestForKeyURI(const String&);
+ void setRequestForKey(const String& keyURI, AVCFAssetResourceLoadingRequestRef avRequest);
#endif
private:
@@ -197,7 +198,8 @@
InbandTextTrackPrivateAVF* m_currentTextTrack;
#if ENABLE(ENCRYPTED_MEDIA_V2)
- HashMap<String, RetainPtr<AVCFAssetResourceLoadingRequestRef>> m_keyURIToRequestMap;
+ HashMap<String, Vector<RetainPtr<AVCFAssetResourceLoadingRequestRef>>> m_keyURIToRequestMap;
+ AVCFAssetResourceLoaderCallbacks m_resourceLoaderCallbacks;
#endif
};
@@ -342,7 +344,7 @@
void MediaPlayerPrivateAVFoundationCF::registerMediaEngine(MediaEngineRegistrar registrar)
{
if (isAvailable())
- registrar(create, getSupportedTypes, supportsType, 0, 0, 0, 0);
+ registrar(create, getSupportedTypes, supportsType, 0, 0, 0, supportsKeySystem);
}
MediaPlayerPrivateAVFoundationCF::MediaPlayerPrivateAVFoundationCF(MediaPlayer* player)
@@ -407,6 +409,7 @@
void MediaPlayerPrivateAVFoundationCF::createContextVideoRenderer()
{
LOG(Media, "MediaPlayerPrivateAVFoundationCF::createContextVideoRenderer(%p)", this);
+ ASSERT(isMainThread());
if (imageGenerator(m_avfWrapper))
return;
@@ -417,12 +420,14 @@
void MediaPlayerPrivateAVFoundationCF::destroyContextVideoRenderer()
{
+ ASSERT(isMainThread());
if (m_avfWrapper)
m_avfWrapper->destroyImageGenerator();
}
void MediaPlayerPrivateAVFoundationCF::createVideoLayer()
{
+ ASSERT(isMainThread());
ASSERT(supportsAcceleratedRendering());
if (m_avfWrapper)
@@ -431,6 +436,7 @@
void MediaPlayerPrivateAVFoundationCF::destroyVideoLayer()
{
+ ASSERT(isMainThread());
LOG(Media, "MediaPlayerPrivateAVFoundationCF::destroyVideoLayer(%p) - destroying %p", this, videoLayer(m_avfWrapper));
if (m_avfWrapper)
m_avfWrapper->destroyVideoLayer();
@@ -470,6 +476,7 @@
void MediaPlayerPrivateAVFoundationCF::createAVPlayer()
{
+ ASSERT(isMainThread());
ASSERT(m_avfWrapper);
setDelayCallbacks(true);
@@ -479,6 +486,7 @@
void MediaPlayerPrivateAVFoundationCF::createAVPlayerItem()
{
+ ASSERT(isMainThread());
ASSERT(m_avfWrapper);
setDelayCallbacks(true);
@@ -529,6 +537,7 @@
PlatformLayer* MediaPlayerPrivateAVFoundationCF::platformLayer() const
{
+ ASSERT(isMainThread());
if (!m_avfWrapper)
return 0;
@@ -537,6 +546,7 @@
void MediaPlayerPrivateAVFoundationCF::platformSetVisible(bool isVisible)
{
+ ASSERT(isMainThread());
if (!m_avfWrapper)
return;
@@ -829,6 +839,7 @@
void MediaPlayerPrivateAVFoundationCF::paintCurrentFrameInContext(GraphicsContext* context, const IntRect& rect)
{
+ ASSERT(isMainThread());
if (!metaDataAvailable() || context->paintingDisabled())
return;
@@ -843,6 +854,7 @@
void MediaPlayerPrivateAVFoundationCF::paint(GraphicsContext* context, const IntRect& rect)
{
+ ASSERT(isMainThread());
if (!metaDataAvailable() || context->paintingDisabled() || !imageGenerator(m_avfWrapper))
return;
@@ -911,7 +923,26 @@
return MediaPlayer::IsNotSupported;
}
+bool MediaPlayerPrivateAVFoundationCF::supportsKeySystem(const String& keySystem, const String& mimeType)
+{
+#if ENABLE(ENCRYPTED_MEDIA) || ENABLE(ENCRYPTED_MEDIA_V2)
+ if (keySystem.isEmpty())
+ return false;
+ if (!keySystemIsSupported(keySystem))
+ return false;
+
+ if (!mimeType.isEmpty() && !mimeTypeCache().contains(mimeType))
+ return false;
+
+ return true;
+#else
+ UNUSED_PARAM(keySystem);
+ UNUSED_PARAM(mimeType);
+ return false;
+#endif
+}
+
bool MediaPlayerPrivateAVFoundationCF::isAvailable()
{
return AVFoundationCFLibrary() && CoreMediaLibrary();
@@ -1037,6 +1068,7 @@
void MediaPlayerPrivateAVFoundationCF::sizeChanged()
{
+ ASSERT(isMainThread());
if (!avAsset(m_avfWrapper))
return;
@@ -1157,11 +1189,8 @@
// We enabled automatic media selection because we want alternate audio tracks to be enabled/disabled automatically,
// but set the selected legible track to nil so text tracks will not be automatically configured.
- if (!m_textTracks.size()) {
- ASSERT(AVCFMediaSelectionGroupAllowsEmptySelection(legibleGroup));
- AVCFPlayerItemRef playerItem = avPlayerItem(m_avfWrapper);
-
- if (playerItem)
+ if (!m_textTracks.size() && AVCFMediaSelectionGroupAllowsEmptySelection(legibleGroup)) {
+ if (AVCFPlayerItemRef playerItem = avPlayerItem(m_avfWrapper))
AVCFPlayerItemSelectMediaOptionInMediaSelectionGroup(playerItem, 0, legibleGroup);
}
@@ -1285,6 +1314,13 @@
LOG(Media, "AVFWrapper::AVFWrapper(%p)", this);
m_notificationQueue = dispatch_queue_create("MediaPlayerPrivateAVFoundationCF.notificationQueue", 0);
+
+#if HAVE(AVFOUNDATION_LOADER_DELEGATE)
+ m_resourceLoaderCallbacks.version = kAVCFAssetResourceLoader_CallbacksVersion_1;
+ m_resourceLoaderCallbacks.context = nullptr;
+ m_resourceLoaderCallbacks.resourceLoaderShouldWaitForLoadingOfRequestedResource = AVFWrapper::resourceLoaderShouldWaitForLoadingOfRequestedResource;
+#endif
+
addToMap();
}
@@ -1431,14 +1467,11 @@
m_avAsset = adoptCF(AVCFURLAssetCreateWithURLAndOptions(kCFAllocatorDefault, urlRef.get(), optionsRef.get(), m_notificationQueue));
#if HAVE(AVFOUNDATION_LOADER_DELEGATE)
- AVCFAssetResourceLoaderCallbacks loaderCallbacks;
- loaderCallbacks.version = kAVCFAssetResourceLoader_CallbacksVersion_1;
ASSERT(callbackContext());
- loaderCallbacks.context = callbackContext();
- loaderCallbacks.resourceLoaderShouldWaitForLoadingOfRequestedResource = AVFWrapper::resourceLoaderShouldWaitForLoadingOfRequestedResource;
+ m_resourceLoaderCallbacks.context = callbackContext();
AVCFAssetResourceLoaderRef resourceLoader = AVCFURLAssetGetResourceLoader(m_avAsset.get());
- AVCFAssetResourceLoaderSetCallbacks(resourceLoader, &loaderCallbacks, globalLoaderDelegateQueue());
+ AVCFAssetResourceLoaderSetCallbacks(resourceLoader, &m_resourceLoaderCallbacks, globalLoaderDelegateQueue());
#endif
}
@@ -1572,7 +1605,7 @@
void AVFWrapper::processNotification(void* context)
{
- ASSERT(dispatch_get_main_queue() == dispatch_get_current_queue());
+ ASSERT(isMainThread());
ASSERT(context);
if (!context)
@@ -1718,7 +1751,7 @@
void AVFWrapper::processCue(void* context)
{
- ASSERT(dispatch_get_main_queue() == dispatch_get_current_queue());
+ ASSERT(isMainThread());
ASSERT(context);
if (!context)
@@ -1741,7 +1774,7 @@
void AVFWrapper::legibleOutputCallback(void* context, AVCFPlayerItemLegibleOutputRef legibleOutput, CFArrayRef attributedStrings, CFArrayRef nativeSampleBuffers, CMTime itemTime)
{
- ASSERT(dispatch_get_main_queue() != dispatch_get_current_queue());
+ ASSERT(!isMainThread());
MutexLocker locker(mapLock());
AVFWrapper* self = avfWrapperForCallbackContext(context);
if (!self) {
@@ -1784,12 +1817,15 @@
AVFWrapper* self = avfWrapperForCallbackContext(loadRequestData->m_context);
if (!self) {
LOG(Media, "AVFWrapper::processShouldWaitForLoadingOfResource invoked for deleted AVFWrapper %d", reinterpret_cast<uintptr_t>(context));
- AVCFAssetResourceLoadingRequestFinishLoadingWithError(loadRequestData->m_request.get(), nullptr);
+ RetainPtr<CFErrorRef> error = adoptCF(CFErrorCreate(kCFAllocatorDefault, kCFErrorDomainCFNetwork, kCFURLErrorUnknown, nullptr));
+ AVCFAssetResourceLoadingRequestFinishLoadingWithError(loadRequestData->m_request.get(), error.get());
return;
}
- if (!self->shouldWaitForLoadingOfResource(loadRequestData->m_request.get()))
- AVCFAssetResourceLoadingRequestFinishLoadingWithError(loadRequestData->m_request.get(), nullptr);
+ if (!self->shouldWaitForLoadingOfResource(loadRequestData->m_request.get())) {
+ RetainPtr<CFErrorRef> error = adoptCF(CFErrorCreate(kCFAllocatorDefault, kCFErrorDomainCFNetwork, kCFURLErrorUnknown, nullptr));
+ AVCFAssetResourceLoadingRequestFinishLoadingWithError(loadRequestData->m_request.get(), error.get());
+ }
}
bool AVFWrapper::shouldWaitForLoadingOfResource(AVCFAssetResourceLoadingRequestRef avRequest)
@@ -1819,7 +1855,7 @@
if (!m_owner->player()->keyNeeded(initData.get()))
return false;
- m_keyURIToRequestMap.set(keyURI, avRequest);
+ setRequestForKey(keyURI, avRequest);
return true;
}
#endif
@@ -1861,6 +1897,7 @@
PlatformLayer* AVFWrapper::platformLayer()
{
+ ASSERT(isMainThread());
if (m_videoLayerWrapper)
return m_videoLayerWrapper->platformLayer();
@@ -1991,14 +2028,36 @@
}
#if ENABLE(ENCRYPTED_MEDIA_V2)
+void AVFWrapper::setRequestForKey(const String& keyURI, AVCFAssetResourceLoadingRequestRef avRequest)
+{
+ auto requestsIterator = m_keyURIToRequestMap.find(keyURI);
+ if (requestsIterator != m_keyURIToRequestMap.end()) {
+ requestsIterator->value.append(avRequest);
+ return;
+ }
+
+ Vector<RetainPtr<AVCFAssetResourceLoadingRequestRef>> requests;
+ requests.append(avRequest);
+ m_keyURIToRequestMap.set(keyURI, requests);
+}
+
RetainPtr<AVCFAssetResourceLoadingRequestRef> AVFWrapper::takeRequestForKeyURI(const String& keyURI)
{
- return m_keyURIToRequestMap.take(keyURI);
+ auto requestsIterator = m_keyURIToRequestMap.find(keyURI);
+ if (requestsIterator == m_keyURIToRequestMap.end())
+ return RetainPtr<AVCFAssetResourceLoadingRequestRef>();
+
+ auto request = requestsIterator->value.takeLast();
+ if (requestsIterator->value.isEmpty())
+ m_keyURIToRequestMap.take(keyURI);
+
+ return request;
}
#endif
void LayerClient::platformCALayerLayoutSublayersOfLayer(PlatformCALayer* wrapperLayer)
{
+ ASSERT(isMainThread());
ASSERT(m_parent);
ASSERT(m_parent->videoLayerWrapper() == wrapperLayer->platformLayer());
Modified: trunk/Source/WebCore/platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp (174345 => 174346)
--- trunk/Source/WebCore/platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp 2014-10-06 16:39:54 UTC (rev 174345)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp 2014-10-06 17:49:24 UTC (rev 174346)
@@ -81,7 +81,8 @@
m_resource->addClient(this);
else {
LOG_ERROR("Failed to start load for media at url %s", requestURL.string().ascii().data());
- AVCFAssetResourceLoadingRequestFinishLoadingWithError(m_avRequest.get(), nullptr);
+ RetainPtr<CFErrorRef> error = adoptCF(CFErrorCreate(kCFAllocatorDefault, kCFErrorDomainCFNetwork, kCFURLErrorUnknown, nullptr));
+ AVCFAssetResourceLoadingRequestFinishLoadingWithError(m_avRequest.get(), error.get());
}
}
@@ -110,7 +111,8 @@
int status = response.httpStatusCode();
if (status && (status < 200 || status > 299)) {
- AVCFAssetResourceLoadingRequestFinishLoadingWithError(m_avRequest.get(), nullptr);
+ RetainPtr<CFErrorRef> error = adoptCF(CFErrorCreate(kCFAllocatorDefault, kCFErrorDomainCFNetwork, status, nullptr));
+ AVCFAssetResourceLoadingRequestFinishLoadingWithError(m_avRequest.get(), error.get());
return;
}
@@ -131,7 +133,8 @@
// FIXME: [[m_avRequest.get() contentInformationRequest] setContentType:@""];
notImplemented();
- AVCFAssetResourceLoadingRequestFinishLoadingWithError(m_avRequest.get(), nullptr);
+ RetainPtr<CFErrorRef> error = adoptCF(CFErrorCreate(kCFAllocatorDefault, kCFErrorDomainCFNetwork, kCFURLErrorUnknown, nullptr));
+ AVCFAssetResourceLoadingRequestFinishLoadingWithError(m_avRequest.get(), error.get());
} else {
fulfillRequestWithResource(resource);
// FIXME: [m_avRequest.get() finishLoading];