Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(FEC-13946): Player core - Use shaka preload mechanism during playlist playback #262

Merged
merged 26 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c062b44
upgrade shaka
SivanA-Kaltura May 21, 2024
1792bdd
add cachedUrls API
SivanA-Kaltura May 21, 2024
9cf28a1
add tests for cachedUrls API
SivanA-Kaltura May 21, 2024
a9d32c0
add tests for load cached url
SivanA-Kaltura May 22, 2024
eea8891
add tests for cache add and list
SivanA-Kaltura May 28, 2024
fab0bce
add tests for asset cache remove
SivanA-Kaltura Jun 2, 2024
3c919aa
add tests for asset cache init
SivanA-Kaltura Jun 3, 2024
c6d656a
add tests for asset cache init
SivanA-Kaltura Jun 3, 2024
062719c
add setCachedUrls tests
SivanA-Kaltura Jun 3, 2024
dcfa3c8
update tests
SivanA-Kaltura Jun 5, 2024
02f5009
update karma timeout setting
SivanA-Kaltura Jun 5, 2024
f047d77
add tests for dash adapter destroy
SivanA-Kaltura Jun 5, 2024
5334c24
manage one instance of shaka per player
SivanA-Kaltura Jun 5, 2024
e7781bf
upgrade shaka
SivanA-Kaltura Jun 5, 2024
92f791f
add return types to asset cache api
SivanA-Kaltura Jun 6, 2024
31a8ad8
pr fix
SivanA-Kaltura Jun 6, 2024
5f5cdfd
add test for setCachedUrls with empty array
SivanA-Kaltura Jun 6, 2024
03761ca
lint fix
SivanA-Kaltura Jun 6, 2024
5f1820b
lint fix
SivanA-Kaltura Jun 6, 2024
b2e2d18
lint fix
SivanA-Kaltura Jun 6, 2024
d0664d2
use array includes
SivanA-Kaltura Jun 6, 2024
300961a
fix tests
SivanA-Kaltura Jun 9, 2024
de15dbc
unload shaka on destroy
SivanA-Kaltura Jun 10, 2024
dea51c9
fix unit tests
SivanA-Kaltura Jun 16, 2024
13ba13d
lint fix
SivanA-Kaltura Jun 16, 2024
3dc1ba5
update playkit-js version
SivanA-Kaltura Jun 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module.exports = function (config) {
client: {
mocha: {
reporter: 'html',
timeout: 5000
timeout: 50000
}
}
});
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"@babel/runtime": "^7.23.6",
"@microsoft/api-extractor": "^7.38.0",
"@playkit-js/browserslist-config": "1.0.8",
"@playkit-js/playkit-js": "canary",
"@playkit-js/playkit-js": "0.84.10-canary.0-fa40833",
"@types/chai": "^4.3.3",
"@types/mocha": "^9.1.1",
"@types/sinon": "^10.0.20",
Expand All @@ -78,7 +78,7 @@
"karma-webpack": "^5.0.0",
"mocha": "^10.0.0",
"prettier": "^3.0.3",
"shaka-player": "4.7.0",
"shaka-player": "4.8.11",
"sinon": "^14.0.0",
"sinon-chai": "^3.7.0",
"standard-version": "^6.0.1",
Expand All @@ -89,7 +89,7 @@
"webpack-dev-server": "^4.15.1"
},
"peerDependencies": {
"@playkit-js/playkit-js": "canary",
"@playkit-js/playkit-js": "0.84.10-canary.0-fa40833",
"shaka-player": "4.7.0"
},
"browserslist": [
Expand Down
57 changes: 57 additions & 0 deletions src/cache/asset-cache.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
class AssetCache {
private shakaInstance: shaka.Player | null = null;

private cacheQueue = new Set<string>();
private cache = new Map<string, any>();

public init(shakaInstance: shaka.Player): void {
this.clearCache();
this.shakaInstance = shakaInstance;
this.preloadAssets();
}

public add(assetUrl: string): void {
if (this.cache.has(assetUrl)) return;

this.cacheQueue.add(assetUrl);
this.preloadAssets();
}

public get(assetUrl: string): Promise<any> | null {
return this.cache.get(assetUrl) || null;
}

public list(): string[] {
return [...this.cache.keys()];
}

public remove(assetUrl: string, destroy: boolean = false): void {
if (this.cacheQueue.has(assetUrl)) {
this.cacheQueue.delete(assetUrl);
} else if (this.cache.has(assetUrl)) {
const assetPromise = this.cache.get(assetUrl);
if (destroy) {
assetPromise.then(preloadMgr => preloadMgr.destroy());
}
this.cache.delete(assetUrl);
}
}

private clearCache(): void {
const assetUrls = this.cache.keys();
for (const assetUrl of assetUrls) {
this.remove(assetUrl, true);
}
}

private preloadAssets(): void {
if (!this.shakaInstance) return;

for (const assetUrl of this.cacheQueue) {
this.cache.set(assetUrl, this.shakaInstance.preload(assetUrl));
this.cacheQueue.delete(assetUrl);
}
}
}

export {AssetCache};
Loading
Loading