diff options
Diffstat (limited to 'client/src/assets/player/p2p-media-loader')
4 files changed, 19 insertions, 35 deletions
diff --git a/client/src/assets/player/p2p-media-loader/hls-plugin.ts b/client/src/assets/player/p2p-media-loader/hls-plugin.ts index 53969a5a5..3050110cd 100644 --- a/client/src/assets/player/p2p-media-loader/hls-plugin.ts +++ b/client/src/assets/player/p2p-media-loader/hls-plugin.ts | |||
@@ -264,20 +264,16 @@ class Html5Hlsjs { | |||
264 | if (this.errorCounts[ data.type ]) this.errorCounts[ data.type ] += 1 | 264 | if (this.errorCounts[ data.type ]) this.errorCounts[ data.type ] += 1 |
265 | else this.errorCounts[ data.type ] = 1 | 265 | else this.errorCounts[ data.type ] = 1 |
266 | 266 | ||
267 | if (!data.fatal) { | 267 | if (data.fatal) console.warn(error.message) |
268 | console.warn(error.message) | 268 | else console.error(error.message, data) |
269 | return | ||
270 | } | ||
271 | |||
272 | console.error(error.message) | ||
273 | 269 | ||
274 | if (data.type === Hlsjs.ErrorTypes.NETWORK_ERROR) { | 270 | if (data.type === Hlsjs.ErrorTypes.NETWORK_ERROR) { |
275 | error.code = 2 | 271 | error.code = 2 |
276 | this._handleNetworkError(error) | 272 | this._handleNetworkError(error) |
277 | } else if (data.type === Hlsjs.ErrorTypes.MEDIA_ERROR && data.details !== 'manifestIncompatibleCodecsError') { | 273 | } else if (data.fatal && data.type === Hlsjs.ErrorTypes.MEDIA_ERROR && data.details !== 'manifestIncompatibleCodecsError') { |
278 | error.code = 3 | 274 | error.code = 3 |
279 | this._handleMediaError(error) | 275 | this._handleMediaError(error) |
280 | } else { | 276 | } else if (data.fatal) { |
281 | this.hls.destroy() | 277 | this.hls.destroy() |
282 | console.info('bubbling error up to VIDEOJS') | 278 | console.info('bubbling error up to VIDEOJS') |
283 | this.tech.error = () => error as any | 279 | this.tech.error = () => error as any |
@@ -286,12 +282,12 @@ class Html5Hlsjs { | |||
286 | } | 282 | } |
287 | 283 | ||
288 | private switchQuality (qualityId: number) { | 284 | private switchQuality (qualityId: number) { |
289 | this.hls.nextLevel = qualityId | 285 | this.hls.currentLevel = qualityId |
290 | } | 286 | } |
291 | 287 | ||
292 | private _levelLabel (level: Hlsjs.Level) { | 288 | private _levelLabel (level: Hlsjs.Level) { |
293 | if (this.player.srOptions_.levelLabelHandler) { | 289 | if (this.player.srOptions_.levelLabelHandler) { |
294 | return this.player.srOptions_.levelLabelHandler(level) | 290 | return this.player.srOptions_.levelLabelHandler(level as any) |
295 | } | 291 | } |
296 | 292 | ||
297 | if (level.height) return level.height + 'p' | 293 | if (level.height) return level.height + 'p' |
diff --git a/client/src/assets/player/p2p-media-loader/p2p-media-loader-plugin.ts b/client/src/assets/player/p2p-media-loader/p2p-media-loader-plugin.ts index 2eb849d2b..093795e48 100644 --- a/client/src/assets/player/p2p-media-loader/p2p-media-loader-plugin.ts +++ b/client/src/assets/player/p2p-media-loader/p2p-media-loader-plugin.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import * as Hlsjs from 'hls.js/dist/hls.light.js' | 1 | import * as Hlsjs from 'hls.js/dist/hls.light.js' |
2 | import { Events, Segment } from 'p2p-media-loader-core' | ||
3 | import { Engine, initHlsJsPlayer, initVideoJsContribHlsJsPlayer } from 'p2p-media-loader-hlsjs' | ||
4 | import videojs from 'video.js' | 2 | import videojs from 'video.js' |
3 | import { Events, Segment } from '@peertube/p2p-media-loader-core' | ||
4 | import { Engine, initHlsJsPlayer, initVideoJsContribHlsJsPlayer } from '@peertube/p2p-media-loader-hlsjs' | ||
5 | import { timeToInt } from '@shared/core-utils' | 5 | import { timeToInt } from '@shared/core-utils' |
6 | import { P2PMediaLoaderPluginOptions, PlayerNetworkInfo } from '../peertube-videojs-typings' | 6 | import { P2PMediaLoaderPluginOptions, PlayerNetworkInfo } from '../peertube-videojs-typings' |
7 | import { registerConfigPlugin, registerSourceHandler } from './hls-plugin' | 7 | import { registerConfigPlugin, registerSourceHandler } from './hls-plugin' |
@@ -36,9 +36,6 @@ class P2pMediaLoaderPlugin extends Plugin { | |||
36 | 36 | ||
37 | private networkInfoInterval: any | 37 | private networkInfoInterval: any |
38 | 38 | ||
39 | private hlsjsCurrentLevel: number | ||
40 | private hlsjsLevels: Hlsjs.Level[] | ||
41 | |||
42 | constructor (player: videojs.Player, options?: P2PMediaLoaderPluginOptions) { | 39 | constructor (player: videojs.Player, options?: P2PMediaLoaderPluginOptions) { |
43 | super(player) | 40 | super(player) |
44 | 41 | ||
@@ -88,13 +85,12 @@ class P2pMediaLoaderPlugin extends Plugin { | |||
88 | } | 85 | } |
89 | 86 | ||
90 | getCurrentLevel () { | 87 | getCurrentLevel () { |
91 | return this.hlsjsLevels.find(l => l.level === this.hlsjsCurrentLevel) | 88 | return this.hlsjs.levels[this.hlsjs.currentLevel] |
92 | } | 89 | } |
93 | 90 | ||
94 | getLiveLatency () { | 91 | getLiveLatency () { |
95 | return undefined as number | 92 | // FIXME: typings |
96 | // FIXME: Use latency when hls >= V1 | 93 | return Math.round((this.hlsjs as any).latency) |
97 | // return this.hlsjs.latency | ||
98 | } | 94 | } |
99 | 95 | ||
100 | getHLSJS () { | 96 | getHLSJS () { |
@@ -140,31 +136,23 @@ class P2pMediaLoaderPlugin extends Plugin { | |||
140 | } | 136 | } |
141 | 137 | ||
142 | private runStats () { | 138 | private runStats () { |
143 | this.p2pEngine.on(Events.PieceBytesDownloaded, (method: string, size: number) => { | 139 | this.p2pEngine.on(Events.PieceBytesDownloaded, (method: string, _segment, bytes: number) => { |
144 | const elem = method === 'p2p' ? this.statsP2PBytes : this.statsHTTPBytes | 140 | const elem = method === 'p2p' ? this.statsP2PBytes : this.statsHTTPBytes |
145 | 141 | ||
146 | elem.pendingDownload.push(size) | 142 | elem.pendingDownload.push(bytes) |
147 | elem.totalDownload += size | 143 | elem.totalDownload += bytes |
148 | }) | 144 | }) |
149 | 145 | ||
150 | this.p2pEngine.on(Events.PieceBytesUploaded, (method: string, size: number) => { | 146 | this.p2pEngine.on(Events.PieceBytesUploaded, (method: string, _segment, bytes: number) => { |
151 | const elem = method === 'p2p' ? this.statsP2PBytes : this.statsHTTPBytes | 147 | const elem = method === 'p2p' ? this.statsP2PBytes : this.statsHTTPBytes |
152 | 148 | ||
153 | elem.pendingUpload.push(size) | 149 | elem.pendingUpload.push(bytes) |
154 | elem.totalUpload += size | 150 | elem.totalUpload += bytes |
155 | }) | 151 | }) |
156 | 152 | ||
157 | this.p2pEngine.on(Events.PeerConnect, () => this.statsP2PBytes.numPeers++) | 153 | this.p2pEngine.on(Events.PeerConnect, () => this.statsP2PBytes.numPeers++) |
158 | this.p2pEngine.on(Events.PeerClose, () => this.statsP2PBytes.numPeers--) | 154 | this.p2pEngine.on(Events.PeerClose, () => this.statsP2PBytes.numPeers--) |
159 | 155 | ||
160 | this.hlsjs.on(Hlsjs.Events.MANIFEST_PARSED, (_e, manifest) => { | ||
161 | this.hlsjsCurrentLevel = manifest.firstLevel | ||
162 | this.hlsjsLevels = manifest.levels | ||
163 | }) | ||
164 | this.hlsjs.on(Hlsjs.Events.LEVEL_LOADED, (_e, level) => { | ||
165 | this.hlsjsCurrentLevel = level.levelId || (level as any).id | ||
166 | }) | ||
167 | |||
168 | this.networkInfoInterval = setInterval(() => { | 156 | this.networkInfoInterval = setInterval(() => { |
169 | const p2pDownloadSpeed = this.arraySum(this.statsP2PBytes.pendingDownload) | 157 | const p2pDownloadSpeed = this.arraySum(this.statsP2PBytes.pendingDownload) |
170 | const p2pUploadSpeed = this.arraySum(this.statsP2PBytes.pendingUpload) | 158 | const p2pUploadSpeed = this.arraySum(this.statsP2PBytes.pendingUpload) |
diff --git a/client/src/assets/player/p2p-media-loader/segment-url-builder.ts b/client/src/assets/player/p2p-media-loader/segment-url-builder.ts index 039777cea..ad0e460ae 100644 --- a/client/src/assets/player/p2p-media-loader/segment-url-builder.ts +++ b/client/src/assets/player/p2p-media-loader/segment-url-builder.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | import { Segment } from 'p2p-media-loader-core' | 1 | import { Segment } from '@peertube/p2p-media-loader-core' |
2 | import { RedundancyUrlManager } from './redundancy-url-manager' | 2 | import { RedundancyUrlManager } from './redundancy-url-manager' |
3 | 3 | ||
4 | function segmentUrlBuilderFactory (redundancyUrlManager: RedundancyUrlManager) { | 4 | function segmentUrlBuilderFactory (redundancyUrlManager: RedundancyUrlManager) { |
diff --git a/client/src/assets/player/p2p-media-loader/segment-validator.ts b/client/src/assets/player/p2p-media-loader/segment-validator.ts index 4a0caec5e..a28474793 100644 --- a/client/src/assets/player/p2p-media-loader/segment-validator.ts +++ b/client/src/assets/player/p2p-media-loader/segment-validator.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { wait } from '@root-helpers/utils' | 1 | import { wait } from '@root-helpers/utils' |
2 | import { Segment } from 'p2p-media-loader-core' | 2 | import { Segment } from '@peertube/p2p-media-loader-core' |
3 | import { basename } from 'path' | 3 | import { basename } from 'path' |
4 | 4 | ||
5 | type SegmentsJSON = { [filename: string]: string | { [byterange: string]: string } } | 5 | type SegmentsJSON = { [filename: string]: string | { [byterange: string]: string } } |