diff options
Diffstat (limited to 'youtube/static/js/av-merge.js')
-rw-r--r-- | youtube/static/js/av-merge.js | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/youtube/static/js/av-merge.js b/youtube/static/js/av-merge.js index e00f440..ba496e6 100644 --- a/youtube/static/js/av-merge.js +++ b/youtube/static/js/av-merge.js @@ -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: 15 * 10**6, // 15 megabytes WebOS (LG) + samsungTizen: 15 * 10**6, // 15 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']; |