Fix excessive memory usage on chrome+webkit

This commit is contained in:
mrjvs 2023-10-18 15:30:04 +02:00
parent 0ca585f70a
commit 037960f587
3 changed files with 7 additions and 12 deletions

View File

@ -81,6 +81,7 @@ export function CaptionsView({ id }: { id: string }) {
<CaptionOption onClick={() => disableCaption()}>Off</CaptionOption>
{langs.map((v) => (
<CaptionOption
key={v.lang}
countryCode={v.lang}
selected={lang === v.lang}
onClick={() => updateCaption()}

View File

@ -1,10 +1,7 @@
import { ReactNode, useEffect, useMemo, useRef } from "react";
import { makeVideoElementDisplayInterface } from "@/components/player/display/base";
import {
convertSubtitlesToVtt,
vttToDataurl,
} from "@/components/player/utils/captions";
import { convertSubtitlesToDataurl } from "@/components/player/utils/captions";
import { playerStatus } from "@/stores/player/slices/source";
import { usePlayerStore } from "@/stores/player/store";
@ -47,10 +44,9 @@ function VideoElement() {
const captionAsTrack = usePlayerStore((s) => s.caption.asTrack);
const language = usePlayerStore((s) => s.caption.selected?.language);
const trackData = useMemo(
() => (srtData ? vttToDataurl(convertSubtitlesToVtt(srtData)) : null),
[srtData]
);
const trackData = useMemo(() => {
return srtData ? convertSubtitlesToDataurl(srtData) : null;
}, [srtData]);
// report video element to display interface
useEffect(() => {

View File

@ -40,8 +40,6 @@ export function parseSubtitles(text: string): CaptionCueType[] {
return parse(vtt).filter((cue) => cue.type === "caption") as CaptionCueType[];
}
export function vttToDataurl(vtt: string): string {
const bytes = new TextEncoder().encode(vtt);
const encoded = btoa(String.fromCodePoint(...bytes));
return `data:text/vtt;base64,${encoded}`;
export function convertSubtitlesToDataurl(text: string): string {
return `data:text/vtt;${convertSubtitlesToVtt(text)}`;
}