Commit Graph

123 Commits

Author SHA1 Message Date
Michelle Zhuo a09ae24b85 Add audio channels count configuration
Added a preferred audio channel count to configuration, default set
to 2.
Choose the codec with the largest number of audio channels less than
or equal to the configured number of output channels. If this is not
possible, choose the smallest number of channels.

Closes #1013.
Issue #1071.

Change-Id: I6c6a956e33637cf34bd4bd79af563dc10a595e94
2018-04-06 20:51:28 +00:00
Jacob Trimble f13acd6ac5 Fix ABR selecting key-system restricted streams.
ABR should not select key-system restricted tracks since we can't play
them.  Rather than updating AbrManager to do it, the Player should
just filter out the restricted tracks so a custom AbrManager doesn't
need to worry about it.

Change-Id: I5fa5cdcd9a035136fdccf9bee1a54752a0cacf1f
2018-04-04 14:50:57 -07:00
Joey Parrish 0c217391c9 Add alwaysStreamText config
This will allow text streaming to work correctly with browser native
controls.

Closes #1332

Change-Id: If11ba67957babad8dea23759aab9004d891aaf6b
2018-03-15 03:49:44 -07:00
Joey Parrish b27ea82e7f Allow Player to attach/detach from video
This adds attach/detach methods to replace the media element in the
Player constructor.  Now applications can take back control of the
media element or provide a reference later in the Player's life cycle.

This also allows applications to decide whether or not to set up
MediaSource in advance, through an optional argument on attach and
unload.  The default will be to set up MediaSource in advance, which
maintains current behavior.  This advanced setup of MediaSource can
improve load latency later.

This change also introduces async/await for the first time in the
project, which required changes to eslint config, Closure build
arguments, Babel & Babel-polyfill setup, and the esprima parser used
by our extern generator.

The use of async/await will improve readability in many places, and
these infrastructure changes to enable async/await should also unblock
issues #1336 and #1337.

Closes #1087

Change-Id: I0d6b4e0e2af27a6520a3d070fa92b7139b2cb8b0
2018-03-06 22:19:53 +00:00
Joey Parrish 02e648ccf3 Fix track selection during "streaming" event
This turned out to be three issues layered on top of one another:

First, we would fire the "streaming" event too early, before our final
stage of filtering. This meant that for multicodec content, you might
be selecting a track which will be subsequently filtered out. If the
track was no longer available after filtering, we would effectively
ignore your selection. This bug would only be triggered by multicodec
content (VP9 & H.264, for example).

This change fixes the ordering so that filtering comes before the
"streaming" event is fired.  A unit regression test was added.

Second, there was a code path in which we could ignore your track
selection. This was very easy to trigger with the "streaming" event,
and in an uncompiled build, would result in a failed assertion.

This change corrects assumptions about when we can ignore deferred
switches in the Player.  We had not previously accounted for the case
where we were still setting up the first period, which is easy to
trigger with the "streaming" event.  An integration regression test
was added.

Third, once the second bug was fixed, we could fail some assertions in
StreamingEngine and still effectively ignore your track selection.
This is because we did not reset a flag in the Player that tracks the
StreamingEngine setup state and informs when we defer switches.

This change resets the flag when we tear down streaming.  An
integration regression test was added.

Closes #1119

Change-Id: I16be372cfaf4d592ca895e41ad04333bc0b2eeee
2018-03-01 21:35:08 +00:00
Joey Parrish f48f7fd9c4 Clean up uncaught Promise rejections
- Translate uncaught Promise rejections into test failures
   (Chrome only until the event is more widely implemented)

 - Clean up uncaught Promise rejection caused by exceptions thrown
   after destroy() in:
   - CastProxy
   - CastReceiver
   - NetworkingEngine
   - StreamingEngine

 - Clean up uncaught Promise rejection caused by test cases in:
   - CancelableChain unit tests
   - DrmEngine unit tests
   - StreamingEngine unit and integration tests
   - Player unit and integration tests

 - Speed up rejection in NetworkingEngine when we should not retry

 - Add --delay-tests to test.py, to aid in debugging uncaught
   Promise rejections and other types of async test pollution

Closes #1323

Change-Id: I5a8f5702a22430929babeb071bf6650c52c5ad17
2018-02-28 22:56:12 +00:00
Sandra Lokshina 6aae04ae29 Add setTextDisplayer() method to MediaSourceEngine.
Invoke the new method after a textDisplayer's been created.

Closes #1314.

Change-Id: I19891c845905a5a3509e74a93ebfe9a9c1ea7816
2018-02-22 23:47:40 +00:00
Sandra Lokshina e8134ca4de Update currentTextLanguage and currentAudioLanguage on track change.
We've been asked to implement this to allow for a custom app
behavior where app exposes all the tracks independent of language
and role.
In that scenario changing audio language will affect current text
track and the other way around. This CL makes sure it doesn't.

Closes #1299.

Change-Id: I39a9748c033ea748173ca00bfa7168dff642a03e
2018-02-22 17:26:04 +00:00
Jacob Trimble 064089152b Remove spacing around object definitions.
This is an automated fix to be inline with Google style guides, this
was created with eslint's --fix option.

Change-Id: I860eecbc8152603e730aa17a1393f16d26b3b6fc
2018-02-21 13:35:00 -08:00
Jacob Trimble 0154dbc4d4 Convert 'var' to 'let'/'const' (6 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: I475eba0a477d13cd9201c88ad44899d521ad8991
2018-02-20 11:28:02 -08:00
Joey Parrish b7bcafccc2 Move MediaSource setup to MediaSourceEngine
This isolates MediaSource code without changing the early
initialization of MediaSource, which was designed for low-latency
startup.

Prerequisite for #1087, #880, #997, #816

Change-Id: I61acedd95d73610d3e67436d9c7767d643fe2d29
2018-02-20 18:50:54 +00:00
Michelle Zhuo 175e0b9594 Support CEA 708 Closed Captions
Issue #276.

Change-Id: If42ab04a451dc8c4c7038213b7f7c925648c3444
2018-02-03 00:03:44 +00:00
Sandra Lokshina 2b920e228f Add role selection to the demo app
Closes #967

Change-Id: I3a83a85b327901a6ab071b355e6cd890a13d7550
2017-12-18 11:31:17 -08:00
Joey Parrish f4d89cb5a1 Quick fix for Player unit tests
The player unit test setup creates a fake StreamingEngine, which
responds to a request for the current period by returning a value
captured in an anonymous function.

Because of this, any test which loads a manifest other than the
"var manifest" at the top will result in inconsistencies between
the current period known to the fake StreamingEngine and the manifest
loaded by the Player instance.

This makes sure all tests in this file are using the same "var
manifest", even if they overwrite it.

This is not the best fix.  The Player unit tests should be
restructured so that the fake StreamingEngine is always consistent
with the Player instance it belongs to.

Change-Id: Iad3b61006de3dcf902334f5348cd51fe7b5f8db4
2017-12-16 00:10:03 +00:00
Joey Parrish 8351095ac4 Do not restrict tracks when 0 key statuses are known
For some platforms and CDMs, such as PlayReady on Chromecast, there
are no key statuses.  We still get a key status event, but there is
not even a synthetic key ID.  In these cases, do not restrict tracks,
as that would result in a 4012 error (RESTRICTIONS_CANNOT_BE_MET).

Closes #1070

Change-Id: Ib3a853418629433cc9be491a0cf7981dd41a3f59
2017-12-11 22:19:00 +00:00
Michelle Zhuo 41ad98a99f Cancel text mediaState's update when not showing captions
When the user chooses not to show captions, we unload the text stream,
by canceling the update of text mediaState, and deleting the text
mediaState.

Since setupStreams_() is an async function, I'm adding a boolean
variable to mark the request of unloading text stream, so as to prevent
the race condition caused by quickly hiding and showing captions.

Closes #1058.

Change-Id: I554522b542bde5db037d74aa3a499d1ac0001151
2017-12-07 18:30:18 +00:00
Joey Parrish 5cca0e573e Remove deprecated interfaces for v2.3
Closes #1091

Change-Id: I0c15a2bfd51c3074c749d88cd66b89ba64d1fa35
2017-12-06 00:39:11 +00:00
Jacob Trimble bfe41a6da7 Don't always switch tracks in configure().
Configure should only switch tracks if the current variant can't be
played under the new configuration.

Closes #1138

Change-Id: I1acb8bdbb0c8b41252e978bd17ef52bec1095844
2017-12-05 18:33:02 +00:00
theodab ddd5c9f871 Don't return variant/text tracks before playhead
getVariantTracks and getTextTracks both check values on
player.playhead_, but don't check if the playhead exists beforehand.
This leads to problems when casting an encrypted asset; the cast status
update will check getVariantTracks and getTextTracks before the
playhead exists, and the error will make the status updates stop
coming.

Issue #1128

Change-Id: If38e586b1ea3006c01d3556216f5333d9eaf6e17
2017-11-27 09:14:06 -08:00
Michelle Zhuo 156dd3c624 Do not load text stream if caption is hidden
If the user chooses not to show captions, we do not download text
streams, so as to save some bandwidth cost.

Closes #1058.

Change-Id: Ifd0d306680de7bd683405ad9b30b3c3c5c51097c
2017-11-20 22:47:29 +00:00
Theodore Abshire cbdf76d6aa Skip manifest load retries when destroying player
If the parser is failing to load a manifest, perhaps due to being offline,
and the player is destroyed mid-load, it will wait for all of the retries to
run out before canceling. This causes a significant wait time on destroy.
This change adds an optional isCanceled callback to the request method in
NetworkingEngine, allowing requests to be made that can be canceled via a
provided callback. This is then used to quickly skip past all of the
retries, when destroying the parser.

This doesn't stop any backoff in progress, so there still might be a delay of
a second or two (depending on networking settings, of course) if you destroy
during a backoff period. That will be changed in a followup CL.

Issue #1084

Change-Id: I0b99616ed4d5be078161122532ea271e84613170
2017-11-06 18:42:33 +00:00
Aaron Vaage d49c07bcd4 Isolate conversion of variants/streams to tracks
Create functions in StreamUtils to convert from variants/text to tracks.

Change-Id: Ie142c129fb512b2d3dab5c0607e31485e9322e11
2017-11-03 18:47:08 +00:00
Jacob Trimble a2df5327c1 Add a method to allow logging in compiled mode.
We want to be able to write logs for deprecated APIs.  This ensures
that those logs appear even when we disable logging in compiled builds.

Change-Id: I1f1546049fb17967eedb1bb45a7f76d5b1809cd1
2017-10-27 23:07:23 +00:00
Aaron Vaage e6450da548 Test that clear buffer is false
When changing restrictions, we don't need to clear the buffers. This tests
checks that when we change the config to change the ABR restrictions,
we do not clear the buffers.

Change-Id: I04e360c7fdfa008d7ae9a8050974bcd28f1d3388
Closes: #1009
2017-10-27 20:08:12 +00:00
Michelle Zhuo bd37a7c161 Add Streaming Event and Manifest Getter Method
Adding an event right after the player parses the manifest, and before
initiating streaming, so that users can get the manifest information.
Adding manifest getter method in player so that customers can access
manifest information.

Closes #1043
Closes #1074
Issue #1036

Change-Id: I0016c312bacdfa86299e5df68b586f90d565cfdc
2017-10-26 11:07:55 -07:00
Joey Parrish 432aee3ee8 Fix TextDisplayer remembering old cues
Instead of destroying the TextDisplayer instance when the Player is
destroyed, it should be destroyed when the Player resets for another
piece of content.  This way, old cues are removed before we start
streaming new media.

Fixes #984

Change-Id: I9f417682a6f79eb2190404876b0bcb4b670040ad
2017-08-24 11:19:35 -07:00
Joey Parrish 6df9d162a6 Fix exception in getStats before load
Applications should be able to call player.getStats() on any
non-destroyed Player instance.  We were throwing an exception in
getStats() if called before load().

Closes #968

Change-Id: Idb32694a0502b52a4127e7179496dfd87192f017
2017-08-14 23:24:48 +00:00
Michelle Zhuo d67764b5ff New Error Code for Content unsupported by Browser
Previously "UNPLAYABLE_PERIOD" exception is thrown when a browser
doesn't support the container or codecs in a piece of content, which is
confusing to developers and customers.
Changing it to "CONTENT_NOT_SUPPORTED_BY_BROWSER" exception.

Test manifest:
https://media-ci.foxford.ru/dist/hls-issue/issue.master.m3u8

Closes #868.

Change-Id: Ied135b687190919abbeb1561c2bff36a7203136e
2017-08-04 11:07:07 -07: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 a2a7c2f4ad Add player.isAudioOnly()
This simplifies detection of audio-only content and makes the process
a little more obvious.

Closes #942

Change-Id: I89b599fb8c8915c9e1b45d2f9b81a3ac7193e5ef
2017-07-31 23:03:51 +00:00
Joey Parrish 015b4f456f Revert timeline correction code.
This reverts commit 478fb1a473
("Detect and attempt to correct timeline sync issues") and commit
4334b6ea90 ("Add mediaSegmentReferences
 to shakaExtern.Stream").

Timeline correction only addresses one class of broken live content,
while actually making it more difficult to diagnose other classes of
broken live content.

Issue #933

Change-Id: Ie71b8a45600ed0994626f53268fb90e336c3c62b
2017-07-31 10:42:33 -07:00
Joey Parrish 478fb1a473 Detect and attempt to correct timeline sync issues
This uses the new mediaSegmentReferences field, if available, to
detect and attempt to correct common timeline sync issues.  If the
most recent segment is outside the availability window, we make a
guess and move the window to align with the segments.

Closes #933

Change-Id: I1b9c444f82f9c526caf7a6942a758493d0adf9be
2017-07-26 07:22:11 +00:00
Joey Parrish 4334b6ea90 Add mediaSegmentReferences to shakaExtern.Stream.
This will allow us, in many cases, to detect time sync issues in
content by comparing the media segment references to the presentation
timeline.  If the references are outside the timeline, it may indicate
a common form of bad content, and we may be able to attempt to correct
it.

In some cases, the references are not available upfront.  We can't
detect time sync issues in DASH with SegmentTemplate+duration, because
the references are not explicitly described by the manifest.  We can't
detect time sync issues in DASH with SegmentBase, because the segment
index requires additional fetching and parsing.  (SegmentBase is not
used with live content, so this should be a non-issue.)

This only introduces the new data, but does not use it for detection
or correction yet.

Issue #933

Change-Id: If70b1bdbd3b08a7c8b7ae296da209737492dfe17
2017-07-25 20:13:42 +00:00
Joey Parrish 3062b72390 Tolerate bandwidth of 0 or missing bandwidth
Although bandwidth is a required attribute in DASH and a bandwidth
value of 0 makes no sense, we can tolerate such content in many cases
and play it regardless.  This used to work in v2.0.x, but stopped
working in v2.1.0 through v2.1.5.

Closes #938
Closes #940

Change-Id: I0c9b8eba923971f00946282cd8c138f68827961f
2017-07-25 08:24:16 +00:00
Joey Parrish a1bdb03769 Fix backward compatibility for AbrManager
The old interface is deprecated and will be removed in v2.3.
It should still work (with a warning) in v2.2.x.

Change-Id: I8f8bf092683f6c91ba17175316b463f537b993d2
2017-07-18 17:43:10 +00:00
Joey Parrish 4c85652768 Fix TextDisplayer exception before load
Before load(), there is no TextDisplayer instance yet, so
isTextTrackVisible() throws.

Change-Id: I020ddc5e08bfd78025f7d4325c669cb46e418a41
2017-07-17 16:01:43 -07:00
Sandra Lokshina c70367dc97 Separate text parsing and display logic.
Closes #796.
Closes #923.

Change-Id: Ifc2017b40a0fb570103f0fed7bc130aa24819e9f
2017-07-17 21:39:59 +00:00
Sandra Lokshina af252c94e7 Add bandwidth info to switch history and make it accept variants.
Change-Id: I3927697cd820dcdd681de39eca3517b81150d7df
2017-07-12 15:18:18 -07:00
Sandra Lokshina b3586c193a Add stream bandwidth info to variant tracks.
Closes #834.

Change-Id: I3af66a227ad09f1686a7ca3f545c2bf9683d3c24
2017-07-07 10:20:54 -07:00
Theodore Abshire 54d2914791 Filters out single-stream variants.
In situations where there are variants with video and audio, and variants
with only one of the two, this filters out the less-complete variants.
This removes the possibility of the player switching to an audio-only
variant and breaking MediaSource. It also solves the regression where
audio-only variants have the lowest bandwidth and thus are chosen
preferentially on weak connections.

Closes #824
Closes #861

Change-Id: Ic37543d98962ddd83a85224e26e5225d142b844e
2017-07-06 15:46:28 -07:00
Jacob Trimble 78fc6d9b36 Disallow unknown properties (2/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: I48335fc6659d3c33a6d55b00d087b59410c79cf7
2017-06-27 19:47:42 +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
Michelle Zhuo f09999aa80 Add channel count information for HLS audio tracks
Adding the count of channels, as a new field for tracks and streams.
Used for HLS audio tracks.

Resolves #826.

Change-Id: I1448b4a8cfaf6dd798670bb2f0f3981d6c7e40c3
2017-06-22 11:34:36 -07:00
Jacob Trimble bb621714e9 Cleanup Player unit tests.
Change-Id: Ia0a6e9a3493c247cc8f03a2d9a02f5a817786dc1
2017-06-21 12:55:09 -07:00
Jacob Trimble 4aa2430a1b Fix key status problems with EME polyfills.
Our EME polyfills give a key status with a Key ID of '00' (a single 0
byte).  This breaks the Player logic for restricted tracks since it
assumes that those are not playable.  When we get this Key ID, we should
treat the key status as a global status, not for that specific Key ID.

Closes #884
Closes #890

Change-Id: I392550227274fb321d2c223eb8d483a0a4733186
2017-06-21 19:42:05 +00:00
Joey Parrish 434f1bf9b0 Choose lowest bandwidth codecs
Before asking AbrManager to choose streams, we should choose codecs.
Choose the most efficient codecs, and do it after we have filtered
out the codecs that the platform cannot use.

Closes #841

Change-Id: Ifbdd22b33254d4584f77db6456ab238f7c04c755
2017-06-05 18:00:23 +00:00
Matias Russitto ace0e8cf49 add video and audio stream IDs for getStats().switchHistory (#846)
Closes #785, #823
2017-06-05 10:29:55 -07:00
Joey Parrish 5f33c119dc Clean up FakeStreamingEngine
- Make FakeStreamingEngine injectable by removing Period argument
   - FakeStreamingEngine can now have its spies manipulated before we
     call player.load().
 - Do not poke into player's manifest_ and streamingEngine_ members in
   chooseStreams(), since load() sets those already.
 - Instead of setting activeStreams in the constructor, set them in
   init().  This is a more accurate fake, and this is important for
   upcoming tests related to early filtering, since filtering takes
   into account the active streams.

Leads into a fix for #841

Change-Id: Ia893053490cde819e32907c7a1a2030c29022f62
2017-06-05 16:48:08 +00:00
Joey Parrish bc56744812 Cleanup in Player and MSE unit tests
- Fix isTypeSupported override in MSE unit tests
   (Should not be a prototype method)
 - Add isTypeSupported override in Player unit tests
 - Fix a Player test that used to pass for the wrong reasons
   (MSE type filtering instead of EME type filtering)

Change-Id: Ibb72957f3bdff62923f2b235e9b9e9a598353912
2017-06-05 03:23:15 +00:00
Joey Parrish e8af210dab Clean up config merging, type check certs
- cleans up config merging now that abr.manager has been removed
   from the config
 - uses thing.constructor == Object instead of
   typeof(thing) == 'object', for better detection of anonymous
   objects
 - adds a default (empty) server certificate for type-checking
 - treats empty certs the same as null (no cert provided)

Fixes #784

Change-Id: Ie833a1b3bf484d5f12f3ebf6d513ed51740bdc44
2017-06-05 03:21:48 +00:00