BlueGit

timfa filemanager

Merge fix/subtitle-tail-markers

timfa Tim Falken · pushed by timfa

Authored 2026-05-27 · 5 months ago

Hash
9fdb612424b367d49498a9acd479149562457952
3 files changed +79 −7
.github/technical-reference.md +1 −1
@@ -210,7 +210,7 @@
210 210 ## public/shared-video-player.js
211 211 - applyDefaultTextTrackPrefs() - Writes the default Video.js caption override settings (transparent background, uniform edge style) so all streamed players start from the same text-track baseline.
212 212 - bindTrackPrefs(player, prefs, savePrefs) - Restores subtitle/audio track selections by track name and persists later track changes; shared by the authenticated player and the share page so both resolve track matches the same way.
213 - bindImageSubtitleOverlay(player, videojs, prefs, session, opts) - Adds the shared IM button/menu/overlay for bitmap subtitle tracks, restores saved image-subtitle selections, fetches rendered frames through a caller-supplied request builder, can optionally use a separate range-prefetch request builder (`buildPrefetchRequest`) so the walker caches multiple subtitle images from one window request, keeps a separate rolling lookahead-prefetch worker alive across timeupdates (including gaps where no subtitle is currently visible), supports cache-only foreground playback with `currentFetchEnabled: false` (foreground uses cached frames while walker owns server fetches), supports startup warmup with `initialPrefetchSeconds` (default 60s) so early timeline subtitle frames are requested immediately on player load before playback advances, supports fixed prefetch stride (`prefetchStepSeconds`) and adaptive stride mode (`prefetchAdaptiveStepEnabled` with `prefetchStepSecondsMin`/`prefetchStepSecondsMax`) plus optional adaptive pacing (`prefetchAdaptivePacingEnabled`) to balance cache fill speed against backend request pressure, extends prefetch target to at least the latest buffered video end (not only fixed lookahead seconds), clamps tail requests to the known video duration when that boundary is available, merges buffered-end signals from both Video.js/player APIs and underlying media buffered ranges so under-reported player values do not cap subtitle prefetch early, keeps the prefetch frontier pinned to at least current playback time so it chases buffered-ahead range instead of replaying stale lag after video/session changes, coalesces overlapping current-frame refreshes into a single in-flight fetch (only force-refresh paths abort/restart), applies per-request timeouts (`currentRequestTimeoutMs`, `prefetchRequestTimeoutMs`) so hung subtitle frame requests cannot stall updates indefinitely, paces prefetch polling (`prefetchRequestIntervalMs`) to reduce request bursts, logs current and prefetch subtitle request/send/receive/not-available timing to the browser console and optional batch sink, caches received subtitle PNG frames client-side for the lifetime of the player session (including prefetched frames) so rewind playback can render from local cache even after server-side purge, ensures force-seek aborts still clear in-flight current-request state so subtitle refreshes continue instead of deadlocking, updates seek-bar bracket markers only after responses resolve (no in-flight jump-back flicker), keeps both marker positions forward-only (never regressing to earlier times), allows the two bracket glyphs to overlap naturally when positions match, advances markers even when responses are 204/no-frame, and disables the track after the first hard failure.
213 - bindImageSubtitleOverlay(player, videojs, prefs, session, opts) - Adds the shared IM button/menu/overlay for bitmap subtitle tracks, restores saved image-subtitle selections, fetches rendered frames through a caller-supplied request builder, can optionally use a separate range-prefetch request builder (`buildPrefetchRequest`) so the walker caches multiple subtitle images from one window request, keeps a separate rolling lookahead-prefetch worker alive across timeupdates (including gaps where no subtitle is currently visible), supports cache-only foreground playback with `currentFetchEnabled: false` (foreground uses cached frames while walker owns server fetches), supports startup warmup with `initialPrefetchSeconds` (default 60s) so early timeline subtitle frames are requested immediately on player load before playback advances, supports fixed prefetch stride (`prefetchStepSeconds`) and adaptive stride mode (`prefetchAdaptiveStepEnabled` with `prefetchStepSecondsMin`/`prefetchStepSecondsMax`) plus optional adaptive pacing (`prefetchAdaptivePacingEnabled`) to balance cache fill speed against backend request pressure, extends prefetch target to at least the latest buffered video end (not only fixed lookahead seconds), clamps tail requests to the known video duration when that boundary is available, drives range-prefetch seek markers from the covered-through window end instead of the window start so empty tail windows still reach the video end, merges buffered-end signals from both Video.js/player APIs and underlying media buffered ranges so under-reported player values do not cap subtitle prefetch early, keeps the prefetch frontier pinned to at least current playback time so it chases buffered-ahead range instead of replaying stale lag after video/session changes, coalesces overlapping current-frame refreshes into a single in-flight fetch (only force-refresh paths abort/restart), applies per-request timeouts (`currentRequestTimeoutMs`, `prefetchRequestTimeoutMs`) so hung subtitle frame requests cannot stall updates indefinitely, paces prefetch polling (`prefetchRequestIntervalMs`) to reduce request bursts, logs current and prefetch subtitle request/send/receive/not-available timing to the browser console and optional batch sink, caches received subtitle PNG frames client-side for the lifetime of the player session (including prefetched frames) so rewind playback can render from local cache even after server-side purge, ensures force-seek aborts still clear in-flight current-request state so subtitle refreshes continue instead of deadlocking, updates seek-bar bracket markers only after responses resolve (no in-flight jump-back flicker), keeps both marker positions forward-only (never regressing to earlier times), allows the two bracket glyphs to overlap naturally when positions match, advances markers even when responses are 204/no-frame, and disables the track after the first hard failure.
214 214 - bindImageSubtitleOverlay(player, videojs, prefs, session, opts) - Cache-frame time matching now uses a small epsilon window around start/end timestamps to avoid boundary misses; cache-only mode can also perform a throttled direct current-frame fallback fetch on cache miss (`cacheMissFallbackEnabled`, `cacheMissFallbackIntervalMs`) so subtitles recover without waiting for another seek/timeupdate cycle, fallback fetches preserve prefetch progress so repeated cache misses do not keep resetting subtitle lookahead, and duration metadata hints now extend lookahead prefetch to the known video end even before playback advances.
215 215 - bindStreamAheadPrefetch(opts) - Starts a background HLS walker that repeatedly fetches the session playlist, discovers variant playlists and media segments, and prefetches those assets into the browser cache so playback can read already-fetched segments while the backend prunes old files; tracks cached-through timeline progress (primary from playlist segment durations, with filename-based segment-index fallback for `.ts/.m4s` naming and a section-ratio fallback from fetched segments/total discovered segments when absolute timing metadata is missing) and returns a controller with stop()/done()/getStatus()/subscribe().
216 216 - bindStreamAheadSeekMarker(player, streamAheadPrefetch, opts) - Renders a non-interactive `:` marker on the playback seek bar showing how far the stream-ahead walker has cached through the timeline; subscribes to walker progress updates, updates tooltip text with formatted cached-through time, and removes itself on detach.
@@ -210,7 +210,7 @@
210## public/shared-video-player.js
210## public/shared-video-player.js
211- applyDefaultTextTrackPrefs() - Writes the default Video.js caption override settings (transparent background, uniform edge style) so all streamed players start from the same text-track baseline.
211- applyDefaultTextTrackPrefs() - Writes the default Video.js caption override settings (transparent background, uniform edge style) so all streamed players start from the same text-track baseline.
212- bindTrackPrefs(player, prefs, savePrefs) - Restores subtitle/audio track selections by track name and persists later track changes; shared by the authenticated player and the share page so both resolve track matches the same way.
212- bindTrackPrefs(player, prefs, savePrefs) - Restores subtitle/audio track selections by track name and persists later track changes; shared by the authenticated player and the share page so both resolve track matches the same way.
213- bindImageSubtitleOverlay(player, videojs, prefs, session, opts) - Adds the shared IM button/menu/overlay for bitmap subtitle tracks, restores saved image-subtitle selections, fetches rendered frames through a caller-supplied request builder, can optionally use a separate range-prefetch request builder (`buildPrefetchRequest`) so the walker caches multiple subtitle images from one window request, keeps a separate rolling lookahead-prefetch worker alive across timeupdates (including gaps where no subtitle is currently visible), supports cache-only foreground playback with `currentFetchEnabled: false` (foreground uses cached frames while walker owns server fetches), supports startup warmup with `initialPrefetchSeconds` (default 60s) so early timeline subtitle frames are requested immediately on player load before playback advances, supports fixed prefetch stride (`prefetchStepSeconds`) and adaptive stride mode (`prefetchAdaptiveStepEnabled` with `prefetchStepSecondsMin`/`prefetchStepSecondsMax`) plus optional adaptive pacing (`prefetchAdaptivePacingEnabled`) to balance cache fill speed against backend request pressure, extends prefetch target to at least the latest buffered video end (not only fixed lookahead seconds), clamps tail requests to the known video duration when that boundary is available, merges buffered-end signals from both Video.js/player APIs and underlying media buffered ranges so under-reported player values do not cap subtitle prefetch early, keeps the prefetch frontier pinned to at least current playback time so it chases buffered-ahead range instead of replaying stale lag after video/session changes, coalesces overlapping current-frame refreshes into a single in-flight fetch (only force-refresh paths abort/restart), applies per-request timeouts (`currentRequestTimeoutMs`, `prefetchRequestTimeoutMs`) so hung subtitle frame requests cannot stall updates indefinitely, paces prefetch polling (`prefetchRequestIntervalMs`) to reduce request bursts, logs current and prefetch subtitle request/send/receive/not-available timing to the browser console and optional batch sink, caches received subtitle PNG frames client-side for the lifetime of the player session (including prefetched frames) so rewind playback can render from local cache even after server-side purge, ensures force-seek aborts still clear in-flight current-request state so subtitle refreshes continue instead of deadlocking, updates seek-bar bracket markers only after responses resolve (no in-flight jump-back flicker), keeps both marker positions forward-only (never regressing to earlier times), allows the two bracket glyphs to overlap naturally when positions match, advances markers even when responses are 204/no-frame, and disables the track after the first hard failure.
213- bindImageSubtitleOverlay(player, videojs, prefs, session, opts) - Adds the shared IM button/menu/overlay for bitmap subtitle tracks, restores saved image-subtitle selections, fetches rendered frames through a caller-supplied request builder, can optionally use a separate range-prefetch request builder (`buildPrefetchRequest`) so the walker caches multiple subtitle images from one window request, keeps a separate rolling lookahead-prefetch worker alive across timeupdates (including gaps where no subtitle is currently visible), supports cache-only foreground playback with `currentFetchEnabled: false` (foreground uses cached frames while walker owns server fetches), supports startup warmup with `initialPrefetchSeconds` (default 60s) so early timeline subtitle frames are requested immediately on player load before playback advances, supports fixed prefetch stride (`prefetchStepSeconds`) and adaptive stride mode (`prefetchAdaptiveStepEnabled` with `prefetchStepSecondsMin`/`prefetchStepSecondsMax`) plus optional adaptive pacing (`prefetchAdaptivePacingEnabled`) to balance cache fill speed against backend request pressure, extends prefetch target to at least the latest buffered video end (not only fixed lookahead seconds), clamps tail requests to the known video duration when that boundary is available, drives range-prefetch seek markers from the covered-through window end instead of the window start so empty tail windows still reach the video end, merges buffered-end signals from both Video.js/player APIs and underlying media buffered ranges so under-reported player values do not cap subtitle prefetch early, keeps the prefetch frontier pinned to at least current playback time so it chases buffered-ahead range instead of replaying stale lag after video/session changes, coalesces overlapping current-frame refreshes into a single in-flight fetch (only force-refresh paths abort/restart), applies per-request timeouts (`currentRequestTimeoutMs`, `prefetchRequestTimeoutMs`) so hung subtitle frame requests cannot stall updates indefinitely, paces prefetch polling (`prefetchRequestIntervalMs`) to reduce request bursts, logs current and prefetch subtitle request/send/receive/not-available timing to the browser console and optional batch sink, caches received subtitle PNG frames client-side for the lifetime of the player session (including prefetched frames) so rewind playback can render from local cache even after server-side purge, ensures force-seek aborts still clear in-flight current-request state so subtitle refreshes continue instead of deadlocking, updates seek-bar bracket markers only after responses resolve (no in-flight jump-back flicker), keeps both marker positions forward-only (never regressing to earlier times), allows the two bracket glyphs to overlap naturally when positions match, advances markers even when responses are 204/no-frame, and disables the track after the first hard failure.
214- bindImageSubtitleOverlay(player, videojs, prefs, session, opts) - Cache-frame time matching now uses a small epsilon window around start/end timestamps to avoid boundary misses; cache-only mode can also perform a throttled direct current-frame fallback fetch on cache miss (`cacheMissFallbackEnabled`, `cacheMissFallbackIntervalMs`) so subtitles recover without waiting for another seek/timeupdate cycle, fallback fetches preserve prefetch progress so repeated cache misses do not keep resetting subtitle lookahead, and duration metadata hints now extend lookahead prefetch to the known video end even before playback advances.
214- bindImageSubtitleOverlay(player, videojs, prefs, session, opts) - Cache-frame time matching now uses a small epsilon window around start/end timestamps to avoid boundary misses; cache-only mode can also perform a throttled direct current-frame fallback fetch on cache miss (`cacheMissFallbackEnabled`, `cacheMissFallbackIntervalMs`) so subtitles recover without waiting for another seek/timeupdate cycle, fallback fetches preserve prefetch progress so repeated cache misses do not keep resetting subtitle lookahead, and duration metadata hints now extend lookahead prefetch to the known video end even before playback advances.
215- bindStreamAheadPrefetch(opts) - Starts a background HLS walker that repeatedly fetches the session playlist, discovers variant playlists and media segments, and prefetches those assets into the browser cache so playback can read already-fetched segments while the backend prunes old files; tracks cached-through timeline progress (primary from playlist segment durations, with filename-based segment-index fallback for `.ts/.m4s` naming and a section-ratio fallback from fetched segments/total discovered segments when absolute timing metadata is missing) and returns a controller with stop()/done()/getStatus()/subscribe().
215- bindStreamAheadPrefetch(opts) - Starts a background HLS walker that repeatedly fetches the session playlist, discovers variant playlists and media segments, and prefetches those assets into the browser cache so playback can read already-fetched segments while the backend prunes old files; tracks cached-through timeline progress (primary from playlist segment durations, with filename-based segment-index fallback for `.ts/.m4s` naming and a section-ratio fallback from fetched segments/total discovered segments when absolute timing metadata is missing) and returns a controller with stop()/done()/getStatus()/subscribe().
216- bindStreamAheadSeekMarker(player, streamAheadPrefetch, opts) - Renders a non-interactive `:` marker on the playback seek bar showing how far the stream-ahead walker has cached through the timeline; subscribes to walker progress updates, updates tooltip text with formatted cached-through time, and removes itself on detach.
216- bindStreamAheadSeekMarker(player, streamAheadPrefetch, opts) - Renders a non-interactive `:` marker on the playback seek bar showing how far the stream-ahead walker has cached through the timeline; subscribes to walker progress updates, updates tooltip text with formatted cached-through time, and removes itself on detach.
public/shared-video-player.js +24 −6
@@ -306,6 +306,7 @@
306 306 const savePrefs = typeof opts.savePrefs === 'function' ? opts.savePrefs : (() => { });
307 307 const buildFrameRequest = typeof opts.buildFrameRequest === 'function' ? opts.buildFrameRequest : null;
308 308 const buildPrefetchRequest = typeof opts.buildPrefetchRequest === 'function' ? opts.buildPrefetchRequest : buildFrameRequest;
309 const prefetchUsesRangeRequests = !!(buildFrameRequest && buildPrefetchRequest && buildPrefetchRequest !== buildFrameRequest);
309 310 const notifyError = typeof opts.onError === 'function' ? opts.onError : (() => { });
310 311 const sendSubtitleLogBatch = typeof opts.sendSubtitleLogBatch === 'function' ? opts.sendSubtitleLogBatch : null;
311 312 const requestedLookaheadSeconds = Number(opts.lookaheadSeconds);
@@ -1032,11 +1033,15 @@
1032 1033 ? startTime
1033 1034 : prefetchedThroughTimeSeconds + stepSeconds;
1034 1035 if (!Number.isFinite(nextTime) || nextTime > prefetchTargetTimeSeconds + 1e-6) return;
1036 const requestedRangeEndTimeSeconds = Math.min(prefetchTargetTimeSeconds, nextTime + stepSeconds);
1037 const prefetchProgressTimeSeconds = prefetchUsesRangeRequests
1038 ? requestedRangeEndTimeSeconds
1039 : nextTime;
1035 1040
1036 1041 const request = buildPrefetchRequest({
1037 1042 streamIndex: selectedStreamIndex,
1038 1043 currentTime: nextTime,
1039 endTime: Math.min(prefetchTargetTimeSeconds, nextTime + stepSeconds),
1044 endTime: requestedRangeEndTimeSeconds,
1040 1045 session,
1041 1046 });
1042 1047 if (!request || !request.url) return;
@@ -1049,7 +1054,7 @@
1049 1054 requestUrl: String(request.url || ''),
1050 1055 requestedAtMs: prefetchRequestStartedAtMs,
1051 1056 requestedVideoTimeSeconds: roundLogNumber(nextTime),
1052 requestedRangeEndTimeSeconds: roundLogNumber(Math.min(prefetchTargetTimeSeconds, nextTime + stepSeconds)),
1057 requestedRangeEndTimeSeconds: roundLogNumber(requestedRangeEndTimeSeconds),
1053 1058 });
1054 1059
1055 1060 let prefetchTimedOut = false;
@@ -1080,6 +1085,7 @@
1080 1085 subtitleEndTimeSeconds: parseHeaderFloat(res, 'X-Subtitle-Frame-End-Time'),
1081 1086 responseHeadersReceivedAtMs: Date.now(),
1082 1087 requestedVideoTimeSeconds: roundLogNumber(nextTime),
1088 requestedRangeEndTimeSeconds: roundLogNumber(requestedRangeEndTimeSeconds),
1083 1089 };
1084 1090 logSubtitleEvent('subtitle_png_sent', {
1085 1091 ...responseMeta,
@@ -1087,10 +1093,10 @@
1087 1093 sentToHeadersReceivedMs: diffMilliseconds(responseMeta.responseHeadersReceivedAtMs, responseMeta.serverResponseSentAtMs),
1088 1094 });
1089 1095
1090 setSeekMarkerTime('requested', nextTime);
1096 setSeekMarkerTime('requested', prefetchProgressTimeSeconds);
1091 1097 const receivedMarkerTime = Number.isFinite(responseMeta.shouldShowAtVideoTimeSeconds)
1092 1098 ? responseMeta.shouldShowAtVideoTimeSeconds
1093 : nextTime;
1099 : prefetchProgressTimeSeconds;
1094 1100 setSeekMarkerTime('received', receivedMarkerTime);
1095 1101 updateSeekBarMarkers();
1096 1102
@@ -1102,7 +1108,13 @@
1102 1108 frameStatus,
1103 1109 });
1104 1110 if (frameStatus === 'error') return;
1105 prefetchedThroughTimeSeconds = nextTime;
1111 prefetchedThroughTimeSeconds = prefetchProgressTimeSeconds;
1112 if (prefetchUsesRangeRequests)
1113 {
1114 setSeekMarkerTime('requested', prefetchedThroughTimeSeconds);
1115 setSeekMarkerTime('received', prefetchedThroughTimeSeconds);
1116 updateSeekBarMarkers();
1117 }
1106 1118 const waitMs = getPrefetchDelayMs(Number(player.currentTime()));
1107 1119 if (waitMs > 0)
1108 1120 {
@@ -1185,7 +1197,13 @@
1185 1197 requestedToReceivedMs: diffMilliseconds(receivedAtMs, prefetchRequestStartedAtMs),
1186 1198 blobBytes: receivedBlobBytes,
1187 1199 });
1188 prefetchedThroughTimeSeconds = Math.min(prefetchTargetTimeSeconds, nextTime + stepSeconds);
1200 prefetchedThroughTimeSeconds = prefetchProgressTimeSeconds;
1201 if (prefetchUsesRangeRequests)
1202 {
1203 setSeekMarkerTime('requested', prefetchedThroughTimeSeconds);
1204 setSeekMarkerTime('received', prefetchedThroughTimeSeconds);
1205 updateSeekBarMarkers();
1206 }
1189 1207 const waitMs = getPrefetchDelayMs(Number(player.currentTime()));
1190 1208 if (waitMs > 0)
1191 1209 {
@@ -306,6 +306,7 @@
306 const savePrefs = typeof opts.savePrefs === 'function' ? opts.savePrefs : (() => { });
306 const savePrefs = typeof opts.savePrefs === 'function' ? opts.savePrefs : (() => { });
307 const buildFrameRequest = typeof opts.buildFrameRequest === 'function' ? opts.buildFrameRequest : null;
307 const buildFrameRequest = typeof opts.buildFrameRequest === 'function' ? opts.buildFrameRequest : null;
308 const buildPrefetchRequest = typeof opts.buildPrefetchRequest === 'function' ? opts.buildPrefetchRequest : buildFrameRequest;
308 const buildPrefetchRequest = typeof opts.buildPrefetchRequest === 'function' ? opts.buildPrefetchRequest : buildFrameRequest;
309 const prefetchUsesRangeRequests = !!(buildFrameRequest && buildPrefetchRequest && buildPrefetchRequest !== buildFrameRequest);
309 const notifyError = typeof opts.onError === 'function' ? opts.onError : (() => { });
310 const notifyError = typeof opts.onError === 'function' ? opts.onError : (() => { });
310 const sendSubtitleLogBatch = typeof opts.sendSubtitleLogBatch === 'function' ? opts.sendSubtitleLogBatch : null;
311 const sendSubtitleLogBatch = typeof opts.sendSubtitleLogBatch === 'function' ? opts.sendSubtitleLogBatch : null;
311 const requestedLookaheadSeconds = Number(opts.lookaheadSeconds);
312 const requestedLookaheadSeconds = Number(opts.lookaheadSeconds);
@@ -1032,11 +1033,15 @@
1032 ? startTime
1033 ? startTime
1033 : prefetchedThroughTimeSeconds + stepSeconds;
1034 : prefetchedThroughTimeSeconds + stepSeconds;
1034 if (!Number.isFinite(nextTime) || nextTime > prefetchTargetTimeSeconds + 1e-6) return;
1035 if (!Number.isFinite(nextTime) || nextTime > prefetchTargetTimeSeconds + 1e-6) return;
1036 const requestedRangeEndTimeSeconds = Math.min(prefetchTargetTimeSeconds, nextTime + stepSeconds);
1037 const prefetchProgressTimeSeconds = prefetchUsesRangeRequests
1038 ? requestedRangeEndTimeSeconds
1039 : nextTime;
1035
1040
1036 const request = buildPrefetchRequest({
1041 const request = buildPrefetchRequest({
1037 streamIndex: selectedStreamIndex,
1042 streamIndex: selectedStreamIndex,
1038 currentTime: nextTime,
1043 currentTime: nextTime,
1039 endTime: Math.min(prefetchTargetTimeSeconds, nextTime + stepSeconds),
1044 endTime: requestedRangeEndTimeSeconds,
1040 session,
1045 session,
1041 });
1046 });
1042 if (!request || !request.url) return;
1047 if (!request || !request.url) return;
@@ -1049,7 +1054,7 @@
1049 requestUrl: String(request.url || ''),
1054 requestUrl: String(request.url || ''),
1050 requestedAtMs: prefetchRequestStartedAtMs,
1055 requestedAtMs: prefetchRequestStartedAtMs,
1051 requestedVideoTimeSeconds: roundLogNumber(nextTime),
1056 requestedVideoTimeSeconds: roundLogNumber(nextTime),
1052 requestedRangeEndTimeSeconds: roundLogNumber(Math.min(prefetchTargetTimeSeconds, nextTime + stepSeconds)),
1057 requestedRangeEndTimeSeconds: roundLogNumber(requestedRangeEndTimeSeconds),
1053 });
1058 });
1054
1059
1055 let prefetchTimedOut = false;
1060 let prefetchTimedOut = false;
@@ -1080,6 +1085,7 @@
1080 subtitleEndTimeSeconds: parseHeaderFloat(res, 'X-Subtitle-Frame-End-Time'),
1085 subtitleEndTimeSeconds: parseHeaderFloat(res, 'X-Subtitle-Frame-End-Time'),
1081 responseHeadersReceivedAtMs: Date.now(),
1086 responseHeadersReceivedAtMs: Date.now(),
1082 requestedVideoTimeSeconds: roundLogNumber(nextTime),
1087 requestedVideoTimeSeconds: roundLogNumber(nextTime),
1088 requestedRangeEndTimeSeconds: roundLogNumber(requestedRangeEndTimeSeconds),
1083 };
1089 };
1084 logSubtitleEvent('subtitle_png_sent', {
1090 logSubtitleEvent('subtitle_png_sent', {
1085 ...responseMeta,
1091 ...responseMeta,
@@ -1087,10 +1093,10 @@
1087 sentToHeadersReceivedMs: diffMilliseconds(responseMeta.responseHeadersReceivedAtMs, responseMeta.serverResponseSentAtMs),
1093 sentToHeadersReceivedMs: diffMilliseconds(responseMeta.responseHeadersReceivedAtMs, responseMeta.serverResponseSentAtMs),
1088 });
1094 });
1089
1095
1090 setSeekMarkerTime('requested', nextTime);
1096 setSeekMarkerTime('requested', prefetchProgressTimeSeconds);
1091 const receivedMarkerTime = Number.isFinite(responseMeta.shouldShowAtVideoTimeSeconds)
1097 const receivedMarkerTime = Number.isFinite(responseMeta.shouldShowAtVideoTimeSeconds)
1092 ? responseMeta.shouldShowAtVideoTimeSeconds
1098 ? responseMeta.shouldShowAtVideoTimeSeconds
1093 : nextTime;
1099 : prefetchProgressTimeSeconds;
1094 setSeekMarkerTime('received', receivedMarkerTime);
1100 setSeekMarkerTime('received', receivedMarkerTime);
1095 updateSeekBarMarkers();
1101 updateSeekBarMarkers();
1096
1102
@@ -1102,7 +1108,13 @@
1102 frameStatus,
1108 frameStatus,
1103 });
1109 });
1104 if (frameStatus === 'error') return;
1110 if (frameStatus === 'error') return;
1105 prefetchedThroughTimeSeconds = nextTime;
1111 prefetchedThroughTimeSeconds = prefetchProgressTimeSeconds;
1112 if (prefetchUsesRangeRequests)
1113 {
1114 setSeekMarkerTime('requested', prefetchedThroughTimeSeconds);
1115 setSeekMarkerTime('received', prefetchedThroughTimeSeconds);
1116 updateSeekBarMarkers();
1117 }
1106 const waitMs = getPrefetchDelayMs(Number(player.currentTime()));
1118 const waitMs = getPrefetchDelayMs(Number(player.currentTime()));
1107 if (waitMs > 0)
1119 if (waitMs > 0)
1108 {
1120 {
@@ -1185,7 +1197,13 @@
1185 requestedToReceivedMs: diffMilliseconds(receivedAtMs, prefetchRequestStartedAtMs),
1197 requestedToReceivedMs: diffMilliseconds(receivedAtMs, prefetchRequestStartedAtMs),
1186 blobBytes: receivedBlobBytes,
1198 blobBytes: receivedBlobBytes,
1187 });
1199 });
1188 prefetchedThroughTimeSeconds = Math.min(prefetchTargetTimeSeconds, nextTime + stepSeconds);
1200 prefetchedThroughTimeSeconds = prefetchProgressTimeSeconds;
1201 if (prefetchUsesRangeRequests)
1202 {
1203 setSeekMarkerTime('requested', prefetchedThroughTimeSeconds);
1204 setSeekMarkerTime('received', prefetchedThroughTimeSeconds);
1205 updateSeekBarMarkers();
1206 }
1189 const waitMs = getPrefetchDelayMs(Number(player.currentTime()));
1207 const waitMs = getPrefetchDelayMs(Number(player.currentTime()));
1190 if (waitMs > 0)
1208 if (waitMs > 0)
1191 {
1209 {
tests/shared-video-player.test.js +54 −0
@@ -1208,6 +1208,60 @@ describe('shared image subtitle prefetching', () =>
1208 1208 window.close();
1209 1209 });
1210 1210
1211 test('advances seek markers to the end of an empty prefetch tail window', async () =>
1212 {
1213 const window = createWindow();
1214 const helper = loadSharedVideoPlayer(window);
1215 const { player, videojs } = buildPlayerHarness(window);
1216
1217 player.duration(120);
1218 player.setCurrentTime(110);
1219
1220 window.fetch = jest.fn(async () =>
1221 {
1222 return new Response(null, {
1223 status: 204,
1224 headers: {
1225 'X-Subtitle-Frame-Status': 'none',
1226 'X-Subtitle-Request-Received-At-Ms': '1000',
1227 'X-Subtitle-Response-Sent-At-Ms': '1010',
1228 },
1229 });
1230 });
1231
1232 const controller = helper.bindImageSubtitleOverlay(player, videojs, {}, {
1233 imageSubtitleTracks: [{ label: 'PGS English', streamIndex: 0, default: true }],
1234 }, {
1235 lookaheadSeconds: 0,
1236 initialPrefetchSeconds: 0,
1237 currentFetchEnabled: false,
1238 cacheMissFallbackEnabled: false,
1239 prefetchAdaptiveStepEnabled: true,
1240 prefetchStepSecondsMin: 10,
1241 prefetchStepSecondsMax: 10,
1242 buildFrameRequest: ({ currentTime, streamIndex }) => ({
1243 url: `/subtitle-frame?streamIndex=${streamIndex}&timeSeconds=${currentTime}`,
1244 }),
1245 buildPrefetchRequest: ({ currentTime, endTime, streamIndex }) => ({
1246 url: `/subtitle-range?streamIndex=${streamIndex}&startTimeSeconds=${currentTime}&endTimeSeconds=${endTime}`,
1247 }),
1248 });
1249
1250 player.trigger('timeupdate');
1251 await flushAsyncWork(window, 8);
1252
1253 const requestedMarker = player.el().querySelector('.vjs-image-subtitle-seek-marker-right');
1254 const receivedMarker = player.el().querySelector('.vjs-image-subtitle-seek-marker-left');
1255 expect(requestedMarker).toBeTruthy();
1256 expect(receivedMarker).toBeTruthy();
1257 expect(requestedMarker.style.left).toBe('100.0000%');
1258 expect(receivedMarker.style.left).toBe('100.0000%');
1259
1260 controller.detach();
1261 await flushAsyncWork(window, 2);
1262 window.close();
1263 });
1264
1211 1265 test('keeps existing marker positions while the next request is still in flight', async () =>
1212 1266 {
1213 1267 const window = createWindow();
@@ -1208,6 +1208,60 @@ describe('shared image subtitle prefetching', () =>
1208 window.close();
1208 window.close();
1209 });
1209 });
1210
1210
1211 test('advances seek markers to the end of an empty prefetch tail window', async () =>
1212 {
1213 const window = createWindow();
1214 const helper = loadSharedVideoPlayer(window);
1215 const { player, videojs } = buildPlayerHarness(window);
1216
1217 player.duration(120);
1218 player.setCurrentTime(110);
1219
1220 window.fetch = jest.fn(async () =>
1221 {
1222 return new Response(null, {
1223 status: 204,
1224 headers: {
1225 'X-Subtitle-Frame-Status': 'none',
1226 'X-Subtitle-Request-Received-At-Ms': '1000',
1227 'X-Subtitle-Response-Sent-At-Ms': '1010',
1228 },
1229 });
1230 });
1231
1232 const controller = helper.bindImageSubtitleOverlay(player, videojs, {}, {
1233 imageSubtitleTracks: [{ label: 'PGS English', streamIndex: 0, default: true }],
1234 }, {
1235 lookaheadSeconds: 0,
1236 initialPrefetchSeconds: 0,
1237 currentFetchEnabled: false,
1238 cacheMissFallbackEnabled: false,
1239 prefetchAdaptiveStepEnabled: true,
1240 prefetchStepSecondsMin: 10,
1241 prefetchStepSecondsMax: 10,
1242 buildFrameRequest: ({ currentTime, streamIndex }) => ({
1243 url: `/subtitle-frame?streamIndex=${streamIndex}&timeSeconds=${currentTime}`,
1244 }),
1245 buildPrefetchRequest: ({ currentTime, endTime, streamIndex }) => ({
1246 url: `/subtitle-range?streamIndex=${streamIndex}&startTimeSeconds=${currentTime}&endTimeSeconds=${endTime}`,
1247 }),
1248 });
1249
1250 player.trigger('timeupdate');
1251 await flushAsyncWork(window, 8);
1252
1253 const requestedMarker = player.el().querySelector('.vjs-image-subtitle-seek-marker-right');
1254 const receivedMarker = player.el().querySelector('.vjs-image-subtitle-seek-marker-left');
1255 expect(requestedMarker).toBeTruthy();
1256 expect(receivedMarker).toBeTruthy();
1257 expect(requestedMarker.style.left).toBe('100.0000%');
1258 expect(receivedMarker.style.left).toBe('100.0000%');
1259
1260 controller.detach();
1261 await flushAsyncWork(window, 2);
1262 window.close();
1263 });
1264
1211 test('keeps existing marker positions while the next request is still in flight', async () =>
1265 test('keeps existing marker positions while the next request is still in flight', async () =>
1212 {
1266 {
1213 const window = createWindow();
1267 const window = createWindow();