Commit Graph

380 Commits

Author SHA1 Message Date
michellezhuo 109973c7e2 feat(LL-HLS):Enable preload hinted segments
LL-HLS hints a resource that is needed to playback in the upcoming
update. It's available for request, and may not be available for
download yet.

A preload hinted resource is either a partial segment, or an init
segment. If it's an init segment, treat it the same way as the Map tag
in ManifestTextParser.
A preload hinted segment contains no duration information, so its
start time and end time are the same. It will be replaced by a partial
segment in the next update.
We should fetch and append the preload hinted segment the same way as a
partial segment.

Issue #1525

Change-Id: I1e30f216ecdc843c3cd01681629a8886383d0b22
2020-07-08 22:11:06 +00:00
michellezhuo 965ef453b6 feat(LL-HLS):Enable Partial Segments streaming
Changed SegmentIndex and SegmentIterator to iterate through regular and
Partial SegmentReferences.

SegmentIndex:
merge(): Find all the old segments after the first new segment's start
time, and replace the old ones with new segments.

SegmentIterator:
Use the currentPosition and currentPartialPosition pointers to iterate
through the two-layer arrays.
current(): Get the current SegmentReference, and get its current Partial
SegmentReference if it has a Partial Segment list. Move to the next
regular segment if we reached the end of the current segment's partial
list.
next():
If the regular segment has a partial list, go to the next Partial
Segment. If reached the end of the current partial list, move to the
next regular segment.
If the regular segment doesn't have a partial list, move to the next
regular segment.

Issue #1525

Change-Id: Icb7f49e50314f15ea40bf3a74d008191ed1a9a6c
2020-07-06 00:34:55 +00:00
Muhammad Haris d53fbaeeeb fix: Fix disappearing captions with certain input patterns (#2674)
When the subtitles are turned off, unloadTextStream() on streaming engine is called, but currentTextStream is never set to null. When the captions are turned back on, a check in player.js sees that the current text stream is not null, so it assumes it exists, and is ready to go. Thus captions are never loaded.

Clearing (setting to null) the current stream on unloadTextStream ensures the text stream is properly initialized the next time it is called, and in a state so that captions can resume being parsed.

After further investigation, it seems that the unit tests are written in a way that assumes that the text stream is nulled when unloadTextStream is called. So this fix is definitely something that we assume already happens.

Closes #2671
2020-06-24 13:12:09 -07:00
Muhammad Haris d383047de1 fix(CEA): Fix missing captions when switching streams (#2672)
During video playback, if the user switches the caption stream (e.g. CC1 to CC3 which changes languages), the first caption in the next fragment is missing.

In fragmented MP4s, the end time of a caption is determined by the start time of the next caption. Thus for the last caption in a fragment, the end time cannot be determined until the next fragment is parsed.

Before this fix: the clearing of the caption stream was being called from a chain of function calls originating from clearBuffer_() on the Media source engine. But clearing a buffer and resetting a caption stream are two independent operations. As a result, the caption parser was being reset (its buffer cleared) during video seeks, and during stream switches. This makes sense for video seeks, because the end time of the last caption in the fragment can't be determined if the entire presentation timestamp changes. However for stream switches, resetting the parser doesn't make sense. Clearing the caption parser during a stream switch would actually get rid of the last caption in that fragment (which wasn't emitted since its end time wasn't determined yet), and we would lose the data, causing the problem.

The fix is to reset (and hence clear) the caption parser during seeks, but not during stream switches.

Issue #2648
2020-06-23 16:40:35 -07:00
Muhammad Haris e8f24ece6f Created MP4 Box parsers to parse data for common box types (#2649)
Issue #2648
2020-06-15 17:35:38 -07:00
Joey Parrish b84061a764 build: Upgrade the compiler
This upgrades the compiler to the latest release and fixes some type
errors in the tests found by the new compiler.

Change-Id: I3a555cbdfc94c51fb0683f8397c6adb8ea43f120
2020-06-11 22:03:47 +00: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 02379d354e fix: Abort pending requests in StreamingEngine.destroy
Closes #2619

Change-Id: I10cc2e9567720c9d021038a4da3c26b6857ec709
2020-06-08 21:28:28 +00:00
michellezhuo 9584804b6c Fix HLS live stream freezing
When we get a playlist update, we replace the list of SegmentReferences
in the SegmentIndex. However, the position pointer in the
SegmentIterator of the SegmentIndex is not updated, and still points to
the index of the old SegmentReference list. Thus, the current
SegmentReference may be null.
We should merge the new SegmentReference list with the old list, and
mark the offset of the list.

Closes #2605

Change-Id: Ia6740e1173ac48467e7b141257cc9c6148e30a0c
2020-06-02 15:57:37 -07:00
Joey Parrish ba4f1d5468 Fix type info for StreamingEngine test fakes
The StreamingEngine tests use various fakes that did not have strong
type info before.  The new Closure Compiler won't allow this, and for
good reason.  Cleaning up the type info exposed a few ways that we had
left out important things or failed to remove methods that are no
longer on the types we're faking.

We also had some fakes for StreamingEngine tests that were redundant
with strongly-typed fakes that already existed in shaka.test.  This
deduplicates them.  The fakes for StreamingEngine are now just
instances of the other fakes with specific behavior attached.

Issue #2528

Change-Id: I0da67bea462e855fcfcb1b391fe83027ffa70702
2020-04-30 19:32:30 -07:00
Joey Parrish 11f3347a48 Fix static method aliases
We used to alias static utility methods by assigning the method itself
to a local variable.  This is not allowed by the new Closure Compiler
release that we are adopting, and for good reason.

The old compiler did not understand the use of "this" in static
methods, but the new one does.  And it turns out that when we start
using "this" in static methods (see #2532), aliasing the method itself
can break everything.

When you refer to "this" in a static method, it refers to the class.
This is really useful in utility classes that have private static
methods they use to perform common tasks.  However, just as it ruins
the value of "this" to alias an instance method, the same is true of
an ES6 class's static method.

The fix is to always alias the class instead of the method.  The new
compiler will simply not let us get away with the old way any more, so
regressions after this are unlikely.

Issue #2528 (compiler upgrade)
Issue #2532 (static "this")

Change-Id: Id800d466e639c7cbcf4aa6fbb05114c772a2229f
2020-04-30 19:28:53 +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 342d35f4f9 Fix issues with nullability of numbers
Various issues with the nullability of number types led to various
fixes, including:
 - defaulting a nullable number to 0 to avoid propagating a null value
   through calculations
 - adding an assertion or runtime check that something is not null
 - moving an existing null check to before the calculation
 - returning early on null during an iteration
 - changing a nullable number to non-nullable
 - defaulting to NaN instead of null

These issues were caught by a compiler upgrade.

Issue #2528

Change-Id: I86d516c74a42ee3624c33d7513d2d4c76d3ea589
2020-04-30 16:00:00 +00:00
Joey Parrish 4dc2c65578 Add type assertions for Errors
In many places, we check error codes on shaka.util.Error.  But the
compiler doesn't know that what is caught in "catch" is that type, so
we add type assertions.

In some cases, we know that other types may also be thrown, so there
are also some runtime checks.  Some of these had to be refactored to
allow the compiler to correctly infer types.

Change-Id: I053bd7e96213c689aae3889315052dd402124690
2020-04-29 10:11:21 -07:00
Joey Parrish e24fec4b08 Flatten periods
This creates a new utility used by DashParser and old offline DB
formats to combine Streams across Periods.  This allows multi-Period
DASH content to be played without period-specific structures in the
manifest format, StreamingEngine, or Player.  This also makes the
Tracks stable across Periods.

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

Change-Id: Icb04c8e47e36eacf7ac024a5063130d85a115e54
2020-04-09 19:22:16 +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 5d07b5fbb7 Fix flake in high playback rate test
Something weird happens on some platforms (variously Chromecast, IE,
legacy Edge, and Safari) where the playhead can go past duration.  To
cope with this, don't fail on timeout.  If the video never got flagged
as "ended", check for the playhead to be near or past the end.

Also, wait for playback to begin before increasing the playback rate.
This improves test reliability on slow platforms like Chromecast.

Change-Id: If7d70de95b75e602853ec77ad1c285c118875db4
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
Joey Parrish bf5e0e254b Fix SegmentIterator after evict
After evicting segments from a SegmentIndex, SegmentIterator should no
longer start at 0.  So instead of starting at 0, start at the earliest
position, which is returned by find(0).

Change-Id: I512ffb10a7f09f52930c5afbd783db063e9ebd66
2020-04-02 21:46:13 +00:00
Jacob Trimble fda84c0343 Use waitForMovement in DRM tests.
This could help test failures on Windows since the video doesn't start
playing after the 5 seconds.  If it fails, we'll also get more
debug information for it.

Bug: 146050219
Change-Id: I1be5156350a591762022664feb05975470bbf92d
2020-03-27 15:56:58 +00:00
Joey Parrish 1ab3f9c6db Remove position from SegmentReference
As part of Period-flattening, I'm trying to remove our dependence on
the "position" field of SegmentReference.  With that eliminated, we
can more easily concatenate Arrays of SegmentReferences without
modifying them.

 - Make SegmentIndex iterable
 - Add specialized seek() and current() methods to SegmentIterator
 - Remove position from SegmentReference
 - Make positions in SegmentIndex API stable without field in
   reference
 - Remove brittle hard-coded positions in tests (except SegmentIndex
   tests, where they would be hard to avoid in testing methods
   separately)
 - Use SegmentIterator in StreamingEngine to track the next segment
   between switches

Issue #892 (refactor StreamingEngine)
Issue #1339 (period flattening)

Change-Id: I666cc21249c34ee6cbc138a59109d9f1159fa127
2020-03-23 10:09:35 -07:00
Joey Parrish 6202b9372e Revert "Move next-segment tracking to SegmentIndex"
This reverts commit 235e4e11ad.

The effort to remove SegmentReference's position field will be handled
in a different way.

Issue #892 (refactor StreamingEngine)
Issue #1339 (period flattening)

Change-Id: I62b115137abc89f498b30467e574b0401dcad05d
2020-03-23 10:09:35 -07:00
Joey Parrish 235e4e11ad Move next-segment tracking to SegmentIndex
As part of Period-flattening, I'm trying to reduce our dependence on
the "position" field of SegmentReference.  If it can be eliminated, we
can more easily concatenate Arrays of SegmentReferences without
modifying them.

SegmentIndex can now track the last reference you asked for and
iterate through the list of references.  This means we don't need the
"position" field of SegmentReference, which means we don't need to
know positions in advance or globally.  StreamingEngine will no longer
use position to request segments.

The old methods find(time):position and get(position):SegmentReference
have been replaced with seek(time), current(), and next(), all of
which return a SegmentReference and maintain an internal pointer to
the "current" reference.  Care has been taken to maintain that pointer
during the evict() and fit() operations.  Recent changes to merge()
made sure that the pointer does not need to change during that
operation.

All test updates are related to the SegmentIndex API change, not
changing expectations or behavior.

Issue #892 (refactor StreamingEngine)
Issue #1339 (period flattening)

Change-Id: I1682dcc2dd625c6e390711538e46d31e6eb6cea8
2020-03-11 18:14:14 +00:00
Joey Parrish 3cdb9c8e16 Simplify SegmentIndex merge
As part of Period-flattening, I'm trying to reduce our dependence on
the "position" field of SegmentReference.  If it can be eliminated, we
can more easily concatenate Arrays of SegmentReferences without
modifying them.

There has long been a comment at the top of SegmentIndex's merge
method stating that we only ever extend the references, but never
interleave them.  The code, however, is structured in such a way that
it could interleave them.  This could cause the offset of a given
SegmentReference in the Array to change, which would be counter to the
comment about only ever extending the list.

This change simplifies merge() so that it can only ever extend the
array of SegmentReferences.  This will guarantee that their offset
within the Array will not change during the merge operation.  This, in
turn, enables further SegmentIndex changes to move "next" segment
tracking out of StreamingEngine (where it is based on the "position"
field of SegmentReference) and into SegmentIndex (where it could be
based on offset into the Array of references).

It removes one test related to PR #838.  This test was about our
ability to update the position of the final segment in a list.  This
doesn't seem to make a lot of sense, and we're going to stop relying
on segment position anyway.

Issue #1339 (period-flattening)

Change-Id: I2067e2266cf2d02c0e6350d6b57d74f9ed1b27d3
2020-03-11 18:14:14 +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
Álvaro Velad Galván dcf471d85c Calculate approximate segment size based on bandwidth (#2288) 2020-02-17 13:05:38 -08:00
Jacob Trimble c8043f3916 Allow configuring when to fetch prev segment.
We fetch the previous segment in Live streams to combat differences
between the manfiest times and the segment times.  Now this can be
configured so apps with correct manifests can avoid the extra segment
request.

Also, we'll update the buffering state when a segment appends so we
leave the buffering state sooner.

Issue #2291

Change-Id: Id12c8132dc11739e4c8d42cb1f08e6ae7da1a966
2020-02-15 01:52:05 +00:00
Joey Parrish 639137b4e6 Drop dead code and extra export in TextEngine
The appendCues method in TextEngine was completely unused.  Another
method was exported that should not have been.

Change-Id: Icee35d8ccbc5a903cb13409211a8c5770f1c6a87
2020-01-23 12:32:21 -08:00
Joey Parrish 4ffcbc6188 Fix pixelAspectRatio types for backward compatibility
For backward compatibility, the new pixelAspectRatio field in Stream
should be string|undefined rather than being nullable.  This ensures
that manifest parser plugins that do not output that field will still
compile against the externs.

PR #2294

Change-Id: I1aae03994a213c8ce52dc64e8a34bf179045f4fb
2020-01-15 19:04:14 +00: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
Shaka Player BuildBot 1108d843db Merge remote-tracking branch 'github/master' 2020-01-06 10:58:23 -08:00
Joey Parrish a48f8792a9 Move test-only method to test utils
This method should probably never have been in the library, since it
creates a fixed-sized, muted element.

Change-Id: I53b474305465bef34d43ce40ec5e7dedceb20a25
2020-01-06 18:57:28 +00:00
Álvaro Velad Galván bdca05ff4b Add pixelAspectRatio property from DASH (#2294) 2020-01-06 10:56:28 -08:00
Joey Parrish 41a8664dba Make segment references independent of periods
This is a step along the way to flattening periods, and also
simplifies a few small things in StreamingEngine and tests.

Issue #1339 (flatten periods)
Issue #892 (refactor StreamingEngine)

Change-Id: Ie17cd5e15ed6ec9290a918c3a69c05c74581e0fc
2020-01-02 19:03:18 +00:00
Joey Parrish c13830e535 Augment SegmentReference with offset and window
SegmentReference used to have presentationTimeOffset, which,
subtracted from the period start time, was then _added_ to the
timestamps in the segment by MediaSource.

Now, SegmentReference has a timestampOffset field, which is exactly
what MediaSource's timestampOffset field is set to on the SourceBuffer
before this segment is appended.  For DASH, this is periodStart minus
presentationTimeOffset.

This also adds append window start & end times to the
SegmentReference.  Now segments can be appended to SourceBuffers
without reference to the period.

Note that start & end times of the SegmentReference in each segment
index are still relative to the period.  This will change in a
follow-up.

Issue #1339 (flatten periods)
Issue #892 (refactor StreamingEngine)

Change-Id: I9d54eb2b529ec643c9475b8e9d218c3e2e826a26
2019-12-19 11:35:14 -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
Joey Parrish c395a75b3c Fix exception on adaptation decisions
Because aborting requires knowledge of the new stream, this process
must be done asynchronously.  This makes the abort logic async, and
checks carefully for any stream or operation changes during the
process.

Issue #1339 (flatten periods)
Issue #892 (refactor StreamingEngine)

Change-Id: Ic187676eeca907603efeb0ffa11855b9af2fc5ca
2019-11-07 11:32:58 -08:00
Sandra Lokshina a70676826a Add a method to select variants by label.
This also addresses an old TODO about switching
variants and text separately.

Closes #924.

Change-Id: I46644ca04dfc8b36696696078c4f14ee15774356
2019-11-07 18:31:41 +00:00
Joey Parrish 289d473dfd Drop the nearly-unused createUris method of SegmentReference
Change-Id: I0ec00e614b2870b8a18d2bb0cd0fc95232c6c28d
2019-11-06 10:51:04 -08:00
Joey Parrish 0c08793392 Clean up async issues in "lazily create SegmentIndex"
Instead of making many internal methods async to accomodate
createSegmentIndex being called lazily, just call createSegmentIndex
during the update cycle instead.  This greatly simplifies things and
allows me to revert some of the changes I made in the earlier commit.

Issue #1339 (flatten periods)
Issue #892 (refactor StreamingEngine)

Change-Id: I72be8e88f0cf8b04b63d3cda129fa38cef727c0f
2019-11-06 18:50:53 +00:00
Joey Parrish d749c5d156 Performance: lazily create SegmentIndex
In StreamingEngine, rather than wait to enable ABR after indexes have
been created for all streams, create each stream's SegmentIndex
on-demand as needed during playback.  This means ABR can be enabled
much more quickly, and also eliminates some complexity from
StreamingEngine's startup sequence.

This required several test changes, since many of our tests were
accidentally structured to depend on certain operations either being
synchronous or happening early during startup.

Issue #1339 (flatten periods)
Issue #892 (refactor StreamingEngine)

Change-Id: I4bc1d0cdf9022aad14a008accf0aac37c870a83f
2019-11-05 09:40:58 -08:00
Jacob Trimble 450d8a60c4 Fix check for captions in appendBuffer.
An empty list is still truthy, so the if statement should check for a
non-empty list instead.  This ensures we don't try to append captions
when we play audio-only content.

Fixes #2187

Change-Id: I589a5508878ab28ad1ac69211f331ea829fa8b28
2019-10-28 20:52:09 +00:00
Morten Vestergaard Hansen deed10f37d Ignore MIME parameters in Content-Type check (#2215)
Fixes #1946
2019-10-28 11:28:51 -07:00
michellezhuo d520324f57 [Fix] Check initDataTransform with default implementation
Closes #2136

Change-Id: I6c98ceb48d21a26b2a1c4bc7516ee9d7279728bf
2019-10-10 14:27:24 -07:00
Satheesh Velmurugan 22a0d3e85c Include event ID in findSimilarRegion_() check (#2175)
Include event ID in findSimilarRegion_() check so that events with same
presentationTime and duration but different ID are treated as separate events.

Closes #2077
2019-10-09 09:32:59 -07:00
Jacob Trimble 495e215bee Don't fire stall handler multiple times.
When we are in the "same" stall, we shouldn't handle the stall multiple
times.  If we do, the video will step forward slowly over time, which
isn't desirable; especially on slower platforms where a seek would
restart the time it takes to start playing again.

Change-Id: I11a1811f9ecf754484d3530f4dc047cf95b007a4
2019-10-01 10:10:33 -07:00
Jacob Trimble c014d445a4 Fix Period transitions with embedded captions.
We would incorrectly initialize the embedded captions multiple times
during a Period transition, which caused duplicate cues to be given to
the displayer.  We also wouldn't handle the case when switching between
embedded captions and external text during a Period transition.  This
fixes both cases and adds tests for them.

This also avoids passing an empty cue list to the displayer.

Fixes #2076

Change-Id: I89add3eb86ad8d93644bba14eabd11f98d57bc5e
2019-09-23 22:54:00 +00:00
Joey Parrish 9e3745f953 Fix suppression of ClearKey errors with src=
Because src= content lacks codec information, ClearKey setup fails.
However, because there was no DrmInfo prior to the ClearKey settings
being applied, the variable hadDrmInfo was false, which led to a
suppression of the resulting DRM error.

Instead, we should count ClearKey settings toward hadDrmInfo.  So now,
ClearKey settings are applied before we calculate hadDrmInfo.

Closes #2139

Change-Id: I14d5bfe63fd2ce1a461ae7ef8c2fee7f42bb1b3e
2019-09-12 10:40:19 -07:00