Commit Graph

137 Commits

Author SHA1 Message Date
Jacob Trimble 3da809019b Enable additional ES6 linter rules.
Change-Id: I6861541b27153ba034364a5972a9b086de581cef
2019-06-11 18:35:09 +00:00
Joey Parrish 6cb12ad174 Fix stack overflow in tests on IE
In our tests, we can load the library many times.  Each time, the
polyfills get installed, so each polyfill must be able to handle being
installed twice, and avoid any bad behavior.

The InputEvent polyfill, which is used on IE only to get correct UI
behavior on input elements, was only able to handle being installed
twice if each call was on the same copy of the library.  In our tests,
this is not the case.  If we load the library 20 times, we get the
polyfill installed 20 times.

Since it was comparing addEventListener with the polyfilled version,
this check would fail when the library was reloaded.  Each "shaka"
namespace was distinct.  So on 20 hypothetical library loads, each
polyfill would delegate to its predecessor, creating a stack some 40
functions deep.  This would trigger a stack overflow when testing on
IE.

Instead, we can store the original addEventListener in some global
place, such as on HTMLInputElement.prototype.originalAddEventListener.
If that exists, the polyfill (or some version of it) was installed, so
we don't install another.

Found in Jasmine upgrade process (issue #1949)

Change-Id: I714631c9b3ac5c59cf82a5cf7501cb544d1cb5cb
2019-06-05 09:08:37 -07:00
Joey Parrish 0239d04915 Fix IE11 EME polyfill
Two patches in the IE EME polyfill became undefined during the ES6
conversion.  These mistakes were caught by a newer compiler.

setMediaKeys was declared on a different class (MediaKeySystemAccess).
And both setMediaKeys and requestMediaKeySystemAccess needed to be
declared static in order to be referenced from a static install
method.

Issue #1852

Change-Id: Ibbeb57bb3f25e84826ab094681717fdaf1b5a8b7
2019-06-03 18:40:50 +00:00
Theodore Abshire 4816359982 Convert patchedmediakeys polyfills to ES6
Issue #1157

Change-Id: I034cb3b6b947f24f828e221612f46366ec6d660d
2019-05-30 16:57:27 +00:00
Theodore Abshire f584c9aab6 Convert remaining polyfills to ES6.
Issue #1157

Change-Id: Ie330cd870ccf14dc3f56987b2787970b46b1ac89
2019-05-29 23:39:08 +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 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 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 9108431359 Simplify Webkit PiP polyfill
By listening to events on document in the capturing phase, we can
avoid complex event shims on HTMLVideoElement.  By monitoring
global PiP state on the document, we can get rid of the getter and
setter for the document's PiP element, as well.

Follow-up on PR #1902

Change-Id: Ib5f5d0c7c735124a438901c5bb15e034ab10b996
2019-05-07 18:39:24 +00:00
Sandra Lokshina 65768a3d41 Hide fullscreen button on platforms that don't support it.
Safari on iOS does not support HTML5 fullscreen API. There
seems to be a (separate) way for a video element to enter
fullscreen mode. I will see if we can adopt it in a different CL.
For now, just hide the button if fullscreen API is not supported.

Issue #1909
Issue b/131923216
Change-Id: Ia30660c7a68fd626051fdf5abce59dbe993b2de2
2019-05-06 22:25:41 +00:00
Joey Parrish e3b49573a2 Rename PiP polyfill to PiPWebkit
Follow-up to #1902

Change-Id: I760d0006c4cbd7c3aad2ce96801259b578269195
2019-05-03 21:30:17 +00:00
Álvaro Velad Galván caa34ca90d Add PiP pollyfill for Safari (#1902) 2019-05-03 10:50:37 -07:00
Joey Parrish 9a4b73df7c Fix runtime errors in the new demo on IE 11
- Polyfill navigator.languages, which is missing on IE
 - Add missing handler for uncaught exceptions (doesn't work on IE,
   but is a good idea to have for debugging the demo app)
 - Avoid offline setup if it's not supported (as on IE)
 - Fix bad reference to uncompiled link (wrong ID)
 - Log any caught errors to the console
 - Wrap the init functions to catch and log any errors during init

Fixes b/131863587
Fixes #1911 (similar storage error on iOS)

Change-Id: Ib2a53392d5632c71825af17dd3e955cd54279e98
2019-05-03 17:26:44 +00:00
Joey Parrish 1d4efe6f35 Prefer prefixed EME on Apple devices
The unprefixed EME launched with macOS 10.14 (Mojave) rejects requests
for the key system IDs we know how to use.  So until the bug we filed
against Apple is resolved, prefer the prefixed API.

Issue #382

Change-Id: I71313be2102af2da66a6389a9e9afdebd8ae033d
2019-04-30 21:15:11 +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
Joey Parrish 133f161b93 Support all types of single-file playback
Instead of triggering src= based on 'video/mp4' MIME types, ask the
browser what it can support using video.canPlayType().

Querying canPlayType() also allows us to detect src= support for
native HLS in Safari.

The original version of this change also added a complete fallback
system to detect MIME types based on common file extensions and
fetch MIME types via HEAD request when necessary, but the load graph
system does not yet allow us to make async decisions about destination
node.  So this async MIME detection is commented out for now.

Closes #816 (src= single file playback)
Issue #997 (native HLS in Safari)

Change-Id: If1930ca4fd5710481a925d63fb312d9a5b15fec8
2019-04-16 22:59:18 +00:00
Aaron Vaage 040ecf6978 Create src= node
This CL creates the "loaded with src=" node and its initial
implementation. Adding this node required some changed to the routing
logic as a new destination was created.

We will use src= when given mp4 content or media source is unavailable.
We detect mp4 content via the mimeType in |load| and/or the file
extension. When media source is not available on a platform, we fall
back to using src=. To do this, we check if media source is available
whenever |load| is called, and will route to the src= branch if media
source is not found.

To avoid pre-initializing media source (when it is not available) we
modify the |initializeMediaSource| flag in |attach| and |unload| when
media source is not available.

Doing this showed that we had inconsistent behaviour between |attach|
and |unload|. |attach| would default to initializing media source
whereas |unload| would not. This has been fixed.

Issue #816
Issue #997

Change-Id: I00599832b49c9079e273e65a4b827fee736479cc
2019-04-01 22:56:39 +00:00
Bart Teeuwisse 7660edc995 Dolby Vision fixes for Chromecast (#1844)
- Fix the link to Dolby's Dolby Vision Profiles and levels PDF
  - Was pointing to a document version that no longer exists
- Update Dolby Vision regex to match all DV codecs
  - Dolby Vision is available in 4 different (base) codecs: dvhe, dvh1, dvav, dva1
  - dvh* represents HEVC-based Dolby Vision
  - dva* represents AVC-based Dolby Vision.
- Do not remove Dolby Vision codecs on Chromecast

No need to remove Dolby Vision codecs on Chromecast. Chromecast's canDisplayType will reject them when the cast receiver or the attached display can't play Dolby Vision.

On Dolby Vision capable cast receivers attached to a TV in Dolby Vision mode, canDisplayType does not reject Dolby Vision streams. One such device is the Chromecast Ultra. With this change, Shaka Player plays Dolby Vision on qualifying setups.
2019-03-18 15:43:37 +05:30
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 1506182de9 Reject opus content on Tizen
Tizen Smart TVs do not play opus content well when using MSE. To prevent
Shaka Player from trying to play opus content on Tizen, we override
media source's isTypeSupported to reject opus content.

Since most content will have AAC as a fallback, this should not limit
playback on Tizen.

Issue #1751

Change-Id: Ia61a1d26f547082fa68a9f38e4af16951191dd4f
2019-02-12 20:54:57 +00:00
Joey Parrish 2872f31e01 Add polyfills for Safari 12
Now that we have Safari 12 in the lab, we have found that it requires
the same MediaSource polyfills as Safari 11.

Fixes b/120434307

Change-Id: I45f8be79d0aca7987ffcba1ce13b8589a2287712
2018-12-12 10:47:39 -08:00
Aaron Vaage 4167b1658b Isolate Platform Checks
To make it easier to know where we are check what platform something is
(normally a sign of a work-around), this change isolates the logic to
make the check into functions.

Now looking for uses of |shaka.util.Platform| should show when we are
using platform-specific logic.

Change-Id: Ief49837c503e951f7138ec08a83355fe1c46db88
2018-12-11 05:43:52 +00:00
Jacob Trimble 3db435e87d Fix some issues with IE11 EME polyfill.
- We can get a 'msneedkey' event with no init data.
- Use the correct message type name.

Issue #1689

Change-Id: Ic0e54fe8331d4700971d78095b77831de2d9580b
2018-11-30 22:43:00 +00:00
Aaron Vaage f8b707aaeb Use Sets For Uniqueness
Update all our code to use |Set| to handle storing and testing
unique values.

Change-Id: Id809d4d84e4779ae19be58eca96983750c3f3a81
2018-09-14 22:03:04 +00:00
Joey Parrish 7091275cbf Replace indexOf with includes, startsWith
This replaces almost every instance of indexOf on both String and
Array.  There are very few places where we really wanted an index.
Mostly, indexOf was used to check for inclusion.

Change-Id: I08e299768b6ffdb4bfc30b39b5d82a058c6d1b56
2018-09-14 19:10:56 +00:00
Joey Parrish fd0449d8f7 Re-enable some disabled style rules
This re-enables the following style rules:
  - "block-spacing"
  - "brace-style"
  - "comma-dangle"
  - "comma-spacing"
  - "new-cap"
  - "no-multi-spaces"
  - "no-multiple-empty-lines"
  - "one-var"
  - "padded-blocks"
  - "prefer-rest-params"

Change-Id: I15d616e8d5b88b273ded6128b4f9ad86bdb26bd1
2018-07-09 19:44:56 +00:00
Jacob Trimble 759eef9685 Change goo.gl links to bit.ly.
https://goo.gl is being turned-down, so we can't use it for new URLS.
So we have consistent short links, this converts them to be
https://bit.ly.

Change-Id: I07a86cba807b67157664893341f648023918d0de
2018-06-22 20:20:00 +00:00
Michelle Zhuo 535de4db84 Refactor: Remove underscore from parameter names
Change-Id: Ie9e6fb59763f454f245175f23c6444f919ba8135
2018-05-08 19:21:51 +00:00
Theodore Abshire 7c5186332b Typo fixes and rewording in comments, part 7
This makes a large number of small typo fixes. It also rewords a
number of comments and JSDoc descriptions, and does some
formatting standardization.

This doesn't fix every single issue, but it fixes a lot. Notably,
there were some formatting issues I declined to standardize due to
ambivalence on what the proper standardization would be; for example,
when and where empty lines should show up in JSDoc.

Change-Id: I225f5c7e54adf4cca8512cddae082ba50ed82e4e
2018-03-21 19:45:15 +00:00
Theodore Abshire d46e8fdf92 Typo fixes and rewording in comments, part 6
This makes a large number of small typo fixes. It also rewords a
number of comments and JSDoc descriptions, and does some
formatting standardization.

This doesn't fix every single issue, but it fixes a lot. Notably,
there were some formatting issues I declined to standardize due to
ambivalence on what the proper standardization would be; for example,
when and where empty lines should show up in JSDoc.

Change-Id: I2bfa4d531a8fcdcf9578e9c181c4534ad7443b7a
2018-03-21 17:59:42 +00:00
Theodore Abshire f58afd21da Typo fixes and rewording in comments, part 5
This makes a large number of small typo fixes. It also rewords a
number of comments and JSDoc descriptions, and does some
formatting standardization.

This doesn't fix every single issue, but it fixes a lot. Notably,
there were some formatting issues I declined to standardize due to
ambivalence on what the proper standardization would be; for example,
when and where empty lines should show up in JSDoc.

Change-Id: Ibcaf21382bd78b91e589122983dd14e001bfdad5
2018-03-21 17:25:13 +00:00
Jacob Trimble bfb42c69c4 Make EME polyfills independent.
Now each EME polyfill can be removed independently; this allows
someone to remove just the IE11 polyfill while still keeping the
others.

This adds a priority ordering to the polyfills so the nop polyfill
will be run last as a fallback if there are no other polyfills.

Issue #1261

Change-Id: I865e1c0d6a73a079dd91505e96572e215e6f6c6a
2018-03-06 21:34:25 +00:00
Jacob Trimble b512db87dd Convert 'var' to 'let'/'const' (8 of 9).
This is part of a change to convert all usages of 'var' with either
'let' or 'const'.  This takes a conservative approach for 'const' where
it will only be used for aliases and storing the "original" values in
tests.

Change-Id: I6a329d28e13a81c9f7136737518c6bb8fa18402e
2018-02-20 11:29:30 -08:00
Joey Parrish 82357486a6 Replace buggy Promise polyfill
A bug in our Promise polyfill caused issues with the recently-added
AbortableOperation class on IE11.  Since external polyfills for this
are smaller, it is easier to remove ours in favor of a third-party
polyfill.  Applications that wish to support IE11 must now load this
additional polyfill.

We are using the "es6-promise-polyfill" module from npm, but any
compliant polyfill should suffice.

One feature our own polyfill offered was the ability to flush all
Promises, which allowed us to write synchronous unit tests that
simulated async processes.  To get this ability back, we are now
using the "promise-mock" module in our tests.

Getting "promise-mock" to load correctly involved switching from
"requirejs" to "cajon", which builds on requirejs and supports
AMD modules more directly.

Closes #1260

Change-Id: I5de48e88a910736ae5c1897a7a509bc5641acb70
2018-01-30 23:10:04 +00:00
Joey Parrish a63352c8f3 [ES6] Enable stricter checks in eslint
This digests and organizes many of the automatic settings in eslint,
and changes several of them to be more strict.  This also fixes the
following errors:
  - array-callback-return
  - no-catch-shadow
  - no-multi-spaces
  - no-new
  - no-throw-literal
  - no-useless-call
  - no-useless-concat
  - no-useless-return

Several checks have been organized into a group of checks we should
use, but need more time to implement and fix.  Some other checks have
been delegated to the Closure compiler, which can more precisely
whitelist exceptions.

Issue #1157

Change-Id: I8fe4966959e08050f8159e6a1fee161e7d71177e
2018-01-17 21:56:41 +00:00
Joey Parrish 4067c20a7c [ES6] Replace gjslint with compiler linter & eslint
The eslint configuration is derived from analyzing the style of our
sources as they are now, plus a few tweaks.

In particular, we have disabled checks for undefined variables and use
of console, both of which the compiler handle with greater precision.
The compiler already knows what is defined in the environment through
our externs, and has specific exceptions for the use of console (demo,
tests).

We have also disabled a few checks that we should use, but will
require many changes to the code: no-unused-vars, no-redeclare,
and comma-dangle.

This commit also fixes several types of eslint errors that were easy:
  - no-useless-escape (unneccessary escape characters in Regexp)
  - no-constant-condition (using true/false/0/1/etc in if/while)
  - no-fallthrough (caught an actual bug in one EME polyfill)
  - no-irregular-whitespace (we had a UTF-8 nbsp in externs)
  - no-cond-assign (using an assignment inside a conditional)

To satisfy stricter provide/require checks in the Closure Compiler
Linter, we will no longer use provide/require at all in tests.  We
will still use provide in test utilities (test/test/util/) since it
sets up the namespace for us.  But we will not use require there
because there is no deps management for test code.

Issue #1157

Change-Id: Icc44f51feeb568ea7d3980e693e92e560d897afd
2018-01-16 17:25:05 +00:00
Joey Parrish 1a2c88745e Upgrade the Closure compiler to v20171203
Change-Id: Id0dd4619db0c3a141d60e9e38757739e0697e6f0
2018-01-03 15:07:02 -08:00
Joey Parrish e2aef50912 Disallow unknown "this"
This change enables an additional conformance check in the compiler
which prevents us from committing code where the compiler fails to
infer what "this" means.

None of these changes constituted actual bugs, just inference failures
in the compiler.

Issue #1130

Change-Id: If9b18203768e197258042a9b4339530f371ed831
2017-11-15 11:35:56 -08:00
Theodore Abshire c6ddf593e5 Polyfill Safari 11 MSE bug in SourceBuffer.remove
SourceBuffer.remove, when told to remove exactly up to a keyframe,
will also remove that keyframe and all of the content till the next
keyframe. This results in far too much content being deleted, and is
breaking our tests on Safari 11.

Patching this by offseting the end of the removal range by 1ms seems
to be a viable workaround.

Closes #1048

Change-Id: I062b2dc2617f1372f885f4ccbc906d77c65412d7
2017-10-05 13:15:25 -07:00
Joey Parrish 859d7d1a8f Reject TS content in Safari
Because Safari's support for TS via MSE is broken, reject all TS
content in Safari.  Transmuxing (#887) will compensate.

https://bugs.webkit.org/show_bug.cgi?id=165342

Closes #743

Change-Id: Iff8a6a7c159e48a4f388d99396915752e649c6ac
2017-10-03 15:31:10 -07:00
Joey Parrish 87b723473b Apply MSE patches to Safari 11
One of the Safari 10 bugs we work around is still present in Safari 11.

Issue #1048

Change-Id: I54e146bcce9770f980a0dabd477a86b482a6c901
2017-10-03 15:31:09 -07:00
Joey Parrish b7b890b908 Add a polyfill for Chromecast isTypeSupported
There are several issues with isTypeSupported on Chromecast that
require workarounds in JavaScript:
  - Dolby Vision strings must be removed from the codecs parameter,
    even though the content is supported by the platform
  - HDR must be guessed at from the codecs parameter and an additional
    parameter must be added to query HDR support
  - Queries must be made through a non-standard interface

Change-Id: I4c8c70e70cf9c26283913783f5f62f7d6470c2f1
2017-08-17 17:35:00 +00:00
Jacob Trimble b974a1d12d Fix field renaming in Safari polyfill.
Closes #974

Change-Id: I407f7d0437383e05c42c0762bad42337bd558f8c
2017-08-15 17:21:38 -07:00
Joey Parrish d1df5dade6 Make it safe to install polyfills twice
Closes #941

Change-Id: I706aadd1bfc2c477d0ac8a0dff13defad74b3bda
2017-07-24 12:25:46 -07:00
Joey Parrish 84a8d1ca18 Polyfill the HTML5 'input' event
The HTML5 'input' event does not work correctly on all input elements
in IE 11.  There are equivalent events that the UI can use on IE.

Instead of remembering this and checking for IE every time the 'input'
event is needed, let the polyfill translate the event type.

Change-Id: I23258a5c6a0bd37e946214380ad07949f3ee7f88
2017-07-12 12:29:14 -07:00
Joey Parrish c69a009960 Do not assume persistent storage support
Two EME polyfills currently assume persistent storage support: one
for old Tizen TVs and other older embedded Chromium devices, and one
for IE11.

This backfires when an application is trying to detect support for
encrypted offline content.

By removing this assumption, we do not convey support for EME features
that are not known to be available on these devices.

Change-Id: If427eeda1cde60341a2b57f76744c2adfdb34beb
2017-07-12 18:46:08 +00:00
Jacob Trimble adb8da4764 Disallow unknown properties (1/5).
This is part of adding a new conformance rule to add additional type
safety.  This will disallow using properties of unknown types or using
unknown properties.

The first parts will be fixing errors caused by the new rule.  These
are backwards compatible, so can be applied before the rule is enabled.
Once all the errors and bugs are fixed, the rule will be enabled.

Change-Id: Iefde089b2f62ddfdf43944cda5badab438577561
2017-06-27 19:43:00 +00:00