Commit Graph

53 Commits

Author SHA1 Message Date
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 c6c6d05810 Move text-related files into their own directory.
This change creates a lib/text directory and moves all files
with text-related logic to it. It also lays the ground for
separating text parsing and display logic. (That change will
introduce even more files with text-related logic which will
crowd lib/media directory).

Issue #796.

Change-Id: I65ac134020a0126ff02a8f2067beb73870232e65
2017-06-06 18:21:09 +00:00
Joey Parrish bf404d4fbc Check for MediaSource.isTypeSupported
On at least one TV platform, isBrowserSupported returned true in spite
of a lack of MediaSource.isTypeSupported.  (See #804)  This adds a
check for that required method.

Change-Id: I4e68b66700508c1b3eafc9a97901f7d573ecbb80
2017-05-16 11:36:38 -07:00
Jacob Trimble e5ce395f37 Implement gap jumping.
The bulk of the logic for gap jumping is handled in Playhead.  It
tracks the current buffered ranges and jumps over any gaps that appear.
It listens for a special browser event ('waiting') for when the video
element runs out of playable frames.

This change also removes the logic for jumping gaps at the beginning
of the timeline.  This is handled by the more general gap jumping
logic and works cross-browser.

Finally, this updates the buffering logic to only count the amount of
content buffered (i.e. ignoring the gaps).  This fixes some bugs where
gaps in the content can result in StreamingEngine buffering forever
since it thinks only a little is buffered.

This includes full implementation of the logic, but this doesn't close
the issue since there aren't any integration tests yet.  Those will
be added next.

Issue #555

Change-Id: Id99eb9fe469e8cf2c7464a3d70c3733791e806e0
2017-04-17 18:15:23 +00:00
Aaron Vaage 9a86d0460f Redefining Text Parsing Plugin System
The text parsers were all stateless. This caused problems with MP4
VTT as the timescale is needed later on for other boxes. This changes
parsers to carry state.

How time is referenced with the text parsers is not clear and has
caused confusion. In v2.0.1, we introduced the useRelativeCueTimestamps
option to control the behavior of our WebVTT parser. We decided in #480
(comment) that we would remove this option in v2.1.0. All WebVTT
timestamps in v2.1.0 will be relative to the segment time. This change
creates a new time context interface that will be used to help limit
the confusion around how time is communicated.

Closes #726

Change-Id: I67409608c35d2d5abb8b8b25529859cb37f8f0a8
2017-04-05 13:41:27 -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
Jacob Trimble e7ce5a7f35 Allow small gap at start when buffering.
We allow small gaps ahead of the playhead in StreamingEngine.  But this
is not mirrored in Playhead.  We should exit a buffering state even
when there is a small gap.

Note this is unrelated to the issue where Chrome won't jump gaps after
a seek.  In StreamingEngine, we don't allow this gap when seeking;
however, this change involves normal playback and doesn't involve that
bug.

Change-Id: If091994ee1a93965836e99cdb41873afb18d0fd4
2017-03-22 21:22:24 +00:00
Sandra Lokshina 0b12937520 Replace content type strings with constansts.
Change-Id: I4fda583915766b40ee7a5c7451d037077d9f2582
2017-03-08 21:41:59 +00:00
Jacob Trimble 43380239ba Call abort() before setting timestampOffset.
When appending MPEG2-TS segments, we seem to always enter a
PARSING_MEDIA_SEGMENT state in the SourceBuffer.  While we are in this
state we can't change the timestampOffset.  This means that we can't
change Periods or adapt to a different resolution.

To fix this, we call abort() before setting the timestampOffset to
reset the state.  Because abort() also resets the appendWindowEnd,
this merges the two operations so we set timestampOffset and
appendWindowEnd at the same time (since we do already).

Issue #279

Change-Id: Icd893ded9e3137179f262ba10e55e41d06ec5a77
2017-02-17 11:51:06 -08:00
Joey Parrish 25c500242b Refactor pipeline flushing
Rather than flushing implicitly when clearing the buffer, flush
explicitly in some circumstances.  In particular, do not flush on
unbuffered seeks.  Flushing uses seeking, so flushing on seek
creates a race condition that may cause a nasty loop.

Issue #569

Change-Id: I61489b13100b56a5316a8313a1b2782dc242f858
2016-11-28 18:54:05 +00:00
Joey Parrish 4c9ee5db76 Allow text parsers to change during playback
Text parsers can easily be changed during playback, unlike the
browser's media decoders.  Whenever we change text tracks,
reinitialize the text parser.

This also removes restrictions on text tracks of different types
when we filter manifests.

Closes #571

Change-Id: I3c243dde951cd04554c2fa1be2c8ebf06988791b
2016-11-21 17:50:08 +00:00
Joey Parrish 894c56d3c9 Remove suppression of "unnecessaryCasts"
This no longer seems to be needed.

Change-Id: I8f9ed03f97b235d4652930745d4416f6c8f77445
2016-11-04 19:40:55 +00:00
Joey Parrish a4bc7f36d7 Add additional codecs to the MediaSource probe
Change-Id: Ia41fe1514020a86f989aed8a7ca19c98d6be9283
2016-11-03 23:27:28 +00:00
Sanborn Hilland fff9892373 Add config option for using segment relative timestamps for VTT (#542)
* Add config option for using segment relative timestamps for VTT

Fix for #480

* Make useRelativeCueTimestamps a non-nullable param

* Update tests for the new useRelativeCueTimestamps param

* Move period relative timestamp deprecation warning to vtt parser

* Log warning only if using absolute timestamps in text cue

* Fix vtt text parser test
2016-10-24 11:22:54 -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 96045b5ff2 Flush Chromecast pipeline after clearing buffer
To work around a bug in Chromecast, seek after clearing the buffer.
This forces the device to flush the pipeline and remove any decoded
data from the old representation.

Closes #544

Change-Id: I3c34d344bfd856b429a360fc41ce7288791716bb
2016-10-19 14:00:21 -07: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
Joey Parrish 8c7c74e950 Polyfill Safari 9 MediaSource bugs
This adds a polyfill for a Safari 9 MediaSource bug where calling
abort() on SourceBuffer causes the decoder to fail.

The reason we call abort() at all is to reset the decoder and smooth
segment transitions on Chrome, Firefox, and Opera.  Safari does not
seem to have this problem in the first place, so it is fine to
completely stub out abort().

Issue #446

Change-Id: Icbaaa3e9ce5372efdee937ddc4cf94a27dce6a47
2016-07-29 18:42:31 +00:00
Joey Parrish ab64c76ee9 Fix MP4 text parser integration
* removes an assertion which is no longer valid
 * corrects the registration of the VTT in MP4 parser
 * fixes some type issues in TextEngine

Change-Id: I0b7f41f01e5d7be2932c86a56f3cdfd6a53d04cb
2016-07-19 23:03:16 +00:00
Sandra Lokshina 259777fe9f Implement parser for segmented TTML in MP4
Closes issue #278

Change-Id: I2f454a2c2f63d8ce6682cd4593c1d843b2967978
2016-07-13 21:49:43 +00: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
Jacob Trimble 2c3dccc45e Fix bug with text engine buffered ranges.
Based on pull request by @baconz.  Before, when appending segments,
TextEngine was given the segment times and then added the timestamp
offset to get the real time.  However, this is incorrect as we want
the time relative to the presentation timeline.  So we should only be
adding the period start time (the timestamp offset also includes PTO).

Closes #411

Change-Id: I92582d1cda034daef5e8ce2d7b79deafa0ddf828
2016-07-08 16:21:23 -07:00
Joey Parrish 422f5aa5cb Correct usage of jasmine's toBeCloseTo matcher
The second argument is meant to be the number of decimal places to
which the value must match, not the maximum difference.  So using
"0.1 decimal places" meant the maximum difference was actually 1.25.
You must pass "1" to get a maximum difference of "0.1".

This also adjusts some of the expectations to fix affected tests.

Change-Id: Ibc1223297011063e3e4f3fff0ba64fde06292128
2016-07-07 17:52:46 +00:00
Andy Hochhaus 87a62d717e Add missing goog.require() dependencies 2016-06-25 15:45:15 -07:00
Jacob Trimble 5102f54120 Make Player.support synchronous and add support plugin system.
Now there is a new synchronous method Player.isBrowserSupported.  This
will detect basic support and return a boolean.  The support() method
has been renamed to probeSupport() and should only be used for
diagnostics.

Also added a plugin system to Player support testing.  Now a plugin
(e.g. offline) can add extra info to the output of probeSupport().

Closes #388
Closes #389

Change-Id: I313a41d9f123871272f1395aeb99c980df1f4bae
2016-06-02 21:57:38 +00:00
Timothy Drews ddbc13d4f8 Handle QuotaExceededError from appendBuffer().
MediaSource may throw QuotaExceededError if it cannot append a
segment. Now, StreamingEngine will catch these errors from
MediaSourceEngine and reduce the buffering goals to avoid
encountering additional errors.

Closes #258

Change-Id: I1d957831424a4a6fb2681ee2c4f9ed7db7bf1711
2016-05-12 18:12:17 +00:00
Timothy Drews a8a2ff9f0b Handle exceptions thrown by buffered property.
This mitigates "wrong error type" failures when accessing
the buffered property after a previous MSE error was
encountered.

Change-Id: I5ae9f6f689e17a04fc6d855a8bb179d40a2ddea0
2016-05-06 18:32:29 +00:00
Timothy Drews 7ab8970852 Tolerate spurious 'updateend' events.
Some browsers/platforms emit 'updateend' events at unexpected
times.  Instead of failing right away when encountering these
events, just ignore them.

Change-Id: I71d1e5aba2591b1890d49dd746e4d20a5be71cf4
2016-05-04 07:46:01 +00:00
Joey Parrish 8f14f3c91e Fix VOD with positive drift
This adds a tolerance for certain buffered range checks.  The browser
will jump small gaps, so we should not let small gaps interfere with
our buffering algorithm.

This also clamps lookup times to zero to avoid errors thrown on
positive drift.

Fixes #320

Change-Id: I2de9ef4850a96cac29bbcacaeb75285a358c230f
2016-04-04 23:18:20 +00:00
Jacob Trimble 8b85e58f73 Add several utility functions.
Change-Id: Ifbd2582747d2cb54d4abda789b0989b7a6b77aa6
2016-03-29 20:17:44 +00:00
Joey Parrish 32139729ad Blacklist Safari 8
Safari 8's MediaSource implementation is incomplete (missing
appendWindowEnd), so we can't fully support it.

Since it is too complex to detect the missing feature directly,
we blacklist Safari 8.

Closes #169, #294

Change-Id: I7ef963922ba9e621b3187fcaae092dc56a3565af
2016-03-16 21:21:30 +00:00
Jacob Trimble 19973d63f4 Changed copyright headers from 2015 to 2016.
Change-Id: I429ff27e4794c03b7ea392e38415075077f9bfb1
2016-03-15 16:32:13 -07:00
Joey Parrish c281403237 Destroy TextEngine
This cleans up cues between playbacks.  Otherwise, text from one video
shows on the next.

Change-Id: I5d981d3afe23995968ace6bed690f6a7928a98c4
2016-03-14 16:15:56 -07: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
Joey Parrish edc9bc8d49 Reject with Error objects in MediaSourceEngine
Instead of rejecting Promises with either exceptions or empty error
events, build full Error objects in MediaSourceEngine.

Change-Id: Ib4317f0ffe66c0292b3560f89f7a07e74e474dd3
2016-03-07 21:53:32 +00:00
Joey Parrish c2dc1d8958 Fix off-by-one-frame issues with MSE window end
This adds a fudge to appendWindowEnd so that the final frame in a
period won't be dropped and a gap will not appear between periods.

Change-Id: I9ded5237c949a3bae7e2c4081b32fa33938d9583
2016-02-17 22:55:50 +00:00
Joey Parrish cd2d25cbb2 Convert TextSourceBuffer to TextEngine
This changes the text APIs to correctly handle buffered ranges of
segmented text.

b/25517444

Related to issue #150

Change-Id: I3a11b87e8d93376a5012566deb3bf0d015f52391
2016-02-17 00:19:49 +00:00
Timothy Drews a0c35403e5 Add StreamingEngine tests and fix several bugs.
* Tidy up unit tests, and add more eviction tests and drift tests.
* Add integration tests.
* Handle end-of-stream and end-of-Period scenarios when segments
  are not perfectly aligned to Period boundaries.
* Use segment receipts to determine which segment to buffer next.
* Handle drift with eviction and other drift corner cases.
* Handle additional errors and improve overall robustness.

Change-Id: Ib57a255cda7a6e8c5857eb82accc14697983b893
2016-02-13 01:57:09 +00:00
Joey Parrish d03021603b Make types nullable, use HTMLMediaElement
Non-nullability on some types forces us to use casts everywhere, at
which point the compiler is just trusting us.  So they might as well
be nullable and save us some typing.

Also, change HTMLVideoElement to the more general HTMLMediaElement.

Change-Id: Iaf111835bfbf230b99ad8cd7a7a06a6caffd16bc
2016-02-10 19:00:42 +00:00
Joey Parrish 17fdcc61b9 Do not assume an initial duration of 0
This brings the MediaSourceEngine integration tests more in line with
reality.

Change-Id: I2a9446071e937e58c3878250aa1ece2c8a750b93
2016-02-09 11:28:36 -08:00
Donato Borrello 5fb0bb4f12 Fix typo
Negotiation was the intended spelling
2016-01-29 17:57:15 -05:00
Timothy Drews a4ff2711f2 Add StreamingEngine and Playhead.
Closes #101
Closes #186

Change-Id: I8d1a8d6c0f8cfb5abdd81a149318377282b2bea0
2016-01-15 14:30:27 -08:00
Joey Parrish dea1021a9b Restrict SourceBuffer.remove() for IE11
This makes sure that remove() is called in a way that is compatible
with IE11.  For more information, see #251.

Change-Id: Iabe752713ba74c7bf516b4e7b93bc83cfccdd481
2016-01-11 17:46:36 -08:00
Joey Parrish b6a39b3e92 Add throws QuotaExceededError to MediaSourceEngine.append_
Relates to issue #258

Change-Id: Id83b1df13f876e565ad481169af11d65902047d6
2016-01-08 17:04:18 -08:00
Joey Parrish e798f060dc Add property docs to internal typedefs
We will be transitioning toward a new way of documenting record
typedefs.  Each record will be annotated with 'property' for each
field in the record.  This results in better output from jsdoc.

This covers all internal record types.  External records will be
handled in a separate CL.

Change-Id: I2ab93015bfc9db01b4b6d474b608709c99fd70cd
2016-01-04 12:36:44 -08:00
Joey Parrish 1d1a0fcb46 Enable all compiler errors
This also cleans up compiler errors for:
  - Things required but not used
  - Things used but not required
  - Write-only local variables

We are suppressing the 'unnecessaryCasts' error in specific places
where it is, in fact, necessary to convert between unrelated types
for polyfills and work-alikes.

Change-Id: I155c746116f95383ea0a9caf9239fadccd8601af
2015-12-11 13:30:44 -08:00
Joey Parrish c9235f859c Add support-testing framework.
Support testing is hierarchical.  Player.support returns an object
mapping out the support present in various parts of the system.

This creates a shell for Player and DrmEngine, and introduces support
tests for MediaSourceEngine, ManifestParser, and DrmEngine.

This also adjusts the way support checks are done for text types, to
allow for expansion into MP4-embedded text types and other segmented
subtitle types.

Text changes related to #150 and #146

Change-Id: I707f01ba52cba6262ee89bee2c1f28d24aca4655
2015-12-10 20:00:22 +00:00
Joey Parrish c934f426d8 Add new error type
This error type will be used for all internal errors, and will rely
on numeric error codes which can be easily checked by the application.

This also changes PSSH parsing to throw on errors instead of retaining
partial data.

Issue #201
b/25306826

Change-Id: I19d23d99d4ee72cb31fe5f233bac57a3a9cfc283
2015-12-04 10:26:08 -08:00
Joey Parrish 9dbd6e6549 Add messages to all assertions
This makes debugging easier when an assertion fails.

Change-Id: I362e58706c71a12cffcda84dcd0b9ad281c51f30
2015-12-04 02:17:28 +00:00