Skip to content

Commit

Permalink
revert maxSeekHole
Browse files Browse the repository at this point in the history
refactor mediaChannels to elementaryStreams
  • Loading branch information
davidkim9 committed Jan 9, 2018
1 parent e4f1fcf commit 53876ed
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 27 deletions.
1 change: 1 addition & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export var hlsDefaultConfig = {
maxBufferLength: 30, // used by stream-controller
maxBufferSize: 60 * 1000 * 1000, // used by stream-controller
maxBufferHole: 0.5, // used by stream-controller
maxSeekHole: 2, // used by stream-controller
lowBufferWatchdogPeriod: 0.5, // used by stream-controller
highBufferWatchdogPeriod: 3, // used by stream-controller
nudgeOffset: 0.1, // used by stream-controller
Expand Down
6 changes: 1 addition & 5 deletions src/controller/audio-stream-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -645,11 +645,7 @@ class AudioStreamController extends TaskLoop {
data.endDTS = data.startDTS + fragCurrent.duration;
}

if(!fragCurrent.mediaChannels) {
// Set is used because the elements do not repeat
fragCurrent.mediaChannels = new Set();
}
fragCurrent.mediaChannels.add(data.type);
fragCurrent.elementaryStreams.add(data.type);

logger.log(`parsed ${data.type},PTS:[${data.startPTS.toFixed(3)},${data.endPTS.toFixed(3)}],DTS:[${data.startDTS.toFixed(3)}/${data.endDTS.toFixed(3)}],nb:${data.nb}`);
LevelHelper.updateFragPTSDTS(track.details,fragCurrent,data.startPTS,data.endPTS);
Expand Down
21 changes: 13 additions & 8 deletions src/controller/stream-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -1085,11 +1085,7 @@ class StreamController extends TaskLoop {
data.endDTS = data.startDTS + fragCurrent.duration;
}

if(!frag.mediaChannels) {
// Set is used because the elements do not repeat
frag.mediaChannels = new Set();
}
frag.mediaChannels.add(data.type);
frag.elementaryStreams.add(data.type);

logger.log(`Parsed ${data.type},PTS:[${data.startPTS.toFixed(3)},${data.endPTS.toFixed(3)}],DTS:[${data.startDTS.toFixed(3)}/${data.endDTS.toFixed(3)}],nb:${data.nb},dropped:${data.dropped || 0}`);

Expand Down Expand Up @@ -1365,10 +1361,19 @@ _checkBuffer() {
this.loadedmetadata = true;
// only adjust currentTime if different from startPosition or if startPosition not buffered
// at that stage, there should be only one buffered range, as we reach that code after first fragment has been buffered
let startPosition = media.seeking ? currentTime : this.startPosition;
// if currentTime not matching with expected startPosition
if (currentTime !== startPosition) {
let startPosition = media.seeking ? currentTime : this.startPosition,
startPositionBuffered = BufferHelper.isBuffered(mediaBuffer,startPosition),
firstbufferedPosition = buffered.start(0),
startNotBufferedButClose = !startPositionBuffered && (Math.abs(startPosition-firstbufferedPosition) < config.maxSeekHole);
// if currentTime not matching with expected startPosition or startPosition not buffered but close to first buffered
if (currentTime !== startPosition || startNotBufferedButClose) {
logger.log(`target start position:${startPosition}`);

// if startPosition not buffered, let's seek to buffered.start(0)
if(startNotBufferedButClose) {
startPosition = firstbufferedPosition;
logger.log(`target start position not buffered, seek to buffered.start(0) ${startPosition}`);
}
logger.log(`adjust currentTime from ${currentTime} to ${startPosition}`);
media.currentTime = startPosition;
}
Expand Down
18 changes: 9 additions & 9 deletions src/helper/fragment-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ export class FragmentTracker extends EventHandler {
* Partial fragments effected by coded frame eviction will be removed
* The browser will unload parts of the buffer to free up memory for new buffer data
* Fragments will need to be reloaded when the buffer is freed up, removing partial fragments will allow them to reload(since there might be parts that are still playable)
* @param {String} channel The channel of media this is (eg. video/audio)
* @param {String} elementaryStream The elementaryStream of media this is (eg. video/audio)
* @param {Object} timeRange TimeRange object from a sourceBuffer
*/
detectEvictedFragments(channel, timeRange) {
detectEvictedFragments(elementaryStream, timeRange) {
let fragmentTimes, time;
// Check if any flagged fragments have been unloaded
for (let fragmentEntity of this.fragments.values()) {
if(fragmentEntity.buffered === true) {
fragmentTimes = fragmentEntity.range[channel].time;
fragmentTimes = fragmentEntity.range[elementaryStream].time;
for (let i = 0; i < fragmentTimes.length; i++) {
time = fragmentTimes[i];

Expand All @@ -68,11 +68,11 @@ export class FragmentTracker extends EventHandler {
let fragKey = this.getFragmentKey(fragment);
let fragmentEntity = this.fragments.get(fragKey);
fragmentEntity.buffered = true;
for (let [channel, timeRange] of this.timeRanges) {
if(fragment.mediaChannels.has(channel) === true) {
for (let [elementaryStream, timeRange] of this.timeRanges) {
if(fragment.elementaryStreams.has(elementaryStream) === true) {
// Check for malformed fragments
// Gaps need to be calculated for each channel
fragmentEntity.range[channel] = this.getBufferedTimes(fragment.startPTS, fragment.endPTS, timeRange);
// Gaps need to be calculated for each elementaryStream
fragmentEntity.range[elementaryStream] = this.getBufferedTimes(fragment.startPTS, fragment.endPTS, timeRange);
}
}
}
Expand Down Expand Up @@ -207,8 +207,8 @@ export class FragmentTracker extends EventHandler {
onBufferAppended(e) {
// Store the latest timeRanges loaded in the buffer
this.timeRanges = e.timeRanges;
for (let [channel, timeRange] of this.timeRanges) {
this.detectEvictedFragments(channel, timeRange);
for (let [elementaryStream, timeRange] of this.timeRanges) {
this.detectEvictedFragments(elementaryStream, timeRange);
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/loader/fragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export default class Fragment {
this._byteRange = null;
this._decryptdata = null;
this.tagList = [];

// Set is used because the elements do not repeat
this.elementaryStreams = new Set();
}

get url() {
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/helper/fragment-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('FragmentTracker', () => {
endPTS: 1,
sn: 1,
level: 1,
mediaChannels: new Set(['audio', 'video']),
elementaryStreams: new Set(['audio', 'video']),
type: 'main'
};
hls.trigger(Event.FRAG_LOADED, { frag: fragment });
Expand Down Expand Up @@ -72,7 +72,7 @@ describe('FragmentTracker', () => {
endPTS: 1,
sn: 1,
level: 0,
mediaChannels: new Set(['audio', 'video']),
elementaryStreams: new Set(['audio', 'video']),
type: 'main'
};
hls.trigger(Event.FRAG_LOADED, { frag: fragment });
Expand Down Expand Up @@ -165,7 +165,7 @@ describe('FragmentTracker', () => {
endPTS: 1,
sn: 1,
level: 1,
mediaChannels: new Set(['audio', 'video']),
elementaryStreams: new Set(['audio', 'video']),
type: 'main'
};
hls.trigger(Event.FRAG_LOADED, { frag: fragment });
Expand Down Expand Up @@ -196,7 +196,7 @@ describe('FragmentTracker', () => {
endPTS: 1,
sn: 1,
level: 1,
mediaChannels: new Set(['audio', 'video']),
elementaryStreams: new Set(['audio', 'video']),
type: 'main'
};
hls.trigger(Event.FRAG_LOADED, { frag: fragment });
Expand Down Expand Up @@ -227,7 +227,7 @@ describe('FragmentTracker', () => {
endPTS: 1,
sn: 1,
level: 1,
mediaChannels: new Set(['audio']),
elementaryStreams: new Set(['audio']),
type: 'audio'
};
hls.trigger(Event.FRAG_LOADED, { frag: fragment });
Expand Down

0 comments on commit 53876ed

Please sign in to comment.