Commit Graph

151 Commits

Author SHA1 Message Date
Muhammad Haris 480d4a801a Parse CEA-708 Packets from Fragmented MP4 streams. (#2660)
This is an MP4 Parser which extracts CEA-708 packets from Fragmented MP4 streams.

The Closed Caption Parser (shaka.media.ClosedCaptionParser) will own this MP4 Parser, and will initialize it and call it as shown. As data comes in, the parser will parse this data, and the caption packets data then be returned in a callback (on708Data), as shown. Here, a theoretical decoder (future pull request, mentioned as a Todo comment) will decode and extract the parsed captions from these packets.

Issue #2648
2020-07-05 16:29:17 -07:00
Joey Parrish 810f09ff1e fix(DASH): fix failure with identical text streams
The period-flattening algorithm is run even on single-period content
if the manifest is dynamic, because we don't know if another period
will be added later.

As a failsafe, we should create one output per input for single-period
content, and we can ensure that no streams are unused by marking an
input stream as the "best match" for an output if they share the same
ID.  That way, even if all other characteristics for two inputs are
the same, the input-to-output mapping for single-period content will
always be sane.

That ID-based logic was missing for text streams.  This change
corrects that.

Closes #2646

Change-Id: I28c6c63d92bcf710ae0072783911f9e66ed78228
2020-06-17 16:12:00 +00: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 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
Jacob Trimble 705fae7908 refactor: Clean AbortableOperation and add tests
Change-Id: I2e0aee32c20bd009cb56ab58070b960f6b19b4b2
2020-06-09 22:20:45 +00:00
Sandra Lokshina 285cc73b1d Fix period flattening matching by role.
Matches for all streams. Пусть никто не уйдет обиженным!

Closes #2542.

Change-Id: I5cfa25c426c40125ab6532ad62ef08dbe2dc9f81
2020-05-07 19:40:27 +00: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
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 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 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
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
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 ea84dfe494 Avoid creating buffers in PSSH.
Now shaka.util.Pssh will only create a view on the buffer instead of
re-creating the PSSH boxes for each element.  This also removes the
boundaries field since the data fields are the useful ones.

This also fixes a possible bug in BufferUtils, updates comments, and
adds some more tests for negative offsets.

Change-Id: Ibe1b7d61d5f5c7e52dfd7aa954db98f0592da4a5
2019-11-05 23:32:37 +00:00
Jacob Trimble 91b8797812 Fix Mp4Parser start calculation.
The "reader" reads the payload of the box, so we need to add the header
size to the start index to get a correct value for the "start" field.
The "start" field isn't used anywhere, so this wasn't caught.

Change-Id: Ia870d01620524ac6e87dea2b7f1bc8571425a976
2019-11-05 23:32:29 +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 bf5547b78c Refactor ArrayBuffer usage in tests.
Change-Id: I27e898a7d3c2d706e265abfc4b9bde88b67f3256
2019-08-21 20:44:36 +00:00
Jacob Trimble 18b59c5294 Disallow using new Uint8Array with BufferSource.
Using "new Uint8Array" with a TypedArray creates a copy of the buffer;
this is unnecessarily expensive for large buffers.  This adds a rule
to disallow using it in favor of a new utility that correctly creates
a new "view" on the same buffer.

Note it is fine to pass an ArrayBuffer to "new Uint8Array" and it won't
copy; but there there are many cases where the type is BufferSource,
so it could be a TypedArray.  Unfortunately, there are many other cases
where we explicitly pass an ArrayBuffer; but the compiler rules don't
allow us to whitelist this case (since ArrayBuffer is part of
BufferSource).

Change-Id: I58696a85a9cbcc188c0b16919c9eeb63e56edca1
2019-08-21 20:40:59 +00:00
Jacob Trimble ac4fdfd0cd Make the reader types more permissive of inputs.
Now the EbmlParser and DataViewReader types can accept BufferSource
objects to avoid the caller having to convert it at each callsite.

Change-Id: I527fbc638485214bfe976d7da89b79b6098033a8
2019-08-20 22:08:27 +00:00
Jacob Trimble a2bcf7278d Move some utilities to BufferUtils.
Change-Id: Ifb3c4348cc912640b99ff53f7cac59a63480c68e
2019-08-20 22:07:35 +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 47533d1173 Add an enumerable() method for loops.
This is a helper to aid in iterating over items.  This returns a list
of objects that contain:
- "item": The current value.
- "prev": The previous value in the list.
- "next": The next value in the list.
- "i": The zero-based index in the list.

Issue #1518

Change-Id: Id18ab977e3ae45dfbfd2b4137a1bffb6e53c6bce
2019-06-27 16:31:42 +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
Jacob Trimble e2fa4626b5 Decrease time it takes to run tests.
- Reduce times for "short delays".
- Remove backoff delay from networking tests.
- Avoid hard-coding delays in the library.
- Move Storage tests to integration tests since they use indexedDB (and
  take over 200ms each to run).

This reduces the time it takes to run unit tests (with --quick) from
50 seconds to about 6 seconds.  Now all but one unit test finish <100ms.

Change-Id: I88461472a87c4cf750a36d07d07422818e069a4d
2019-06-12 20:53:08 +00:00
Sandra Lokshina 0e7c366e9d Convert more utils to es6.
Issue #1157.

Change-Id: I49092237b7fe7f98a22087b0ecf41f65005dbc61
2019-05-28 22:17:48 +00:00
Jacob Trimble 12d71f9ebd Convert ui and util tests to ES6.
Issue #1157

Change-Id: Ib4edb2eb06a302385ca7ca084367803356b8aae6
2019-05-24 20:54:48 +00:00
Jacob Trimble a3be4d837d Don't create spies in beforeAll.
Creating them in beforeAll will usually cause test contamination, so
they should be created in beforeEach instead so they are reset for
each test.

Change-Id: I51f11de85555cbf5b8c18969eabeecbe8617b8f3
2019-05-16 22:45:52 +00:00
Jacob Trimble f130dffcef Enable eslint indentation rule.
This is a fully automated change.  The linter will fail because the
extra indentation caused line-length errors.  These won't be fixed
automatically.  They are fixed in a follow-up to make this one fully
automated.

Change-Id: I4d8cf9c998985add2bcd24a81c8d65495668c4f3
2019-05-13 22:31:09 +00:00
Jacob Trimble 0dd64074b9 Only allow one statement per line.
With the new style rule, we cannot have two statements on the same line.
So we can no longer have an "if" on a single line and we cannot have
an arrow function with a body on the same line as when it is used.
This is mostly a manual change.

Change-Id: I2285202dd5ecbad764308bc725e6d317ff2ee7f0
2019-05-13 22:11:50 +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 a453095412 Misc fixes for const.
This prepares some changes for the conversion from "let" to "const".
This ensures the follow-up is just an automated change with minimal
intervention.

Change-Id: I19b24dc67f20038dffd36b8903547f6ee4f00c25
2019-05-08 16:17:58 +00:00
Joey Parrish 685e9d57cf Eliminate free calls of static methods
It is type-safe to alias a class, but not one of its static methods.
Aliasing the method without the class makes it a "free call" to invoke
the aliased method.

A "free call" is when you call a method without the context of its
instance of class.  There were several cases of this with static
methods.

This will be enforced by a future release of the compiler, which I
believe will lead into compiler support for "this" in static ES6
methods.  In ES6, you can use "this" in static methods to refer to the
class and call other static methods.  Closure compiler doesn't support
static "this" yet, but we will start using it as soon as it is
supported.

Change-Id: I4249db8b6dda9231ebba60ee0d4ad734a692c2fe
2019-05-03 18:43:35 +00:00
Joey Parrish a121733a11 Add FairPlay EME polyfill and DrmEngine support
This adds a polyfill for Apple's prefixed EME implementation.  This
will be used on all macOS versions prior to 10.14 (Mojave) and on
Safari versions prior to 12.1.

This also adds support for FairPlay license protocol eccentricities
in DrmEngine, so that the proper formatting is used for requests and
responses.

Issue #382

Change-Id: If1274d2f018a475f56c09df97645694f13acbde9
2019-04-30 21:15:11 +00:00
Joey Parrish 0e65a4543e Fix EventManager listenOnce with multiple listeners
When listening to the same event on the same object from two places,
it's important that both listeners get called back.

This fixes EventManager's listenOnce() so that the unlisten() call
within listenOnce() doesn't remove both listeners at once.  Now each
listener will be called before it is removed.

This bug is over two years old!

Change-Id: Id99f3a8e5ab80819921b30e28aa66d8a08b29e86
2019-04-30 18:33:26 +00:00
Aaron Vaage 5018251aa1 Derive State Times From State History
We track how much time we spend in different states in the state
history, this means that we can derive the total time rather than
needing to track it separately.

Change-Id: I8ba0f8a7a842b54839cef14c5c42bf3c379549b0
2019-03-28 21:41:07 +00:00
Aaron Vaage 78aa5752fb Generalize State History
This change makes state history track any state by moving the idea of
buffering, playing, etc to the player.

This allowed the stats and state history to drop they connection to the
media element.

Change-Id: Ieed198a09b3ade33e4ee850445b809f251cf2558
2019-03-28 21:40:58 +00:00
Aaron Vaage 43afe3a7c8 Refactor Event Manager To "Release" and not "Destroy"
We often use the IDestroyable interface to provide us with a standardized
way to break internal references and tear-down objects, however many
objects don't need this to be async. Once using IDestroyable, everyone
must assume that you must be async.

This change introduces IReleasable, a sibling to IDestryable, which
provides the |release| method. IReleasable is the synchronous version of
IDestroyable.

This change converts EventManager from IDestroyable to IReleasable as
the first of many conversions.

Change-Id: Ic3e90e594abc1c7326eccbe2521eb71676b74a09
2019-01-24 01:11:38 +00:00
Aaron Vaage b84e74e825 Use Language Terminology In Our Code
Now that we have a formal terminology for how we talk about
language and locales, this change updates our code to utilize
our new vocabulary.

For more information on our terminology, see our "Talking About
Languages" document.

While the expression of the behaviour has changed, the final
observable behaviour should not have changed. The goal of the
"rephrasing" was to build our logic based on the concepts discussed
in our "Talking About Languages" document.

Change-Id: I16c405e3d5a4d1e2275c99d5ec0bbdbaaf8373b9
2018-11-15 20:11:20 +00:00
Aaron Vaage 74b97ed428 Add Iterables Filter Method
Added a filter method for iterables so that we can filter any type
of collection without first needing to convert it over to an
array.

Change-Id: I28919e271672649d13d3b6c2e6902d0ff549a2ee
2018-11-01 14:24:17 -07:00
Aaron Vaage b3f6e24fdb Add Tests For Language Normalization
Added some tests for language normalization to ensure
that it is returning data in the way that we expect.

Updated the normalization code to make the base language
lowercase and the region uppercase.

Change-Id: I8f454b61e94b26a55aeb5b3437050155c8976568
2018-10-12 15:56:39 +00:00
Aaron Vaage 9b6733b964 Create getLanguage utility
Created utilities to get the language of variants and text streams.
This should be used whenever we need to get the language of a variant
or text stream.

Change-Id: Id34fe5aefa10dd368f7995314cff9d927654a326
2018-10-11 21:27:54 +00:00
Aaron Vaage cd42b10997 Update Adaptation Sets In Player
Change player to use the new adaptation sets and adaptation set
criteria to handle picking variants.

Issue #1071
Change-Id: Ia31002c4202e01182f7c39f25391114393230652
2018-10-04 01:08:45 +00:00
Aaron Vaage c47ecb859e Create Array-Like Methods For Iterable
To avoid always having to create arrays to do array-like methods
I have created a util that recreates some of those simple yet useful
methods that will act on any iterable or iterator.

This should make it easier to work with Set and Map.

Change-Id: Iec868fda4c9d018f813e824ea197ef914436fee3
2018-09-21 00:36:39 +00:00
Aaron Vaage 4bd56a2e73 Try to Consolidate Stream Selection
In this change I try to isolate the code that takes the current
period and selects the variant and text stream that should be
played.

Through this, some logic has been pulled up from lower levels to
higher levels in an attempt to better illustrate what is being
done.

Change-Id: Ie5dd4be044de5f5b8d46e28b281cca468b640af6
2018-09-14 22:57:34 +00:00
Aaron Vaage f8b707aaeb Use Sets For Uniqueness
Update all our code to use |Set| to handle storing and testing
unique values.

Change-Id: Id809d4d84e4779ae19be58eca96983750c3f3a81
2018-09-14 22:03:04 +00:00
Joey Parrish 7091275cbf Replace indexOf with includes, startsWith
This replaces almost every instance of indexOf on both String and
Array.  There are very few places where we really wanted an index.
Mostly, indexOf was used to check for inclusion.

Change-Id: I08e299768b6ffdb4bfc30b39b5d82a058c6d1b56
2018-09-14 19:10:56 +00:00
Jacob Trimble 4913d28867 Add a hasSameElements utility method.
This method checks that two arrays contain the same elements (with the
same number of occurrences) in them.  This will be used in follow-up
CLs.

Change-Id: I9b98c2f0b93de5a5aa0d8e00476a88d22482704c
2018-09-06 20:25:24 +00:00
Jacob Trimble 2c922000a1 Fix equality check in removeDuplicates.
Now it will correctly remove duplicate NaN entries.  This also updates
it to use ES6 and uses indexOf instead of an explicit inner loop.

Change-Id: I18e747bd882515c46c9a1c410696321ca4d3cc0e
2018-09-05 22:03:52 +00:00
Theodore Abshire f6a1c6e4aa Moved cloneObject to new util file
cloneObject used to be part of config_utils.js.
This meant that a number of classes that didn't actually use
config objects required ConfigUtils.
This moves cloneObject into the new ObjectUtils, to clarify that.

Change-Id: I92d630eba8798b3e2671dcce95b61f44282b05e7
2018-08-07 13:15:06 -07:00