http://monterosa.d2.comp.nus.edu.sg/streaming/bbb.mpd
setInterval(() => {
let videoMetrics = player.getDashMetrics();
let bufferLevelSec = "N/A",
avgThroughputKbps = "N/A",
avgLatencySec = "N/A";
if (videoMetrics) {
// Retrieve the current buffer level (in seconds) for the video stream.
const currentBufferLevel = videoMetrics.getCurrentBufferLevel("video");
if (currentBufferLevel !== null && currentBufferLevel !== undefined) {
bufferLevelSec = parseFloat(currentBufferLevel).toFixed(2);
}
// Retrieve average throughput (in kbps) using the dedicated API.
const throughputKbps = player.getAverageThroughput("video");
if (throughputKbps) {
avgThroughputKbps = throughputKbps.toFixed(2);
}
// Retrieve all HTTP requests for the video stream.
const httpRequests = videoMetrics.getHttpRequests("video");
if (httpRequests && httpRequests.length > 0) {
let latencyValues = [];
// Loop backwards over the HTTP requests, using the last 4 that include trequest and tresponse.
for (let j = httpRequests.length - 1; j >= 0 && latencyValues.length < 4; j--) {
let req = httpRequests[j];
if (req.trequest && req.tresponse) {
let startTime = new Date(req.trequest).getTime();
let endTime = new Date(req.tresponse).getTime();
latencyValues.push(endTime - startTime);
}
}
if (latencyValues.length > 0) {
let sumLatency = latencyValues.reduce((sum, val) => sum + val, 0);
avgLatencySec = (sumLatency / latencyValues.length / 1000).toFixed(2);
}
}
}
// Construct log message and log to console
const logMessage = `Buffer Level: ${bufferLevelSec} sec, Throughput: ${avgThroughputKbps} kbps, Latency: ${avgLatencySec} sec`;
console.log(logMessage);
// Prepare a log entry object with a timestamp and metrics.
const logEntry = {
timestamp: new Date().toISOString(),
bufferLevelSec: bufferLevelSec,
avgThroughputKbps: avgThroughputKbps,
avgLatencySec: avgLatencySec,
logMessage: logMessage
};
// Send the log entry to Firebase Realtime Database via an HTTP POST request.
fetch("https://test-32e43-default-rtdb.firebaseio.com/logs.json", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(logEntry)
})
.then(response => response.json())
.then(data => console.log("Log sent successfully:", data))
.catch(error => console.error("Error sending log:", error));
}, 8000);
player.on(dashjs.MediaPlayer.events.QUALITY_CHANGE_RENDERED, (e) => {
console.log("Quality changed to level:", e.newQuality);
});
Video Metrics(Dynamic)
Video Metrics(Throughputs)
Video Metrics(BOLA)
Buffer Level Comparison
Throughput Comparison
Latency Comparison