Commit Graph

52 Commits

Author SHA1 Message Date
Álvaro Velad Galván 943bdb2b35 Use Network Information API to react to network changes (#2663)
Resolves #1067
2020-07-09 09:46:24 -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
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
Álvaro Velad Galván 02db99f567 Take into account the playbackRate in bandwidth calculations (#2329)
Resolves #812
2020-01-31 10:03:00 -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
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 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
Michelle Zhuo 3103e30d95 Convert abr files to ES6
Issue #1157

Change-Id: Iab9c4be5d98494bf644f45cc0b4a5c235b31e80e
2019-05-28 23:20:03 +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 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 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
Joey Parrish ed0f37b099 Make AbrManager restrictions "soft"
This change makes restrictions on AbrManager into "soft" restrictions.
This means that if these restrictions cannot be met, AbrManager will
still choose something instead of throwing an error.

This is in contrast to top-level restrictions or DRM-based
restrictions, which are "hard" restrictions that will stop playback if
necessary.

This change also fixes some minor issues with the SimpleAbrManager
tests, such as cross-test pollution in the restrictions object.

This is a lead-in to issue #855, where AbrManager's restrictions will
have their defaults changed when the "saveData" signal is present in
the browser.

Change-Id: Icdb2ff5df7ceb0d94f1267bf81e59dede3c2baf9
2018-05-31 10:57:33 -07:00
Sandra Lokshina 8065bd54a8 Change namespace from shakaExterns to shaka.externs
Change-Id: I16432351e2a266aa8fd175669aa27c44bfdffeae
2018-04-11 17:26:26 +00:00
Theodore Abshire dc17969822 Typo fixes and rewording in comments, part 1
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: I048b430e4c0bea2ccb9aec572d5e9ec6b606a87a
2018-03-14 17:59:26 +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 61fc107be3 Convert 'var' to 'let'/'const' (1 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: I8f857a24e4c1ad336177d23dfed4f4a29d3262d2
2018-02-13 13:40:02 -08:00
Sandra Lokshina 891b9716cf Use Network Information API to get bandwidth estimate when possible.
Issue #994

Change-Id: Id4a33ce7467c2e89613acb191fb304f02d10ed65
2017-12-04 15:35:02 -08:00
Joey Parrish 7e0f46931e Overhaul variant-based and stream-based interfaces
While I set out to fix failing assertions during playback, I found
many more changes necessary to clean up the code and make things more
consistent.

When we changed switch history to include variants instead of streams,
we broke the filtering logic that is applied to the history.  This
caused assertions at runtime that were not caught by the tests.

This moves the filtering logic to addToSwitchHistory_ and makes it
aware of variants.  It also adds a regression test that would have
caught the assertions.

This fix affected many other tests, though, which necessitated other
API changes and cleanup.

Many interfaces are simplified, as is switching logic in Player.  The
data flow is also easier to follow, since there are fewer transitions
between variant and stream.  Everything up to StreamingEngine uses
Variants, and StreamingEngine uses Streams internally.

  - All stream-based interfaces on AbrManager replaced
    - switch callback takes a variant
    - chooseStreams replaced with chooseVariant
    - setTextStreams has been dropped
    - Player maintains compatibility with old interfaces until v2.3

  - Most stream-based interfaces on StreamingEngine replaced
    - onChooseStreams callback to Player returns variant & text
      instead of a stream map
    - switch was replaced with switchVariant and switchTextStream,
      both of which delegate to switchInternal_, which is largely
      unchanged from the original switch method
    - still has getActiveStreams, which I hope some day can become
      getActiveVariant and getActiveTextStream so Player no longer
      has to convert anything

  - Most stream-based logic in Player replaced
    - deferred switches map broken into variant and text members
    - switch history logging broken into simpler variant and text
      methods
    - simplified manual and automatic track selection logic using
      new AbrManager and StreamingEngine APIs
    - player no longer filters duplicate selections, StreamingEngine
      handles that
    - replaced one case of deferred switches with an assertion

Closes #954

Change-Id: Ia49f6ffb9c5fa13ed8790dd03eeeded5122f7683
2017-08-03 21:34:47 +00:00
Joey Parrish 5798845d4b Minor cleanup in AbrManager
No need to pass a member variable around.

Change-Id: I84cab5d4327faadbfd1fc427f5d5bc2c15a31d1a
2017-06-02 16:12:10 -07:00
Sandra Lokshina 859130fd45 Refactor player to accept abr manager factory.
This change makes ABR targets configurable and refactors player
to accept Abr Manager factory rather than have manager be
part of ABR config.

Closes #744

Change-Id: I732daaf555d21cc9e79450eeb1f74ac3544b90cc
2017-06-01 09:35:54 -07: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
Sandra Lokshina 0b12937520 Replace content type strings with constansts.
Change-Id: I4fda583915766b40ee7a5c7451d037077d9f2582
2017-03-08 21:41:59 +00:00
Jacob Trimble 3f4eb4a111 Add additional docs for AbrManager.
Issue #629

Change-Id: I9548c24078e07537ae4c1e6f28461c992f5f794e
2017-01-27 23:19:13 +00:00
Jacob Trimble b28f84ccc3 Add separate restrictions to AbrManager.
This adds a second Restrictions object to the Player configuration to
restrict ABR decisions.  The original restrictions will remove any
non-matching streams from the manifest, like before.  This new
configuration will only apply to AbrManager choices.  Any restricted
track can still be explicitly selected using Player.selectTrack.

Closes #565

Change-Id: I52379b096e81f97df22b6683669c5787694d87e7
2017-01-09 20:25:14 +00:00
Sandra Lokshina e95d7b9de4 Refactor shaka internals to use variants instead of stream sets.
Issue #279

Change-Id: Idf4241b4e2490876bdc6275685361a5c9bf132b0
2016-12-28 17:49:24 +00:00
Jacob Trimble b1711c346d Allow passing durations from scheme plugins.
This allows the networking plugins to pass the duration it took for
the request.  For example, if a plugin were pre-fetching the segment,
this allows the plugin to tell NetworkingEngine about how long it
really took to download.

Closes #621

Change-Id: Ie67e3f99389cf02d5b4a345bde06ccc418b6e91c
2016-12-20 20:17:43 +00:00
Sanborn Hilland 465206b0e8 Avoid ewma sampling from failing on 0 duration segments. (#583)
This fixes a divide-by-zero that caused the estimate to become NaN.

Fixes #582
2016-11-16 11:12:26 -08:00
Joey Parrish 1d2929ab00 Add extra exports for the sake of generated externs
An upcoming compiler release will allow us to generate externs from
exports.  Because of that, we are adding some extra exports which are
otherwise not needed at runtime.

 - Export properties which implement an interface
 - Export classes which are referenced in external APIs
 - Export base classes of other exported classes

Change-Id: I78b3a4569b4b82b0a9d8993978faf268c2a791d9
2016-11-04 17:12:16 +00:00
Joey Parrish 4ec00f56e3 Audio adaptation
SimpleAbrManager will still choose the middle audio stream by default,
but will adjust audio up or down once video has been chosen.  Video
will be downgraded before audio, and audio will be downgraded only as
a last resort.

For audio-only content or content with one video stream and many audio
streams, audio will be chosen to fill available bandwidth, just as it
already was for video.

Change-Id: Ia4a0e9607d860713a5ad7887ac6a9aa04767eb25
2016-10-24 17:24:47 -07:00
Joey Parrish 385a501d0d Stop clearing the buffer ahead of the playhead
Clearing ahead of the playhead is causing hiccups in playback on the
following browsers:
 * Chrome (all platforms, inconsistent)
 * Edge

These browsers appear not to be affected:
 * IE 11
 * Firefox
 * Safari

This is a manual change that reverts almost all of:
 * a8ac3142 - Make buffer clearing behavior explicit
 * 4593cf78 - Check position against null, fix bug in a8ac3142
 * 10b3dd0a - Seek after clearing a buffer, workaround Chrome bug
 * 6daa7f3b - Allow AbrManager to clear ahead of the playhead

Clearing the buffer is now an all-or-nothing proposition because that
is the only way to get consistent playback quality across browsers.
This comes at a cost, because we can no longer count on the ability to
remove buffered data on upgrade without a stutter.

Issue #520

Change-Id: Ia6f8b2fcb223f9c50e9829b26d7003ae8f6efb8d
2016-10-20 10:30:59 -07:00
Joey Parrish 8152e649f1 Speed up ABR decisions
- Speed up EWMA estimates (lower half-lives)
 - Drop min delay concept
 - Trust the estimate after a certain number of bytes have been
   sampled (128kB)
 - Take samples as small as 16kB (previously 64kB)
 - Drop startup interval, just wait for estimate to be trustworthy

The result is much faster initial adaptation when the default
bandwidth estimate is too low, without sacrificing startup speed in
low bandwidth situations.  The best track is selected right away,
and is visible after the first two segments have played out.

In a high-bandwidth scenario using our test clips (Angel One and
Sintel), the initial ABR decision is visible 2.4x to 4.4x faster now.
Decision speed is now largely independent of available bandwidth.

Change-Id: I121f4dd44b725dc53de61c02f7afea14d9234df6
2016-10-03 16:04:26 -07:00
Joey Parrish a8ac3142ef Make buffer clearing behavior explicit
- Replace both boolean clear and number-of-seconds args with an enum
   indicating a specific type of clear behavior: none, all, or most
   (all but 2 segments, currently).
 - Calculate segment size from the content in StreamingEngine, rather
   than assuming a common segment size in AbrManager.

Change-Id: I9e4fee0945d5e50fd7da86bb8467911e60c4575e
2016-09-28 22:48:51 +00:00
Joey Parrish eafe954d0c Replace Number.POSITIVE_INFINITY with Infinity
This is supported on all browsers, is more compact, and is easier to
read.

Change-Id: I96576dc341e093b7be9ef94fe36595c945b063c1
2016-08-29 18:56:54 +00:00
Jacob Trimble ee0959315c Use buffer end to determine which segments to download.
Before, when we adapt we tell StreamingEngine we are in an unbuffered
state.  This causes it to download segments at the playhead, even
though we have some buffered.  Normally this does not cause problems,
but on Edge, it can cause skipping.  So now, StreamingEngine will
use buffer end to determine which segments to download.

Issue #446

Change-Id: Ib1f4cd3a1627efa957825eb0445c99f753f31e7b
2016-07-27 17:30:59 +00:00
Joey Parrish 9eadb61b4a Allow redundant switches from AbrManager
Working toward a solution for #435

Change-Id: I662c06c21eab7c5b6f2af85236088f1712ee7a72
2016-07-22 14:42:20 -07:00
Joey Parrish 10fd95760c Take partial StreamSet list in AbrManager
This will allow us to pass only audio stream sets when a language
changes, which will remove the need to filter the output of
chooseStreams in Player.applyConfig_.

Working toward a solution for #435

Change-Id: I893d13882809ef461b16c6c9426c8e9e33604c02
2016-07-20 13:37:53 -07:00
Joey Parrish 6daa7f3b83 Allow AbrManager to clear ahead of the playhead
SimpleAbrManager will now leave 5s of video ahead of the playhead and
clear the rest when upgrading to a higher resolution.

Also smooths transitions for overlapping segments by scheduling an
abort() call to reset MediaSource internals after removing content or
changing the append window.

Related to issue #435

Change-Id: Ie036515388e1e7e4b3b8f3ab9922e3d5e7ed2627
2016-07-13 04:01:11 +00:00
Joey Parrish 9388c1e8dc Revert "Make bandwidth estimator cache friendly."
This reverts commit 60d2944c25.

Closes #367
Reopens #324

Change-Id: I4302469a319b30f1ce502554348fd69726a50c58
2016-05-05 13:32:24 +00:00
Timothy Drews 058004eb02 Export SimpleAbrManager.
This allows applications to reset the Player's AbrManager
and to use SimpleAbrManager in their own ABR
implementations.

Issue #355

Change-Id: I58d06c1d547b83b3221a30518620ad2352e97636
2016-04-25 22:20:36 +00:00
Jacob Trimble 60d2944c25 Make bandwidth estimator cache friendly.
Closes #324

Change-Id: Ie01be560c607c77c116ac7bcea18efe081526d61
2016-04-21 23:38:34 +00:00
Jacob Trimble e1d834f3c2 Add track restrictions to Player.
Now the application can restrict the kinds of tracks that the Player
will play.  This is done through player.configure().  This also
allows restricting the playable tracks based on the EME key status.

Closes #326
Closes #327

Change-Id: I88210ece6fd1db886c49d4599fbe5814d394132d
2016-04-15 12:21:24 -07:00
Jacob Trimble 3bdfc7dfa1 Make default bandwidth estimate configurable.
Now, the default bandwidth estimate used is configurable and can be
set using Player.configure.

This also moves enableAdaptation and abrManager configuration values
to a subcategory 'abr'.

Closes #268

Change-Id: I11ab30452b20dc4fd9385210811185fe2969821e
2016-04-06 23:28:52 +00:00
Jacob Trimble 990042ab40 Added tests for Player stats.
This also changes the units of the bandwidth to bits/sec.

Change-Id: I00ff0f2f0ae2caed6690b6533065b37a33e35984
2016-04-06 18:18:17 +00:00
Jacob Trimble 5b22d122d1 Add stats to Player.
Change-Id: I9141d7722fb94120ea204c88efbe11c7a2af2f84
2016-04-01 16:11:51 +00:00
Joey Parrish 698fff9846 Add AdaptationEvent and TracksChangedEvent
- Fire adaptation event when AbrManager calls switch.
 - AbrManager only calls switch when something needs to change.
 - Wait for StreamingEngine.init to complete before firing the first
   AdaptationEvent.
 - Fire trackschange event when we change periods.

Change-Id: I1701afbe71caae87a93c379a71911541c7bda86a
2016-03-28 09:49:45 -07:00
Jacob Trimble 19973d63f4 Changed copyright headers from 2015 to 2016.
Change-Id: I429ff27e4794c03b7ea392e38415075077f9bfb1
2016-03-15 16:32:13 -07:00
Joey Parrish 792303ed52 Make Player reusable
This greatly simplifies things for the caller, who can simply call
load() multiple times instead of waiting on cleanup or creating a new
Player instance.

Change-Id: I83ec5ee7f7de2b652d0f193f4b6ece1971c80c16
2016-03-15 16:38:01 +00:00
Jacob Trimble 8daf53e329 Renamed shaka.asserts to goog.asserts.
Using goog.asserts will work with the compiler.  So rather than
simply casting a nullable value when passing to a method, we can use
an assert which will correct the type and print a log if it somehow
is null.

This is not the same goog.asserts found in closure library, this
simply calls console.assert, but it is not required to do anything
for the compiler help.

Change-Id: I2548e39e772f0aa7ec41437cf9f5a2be383e0fbd
2016-03-11 15:29:20 -08:00
Jacob Trimble 846e7beb48 Unified comment spacing.
Before there were two style to indent comments after an annotation,
using 2 and 4 spaces.  Now this only uses 2 spaces.

Change-Id: Id06415d7193cc154a2768fb3932aff7a06b7ed32
2016-03-10 16:27:45 -08:00