refactor: 💡 (xgplayer-stream-shared) MSE ChangeType不支持时,对外抛出错误

This commit is contained in:
gemstone 2024-05-15 13:56:35 +08:00
parent 20097cec9d
commit b9073a4a80
2 changed files with 52 additions and 35 deletions

View File

@ -2,15 +2,15 @@ export const ERR = {
MANIFEST: 'manifest',
NETWORK: 'network',
NETWORK_TIMEOUT: 'network_timeout',
NETWORK_FORBIDDEN:'network_forbidden',
NETWORK_FORBIDDEN: 'network_forbidden',
NETWORK_NOTFOUND: 'network_notfound',
NETWROK_RANGE_NOT_SATISFIABLE:'network_range_not_satisfiable',
NETWROK_RANGE_NOT_SATISFIABLE: 'network_range_not_satisfiable',
DEMUX: 'demux',
REMUX: 'remux',
MEDIA: 'media',
DRM: 'drm',
OTHER: 'other',
RUNTIME:'runtime',
RUNTIME: 'runtime',
SUB_TYPES: {
FLV: 'FLV',
@ -21,35 +21,36 @@ export const ERR = {
MSE_APPEND_BUFFER: 'MSE_APPEND_BUFFER',
MSE_OTHER: 'MSE_OTHER',
MSE_FULL: 'MSE_FULL',
MSE_CHANGE_TYPE: 'MSE_CHANGE_TYPE',
OPTION: 'OPTION',
DASH:'DASH',
LICENSE:'LICENSE',
CUSTOM_LICENSE:'CUSTOM_LICENSE',
MSE_HIJACK:'MSE_HIJACK',
EME_HIJACK:'EME_HIJACK',
SIDX:'SIDX',
NO_CANPLAY_ERROR:'NO_CANPLAY_ERROR',
BUFFERBREAK_ERROR:'BUFFERBREAK_ERROR',
DASH: 'DASH',
LICENSE: 'LICENSE',
CUSTOM_LICENSE: 'CUSTOM_LICENSE',
MSE_HIJACK: 'MSE_HIJACK',
EME_HIJACK: 'EME_HIJACK',
SIDX: 'SIDX',
NO_CANPLAY_ERROR: 'NO_CANPLAY_ERROR',
BUFFERBREAK_ERROR: 'BUFFERBREAK_ERROR',
WAITING_TIMEOUT_ERROR: 'WAITING_TIMEOUT_ERROR',
MEDIA_ERR_ABORTED:'MEDIA_ERR_ABORTED',
MEDIA_ERR_NETWORK:'MEDIA_ERR_NETWORK',
MEDIA_ERR_DECODE:'MEDIA_ERR_DECODE',
MEDIA_ERR_SRC_NOT_SUPPORTED:'MEDIA_ERR_SRC_NOT_SUPPORTED',
MEDIA_ERR_CODEC_NOT_SUPPORTED:'MEDIA_ERR_CODEC_NOT_SUPPORTED',
MEDIA_ERR_URL_EMPTY:'MEDIA_ERR_URL_EMPTY'
MEDIA_ERR_ABORTED: 'MEDIA_ERR_ABORTED',
MEDIA_ERR_NETWORK: 'MEDIA_ERR_NETWORK',
MEDIA_ERR_DECODE: 'MEDIA_ERR_DECODE',
MEDIA_ERR_SRC_NOT_SUPPORTED: 'MEDIA_ERR_SRC_NOT_SUPPORTED',
MEDIA_ERR_CODEC_NOT_SUPPORTED: 'MEDIA_ERR_CODEC_NOT_SUPPORTED',
MEDIA_ERR_URL_EMPTY: 'MEDIA_ERR_URL_EMPTY'
}
}
export const ERR_CODE = {
[ERR.MANIFEST]: {
HLS: 1100,
DASH:1200
DASH: 1200
},
[ERR.NETWORK]: 2100,
[ERR.NETWORK_TIMEOUT]: 2101,
[ERR.NETWORK_FORBIDDEN]:2103,
[ERR.NETWORK_NOTFOUND]:2104,
[ERR.NETWROK_RANGE_NOT_SATISFIABLE]:2116,
[ERR.NETWORK_FORBIDDEN]: 2103,
[ERR.NETWORK_NOTFOUND]: 2104,
[ERR.NETWROK_RANGE_NOT_SATISFIABLE]: 2116,
[ERR.DEMUX]: {
FLV: 3100,
HLS: 3200,
@ -72,23 +73,22 @@ export const ERR_CODE = {
MSE_APPEND_BUFFER: 5201,
MSE_OTHER: 5202,
MSE_FULL: 5203,
MSE_HIJACK:5204,
EME_HIJACK:5301
MSE_HIJACK: 5204,
MSE_CHANGE_TYPE: 5205,
EME_HIJACK: 5301
},
[ERR.DRM]:{
LICENSE:7100,
CUSTOM_LICENSE:7200
[ERR.DRM]: {
LICENSE: 7100,
CUSTOM_LICENSE: 7200
},
[ERR.OTHER]: 8000,
[ERR.RUNTIME]:{
NO_CANPLAY_ERROR:9001,
BUFFERBREAK_ERROR:9002,
WAITING_TIMEOUT_ERROR:9003
[ERR.RUNTIME]: {
NO_CANPLAY_ERROR: 9001,
BUFFERBREAK_ERROR: 9002,
WAITING_TIMEOUT_ERROR: 9003
}
}
export class StreamingError extends Error {
constructor (type, subType, origin, payload, msg) {
super(msg || origin?.message)

View File

@ -342,10 +342,23 @@ export class MSE {
const sb = this._sourceBuffer[type]
if (!this.mediaSource || !sb || sb.mimeType === mimeType) return Promise.resolve()
if (typeof sb.changeType !== 'function') return Promise.reject()
if (typeof sb.changeType !== 'function') {
return Promise.reject(
new StreamingError(
ERR.MEDIA,
ERR.SUB_TYPES.MSE_CHANGE_TYPE,
new Error('changeType is not a function')
)
)
}
return this._enqueueOp(type, () => {
sb.changeType(mimeType)
try {
sb.changeType(mimeType)
} catch (e) {
throw new StreamingError(ERR.MEDIA, ERR.SUB_TYPES.MSE_CHANGE_TYPE, e)
}
sb.mimeType = mimeType
this._onSBUpdateEnd(type)
}, 'changeType', {mimeType})
@ -581,7 +594,11 @@ export class MSE {
op.promise.reject(new StreamingError(ERR.MEDIA, ERR.SUB_TYPES.MSE_FULL, error))
} else {
this._logger.error(error)
op.promise.reject(new StreamingError(ERR.MEDIA, ERR.SUB_TYPES.MSE_OTHER, error))
op.promise.reject(
error.constructor === StreamingError
? error
: new StreamingError(ERR.MEDIA, ERR.SUB_TYPES.MSE_OTHER, error)
)
queue.shift()
this._startQueue(type)
}