Skip to content

Commit

Permalink
Log additional information for EOS test (video-dev#5130)
Browse files Browse the repository at this point in the history
  • Loading branch information
robwalch authored Dec 22, 2022
1 parent de0daa0 commit 6dac6ac
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 17 deletions.
16 changes: 8 additions & 8 deletions src/controller/audio-stream-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,25 +306,25 @@ class AudioStreamController
if (bufferInfo === null) {
return;
}
const audioSwitch = this.audioSwitch;

if (!audioSwitch && this._streamEnded(bufferInfo, trackDetails)) {
hls.trigger(Events.BUFFER_EOS, { type: 'audio' });
this.state = State.ENDED;
return;
}

const mainBufferInfo = this.getFwdBufferInfo(
this.videoBuffer ? this.videoBuffer : this.media,
PlaylistLevelType.MAIN
);
const bufferLen = bufferInfo.len;
const maxBufLen = this.getMaxBufferLength(mainBufferInfo?.len);
const audioSwitch = this.audioSwitch;

// if buffer length is less than maxBufLen try to load a new fragment
if (bufferLen >= maxBufLen && !audioSwitch) {
return;
}

if (!audioSwitch && this._streamEnded(bufferInfo, trackDetails)) {
hls.trigger(Events.BUFFER_EOS, { type: 'audio' });
this.state = State.ENDED;
return;
}

const fragments = trackDetails.fragments;
const start = fragments[0].start;
let targetBufferTime = bufferInfo.end;
Expand Down
1 change: 1 addition & 0 deletions src/controller/base-stream-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1403,6 +1403,7 @@ export default class BaseStreamController
}

protected resetLoadingState() {
this.log('Reset loading state');
this.fragCurrent = null;
this.fragPrevious = null;
this.state = State.IDLE;
Expand Down
6 changes: 6 additions & 0 deletions src/controller/buffer-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,14 @@ export default class BufferController implements ComponentAPI {
this.blockBuffers(() => {
const { mediaSource } = this;
if (!mediaSource || mediaSource.readyState !== 'open') {
if (mediaSource) {
logger.warn(
`[buffer-controller]: Could not call mediaSource.endOfStream(). mediaSource.readyState: ${mediaSource.readyState}`
);
}
return;
}
logger.log(`[buffer-controller]: Calling mediaSource.endOfStream()`);
// Allow this to throw and be caught by the enqueueing function
mediaSource.endOfStream();
});
Expand Down
19 changes: 10 additions & 9 deletions src/controller/stream-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,6 @@ export default class StreamController
if (bufferInfo === null) {
return;
}
const bufferLen = bufferInfo.len;

// compute max Buffer Length that we could get from this load level, based on level bitrate. don't buffer more than 60 MB and more than 30s
const maxBufLen = this.getMaxBufferLength(levelInfo.maxBitrate);

// Stay idle if we are still with buffer margins
if (bufferLen >= maxBufLen) {
return;
}

if (this._streamEnded(bufferInfo, levelDetails)) {
const data: BufferEOSData = {};
Expand All @@ -274,6 +265,16 @@ export default class StreamController
return;
}

const bufferLen = bufferInfo.len;

// compute max Buffer Length that we could get from this load level, based on level bitrate. don't buffer more than 60 MB and more than 30s
const maxBufLen = this.getMaxBufferLength(levelInfo.maxBitrate);

// Stay idle if we are still with buffer margins
if (bufferLen >= maxBufLen) {
return;
}

if (
this.backtrackFragment &&
this.backtrackFragment.start > bufferInfo.end
Expand Down
28 changes: 28 additions & 0 deletions tests/functional/auto/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,16 @@ async function testSeekOnVOD(url, config) {
function (url, config) {
const callback = arguments[arguments.length - 1];
self.startStream(url, config, callback);

let tracks;
self.hls.on(self.Hls.Events.BUFFER_CREATED, function (eventName, data) {
tracks = data.tracks;
});
const endOfStreamEvents = [];
self.hls.on(self.Hls.Events.BUFFER_EOS, function (eventName, data) {
endOfStreamEvents.push(data.type || 'main');
});

const video = self.video;
video.ondurationchange = function () {
console.log(
Expand Down Expand Up @@ -277,11 +287,29 @@ async function testSeekOnVOD(url, config) {
video.currentTime = seekToTime;
self.setTimeout(function () {
const currentTime = video.currentTime;
const duration = video.duration;
const paused = video.paused;

const buffers = Object.keys(tracks).map(function (type) {
const sourceBuffer = tracks[type].buffer;
const timeRangeTuples = [];
const buffered = sourceBuffer.buffered;
for (let i = 0; i < buffered.length; i++) {
timeRangeTuples.push(
`${buffered.start(i).toFixed(2)}-${buffered
.end(i)
.toFixed(2)}`
);
}
return `${type}: [${timeRangeTuples.join(', ')}]`;
});

callback({
code: 'timeout-waiting-for-ended-event',
currentTime: currentTime,
duration: duration,
buffers: buffers,
endOfStreamEvents: endOfStreamEvents,
paused: paused,
logs: self.logString,
});
Expand Down

0 comments on commit 6dac6ac

Please sign in to comment.