Commit Graph

43 Commits

Author SHA1 Message Date
Theodore Abshire 8ea237c214 Fixes how the MDAT is read for VTT in mp4 content.
Previously, we would read each individual VTTC and VTTE box in the
MDAT and associate them with durations in the TRUN. This worked for a
lot of content, but if sampleSize is defined in the TRUN, a duration
might refer to multiple VTTC boxes.

This changes the VTT in mp4 reader to parse the MDAT based on the TRUN,
to account for such situations.

For the moment, this only accounts for a single MDAT, and assumes that
the MDAT contains nothing but vttc or vtte boxes, listed in order.

Issue #1266

Change-Id: I56e310d085abdda16e968761ed3b4fd0cc5e24d0
2018-03-27 17:10:48 +00:00
Theodore Abshire d46e8fdf92 Typo fixes and rewording in comments, part 6
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: I2bfa4d531a8fcdcf9578e9c181c4534ad7443b7a
2018-03-21 17:59:42 +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 0a2190246c Fix catastrophic backtracking in TTML text parser.
Issue #1312

Change-Id: I0aed14068776a800eee35f03d2f878db0dd565b6
2018-02-21 18:49:07 +00:00
Jacob Trimble b512db87dd Convert 'var' to 'let'/'const' (8 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: I6a329d28e13a81c9f7136737518c6bb8fa18402e
2018-02-20 11:29:30 -08:00
Sandra Lokshina 118756e8e8 Add parsing of VTTRegions and TTML attributes set in pixels.
Closes #1188

Change-Id: Ib9fc1a5b35065fdadafae01df4737ce1dcfa3ada
2018-02-08 18:19:31 +00:00
Michelle Zhuo 175e0b9594 Support CEA 708 Closed Captions
Issue #276.

Change-Id: If42ab04a451dc8c4c7038213b7f7c925648c3444
2018-02-03 00:03:44 +00:00
Joey Parrish 14d91b0be8 Improve annotations and docs for TtmlTextParser
During docs review, I noticed that shaka.text.TtmlTextParser's
textAlignToLineAlign_ was defined as merely {Object}.  Improving that
to {Object.<string, string>} caused compiler issues, so I had to
further refine to {Object.<string, shaka.text.Cue.lineAlign>} and
refer to the enum values instead of directly using strings.

Issue #1259

Change-Id: Ifb012771a534f74f4458f8673fd4d12d136b2638
2018-02-01 21:55:01 +00:00
Jacob Trimble 554cffc95c Fix SegmentTemplate w/ duration.
We incorrectly added the presentationTimeOffset to the segment times as
a fix for #1164.  The correct fix is to use the include the PTO in the
time structure passed to the text parsers.  This is a partial revert
of 207505.

Issue #1164
Closes #1232

Change-Id: I1f2805e0dbdc44be71e2160b3d37a73732c97a4f
2018-02-01 00:12:45 +00:00
Joey Parrish ed54199260 Upgrade and unfork jsdoc
This updates jsdoc to the latest version from npm and forks a copy of
the default jsdoc template.

In subsequent commits, we will reapply our customizations to the
template and to a jsdoc plugin.

This also fixes several bad annotations that the new jsdoc failed to
parse.

Issue #1259

Change-Id: I00a47270ea4754e1c96c43ca900d5cf889ab72e6
2018-01-31 22:04:48 +00:00
Joey Parrish d36168a55f Protect against WebVTT MPEGTS rollover
When the MPEGTS field rolls over in HLS live WebVTT, we need to avoid
our parsed cue timestamps rolling over as well.  To achieve this, we
simply ignore the X-TIMESTAMP-MAP tag once the segment index is built.

Rollover in TS video and audio segments is handled by mux.js already.

Closes #1191

Change-Id: Ie52734509921973ff47517fab34367ec413a6ca6
2018-01-19 21:48:35 +00:00
Joey Parrish 4067c20a7c [ES6] Replace gjslint with compiler linter & eslint
The eslint configuration is derived from analyzing the style of our
sources as they are now, plus a few tweaks.

In particular, we have disabled checks for undefined variables and use
of console, both of which the compiler handle with greater precision.
The compiler already knows what is defined in the environment through
our externs, and has specific exceptions for the use of console (demo,
tests).

We have also disabled a few checks that we should use, but will
require many changes to the code: no-unused-vars, no-redeclare,
and comma-dangle.

This commit also fixes several types of eslint errors that were easy:
  - no-useless-escape (unneccessary escape characters in Regexp)
  - no-constant-condition (using true/false/0/1/etc in if/while)
  - no-fallthrough (caught an actual bug in one EME polyfill)
  - no-irregular-whitespace (we had a UTF-8 nbsp in externs)
  - no-cond-assign (using an assignment inside a conditional)

To satisfy stricter provide/require checks in the Closure Compiler
Linter, we will no longer use provide/require at all in tests.  We
will still use provide in test utilities (test/test/util/) since it
sets up the namespace for us.  But we will not use require there
because there is no deps management for test code.

Issue #1157

Change-Id: Icc44f51feeb568ea7d3980e693e92e560d897afd
2018-01-16 17:25:05 +00:00
Joey Parrish 74316c37d9 Add missing require statements
These were not caught by the compiler due to aliases used to access
them, but they were caught by some new linter tools I am trying to
integrate into the build.

Change-Id: I343d155d43285e8244376b95c95b08b5d4f2fa39
2018-01-03 22:29:45 +00:00
Joey Parrish 186e3e69c4 Consistently take Uint8Array in text plugins
Instead of taking Uint8Array for media segments and ArrayBuffer for
init segments, take Uint8Array for everything.

Clean-up after #1022, discovered while preparing the upgrade guide for
v2.3.

Change-Id: I1f284f6f51f345e663c06d96d788bd9cfb941c52
2017-12-19 22:29:43 +00:00
Joey Parrish 66bfa31538 Do not use VTTRegion yet
Our use of VTTRegion seems to be wrong.  The feature in Chrome is
behind the "experimental web platform features" flag.  If this is
turned on, we display subtitles in the wrong place.

Until we can verify and fix our usage of VTTRegion, we will not
use it.  There are other issues to deal with in our region support,
in particular that TTML uses px and VTT uses percentages.  Futher,
our VTT parser does not yet extract region information.

This fixes the main issue for v2.3, so that future releases of Chrome
do not break sites built with v2.3.  There is more work to do in v2.4.

Issue #1188

Change-Id: I0de3392bdfca381c3727580e66c1a57ec457c5c2
2017-12-18 22:39:20 +00:00
Joey Parrish 5cca0e573e Remove deprecated interfaces for v2.3
Closes #1091

Change-Id: I0c15a2bfd51c3074c749d88cd66b89ba64d1fa35
2017-12-06 00:39:11 +00:00
Joey Parrish 9759eddf54 Ignore style blocks in WebVTT
We do not support CSS embedded in WebVTT at this time.  Instead of
failing to parse the cues, skip the style block.

Closes #1104

Change-Id: I3d500ba11afe43e81bbdef9924e4dd9e05db2b85
2017-12-05 23:31:23 +00:00
Joey Parrish af73139d05 Set appendWindowStart in MediaSource
This avoids having media from one period replaced by media from the
next period.  Instead, media that comes before the period start will
be chopped off by MediaSource.

Closes #1098

Change-Id: Idf6dc2ffafe78214e94bc75aca63920e153f1a2c
2017-11-10 10:23:40 -08:00
Joey Parrish a93455a917 Make partial segment requests in HLS parser
This speeds up HLS stream startup significantly for servers that
permit this kind of request, and falls back to full segments for
servers that do not.

Closes #1106

Change-Id: I96bc7f0df0fb84b75f3a3fe43476ba0ba5fc2264
2017-11-07 19:44:35 +00:00
Joey Parrish a18dc01874 Remove broken HLS time offset code
We misinterpretted the EXT-X-START tag before.  Now, we ignore this
tag and parse segment times from the segments themselves.  This is
more robust for both VOD and live HLS content.

We avoid segment parsing when updating normal, well-behaved live
streams.  For poorly-behaved live streams, we will fall back to
segment parsing and recover.

This also addresses the issue of VOD content which does not start at
zero.  Instead of using configuration to make this playable, we will
now offset VOD content back to 0 automatically.

Issue #740
Closes #1011

Change-Id: Ib3a59f87e3a050244cd39854409d8e3542c50b0a
2017-10-30 18:51:29 +00:00
Jacob Trimble a2df5327c1 Add a method to allow logging in compiled mode.
We want to be able to write logs for deprecated APIs.  This ensures
that those logs appear even when we disable logging in compiled builds.

Change-Id: I1f1546049fb17967eedb1bb45a7f76d5b1809cd1
2017-10-27 23:07:23 +00:00
Jacob Trimble d125a54656 Use Uint8Arrays in text parsers.
This converts from using ArrayBuffer in the text parsers to using
Uint8Array.  This avoids doing extra buffer copies when using
ArrayBuffer.slice().

Closes #1022

Change-Id: I34a789ec4eb76c95169ba81f27a8433ef25f27f0
2017-10-03 10:36:48 -07:00
Joey Parrish 3a91c466cf Pull interface exports from constructors
Generated externs should include member assignments from constructors.
Without them, the generated externs may not appear to implement the
full interface.  The alternative is to re-declare these members on the
prototype, but that is more difficult to maintain.  Instead, the
extern generator can convert them for us.

Example code:

/** @interface @exportInterface */
FooLike = function() {};

/** @exportInterface @type {number} */
FooLike.prototype.bar;

/** @constructor @export @implements {FooLike} */
Foo = function() {
  /** @override @exportInterface */
  this.bar = 10;
};

Example externs:

/** @interface */
FooLike = function() {};

/** @type {number} */
FooLike.prototype.bar;

/**
 * @constructor @implements {FooLike}
 */
Foo = function() {}

/**
 * @override
 */
Foo.prototype.bar;

Change-Id: I435ba1800d5eefbf68c27851d6454c1a572cc6f6
2017-09-26 17:57:47 +00:00
Jacob Trimble d997065a02 Fix TTML region parsing.
The tts:origin and tts:extent attributes specify the sub-region to
render cues onto.  We parsed them as positioning info for the cues
themselves.  This converts to using VTTRegion for this.  However, this
is ignored on browsers since none expose VTTRegion as of now.

Closes #1020

Change-Id: I0f922868690461cdd8847c3eba21d944d854f537
2017-09-25 17:35:57 +00:00
Theodore Abshire 3af3a2caec Modified mp4 ttml parser to allow multiple MDATs.
Beforehand, if we were parsing a ttml subtitles stored in an mp4, we did
not account for the possibility that there would be multiple mdat boxes,
each with its own ttml data. In such a case, we would only use the
payload from the final mdat.
I don't know if having multiple mdat like that is really in the spec, but
at least one user has had this problem, and it's a straightforward change
to make that doesn't really slow down the text parser at all (since we
parse every mdat anyway).

Closes #1028

Change-Id: Id782695548cb92f7aa7278843695b670d8c15ff0
2017-09-20 16:18:24 +00:00
Jacob Trimble 2c30ac70b1 Fix shaka.text.Cue in compiled builds.
The fields in shaka.text.Cue were getting renamed in compiled builds,
which would cause problems with custom text parsers or text
displayers.

Change-Id: I5a1c05ad373aca722268417c55a84f195e53ee20
2017-09-15 20:55:14 +00:00
Aaron Vaage 7628bdd7da Issue 991 - Subtitles Fail in Safari
It appears there are different behaviours for text cues on
safari compared to other browsers. We were using "auto" for
position, but Safari does not support setting that value for
position. The spec says that the default value is "auto", so
by not setting it, we can assume that it will be "auto".

Closes #991
Closes #1012

Change-Id: Ibedc5f01f72138df85b911bb5112d40f2f327ad3
2017-09-11 16:30:40 +00:00
Aaron Vaage 2131946bf4 Fix Issue #990 - Null Cue List
When a text track's mode is set to "disabled" the cues exposed cue
list is set to null. However, if you save a reference to the list,
the reference is valid. If the track is disabled, the add and remove
calls still work.

This change caches the reference to the cue's list when the track is
first created so that we can always read it - regardless of what mode
the track is set to.

Fix #990

Change-Id: I8274ea8450e664eeaa359bf9e78d13405fd2e503
2017-09-06 23:03:13 +00:00
Joey Parrish 44fb94a0e3 Add support for MP4+TTML in HLS
Previously, our HLS implementation only supported WebVTT, because
that seemed to be the only supported format in HLS.

Now, we add support for other formats by extending the MIME and codec
guessing system to text streams.  We also add a parser registration
for HLS's new "stpp.TTML.im1t" codec string.

Closes #986

Change-Id: I0a58ca4650675ff0546e36edf4114290f7931239
2017-08-30 12:36:44 -07:00
Sandra Lokshina 2f9b6cc62d Add quotation marks around enums in shaka.text.Cue
Text parsers set several cue enum properties with
parsedValue.toUpper() rather than explicitely stating the enum
value. Renaming enum keys in compiled mode interferes with it.

Closes #987

Change-Id: Id3ff878eaa96bce28eaddd379a457f8743c97ea2
2017-08-25 11:16:37 -07:00
Jacob Trimble 404d42cfa0 Fix text tracks on IE/Edge.
IE/Edge don't accept cues that are out of time order.  So when we
reverse the order of cues for #848, the cues would be rejected.  Now
we sort the cues and only reverse the order of cues with equal times.

Change-Id: I860e1ea9694eb95ff2e74d9545c92373eb371686
2017-08-10 21:03:35 +00:00
Joey Parrish aebb418a44 Fix TextDisplayer check for line and position
If line and position are null, the corresponding VttCue should have
default values.  Before this change, we treated 0 as null, which would
have prevented setting line or position to 0.

Change-Id: I63c3ce301016eb96bf3e6c1299433262c998cdc2
2017-08-07 23:55:20 +00:00
Joey Parrish 9d47a78652 Fix display order of cues with identical ranges
Since the browser displays identical ranges from bottom up, we must
reverse the order before feeding them to the browser.  This way, the
first one parsed shows up on top.

Issue #848

Change-Id: Id2e6582e610808f7061bd0f8281c0705ecf1d6dc
2017-08-07 23:23:20 +00:00
Joey Parrish 7d36a2091f Parse default duration in WVTT MP4s
This adds support for WVTT samples with no sample duration by parsing
the default duration from the "tfhd" box.  If neither is provided, we
now log an error to the console.

Closes #919

Change-Id: Icc5550de7bc6018253004a5d3429ccc083ff6cb6
2017-08-07 19:45:18 +00:00
Joey Parrish a7dec51f76 Make VTT settings parser more flexible
We can now accept non-integral values in settings, such as
"position: 100.0%" instead of just "position: 100%".

The regex change is very simple, so we would also accept invalid
settings such as "position: 12.34.56%" or "position: ...%", both
of which would result in NaN in the output.

Issue #919

Change-Id: I0a437322e76e35fe1d2f369b4a3ea87269799431
2017-08-04 21:28:15 +00:00
Sandra Lokshina 2aefcb8eb6 TtmlParser: add support for tts:direction attribute.
Closes #927.

Change-Id: If7394ecbbee861ad5b60c3c2bfd929ecd999db3e
2017-07-31 18:44:15 +00:00
Jacob Trimble c0976428b0 Disallow Array.prototype.includes.
This is not supported on IE11.

Change-Id: Ifefdbd45cd453fae38ac6b7926a9de8086e773e7
2017-07-19 10:41:16 -07:00
Joey Parrish dc27217518 Fix failures on Safari introduced by TextDisplayer
Our test lab was down for several days and this was not caught until
the lab was back up.

Change-Id: I6c63a8670a780d42c140bfcb3a55614cbb412d8c
2017-07-19 16:30:18 +00:00
Sandra Lokshina b1f337a625 Add style attributes to shaka.text.Cue and TtmlParser.
Closes #927.

Change-Id: Ife2e241f8e91999ac0f4600766b0b0c04738c013
2017-07-19 16:13:56 +00:00
Sandra Lokshina c70367dc97 Separate text parsing and display logic.
Closes #796.
Closes #923.

Change-Id: Ifc2017b40a0fb570103f0fed7bc130aa24819e9f
2017-07-17 21:39:59 +00:00
Jacob Trimble 845c9af2f6 Fix text track reinitialization.
We should not reinit text until we are sure we are switching.
Otherwise, the new text parser won't have seen the init segment and
won't be properly initialized.

Closes #910

Change-Id: Ieb5549afcad7aa58aa1a6e8d383f3cd783280d5c
2017-06-28 13:07:07 -07:00
Jacob Trimble adb8da4764 Disallow unknown properties (1/5).
This is part of adding a new conformance rule to add additional type
safety.  This will disallow using properties of unknown types or using
unknown properties.

The first parts will be fixing errors caused by the new rule.  These
are backwards compatible, so can be applied before the rule is enabled.
Once all the errors and bugs are fixed, the rule will be enabled.

Change-Id: Iefde089b2f62ddfdf43944cda5badab438577561
2017-06-27 19:43:00 +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