Commit Graph

374 Commits

Author SHA1 Message Date
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
Wojciech Tyczyński 769ced524d fix: Use proper method for checking is object an array (#8644) 2025-05-26 17:03:44 +02:00
Álvaro Velad Galván 712738df81 chore: Useless warning on UITextDisplayer (#8637)
Eg: fullscreen is not supported on Tizen, but we want use
UITextDisplayer
2025-05-22 12:42:43 +02:00
Álvaro Velad Galván b9876625d3 fix: Disable translate of cues when using UITextDisplayer (#8636) 2025-05-22 12:04:41 +02:00
Álvaro Velad Galván 3618d4f4ca fix: Only create shaka-text-container when necessary (#8581) 2025-05-09 22:05:39 +02:00
xiao 724b0b2a71 feat: new TextDisplayer implementation to allow selecting subtitles via native API and controls (#8520)
Close https://github.com/shaka-project/shaka-player/issues/8519
Fixes https://github.com/shaka-project/shaka-player/issues/8475

Introduce `NativeTextDisplayer` as a replacement of
`SimpleTextDisplayer`. But keep them both work.
Is MSE mode, `NativeTextDisplayer` creates `<track>` elements for text
streams. And listens to change events on both ends to keep them in sync.
In SRC mode, `NativeTextDisplayer` would do nothing, the player uses
original TextTracks instead.

Advantages of `NativeTextDisplayer`:
- Allow text track selection using the browser built-in UI
- Allow text track manipulation using native APIs
- Avoid transferring and processing cues in SRC mode

---------

Co-authored-by: Álvaro Velad Galván <ladvan91@hotmail.com>
2025-05-07 12:58:29 +02:00
Wojciech Tyczyński 51ff82f204 build: Migrate to stylistic eslint plugin (#8298)
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.
2025-03-19 16:18:30 +01:00
Álvaro Velad Galván c8747ab0b8 feat: Move caption scaling from css to new textDisplayer.fontScaleFactor config (#8242)
Fixes
https://github.com/shaka-project/shaka-player/pull/8215#issuecomment-2711266477
2025-03-12 13:16:48 +01:00
David HM Morgan 18695c6c23 feat: Text font scaling customisation ability (#8215)
With reference to #8025, this is a partial proposal to see if this style
of extensible customisation could be favourable to the shaka-player
community:

Proposal for some accessibility options whereby an App builder can
customise subtitle/caption size, with the potential of an App offering
accessibility options for text size.

This style could be used for other text styling attributes in a similar
way, but this is just the first step.

---------

Co-authored-by: Álvaro Velad Galván <ladvan91@hotmail.com>
2025-03-06 13:44:49 +01:00
Álvaro Velad Galván f3108330c6 perf: Only set the timers on UITextDisplayer when there are cues (#8114) 2025-02-19 13:34:21 +01:00
Juliane Holzt 2562384055 fix(TTML): Correctly handle multiple samples in a segment (#8088)
Fixes https://github.com/shaka-project/shaka-player/issues/8087

Implements handling of multiple samples in a MP4/ISOBMFF/DASH TTML
segment/fragment. Such segments are allowed by ISO14496-12 and
ISO23000-19. gpac creates such segments. The prior code just treated the
full MDAT as one TTML XML document and tried to parse it in whole
without accounting for sample(s). A testcase is included which was
created by taking the testdata from ttml-segment.mp4 and splitting the
subtitles into two independent TTML-XML documents, which then were put
as individual samples.

The testdata for the prior existing multiple MDAT testcase was invalid.
It was created by taking the same ttml-segment.mp4 as a source and just
duplicating the MDAT box, but without then also fixing the TRUN box. The
duplicated data was thus not referenced. The test case still worked,
because the prior code did not look at the TRUN box and the sample
specification at all and just handled any full MDAT box = 1 sample. The
testdata was replaced with a new file, which is basically the same as
for the multiple samples case, but with the two samples split into two
MDAT boxes.
2025-02-17 12:39:10 +01:00
Wojciech Tyczyński 24283e6c4d fix(Subtitles): Prevent rounding errors when filtering duplicated cues (#8018)
Related to #6773
2025-02-05 14:01:28 +01:00
Álvaro Velad Galván 3be3b142ea fix: Fix displaying subtitles in UITextDisplayer at high playback rates (#7991) 2025-01-30 13:37:04 +01:00
Álvaro Velad Galván 5c100f9847 chore: Stop using "Object" in TTML annotations (#7950)
Related to #1672
2025-01-27 10:35:19 +01:00
Álvaro Velad Galván c54b2dee19 chore: Stop using "Object" in plugins annotations (#7933)
Related to https://github.com/shaka-project/shaka-player/issues/1672
2025-01-24 08:29:51 +01:00
Álvaro Velad Galván 9e71a011f2 fix: Only create TextTrack of SimpleTextDisplayer when necessary (#7913)
Fixes https://github.com/shaka-project/shaka-player/issues/7912
2025-01-21 11:09:26 +01:00