Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/controller/audio-stream-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,9 @@ class AudioStreamController
const fragPlaying = this.fragPlaying;
const fragPreviousLevel = previousFrag?.level;
if (!fragPlaying || fragPlaying.level !== fragPreviousLevel) {
this.cleanupBackBuffer();
if (previousFrag) {
this.cleanupBackBuffer();
}
if (this.switchingTrack) {
this.completeAudioSwitch(this.switchingTrack);
}
Expand Down
4 changes: 2 additions & 2 deletions src/controller/stream-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,10 @@ export default class StreamController
}

const fragPlaying = this.fragPlaying;
if (fragPlaying && previousFrag) {
if (fragPlaying) {
const fragCurrentLevel = fragPlaying.level;
this.hls.trigger(Events.FRAG_CHANGED, { frag: fragPlaying });
if (previousFrag.level !== fragCurrentLevel) {
if (previousFrag?.level !== fragCurrentLevel) {
this.hls.trigger(Events.LEVEL_SWITCHED, {
level: fragCurrentLevel,
});
Expand Down
67 changes: 42 additions & 25 deletions tests/functional/auto/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,20 +122,25 @@ async function testIdleBufferLength(url, config) {
const bufferEnd = buffered.end(buffered.length - 1);
const duration = video.duration;
const durationOffsetTolerance = config.avBufferOffset || 1;
const requiredBuffer = Math.min(
maxBufferLength,
duration - durationOffsetTolerance
);
console.log(
'[test] > progress: ' +
bufferEnd.toFixed(2) +
bufferEnd.toFixed(3) +
'/' +
duration.toFixed(2) +
requiredBuffer.toFixed(3) +
' buffered.length: ' +
buffered.length +
' allowed duration offset ' +
durationOffsetTolerance
' allowed duration offset: ' +
durationOffsetTolerance +
' duration: ' +
duration.toFixed(3)
);
if (
bufferEnd >= maxBufferLength ||
bufferEnd > duration - durationOffsetTolerance
) {
if (bufferEnd >= requiredBuffer) {
video.onprogress = null;
console.log('[test] > passed (exec callback)');
callback({ code: 'loadeddata', logs: self.logString });
}
}
Expand All @@ -157,14 +162,21 @@ async function testSmoothSwitch(url, config) {
self.startStream(url, startConfig, callback);
self.hls.manualLevel = 0;
const video = self.video;
let playedInterval = -1;
self.hls.once(self.Hls.Events.FRAG_CHANGED, function (eventName, data) {
console.log(
'[test] > ' + eventName + ' frag.level: ' + data.frag.level
'[test] > ' +
eventName +
' frag.level: ' +
data.frag.level +
' @' +
video.currentTime
);
const highestLevel = self.hls.levels.length - 1;
const level = self.hls.levels[data.frag.level];
const fragmentCount = level.details.fragments.length;
if (highestLevel === 0 || fragmentCount === 1) {
self.clearInterval(playedInterval);
callback({
highestLevel: highestLevel,
currentTimeDelta: 1, // pass the test by assigning currentTimeDelta > 0
Expand All @@ -181,18 +193,21 @@ async function testSmoothSwitch(url, config) {
const currentTime = video.currentTime;
const highestLevel = self.hls.levels.length - 1;
if (data.level === highestLevel) {
self.setTimeout(function () {
self.clearInterval(playedInterval);
playedInterval = self.setInterval(function () {
const newCurrentTime = video.currentTime;
const paused = video.paused;
console.log(
'[test] > currentTime delta: ' + (newCurrentTime - currentTime)
);
callback({
highestLevel: highestLevel,
currentTimeDelta: newCurrentTime - currentTime,
paused: paused,
logs: self.logString,
});
const currentTimeDelta = newCurrentTime - currentTime;
console.log('[test] > currentTime delta: ' + currentTimeDelta);
if (currentTimeDelta > 0) {
const paused = video.paused;
self.clearInterval(playedInterval);
callback({
highestLevel: highestLevel,
currentTimeDelta: currentTimeDelta,
paused: paused,
logs: self.logString,
});
}
}, 2000);
}
});
Expand Down Expand Up @@ -257,6 +272,7 @@ async function testSeekOnVOD(url, config) {
self.setTimeout(function () {
const duration = video.duration;
if (!isFinite(duration)) {
video.onprogress = null;
callback({
code: 'non-finite-duration',
duration: duration,
Expand All @@ -272,6 +288,7 @@ async function testSeekOnVOD(url, config) {
const currentTime = video.currentTime;
const paused = video.paused;
if (video.currentTime === 0 || paused) {
video.onprogress = null;
callback({
code: 'paused',
currentTime: currentTime,
Expand All @@ -291,6 +308,7 @@ async function testSeekOnVOD(url, config) {
);
video.currentTime = seekToTime;
seekingTimeout = self.setTimeout(function () {
video.onprogress = null;
const currentTime = video.currentTime;
const duration = video.duration;
const paused = video.paused;
Expand All @@ -310,10 +328,7 @@ async function testSeekOnVOD(url, config) {
});

console.log(
'[test] > Timed out while seeking ' +
video.currentTime +
' to ' +
seekToTime
'[test] > Timed out while seeking ' + video.currentTime
);

callback({
Expand All @@ -332,6 +347,7 @@ async function testSeekOnVOD(url, config) {
const allowedBufferedRanges = config.allowedBufferedRangesInSeekTest || 2;
video.onprogress = function () {
if (video.buffered.length > allowedBufferedRanges) {
video.onprogress = null;
const duration = video.duration;
callback({
code: 'buffer-gaps',
Expand All @@ -342,6 +358,7 @@ async function testSeekOnVOD(url, config) {
}
};
self.hls.on(self.Hls.Events.MEDIA_ENDED, function (eventName, data) {
video.onprogress = null;
console.log(
'[test] > video "ended"' + data.stalled ? ' (stalled near end)' : ''
);
Expand Down Expand Up @@ -721,7 +738,7 @@ ${data.logs}

if (stream.abr) {
it(
`should "smooth switch" to highest level and still play after 2s`,
`should "smooth switch" to highest level with playback advancing`,
testSmoothSwitch.bind(null, url, config)
);
}
Expand Down
Loading