Bug 180081 - [EME] Add the CENC initData support in ClearKey CDM
Summary: [EME] Add the CENC initData support in ClearKey CDM
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Media (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks: 180928
  Show dependency treegraph
 
Reported: 2017-11-28 07:06 PST by Yacine Bandou
Modified: 2018-01-09 02:03 PST (History)
7 users (show)

See Also:


Attachments
Patch (7.89 KB, patch)
2017-11-28 07:25 PST, Yacine Bandou
no flags Details | Formatted Diff | Diff
Patch (9.08 KB, patch)
2017-12-18 16:50 PST, Yacine Bandou
no flags Details | Formatted Diff | Diff
Patch (9.10 KB, patch)
2017-12-22 07:20 PST, Yacine Bandou
no flags Details | Formatted Diff | Diff
Patch (9.10 KB, patch)
2018-01-08 10:36 PST, Yacine Bandou
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yacine Bandou 2017-11-28 07:06:51 PST
Add the "cenc" initDataType support in ClearKey CDM.
Parse the CENC initData and extract the KIDs by following the W3C spec https://www.w3.org/TR/eme-initdata-cenc/#common-system
Comment 1 Yacine Bandou 2017-11-28 07:25:26 PST
Created attachment 327751 [details]
Patch
Comment 2 Xabier Rodríguez Calvar 2017-11-29 04:04:14 PST
Comment on attachment 327751 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=327751&action=review

> Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.cpp:50
> +const unsigned ClearKeyCencSystemIdSize = sizeof(ClearKeyCencSystemId) / sizeof(uint8_t);

Is there any architecture where sizeof(uint8_t) is not 1? If you know of any, leave it, if not, please remove.

> Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.cpp:168
> +    Ref<SharedBuffer> keyids = SharedBuffer::create();

keyIds

> Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.cpp:207
> +    unsigned nbKeyId =  data[index + 3];

The variable name should full words.

> Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.cpp:208
> +    index += 4; // KID_count size.

Why KID_count with an underscore?

> Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.cpp:210
> +    // check the overflow.

Check

> Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.cpp:215
> +    auto kidsArray = InspectorArray::create();

keyIdsArray

> Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.cpp:217
> +    // Read the KeyID

Missing period.

> Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.cpp:372
> +    if (!(isKeyids || isCenc))

if (!isKeyids && !isCenc)

> Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.cpp:380
> +    if (isCenc && (initData.isEmpty()))

I wonder if we should actually parse the initData instead of just ensuring it is not empty. I think we should and for that we need to split the extraction function into two because just for consistency you don't need to create the JSON, just just need the information of how many keys are there and where they are located. So I'd write the following functions:

* std::pair<unsigned, unsigned> extractKeyidsLocationFromCencInitData(...) that returns the number of keys and the position in the SharedBuffer data.
* isCencInitData that invokes the first and checks keys are not zero.
* extractKeyidsFromCencInitData that uses the first and continues the algorithm by extracting the keys and creating the JSON.

> Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.cpp:383
>      return true;

I think we should change the logic here, we consider it's a failure by default unless we manage to ensure initDatas check out.
Comment 3 Xabier Rodríguez Calvar 2017-11-29 04:17:59 PST
And again, I forgot to ask the same question. Are there any tests for this?
Comment 4 Michael Catanzaro 2017-11-29 08:01:49 PST
(In reply to Xabier Rodríguez Calvar from comment #2)
> Is there any architecture where sizeof(uint8_t) is not 1? If you know of
> any, leave it, if not, please remove.

Surely not any that can run glib or WebKit.
Comment 5 Yacine Bandou 2017-11-30 02:06:06 PST
(In reply to Xabier Rodríguez Calvar from comment #3)
> And again, I forgot to ask the same question. Are there any tests for this?

I am working to add a ClearKey tests.
I rework the patch as soon as possible.
Comment 6 Yacine Bandou 2017-12-18 16:50:54 PST
Created attachment 329713 [details]
Patch
Comment 7 Xabier Rodríguez Calvar 2017-12-22 04:20:59 PST
Comment on attachment 329713 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=329713&action=review

> Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.cpp:50
> +const uint8_t ClearKeyCencSystemId[] = { 0x10, 0x77, 0xef, 0xec, 0xc0, 0xb2, 0x4d, 0x02, 0xac, 0xe3, 0x3c, 0x1e, 0x52, 0xe2, 0xfb, 0x4b };
> +const unsigned ClearKeyCencSystemIdSize = sizeof(ClearKeyCencSystemId);
> +const unsigned KIDSize = 16;

These things are variables, their names should begin with non-capital. I guess the naming rules would require that KIDSize -> keyIdSize;

> Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.cpp:172
> +    if (initData.isEmpty() ||  initData.size() > std::numeric_limits<unsigned>::max())

There are two spaces before initData.size().

> Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.cpp:185
> +        if (index + 12 +  ClearKeyCencSystemIdSize >= initDataSize)

There are two spaces before ClearKeyCenc...

> Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.cpp:208
> +    keyIdsMap.first = data[index + 3]; // Read the KeyIdsCount

Missing period at the end of the comment.

> Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.cpp:220
> +// This function checks if the initData sharedBuffer is a validate CENC initData.

...is a valid...

> Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.cpp:251
> +        String keyID = WTF::base64URLEncode(&data[index], KIDSize);

keyId
Comment 8 Yacine Bandou 2017-12-22 07:20:12 PST
Created attachment 330125 [details]
Patch
Comment 9 Xabier Rodríguez Calvar 2018-01-08 09:44:58 PST
Comment on attachment 330125 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=330125&action=review

> Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.cpp:172
> +    if (initData.isEmpty() ||  initData.size() > std::numeric_limits<unsigned>::max())

(In reply to Xabier Rodríguez Calvar from comment #7)
> > Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.cpp:172
> > +    if (initData.isEmpty() ||  initData.size() > std::numeric_limits<unsigned>::max())
> 
> There are two spaces before initData.size().

Not addressed.
Comment 10 Yacine Bandou 2018-01-08 10:36:23 PST
Created attachment 330715 [details]
Patch
Comment 11 WebKit Commit Bot 2018-01-09 02:02:50 PST
Comment on attachment 330715 [details]
Patch

Clearing flags on attachment: 330715

Committed r226621: <https://trac.webkit.org/changeset/226621>
Comment 12 WebKit Commit Bot 2018-01-09 02:02:52 PST
All reviewed patches have been landed.  Closing bug.
Comment 13 Radar WebKit Bug Importer 2018-01-09 02:03:28 PST
<rdar://problem/36372226>