Commit Graph

36 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 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 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
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 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
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 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
Theodore Abshire 3de04a92d0 Convert simple abr manager unit to ES6.
Issue #1157

Change-Id: I55a732a76d89217b677c375d4000fef2947018ae
2019-05-31 02:11:54 +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 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
Jacob Trimble c3ce160217 Consolidate default configs in tests.
Instead of duplicating the default configuration values in each test,
this now uses the default configuration methods.

Change-Id: Ifd2ab349db7903a2acb0d06fed4bd0ccd5050b35
2018-12-27 18:00:55 +00:00
Jacob Trimble 6c49ddcfd1 Restore addPartialStream method.
This method was removed during the Variants refactoring.  This method
uses jasmine's asymmetric matchers to only match some of the fields.
This is important for tests so they only test the relevant fields.

This also removes implicit reuse of stream IDs.  Stream IDs must be
unique and there is a new method for cases where the intent is to
use duplicate streams.

Change-Id: I185df5f0beb018169ff537abb952ee4ebbf49be6
2018-08-16 22:51:59 +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
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
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
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 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
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
Jacob Trimble d8a3d8d2f7 Change jasmine.Spy type definition.
The old definition using a union with a Function causes problems.  The
compiler tends to treat this as an unknown type, so we loose type
safety.  The new types ensure full type safety, at the cost of needing
to "convert" the spy when it is used as a function.

Change-Id: I98ebd9dffd9cb865d0cf5d03db0fb5d6ea001ed3
2017-06-27 12:18:48 -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
Sandra Lokshina 0b12937520 Replace content type strings with constansts.
Change-Id: I4fda583915766b40ee7a5c7451d037077d9f2582
2017-03-08 21:41:59 +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 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 1ba2ebb23e Simplify and speed up fakeEventLoop with polyfill
Forcing the use of the Promise polyfill allows us to remove the hacky
parts of fakeEventLoop and gives a huge boost in speed for the tests
that use it, particularly on Edge where the delays were large.  Many
fakeEventLoop tests can now run synchronously.

Time to run tests in our lab before this change:
  - Edge: 21 minutes
  - Safari: 6 minutes
  - Chrome, Firefox, Opera, IE: 6-7 minutes

Time to run tests in our lab after this change:
  - All browsers: 5-6 minutes

This also reduces the incidence of Safari failures in our lab, but
that issue does not reproduce on other machines.  It looks
increasingly likely that our lab machine is faulty and needs to be
replaced.

Change-Id: I7bdcc6830c8fdf298538ce6538b1ca8e1b92cab2
2016-08-18 19:51:48 +00:00
Joey Parrish d0908fe743 Raise the async test timeout to 120s
All tests now have the same timeout value.  This should simplify the
process of addressing timeouts on Safari.

Change-Id: I3b455bd639758007ec8b2b86ef236c56e919c15a
2016-08-11 10:54:49 -07: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 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
Leandro Moreira a8c44da4b1 restructures test files 2016-07-01 09:53:30 -03:00