Skip to content

Commit

Permalink
Refactor transmuxing data flow (#199)
Browse files Browse the repository at this point in the history
Refactors transmuxing data flow so that the transmuxer returns the result instead of having the remuxer emit it via events. Also implements a push/flush workflow, in which flush signals the end of transmuxing for a single segment. This PR also converts a significant amount of classes to TypeScript.
  • Loading branch information
johnBartos committed Mar 26, 2019
1 parent e8cd7f3 commit 6836ef3
Show file tree
Hide file tree
Showing 31 changed files with 2,676 additions and 2,159 deletions.
467 changes: 233 additions & 234 deletions src/controller/audio-stream-controller.js

Large diffs are not rendered by default.

39 changes: 22 additions & 17 deletions src/controller/base-stream-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ export default class BaseStreamController extends TaskLoop {
}
this.fragmentTracker.removeFragment(frag);
}
if (this.demuxer) {
this.demuxer.destroy();
this.demuxer = null;
if (this.transmuxer) {
this.transmuxer.destroy();
this.transmuxer = null;
}
this.fragCurrent = null;
this.fragPrevious = null;
Expand Down Expand Up @@ -141,12 +141,6 @@ export default class BaseStreamController extends TaskLoop {
data.frag = frag;
this.hls.trigger(Event.FRAG_LOADED, data);
this._handleFragmentLoad(frag, payload, stats);
})
.catch((e) => {
if (e.data.details === ErrorDetails.INTERNAL_ABORTED) {
return;
}
this.hls.trigger(Event.ERROR, e.data);
});
}

Expand All @@ -164,12 +158,6 @@ export default class BaseStreamController extends TaskLoop {
stats.tparsed = stats.tbuffered = window.performance.now();
hls.trigger(Event.FRAG_BUFFERED, { stats: stats, frag: fragCurrent, id: 'main' });
this.tick();
})
.catch((e) => {
if (e.data.details === ErrorDetails.INTERNAL_ABORTED) {
return;
}
this.hls.trigger(Event.ERROR, e.data);
});
}

Expand All @@ -180,8 +168,25 @@ export default class BaseStreamController extends TaskLoop {
_doFragLoad (frag) {
this.state = State.FRAG_LOADING;
this.hls.trigger(Event.FRAG_LOADING, { frag });
return this.fragmentLoader.load(frag);
return this.fragmentLoader.load(frag)
.catch((e) => {
const errorData = e ? e.data : null;
if (errorData && errorData.details === ErrorDetails.INTERNAL_ABORTED) {
const fragPrev = this.fragPrevious;
if (fragPrev) {
this.nextLoadPosition = fragPrev.start + fragPrev.duration;
} else {
this.nextLoadPosition = this.lastCurrentTime;
}
logger.log(`Frag load aborted, resetting nextLoadPosition to ${this.nextLoadPosition}`);
return;
}
this.hls.trigger(Event.ERROR, errorData);
});
}

_handleFragmentLoad (frag, payload, stats) {}
_handleFragmentLoadComplete (frag, stats) {
const transmuxIdentifier = { level: frag.level, sn: frag.sn };
this.transmuxer.flush(transmuxIdentifier);
}
}
1 change: 1 addition & 0 deletions src/controller/buffer-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class BufferController extends EventHandler {
Events.BUFFER_FLUSHING,
Events.LEVEL_PTS_UPDATED,
Events.LEVEL_UPDATED);
this.hls = hls;
}

destroy () {
Expand Down
12 changes: 8 additions & 4 deletions src/controller/level-helper.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
/**
* @module LevelHelper
*
* Providing methods dealing with playlist sliding and drift
*
* TODO: Create an actual `Level` class/model that deals with all this logic in an object-oriented-manner.
*
* */

import { logger } from '../utils/logger';
Expand Down Expand Up @@ -227,3 +223,11 @@ export function computeReloadInterval (currentPlaylist, newPlaylist, lastRequest
// in any case, don't reload more than half of target duration
return Math.round(reloadInterval);
}

export function getFragmentWithSN (level, sn) {
if (!level || !level.details) {
return null;
}
const levelDetails = level.details;
return levelDetails.fragments[sn - levelDetails.startSN];
}

0 comments on commit 6836ef3

Please sign in to comment.