Two targeted performance improvements in aimed at reducing overhead on
older devices
1. Avoid intermediate array for representation ID uniqueness check
Previously, all representation IDs were pushed into a temporary ids[]
array, then a Set - this PR eliminates the array allocation entirely.
2. Re-parse only affected AdaptationSets for dependency streams
Previously, when any stream had a dependency stream, every AdaptationSet
was re-parsed from XML. Now, only the specific AdaptationSet nodes that
contain streams with dependencies are re-parsed. This avoids redundant
XML traversal and parsing for the common case where most adaptation sets
have no dependency streams.
A new integration test has been added.
The use of `stream` within `stream` in `periods.js` has been refactored
to simplify management and avoid duplicates.
---------
Co-authored-by: Wojciech Tyczyński <tykus160@gmail.com>
Adds period caching to speed up manifest parsing. The aim of this
feature is to improve parsing of length multi-period DASH manifests on
low power devices.
This initial support is complete but not efficient, as it involves
conversion to XML and normal processing. It should only be used for
testing purposes. Improved support will be added in the future.
Tested with https://github.com/Dash-Industry-Forum/dash-json-schema
Note: This is only added to the experimental build.
This PR modernizes and optimizes XLink handling in the DASH parser by
removing the legacy flag-based behavior and replacing it with a
standards‑aligned, fast, and deterministic workflow. The changes improve
performance on large MPDs, simplify configuration, and ensure correct
XLink expansion according to DASH/XLink rules.
XLink processing is now automatically enabled only when needed. If the
MPD contains no XLinks, the parser skips processXlinks entirely.
Added polyfills for `Map.getOrInsert()` and
`Map.getOrInsertComputed()` from the TC39 upsert proposal and refactor
the codebase to use them.
These methods replace the common "check if key exists, then set default"
pattern with a single atomic operation. This improves code readability
and eliminates redundant map lookups throughout the player.
---------
Co-authored-by: Álvaro Velad Galván <ladvan91@hotmail.com>
This pull request improves support for external SIDX (Segment Index)
files in DASH manifests, particularly when the `RepresentationIndex`
uses a different `BaseURL` or `sourceURL` than the media itself. It also
enhances base64 decoding robustness and adds a new unit test to verify
correct behavior.
**DASH SIDX and Segment Reference Handling:**
* Enhanced `Mp4SegmentIndexParser.parse` to accept an `indexIsExternal`
parameter, enabling correct parsing of SIDX files that are external to
the media and may have different base URIs. The parser now adjusts the
offset logic for external indices.
[[1]](diffhunk://#diff-6435d27cfd56024b0920175aa9a6992242d18900d27f7edfaa77d89673a8dd0aR29-R37)
[[2]](diffhunk://#diff-6435d27cfd56024b0920175aa9a6992242d18900d27f7edfaa77d89673a8dd0aR54-L63)
* Addresses #6091: Updated `SegmentBase.generateSegmentIndexFromUris` to
detect when the index URI is external by comparing the base URIs, and to
pass this information to the parser. This ensures that segment
references are resolved against the correct URIs.
**Robustness Improvements:**
* Improved base64 decoding in `Uint8ArrayUtils.fromBase64` by
normalizing padding, handling cases where the input string omits
trailing `=` characters.
**Testing Enhancements:**
* Added a unit test to verify that `RepresentationIndex` with a
different `BaseURL` or `sourceURL` is correctly honored, ensuring that
segment index requests use the proper URI and range.
---------
Co-authored-by: Álvaro Velad Galván <ladvan91@hotmail.com>
Fixes https://github.com/shaka-project/shaka-player/issues/9480.
A change in PTO when updating periods & segment timelines should be
avoided by whatever produces the manifest. This is merely a mitigation.
When detected, it'll log an error to warn the user about the timeline
shift.
Use PSSH string to cache init data in order to avoid creating duplicated
init data buffers. On streams with many periods due to ad insertion it
can make a difference - i.e. on stream with 50 periods this change
reduces used memory by init data buffers from 40 KB to 1 KB.
In DASH, PSSH can often be a duplicated data between protected periods
and/or adaptation sets.
Keeping `this` references in DASH uri callbacks leads to keeping
DashParser instances in memory after unloading.
Luckily this is only the issue in uncompiled mode, Closure Compiler
handles it somehow. It is though better to fix it in case we change
tooling some day.
Closure Compiler will soon start typechecking well-known symbol
properties, such as Symbol.iterator - see
https://github.com/google/closure-compiler/issues/1737.
This will cause some type errors in existing code that implements
`Iterable` (for context, I ran into these errors in google's internal
repo) that is missing a Symbol.iterator override or `@override`
annotation
Due to not setting the `boundaryEnd` for the last period, we ensure we
do not discard the wrong segments in a live to VOD situation (where a
boundaryEnd becomes available mid stream).
The same applies in live, when a period ends and a new period starts.
The previous one will now have a boundaryEnd, the new one does not.
Co-authored-by: @avelad
For DASH segment templates, MpdUtils.fillUriTemplate() is used for
substitution of tokens in the fetch URL, like $RepresentationID$. When
supplemental codecs are used, the incorrect RepresentationID will be
substituted for media segments. The initialisation segment is correctly
substituted.
The symptom is that fetches for media segments will fail with 404
response codes.
In LCEVC dual-track implementation, both tracks share the same
originalVideoId, which causes one to be dropped when `getVideoTracks()`
returns them as a Map. This PR assigns a unique originalVideoId to each
track to ensure both appear correctly in the resolution menu
We had an issue where in SSAI content, 708 data was being split by ad
periods. Currently, when this happens, we reset the 708 decoder, which
means that captions are lost. Instead, we want to cache this decoder for
a later time. This change keeps track of continuous periods and caches
the 708 decoder when a period change happens to a discontinuous period.
This is so that it could be later restored if we go back to a continuous
period.
---------
Co-authored-by: Álvaro Velad Galván <ladvan91@hotmail.com>
Co-authored-by: Wojciech Tyczyński <tykus160@gmail.com>
This PR introduces support for `ProducerReferenceTime` tags in DASH.
When finding any, it emits event, similar to inband PRFTs added in
#4389.
Additionally, calculated start date from `ProducerReferenceTime` is used
as program start date, as it's more accurate value than
`MPD#availabilityStartTime` used before.
Fixes#8278
Migrates deprecated rules from `eslint-config-google` and our rules as
well to stylistic.
Additionally removes broken `eslint-disable` python check and replaces
with eslint `reportUnusedDisableDirectives` option.
There's devices out there that are not compliant with the MSE spec. Such
as halting MSE when a secondary init segment is appended (webOS 3), or
failing to transition from a plain to encrypted init segment (Tizen
2017). While we initially prefer content workarounds, it's a time
consuming and trial & error process. For some devices it might not be
worth investing time into finding a proper workaround due to low usage.
We're giving people an alternative by resetting MSE when needed
(configurable). dash.js offers somewhat similar behavior
[here](https://github.com/Dash-Industry-Forum/dash.js/blob/a656ec709e7f92f76b392bf196ee9883da7928ce/src/streaming/controllers/StreamController.js#L672),
where MSE is reset before applying an encrypted init segment.
This PR introduces `crossBoundaryStrategy` in `StreamingConfiguration`.
It can be configured as following:
- KEEP - we're keeping MSE active, this is the default and the current
behavior.
- RESET - we'll always reset MSE when it crosses a boundary.
- RESET_TO_ENCRYPTED - we reset MSE when it crosses an encrypted
boundary, and we keep MSE afterwards. Additionally, we're not going to
reset when we're crossing a plain to plain boundary.
Each initSegmentReference now holds an `encrypted` and `boundaryEnd`
value. When configured with a different value than KEEP,
`StreamingEngine` will be instructed to fetch and append segment
references up until the boundary of the currently applied init segment.
We detect whether we're at a boundary in a few ways:
- Listening to the HTML5 MediaElement's `waiting` event, this'll
indicate that we do not have enough buffer to advance. If we're pretty
close to the boundary, we assume we're at the boundary.
- Due to subtle differences in the segment alignments, waiting wasn't
reliable. When close to a boundary, a timer is fired with the assumption
that "we'll reach the boundary at soon". I've set the threshold to 1
second, when playhead is further than the threshold, we'll skip checking
whether an MSE reset is due.
The implementation relies on the added properties in the init segment
reference, and the concept of a "Period" is avoided in StreamingEngine
to ensure it's compatible with HLS too.
---------
Co-authored-by: Álvaro Velad Galván <ladvan91@hotmail.com>
Co-authored-by: Wojciech Tyczyński <tykus160@gmail.com>
`TimelineSegmentIndex` `fitTimeline` doesn't check if `templateInfo` is
null. This means it errors in this case when it tries to access the
`timeline` property. It now exits early if it's null