CDMSessionAVFoundationCF.cpp [plain text]
#include "config.h"
#include "CDMSessionAVFoundationCF.h"
#if HAVE(AVFOUNDATION_LOADER_DELEGATE) && ENABLE(ENCRYPTED_MEDIA_V2)
#include "CDM.h"
#include "CDMSession.h"
#include "ExceptionCode.h"
#include "MediaPlayer.h"
#include "MediaPlayerPrivateAVFoundationCF.h"
#include "NotImplemented.h"
#include "SoftLinking.h"
#include "UUID.h"
#include <AVFoundationCF/AVFoundationCF.h>
#include <wtf/text/CString.h>
#include "AVFoundationCFSoftLinking.h"
namespace WebCore {
CDMSessionAVFoundationCF::CDMSessionAVFoundationCF(MediaPlayerPrivateAVFoundationCF* parent, CDMSessionClient* client)
: m_parent(parent)
, m_client(client)
, m_sessionId(createCanonicalUUIDString())
{
}
RefPtr<Uint8Array> CDMSessionAVFoundationCF::generateKeyRequest(const String& mimeType, Uint8Array* initData, String& destinationURL, unsigned short& errorCode, uint32_t& systemCode)
{
UNUSED_PARAM(mimeType);
String keyURI;
String keyID;
RefPtr<Uint8Array> certificate;
if (!MediaPlayerPrivateAVFoundationCF::extractKeyURIKeyIDAndCertificateFromInitData(initData, keyURI, keyID, certificate)) {
errorCode = MediaPlayer::InvalidPlayerState;
return nullptr;
}
m_request = m_parent->takeRequestForKeyURI(keyURI);
if (!m_request) {
errorCode = MediaPlayer::InvalidPlayerState;
return nullptr;
}
RetainPtr<CFMutableDataRef> certificateData = adoptCF(CFDataCreateMutable(kCFAllocatorDefault, certificate->byteLength()));
CFDataAppendBytes(certificateData.get(), reinterpret_cast<const UInt8*>(certificate->baseAddress()), certificate->byteLength());
CString assetStr = keyID.utf8();
RetainPtr<CFMutableDataRef> assetID = adoptCF(CFDataCreateMutable(kCFAllocatorDefault, assetStr.length()));
CFDataAppendBytes(assetID.get(), reinterpret_cast<const UInt8*>(assetStr.data()), assetStr.length());
CFErrorRef cfError = nullptr;
RetainPtr<CFDataRef> keyRequest = adoptCF(AVCFAssetResourceLoadingRequestCreateStreamingContentKeyRequestDataForApp(m_request.get(), certificateData.get(), assetID.get(), nullptr, &cfError));
if (!keyRequest) {
RetainPtr<CFDictionaryRef> userInfo;
if (cfError) {
userInfo = adoptCF(CFErrorCopyUserInfo(cfError));
if (userInfo) {
if (CFErrorRef underlyingError = (CFErrorRef)CFDictionaryGetValue(userInfo.get(), kCFErrorUnderlyingErrorKey))
systemCode = CFErrorGetCode(underlyingError);
}
CFRelease(cfError);
}
return nullptr;
}
errorCode = MediaPlayer::NoError;
systemCode = 0;
destinationURL = String();
RefPtr<ArrayBuffer> keyRequestBuffer = ArrayBuffer::create(CFDataGetBytePtr(keyRequest.get()), CFDataGetLength(keyRequest.get()));
return Uint8Array::create(keyRequestBuffer, 0, keyRequestBuffer->byteLength());
}
void CDMSessionAVFoundationCF::releaseKeys()
{
}
bool CDMSessionAVFoundationCF::update(Uint8Array* key, RefPtr<Uint8Array>& nextMessage, unsigned short& errorCode, uint32_t& systemCode)
{
RetainPtr<CFMutableDataRef> keyData = adoptCF(CFDataCreateMutable(kCFAllocatorDefault, key->byteLength()));
CFDataAppendBytes(keyData.get(), reinterpret_cast<const UInt8*>(key->baseAddress()), key->byteLength());
AVCFAssetResourceLoadingRequestFinishLoadingWithResponse(m_request.get(), nullptr, keyData.get(), nullptr);
errorCode = MediaPlayer::NoError;
systemCode = 0;
nextMessage = nullptr;
return true;
}
}
#endif