From f54a2f50d28c135e2cc5309a4570eec4064e7262 Mon Sep 17 00:00:00 2001 From: Andrew S Date: Wed, 13 Mar 2024 20:54:17 -0500 Subject: [PATCH] V1.3.0 1000 commits --- chrome/manifest.json | 2 +- chrome/player/FastStreamClient.mjs | 3 ++- chrome/player/enums/ReferenceTypes.mjs | 6 ++++++ .../player/modules/analyzer/VideoAnalyzer.mjs | 5 +++-- chrome/player/players/Fragment.mjs | 4 ++-- chrome/player/players/dash/DashPlayer.mjs | 7 ++++--- chrome/player/players/hls/HLSPlayer.mjs | 7 ++++--- chrome/player/players/mp4/MP4Player.mjs | 18 ++++++++++-------- package.json | 2 +- 9 files changed, 33 insertions(+), 21 deletions(-) create mode 100644 chrome/player/enums/ReferenceTypes.mjs diff --git a/chrome/manifest.json b/chrome/manifest.json index 7f2be77a..df946c4f 100644 --- a/chrome/manifest.json +++ b/chrome/manifest.json @@ -3,7 +3,7 @@ "default_locale": "en", "name": "__MSG_extension_name__", "description": "__MSG_extension_description__", - "version": "1.2.25.1", + "version": "1.3.0", "author": "Andrew S", "options_ui": { "page": "player/options/index.html", diff --git a/chrome/player/FastStreamClient.mjs b/chrome/player/FastStreamClient.mjs index 81908f85..f2580f98 100644 --- a/chrome/player/FastStreamClient.mjs +++ b/chrome/player/FastStreamClient.mjs @@ -22,6 +22,7 @@ import {Utils} from './utils/Utils.mjs'; import {DefaultToolSettings} from './options/defaults/ToolSettings.mjs'; import {AudioAnalyzer} from './modules/analyzer/AudioAnalyzer.mjs'; import {PreviewFrameExtractor} from './modules/analyzer/PreviewFrameExtractor.mjs'; +import {ReferenceTypes} from './enums/ReferenceTypes.mjs'; export class FastStreamClient extends EventEmitter { @@ -390,7 +391,7 @@ export class FastStreamClient extends EventEmitter { if (!newHasDownloadSpace && this.hasDownloadSpace) { fragments.forEach((fragment) => { if (fragment && fragment.status === DownloadStatus.DOWNLOAD_COMPLETE) { - fragment.addReference(1); // Don't free already downloaded fragments + fragment.addReference(ReferenceTypes.GRANDFATHERED); // Don't free already downloaded fragments } }); this.interfaceController.setStatusMessage('info', Localize.getMessage('player_buffer_storage_warning', [this.options.bufferBehind + this.options.bufferAhead]), 'warning', 5000); diff --git a/chrome/player/enums/ReferenceTypes.mjs b/chrome/player/enums/ReferenceTypes.mjs new file mode 100644 index 00000000..3c5adca9 --- /dev/null +++ b/chrome/player/enums/ReferenceTypes.mjs @@ -0,0 +1,6 @@ +export const ReferenceTypes = { + GRANDFATHERED: 0, + ANALYZER: 1, + SAVER: 2, + MP4PLAYER: 3, +}; diff --git a/chrome/player/modules/analyzer/VideoAnalyzer.mjs b/chrome/player/modules/analyzer/VideoAnalyzer.mjs index ca60550b..843f94a7 100644 --- a/chrome/player/modules/analyzer/VideoAnalyzer.mjs +++ b/chrome/player/modules/analyzer/VideoAnalyzer.mjs @@ -5,6 +5,7 @@ import {PlayerModes} from '../../enums/PlayerModes.mjs'; import {EventEmitter} from '../eventemitter.mjs'; import {EnvUtils} from '../../utils/EnvUtils.mjs'; import {VideoAligner} from './VideoAligner.mjs'; +import {ReferenceTypes} from '../../enums/ReferenceTypes.mjs'; const AnalyzerStatus = { IDLE: 'idle', @@ -203,7 +204,7 @@ export class VideoAnalyzer extends EventEmitter { dereferenceFragments(fragments) { for (let i = 0; i < fragments.length; i++) { - fragments[i].removeReference(0); + fragments[i].removeReference(ReferenceTypes.ANALYZER); } fragments.length = 0; } @@ -228,7 +229,7 @@ export class VideoAnalyzer extends EventEmitter { if (fragments[i].end > timeEnd) { break; } - fragments[i].addReference(0); + fragments[i].addReference(ReferenceTypes.ANALYZER); reserved.push(fragments[i]); } return reserved; diff --git a/chrome/player/players/Fragment.mjs b/chrome/player/players/Fragment.mjs index 9a1ee56c..52fa3308 100644 --- a/chrome/player/players/Fragment.mjs +++ b/chrome/player/players/Fragment.mjs @@ -12,8 +12,8 @@ export class Fragment { this.dataSize = null; } - addReference(id) { - if (!this.references.includes(id)) { + addReference(id, duplicate = false) { + if (duplicate || !this.references.includes(id)) { this.references.push(id); } } diff --git a/chrome/player/players/dash/DashPlayer.mjs b/chrome/player/players/dash/DashPlayer.mjs index c362a396..a9d43518 100644 --- a/chrome/player/players/dash/DashPlayer.mjs +++ b/chrome/player/players/dash/DashPlayer.mjs @@ -1,5 +1,6 @@ import {DefaultPlayerEvents} from '../../enums/DefaultPlayerEvents.mjs'; import {DownloadStatus} from '../../enums/DownloadStatus.mjs'; +import {ReferenceTypes} from '../../enums/ReferenceTypes.mjs'; import {DashJS} from '../../modules/dash.mjs'; import {EmitterRelay, EventEmitter} from '../../modules/eventemitter.mjs'; import {Utils} from '../../utils/Utils.mjs'; @@ -395,12 +396,12 @@ export default class DashPlayer extends EventEmitter { } zippedFragments.forEach((data) => { - data.fragment.addReference(2); + data.fragment.addReference(ReferenceTypes.SAVER); data.getEntry = async () => { if (data.fragment.status !== DownloadStatus.DOWNLOAD_COMPLETE) { await this.downloadFragment(data.fragment, -1); } - data.fragment.removeReference(2); + data.fragment.removeReference(ReferenceTypes.SAVER); return this.client.downloadManager.getEntry(data.fragment.getContext()); }; }); @@ -436,7 +437,7 @@ export default class DashPlayer extends EventEmitter { }; } catch (e) { zippedFragments.forEach((data) => { - data.fragment.removeReference(2); + data.fragment.removeReference(ReferenceTypes.SAVER); }); throw e; } diff --git a/chrome/player/players/hls/HLSPlayer.mjs b/chrome/player/players/hls/HLSPlayer.mjs index 4d1848cb..cb2be1a3 100644 --- a/chrome/player/players/hls/HLSPlayer.mjs +++ b/chrome/player/players/hls/HLSPlayer.mjs @@ -1,5 +1,6 @@ import {DefaultPlayerEvents} from '../../enums/DefaultPlayerEvents.mjs'; import {DownloadStatus} from '../../enums/DownloadStatus.mjs'; +import {ReferenceTypes} from '../../enums/ReferenceTypes.mjs'; import {EmitterRelay, EventEmitter} from '../../modules/eventemitter.mjs'; import {Hls} from '../../modules/hls.mjs'; import {Utils} from '../../utils/Utils.mjs'; @@ -124,12 +125,12 @@ export default class HLSPlayer extends EventEmitter { } zippedFragments.forEach((data) => { - data.fragment.addReference(2); + data.fragment.addReference(ReferenceTypes.SAVER); data.getEntry = async () => { if (data.fragment.status !== DownloadStatus.DOWNLOAD_COMPLETE) { await this.downloadFragment(data.fragment, -1); } - data.fragment.removeReference(2); + data.fragment.removeReference(ReferenceTypes.SAVER); return this.client.downloadManager.getEntry(data.fragment.getContext()); }; }); @@ -187,7 +188,7 @@ export default class HLSPlayer extends EventEmitter { } } catch (e) { zippedFragments.forEach((data) => { - data.fragment.removeReference(2); + data.fragment.removeReference(ReferenceTypes.SAVER); }); throw e; } diff --git a/chrome/player/players/mp4/MP4Player.mjs b/chrome/player/players/mp4/MP4Player.mjs index ef5b3c68..025c01a8 100644 --- a/chrome/player/players/mp4/MP4Player.mjs +++ b/chrome/player/players/mp4/MP4Player.mjs @@ -1,5 +1,6 @@ import {DefaultPlayerEvents} from '../../enums/DefaultPlayerEvents.mjs'; import {DownloadStatus} from '../../enums/DownloadStatus.mjs'; +import {ReferenceTypes} from '../../enums/ReferenceTypes.mjs'; import {EmitterCancel, EmitterRelay, EventEmitter} from '../../modules/eventemitter.mjs'; import {MP4Box} from '../../modules/mp4box.mjs'; import {Utils} from '../../utils/Utils.mjs'; @@ -351,7 +352,7 @@ export default class MP4Player extends EventEmitter { if (frag.end < time - this.options.backBufferLength) { this.currentFragments.splice(i, 1); - frag.removeReference(3); + frag.removeReference(ReferenceTypes.MP4PLAYER); i--; } } @@ -392,17 +393,18 @@ export default class MP4Player extends EventEmitter { if (!rangeHeader) { console.log(entry.responseHeaders); this.running = false; + this.emit(DefaultPlayerEvents.ERROR, 'No content range'); throw new Error('No content length'); + } else { + this.fileLength = parseInt(rangeHeader.split('/')[1]); } - this.fileLength = parseInt(rangeHeader.split('/')[1]); - this.initializeFragments(); } // console.log("append", frag) this.mp4box.appendBuffer(data); this.currentFragments.push(frag); - frag.addReference(3); + frag.addReference(ReferenceTypes.MP4PLAYER, true); this.runLoad(); }, onProgress: (stats, context, data, xhr) => { @@ -507,7 +509,7 @@ export default class MP4Player extends EventEmitter { } this.currentFragments.forEach((frag) => { - frag.removeReference(3); + frag.removeReference(ReferenceTypes.MP4PLAYER); }); this.currentFragments.length = 0; @@ -711,7 +713,7 @@ export default class MP4Player extends EventEmitter { if (!options.partialSave) { for (let i = 0; i < lastFrag; i++) { const frag = frags[i]; - frag.addReference(2); + frag.addReference(ReferenceTypes.SAVER); } } @@ -720,7 +722,7 @@ export default class MP4Player extends EventEmitter { const frag = frags[i]; if (!options.partialSave) { await this.downloadFragment(frag, -1); - frag.removeReference(2); + frag.removeReference(ReferenceTypes.SAVER); } if (frag.status === DownloadStatus.DOWNLOAD_COMPLETE) { const entry = this.client.downloadManager.getEntry(frag.getContext()); @@ -743,7 +745,7 @@ export default class MP4Player extends EventEmitter { } catch (e) { for (let i = 0; i < lastFrag; i++) { const frag = frags[i]; - frag.removeReference(2); + frag.removeReference(ReferenceTypes.SAVER); } writer.abort(); throw e; diff --git a/package.json b/package.json index 425928d7..00abca2a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "faststream", - "version": "1.2.25.1", + "version": "1.3.0", "description": "Stream videos without buffering", "scripts": { "test": "echo \"Error: no test specified\" && exit 1",