This commit is contained in:
Josh Hawkins 2024-08-17 12:07:47 -05:00
parent fc49a1e601
commit b6b96dafa3
3 changed files with 6 additions and 45 deletions

View File

@ -209,15 +209,6 @@ export default function LivePlayer({
player = <ActivityIndicator />; player = <ActivityIndicator />;
} }
useEffect(() => {
console.log(
cameraConfig.name,
cameraConfig.live.stream_name,
"switching to",
preferredLiveMode,
);
}, [preferredLiveMode]);
return ( return (
<div <div
ref={cameraRef ?? internalContainerRef} ref={cameraRef ?? internalContainerRef}

View File

@ -206,6 +206,7 @@ function MSEPlayer({
const onMse = () => { const onMse = () => {
if ("ManagedMediaSource" in window) { if ("ManagedMediaSource" in window) {
// safari
const MediaSource = window.ManagedMediaSource; const MediaSource = window.ManagedMediaSource;
msRef.current?.addEventListener( msRef.current?.addEventListener(
@ -223,10 +224,8 @@ function MSEPlayer({
onDisconnect(); onDisconnect();
} }
if (isIOS || isSafari) { if (isIOS || isSafari) {
console.log(camera, "Safari MSE sourceopen error");
onError?.("mse-decode"); onError?.("mse-decode");
} else { } else {
console.log(camera, "MSE sourceopen error");
onError?.("startup"); onError?.("startup");
} }
}); });
@ -239,6 +238,7 @@ function MSEPlayer({
videoRef.current.srcObject = msRef.current; videoRef.current.srcObject = msRef.current;
} }
} else { } else {
// non safari
msRef.current?.addEventListener( msRef.current?.addEventListener(
"sourceopen", "sourceopen",
() => { () => {
@ -254,10 +254,8 @@ function MSEPlayer({
onDisconnect(); onDisconnect();
} }
if (isIOS || isSafari) { if (isIOS || isSafari) {
console.log(camera, "Safari MSE sourceopen error");
onError?.("mse-decode"); onError?.("mse-decode");
} else { } else {
console.log(camera, "MSE sourceopen error");
onError?.("startup"); onError?.("startup");
} }
}); });
@ -274,8 +272,6 @@ function MSEPlayer({
onmessageRef.current["mse"] = (msg) => { onmessageRef.current["mse"] = (msg) => {
if (msg.type !== "mse") return; if (msg.type !== "mse") return;
console.log(camera, "codecs", msg.value);
let sb: SourceBuffer | undefined; let sb: SourceBuffer | undefined;
try { try {
sb = msRef.current?.addSourceBuffer(msg.value); sb = msRef.current?.addSourceBuffer(msg.value);
@ -288,7 +284,6 @@ function MSEPlayer({
if (wsRef.current) { if (wsRef.current) {
onDisconnect(); onDisconnect();
} }
console.log(camera, "threw InvalidStateError");
onError?.("mse-decode"); onError?.("mse-decode");
return; return;
} else { } else {
@ -345,15 +340,12 @@ function MSEPlayer({
const jumpToLive = () => { const jumpToLive = () => {
if (!videoRef.current) return; if (!videoRef.current) return;
const now = Date.now();
const buffered = videoRef.current.buffered; const buffered = videoRef.current.buffered;
if (buffered.length > 0) { if (buffered.length > 0) {
const liveEdge = buffered.end(buffered.length - 1); const liveEdge = buffered.end(buffered.length - 1);
// Jump to the live edge // Jump to the live edge
videoRef.current.currentTime = liveEdge; videoRef.current.currentTime = liveEdge - 0.75;
lastJumpTimeRef.current = now; lastJumpTimeRef.current = Date.now();
console.log(camera, "jumped to live");
} }
}; };
@ -361,7 +353,7 @@ function MSEPlayer({
const filledEntries = bufferTimes.current.length; const filledEntries = bufferTimes.current.length;
const sum = bufferTimes.current.reduce((a, b) => a + b, 0); const sum = bufferTimes.current.reduce((a, b) => a + b, 0);
const averageBufferTime = filledEntries ? sum / filledEntries : 0; const averageBufferTime = filledEntries ? sum / filledEntries : 0;
return averageBufferTime * (isSafari || isIOS ? 2 : 1.5); return averageBufferTime * (isSafari || isIOS ? 3 : 1.5);
}; };
const calculateAdaptivePlaybackRate = ( const calculateAdaptivePlaybackRate = (
@ -467,7 +459,6 @@ function MSEPlayer({
onPlaying?.(); onPlaying?.();
setIsPlaying(true); setIsPlaying(true);
lastJumpTimeRef.current = Date.now(); lastJumpTimeRef.current = Date.now();
console.log(camera, "loaded mse data");
}} }}
muted={!audioEnabled} muted={!audioEnabled}
onPause={handlePause} onPause={handlePause}
@ -505,7 +496,6 @@ function MSEPlayer({
(bufferThreshold > 10 || bufferTime > 10) (bufferThreshold > 10 || bufferTime > 10)
) { ) {
onDisconnect(); onDisconnect();
console.log(camera, "MSE stream buffer is > 10 seconds");
onError?.("stalled"); onError?.("stalled");
} }
@ -525,7 +515,7 @@ function MSEPlayer({
) { ) {
// Jump to live on Safari/iOS due to a change of playback rate causing re-buffering // Jump to live on Safari/iOS due to a change of playback rate causing re-buffering
if (isSafari || isIOS) { if (isSafari || isIOS) {
if (bufferTime > bufferThreshold) { if (bufferTime > 3) {
jumpToLive(); jumpToLive();
} }
} else { } else {
@ -533,20 +523,6 @@ function MSEPlayer({
} }
} }
console.log(
camera,
"isPlaying?",
isPlaying,
"playbackEnabled?",
playbackEnabled,
"bufferTime",
bufferTime,
"bufferThreshold",
bufferThreshold,
"playbackRate",
playbackRate,
);
if (onError != undefined) { if (onError != undefined) {
if (videoRef.current?.paused) { if (videoRef.current?.paused) {
return; return;
@ -565,7 +541,6 @@ function MSEPlayer({
videoRef.current videoRef.current
) { ) {
onDisconnect(); onDisconnect();
console.log(camera, "MSE buffer timeout > 3 seconds");
onError("stalled"); onError("stalled");
} }
}, 3000), }, 3000),
@ -580,7 +555,6 @@ function MSEPlayer({
if (wsRef.current) { if (wsRef.current) {
onDisconnect(); onDisconnect();
} }
console.log(camera, "MSE network error");
onError?.("startup"); onError?.("startup");
} }
@ -592,7 +566,6 @@ function MSEPlayer({
if (wsRef.current) { if (wsRef.current) {
onDisconnect(); onDisconnect();
} }
console.log(camera, "Safari MSE decoding error");
onError?.("mse-decode"); onError?.("mse-decode");
} }
@ -602,7 +575,6 @@ function MSEPlayer({
onDisconnect(); onDisconnect();
if (errorCount >= 3) { if (errorCount >= 3) {
// too many mse errors, try jsmpeg // too many mse errors, try jsmpeg
console.log(camera, "too many MSE errors");
onError?.("startup"); onError?.("startup");
} else { } else {
reconnect(5000); reconnect(5000);

View File

@ -230,8 +230,6 @@ export default function LiveDashboardView({
newModes[cameraName] = isRestreamed ? "mse" : "jsmpeg"; newModes[cameraName] = isRestreamed ? "mse" : "jsmpeg";
} }
console.log("resetting", cameraName, "to", newModes[cameraName]);
return newModes; return newModes;
}); });
}, },