Commit Graph

205 Commits

Author SHA1 Message Date
Joey Parrish 7e6a0f38ff fix: Correct license headers in misc. files
This corrects/normalizes license headers in misc. files, such as
config files, docs, build tools, tests, and externs.  This does not
affect the compiled output, and is only done for consistency.

Issue #2638

Change-Id: I9d8da2de55243b08d7df2b743aac73c6f15e858a
2020-06-09 16:13:56 -07:00
Joey Parrish 286ff17361 Fix getPlayheadTimeAsDate while loading/buffering
Before we buffer a segment, video.currentTime will be 0, even for live
streams.  So this should not be used in getPlayheadTimeAsDate().
Instead, we should use the Playhead time or the time that will be used
later once content is loaded.

Bug: 149549467

Change-Id: I585fd2364003021839bc16724f41510637489326
2020-04-30 16:22:34 +00:00
Joey Parrish 4eefaa44cb Correct type info in tests
In many places in the tests, we used "Object" or "*" or just no type
at all for various fakes.  These were all flagged by the new Closure
Compiler version we are adopting.

In some other places, we mixed up similar types or had the wrong
nullability on a type.

In still others, types were missing fields.

These issues were caught by a compiler upgrade.

Issue #2528

Change-Id: I324e0b28f7e30a4102aa26ec2c9901fa9732211b
2020-04-30 16:00:17 +00: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
Joey Parrish 99de217c23 Remove periods from manifest structure
This removes periods from the internal manifest structure and cleans
up code and tests accordingly.  This leaves us unable to play
multi-period DASH & offline streams until the main period-flattening
algorithm is completed in shaka.util.Periods.

Three test cases have been disabled for the moment.

Multi-period playback will be restored in a smaller, more focused
follow-up commit, with disabled tests re-enabled.

Issue #1339 (flatten periods)
Issue #1698 (rapid period transitions issue)
Issue #856 (audio change causes bitrate change)
Closes #892 (refactor StreamingEngine)

Change-Id: I0cbf3b56bfdb51add15229df323b902f0b2e643a
2020-04-09 19:22:16 +00:00
michellezhuo 3b52166f56 Remove support for custom DASH ContentProtection schemas
Remove manifest.dash.customScheme callback function since it's no longer used.

Closes #2356

Change-Id: I6d08fcf97cff1bf2985e7c660d74efcd767eaed9
2020-04-09 09:11:20 -07:00
Joey Parrish e018aaaaba Fix potential memory leak in SegmentIndex
SegmentIndex has had a destroy() method for a long time, but it has
never been called.  Now that SegmentIndex has a timer which adds new
references for DASH SegmentTemplate live streams, it is more important
than ever to properly stop this active part of SegmentIndex.

This change replaces async destroy() with synchronous release() and
calls it from Player when the manifest is being disposed of.  This
will ensure that SegmentIndexes don't grow out of control after
content is unloaded.

This would not have affected v2.5, since we didn't have this
timer-driven growth of DASH SegmentTemplate live streams in that
release branch.

Related to #1339 (fixes issues introduced for period flattening)

Change-Id: I419a06a62eaa507d92132e20d4cc2d6e45c83ff2
2020-03-23 10:21:13 -07:00
Jacob Trimble bc45564721 Remove deprecated ability to pass factories to load.
Player.load and Storage.store used to accept the manifest parser factory
directly.  But now they should only accept the MIME type string.  This
removes the deprecated functionality in preparation for v2.6.

Change-Id: I1b4c5a4a9f0b6edbea909d18111ddc87a39da331
2020-02-20 23:44:51 +00:00
Jacob Trimble 3f63021a2f Avoid using "new" with factories.
Instead of having the "factories" use "new" to construct them, now they
will be plain functions.

Closes #1521

Change-Id: Ia6151ad679a78a5c6db128d43094c82add0af348
2020-02-19 09:57:51 -08:00
Joey Parrish 39eb6cfcbf Always log config errors
This makes the config-rejection logs always-on in compiled mode, to
help application developers notice problems during upgrade.

Found while fixing #2383

Change-Id: I131a1bf8197da394a743e9a121348178d38e5948
2020-02-14 15:13:03 -08:00
Joey Parrish e82b13b311 Fix acceptance of async functions in configuration
The config merging code was rejecting async functions, because the
.constructor field of a function is the "Function" constructor, but
the .constructor field of an async function is the "AsyncFunction"
constructor (not exposed as a global).  This led to the async function
being rejected because it was misdetected as a different type of
"object" than the default value.

The fix is to exclude functions from this constructor-based
type-checking.

Note that the compiler will turn async default values into synchronous
functions in the compiled build, so an async default will appear as a
synchronous function in the compiled build and an async function in
the uncompiled demo.

A synchronous function from the app will always be okay, even if the
library expects async, because "await" will still work.  But if the
library expects a synchronous function, the app should not supply an
async function, because that will return a Promise instead of the
expected type.

This adds a test to show that it is okay to pass a synchronous
function to an async config field, which is important for backward
compatibility as we make trackSelectionCallback async (#2383).
However, because the compiler causes us to lose the native async-ness
of our default values, we can't reject async for sync fields or write
a test for that scenario.

Found while fixing #2383

Change-Id: I62891441ce75bfc887ea13c24212a2ee78f90af4
2020-02-14 15:13:03 -08:00
michellezhuo 84b8ab4dfe selectAudioLanguage() selects only audio's role
Before, we checked either the audio role or the video role matches the selected role,
but we should check only the audio role when selecting audio language.

Closes #2346

Change-Id: I040f41129dc902cce79c66ba36cb10917fcc8453
2020-01-24 10:07:38 -08:00
Álvaro Velad Galván e0045e5731 Add corruptedFrames to stats (#2328) 2020-01-10 15:46:20 -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 bdca05ff4b Add pixelAspectRatio property from DASH (#2294) 2020-01-06 10:56:28 -08:00
Álvaro Velad Galván 02fa8c6876 Add audioSamplingRate property (#2290) 2019-12-10 18:00:16 -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 0e1e1a0491 Fix multi-Period handling of key statuses.
Before we would only update the current Period when we got a key status
change; this caused us to fail playback for the second Period if the
streams were restricted.  Now we update all the Periods.

Closes #2135

Change-Id: I2238a90c1d367a1d898ec26e4318852cd26da4b7
2019-09-10 21:39:19 +00:00
Jacob Trimble c0e7a9b62a Use callbacks for ManifestGenerator.
This allows us to avoid suppressing the indentation rules and ensures
we have correct indentation.  It also makes it harder to make mistakes
since the variables are only accessible within the callback and you
can't accidentally contaminate another object with an incorrect call.

Closes #1692

Change-Id: Ic38b5cd57a2587dfc8c115ba782656c15565b655
2019-09-04 22:51:12 +00:00
Joey Parrish 3e44fac804 Use function for factories in tests
These factories require actual functions, not arrow functions.  This
was only working so far because of Babel translating the code to ES5.

Closes #1953

Change-Id: If05d11f4a66f920077343c3e1759964f41e4433c
2019-07-09 21:23:54 +00:00
Jacob Trimble 19b42441ae Modify Date.now instead of using jasmine.clock.
This allows us to avoid using mock timers and makes the timing more
clear.

Issue #1379

Change-Id: I0dc4bd57c3efc0c1495e32092e4b6c3a963aeda2
2019-07-09 16:42:29 +00:00
Jacob Trimble a27f50dd43 Avoid changing variant when switching text lang.
This fixes a TODO and fixes setting the "active" track when switching
languages when not displaying text.

Fixes #2010

Change-Id: Ic4cf4126ffb9b93a09af998e20f9da0e7af852fb
2019-06-27 18:40:28 +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 83de1ad634 Use toBe instead of toEqual for primitives.
This ensures that we get the expected types and that type coercion
doesn't convert between types.  This also ensures we are consistent
in how we check for equality of primitives in tests.

Change-Id: I9f3aacdf25ab1afe5e8d6e4b895b5299ee687d54
2019-06-26 18:57:18 +00:00
Jacob Trimble 52522c7dca Fix cases where errors weren't propagated.
This propagates errors in several places and fixes waiting for some
async calls.

Change-Id: Idf4519b473538c1fa00bfe63e634194610ba29f2
2019-06-19 20:35:30 +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
Jacob Trimble e59187adf5 Convert player tests to ES6.
Issue #1157

Change-Id: Ib405576ff77e324e5586b93cdbfddcde69d264ab
2019-05-22 16:14:19 +00:00
Jacob Trimble d76b339795 Add externs for expectAsync().
These allow you to use expectations for async methods. This is
especially useful for expecting failures.

Change-Id: I7281b0c1370aab688957f3d77affdc9d3044ce74
2019-05-21 16:07:07 +00:00
Jacob Trimble a3be4d837d Don't create spies in beforeAll.
Creating them in beforeAll will usually cause test contamination, so
they should be created in beforeEach instead so they are reset for
each test.

Change-Id: I51f11de85555cbf5b8c18969eabeecbe8617b8f3
2019-05-16 22:45:52 +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 984bb6f340 Fix ManifestGenerator indentation.
We use custom indentation for the ManifestGenerator to make the repeated
calls easier to read.  This disables the coming linter rule for these
blocks of code.  This also goes through and unifies the formatting.  The
indentation should be 4 spaces from the left side.

Change-Id: I687e69cea39bded1e9e06bffdcc888970b383fa2
2019-05-13 22:11:37 +00:00
Jacob Trimble 381274fbbd Enforce a consistent dot location.
Change-Id: Ic3b86c4c113023206bc37a117e96f672f351121b
2019-05-09 21:09:30 +00:00
Joey Parrish ab6f9cfd3d Allow short-form config for UI and offline
With this change, offline and UI config can use the same two-argument
short form that the Player config interface offers.

Change-Id: I5f40ef58da76f3aab1d7178fe7d6e82097352b9a
2019-05-09 19:34:01 +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 8391fe1684 Extend Player track methods to cover native HLS
Track methods are now implemented for native HLS and other src=
playbacks.  This will allow the UI to select text and audio languages.

This change adds best-effort methods to get track information for src=
playbacks, including native HLS on Safari.  In many cases, it relies
on the audioTracks and videoTracks members of HTMLVideoElement which
are only implemented on Safari.  They are in the spec, though, so
there's no harm in using them when they exist.

This is fully parallel to the manifest-based paradigm for MSE-based
playbacks.  Each of these top-level methods in Player has an "if" to
decide which way to supply the requested info, except for the language
methods, which now delegate to the track methods.

With this, Safari's native HLS can supply audio and text language
information to the UI/app, and the UI/app can have some control over
those things through the tracks API.  I believe this is important to
the success of our new iOS support.

Issue #997
Issue #382

Change-Id: Icc44a932927fafedda1b62a9d4c6e2ed3dc7db30
2019-04-30 21:15:00 +00:00
Aaron Vaage 2d9c6d62a6 Make Buffering Observer the Authority on "Is Buffering"
Previously there was a boolean that held the "is buffering" state,
however with the buffering observer directly assessable, we can just ask
it if we have enough content.

Change-Id: Ic5adb2b54fc7a7f6d732520ac257bf4ca1407287
2019-03-29 19:43:33 +00:00
Aaron Vaage 1284dd484b Make Buffering Observer A Top-Level Component
Before the buffering observer was a playhead observer, but with
supporting src=, changing how we interact with the buffering observer
was made easier if it was handled as a top-level component.

This meant moving it off the playhead observer interface and create its
own timer in player.

Coming off the playehead observer interface, the buffering observer did
not need to use callbacks, which made it easier to use. This will also
allow us to use it as the single source of "is buffering" in a later
change.

Change-Id: I8cad9bfde3309de7c2b8301b90aa8c40b6e4d247
2019-03-29 19:43:31 +00:00
Aaron Vaage 78aa5752fb Generalize State History
This change makes state history track any state by moving the idea of
buffering, playing, etc to the player.

This allowed the stats and state history to drop they connection to the
media element.

Change-Id: Ieed198a09b3ade33e4ee850445b809f251cf2558
2019-03-28 21:40:58 +00:00
Aaron Vaage 954f55e569 Inline |findVariantForTrack|
|findVariantForTrack| was only called from one place in the library and
once in a test. There were ways to get the same behaviour without
needing a utility method in a different class.

The CL inlines the behavior in the player and replaces how the test
handles its logic.

Change-Id: I82e3b7933cc6b4da4b8b2d2da07b405900ecba8b
2019-02-27 16:46:58 +00:00
Aaron Vaage 1752f1d486 Add Media Source Engine Step in Load Graph
This change takes the part of |onLoad| that creates media source
engine and makes it into its own state in the graph.

This allows us to pre-initialize media source engine and will allow for
the load-process to be aborted after initializing media source engine
but before load.

This ensure that we only initialize media source engine once per load
(fixing #1570) by modeling "initialized media source" as its own
node in the graph.

The tests that appear to be removed from "player_integration.js" have
been moved to be with the other load graph tests and re-written to
make use of the load-graph events for testing.

The stats test that appears to be removed from "player_unit.js" was
moved to "player_integration.js". This test was failing before the
player was not overriding media source (like the other tests were) since
this one had to do with load order, it was moved to be closer to the
other load order tests.

Issue #816
Issue #997
Closes #1570

Change-Id: I646f0559e3878f28374a3fc56f3d70f6d8a462a4
2019-02-26 23:42:36 +00:00
Aaron Vaage b978ae83b5 Refactor Player to Use Walker
This is the initial integration between the walker and the player. In
order to make this simpler, this keeps all of "load" as one transition
and will slowly break it into multiple parts in later CLs.

Tests that focused on verifying the changes in states were moved from
the unit tests to the integration tests.

As of this CL we model the load graph as:

  Detached -> Attached -> Loaded -> Unloading
      ^         ^                       |
      |         |                       |
      +---------+-----------------------+

With this CL we lose:
  - Interrupting manifest load retries when interrupting a load.
  - Interrupting loading.
  - Pre-initializing media source.

We have immediate plans to add back:
  - Interrupting loading.
  - Pre-initializing media source.

We are still designing how to handle:
  - Interrupting manifest load retries when interrupting a load.

Issue #816
Issue #997
Issue #1570

Change-Id: Ie929621f94c2701f7d4e031b7a31dbd1c74a69c6
2019-02-26 23:42:36 +00:00
Aaron Vaage 88b5ad7852 Refactor Playhead Observers Into Separate Classes For Each Observation
Before we had one central playhead observer that would monitor multiple
different relationships:
  1. Buffering
  2. Periods
  3. Timeline Regions

This CL breaks each observer into their own class (allowing for them
to be tested independently). To allow the player to be ignorant of which
ones are in-use, a playhead observer manager has been created.

The player is responsible for creating the observers since it has the
knowledge of what ones need to be created (and the references to
everything).

As part of breaking the observers apart, the Region Timeline was broken
out so that the observer has something to observe (similar to how the
buffering observer observes the buffered region and the period observer
observes the periods).

Change-Id: I18bf0f45561f3bac44da50c0d00a02f8b1fbf3cf
2019-02-01 00:43:35 +00:00
Aaron Vaage 0f0a3515b6 Refactor media source engine to take text displayer in constructor
Before, media source engine could be created with no text displayer.
However, player would always create media source engine with a
text displayer.

Just like with closed captions, this appeared to be a good time
to change it to be passed in the constructor and have media source
engine own it.

This now means that media source engine is responsible for destroying
it - lessening player's responsibilities.

Change-Id: I71cd1c28a3c22d3c765a3892fe74ae3f9abd1914
2019-01-24 01:12:37 +00:00
Aaron Vaage 7148354aab Refactor Playhead (and below) to use IReleasable
This change takes playhead and its internal members and moves them
over to use the IReleasable interfaces instead of the IDestroyable
interface.

Change-Id: Iddb525725591a29a61ca6b5e2ad519ab708164eb
2019-01-24 01:11:48 +00:00
Aaron Vaage 39651c51b0 Refactor to have a central fake text displayer in tests
There we a couple different fake text displayers in our tests. This CL
take them all and consolidates them into one fake text displayer.

Change-Id: I889aa4f11660d641920b0628e7e91549cb715c6a
2019-01-22 19:13:31 +00:00
Aaron Vaage 846c15cdb9 Rename getActive* to getBuffering*
To make it easier to understand the context of the streams
and periods returned by StreamingEngine, "getActive" is
renamed to "getBuffering".

Change-Id: I99aec589bd4d736b170fa2197e5097ff33c0fc82
2019-01-15 15:24:18 -08:00