389 Commits

Author SHA1 Message Date
Álvaro Velad Galván 4f62ce8b24 build: Reduce bundle size by deduplicating license headers (#10182)
Ensure generated bundles contain a single license header instead of
repeating the same notice across bundled modules.

Normalize all copyright years to 2016 and remove
duplicate license headers from generated bundles.

This reduces the final bundle size while preserving license information
in the distributed artifacts.
2026-06-05 12:43:28 +02:00
Álvaro Velad Galván ad8b674784 refactor: Improve code of NativeTextDisplayer (#10106)
Improve readability and separate responsibilities. Use Intl.DisplayNames
when available and fallback to mozilla.LanguageMapping otherwise.

Note: this is in preparation for addressing
https://github.com/shaka-project/shaka-player/issues/9694

---------

Co-authored-by: Matthias Van Parijs <matvp91@gmail.com>
2026-05-27 14:43:58 +02:00
Álvaro Velad Galván 2c4499f153 chore(Mp4Parser): introduce boxes() for multiple box registration (#10091) 2026-05-14 22:56:06 +02:00
Aditya Mishra 415ebdc52e feat(UI): Add live subtitle style preview on hover (#10077) 2026-05-12 13:24:17 +02:00
Álvaro Velad Galván 99fb7e4f8e fix(text): include regionAnchorX/Y in region cache key (#10073)
Region elements were cached by an ID that omitted regionAnchorX and
regionAnchorY, causing regions that shared the same viewport anchor but
differed in region anchor to reuse a previously cached DOM element
positioned incorrectly. Include both region anchor values in the
generated ID so each unique anchor combination gets its own element.

Issue: https://github.com/shaka-project/shaka-player/issues/2583
2026-05-08 12:47:52 +02:00
Karim Laham 27ed71e791 feat(UITextDisplayer): add suspendRenderingWhenHidden config (#10043)
Closes #10042

Adds a `textDisplayer.suspendRenderingWhenHidden` config flag that gates
the IntersectionObserver-based render suspension introduced in #9545.

- Defaults to `true` (existing behavior preserved for browsers/desktop).
- Defaults to `false` on TV devices (detected via
`shaka.device.DeviceFactory.getDevice().getDeviceType() ===
DeviceType.TV`).

Some TV browsers (e.g. older Tizen WebKit) misreport
`IntersectionObserver` visibility for transformed/absolute-positioned
player containers, leading to permanently suspended caption rendering.
Disabling suspension on TVs sidesteps the platform bug at the cost of
running one DOM update per `captionsUpdatePeriod` (default 0.25s) while
the player is off-screen.

Externs updated at `externs/shaka/player.js`. When the flag is `false`,
`applyVisibility_` short-circuits to "always visible" so the IO observer
can never suspend rendering.

---------

Co-authored-by: Álvaro Velad Galván <ladvan91@hotmail.com>
2026-05-06 08:51:25 +02:00
Fredrik Höglin c2ad355e28 fix: avoid pts rollover correction for fmp4/cmaf streams (#10021)
For HLS CMAF streams with WebVTT subtitles with large timestamps, the
rollover wrapping prevents the cues from being shown at the correct
time.

By adding a check to only do the wrapping for MPEG-TS streams this
problem is eliminated.

fixes #10020
2026-04-22 16:12:34 +02:00
Álvaro Velad Galván d689f69c45 fix: Fix suspend caption rendering when captions container is not visible (#9959)
There are platforms (some WebKit STBs) where IntersectionObserver
doesn't work well with fullscreen.
Managing multiple videos on screen. Detecting which one opens in PiP and
Fullscreen.
2026-04-11 23:00:27 +02:00
mohammadmseet-hue b6bc40635e fix(TTML): sanitize backgroundImage URL to prevent CSS injection (#9929) 2026-04-07 12:17:57 +02:00
Álvaro Velad Galván 845b6bd197 fix: Properly clone nested cues and CueRegion in Cue.clone() (#9940) 2026-04-07 12:16:44 +02:00
Álvaro Velad Galván 4706d5f286 feat: Add subtitleDelay config for manual subtitle timing offset (#9939) 2026-04-07 12:15:21 +02:00
Ivan 503234e9c6 perf(VTT): reduce GC pressure in VTT text parser (#9869)
This PR:

 - replaces `splice` with an index variable to avoid array shifts on every cue parse
 - replaces `slice(1).join('\n')` with a manual loop to eliminate two intermediate allocations per cue
 - hoists inline regex literals to static class constants, fixing unreliable literal caching in older Chromium version (helps TV devices and Xbox)
2026-03-20 15:11:10 -07:00
Álvaro Velad Galván 26ecc07c06 fix: Set IntersectionObserver root to null (document not supported in Chrome 63) (#9782)
Fixes https://github.com/shaka-project/shaka-player/issues/9781
2026-03-03 12:37:48 +01:00
Álvaro Velad Galván e35ab38015 fix: Improve NativeTextDisplayer robustness, track-kind issues and enhance cleanup logic (#9776) 2026-03-02 15:29:47 +01:00
Gary Katsevman 8b86ba5f06 fix: delay appending vtt subtitles depending on presence of discontinuity sequence and timestamp offset (#9676)
This PR changes the way that timestamp offsets are stored in the media
source engine. Instead of a single value, it now has a map of values.
For DASH, it should contain a single value, which is the last timestamp
offset available. For HLS, it'll keep track of the timestamp offsets per
discontinuity sequence. If content is appended and we don't yet have a
timestamp offset for that discontinuity sequence number, it'll defer
creating the cues until the timestamp offset is set, otherwise, the
times for the cues may not be correct.

Fixes #9470
2026-02-23 17:23:09 +01:00
gmamzn 548fe2953e fix(TTML): Update position alignment map (#9735)
Map 'start' to 'LEFT' and 'end' to 'RIGHT'
This mapping needs to be reversed for RTL languages.
2026-02-19 14:30:23 -08:00
Álvaro Velad Galván 1139a4e42c fix(UITextDisplayer): avoid ResizeObserver loop warning (#9722)
UITextDisplayer was triggering:

  "ResizeObserver loop completed with undelivered notifications"

This happened because updateCaptions_() mutates the DOM inside the
ResizeObserver callback, which can cause synchronous layout feedback
loops.

This change:

- Observes videoContainer_ instead of textContainer_
- Defers updateCaptions_() using requestAnimationFrame
- Coalesces multiple resize events using a pendingResize_ flag
- Ensures updates only run when captions are visible

This prevents layout feedback loops while preserving correct caption
re-rendering behavior.

Fixes https://github.com/shaka-project/shaka-player/issues/9721
2026-02-17 11:03:18 +01:00
Álvaro Velad Galván 56ac70d44a perf(S2T): Improve SpeechToText code (#9718)
Avoid race conditions when using Translator API.
Avoid unnecessary DOM mutations.
Separate responsibilities in the code.
2026-02-17 10:07:29 +01:00
Álvaro Velad Galván bd167c3744 feat: Add listenMulti and listenOnceMulti to shaka.util.EventManager (#9652)
Co-authored-by: Wojciech Tyczyński <tykus160@gmail.com>
2026-02-03 21:49:35 +01:00
Álvaro Velad Galván afd24224ce feat(SRT): Improve SRT to WebVTT conversion and color handling (#9624)
- Full SRT → WebVTT conversion now supports timestamps, alignment,
position, and basic styles (bold, italic, underline).
- Added proper handling for <font color="..."> tags:
  - Converts known colors to WebVTT <c.color> classes.
  - Safely removes unknown colors without leaving orphaned </c> tags.
- Supports Aegisub cues ({\anX} → line & align, {\pos(x,y)} → position &
line).
- Normalizes timestamps (MM:SS,mmm → 00:MM:SS.mmm) for WebVTT
compliance.
2026-01-29 12:39:38 +01:00
Álvaro Velad Galván aaecc079be fix(TTML): Fix MP4 TTML Parser producing invalid image subtitles (#9559)
Fixes https://github.com/shaka-project/shaka-player/issues/9557
2026-01-14 12:01:02 +01:00
Andy(김규회) 05b09728c7 perf: Use Map.getOrInsert/getOrInsertComputed native methods (#9546)
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>
2026-01-13 10:57:25 +01:00
Álvaro Velad Galván 14ebd65856 feat: Suspend caption rendering when not visible using IntersectionObserver + Page Visibility + PiP (#9545) 2026-01-07 10:20:48 +01:00
Álvaro Velad Galván c4de8f1f53 fix: Fix alignItems usage on old devices (#9544)
start/end are supported from Chromium 93+ (see:
https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/align-items).
2026-01-05 15:04:13 +01:00
Gary Katsevman 2d23ea456a fix: don't clear text displayer cache for vtt if we're clearing cea cache (#9538)
an issue we found as part of making the fix for #9470 and also
separately.
2025-12-23 15:43:33 +01:00
Álvaro Velad Galván c6e6082bc2 feat: Allow override subtitle position (#9522)
Close https://github.com/shaka-project/shaka-player/issues/9521

---------

Co-authored-by: Wojciech Tyczyński <tykus160@gmail.com>
2025-12-19 13:38:33 +01:00
Álvaro Velad Galván d5be5d6f45 feat!: Text displayers should receive a shaka.Player pointer (#9515)
Related to https://github.com/shaka-project/shaka-player/issues/9301
2025-12-17 10:11:00 +01:00
Álvaro Velad Galván 84dccd38f5 fix: Fix external text track timing when using HLS (#9511)
Fixes https://github.com/shaka-project/shaka-player/issues/9510
2025-12-16 14:58:04 +01:00
Álvaro Velad Galván 8f6232027e feat: Improve management of processLocally when using Speech To Text (#9449) 2025-12-01 17:26:26 +01:00
Álvaro Velad Galván 4bc2518e29 feat!: Remove LRC, SBV, SSA support (#9330)
Related to https://github.com/shaka-project/shaka-player/issues/9321
2025-11-04 20:07:02 +01:00
Álvaro Velad Galván b6b3d245ad chore: Reduce SRT complexity (#9333) 2025-11-03 11:30:23 +01:00
Álvaro Velad Galván 8e0e0d85c1 feat!: Remove setSequenceMode from TextParser plugins (#9326) 2025-10-31 16:14:52 +01:00
Álvaro Velad Galván 72955e0cf0 fix(WebVTT): Fix times when using HLS without X-TIMESTAMP-MAP (#9313) 2025-10-30 10:33:31 +01:00
Álvaro Velad Galván 7f662a15b9 feat!: Remove enableTextDisplayer from TextDisplayer plugins (#9311)
This is no longer necessary since we have removed
shaka.text.SimpleTextDisplayer
2025-10-29 16:43:06 +01:00
Álvaro Velad Galván 945c57ab77 feat!: Remove all deprecated things (#9162) 2025-10-07 10:52:13 +02:00
Álvaro Velad Galván 61d80f6e59 feat: Add automatic subtitles (#9123)
Internally this uses Web Speech API
https://webaudio.github.io/web-speech-api/ and Translator APIs
https://webmachinelearning.github.io/translation-api/

The feature is experimental and disabled by default since Chrome is the
only browser that currently supports it.

Closes https://github.com/shaka-project/shaka-player/issues/9110

---------

Co-authored-by: Wojciech Tyczyński <tykus160@gmail.com>
Co-authored-by: Joey Parrish <joeyparrish@google.com>
Co-authored-by: Theodore Abshire <TheodoreAbshire@Gmail.com>
Co-authored-by: Joey Parrish <joeyparrish@users.noreply.github.com>
2025-09-26 13:18:44 +02:00
Wojciech Tyczyński 98fc330945 fix(CEA): Remove closed captions only on video update (#9125)
This change will prevent removing every stored caption on seeking.

Issue is a regression introduced in #9068
2025-09-22 13:54:03 +02:00
Rohan Gupta badaafc8c2 fix: Add cue fontSize fallback when using fontScaleFactor (#9117)
Fixes https://github.com/shaka-project/shaka-player/issues/9087

<img width="1477" height="1017" alt="image"
src="https://github.com/user-attachments/assets/b4a5a6c5-608d-47c6-a639-120167279102"
/>

---------

Co-authored-by: Álvaro Velad Galván <ladvan91@hotmail.com>
2025-09-22 10:39:18 +02:00
Álvaro Velad Galván 2eb3b0a9c8 fix(WebVTT): Fix lines starting with spaces don't break correctly (#9100)
This only happens when there are multiple line breaks.
2025-09-16 16:38:38 +02:00
Álvaro Velad Galván 2d8056a81c fix: Fix blink subtitles when using NativeTextDisplayer in Safari (#9082) 2025-09-12 11:58:33 +02:00
Álvaro Velad Galván f2b5034b64 fix(WebVTT): Fix lines starting with spaces don't break correctly (#9069)
Fixes https://github.com/shaka-project/shaka-player/issues/9062
2025-09-09 11:27:09 +02:00
Wojciech Tyczyński f128e2261a perf(CEA): Remove captions attached to removed segments (#9068)
TextEngine was storing closed captions and releasing them only on
teardown. This might be a potential memory leak for long running
sessions.
This PR addresses it by removing cached captions along with removed
segments. Furthermore, it adds some more tweaks and improvements, such
as:
- simplify CEA cache structure, from `Map<string, Map<string,
Array<Cue>>>` to `Map<string, Array<Cue>>`
- adjust TextEngine buffered ranges with cached cues values
2025-09-09 11:26:48 +02:00
Joey Parrish 849bff1db3 fix: Audit all usage of readBytes for memory leaks (#9027)
Make cloning buffers (or not) explicit in readBytes.

When we use a range of bytes temporarily for further parsing, we pass
clone=false and get a view on the existing memory buffer. When we want
to store the range of bytes, we pass clone=true and avoid holding a
reference to an entire segment in memory.

The call for the EMSG parser in MediaSourceEngine had an explicit clone,
but now uses the new clone parameter. This is not a functional change,
though.

The only readBytes call that changed in this audit was in the UI seek
bar.

The rest all appear to be values for temporary usage, and so are not
being cloned.

The new `clone` parameter will require future callers of `readBytes()`
to think about their purpose and make a choice.
2025-08-27 10:49:48 +02:00
Álvaro Velad Galván aaef0abd84 fix: Fix WebVTT position handling in UITextDisplayer (#9017)
Fixes https://github.com/shaka-project/shaka-player/issues/8948
2025-08-25 15:05:29 +02:00
Álvaro Velad Galván 43a45eab2b fix(HLS): Fix display stpp subtitles (#8995)
It also eliminates the use of private static

Fixes https://github.com/shaka-project/shaka-player/issues/8994
2025-08-20 11:30:48 +02:00
Wojciech Tyczyński f1768a5f84 chore: Remove JSDoc for empty constructors (#8955)
We don't need this anymore with `exemptEmptyConstructors` config added
in #8901
2025-08-05 13:06:00 +02:00
Joey Parrish 7c1e31d4e6 chore: Add trailing commas to all record types (#8820)
Now that jsdoc supports this, it will make future diffs cleaner. See
#8819 and #1236.
2025-06-30 13:36:04 -07:00
Álvaro Velad Galván fa1a6b7c4c fix: Allow change NativeTextDisplayer on runtime (#8735)
This is required to be able to switch at runtime from UITextDisplayer to
NativeTextDisplayer and allow subtitles to be displayed correctly.
2025-06-12 11:02:01 +02:00
xiao 3cbc770b76 fix: NativeTextDisplayer.remove() not following the spec (#8714)
Should return false only if it's destroyed. Or it may cause
[`StreamingEngine`](https://github.com/shaka-project/shaka-player/blob/b752f779cfde99bb6bfa4f7f7dec31bb4f64209e/lib/media/streaming_engine.js#L2627)
to call it repeatedly, thus blocking the thread.

---------

Co-authored-by: Wojciech Tyczyński <tykus160@gmail.com>
2025-06-09 11:40:51 +02:00
Wojciech Tyczyński 970d7756ea feat: Add Device API (#8210)
The goal is to simplify and abstract feature logic detection. Currently
lots of places depend on various calls to `shaka.util.Platform` and
mainteinance of this is hard & not easy to read.

By introducing device API ideally rest of the player logic would look
into device features instead of directly checking platform. Additionally
we can more easily cache needed values, so we won't have to parse user
agent several times anymore.

---------

Co-authored-by: Álvaro Velad Galván <ladvan91@hotmail.com>
2025-06-02 13:46:40 +02:00