Title: [244439] trunk
Revision
244439
Author
jer.no...@apple.com
Date
2019-04-18 15:07:56 -0700 (Thu, 18 Apr 2019)

Log Message

Add support for parsing FairPlayStreaming PSSH boxes.
https://bugs.webkit.org/show_bug.cgi?id=197064

Reviewed by Eric Carlson.

Source/WebCore:

API Tests: ISO.ISOFairPlayStreamingPsshBox

Add a new set of ISOBox classes for parsing the contents of a FairPlayStreaming PSSH box,
and add support for this new box to CDMFairPlayStreaming.

Drive-by fix: add an explicit include for MainThread.h to LibWebRTCProviderCocoa.cpp.

* SourcesCocoa.txt:
* WebCore.xcodeproj/project.pbxproj:
* platform/graphics/FourCC.h:
* platform/graphics/avfoundation/CDMFairPlayStreaming.cpp:
(WebCore::CDMPrivateFairPlayStreaming::cencName):
(WebCore::fairPlaySystemID):
(WebCore::extractSchemeAndKeyIdFromCenc):
(WebCore::CDMPrivateFairPlayStreaming::extractKeyIDsCenc):
(WebCore::CDMPrivateFairPlayStreaming::sanitizeCenc):
(WebCore::validInitDataTypes):
(WebCore::CDMFactory::platformRegisterFactories):
* platform/graphics/avfoundation/CDMFairPlayStreaming.h:
* platform/graphics/avfoundation/ISOFairPlayStreamingPsshBox.cpp: Added.
(WebCore::ISOFairPlayStreamingPsshBox::fairPlaySystemID):
(WebCore::ISOFairPlayStreamingInfoBox::parse):
(WebCore::ISOFairPlayStreamingKeyRequestInfoBox::parse):
(WebCore::ISOFairPlayStreamingKeyAssetIdBox::parse):
(WebCore::ISOFairPlayStreamingKeyContextBox::parse):
(WebCore::ISOFairPlayStreamingKeyVersionListBox::parse):
(WebCore::ISOFairPlayStreamingKeyRequestBox::parse):
(WebCore::ISOFairPlayStreamingInitDataBox::parse):
(WebCore::ISOFairPlayStreamingPsshBox::parse):
* platform/graphics/avfoundation/ISOFairPlayStreamingPsshBox.h: Added.
* platform/mediastream/libwebrtc/LibWebRTCProviderCocoa.cpp:

Source/WTF:

* wtf/Platform.h:

Tools:

* TestWebKitAPI/Tests/WebCore/ISOBox.cpp:
(TestWebKitAPI::TEST):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (244438 => 244439)


--- trunk/Source/WTF/ChangeLog	2019-04-18 21:57:48 UTC (rev 244438)
+++ trunk/Source/WTF/ChangeLog	2019-04-18 22:07:56 UTC (rev 244439)
@@ -1,3 +1,12 @@
+2019-04-18  Jer Noble  <jer.no...@apple.com>
+
+        Add support for parsing FairPlayStreaming PSSH boxes.
+        https://bugs.webkit.org/show_bug.cgi?id=197064
+
+        Reviewed by Eric Carlson.
+
+        * wtf/Platform.h:
+
 2019-04-18  Yusuke Suzuki  <ysuz...@apple.com>
 
         [WTF] StringBuilder should set correct m_is8Bit flag when merging

Modified: trunk/Source/WTF/wtf/Platform.h (244438 => 244439)


--- trunk/Source/WTF/wtf/Platform.h	2019-04-18 21:57:48 UTC (rev 244438)
+++ trunk/Source/WTF/wtf/Platform.h	2019-04-18 22:07:56 UTC (rev 244439)
@@ -1517,6 +1517,7 @@
 
 #if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 130000) || (PLATFORM(WATCHOS) && __WATCH_OS_VERSION_MIN_REQUIRED >= 60000) || (PLATFORM(APPLETV) && __TV_OS_VERSION_MIN_REQUIRED >= 130000)
 #define HAVE_ALLOWS_SENSITIVE_LOGGING 1
+#define HAVE_FAIRPLAYSTREAMING_CENC_INITDATA 1
 #endif
 
 #if (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 130000) || (PLATFORM(WATCHOS) && __WATCH_OS_VERSION_MIN_REQUIRED >= 60000) || (PLATFORM(APPLETV) && __TV_OS_VERSION_MIN_REQUIRED >= 130000)

Modified: trunk/Source/WebCore/ChangeLog (244438 => 244439)


--- trunk/Source/WebCore/ChangeLog	2019-04-18 21:57:48 UTC (rev 244438)
+++ trunk/Source/WebCore/ChangeLog	2019-04-18 22:07:56 UTC (rev 244439)
@@ -1,3 +1,42 @@
+2019-04-18  Jer Noble  <jer.no...@apple.com>
+
+        Add support for parsing FairPlayStreaming PSSH boxes.
+        https://bugs.webkit.org/show_bug.cgi?id=197064
+
+        Reviewed by Eric Carlson.
+
+        API Tests: ISO.ISOFairPlayStreamingPsshBox
+
+        Add a new set of ISOBox classes for parsing the contents of a FairPlayStreaming PSSH box,
+        and add support for this new box to CDMFairPlayStreaming.
+
+        Drive-by fix: add an explicit include for MainThread.h to LibWebRTCProviderCocoa.cpp.
+
+        * SourcesCocoa.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/graphics/FourCC.h:
+        * platform/graphics/avfoundation/CDMFairPlayStreaming.cpp:
+        (WebCore::CDMPrivateFairPlayStreaming::cencName):
+        (WebCore::fairPlaySystemID):
+        (WebCore::extractSchemeAndKeyIdFromCenc):
+        (WebCore::CDMPrivateFairPlayStreaming::extractKeyIDsCenc):
+        (WebCore::CDMPrivateFairPlayStreaming::sanitizeCenc):
+        (WebCore::validInitDataTypes):
+        (WebCore::CDMFactory::platformRegisterFactories):
+        * platform/graphics/avfoundation/CDMFairPlayStreaming.h:
+        * platform/graphics/avfoundation/ISOFairPlayStreamingPsshBox.cpp: Added.
+        (WebCore::ISOFairPlayStreamingPsshBox::fairPlaySystemID):
+        (WebCore::ISOFairPlayStreamingInfoBox::parse):
+        (WebCore::ISOFairPlayStreamingKeyRequestInfoBox::parse):
+        (WebCore::ISOFairPlayStreamingKeyAssetIdBox::parse):
+        (WebCore::ISOFairPlayStreamingKeyContextBox::parse):
+        (WebCore::ISOFairPlayStreamingKeyVersionListBox::parse):
+        (WebCore::ISOFairPlayStreamingKeyRequestBox::parse):
+        (WebCore::ISOFairPlayStreamingInitDataBox::parse):
+        (WebCore::ISOFairPlayStreamingPsshBox::parse):
+        * platform/graphics/avfoundation/ISOFairPlayStreamingPsshBox.h: Added.
+        * platform/mediastream/libwebrtc/LibWebRTCProviderCocoa.cpp:
+
 2019-04-18  Sihui Liu  <sihui_...@apple.com>
 
         Blob type cannot be stored correctly in IDB when IDBObjectStore has autoIncrement and keyPath options

Modified: trunk/Source/WebCore/SourcesCocoa.txt (244438 => 244439)


--- trunk/Source/WebCore/SourcesCocoa.txt	2019-04-18 21:57:48 UTC (rev 244438)
+++ trunk/Source/WebCore/SourcesCocoa.txt	2019-04-18 22:07:56 UTC (rev 244439)
@@ -225,6 +225,7 @@
 platform/graphics/avfoundation/CDMPrivateMediaSourceAVFObjC.mm @no-unify
 platform/graphics/avfoundation/InbandMetadataTextTrackPrivateAVF.cpp @no-unify
 platform/graphics/avfoundation/InbandTextTrackPrivateAVF.cpp @no-unify
+platform/graphics/avfoundation/ISOFairPlayStreamingPsshBox.cpp
 platform/graphics/avfoundation/MediaPlaybackTargetMac.mm @no-unify
 platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp @no-unify
 platform/graphics/avfoundation/MediaSelectionGroupAVFObjC.mm @no-unify

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (244438 => 244439)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2019-04-18 21:57:48 UTC (rev 244438)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2019-04-18 22:07:56 UTC (rev 244439)
@@ -4046,6 +4046,7 @@
 		CD62FB961AF018E70012ED7D /* GenericTaskQueue.h in Headers */ = {isa = PBXBuildFile; fileRef = CD62FB941AF018E70012ED7D /* GenericTaskQueue.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		CD641EB31818F5ED00EE4C41 /* MediaSourcePrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = CD641EB11818F5ED00EE4C41 /* MediaSourcePrivate.h */; };
 		CD641EB41818F5ED00EE4C41 /* SourceBufferPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = CD641EB21818F5ED00EE4C41 /* SourceBufferPrivate.h */; };
+		CD720B4F2268B51300047FDE /* ISOFairPlayStreamingPsshBox.h in Headers */ = {isa = PBXBuildFile; fileRef = CD720B4922682C7F00047FDE /* ISOFairPlayStreamingPsshBox.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		CD7D33441C7A123F00041293 /* PixelBufferConformerCV.h in Headers */ = {isa = PBXBuildFile; fileRef = CD7D33421C7A123F00041293 /* PixelBufferConformerCV.h */; };
 		CD7D33481C7A16BF00041293 /* CoreVideoSoftLink.h in Headers */ = {isa = PBXBuildFile; fileRef = CD7D33461C7A16BF00041293 /* CoreVideoSoftLink.h */; };
 		CD7DBB2918CA19C600C11066 /* CSSGridLineNamesValue.h in Headers */ = {isa = PBXBuildFile; fileRef = CD7DBB2718CA11FF00C11066 /* CSSGridLineNamesValue.h */; };
@@ -13499,6 +13500,8 @@
 		CD641EB11818F5ED00EE4C41 /* MediaSourcePrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaSourcePrivate.h; sourceTree = "<group>"; };
 		CD641EB21818F5ED00EE4C41 /* SourceBufferPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SourceBufferPrivate.h; sourceTree = "<group>"; };
 		CD641EC7181ED60100EE4C41 /* MediaSample.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MediaSample.h; sourceTree = "<group>"; };
+		CD720B4722682C7E00047FDE /* ISOFairPlayStreamingPsshBox.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ISOFairPlayStreamingPsshBox.cpp; sourceTree = "<group>"; };
+		CD720B4922682C7F00047FDE /* ISOFairPlayStreamingPsshBox.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ISOFairPlayStreamingPsshBox.h; sourceTree = "<group>"; };
 		CD78A2EC1F75648600DE371B /* CDMInstanceFairPlayStreamingAVFObjC.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CDMInstanceFairPlayStreamingAVFObjC.mm; sourceTree = "<group>"; };
 		CD78A2EE1F75648600DE371B /* CDMInstanceFairPlayStreamingAVFObjC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDMInstanceFairPlayStreamingAVFObjC.h; sourceTree = "<group>"; };
 		CD7D33411C7A123F00041293 /* PixelBufferConformerCV.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PixelBufferConformerCV.cpp; sourceTree = "<group>"; };
@@ -15872,6 +15875,8 @@
 				07E9E12D18F5E2760011A3A4 /* InbandMetadataTextTrackPrivateAVF.h */,
 				07B442D4166C70B000556CAD /* InbandTextTrackPrivateAVF.cpp */,
 				07B442D5166C70B000556CAD /* InbandTextTrackPrivateAVF.h */,
+				CD720B4722682C7E00047FDE /* ISOFairPlayStreamingPsshBox.cpp */,
+				CD720B4922682C7F00047FDE /* ISOFairPlayStreamingPsshBox.h */,
 				071E496F1AD5AB5E008A50B4 /* MediaPlaybackTargetMac.h */,
 				071E496D1AD5AA0D008A50B4 /* MediaPlaybackTargetMac.mm */,
 				076F0D0912B8192700C26AA4 /* MediaPlayerPrivateAVFoundation.cpp */,
@@ -29456,6 +29461,7 @@
 				2D0B4AAB18DA1CCD00434DE1 /* IOSurface.h in Headers */,
 				1C21E57D183ED1FF001C289D /* IOSurfacePool.h in Headers */,
 				CD5FF4992162E2BE004BD86F /* ISOBox.h in Headers */,
+				CD720B4F2268B51300047FDE /* ISOFairPlayStreamingPsshBox.h in Headers */,
 				CD5FF49E2162E4E8004BD86F /* ISOOriginalFormatBox.h in Headers */,
 				CD5FF49D2162E4DB004BD86F /* ISOProtectionSchemeInfoBox.h in Headers */,
 				CD5FF49C2162E4CF004BD86F /* ISOProtectionSystemSpecificHeaderBox.h in Headers */,

Modified: trunk/Source/WebCore/platform/graphics/FourCC.h (244438 => 244439)


--- trunk/Source/WebCore/platform/graphics/FourCC.h	2019-04-18 21:57:48 UTC (rev 244438)
+++ trunk/Source/WebCore/platform/graphics/FourCC.h	2019-04-18 22:07:56 UTC (rev 244439)
@@ -30,6 +30,7 @@
 namespace WebCore {
 
 struct FourCC {
+    FourCC() = default;
     FourCC(uint32_t value) : value(value) { }
 
     template<std::size_t N>
@@ -45,7 +46,7 @@
     bool operator==(const FourCC& other) const { return value == other.value; }
     bool operator!=(const FourCC& other) const { return value != other.value; }
 
-    uint32_t value;
+    uint32_t value { 0 };
 };
 
 }

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/CDMFairPlayStreaming.cpp (244438 => 244439)


--- trunk/Source/WebCore/platform/graphics/avfoundation/CDMFairPlayStreaming.cpp	2019-04-18 21:57:48 UTC (rev 244438)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/CDMFairPlayStreaming.cpp	2019-04-18 22:07:56 UTC (rev 244439)
@@ -32,6 +32,7 @@
 #include "CDMKeySystemConfiguration.h"
 #include "CDMRestrictions.h"
 #include "CDMSessionType.h"
+#include "ISOFairPlayStreamingPsshBox.h"
 #include "ISOSchemeInformationBox.h"
 #include "ISOSchemeTypeBox.h"
 #include "ISOTrackEncryptionBox.h"
@@ -74,6 +75,18 @@
     return skd;
 }
 
+const AtomicString& CDMPrivateFairPlayStreaming::cencName()
+{
+    static NeverDestroyed<AtomicString> cenc { MAKE_STATIC_STRING_IMPL("cenc") };
+    return cenc;
+}
+
+static const Vector<uint8_t>& fairPlaySystemID()
+{
+    static NeverDestroyed<Vector<uint8_t>> systemID = Vector<uint8_t>({ 0x94, 0xCE, 0x86, 0xFB, 0x07, 0xFF, 0x4F, 0x43, 0xAD, 0xB8, 0x93, 0xD2, 0xFA, 0x96, 0x8C, 0xA2 });
+    return systemID;
+}
+
 static Vector<Ref<SharedBuffer>> extractSinfData(const SharedBuffer& buffer)
 {
     // JSON of the format: "{ sinf: [ <base64-encoded-string> ] }"
@@ -171,6 +184,54 @@
     return keyIDs;
 }
 
+static SchemeAndKeyResult extractSchemeAndKeyIdFromCenc(const SharedBuffer& buffer)
+{
+    auto arrayBuffer = buffer.tryCreateArrayBuffer();
+    if (!arrayBuffer)
+        return { };
+
+    auto view = JSC::DataView::create(WTFMove(arrayBuffer), 0, buffer.size());
+    unsigned offset { 0 };
+
+    SchemeAndKeyResult result;
+    while (offset < buffer.size()) {
+        auto peekResult = ISOBox::peekBox(view, offset);
+        if (!peekResult || peekResult.value().first != ISOProtectionSystemSpecificHeaderBox::boxTypeName())
+            return { };
+
+        ISOProtectionSystemSpecificHeaderBox psshBox;
+        if (!psshBox.read(view, offset))
+            return { };
+
+        if (psshBox.systemID() != fairPlaySystemID())
+            continue;
+
+        ISOFairPlayStreamingPsshBox fpsPssh;
+        offset -= psshBox.size();
+        if (!fpsPssh.read(view, offset))
+            return { };
+
+        FourCC scheme = fpsPssh.initDataBox().info().scheme();
+        for (auto request : fpsPssh.initDataBox().requests())
+            result.append(std::make_pair(scheme, request.requestInfo().keyID()));
+    }
+
+    return result;
+}
+
+Optional<Vector<Ref<SharedBuffer>>> CDMPrivateFairPlayStreaming::extractKeyIDsCenc(const SharedBuffer& buffer)
+{
+    Vector<Ref<SharedBuffer>> keyIDs;
+    auto results = extractSchemeAndKeyIdFromCenc(buffer);
+
+    for (auto& result : results) {
+        if (validFairPlayStreamingSchemes().contains(result.first))
+            keyIDs.append(SharedBuffer::create(result.second.data(), result.second.size()));
+    }
+
+    return keyIDs;
+}
+
 RefPtr<SharedBuffer> CDMPrivateFairPlayStreaming::sanitizeSinf(const SharedBuffer& buffer)
 {
     // Common SINF Box Format
@@ -186,6 +247,13 @@
     return buffer.copy();
 }
 
+RefPtr<SharedBuffer> CDMPrivateFairPlayStreaming::sanitizeCenc(const SharedBuffer& buffer)
+{
+    UNUSED_PARAM(buffer);
+    notImplemented();
+    return buffer.copy();
+}
+
 Optional<Vector<Ref<SharedBuffer>>> CDMPrivateFairPlayStreaming::extractKeyIDsSkd(const SharedBuffer& buffer)
 {
     // In the 'skd' scheme, the init data is the key ID.
@@ -196,7 +264,13 @@
 
 static const HashSet<AtomicString>& validInitDataTypes()
 {
-    static NeverDestroyed<HashSet<AtomicString>> validTypes = HashSet<AtomicString>({ CDMPrivateFairPlayStreaming::sinfName(), CDMPrivateFairPlayStreaming::skdName() });
+    static NeverDestroyed<HashSet<AtomicString>> validTypes = HashSet<AtomicString>({
+        CDMPrivateFairPlayStreaming::sinfName(),
+        CDMPrivateFairPlayStreaming::skdName(),
+#if HAVE(FAIRPLAYSTREAMING_CENC_INITDATA)
+        CDMPrivateFairPlayStreaming::cencName(),
+#endif
+    });
     return validTypes;
 }
 
@@ -207,6 +281,9 @@
 
     InitDataRegistry::shared().registerInitDataType(CDMPrivateFairPlayStreaming::sinfName(), { CDMPrivateFairPlayStreaming::sanitizeSinf, CDMPrivateFairPlayStreaming::extractKeyIDsSinf });
     InitDataRegistry::shared().registerInitDataType(CDMPrivateFairPlayStreaming::skdName(), { CDMPrivateFairPlayStreaming::sanitizeSkd, CDMPrivateFairPlayStreaming::extractKeyIDsSkd });
+#if HAVE(FAIRPLAYSTREAMING_CENC_INITDATA)
+    InitDataRegistry::shared().registerInitDataType(CDMPrivateFairPlayStreaming::cencName(), { CDMPrivateFairPlayStreaming::sanitizeCenc, CDMPrivateFairPlayStreaming::extractKeyIDsCenc });
+#endif
 }
 
 CDMFactoryFairPlayStreaming& CDMFactoryFairPlayStreaming::singleton()

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/CDMFairPlayStreaming.h (244438 => 244439)


--- trunk/Source/WebCore/platform/graphics/avfoundation/CDMFairPlayStreaming.h	2019-04-18 21:57:48 UTC (rev 244438)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/CDMFairPlayStreaming.h	2019-04-18 22:07:56 UTC (rev 244439)
@@ -74,6 +74,10 @@
     static const AtomicString& skdName();
     static Optional<Vector<Ref<SharedBuffer>>> extractKeyIDsSkd(const SharedBuffer&);
     static RefPtr<SharedBuffer> sanitizeSkd(const SharedBuffer&);
+
+    static const AtomicString& cencName();
+    static Optional<Vector<Ref<SharedBuffer>>> extractKeyIDsCenc(const SharedBuffer&);
+    static RefPtr<SharedBuffer> sanitizeCenc(const SharedBuffer&);
 };
 
 }

Added: trunk/Source/WebCore/platform/graphics/avfoundation/ISOFairPlayStreamingPsshBox.cpp (0 => 244439)


--- trunk/Source/WebCore/platform/graphics/avfoundation/ISOFairPlayStreamingPsshBox.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/ISOFairPlayStreamingPsshBox.cpp	2019-04-18 22:07:56 UTC (rev 244439)
@@ -0,0 +1,251 @@
+/*
+ * Copyright (C) 2019 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.
+ */
+
+#include "config.h"
+#include "ISOFairPlayStreamingPsshBox.h"
+
+#include <_javascript_Core/DataView.h>
+
+namespace WebCore {
+
+const Vector<uint8_t>& ISOFairPlayStreamingPsshBox::fairPlaySystemID()
+{
+    static NeverDestroyed<Vector<uint8_t>> systemID = Vector<uint8_t>({ 0x94, 0xCE, 0x86, 0xFB, 0x07, 0xFF, 0x4F, 0x43, 0xAD, 0xB8, 0x93, 0xD2, 0xFA, 0x96, 0x8C, 0xA2 });
+    return systemID;
+}
+
+bool ISOFairPlayStreamingInfoBox::parse(JSC::DataView& view, unsigned& offset)
+{
+    if (!ISOFullBox::parse(view, offset))
+        return false;
+
+    return checkedRead<uint32_t>(m_scheme, view, offset, BigEndian);
+}
+
+bool ISOFairPlayStreamingKeyRequestInfoBox::parse(JSC::DataView& view, unsigned& offset)
+{
+    unsigned localOffset = offset;
+    if (!ISOBox::parse(view, localOffset))
+        return false;
+
+    Checked<uint64_t, RecordOverflow> remaining = m_size;
+    remaining -= (localOffset - offset);
+    if (remaining.hasOverflowed())
+        return false;
+
+    if (remaining < m_keyID.capacity())
+        return false;
+
+    auto buffer = view.possiblySharedBuffer();
+    if (!buffer)
+        return false;
+
+    auto keyID = buffer->slice(localOffset, localOffset + m_keyID.capacity());
+    localOffset += m_keyID.capacity();
+
+    m_keyID.resize(m_keyID.capacity());
+    memcpy(m_keyID.data(), keyID->data(), m_keyID.capacity());
+
+    offset = localOffset;
+    return true;
+}
+
+bool ISOFairPlayStreamingKeyAssetIdBox::parse(JSC::DataView& view, unsigned& offset)
+{
+    unsigned localOffset = offset;
+    if (!ISOBox::parse(view, localOffset))
+        return false;
+
+    if (localOffset - offset == m_size) {
+        m_data.clear();
+        offset = localOffset;
+        return true;
+    }
+
+    auto buffer = view.possiblySharedBuffer();
+    if (!buffer)
+        return false;
+
+    uint64_t dataSize;
+    if (!WTF::safeSub(m_size, localOffset - offset, dataSize))
+        return false;
+
+    auto parsedData = buffer->slice(localOffset, localOffset + dataSize);
+    localOffset += dataSize;
+
+    m_data.resize(dataSize);
+    memcpy(m_data.data(), parsedData->data(), dataSize);
+    offset = localOffset;
+    return true;
+}
+
+bool ISOFairPlayStreamingKeyContextBox::parse(JSC::DataView& view, unsigned& offset)
+{
+    unsigned localOffset = offset;
+    if (!ISOBox::parse(view, localOffset))
+        return false;
+
+    if (localOffset - offset == m_size) {
+        m_data.clear();
+        offset = localOffset;
+        return true;
+    }
+
+    auto buffer = view.possiblySharedBuffer();
+    if (!buffer)
+        return false;
+
+    uint64_t dataSize;
+    if (!WTF::safeSub(m_size, localOffset - offset, dataSize))
+        return false;
+
+    auto parsedData = buffer->slice(localOffset, localOffset + dataSize);
+    localOffset += dataSize;
+
+    m_data.resize(dataSize);
+    memcpy(m_data.data(), parsedData->data(), dataSize);
+    offset = localOffset;
+    return true;
+}
+
+bool ISOFairPlayStreamingKeyVersionListBox::parse(JSC::DataView& view, unsigned& offset)
+{
+    unsigned localOffset = offset;
+    if (!ISOBox::parse(view, localOffset))
+        return false;
+
+    do {
+        if (localOffset - offset == m_size)
+            break;
+
+        uint64_t remaining;
+        if (!WTF::safeSub(m_size, localOffset - offset, remaining))
+            return false;
+
+        if (remaining < sizeof(uint32_t))
+            return false;
+
+        uint32_t version;
+        if (!checkedRead<uint32_t>(version, view, localOffset, BigEndian))
+            return false;
+        m_versions.append(version);
+    } while (true);
+
+    offset = localOffset;
+    return true; 
+}
+
+bool ISOFairPlayStreamingKeyRequestBox::parse(JSC::DataView& view, unsigned& offset)
+{
+    unsigned localOffset = offset;
+    if (!ISOBox::parse(view, localOffset))
+        return false;
+
+    if (!m_requestInfo.read(view, localOffset))
+        return false;
+
+    while (localOffset - offset < m_size) {
+        auto result = peekBox(view, localOffset);
+        if (!result)
+            return false;
+
+        auto name = result.value().first;
+        if (name == ISOFairPlayStreamingKeyAssetIdBox::boxTypeName()) {
+            if (m_assetID)
+                return false;
+
+            ISOFairPlayStreamingKeyAssetIdBox assetID;
+            if (!assetID.read(view, localOffset))
+                return false;
+
+            m_assetID = WTFMove(assetID);
+            continue;
+        }
+
+        if (name == ISOFairPlayStreamingKeyContextBox::boxTypeName()) {
+            if (m_context)
+                return false;
+
+            ISOFairPlayStreamingKeyContextBox context;
+            if (!context.read(view, localOffset))
+                return false;
+
+            m_context = WTFMove(context);
+            continue;
+        }
+
+        if (name == ISOFairPlayStreamingKeyVersionListBox::boxTypeName()) {
+            if (m_versionList)
+                return false;
+
+            ISOFairPlayStreamingKeyVersionListBox versionList;
+            if (!versionList.read(view, localOffset))
+                return false;
+
+            m_versionList = WTFMove(versionList);
+            continue;
+        }
+
+        // Unknown box type; error.
+        return false;
+    }   
+    
+    offset = localOffset;
+    return true; 
+}
+
+bool ISOFairPlayStreamingInitDataBox::parse(JSC::DataView& view, unsigned& offset)
+{
+    unsigned localOffset = offset;
+    if (!ISOBox::parse(view, localOffset))
+        return false;
+
+    if (!m_info.read(view, localOffset))
+        return false;
+
+    while (localOffset - offset < m_size) {
+        ISOFairPlayStreamingKeyRequestBox request;
+        if (!request.read(view, localOffset))
+            return false;
+
+        m_requests.append(WTFMove(request));
+    }
+
+    offset = localOffset;
+    return true;
+}
+
+bool ISOFairPlayStreamingPsshBox::parse(JSC::DataView& view, unsigned& offset)
+{
+    if (!ISOProtectionSystemSpecificHeaderBox::parse(view, offset))
+        return false;
+
+    // Back up the offset by exactly the size of m_data:
+    offset -= m_data.size();
+
+    return m_initDataBox.read(view, offset);
+}
+
+}

Added: trunk/Source/WebCore/platform/graphics/avfoundation/ISOFairPlayStreamingPsshBox.h (0 => 244439)


--- trunk/Source/WebCore/platform/graphics/avfoundation/ISOFairPlayStreamingPsshBox.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/ISOFairPlayStreamingPsshBox.h	2019-04-18 22:07:56 UTC (rev 244439)
@@ -0,0 +1,135 @@
+/*
+ * Copyright (C) 2019 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.
+ */
+
+#pragma once
+
+#include "ISOProtectionSystemSpecificHeaderBox.h"
+#include <wtf/Optional.h>
+
+namespace WebCore {
+
+class WEBCORE_EXPORT ISOFairPlayStreamingInfoBox : public ISOFullBox {
+public:
+    static FourCC boxTypeName() { return "fpsi"; }
+
+    FourCC scheme() const { return m_scheme; }
+
+private:
+    bool parse(JSC::DataView&, unsigned& offset) override;
+
+    FourCC m_scheme;
+};
+
+class WEBCORE_EXPORT ISOFairPlayStreamingKeyRequestInfoBox : public ISOBox {
+public:
+    static FourCC boxTypeName() { return "fkri"; }
+
+    using KeyID = Vector<uint8_t, 16>;
+    const KeyID& keyID() const { return m_keyID; }
+
+private:
+    bool parse(JSC::DataView&, unsigned& offset) override;
+
+    KeyID m_keyID;
+};
+
+class WEBCORE_EXPORT ISOFairPlayStreamingKeyAssetIdBox : public ISOBox {
+public:
+    static FourCC boxTypeName() { return "fkai"; }
+    const Vector<uint8_t> data() const { return m_data; }
+
+private:
+    bool parse(JSC::DataView&, unsigned& offset) override;
+
+    Vector<uint8_t> m_data;
+};
+
+class WEBCORE_EXPORT ISOFairPlayStreamingKeyContextBox : public ISOBox {
+public:
+    static FourCC boxTypeName() { return "fkcx"; }
+    const Vector<uint8_t> data() const { return m_data; }
+
+private:
+    bool parse(JSC::DataView&, unsigned& offset) override;
+
+    Vector<uint8_t> m_data;
+};
+
+class WEBCORE_EXPORT ISOFairPlayStreamingKeyVersionListBox : public ISOBox {
+public:
+    static FourCC boxTypeName() { return "fkvl"; }
+    const Vector<uint8_t> versions() const { return m_versions; }
+
+private:
+    bool parse(JSC::DataView&, unsigned& offset) override;
+
+    Vector<uint8_t> m_versions;
+};
+
+class WEBCORE_EXPORT ISOFairPlayStreamingKeyRequestBox : public ISOBox {
+public:
+    static FourCC boxTypeName() { return "fpsk"; }
+
+    const ISOFairPlayStreamingKeyRequestInfoBox& requestInfo() const { return m_requestInfo; }
+    const Optional<ISOFairPlayStreamingKeyAssetIdBox>& assetID() const { return m_assetID; }
+    const Optional<ISOFairPlayStreamingKeyContextBox>& content() const { return m_context; }
+    const Optional<ISOFairPlayStreamingKeyVersionListBox>& versionList() const { return m_versionList; }
+
+private:
+    bool parse(JSC::DataView&, unsigned& offset) override;
+
+    ISOFairPlayStreamingKeyRequestInfoBox m_requestInfo;
+    Optional<ISOFairPlayStreamingKeyAssetIdBox> m_assetID;
+    Optional<ISOFairPlayStreamingKeyContextBox> m_context;
+    Optional<ISOFairPlayStreamingKeyVersionListBox> m_versionList;
+};
+
+class WEBCORE_EXPORT ISOFairPlayStreamingInitDataBox : public ISOBox {
+public:
+    static FourCC boxTypeName() { return "fps "; }
+
+    const ISOFairPlayStreamingInfoBox& info() const { return m_info; }
+    const Vector<ISOFairPlayStreamingKeyRequestBox>& requests() const { return m_requests; }
+
+private:
+    bool parse(JSC::DataView&, unsigned& offset) override;
+
+    ISOFairPlayStreamingInfoBox m_info;
+    Vector<ISOFairPlayStreamingKeyRequestBox> m_requests;
+};
+
+class WEBCORE_EXPORT ISOFairPlayStreamingPsshBox : public ISOProtectionSystemSpecificHeaderBox {
+public:
+    static const Vector<uint8_t>& fairPlaySystemID();
+
+    const ISOFairPlayStreamingInitDataBox& initDataBox() { return m_initDataBox; }
+
+private:
+    bool parse(JSC::DataView&, unsigned& offset) override;
+
+    ISOFairPlayStreamingInitDataBox m_initDataBox;
+};
+
+}

Modified: trunk/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCProviderCocoa.cpp (244438 => 244439)


--- trunk/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCProviderCocoa.cpp	2019-04-18 21:57:48 UTC (rev 244438)
+++ trunk/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCProviderCocoa.cpp	2019-04-18 22:07:56 UTC (rev 244439)
@@ -31,6 +31,7 @@
 #include <webrtc/media/engine/webrtcvideodecoderfactory.h>
 #include <webrtc/media/engine/webrtcvideoencoderfactory.h>
 #include <webrtc/sdk/WebKit/WebKitUtilities.h>
+#include <wtf/MainThread.h>
 #include <wtf/darwin/WeakLinking.h>
 
 namespace WebCore {

Modified: trunk/Tools/ChangeLog (244438 => 244439)


--- trunk/Tools/ChangeLog	2019-04-18 21:57:48 UTC (rev 244438)
+++ trunk/Tools/ChangeLog	2019-04-18 22:07:56 UTC (rev 244439)
@@ -1,3 +1,13 @@
+2019-04-18  Jer Noble  <jer.no...@apple.com>
+
+        Add support for parsing FairPlayStreaming PSSH boxes.
+        https://bugs.webkit.org/show_bug.cgi?id=197064
+
+        Reviewed by Eric Carlson.
+
+        * TestWebKitAPI/Tests/WebCore/ISOBox.cpp:
+        (TestWebKitAPI::TEST):
+
 2019-04-18  Brent Fulgham  <bfulg...@apple.com>
 
         InjectedBundle parameters often need initialization function called before unarchiving

Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/ISOBox.cpp (244438 => 244439)


--- trunk/Tools/TestWebKitAPI/Tests/WebCore/ISOBox.cpp	2019-04-18 21:57:48 UTC (rev 244438)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/ISOBox.cpp	2019-04-18 22:07:56 UTC (rev 244439)
@@ -27,6 +27,7 @@
 
 #include "Test.h"
 #include <_javascript_Core/DataView.h>
+#include <WebCore/ISOFairPlayStreamingPsshBox.h>
 #include <WebCore/ISOProtectionSchemeInfoBox.h>
 #include <WebCore/ISOSchemeInformationBox.h>
 #include <WebCore/ISOSchemeTypeBox.h>
@@ -73,4 +74,39 @@
     ASSERT_EQ(defaultIV, trackEncryptionBox->defaultConstantIV());
 }
 
+static const char* base64EncodedPsshWithAssetId = "AAAAqHBzc2gAAAAAlM6G+wf/T0OtuJPS+paMogAAAIgAAACIZnBzZAAAABBmcHNpAAAAAGNlbmMAAAA4ZnBzawAAABhma3JpAAAAAAAAAAAAAAAAAAAAAQAAABhma2FpAAAAAAAAAAAAAAAAAAAA8QAAADhmcHNrAAAAGGZrcmkAAAAAAAAAAAAAAAAAAAACAAAAGGZrYWkAAAAAAAAAAAAAAAAAAADy";
+
+TEST(ISOBox, ISOFairPlayStreamingPsshBox)
+{
+    Vector<uint8_t> psshArray;
+    ASSERT_TRUE(base64Decode(StringView(base64EncodedPsshWithAssetId), psshArray));
+    ASSERT_EQ(168UL, psshArray.size());
+
+    auto view = JSC::DataView::create(ArrayBuffer::create(psshArray.data(), psshArray.size()), 0, psshArray.size());
+
+    ISOFairPlayStreamingPsshBox psshBox;
+
+    ASSERT_TRUE(psshBox.read(view));
+
+    auto infoBox = psshBox.initDataBox().info();
+    ASSERT_EQ(FourCC('cenc'), infoBox.scheme());
+
+    auto requests = psshBox.initDataBox().requests();
+    ASSERT_EQ(2UL, requests.size());
+
+    Vector<uint8_t, 16> expectedFirstKeyID = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
+    ASSERT_EQ(requests[0].requestInfo().keyID(), expectedFirstKeyID);
+
+    Vector<uint8_t> expectedFirstAssetID = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xF1 };
+    ASSERT_TRUE(requests[0].assetID());
+    ASSERT_EQ(requests[0].assetID().value().data(), expectedFirstAssetID);
+
+    Vector<uint8_t, 16> expectedSecondKeyID = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2 };
+    ASSERT_EQ(requests[1].requestInfo().keyID(), expectedSecondKeyID);
+
+    Vector<uint8_t> expectedSecondAssetID = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xF2 };
+    ASSERT_TRUE(requests[1].assetID());
+    ASSERT_EQ(requests[1].assetID().value().data(), expectedSecondAssetID);
 }
+
+}
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to