Commit Graph

43 Commits

Author SHA1 Message Date
Álvaro Velad Galván 57c73241a0 fix(performance): Eliminate use of ES6 generators (#4092)
See: https://github.com/shaka-project/shaka-player/issues/4062#issuecomment-1077826210

Co-authored-by: @joeyparrish

Issue #4062
2022-04-04 10:58:16 -07:00
Álvaro Velad Galván 298b60481d fix(dash): Fix performance regression (#4064)
See: https://github.com/shaka-project/shaka-player/issues/4062#issuecomment-1077826210
2022-03-25 13:56:38 -07:00
Theodore Abshire a72a1e9102 feat(text): Switch to using TextDecoder for UTF8
Previously, to decode UTF8 content, we used the browser's
decodeUriComponent method.  This worked in most situations, but it
would stop and error the moment it found an invalid UTF8 character.
This meant that a single poorly-encoded character inside a text stream
would cause the entire closed captions to fail to display.
In this CL, we switch to using the newer TextDecoder API, which
will instead replace invalid characters with an "unknown character"
code point, and continue parsing. This should make our text parsers
more robust when faced with bad encoding.

Closes #2816

Change-Id: Ibf2887e143d24d15a127bbcf2961539669580eea
2020-09-09 13:49:28 -07:00
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
Theodore Abshire daa316643a Fix compiled release version of supportsChunkSize.
In the code for supportsChunkSize, we test to see if a given chunk
size is supported by array to string conversion by trying to perform an
operation on a Uint8Array of that size without throwing an error.
However, the result of that operation was only ever referenced inside an
assert. Because asserts are compiled out in release builds, the
result of that operation was not being used... and thus, the entire
call was being compiled out.
This changes the return value of the function to use the result of the
operation, thus preventing it from being compiled out.
This also adds a unit test that will detect this problem in the future.

Closes #2433

Change-Id: If3048531afc460beb16de0dda7f7fcbd5499fdaf
2020-03-11 18:17:31 +00:00
Joey Parrish 6f3ffe154d Fix StringUtils on Xbox One
Using the spread operator in StringUtils causes issues on Xbox One.
It has something to do with the compiler's polyfill for it.  But
there's no reason we have to use the spread operator instead of
Function.apply in this instance.

Closes #2186

Change-Id: If8b3ff436f852ccae1f1a8c3ee5b7d8c142e15cf
2020-01-24 22:26:26 +00: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
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
Theodore Abshire a84fd65d9e Added "report bug" button to demo.
Change-Id: I27e25f8b88effc596e2f836ec263f9ae9d2b5fc0
2019-09-04 22:51:03 +00:00
Jacob Trimble 50938a02a4 Remove throws directives.
These are intermittently used and cannot be verified.  Most of our
methods can throw a shaka.util.Error, so having it doesn't really add
anything.  Plus, if we change a function to throw, we'd need to update
all their callers to ensure they have an accurate description of what
they throw; otherwise we can't trust the directive.

Change-Id: I520bd0fc4c33443e967bf5b103ca5aa9e3274884
2019-08-28 17:00:04 +00: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 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 fd0dc8a5cc Add utility for looping from 0 to n.
Closes #1518

Change-Id: I865f7a0311516d04ae84532dab873e1aaa31eb24
2019-07-10 21:23:22 +00:00
Jacob Trimble 47533d1173 Add an enumerable() method for loops.
This is a helper to aid in iterating over items.  This returns a list
of objects that contain:
- "item": The current value.
- "prev": The previous value in the list.
- "next": The next value in the list.
- "i": The zero-based index in the list.

Issue #1518

Change-Id: Id18ab977e3ae45dfbfd2b4137a1bffb6e53c6bce
2019-06-27 16:31:42 +00:00
Jacob Trimble 7bbca076aa Detect the chunk size the browser supports.
Instead of using a hard-coded chunk size when creating large strings,
this now uses a browser check to detect it.  This allows us to use
large chunk sizes on browsers that support it but still support low-end
devices.

Closes #1985
Closes #1994

Change-Id: Ibe45902b659516ae66bd7da33007fd15e7f64207
2019-06-14 19:53:50 +00:00
Jacob Trimble 43e798870f Misc ES6 conversions.
Issue #1157

Change-Id: Ia25a6cae84575f003980e9694b2769f2976e1342
2019-06-03 15:31:57 +00:00
Michelle Zhuo ebdf9d7817 Update Util files to ES6
Issue #1157

Change-Id: Ib81d198e46bc57745f60af328d1160064e253ba3
2019-05-30 16:40:49 +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 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 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
Michelle Zhuo 535de4db84 Refactor: Remove underscore from parameter names
Change-Id: Ie9e6fb59763f454f245175f23c6444f919ba8135
2018-05-08 19:21:51 +00:00
Joey Parrish e7587cc361 Add a test util for dumping and restoring from IDB
This makes it easy to dump and restore databases from IndexedDB. This,
in turn, makes it easy for us to test that all database versions can
be read. Before we close the backward compatibility issue that has
plagued v2.3, we will add tests that use this utility to load DB
snapshots from various older schemas and prove that they can still be
read.

This also adds dumps of all database versions to the assets folder,
including a snapshot of a what our broken upgrade in v2.3.0 did to the
v2 database schema.

Issue #1248

Change-Id: If7e8995f50abbdee67e3fa93e79f07a49582c5e8
2018-04-09 19:06:35 +00:00
Jacob Trimble 624acc66b8 Add curly braces to all blocks.
Google style guide requires adding curly braces to all block statements
even if it is only has one line.  This fixes it by using eslint's
--fix flag followed by running clang-format to reformat the change.

Change-Id: Idc086c2aa8c02df5ef8b2140a11bfb9128eeb4bd
2018-02-21 11:23:34 -08:00
Jacob Trimble f70436540c Convert 'var' to 'let'/'const' (3 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: I10f5c38a8b06b5797c6eec7492829084114514c9
2018-02-14 00:47:03 +00:00
Joey Parrish bb32073725 Fix PlayReady on IE and Edge
We broke PlayReady on IE and Edge in #815 when we fixed PlayReady for
Tizen.  This should work for both, but will still need to be tested on
Tizen after merging.

Closes #837

Change-Id: Iff41845ae6a4b369e8f21a80623ebb2cb5475fd6
2017-06-05 03:21:33 +00:00
Jacob Trimble 575f2ad109 Add an indicator for critical errors.
This adds a severity field to Error objects.  This can be used to
detect whether an error is recoverable.  All the same errors are still
reported so the field can be ignored.

There are two possible values:
* RECOVERABLE means that the Player will try to recover from the error
* CRITICAL means the Player will be unable to continue and must call
  load() again

Closes #564

Change-Id: Ie2c5468340c13e7a288b99690ab65b7ecc0a6b29
2017-04-04 23:57:59 +00:00
Joey Parrish 836bd9a177 Make filters, requests, and responses easier
By exporting StringUtils and Uint8ArrayUtils, we can simplify the
process of wrapping, unwrapping, and parsing requests and responses
in NetworkingEngine filters.

This makes it easier to write filters that deal with text-based
data, as it is no longer the job of the application developer to
deal with subtle conversions between string and ArrayBuffer.

We will also fill in requests with defaults if needed.  This allows
developers to omit fields when initiating extra requests at the
application level.

Closes #667

Change-Id: Ie6a0f23b4d46e7e458d996759eac6cd85a36b741
2017-02-08 00:09:08 +00:00
Joey Parrish 09d221de16 Update the Closure Compiler to v20161024
Change-Id: I6642b1e386667028c1adbcce97ab64b21a9104b9
2016-11-11 22:08:43 +00:00
Joey Parrish e4e200388c Fix encoding issues with Chinese subs
In many places we tried to guess the encoding of a piece of text.
This guess fails for Chinese UTF-8 text, and probably text in many
other languages.

However, DASH manifests, TTML files, WebVTT files, and VTTC box
payloads are all specified to be in UTF-8.  Rather than guess and
possibly fail, treat all text in these contexts as UTF-8.

Change-Id: I00c652a9f1dd20855e94abfac84275e41dd9e266
2016-08-25 22:29:37 +00:00
Andy Hochhaus 87a62d717e Add missing goog.require() dependencies 2016-06-25 15:45:15 -07:00
Jacob Trimble 7c1e7eaa56 Fixed stack overflow with StringUtils.
Because we were using Function.apply to create strings, large arrays
were causing problems with browser argument count limits.  This
now splits the arrays up before calling.

Closes #335

Change-Id: Ic94a950997e2f17563ecba8fb628f62c0ed18fc2
2016-04-19 23:13:28 +00:00
Jacob Trimble 19973d63f4 Changed copyright headers from 2015 to 2016.
Change-Id: I429ff27e4794c03b7ea392e38415075077f9bfb1
2016-03-15 16:32:13 -07:00
Jacob Trimble 49b238b3c9 Fix support for UTF-8 encoded data.
Before, we simply converted each byte from an ArrayBuffer into a
character; however, this is only valid for ASCII characters.  This
changes it to fully support UTF-8 encoded network responses.

Change-Id: I9c49f29b09960501d345b98aa7af1bb711972abf
2016-02-23 00:12:43 +00:00
Joey Parrish fff5dd7ee7 Audit exports
This changes namespace exports to the more targetted exportDoc,
adds exports where they are needed and removes them where they are
not.  Exporting of Uint8Array and String utils should be re-evaluated
later.

Change-Id: I9298e73a0a5ef026b6f2b1854488d2c359be10c1
2015-12-01 13:56:37 -08:00
Joey Parrish 4cc4e96dbd Overhaul license comments and file annotations
* Updates all Copyright years to 2015.
* Adds licenses annotations to all JS.
* Makes all licenses identical to avoid repeated appearance in the
  compiled output.
* Drops fileoverview annotations, which do not affect docs output.
* The linter still requires fileoverview on externs.

This patch required a newer closure compiler, since the previous
version we used had a bug regarding license annotations that caused
the license comment block to appear in the output once per file
regardless of uniqueness.

Change-Id: I2e9272db680cba7ecc4613d97f1d3a94ac2244cc
2015-09-08 12:02:34 -07:00
Joey Parrish 4d9177240a Revert "Adding license annotation to js files."
This reverts commit 8cb24652cb, due to
the fact that the new annotations caused our binary size to jump
by 52%.

The compiler preserves all 'unique' licenses, which causes trouble
since the comment blocks with the license annotations are not unique
and contain file overview comments as well.

We can re-examine this once we have restructured the license headers.

Change-Id: I418e407a0e0253630633697f30cf496a7fc2ddfc
2015-09-04 18:36:39 -07:00
Yohann Connell 8cb24652cb Adding license annotation to js files.
Change-Id: Id10592ccaf35608ac4f01844cae2fec4a2030d65
2015-09-04 00:05:17 +00:00
Timothy Drews 689c2a47aa Use 'keystatuseschange' events and support @group.
Use 'keystatuseschange' events from EME together with cenc:default_KID
from the MPD so StreamVideoSource can determine if the key system
can/will decrypt a stream before it attempts to play it. This enables
the Player to safely (and automatically) switch between streams that
are encrypted with different keys.

Support AdaptationSet @group, which is the preferred approach to safely
use multiple encryption keys over multiple Representations.

* Squash AdaptationSets from the same group into one StreamSetInfo.
  This enables support for @group without introducing special case code
  into StreamVideoSource and EmeManager.
* Fire 'trackchanged' events when tracks becomes available/unavailable
  either from application restrictions or key status changes.
* Pull key IDs out of DrmInfo and put them into StreamInfo so key status
  changes can drive per stream availability instead of per StreamSet
  (AdaptationSet) availability.

Closes #67
Issue #160

Change-Id: Ife0814deb65715923a572b45880137a99b378035
2015-08-31 23:13:17 +00:00
Joey Parrish 598e042b4a Always use base64url encoding.
This fixes clearkey errors on newer versions of Chrome 42.

Change-Id: I3c0d7336fa21587fe730c747e8aea92657a6cf33
2015-02-28 20:38:00 +00:00
Joey Parrish f7d9ea5794 Refactor StringUtils into Uint8ArrayUtils.
Most of these StringUtils were either operating on Uint8Arrays directly
or using strings to move around Uint8Array data anyhow.

Change-Id: I71efe6ede34210ca721d46acd53452344efff5bb
2015-01-29 09:41:06 -08:00
Joey Parrish b3d035be9f Shaka Player release v1.0 2014-12-19 14:26:19 -08:00