Improve buffer management for different platforms
- Introduced `BUFFER_CONFIG` to define buffer sizes for various systems (webOS, Samsung Tizen, Android TV, desktop). - Added `detectSystem()` function to determine the platform based on `navigator.userAgent`. - Updated `Stream` constructor to use platform-specific buffer sizes dynamically. - Added console log for debugging detected system and applied buffer size.
This commit is contained in:
parent
a6ca011202
commit
98603439cb
@ -20,6 +20,29 @@
|
||||
// TODO: Call abort to cancel in-progress appends?
|
||||
|
||||
|
||||
// Buffer sizes for different systems
|
||||
const BUFFER_CONFIG = {
|
||||
default: 50 * 10**6, // 50 megabytes
|
||||
webOS: 20 * 10**6, // 20 megabytes WebOS (LG)
|
||||
samsungTizen: 20 * 10**6, // 20 megabytes Samsung Tizen OS
|
||||
androidTV: 30 * 10**6, // 30 megabytes Android TV
|
||||
desktop: 50 * 10**6, // 50 megabytes PC/Mac
|
||||
};
|
||||
|
||||
function detectSystem() {
|
||||
const userAgent = navigator.userAgent.toLowerCase();
|
||||
if (/webos|lg browser/i.test(userAgent)) {
|
||||
return "webOS";
|
||||
} else if (/tizen/i.test(userAgent)) {
|
||||
return "samsungTizen";
|
||||
} else if (/android tv|smart-tv/i.test(userAgent)) {
|
||||
return "androidTV";
|
||||
} else if (/firefox|chrome|safari|edge/i.test(userAgent)) {
|
||||
return "desktop";
|
||||
} else {
|
||||
return "default";
|
||||
}
|
||||
}
|
||||
|
||||
function AVMerge(video, srcInfo, startTime){
|
||||
this.audioSource = null;
|
||||
@ -164,6 +187,8 @@ AVMerge.prototype.printDebuggingInfo = function() {
|
||||
}
|
||||
|
||||
function Stream(avMerge, source, startTime, avRatio) {
|
||||
const selectedSystem = detectSystem();
|
||||
let baseBufferTarget = BUFFER_CONFIG[selectedSystem] || BUFFER_CONFIG.default;
|
||||
this.avMerge = avMerge;
|
||||
this.video = avMerge.video;
|
||||
this.url = source['url'];
|
||||
@ -173,10 +198,11 @@ function Stream(avMerge, source, startTime, avRatio) {
|
||||
this.mimeCodec = source['mime_codec']
|
||||
this.streamType = source['acodec'] ? 'audio' : 'video';
|
||||
if (this.streamType == 'audio') {
|
||||
this.bufferTarget = avRatio*50*10**6;
|
||||
this.bufferTarget = avRatio * baseBufferTarget;
|
||||
} else {
|
||||
this.bufferTarget = 50*10**6; // 50 megabytes
|
||||
this.bufferTarget = baseBufferTarget;
|
||||
}
|
||||
console.info(`Detected system: ${selectedSystem}. Applying bufferTarget of ${this.bufferTarget} bytes to ${this.streamType}.`);
|
||||
|
||||
this.initRange = source['init_range'];
|
||||
this.indexRange = source['index_range'];
|
||||
|
Loading…
x
Reference in New Issue
Block a user