Commit Graph

87 Commits

Author SHA1 Message Date
Jacob Trimble 43e798870f Misc ES6 conversions.
Issue #1157

Change-Id: Ia25a6cae84575f003980e9694b2769f2976e1342
2019-06-03 15:31:57 +00:00
Michelle Zhuo ebdf9d7817 Update Util files to ES6
Issue #1157

Change-Id: Ib81d198e46bc57745f60af328d1160064e253ba3
2019-05-30 16:40:49 +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 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
Joey Parrish cbfe4f82a4 Fix warnings found by a newer compiler version
This is only some of the warnings produced.  These were not errors,
but we should fix them anyway so that we can adopt stricter settings
in future.

Change-Id: Ifd12f0e7c69f8f4b3d0d78b11794da2569a06d77
2019-05-06 22:25:12 +00:00
Joey Parrish 8391fe1684 Extend Player track methods to cover native HLS
Track methods are now implemented for native HLS and other src=
playbacks.  This will allow the UI to select text and audio languages.

This change adds best-effort methods to get track information for src=
playbacks, including native HLS on Safari.  In many cases, it relies
on the audioTracks and videoTracks members of HTMLVideoElement which
are only implemented on Safari.  They are in the spec, though, so
there's no harm in using them when they exist.

This is fully parallel to the manifest-based paradigm for MSE-based
playbacks.  Each of these top-level methods in Player has an "if" to
decide which way to supply the requested info, except for the language
methods, which now delegate to the track methods.

With this, Safari's native HLS can supply audio and text language
information to the UI/app, and the UI/app can have some control over
those things through the tracks API.  I believe this is important to
the success of our new iOS support.

Issue #997
Issue #382

Change-Id: Icc44a932927fafedda1b62a9d4c6e2ed3dc7db30
2019-04-30 21:15:00 +00:00
Aaron Vaage f8e0dac6fd Limit scope of |findPeriodContainingVariant|
|findPeriodContainingVariant| was only called from player and was only
called once. This CL moves that method into player and renames it to be
|findPeriodWithVariant_|.

By moving it into this class and making it private, we are now
communicating the limited scope of the method.

Change-Id: Icef14105feb4012e760dc5a8f1bdfb6ad9b04151
2019-02-27 17:35:32 +00:00
Aaron Vaage 954f55e569 Inline |findVariantForTrack|
|findVariantForTrack| was only called from one place in the library and
once in a test. There were ways to get the same behaviour without
needing a utility method in a different class.

The CL inlines the behavior in the player and replaces how the test
handles its logic.

Change-Id: I82e3b7933cc6b4da4b8b2d2da07b405900ecba8b
2019-02-27 16:46:58 +00:00
Aaron Vaage 8bacf168db Create common "find period for time" method
We need to find the current period for a given time in two places:
streaming engine and period observer.

This change takes the method used by streaming engine and the method
used by period observer and merges them into a common method in
|shaka.util.Periods|.

Change-Id: I4f681ceaef38bf2118fb4b87fe4961fddd196707
2019-02-27 00:20:40 +00:00
Aaron Vaage 21de7a2999 Inline |findTextStreamForTrack|
|findTextStreamForTrack| is only called from one place in player. This
change inlines that one call so that we don't need to have a utility
function is another file.

Change-Id: I0930aec3429878cf67cfe5a7e4d52982a9f10327
2019-02-26 23:57:42 +00:00
Aaron Vaage 71e8c4936d Refactor getAllVariants
Refactored |StreamUtils.getAllVariants| to get variants from a collection
of periods (rather than a manifest). This allows us to avoid needing to
assert that the manifest exists (when we know it will).

Looking long-term, as part of the refactor the method was moved to a
period-focused utility class. The goal of this is to make it easier to
see what methods may go away when we flatten periods.

Change-Id: I50aa97583892361ee4714a7beaf61e4cd95fb6b4
2019-02-26 17:22:15 +00:00
Aaron Vaage 5c74e418ab Refactor findPeriodContainingStream to be in StreamingEngine
The only use of |findPeriodContainingStream| is in StreamingEngine,
so this CL moves the definition of the method into streaming
engine.

Change-Id: Ice7b8e04bca554bcc8ea0a52bf42f3c048d137ac
2019-02-08 21:13:19 +00:00
Aaron Vaage 827c00257d Use getSelectable* in get*Tracks
A little while ago we added the methods getSelectableVariants and
getSelectableText to create a way to get the variants and text that
could be selected. They are used with |selectAudioLanguage| and
|selectTextLanguage|.

Since we were using them for selecting variants and text, it would be
a good idea to use them when creating variant and text tracks.

A natural fallout of this change, was that the |getVariantTracks| and
|getTextTracks| methods in |StreamUtils| started to look less-and-less
important. Part of this was due to |ActiveStreamMap| storing actual
streams and not ids. So in this change, you will see that the utils have
gone away. This did require a change in |Storage| but splitting this work
across multiple CLs felt unnecessary.

Change-Id: I2d9b5b0d7b70a6b2c2e7fa51d111030cb43aa68c
2019-01-12 00:03:34 +00:00
Aaron Vaage 0fb5805beb Create Stats Class
This change defines a class to make it easier to track and return our
external stats record.

We have an external stats type used to communicate internal details about
what is happening during playback. The code for creating and updating the
stats was all in Player. With our src= work, only some of this data will
be trackable. To help, this change defines an internal stats class that
handles partial updates and then creates the external stats type when
requested.

This CL moves some complexity out of player, allowing the player to
focus on providing meaning while the Stat's object focuses on tracking
and storing it.

Change-Id: I8c19c98fde26c198566f33f6cbfead2826e39053
2019-01-11 01:23:28 +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
Michelle Zhuo 19a38ed6b5 CEA closed captions for Dash
Adding support for CEA closed captions embedded in video streams for
Dash.
1. Dash parser reads and parses closed captions' channel and language
information.
2. Player creates text streams for the closed captions.
3. Media Source Engine calls mux.js Caption Parser API to get the closed
captions embedded in the video streams.
4. Text Engine stores the closed captions, and text displayer shows the
captions.

TODO:
1. Add test cases, will send out another CL.
2. Change closed captions support for hls to the similar way we handle
dash closed captions, will send out another CL.
3. Handle dash content that's missing language indication from the manifest.

Issue: #1404
Change-Id: Ibae8f69623c13561415ec860107d7f5bc86e19e9
2018-11-06 09:53:18 -08: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 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
Aaron Vaage db77c05321 Rename filterVariantsByConfig to filterVariantsByPreference
Since we pass in preferences and not a config object it made sense
to call it filterVariantsByPreference.

Change-Id: I288569ee91f3b19e3927489bf020142fbf3306f7
2018-09-01 00:44:43 +00:00
Aaron Vaage 0310c78b92 Isolate Util Method To Be Near Usage
There was a stream utilty was that only be used in one class
(another utility class). The method was to get tracks, but it
sat along side other methods that look similar but were different
in very small ways.

This change moves that function to be in the same class as where
it is used so that it will be less distracting from the other
getTrack methods.

Change-Id: I21737b6b1341c06b41e6016e24b2b20ce5d40e77
2018-08-30 19:39:37 -07:00
Aaron Vaage e25aa0b17b Refactor Ugly Promise Chain in Storage
There was an ugly promise chain in Storage.loadInternal. This change looks
to clean up that promise chain and to use async syntax instead.

Part of the refactoring splits |loadInternal| into two more focused methods
as an effort to make the code easier to understand.

Change-Id: Ica113344c6c4ba1d82b6cee281268e20be1aa411
2018-08-27 16:31:32 -07:00
Joey Parrish e100553fa0 Add missing @private annotations
Issue #1553

Change-Id: I36cb50cbec9ee816a82274ebc83dfae2ba095214
2018-08-21 10:19:24 -07:00
Aaron Vaage c8a0959d0a Change filterNewPeriod to help with debugging
While working on #1505 I made some changes to |filterNewPeriod|
to make it easier to see which streams were getting rejected
at a high-level.

This helped by making it easier to see which streams would
get rejected and which streams were accepted. This made it
easier to see the differences between which streams were
playable and not playable.

Change-Id: I0558de50552a614692488a6c78d46b5ea345bc7b
2018-08-20 21:41:05 +00:00
Aaron Vaage 68cdd834e9 Change meetsRestrictions to help with debugging
While working on #1505 I made some changes to |meetsRestrictions|
to make it easier to why a stream may not meet the restrictions
while debugging.

I also found that there were some special cases (video.width and
video.height being undefined) that were not well explained in the
code. In this change I try to make those cases more explicit.

Change-Id: I61f7732a30bd391f9ca14cd21f25ccfb8ed33ac7
2018-08-15 21:58:45 +00:00
Joey Parrish 2aacdd25c9 Expose DASH Representation IDs in new field
The DASH parser will now expose Representation IDs via new fields in
the Stream and Track objects.  The "id" field will continue to be a
unique, auto-generated numerical ID, and will be supplemented by a
nullable string containing whatever was originally in the manifest.

The HLS parser will now expose the NAME attribute in the originalId
field as well.

Bug: 112087288

Change-Id: I6b8107d27780fb97ab18de767f7abdc6c7110fe7
2018-08-09 17:08:42 +00:00
Aaron Vaage 05b071d7fa Add Stream Utils for Common Practices
Added two new stream utils for practices that pop up multiple
times in our code base.

  1. getAllVariants - Get all the variants in a manifest.
  2. getVariantStreams - Get all the streams (audio and/or video) back
                         as an array.

Change-Id: I87fa4959e4a17dcfff20d5aa0678e6dc346d413e
2018-08-06 16:52:33 +00:00
Aaron Vaage 44bfce73fd Limit Scope of applyRestrictions
When reading through player I saw we did something like:
let variants = period.variants;
...
shaka.util.StreamUtils.applyRestrictions(period, ...);
...
doSomething(variants);

This causes some confusion as it was not clear if |variants| would
still be valid to use (i.e. could applyRestrictions) change the
reference in period like we do in some other filter functions.

So to help make it clear that it doesn't, I have changed
applyRestrictions to accept a variant array rather than the period.

Change-Id: I6dc080a1b1e563e5dd2789bd00fb0cfeb7de41de
2018-07-19 20:33:32 +00:00
Joey Parrish fd0449d8f7 Re-enable some disabled style rules
This re-enables the following style rules:
  - "block-spacing"
  - "brace-style"
  - "comma-dangle"
  - "comma-spacing"
  - "new-cap"
  - "no-multi-spaces"
  - "no-multiple-empty-lines"
  - "one-var"
  - "padded-blocks"
  - "prefer-rest-params"

Change-Id: I15d616e8d5b88b273ded6128b4f9ad86bdb26bd1
2018-07-09 19:44:56 +00:00
Aaron Vaage e21a87b0d9 Stop Playhead From Passing Manifest To Anyone
In an effort to decouple Manifest from Playhead this change removes
the utility function getRebufferingGoal.

getRebufferingGoal was only used in playhead.js, playhead_observer.js, and
streaming_engine.js. However, it was used in two different ways:
  - playhead.js and playhead_observer.js always used it with a scale of
    one.
  - streaming_engine.js used it with a custom scale and then with another
    buffering value.

Since the logic inside the function was so simple and the use of the function
between call sites were different enough, there appeared to be little value
in keeping the function.

Change-Id: Ie0983a1f84516a3cf5de34cd5ed87d1e786862d8
2018-07-06 10:36:34 -07:00
Sandra Lokshina 8065bd54a8 Change namespace from shakaExterns to shaka.externs
Change-Id: I16432351e2a266aa8fd175669aa27c44bfdffeae
2018-04-11 17:26:26 +00:00
Joey Parrish 79a6146b5f Revert change to Track and Stream structures
In the initial fix for #1013, we changed the name of the channelsCount
field in both the Track and Stream structures.  This would break
compatibility for applications.  So even though the new name was in
some ways preferable, we must revert the name to avoid more breaking
changes in v2.4.

Issue #1013

Change-Id: Ie8f3d211c42c8046039a3db9f0926c68ad1315d9
2018-04-10 23:45:53 +00:00
Joey Parrish 6bdbebfa47 Minor cleanup of null checks on non-nullables
Change-Id: I924c267be2b8fc689391ed888f08707e0bd574e0
2018-04-09 18:05:04 +00:00
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
Theodore Abshire 7c5186332b Typo fixes and rewording in comments, part 7
This makes a large number of small typo fixes. It also rewords a
number of comments and JSDoc descriptions, and does some
formatting standardization.

This doesn't fix every single issue, but it fixes a lot. Notably,
there were some formatting issues I declined to standardize due to
ambivalence on what the proper standardization would be; for example,
when and where empty lines should show up in JSDoc.

Change-Id: I225f5c7e54adf4cca8512cddae082ba50ed82e4e
2018-03-21 19:45:15 +00:00
Jacob Trimble 624acc66b8 Add curly braces to all blocks.
Google style guide requires adding curly braces to all block statements
even if it is only has one line.  This fixes it by using eslint's
--fix flag followed by running clang-format to reformat the change.

Change-Id: Idc086c2aa8c02df5ef8b2140a11bfb9128eeb4bd
2018-02-21 11:23:34 -08:00
Jacob Trimble f70436540c Convert 'var' to 'let'/'const' (3 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: I10f5c38a8b06b5797c6eec7492829084114514c9
2018-02-14 00:47:03 +00:00
Joey Parrish 529e97fbf2 [ES6] Configure eslint with Google style checks
Some style rules are temporarily overridden until we can get in
compliance.

Issue #1157

Change-Id: Ie27be6ec6632b7786a1f9ebc32911ba9dcd42599
2018-01-18 00:01:05 +00:00
theodab d6773da99b Prefer no role text streams when no preferred role
Beforehand, if there were some text streams with a given language
which had a role, and some which did not, the no-role text streams
would never be chosen.
Now, they are chosen if there is no preferred role.

Closes #1212

Change-Id: I28b426304b1a828f500012425b8d89c94ccc3178
2018-01-04 22:26:57 +00:00
Aaron Vaage 6c89a36fa7 Changed filterStreamsByLanuageAndRole to take streams
Before, filterStreamsByLanguageAndRole would take a period, this changes
it to take an array of stream to better match the function name.

Change-Id: I4621f98ff17d8d1c3c95162217eef9b8cf7aaebc
2018-01-02 17:28:11 +00:00
Aaron Vaage d98df7e244 Changed filterVariantsByLanguageAndRole to take variants
Before, filterVariantsByLanguageAndRole would take a period, this changes
it to take an array of variants to better reflect the function name.

Change-Id: Ic090baf4a281798ec855e369b0b4acdf519fee14
2018-01-02 17:28:11 +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
Aaron Vaage f4d655deb1 Changed filterNewPeriods to take audio and video separately
To prevent us from packing and unpacking audio and video from an object
this changes filterNewPeriod to just take audio and video rather than
a map.

Change-Id: I152f2b1762d4ff9ce21cb5b501579bca315e4e4a
2017-11-01 17:18:22 -07:00
Aaron Vaage 9f2e3fbcf3 Changed Stream Utils To Use Filter
Originally some of the logic in Stream Utils was iterating over elements
manually and doing its own splicing and index manipulations. This changes
it to use array.filter so that the logic is simpler.

Change-Id: I2a8d1db9336a574e0992e0de430afd006dea4846
2017-11-01 15:25:26 -07:00
Aaron Vaage fb6907575d Changed how isStreamCompatible is formatted
Changed how isStreamCompatible is formatted to make it easier to read.

Change-Id: Ic40754095ad25a8c91942fd13565f3d3ccc36377
2017-11-01 22:21:08 +00:00
Aaron Vaage 81cad159c3 Renamed functions to be questions
There were two functions is stream utils that were used to check
for compatibility. However they were named as statements, and this changes
them to be named as questions.

Change-Id: I0ca7e4a6597910a8f65192c50b9def895e2ac437
2017-11-01 22:20:58 +00:00
Joey Parrish 3cd18bb336 Query platform MSE support using "extended" MIME types
Some platforms (such as Chromecast) support extra MIME parameters like
framerate, bitrate, width, height, and channels.  Since other
platforms will ignore these extra parameters, we should always query
using these parameters.

This introduces the framework to construct these "extended" MIME types
from Stream objects.  Extra parameters for other platforms can easily
be added later.

Change-Id: I8936ca93e84068da18f12127fbc8fc1a0646695a
2017-08-17 17:35:00 +00:00