Fix space (MonitorStream.js)

pull/4646/head
IgorA100 2026-02-23 23:41:02 +03:00 committed by GitHub
parent 769a1df1dc
commit ab620ab28e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 31 additions and 31 deletions

View File

@ -1479,51 +1479,51 @@ function MonitorStream(monitorData) {
};
this.manageMSESocket = function(videoEl, socket, mediaSource) {
// We correct the lag from real time. Relevant for long viewing and network problems.
// We correct the lag from real time. Relevant for long viewing and network problems.
//const videoEl = document.getElementById("liveStream" + this.id);
if (socket && videoEl && videoEl.buffered != undefined && videoEl.buffered.length > 0) {
const videoElCurrentTime = videoEl.currentTime; // Current time of playback
const currentTime = (Date.now() / 1000);
const deltaRealTime = (currentTime - this.streamStartTime).toFixed(2); // How much real time has passed since playback started
const bufferEndTime = videoEl.buffered.end(videoEl.buffered.length - 1);
let delayCurrent = (deltaRealTime - videoElCurrentTime).toFixed(2); // Delay of playback moment from real time
if (delayCurrent < 0) {
//Possibly with high client CPU load. Cannot be negative.
this.streamStartTime = currentTime - bufferEndTime;
delayCurrent = 0;
}
const videoElCurrentTime = videoEl.currentTime; // Current time of playback
const currentTime = (Date.now() / 1000);
const deltaRealTime = (currentTime - this.streamStartTime).toFixed(2); // How much real time has passed since playback started
const bufferEndTime = videoEl.buffered.end(videoEl.buffered.length - 1);
let delayCurrent = (deltaRealTime - videoElCurrentTime).toFixed(2); // Delay of playback moment from real time
if (delayCurrent < 0) {
//Possibly with high client CPU load. Cannot be negative.
this.streamStartTime = currentTime - bufferEndTime;
delayCurrent = 0;
}
$j('#delayValue'+this.id).text((delayCurrent != 0) ? delayCurrent: '-');
// The first 10 seconds are allocated for the start, at this point the delay can be more than 2-3 seconds. It is necessary to avoid STOP/START looping
if (!videoEl.paused && deltaRealTime > 10) {
// Ability to scroll through the last buffered frames when paused.
if (bufferEndTime - videoElCurrentTime > 2.0) {
// Correcting a flow lag of more than X seconds from the end of the buffer
// When the client's CPU load is 99-100%, there may be problems with constant time adjustment, but this is better than a constantly increasing lag of tens of seconds.
//console.debug(`${dateTimeToISOLocal(new Date())} Adjusting currentTime for a video object ID=${this.id}:${(bufferEndTime - videoElCurrentTime).toFixed(2)}sec.`);
videoEl.currentTime = bufferEndTime - 0.1;
}
if (deltaRealTime - bufferEndTime > 1.5) {
// Correcting the buffer end lag by more than X seconds from real time
console.log(`${dateTimeToISOLocal(new Date())} Adjusting currentTime for a video object ID=${this.id} Buffer end lag from real time='${(deltaRealTime - bufferEndTime).toFixed(2)}sec. RESTART is started.`);
// The first 10 seconds are allocated for the start, at this point the delay can be more than 2-3 seconds. It is necessary to avoid STOP/START looping
if (!videoEl.paused && deltaRealTime > 10) {
// Ability to scroll through the last buffered frames when paused.
if (bufferEndTime - videoElCurrentTime > 2.0) {
// Correcting a flow lag of more than X seconds from the end of the buffer
// When the client's CPU load is 99-100%, there may be problems with constant time adjustment, but this is better than a constantly increasing lag of tens of seconds.
//console.debug(`${dateTimeToISOLocal(new Date())} Adjusting currentTime for a video object ID=${this.id}:${(bufferEndTime - videoElCurrentTime).toFixed(2)}sec.`);
videoEl.currentTime = bufferEndTime - 0.1;
}
if (deltaRealTime - bufferEndTime > 1.5) {
// Correcting the buffer end lag by more than X seconds from real time
console.log(`${dateTimeToISOLocal(new Date())} Adjusting currentTime for a video object ID=${this.id} Buffer end lag from real time='${(deltaRealTime - bufferEndTime).toFixed(2)}sec. RESTART is started.`);
this.restart(this.currentChannelStream);
}
}
this.restart(this.currentChannelStream);
}
}
} else if (!socket && this.started) {
//if (mediaSource.readyState == 'open' || mediaSource.readyState == 'closed') {
if (mediaSource) {
// Go2RTC has a problem with Auto mode, as Go2RTC tries to start each one (MSE and RTC) one at a time. At this point, the socket is destroyed, which can sometimes lead to multiple restarts. Probably...
if (mediaSource.readyState == 'open') {
console.warn(`UNSCHEDULED CLOSE SOCKET for camera ID=${this.id} RESTART is started.`);
this.restart(this.currentChannelStream);
} else {
console.warn(`UNSCHEDULED CLOSE SOCKET for camera ID=${this.id} RESTART is started.`);
this.restart(this.currentChannelStream);
} else {
console.log(`MediaSource for camera ID=${this.id} is in state "${mediaSource.readyState.toUpperCase()}"`);
}
}
}
}
}
}
this.statusQuery = function() {
this.streamCommand(CMD_QUERY);