Commit Graph

193 Commits

Author SHA1 Message Date
Joey Parrish f539147d48 fix: Correct license headers in compiled output
This fixes all the license headers in the main library, which corrects
the appearance of the main license in the compiled output.

It seems that the `!` in the header forces the compiler to keep it in
the output.  I believe older compiler releases did this purely based
on `@license`.

Issue #2638

Change-Id: I7f0e918caad10c9af689c9d07672b7fe9be7b2f3
2020-06-09 16:05:09 -07:00
Oren Me 7e1bb94ef6 Fix PlayReady key ID endianness for TiVo (#2582)
For Tivo Box with Opera browser and Opera Devices SDK inbuilt (Virgin Media STB in UK)
2020-05-20 21:04:00 -07:00
Álvaro Velad Galván 8648a3e0fc Add option to customize the polling of expiration time (#2579)
A large value effectively disables use of the expiration time

Closes #2252
2020-05-20 14:58:35 -07:00
Joey Parrish 4dc2c65578 Add type assertions for Errors
In many places, we check error codes on shaka.util.Error.  But the
compiler doesn't know that what is caught in "catch" is that type, so
we add type assertions.

In some cases, we know that other types may also be thrown, so there
are also some runtime checks.  Some of these had to be refactored to
allow the compiler to correctly infer types.

Change-Id: I053bd7e96213c689aae3889315052dd402124690
2020-04-29 10:11:21 -07:00
Joey Parrish 8d25186072 Don't use dot notation for bogus properties
DrmEngine is adding an extra property to MediaKeySystemConfiguration
objects, knowing that EME will ignore it.  The latest Closure Compiler
won't allow this.

In the future, we should refactor DrmEngine and consider tracking this
in some other way.  For now, this changes the dot to square brackets.

Issue #2528

Change-Id: I544c93dfa2534e9d62ac5ea47e20a6dc3cb79e3a
2020-04-28 21:40:25 +00:00
Dong-heun ebae1158cf Fix error 4012 RESTRICTIONS_CANNOT_BE_MET for webOS TV platform (#2513)
For webOS TV 2020 platform, like for Tizen, key IDs should not be
transformed to big-endian UUIDs, it causes `4012
RESTRICTIONS_CANNOT_BE_MET` error.

Closes #2512
2020-04-24 14:16:54 -07:00
Joey Parrish 6e3dfa40ba Deduplicate key IDs with Set
When period-flattening combines Streams, key ID arrays would get very
long with duplicates.

This changes keyIds in the manifest and offline structures from Array
to Set.

Issue #1339

Change-Id: I003d23e567efafa771ecd2ad597900181604ad18
2020-04-09 19:22:16 +00:00
Joey Parrish e8ac57f36c Move drmInfos array to Stream
Period-flattening will concatenate Stream objects, so this information
should be available per-Stream instead of at the Variant level.

Issue #1339

Change-Id: I96195fea48cab1e4a349b2ab0b16064a443e928a
2020-04-09 19:22:16 +00:00
Jacob Trimble 7ae6fc7d93 Fix FairPlay encrypted event handling.
The 'webkitkeyneeded' and 'encrypted' events send similar data, but
they were incompatible with each other and our transform handling.
This makes our polyfill produce the same format as the browser for
cases where the browser may only fire the old event.  This also makes
our utilities work with the new format.

The 'webkitkeyneeded' event was a length-prefixed UTF-16 string while
the 'encrypted' event was just a UTF-8 string.

This also makes a breaking change in the transform callback to pass the
init data type.  This shouldn't break anyone that only uses the first
argument; the second argument was mainly added so we could have the
default transform work without knowing anything.

This change could also break people who use custom transform functions.
The init data format is changing, which could break people who read
it directly.  If they follow the tutorial and use our utilities, it
shouldn't break.  This also updates the tutorial to match the new format
and be more clear about the format.

Fixes #2214

Change-Id: I006382028e828e31e20e085114fd7fd85c0e1eaa
2020-04-07 16:59:27 +00:00
Jacob Trimble 5f81429aef Don't allow querySelector.
querySelector isn't available in Shaka Player Embedded.  Since we only
use it to find nodes with a specific tag name, we can usually use
getElementsByTagName.

Issue google/shaka-player-embedded#113

Change-Id: Ia225e5d1f7598b13bd05db868fe2ea566dca4493
2020-03-26 16:37:26 +00:00
Peter Nycander 9b08525efe Tizen2.4 bugfixes (#2449)
`'webkitneedkey'` events are fired with the same `event.initData` for the video and audio tracks, and a new session is needed for each.

Closes #813 (duplicate sessions required on Tizen)
Closes #2447 (polyfills broken on Tizen)
Closes #2448 (PlayReady broken on Tizen)
2020-03-13 10:24:41 -07:00
Theodore Abshire ea0131dc80 Remove aliases for BufferUtils in DrmEngine.
That alias was confusing the closure compiler, and causing it to
produce invalid output when making release versions.

Closes #2438

Change-Id: Ic232ce4f29222543b13c2cc725ffefaedea29e3a
2020-03-04 16:31:18 -08:00
Jacob Trimble f7be614c42 Add option to log license exchange.
It is common when debugging protected content to want to see the
license request/response data.  This adds a configuration to easily log
the license request/response data so we can see this without modifying
the code or adding breakpoints.

Change-Id: Ib5db3eaa1447ae8714da935ee459fc7f9ba1e937
2020-02-07 22:22:11 +00:00
LanaIV 3dab79e49c Fix error 4012 RESTRICTIONS_CANNOT_BE_MET for Video Futur platform (#2368)
For Video Futur platform, like for Tizen, key IDs should not be
transformed to big-endian UUIDs, it causes `4012
RESTRICTIONS_CANNOT_BE_MET` error.

Issue #2189
2020-02-05 08:18:13 -08:00
Jacob Trimble 011749e95f Standardize argument comments.
This changes the eslint rule to enforce a strict pattern for the
argument comments.  The comment must appear before the argument and
must be /* foo= */.  This still ignores line comments.

Change-Id: I3afb01c65e1088eda13facb3aeeaa7595a2f5aee
2020-01-06 19:40:52 +00:00
Álvaro Velad Galván cdbf8c5fbc Add licenseTime to stats (#2297)
This gives the cumulative time spent fetching licenses.
2020-01-06 11:11:28 -08:00
Álvaro Velad Galván 3e0bb2bb67 AirPlay support HLS with FairPlay (#2257)
Closes #2177
2020-01-03 12:20:13 -08:00
Joey Parrish 52aa032f18 Fix compiler error with upcoming compiler release
An upcoming release of the compiler gets confused about robustness
fields being potentially undefined.  Adding a fallback to a blank
string satisfies the compiler.

Change-Id: I794b49002c86dde7236a09061c8ed2390ae26136
2019-12-19 09:29:17 -08:00
Joey Parrish 64896d70b0 Use shorter license header
This reflects changes in Google's policy on JavaScript license
headers, which should be smaller to avoid increasing the size of the
binary unnecessarily.

This also updates the company name from "Google, Inc" to "Google LLC".

Change-Id: I3f8b9ed3700b6351f43173d50c94d35c333e82b4
2019-11-22 18:18:36 +00:00
Jacob Trimble 67941d7ae9 Update comments in persistent-license tests.
Most of the persistent-license bugs on Chrome have been fixed, so this
updates the comments to point to the only remaining issue.  The tests
have also been updated to pass (except for the flaky failure caused by
the remaining bug).  The tests are still quarantined since they are
fairly flaky, even with a large delay.

This also adds some more logging to DrmEngine, makes it use the
"session.closed" property when closing, and removes the close
workaround for Chrome since it has been fixed.

Change-Id: I2dbd0b7005e288ae2a4d9694516daae6f5e0b49a
2019-10-31 17:07:23 +00:00
Theodore Abshire 8004e47c46 Ignore delayLicenseRequestUntilPlayed for storage.
When storing assets offline with the storage system, the DRM
engine is used if the asset is protected. However, we never attach
the DRM engine, which means it never gets an associated video.
When the delayLicenseRequestUntilPlayed config value is set, the
DRM engine checks the paused status of the video; thus, if there is no
video element, the DRM engine errors and the download fails.
It would be fairly simple to make the DRM engine attach the video, but
honestly, the delayLicenseRequestUntilPlayed parameter doesn't make
sense for offline storage anyway. So this just changes the DRM engine
to ignore delayLicenseRequestUntilPlayed if it has no video.

Fixes #2218

Change-Id: If4e8d24fdcd1eca81cc39b845e5a833a3f1ce5e6
2019-10-28 16:02:02 -07:00
michellezhuo d520324f57 [Fix] Check initDataTransform with default implementation
Closes #2136

Change-Id: I6c98ceb48d21a26b2a1c4bc7516ee9d7279728bf
2019-10-10 14:27:24 -07:00
Joey Parrish 9e3745f953 Fix suppression of ClearKey errors with src=
Because src= content lacks codec information, ClearKey setup fails.
However, because there was no DrmInfo prior to the ClearKey settings
being applied, the variable hadDrmInfo was false, which led to a
suppression of the resulting DRM error.

Instead, we should count ClearKey settings toward hadDrmInfo.  So now,
ClearKey settings are applied before we calculate hadDrmInfo.

Closes #2139

Change-Id: I14d5bfe63fd2ce1a461ae7ef8c2fee7f42bb1b3e
2019-09-12 10:40:19 -07:00
Jacob Trimble 454ff49006 Add a type to lazily generate a value.
Change-Id: Ibcd5bc76953f1c0c153dd5845d1b095dac0bb358
2019-08-21 22:02:06 +00:00
Jacob Trimble 887f2e614d Make Uint8ArrayUtils accept BufferSource.
Change-Id: Ia22b4535f4a6cbc156022299d732b27602c677d3
2019-08-21 20:41:45 +00:00
Jacob Trimble 18b59c5294 Disallow using new Uint8Array with BufferSource.
Using "new Uint8Array" with a TypedArray creates a copy of the buffer;
this is unnecessarily expensive for large buffers.  This adds a rule
to disallow using it in favor of a new utility that correctly creates
a new "view" on the same buffer.

Note it is fine to pass an ArrayBuffer to "new Uint8Array" and it won't
copy; but there there are many cases where the type is BufferSource,
so it could be a TypedArray.  Unfortunately, there are many other cases
where we explicitly pass an ArrayBuffer; but the compiler rules don't
allow us to whitelist this case (since ArrayBuffer is part of
BufferSource).

Change-Id: I58696a85a9cbcc188c0b16919c9eeb63e56edca1
2019-08-21 20:40:59 +00:00
Jacob Trimble a2bcf7278d Move some utilities to BufferUtils.
Change-Id: Ifb3c4348cc912640b99ff53f7cac59a63480c68e
2019-08-20 22:07:35 +00:00
Jacob Trimble 596c80a949 Refactor handling of ArrayBuffer.
This changes the network API to use BufferSource instead of ArrayBuffer,
which allows plugins to return a "view" on a buffer instead of the
whole buffer.  This also adds some utilities for changing between
views and buffers.

Lastly this forbids the use of the "buffer" property of TypedArrays
since it doesn't work with partial "views".  This audits and fixes the
usages of the "buffer" property to ensure correct usage.

It should be noted that both MSE and EME accept a BufferSource as input,
so we don't need to convert a "view" into an ArrayBuffer before passing
to it.

Change-Id: Iaa417773f8ce5304424e43c7372ce10ebf540d2a
2019-08-20 20:17:33 +00:00
Jacob Trimble c5b9d6804f Allow custom content ID in FairPlay.
Now there is a generic callback to transform the init data before
passing it to the browser.  This can be used by apps to use a custom
content ID in FairPlay content.  This also adds some utilities to help
in writing these functions and moves the default behavior to DrmEngine.

Closes #1951

Change-Id: I78ce660c126b53a69d5f55b16775ffcdbbe4d748
2019-08-07 18:38:40 +00:00
Jacob Trimble e990da0179 Remove FairPlay formatting.
Now any formatting must be done by the app the same as other key
systems.

Issue #1951

Change-Id: Ifeaa0abdfda462cd457d19f6dce93c5af3a5fdad
2019-08-05 16:52:39 +00:00
Jacob Trimble b12075093e Add sessionId field to network request.
This allows a request/response filter to determine which EME session
made the request.  This also changes the session ID of FairPlay sessions
so they are available too.

Issue #1951

Change-Id: I1a07abae6faf4a87fad7b5d4290a00b25e83da8e
2019-08-05 16:52:11 +00:00
Jacob Trimble 5c580e243e Throw an error when FairPlay cert not set.
Fixes #1940

Change-Id: If911986eb70838b1aa81fc85f088c8367f7e1b48
2019-07-29 21:02:21 +00:00
Jacob Trimble f6d0f15fa6 Refactor handling of destroy().
This changes several classes to use the Destroyer class to handle
destroy().  This also changes the behavior to not ignore destruction
and instead throw a new error.  This is more clear for callers and
ensures we propagate errors.

Change-Id: I756c085639558509c22e5c43d69ddf4acd28d46f
2019-06-19 20:39:20 +00:00
Jacob Trimble e2fa4626b5 Decrease time it takes to run tests.
- Reduce times for "short delays".
- Remove backoff delay from networking tests.
- Avoid hard-coding delays in the library.
- Move Storage tests to integration tests since they use indexedDB (and
  take over 200ms each to run).

This reduces the time it takes to run unit tests (with --quick) from
50 seconds to about 6 seconds.  Now all but one unit test finish <100ms.

Change-Id: I88461472a87c4cf750a36d07d07422818e069a4d
2019-06-12 20:53:08 +00:00
Jacob Trimble 3da809019b Enable additional ES6 linter rules.
Change-Id: I6861541b27153ba034364a5972a9b086de581cef
2019-06-11 18:35:09 +00:00
Theodore Abshire 1836b1693e Convert DRM engine to ES6
Issue #1157

Change-Id: I06994fa294401a008c1c2097683c3621eed438cf
2019-06-04 23:41:52 +00:00
Jacob Trimble d5780d401b Fix line length issues for indent fix.
Change-Id: I87d75fd88000f8f9bff7b9f1bf5667ba28f6dd60
2019-05-13 22:31:20 +00:00
Jacob Trimble f130dffcef Enable eslint indentation rule.
This is a fully automated change.  The linter will fail because the
extra indentation caused line-length errors.  These won't be fixed
automatically.  They are fixed in a follow-up to make this one fully
automated.

Change-Id: I4d8cf9c998985add2bcd24a81c8d65495668c4f3
2019-05-13 22:31:09 +00:00
Jacob Trimble 0dd64074b9 Only allow one statement per line.
With the new style rule, we cannot have two statements on the same line.
So we can no longer have an "if" on a single line and we cannot have
an arrow function with a body on the same line as when it is used.
This is mostly a manual change.

Change-Id: I2285202dd5ecbad764308bc725e6d317ff2ee7f0
2019-05-13 22:11:50 +00:00
Jacob Trimble 381274fbbd Enforce a consistent dot location.
Change-Id: Ic3b86c4c113023206bc37a117e96f672f351121b
2019-05-09 21:09:30 +00:00
Jacob Trimble ded2b84313 Require consistent return values.
This enables the eslint rule that requires all functions to consistently
either return a value or not return a value.

Change-Id: I98b579f3689c3b6c74968116824231bb792bd9dd
2019-05-09 20:34:47 +00:00
bcupac b8f032a05e Use standard base64 encoding in FairPlay license request (#1932)
Closes #1915
2019-05-09 09:55:38 -07:00
Jacob Trimble 47daf49f31 Use arrow functions for callbacks.
This is an automated change to convert use of "function" functions
to arrow functions.  This doesn't change all uses of bind() that
could be converted.  This also doesn't remove all "function" functions.

Change-Id: I40ac7d086bcef947a1be083359c8fd1d4499a9c3
2019-05-09 16:40:46 +00:00
Jacob Trimble cea3161ce9 Misc fixes for arrow functions.
A follow-up commit will convert "function" functions to arrow functions.
This caused some errors with the compiler, which this change fixes
beforehand.

Change-Id: Iff85b1e1f56b63a38b09f8db9947ed5daf02ddf4
2019-05-08 20:43:20 +00:00
Jacob Trimble c81389741f Prefer const over let.
A coming update to the Google eslint config will require using "const"
over "let".  This makes that one change to isolate the big changes.

Change-Id: I7d0974c3ae15c53cc45a6b07bf9f6586e2d34aca
2019-05-08 09:22:10 -07:00
Joey Parrish d27d8180e0 Only use configured license servers if provided
If the application developer specifies license servers, only those
should be used.  Before this, a manifest-specified license server
for a certain key system could still be used if the application didn't
provide one.

Now, if there are _any_ license servers specified by the app, _no_
license servers will be used from the manifest.  This is important
because it allows the application a clear way to indicate which DRM
systems should be used on platforms with multiple DRM systems.

The new order of preference for drmInfo:
1. Clear Key config, used for debugging, should override everything else.
   (The application can still specify a clearkey license server.)
2. Application-configured servers, if any are present, should override
   anything from the manifest.  Nuance: if key system A is in the manifest
   and key system B is in the player config, only B will be used, not A.
3. Manifest-provided license servers are only used if nothing else is
   specified.

Introduced in #1644 to solve #484
Internal issue b/131264101
Closes #1905

Change-Id: I1a36a70044dc7bcc22681e3e4246d0a43d58e413
2019-05-02 20:30:54 +00:00
Joey Parrish a121733a11 Add FairPlay EME polyfill and DrmEngine support
This adds a polyfill for Apple's prefixed EME implementation.  This
will be used on all macOS versions prior to 10.14 (Mojave) and on
Safari versions prior to 12.1.

This also adds support for FairPlay license protocol eccentricities
in DrmEngine, so that the proper formatting is used for requests and
responses.

Issue #382

Change-Id: If1274d2f018a475f56c09df97645694f13acbde9
2019-04-30 21:15:11 +00:00
Aaron Vaage 71fb7a03ec Use Timer/DelayedTick instead of setTimeout
This CL limits the use of |setTimeout| by wrapping it in our own timer
class. The timer class makes it easier to track and cancel time-based
events.

To ensure that|setTimeout| is not used outside of our timer classes, the
conformance rules have been updated to only allow |setTimeout| to be
used by our timer classes.

Since |setTimeout| is very similar to |setInterval|, the conformance
rules for |setInternal| rules were updates to reflect more of the logic
behind why we don't want to use |setTimeout| and |setInterval| directly.

Change-Id: Iff5da32a61b515dd2016837fa74a34c04b6c5fd2
2019-03-12 18:52:32 +00:00
Aaron Vaage 7a56dd1bdc Prevent late-timer-invokes
In our tests, it was possible for a timeout to fire after |clearTimeout|
was called. This CL makes sure that cannot happen by adding an "alive"
flag to each timeout.

To ensure that the change was as well defined as possible, this CL
changes how |shaka.util.Timer| is implemented and updates the API to
better communicate what is happening internally.

Change-Id: I57e3899046a762bff3293b9822a7e8f7ac804042
2019-03-12 18:52:32 +00:00
Aaron Vaage 43afe3a7c8 Refactor Event Manager To "Release" and not "Destroy"
We often use the IDestroyable interface to provide us with a standardized
way to break internal references and tear-down objects, however many
objects don't need this to be async. Once using IDestroyable, everyone
must assume that you must be async.

This change introduces IReleasable, a sibling to IDestryable, which
provides the |release| method. IReleasable is the synchronous version of
IDestroyable.

This change converts EventManager from IDestroyable to IReleasable as
the first of many conversions.

Change-Id: Ic3e90e594abc1c7326eccbe2521eb71676b74a09
2019-01-24 01:11:38 +00:00