Skip to content

Commit

Permalink
mediaController : pause fragment loading during buffer flush
Browse files Browse the repository at this point in the history
  • Loading branch information
mangui committed Feb 2, 2016
1 parent e0be290 commit 523b177
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/controller/mse-media-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const State = {
ERROR : 'ERROR',
STARTING : 'STARTING',
IDLE : 'IDLE',
PAUSED : 'PAUSED',
KEY_LOADING : 'KEY_LOADING',
FRAG_LOADING : 'FRAG_LOADING',
FRAG_LOADING_WAITING_RETRY : 'FRAG_LOADING_WAITING_RETRY',
Expand Down Expand Up @@ -145,6 +146,8 @@ class MSEMediaController extends EventHandler {
switch(this.state) {
case State.ERROR:
//don't do anything in error state to avoid breaking further ...
case State.PAUSED:
//don't do anything in paused state either ...
break;
case State.STARTING:
// determine load level
Expand Down Expand Up @@ -636,6 +639,7 @@ class MSEMediaController extends EventHandler {
this.fragCurrent = null;
// flush everything
this.hls.trigger(Event.BUFFER_FLUSHING, {startOffset: 0, endOffset: Number.POSITIVE_INFINITY});
this.state = State.PAUSED;
// increase fragment load Index to avoid frag loop loading error after buffer flush
this.fragLoadIdx += 2 * this.config.fragLoadingLoopThreshold;
// speed up switching, trigger timer function
Expand Down Expand Up @@ -667,6 +671,7 @@ class MSEMediaController extends EventHandler {
// flush buffer preceding current fragment (flush until current fragment start offset)
// minus 1s to avoid video freezing, that could happen if we flush keyframe of current video ...
this.hls.trigger(Event.BUFFER_FLUSHING, {startOffset: 0, endOffset: currentRange.start - 1});
this.state = State.PAUSED;
}
if (!this.media.paused) {
// add a safety delay of 1s
Expand All @@ -688,6 +693,7 @@ class MSEMediaController extends EventHandler {
if (nextRange) {
// flush position is the start position of this new buffer
this.hls.trigger(Event.BUFFER_FLUSHING, {startOffset: nextRange.start, endOffset: Number.POSITIVE_INFINITY});
this.state = State.PAUSED;
// if we are here, we can also cancel any loading/demuxing in progress, as they are useless
var fragCurrent = this.fragCurrent;
if (fragCurrent && fragCurrent.loader) {
Expand Down

0 comments on commit 523b177

Please sign in to comment.