Commit Graph

42 Commits

Author SHA1 Message Date
Álvaro Velad Galván 231dd03dbd fix: Avoid throw BUFFER_READ_OUT_OF_BOUNDS when not necessary (#8753)
This only happens when a stream has incomplete mp4 boxes.
2025-06-17 13:10:29 +02:00
Álvaro Velad Galván e731e8ba37 chore: Stop using "Object" in some utils annotations (#7935) 2025-01-24 08:30:03 +01:00
Wojciech Tyczyński 6e55a3b21b build: Forbid using dot in generic types (#7904)
Fixes #2643

Happy reviewing!
2025-01-20 09:39:51 +01:00
Álvaro Velad Galván bca9f2514b fix: Fix ENCA box parsing (#6298) 2024-02-27 08:27:14 -08:00
Álvaro Velad Galván d6001097a9 fix(cea): Fix not rendering CEA-608 on encrypted mp4 segments (#4756)
Fixes https://github.com/shaka-project/shaka-player/issues/4605

Co-authored-by: Joey Parrish <joeyparrish@google.com>
2022-12-01 22:34:34 +01:00
Álvaro Velad Galván 57c73241a0 fix(performance): Eliminate use of ES6 generators (#4092)
See: https://github.com/shaka-project/shaka-player/issues/4062#issuecomment-1077826210

Co-authored-by: @joeyparrish

Issue #4062
2022-04-04 10:58:16 -07:00
Joey Parrish d99ab7959d build: Update eslint (#3977)
Also fixes linter errors found by the new versions
2022-02-18 08:26:43 -08:00
Percy Tse e02d28c765 fix(LL-DASH): Fix index out of bound issue when parsing mp4 segment (#3403)
Fixes #3402
2021-05-17 10:01:12 -07:00
Joey Parrish edce1899f9 fix: Fix header sizes for MP4 boxes with 64-bit size fields
The MP4 box header depends on both whether the box is a "full" box
(with version and flags) and whether the box has an extra 64-bit size
field.  The MP4 parser was only considering the version and flags, but
not whether the extra size field was present.  We already correctly
parsed the 64-bit size field, but computed offsets for other fields
without considering this.

Groundwork for a fix for #2759

Change-Id: I48f16ef073a036954b6f7d25641ccf29828b02c8
2021-01-14 12:57:41 -08:00
Joey Parrish 562a2d567b chore: Strictly require jsdoc
This enables the eslint rule requiring jsdocs on all class
declarations, function declarations, and methods.

Unfortunately, there are two problems with this:

1. We don't use class _declarations_, we use class _expressions_,
which are not covered by this rule.  So it does not enforce jsdoc at
the class level.
2. We tend to document a class at the class-level, rather than at the
constructor.  But a constructor counts as a method for eslint, so it
requires docs on the constructor.  There is no way to configure it to
make an exception for trivial constructors.

So for all trivial (no-argument) constructors, we add empty jsdocs:
  /** */
  constructor() {

This was quicker and easier than setting up some alternative plugin in
eslint to make an exception for us.

The good news is that this rule caught several undocumented parameters
and places where the jsdoc comment was malformed.  So fixing those
also improves the compiler's ability to enforce types.

Change-Id: Icbc46ed690c94e53d354648a883119524f8fca45
2021-01-09 02:00:31 +00:00
Michelle Zhuo 40d0359732 feat(LL-Dash): Parse and append ReadableStream by MP4 boxes
To enable low latency streaming, we need to append chunked data of
ReadableStream by complete MP4 boxes.
Everytime we get chunked data of the ReadableStream, we find the
last complete Mdat box. Append the completed boxes of data, and save
the data of the incomplete box until next time we get the chunked
data.

Issue #1525

Change-Id: I722ff992f397ee2f62bca45db33a0834ef57a270
2020-09-16 13:18:03 -07:00
Jacob Trimble dc8b007d56 cleanup: Add missing requires.
This is a port of the internal changes: cr/321495405, cr/321592702,
and cr/321594488.

Change-Id: If6a4c4266ed10a70b01442974dbd19329bb5122e
2020-07-16 10:59:49 -07:00
Joey Parrish f539147d48 fix: Correct license headers in compiled output
This fixes all the license headers in the main library, which corrects
the appearance of the main license in the compiled output.

It seems that the `!` in the header forces the compiler to keep it in
the output.  I believe older compiler releases did this purely based
on `@license`.

Issue #2638

Change-Id: I7f0e918caad10c9af689c9d07672b7fe9be7b2f3
2020-06-09 16:05:09 -07: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 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 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 596c80a949 Refactor handling of ArrayBuffer.
This changes the network API to use BufferSource instead of ArrayBuffer,
which allows plugins to return a "view" on a buffer instead of the
whole buffer.  This also adds some utilities for changing between
views and buffers.

Lastly this forbids the use of the "buffer" property of TypedArrays
since it doesn't work with partial "views".  This audits and fixes the
usages of the "buffer" property to ensure correct usage.

It should be noted that both MSE and EME accept a BufferSource as input,
so we don't need to convert a "view" into an ArrayBuffer before passing
to it.

Change-Id: Iaa417773f8ce5304424e43c7372ce10ebf540d2a
2019-08-20 20:17:33 +00:00
Jacob Trimble fd0dc8a5cc Add utility for looping from 0 to n.
Closes #1518

Change-Id: I865f7a0311516d04ae84532dab873e1aaa31eb24
2019-07-10 21:23:22 +00:00
Jacob Trimble 5c35108cb8 Avoid integer for loops.
Issue #1518

Change-Id: I3ba3cb6a439264e823022b2a64e7cdbd265494c7
2019-07-09 17:11:49 +00:00
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 d5780d401b Fix line length issues for indent fix.
Change-Id: I87d75fd88000f8f9bff7b9f1bf5667ba28f6dd60
2019-05-13 22:31:20 +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 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
Theodore Abshire 038688ffa6 Don't error when skipping mp4 boxes with bad size
In some situations, the mp4 parser might be required to read a box
that has a "size" value that is longer than its actual size.
For example, if there was a partial range request that ends in the
middle of a box.
Obviously, trying to READ a box like that would be a bad idea, but
if the box is going to be skipped anyway, skipping it without an
error is probably not harmful.

Closes #1535

Change-Id: I31d4c00426e6127ef6e1492e9edc7e10ac50ec8b
2018-08-14 20:08:12 +00:00
Theodore Abshire 0726543a04 Made ParsedBox into an extern
The ParsedBox structure used by the Mp4Parser, previously, had
its property names changed in compiled mode.
This makes ParsedBox into an extern, so that it will be preserved
unchanged in compiled mode.

Closes #1522

Change-Id: I0964f8a4b9ccea57c61e2c587a776ed76cfbc8da
2018-08-06 22:10:40 +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
Michelle Zhuo 535de4db84 Refactor: Remove underscore from parameter names
Change-Id: Ie9e6fb59763f454f245175f23c6444f919ba8135
2018-05-08 19:21:51 +00:00
Joey Parrish 772dc231c9 Remove non-nullable on implicit non-nullable types
This is a style cleanup to pass stricter checks from future versions
of the Closure linter.

Change-Id: Icca8f974af7c9f4834acf6bba69e4cef1f89e502
2018-04-09 14:52:59 -07: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
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 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
Niklas Korz 284f19fe75 Fix documentation typos (#1272)
* Add a missing word in ManifestParser comments
* Fix a typo in a comment in mp4_parser.js
2018-02-03 14:11:49 -08:00
Joey Parrish 88857c59aa Fix HLS playback where moof box is larger than 1k
When we started fetching partial HLS segments to find the start time,
we were no longer able to start playback for content with a moof box
larger than the partial segment.  This is because we parsed the boxes
hierarchically, which required the entire payload.

Now, we can selectively instruct the parser to tolerate a partial box
if the part we have includes the child box we are looking for.

This fixes playback of several pieces of HLS content in our demo app.

Change-Id: I956c8b8905dc9f1707f2b24b8248b984b1c036c6
2017-11-13 10:48:27 -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
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
Aaron Vaage ca87772a60 Define Mp4Box Using Strings
When defining a box, the box would be defined as a four
byte integer. Now there is a "fromString" function that
can be used to convert a four character assci string to
a four byte integer.

Change-Id: I78c704e012620c94ae681efb450977305bdb84aa
2017-03-22 23:13:24 +00:00
Aaron Vaage e50d01e03c Correcting Times for MP4 VTT Subtitles
Before the segment start time and end time were used to determine
the start and end time for all subtitles that appeared in the MDAT
box. The time values for each subtitle is specified in the TRUN box.

Now the time values are extracted from the TRUN box and mapped to
the correct subtitle in the MDAT box.

Closes: #699

Change-Id: I7179874aee7b617e994b136d17a082060ab1a0d2
2017-03-21 17:54:22 +00:00
Aaron Vaage 175870fb4d MP4 Parser Refactoring
Before parsing Mp4Boxes was done using the "findBox" method. This
was limted to only looking at one level of the structure and
required a large amount of code to dig deeper into the structure.

This change creates a generalized Mp4 Box parser that should
simplify parsing Mp4Boxes. This will help work on #699.

Change-Id: Ie67ff30a6db890cae16fe02ae9c92bca711815a9
2017-03-16 22:46:19 +00:00
Jacob Trimble fc46b29ed8 Move 'emsg' handling to StreamingEngine.
Rather than having it in the DashParser as a network response filter,
we should have it in StreamingEngine.  This will give it access to the
segment times so we can calculate the presentation times for the event.
Otherwise, there is no way to know when the event should actually occur
since the app can't know which segment is being downloaded or which it
came from.

This also adds startTime and endTime fields to the event so the app
doesn't have to calculate them.  For reverse compatibility, the old
fields will still exist.

Closes #698

Change-Id: Icbaf3619aedfca7ea06bc8b1fe49e9cce65b0cc2
2017-02-23 19:36:06 +00:00
Sandra Lokshina 8b767df6a1 Implement parsing for WebVTT subtitles embedded in mp4.
Closes #277

Change-Id: If74bb81b66a78939b4f87e4f9f793328d50ed069
2016-07-18 23:52:56 +00:00