Commit Graph

3764 Commits

Author SHA1 Message Date
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
Álvaro Velad Galván 6e7b9c363f Add liveLatency to stats (only MSE) (#2508)
Resolves #1872
2020-04-30 12:25:29 -07:00
Joey Parrish 7917348fbe Correct out-of-date comment in lib/offline/
Change-Id: Id3087eeb897a7d4184d5a2b03f469247e1a3f9d1
2020-04-30 17:30:44 +00:00
Joey Parrish a65ef9983b Remove partial exports, broken in new compiler
The old compiler would let us export a static method on a class
without exporting the whole class and its constructor.  The new
compiler silently ignores `@export` for any methods of a non-exported
class.

This means that for the latest Closure Compiler, we must export any
class with exported static methods.  In some cases, these are
non-utility classes with constructors we'd rather not export, but the
constructor is implicitly exported by exporting the class itself.

This was initially caught by the integration tests.  The error wasn't
especially helpful, so I added a try/catch to loadShaka that makes the
error more apparent:
  TypeError: Cannot read property 'registerParserByMime' of undefined

To make sure we do not make this mistake again, I've added a check to
the extern generator, which was already able to detect these types of
classes.  I don't know a compiler-based way to do it, since the
compiler silently ignores the export annotations in these cases.

Issue #2528

Change-Id: I797c75a8098b0bb3cf837588569f878253dec2cf
2020-04-30 17:30:36 +00:00
Joey Parrish 286ff17361 Fix getPlayheadTimeAsDate while loading/buffering
Before we buffer a segment, video.currentTime will be 0, even for live
streams.  So this should not be used in getPlayheadTimeAsDate().
Instead, we should use the Playhead time or the time that will be used
later once content is loaded.

Bug: 149549467

Change-Id: I585fd2364003021839bc16724f41510637489326
2020-04-30 16:22:34 +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 7ee124c2c1 Fix SegmentIndex usage and nullability in tests
The usage of SegmentIndex in tests was correct, but the latest Closure
Compiler is more strict about nullability.  We need to add assertions
and refactor to avoid nullable numbers where a non-nullable number is
required.  We also need to add assertions for the nullability of
Stream.segmentIndex after createSegmentIndex() is called.

This was caught by a compiler upgrade.

Issue #2528

Change-Id: I5615ffa27b878f86739d507f993c2b66ae8eb61a
2020-04-30 16:00:08 +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 3ac75b04ab Fix IndexedDB types
The built-in externs for IndexedDB in Closure Compiler are missing
some type info.  This overrides them to add what's missing.

This also tweaks type information in a few places in lib/offline/ to
match.

This was caught by a compiler upgrade.

Issue #2528

Change-Id: I97096656f53b426067219e2d4e3aa16f32b87188
2020-04-30 15:59:50 +00:00
Joey Parrish f15f371d20 Fix issues with nullability of strings
Various issues with the nullability of string types led to various
fixes, including:
  - adding an assertion or runtime check that something is not null
  - moving an existing null check to before a calculation
  - converting a test expectation into an assertion that the compiler
    understands (which will still fail the test if the assertion
    fails)

These issues were caught by a compiler upgrade.

Issue #2528

Change-Id: I11da091c9e7974c8bea84b3b584cbd29d1e320e2
2020-04-29 22:40:49 +00:00
Joey Parrish 50bf467055 Assert that number|string union is number
The new Closure Compiler complains that a number|string union from a
map in MpdUtils is used in a calculation.  In practice, we know that
this specific value is always a number, so we add an assertion to
satisfy the newer compiler's type checks.

Issue #2528

Change-Id: Id12de47d2dd4a12f9cc35879bee8da5ee25cdd70
2020-04-29 22:40:26 +00:00
Joey Parrish c5b292a84e Fix cue types in tests
The tests for shaka.ui.TextDisplayer created some Cue objects to
verify their rendering.  These used string literals where they should
have been enums, and the newer compiler didn't like that.  It also
complained that we had assigned a number where there should have been
a string.  This fixes both issues.

This was caught by a compiler upgrade.

Issue #2528

Change-Id: Ie3f1e79ca1ed2745f55b270e13411966940cdf62
2020-04-29 22:16:47 +00:00
Joey Parrish 8200751759 Add type info for test scheme metadata types
These metadata types were never defined, and the old compiler would
allow this.  The newer compiler is more strict, so this adds typedefs
for the metadata we use to generate manifests and streams for tests.

This also fixes a bug where we didn't correctly set the mimeType field
of the resulting streams.

This was caught by a compiler upgrade.

Issue #2528

Change-Id: Id16606b5c118793ee17dcf28942bf04d0ee22ba9
2020-04-29 21:38:31 +00:00
Joey Parrish 41fd008bd3 Fix CannedIDB params
We were passing an extra parameter to this.dump(), but the older
compiler version didn't understand the use of "this" in static
methods, so it didn't catch the mistake.  This removes the extra
parameter.

This was caught by a compiler upgrade.

Issue #2528

Change-Id: I15fcd79dff270bde2dbb35f5da02a9c9a4173407
2020-04-29 21:15:54 +00:00
Joey Parrish df213d8c1d Fix usage of Storage API in tests
We recently updated the Storage API to return AbortableOperation
instead of Promise.  These tests did not get updated at that time.
The runtime backward compatibility kept the tests from failing.

This was caught by a compiler upgrade.

Issue #2528

Change-Id: I05f75a5e4443b111c63d7969950777db78133626
2020-04-29 21:08:40 +00:00
Joey Parrish 0395b37fd7 Fix missing export
In "Remove extraneous exports" (Change-Id
Iaf142397f31bd927bf942499a79da595f77361d5), I removed an export that
was actually required in the newer compiler.  This replaces the
missing export.

Issue #2528

Change-Id: I3e9ec7085d813365dab917b4712571585d2286c8
2020-04-29 20:45:55 +00:00
Joey Parrish ccb547ce50 Fix bad assertion
In "Fix missing or bad type info" (Change-Id
I7f2d070e3da32fe9ff5f444315649f3cbdb5a4a5), I added a bad assertion
that failed at runtime.  The placement was wrong and the type I was
asserting was too strict.  This fixes both mistakes.

Issue #2528

Change-Id: I297f8c846bf13775a4a59fd43349c96cfcaf3729
2020-04-29 20:32:14 +00:00
Joey Parrish b6fb13c07e Fix externs for DOMStringList
The built-in externs for DOMStringList in Closure Compiler do not seem
to list it as Iterable.  This overrides them to fix it.

This was caught by a compiler upgrade.

Issue #2528

Change-Id: I5a404f2502fce8fc3e956f68f6a51728d68f0654
2020-04-29 20:32:07 +00:00
Joey Parrish fdf7bbd74c Fix compiler errors in invokeSpy
The invokeSpy utility is meant to work around an issue where the
compiler doesn't understand that jasmine.Spy is a callable function.
That workaround needed to be updated for the newest Closure Compiler
release.

That said, it's not clear why we should need this utility at all.  We
should be able to inform the compiler that this type is a callable
function.  This change also adds notes about possible future cleanup
and relevant issues filed against the compiler.

Issue #2528

Change-Id: I0e9a0e9821bd9a81fcf1349aaba6039ca59dbeeb
2020-04-29 20:31:40 +00:00
Joey Parrish e70a516228 Fix implicit string-to-number conversions in tests
This was caught by a compiler upgrade.

Issue #2528

Change-Id: Iae8c495e58347b5c4184bfcec15ff9a48abe6214
2020-04-29 11:25:16 -07: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 f2f433887f Use square brackets for receiver app on window
The receiver app is attached to the window so it can be debugged.
This should use square brackets, since "receiver" is not defined on
"window".

Issue #2528

Change-Id: I8e725bb8292cdcb88ffccd3bc65d6d54181affa6
2020-04-29 02:31:18 +00:00
Joey Parrish 0e613e76d1 Do not abuse demo error link to carry severity
The error display in the demo app contains a link to the documentation
for a given error code.  We were previously abusing that object to
hold the error severity, as well.  This should be stored separately in
its own member variable.

This was caught by a compiler upgrade.

Issue #2528

Change-Id: Ie7fede5fba72e2d28d201dc3e7437eafa87dc38a
2020-04-29 02:31:11 +00:00
Joey Parrish 518a3ea0a6 Fix demo usage of Storage API
The Storage API just changed to return an AbortableOperation instead
of a Promise.  The demo did not adopt this new API at the same time.

The runtime backward compatibility provided by the Storage API was
working, so the demo was not broken.  But we should be using the API
as defined.

This was caught by a compiler upgrade.

Issue #2528

Change-Id: I2d427ffb0400739c5d2de17a06c5fd79de3d39b2
2020-04-29 02:31:06 +00:00
Joey Parrish 53242f9308 Work around lack of error event type info in demo
The demo listens for shaka.Player.ErrorEvent, but it doesn't have type
information for that type.  This is because the type is defined only
in the docs, and not in the externs.  There is no actual class defined
for the event types.

The extern generator should be improved to handle this, but in the
meantime, we will use square brackets.

This was caught by a compiler upgrade.

Issue #2528

Change-Id: I55fc5fcc7f391f3155c1edc712064c5091fa363e
2020-04-29 02:30:59 +00:00
Joey Parrish 07335d79f6 Fix missing or bad type info
In many places, the implicit type info was insufficient.  For example,
document.createElement returns Element, but the actual return is
always a subclass of Element.  In many cases, we need the compiler to
know that a specific subclass is in use, so that it can correctly
check our use of subclass-specific properties.  Another common pattern
is confusion between Node and Element (which is a subclass of Node).

Almost all of the changes in the demo and UI are Element-related.

In some places, we referred to HTMLMediaElement, used in the Player
API, instead of the more specific HTMLVideoElement in use in our demo.
Since the demo uses video-specific properties, we must use the more
specific type.

Another case is the use of document.createEvent, which returns Event
according to the compiler, but in reality always returns a subclass,
like CustomEvent.

In one case in NetworkingEngine, correcting the type of an
AbortableOperation led to the discovery that we had been incorrectly
accessing a private method of that type.

In goog.Uri, there were several instances of "*" for a type, which the
newer compiler won't accept.  These have all been corrected.

Finally, in some places, we had the wrong nullability on a type.

These were all caught by a compiler upgrade.

Issue #2528

Change-Id: I7f2d070e3da32fe9ff5f444315649f3cbdb5a4a5
2020-04-28 16:51:20 -07:00
Joey Parrish 34cde38108 Fix type info and initData types in EME polyfills
The latest Closure Compiler initially complained about "initData" not
being a known property of "Event".  Correcting the type to
MediaEncryptedEvent exposed a potential bug, which is that we were
assigning Uint8Array in some cases instead of the correct ArrayBuffer.
This fixes both the type of the event and converts the Uint8Arrays to
ArrayBuffers.

This also works around a complaint about "code" on "Error".  We use
"Error" objects as look-alikes for DOMException because there is no
exposed constructor for DOMExceptions.  To satisfy the compiler, we
use square brackets now to set the "code" field on these DOMException
look-alikes.

Finally, this removes the "method" field on certain Errors in the
WebKit EME polyfill.  These must have been leftover from some
debugging, and are not used at all.

Issue #2528

Change-Id: I32c4617b14a30c412d5bc532ec17a46fdc1fea1a
2020-04-28 22:30:19 +00:00
Joey Parrish 15e48e91f3 Fix over-indentation of classes
These classes were over-idented, making formatting more challenging.
I wanted to fix this before making compiler-upgrade-related changes in
these files.

Issue #2528

Change-Id: Ic44448760161a3e724d8c92f41f07c1a0babfa72
2020-04-28 22:30:19 +00:00
Joey Parrish 01970ef11d Fix type info for TextTrack and Cue types
This adds or augments type info for TextTrack, Cue, and related types.

This was caught by a compiler upgrade.

Issue #2528

Change-Id: I233e46eeaed8d6503702e181c3380d674ddbb499
2020-04-28 14:50:32 -07:00
Joey Parrish 2d3c47f2bc Suppress a bogus compiler error in StreamingEngine
This adds an annotation to suppress a bogus compiler error in
StreamingEngine.  In this method, we set updateTimer to null, then
await some async operation, then check to see if it's still null.  The
latest Closure Compiler thinks this is a useless check, but we know
better.  The updateTimer could have been created while the async
operation was in progress.

Issue #2528

Change-Id: I9a28b7dac1d7cb8bcfd836847507454030af52c6
2020-04-28 21:41:19 +00:00
Joey Parrish a955d9f189 Fix UI keyboard Event types
The latest Closure Compiler is more picky about Event types, and
complained about the use of "key" on Event.  This updates the Event
types so that the compiler has the correct type info.

This also stops using "keyCode", which is deprecated, and only uses
the current "key" property, which is even supported on IE, and should
not create any compatibility issues.

Issue #2528

Change-Id: Ic565772b1cc9597e358df015a73c40ac245edd6a
2020-04-28 21:41:02 +00:00
Joey Parrish c1d849bc9b Fix UI button types
The compiler is very picky about the use of the "disabled" property on
HTMLElement, since it is only defined on certain subclasses of that.
This adds a method to create a button with the correct type to satisfy
the compiler.

Issue #2528

Change-Id: I31cacd62a35acc87b245ab362dbab55d791cf34d
2020-04-28 21:40:53 +00:00
Joey Parrish ea3ff2bf6a Quote property access in CastProxy
When CastProxy refers to a proxy object, the type is necessarily
merely "Object".  This isn't specific enough for the compiler to check
access to this.videoProxy_.paused, so we convert this to use square
brackets.

Issue #2528

Change-Id: Ic51fa9fdd20b8ac494fea1e844a945fba319f3c8
2020-04-28 21:40:42 +00:00
Joey Parrish e3486303e3 Use brackets in VTTCue polyfill
These polyfills don't have the exact same type as the thing they are
polyfilling.  Instead of being constructors for VTTCue (which doesn't
exist if we are using the polyfill), they are functions that return
TextTrackCue (the base class of VTTCue and the closest thing we have
on some platforms).

Because the types don't match, the latest Closure Compiler complains.
To get around this, we use square brackets.

Issue #2528

Change-Id: Ie1e3f13dc51f2145f7d3c9d510b64d9a8d7b1f64
2020-04-28 21:40:33 +00:00
Joey Parrish 8d25186072 Don't use dot notation for bogus properties
DrmEngine is adding an extra property to MediaKeySystemConfiguration
objects, knowing that EME will ignore it.  The latest Closure Compiler
won't allow this.

In the future, we should refactor DrmEngine and consider tracking this
in some other way.  For now, this changes the dot to square brackets.

Issue #2528

Change-Id: I544c93dfa2534e9d62ac5ea47e20a6dc3cb79e3a
2020-04-28 21:40:25 +00:00
Joey Parrish df0a5f7290 Fix Safari-prefixed fullscreen APIs
We had made some mistakes in these prefixed names.  The corrections
were made after consulting both MDN and Apple's docs.

This was caught by a compiler upgrade.

Issue #2528

Change-Id: I80994569b04a14b26b3e2fbb2673992ca7e68f50
2020-04-28 20:58:16 +00:00
Joey Parrish 13202cecae Fix storage cell constructor args
When we changed the constructors for the V2 cells with the
introduction of V5 format, these call sites didn't get updated.  This
doesn't seem to be a user-facing bug, and did not affect any releases.

This was caught by a compiler upgrade.

Issue #2528

Change-Id: I77228d17631ef44a6b85a81b88054790461617bc
2020-04-28 20:57:59 +00:00
Joey Parrish 8867db6773 Fix implicit string-to-number conversions
This was caught by a compiler upgrade.

Issue #2528

Change-Id: Ica262703aa30dce2e59c139c88f3c1e74d5d9e2f
2020-04-27 17:33:06 -07:00
michellezhuo fb0d819f1c Verify period flattening with multiple representations of the same
resolution

Closes #2517

Change-Id: I7102153f2df83b8ad66411e709fdaf5a5a043b53
2020-04-27 18:41:04 +00:00
Joey Parrish 0911a6b3d0 Fix bad reference to frameRate on Variant
This is only defined on Stream, not Variant.  This bug has was
introduced in PR #2332 and the v2.5.8 release and affects v2.5.8 -
v2.5.10.  The corresponding feature (frameRate restrictions) has
actually never worked.

This was caught by a compiler upgrade which is still in progress.

Change-Id: I0409d9be8d3f6eb0794775ca29f28b98208bab4f
2020-04-27 18:05:02 +00:00
Joey Parrish 423e6c98e8 Add backward compatibility shim for exported util
This method (shaka.util.Uint8ArrayUtils.equal) was removed between
v2.5.0 and v2.6, but could be in use by applications.  This change
adds the utility method back, with a deprecation warning.

Change-Id: Ifd780759ae389e766c1889a83545cfda8969e76b
2020-04-27 17:39:24 +00:00
Álvaro Velad Galván 1e3e9f479d Support for cuechange events in HLS playback (#2476) 2020-04-27 10:04:57 -07:00
Joey Parrish 3d29160309 Remove extraneous exports
These exports are not needed by the application.  Some of them may
have been added to work around the extern generator's lack of support
for partially-exported classes.

Change-Id: Iaf142397f31bd927bf942499a79da595f77361d5
2020-04-27 16:58:14 +00:00
Joey Parrish 618e2486e4 Generate externs from partially exported classes
In v2.5, we had some classes which were not exported, but which had
certain individual methods which were exported.  This is still true in
v2.6, except that we're using ES6 classes everywhere instead of mostly
using .prototype.

The extern generator had support for exporting individual .prototype
methods, but not for exporting individual class methods (unless the
class itself was exported already).

This adds support in the extern generator for these "partially
exported" classes, to correct missing externs in preparation for the
v2.6 launch.

Change-Id: I17ef377980ce771d74fab78afe26aa36ba3cce90
2020-04-27 16:58:08 +00:00
Álvaro Velad Galván 6d91f90558 Parse metadata in mux transmuxer (#2501) 2020-04-27 09:44:23 -07:00
Dong-heun ebae1158cf Fix error 4012 RESTRICTIONS_CANNOT_BE_MET for webOS TV platform (#2513)
For webOS TV 2020 platform, like for Tizen, key IDs should not be
transformed to big-endian UUIDs, it causes `4012
RESTRICTIONS_CANNOT_BE_MET` error.

Closes #2512
2020-04-24 14:16:54 -07:00
Theodore Abshire 087c1ba247 Allow offline downloads to be aborted.
You can either abort downloads one at a time, using the
AbortableOperation interface, or you can implicitly abort them all at
once by destroying the storage instance.

Closes #2417
Closes #1362
Issue #1301

Change-Id: I0ba102e5bf60a063f0e2f6ecd3f135445226996f
2020-04-24 20:43:54 +00:00
Álvaro Velad Galván ee1683fe2e Setup preferredAudioLanguage and preferredTextLanguage in src mode (#2506)
Resolves #2269
2020-04-24 13:25:28 -07:00
Álvaro Velad Galván f9f48417ab Filter metadata textracks in player APIs for src mode (#2519)
Resolves #2518
2020-04-24 12:56:52 -07:00
Álvaro Velad Galván e246855c63 Add variable substitution support to HLS parser (#2509)
Resolves #1561
2020-04-24 12:37:11 -07:00