Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix race that allows multiple text streams to be loaded #5129

Merged
merged 45 commits into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
90b4527
Merge remote-tracking branch 'upstream/master'
dsparacio Oct 29, 2020
49d611f
Merge branch 'master' of https://github.com/google/shaka-player
dsparacio Jan 25, 2021
93fdcd3
Merge remote-tracking branch 'upstream/master'
littlespex May 4, 2021
0b7ac5b
Merge branch 'google:master' into master
littlespex Sep 8, 2021
6db0e3c
Merge branch 'google:master' into master
littlespex Sep 15, 2021
efaebee
Merge branch 'google:master' into master
littlespex Sep 20, 2021
7fed0d0
Merge branch 'google:master' into master
littlespex Sep 22, 2021
7a30028
Merge branch 'google:master' into master
littlespex Sep 30, 2021
0168a7f
Merge branch 'google:master' into master
littlespex Oct 18, 2021
6b64092
Merge branch 'google:master' into master
littlespex Nov 2, 2021
a0cdf79
Merge branch 'google:master' into master
littlespex Dec 16, 2021
28564dd
Merge branch 'google:master' into master
littlespex Jan 7, 2022
5fb344e
Merge branch 'google:master' into master
littlespex Jan 10, 2022
1766930
Merge branch 'google:master' into master
littlespex Jan 12, 2022
b0cad7c
Merge branch 'google:master' into master
littlespex Jan 18, 2022
868b75b
Merge branch 'google:master' into master
littlespex Feb 4, 2022
95589c9
Merge branch 'shaka-project:main' into master
littlespex Mar 15, 2022
f331382
Merge branch 'shaka-project:main' into master
littlespex Jun 13, 2022
d14c111
Merge branch 'shaka-project:main' into master
littlespex Jun 29, 2022
b700d3b
Merge branch 'shaka-project:main' into master
littlespex Sep 21, 2022
0d9ea95
Merge branch 'shaka-project:main' into master
littlespex Oct 21, 2022
ef5177b
Merge branch 'shaka-project:main' into master
littlespex Oct 25, 2022
937638e
Merge branch 'shaka-project:main' into master
littlespex Oct 26, 2022
6f0d4fe
Merge branch 'shaka-project:main' into master
littlespex Oct 27, 2022
5a83556
Merge branch 'shaka-project:main' into master
littlespex Nov 9, 2022
6536603
Merge branch 'shaka-project:main' into master
littlespex Nov 10, 2022
62f7011
Merge branch 'shaka-project:main' into master
littlespex Nov 16, 2022
0e4d4a2
Merge branch 'shaka-project:main' into master
littlespex Nov 17, 2022
bfa45d3
Merge branch 'shaka-project:main' into master
littlespex Dec 9, 2022
f911668
Merge branch 'shaka-project:main' into master
littlespex Jan 21, 2023
5291a2a
Merge branch 'shaka-project:main' into master
littlespex Jan 25, 2023
dc64ede
Merge branch 'shaka-project:main' into master
littlespex Jan 26, 2023
7bee999
fix: exclude "future" segments from presentation timeline calculations
littlespex Jan 26, 2023
172fb81
Revert "fix: exclude "future" segments from presentation timeline cal…
littlespex Jan 26, 2023
127b183
fix: exclude "future" segments from presentation timeline calculations
littlespex Jan 26, 2023
7004b44
Revert "fix: exclude "future" segments from presentation timeline cal…
littlespex Jan 26, 2023
2632ea9
Merge branch 'shaka-project:main' into master
littlespex Feb 17, 2023
407a446
Merge branch 'shaka-project:main' into master
littlespex Mar 7, 2023
4dd2eff
Merge branch 'shaka-project:main' into master
littlespex Mar 23, 2023
720a828
Merge branch 'shaka-project:main' into master
littlespex Mar 29, 2023
d4009a1
Remove async from loadNewTextStream
willdharris Mar 30, 2023
c1cb3d1
Add text stream sequence id
willdharris Apr 4, 2023
ac0e5c3
Add test to verify a single text stream loads
willdharris Apr 10, 2023
3230bfa
Update CONTRIBUTORS
willdharris Apr 10, 2023
f99f9aa
Restore missing return type
willdharris Apr 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ Vincent Valot <[email protected]>
Vinod Balakrishnan <[email protected]>
Wayne Morgan <[email protected]>
Wen Ren <[email protected]>
Will Harris <[email protected]>
Yohann Connell <[email protected]>
Raymond Cheng <[email protected]>
Janroel Koppen <[email protected]>
Expand Down
7 changes: 6 additions & 1 deletion lib/media/streaming_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ shaka.media.StreamingEngine = class {
/** @private {?shaka.extern.Stream} */
this.currentTextStream_ = null;

/** @private {number} */
this.textStreamSequenceId_ = 0;

/** @private {boolean} */
this.parsedPrftEventRaised_ = false;

Expand Down Expand Up @@ -240,6 +243,8 @@ shaka.media.StreamingEngine = class {
const ContentType = shaka.util.ManifestParserUtils.ContentType;
goog.asserts.assert(!this.mediaStates_.has(ContentType.TEXT),
'Should not call loadNewTextStream_ while streaming text!');
this.textStreamSequenceId_++;
const currentSequenceId = this.textStreamSequenceId_;

try {
// Clear MediaSource's buffered text, so that the new text stream will
Expand All @@ -262,7 +267,7 @@ shaka.media.StreamingEngine = class {
const streamText =
textDisplayer.isTextVisible() || this.config_.alwaysStreamText;

if (streamText) {
if (streamText && (this.textStreamSequenceId_ == currentSequenceId)) {
const state = this.createMediaState_(stream);
this.mediaStates_.set(ContentType.TEXT, state);
this.scheduleUpdate_(state, 0);
Expand Down
39 changes: 39 additions & 0 deletions test/player_integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,45 @@ describe('Player', () => {
player.setTextTrackVisibility(true);
expect(getTracksActive()).toEqual([false, true]);
});

// https://github.com/shaka-project/shaka-player/issues/4821
it('loads a single text stream', async () => {
player.configure({preferredTextLanguage: 'en'});
await player.load('test:sintel_no_text_compiled');

// Add preferred language text track.
const locationUri = new goog.Uri(location.href);
const partialUri = new goog.Uri('/base/test/test/assets/text-clip.vtt');
const absoluteUri = locationUri.resolve(partialUri);
await player.addTextTrackAsync(
absoluteUri.toString(), 'en', 'subtitles', 'text/vtt');

// Add alternate language text track.
// Two text tracks with same timings but different text
// are necessary for test.
const partialUri2 =
new goog.Uri('/base/test/test/assets/text-clip-alt.vtt');
const absoluteUri2 = locationUri.resolve(partialUri2);
await player.addTextTrackAsync(
absoluteUri2.toString(), 'fr', 'subtitles', 'text/vtt');

const textTracks = player.getTextTracks();
expect(textTracks.length).toBe(2);
expect(textTracks[0].language).toBe('en');
expect(textTracks[1].language).toBe('fr');

// Enable text visibilty and immediately change language.
// Only one set of cues should be active.
// Cues should be of the selected language track.
player.setTextTrackVisibility(true);
player.selectTextLanguage('fr');
video.currentTime = 5;
video.play();
await waiter.waitForMovementOrFailOnTimeout(video, 10);

expect(video.textTracks[0].activeCues.length).toBe(1);
expect(player.getTextTracks()[1].active).toBe(true);
});
}); // describe('setTextTrackVisibility')

describe('autoShowText', () => {
Expand Down
63 changes: 63 additions & 0 deletions test/test/assets/text-clip-alt.vtt
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
WEBVTT

00:04.000 --> 00:07.300
Journal de bord du capitaine.
Date stellaire 41636.9.

00:07.500 --> 00:11.800
Comme nous le craignions, l'épave
du cargo Odin de la Fédération,

00:12.100 --> 00:16.400
percuté par un astéroïde,
ne révèle aucun signe de vie.

00:16.700 --> 00:19.000
Mais trois nacelles
de sauvetage manquaient,

00:19.300 --> 00:21.900
laissant supposer
qu'il y aurait des survivants.

00:22.700 --> 00:27.700
- Mise sur orbite Angel One, paré.
- Quel genre d'endroit, Data ?

00:28.200 --> 00:31.600
Planète de Classe-M.
Faune et flore à base de carbone.

00:31.900 --> 00:34.300
Population éparse
et forme de vie intelligente.

00:34.600 --> 00:38.400
Développement technique équivalent
au milieu du 20ème siècle terrien.

00:38.800 --> 00:41.000
C'est presque un retour aux sources.

00:41.300 --> 00:43.600
Si jamais des survivants
ont pu aller si loin,

00:43.800 --> 00:49.000
c'était la planète la plus proche.
La distance qui nous a pris 2 jours

00:49.500 --> 00:52.400
aurait pris 5 mois aux nacelles
de sauvetage du Odin.

00:52.600 --> 00:54.700
Cinq mois, six jours, onze heures,
deux min...

00:54.900 --> 00:58.400
- Merci, Data.
- ..et 57 secondes.

00:58.600 --> 01:01.300
Signal audio provenant d'Angel One.