Commit Graph

59 Commits

Author SHA1 Message Date
Theodore Abshire 3a67802ce2 Fix parseFirstCue test on some platforms.
It turns out that, on some browsers, incomplete XML does not properly
parse. This means the parseFirstCue tests did not work on those platforms.
This modifies those tests on platforms that do not support partial XML;
when no support is detected, it instead tries to get the first cue
from a non-partial segment.
This also modifies the HLS parser to only load partial text segments if
the text parser supports it; otherwise, the hls parser will load full
captions in order to extract start times.

b/137945635
Issue #2037

Change-Id: I58112864a818baf155b365a65fba1c8a56eb9520
2019-07-24 11:23:03 -07:00
Theodore Abshire 1e12873fb7 Only parse first cue when getting text start time.
Previously, when the text engine tried to load the start time of
a segment, it would parse every cue in that segment, then check the
time of the first cue. This was judged to not be a significant
performance issue, as parsing cues is a fast operation. However, it
did have an unintended side-effect: in some situations, this method
was being passed partial segments; notably, the HLS parser would load
the first 2048kb of the stream's texts to extract timing data.
If the caption parsers tried to actually parse an incomplete caption,
they would error.
This gives the text parsers "parseFirstCue" methods, and uses those
methods when it only needs the first cue anyway.

Fixes #2037

Change-Id: I2a1fb2f1a96d98967f0c6e6a5c277914a28b42ad
2019-07-17 21:27:32 +00:00
Vincent Valot a88e3be128 fix ttml background image support (#2034) 2019-07-16 11:02:37 -07:00
Vincent Valot c670b55d72 enhance ttml rendering (#1962) 2019-07-12 16:25:59 -07:00
Jacob Trimble 5c35108cb8 Avoid integer for loops.
Issue #1518

Change-Id: I3ba3cb6a439264e823022b2a64e7cdbd265494c7
2019-07-09 17:11:49 +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 010a60b8f1 Use objectContaining in text tests.
Instead of checking each property separately, just use
jasmine.objectContaining.  This also adds a utility for matching a
number that is close to an expected value.  This is required when
matching objects with toEqual().

Change-Id: I4de49cfaf254e0752beffc97c578a77f9ec8ee95
2019-06-26 18:54:13 +00:00
Jacob Trimble e2ba179201 Favor using toHaveBeenCalledTimes.
This gives better error messages than using toBe() or toEqual() with
the number of calls.

Change-Id: Ice353f1ebcc715da69416da2d983e919597f82d1
2019-06-26 18:52:36 +00:00
Jacob Trimble 3da809019b Enable additional ES6 linter rules.
Change-Id: I6861541b27153ba034364a5972a9b086de581cef
2019-06-11 18:35:09 +00:00
Theodore Abshire b805d15444 Convert externs to ES6.
Issue #1157

Change-Id: Ib8ddecc7106fea8c24c10cfac406c4709a3f275b
2019-06-10 17:52:08 +00:00
Jacob Trimble a69047ba0d Convert text tests to ES6.
Issue #1157

Change-Id: I839d4ab38324a2247bb3c788837a16652d401595
2019-05-21 22:56:34 +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 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
Sandra Lokshina 493d459c47 Add a DOM util.
Change-Id: Ia0941868f20dbb42fa0fe02a639015ac244a65ed
2019-04-05 12:01:59 -07:00
Joey Parrish 73c2ac72d3 Fix CEA timestamps with presentationTimeOffset
When CEA captions are extracted from video segments, the
presentationTimeOffset of the video segment should be applied to the
extracted captions, as well.

Fixes b/70902665

Change-Id: I446333a14b8b6374786ab594a579b6e18bc73ac1
2019-02-13 10:45:34 -08:00
Aaron Vaage 39651c51b0 Refactor to have a central fake text displayer in tests
There we a couple different fake text displayers in our tests. This CL
take them all and consolidates them into one fake text displayer.

Change-Id: I889aa4f11660d641920b0628e7e91549cb715c6a
2019-01-22 19:13:31 +00:00
Michelle Zhuo 1f324e27e7 Separate text direction and writingMode
CSS style 'direction' supports only horizontal directions, (left to
right, right to left), and writing-mode supports horizontal top to
bottom, vertical left to right, vertical left to right.
Separating the field 'writingDirection' to two fields 'direction'
and 'writingMode', so that they're the same as the css style names.

Issue #1708

Change-Id: Ie730bd7d13e5483d7425261854c268cd7f095400
2019-01-11 00:40:27 +00:00
Aaron Vaage 60db39bc80 Create Jasmine Matchers for OnceMore Checks
In our tests we regularly have checks that repeatedly check if a
function/spy has been called once more. To check this we would check
the call and then reset the calls each time.

To abstract this out, this CL defines two custom jasmine matchers that
allow us to check if a function/spy has been called once more.

To validate the matchers, TextEngine tests were update to make use of
it.

Change-Id: Ia6bf8d0a585648126881e1713b35be674bd47ba7
2019-01-08 19:58:58 +00:00
Michelle Zhuo a51bc995f7 Add integration tests for closed captions
Issue #1404

Change-Id: Id8c16c073f3f85fd093d33e3f40e809fa574f5ee
2018-12-05 00:07:59 +00:00
Michelle Zhuo b9a806d071 Add test cases for CEA closed captions
Issue #1404

Change-Id: I35e679ef985ac5cef1f8d8673192845cae29b114
2018-11-08 15:13:51 -08:00
Jacob Trimble aa64769513 Remove VTTRegion support.
Browser support is currently buggy and limited, so until they fix it,
this removes VTTRegion support.

Closes #1584

Change-Id: Ia5bb34dd3ea94737adcdd1d441201bb97b303f81
2018-09-18 21:59:10 +00:00
Jacob Trimble d70af736ae Add namespace-aware parsing to TTML parser.
Closes #1585

Change-Id: Ic508e8e882c5a37c0545e19b09c58e642a00ec57
2018-09-18 16:44:35 +00:00
Joey Parrish 9cce246325 Fix TextEngine buffered range calculations
This reverts commit c38d4dd8d3, which
actually broke text range calculations in v2.3.10, and v2.4.2-v2.4.4.
The original commit was meant to account for the period start, but
resulted in a double-accounting of presentationTimeOffset.

The start and ends times passed into TextEngine's appendBuffer were
period-relative, so timestampOffset had already been applied.  To
avoid further confusion and to fix the original issue the reverted
commit tried to address, these have been changed to
presentation-relative timestamps.  Now the period start and all
offsets have been accounted for before the metadata reaches
MediaSourceEngine and TextEngine.

The tests added in the bad commit have been modified to test for the
opposite: that we do not erroneously account for timestamp offset when
calculating the buffered ranges for text.

Closes #1562

Change-Id: I9fa7a3f59906c4f3e623f411e48551f86f5c2ff7
2018-08-28 17:21:39 +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
Jacob Trimble 759eef9685 Change goo.gl links to bit.ly.
https://goo.gl is being turned-down, so we can't use it for new URLS.
So we have consistent short links, this converts them to be
https://bit.ly.

Change-Id: I07a86cba807b67157664893341f648023918d0de
2018-06-22 20:20:00 +00:00
Jacob Trimble c38d4dd8d3 Fix TextEngine buffered range calculations.
For multi-Period content, we need to account for the timestamp offset
in the buffered range calculation since the start/end times are
given as Period-relative.

Change-Id: I6d32de2abc316918333b1c58ba73c71d028284c4
2018-06-18 14:54:15 -07:00
Sandra Lokshina 8065bd54a8 Change namespace from shakaExterns to shaka.externs
Change-Id: I16432351e2a266aa8fd175669aa27c44bfdffeae
2018-04-11 17:26:26 +00:00
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
Jacob Trimble 064089152b Remove spacing around object definitions.
This is an automated fix to be inline with Google style guides, this
was created with eslint's --fix option.

Change-Id: I860eecbc8152603e730aa17a1393f16d26b3b6fc
2018-02-21 13:35:00 -08: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 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
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 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 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 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 e2aef50912 Disallow unknown "this"
This change enables an additional conformance check in the compiler
which prevents us from committing code where the compiler fails to
infer what "this" means.

None of these changes constituted actual bugs, just inference failures
in the compiler.

Issue #1130

Change-Id: If9b18203768e197258042a9b4339530f371ed831
2017-11-15 11:35:56 -08: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
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
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 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
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