Skip to content

Commit

Permalink
Audio stream ctrl error handling logs improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
tchakabam committed Apr 23, 2018
1 parent c3a1e22 commit 7989b2e
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/controller/audio-stream-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ class AudioStreamController extends TaskLoop {
let pendingData = this.pendingData;

if (!pendingData) {
console.warn('Apparently attempt to enqueue media payload without codec initialization data upfront');
logger.warn('Apparently attempt to enqueue media payload without codec initialization data upfront');
hls.trigger(Event.ERROR, { type: ErrorTypes.MEDIA_ERROR, details: null, fatal: true });
return;
}
Expand Down Expand Up @@ -787,6 +787,12 @@ class AudioStreamController extends TaskLoop {
switch (data.details) {
case ErrorDetails.FRAG_LOAD_ERROR:
case ErrorDetails.FRAG_LOAD_TIMEOUT:
const frag = data.frag;
// don't handle frag error not related to audio fragment
if (frag && frag.type !== 'audio') {
break;
}

if (!data.fatal) {
let loadError = this.fragLoadError;
if (loadError) {
Expand All @@ -795,17 +801,17 @@ class AudioStreamController extends TaskLoop {
loadError = 1;
}

let config = this.config;
const config = this.config;
if (loadError <= config.fragLoadingMaxRetry) {
this.fragLoadError = loadError;
// exponential backoff capped to config.fragLoadingMaxRetryTimeout
let delay = Math.min(Math.pow(2, loadError - 1) * config.fragLoadingRetryDelay, config.fragLoadingMaxRetryTimeout);
logger.warn(`audioStreamController: frag loading failed, retry in ${delay} ms`);
const delay = Math.min(Math.pow(2, loadError - 1) * config.fragLoadingRetryDelay, config.fragLoadingMaxRetryTimeout);
logger.warn(`AudioStreamController: frag loading failed, retry in ${delay} ms`);
this.retryDate = performance.now() + delay;
// retry loading state
this.state = State.FRAG_LOADING_WAITING_RETRY;
} else {
logger.error(`audioStreamController: ${data.details} reaches max retry, redispatch as fatal ...`);
logger.error(`AudioStreamController: ${data.details} reaches max retry, redispatch as fatal ...`);
// switch error to fatal
data.fatal = true;
this.state = State.ERROR;
Expand All @@ -820,7 +826,7 @@ class AudioStreamController extends TaskLoop {
if (this.state !== State.ERROR) {
// if fatal error, stop processing, otherwise move to IDLE to retry loading
this.state = data.fatal ? State.ERROR : State.IDLE;
logger.warn(`audioStreamController: ${data.details} while loading frag,switch to ${this.state} state ...`);
logger.warn(`AudioStreamController: ${data.details} while loading frag, now switching to ${this.state} state ...`);
}
break;
case ErrorDetails.BUFFER_FULL_ERROR:
Expand All @@ -835,14 +841,14 @@ class AudioStreamController extends TaskLoop {
if (config.maxMaxBufferLength >= config.maxBufferLength) {
// reduce max buffer length as it might be too high. we do this to avoid loop flushing ...
config.maxMaxBufferLength /= 2;
logger.warn(`audio:reduce max buffer length to ${config.maxMaxBufferLength}s`);
logger.warn(`AudioStreamController: reduce max buffer length to ${config.maxMaxBufferLength}s`);
}
this.state = State.IDLE;
} else {
// current position is not buffered, but browser is still complaining about buffer full error
// this happens on IE/Edge, refer to https://github.com/video-dev/hls.js/pull/708
// in that case flush the whole audio buffer to recover
logger.warn('buffer full error also media.currentTime is not buffered, flush audio buffer');
logger.warn('AudioStreamController: buffer full error also media.currentTime is not buffered, flush audio buffer');
this.fragCurrent = null;
// flush everything
this.state = State.BUFFER_FLUSHING;
Expand All @@ -858,7 +864,7 @@ class AudioStreamController extends TaskLoop {
onBufferFlushed () {
let pendingData = this.pendingData;
if (pendingData && pendingData.length) {
logger.log('appending pending audio data on Buffer Flushed');
logger.log('AudioStreamController: appending pending audio data after buffer flushed');
pendingData.forEach(appendObj => {
this.hls.trigger(Event.BUFFER_APPENDING, appendObj);
});
Expand Down

0 comments on commit 7989b2e

Please sign in to comment.