Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix loading of audio media options with the same URI as the current level #6887

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 4 additions & 4 deletions src/controller/audio-track-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
findClosestLevelWithAudioGroup,
findMatchingOption,
matchesOption,
useAlternateAudio,
} from '../utils/rendition-helper';
import type Hls from '../hls';
import type {
Expand Down Expand Up @@ -401,11 +402,10 @@ class AudioTrackController extends BasePlaylistController {
if (!this.shouldLoadPlaylist(audioTrack)) {
return;
}
if (audioTrack.url === this.hls.levels[this.hls.loadLevel]?.uri) {
// Do not load audio rendition with URI matching main variant URI
return;
// Do not load audio rendition with URI matching main variant URI
if (useAlternateAudio(audioTrack.url, this.hls)) {
this.scheduleLoading(audioTrack, hlsUrlParameters);
}
this.scheduleLoading(audioTrack, hlsUrlParameters);
}

protected loadingPlaylist(
Expand Down
4 changes: 4 additions & 0 deletions src/controller/interstitials-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,10 @@ MediaSource ${JSON.stringify(attachMediaSourceData)} from ${logFromSource}`,
}

private onLevelUpdated(event: Events.LEVEL_UPDATED, data: LevelUpdatedData) {
if (data.level === -1) {
// level was removed
return;
}
const main = this.hls.levels[data.level];
const currentSelection = {
...(this.mediaSelection || this.altSelection),
Expand Down
8 changes: 4 additions & 4 deletions src/controller/stream-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { PlaylistContextType, PlaylistLevelType } from '../types/loader';
import { ChunkMetadata } from '../types/transmuxer';
import { BufferHelper } from '../utils/buffer-helper';
import { pickMostCompleteCodecName } from '../utils/codecs';
import { useAlternateAudio } from '../utils/rendition-helper';
import type { FragmentTracker } from './fragment-tracker';
import type Hls from '../hls';
import type { Fragment, MediaFragment } from '../loader/fragment';
Expand Down Expand Up @@ -851,9 +852,10 @@ export default class StreamController
event: Events.AUDIO_TRACK_SWITCHING,
data: AudioTrackSwitchingData,
) {
const hls = this.hls;
// if any URL found on new audio track, it is an alternate audio track
const fromAltAudio = this.altAudio === AlternateAudio.SWITCHED;
const altAudio = !!data.url;
const altAudio = useAlternateAudio(data.url, hls);
// if we switch on main audio, ensure that main fragment scheduling is synced with media.buffered
// don't do anything if we switch to alt audio: audio stream controller is handling it.
// we will just have to change buffer scheduling on audioTrackSwitched
Expand All @@ -878,7 +880,6 @@ export default class StreamController
// Reset audio transmuxer so when switching back to main audio we're not still appending where we left off
this.resetTransmuxer();
}
const hls = this.hls;
// If switching from alt to main audio, flush all audio and trigger track switched
if (fromAltAudio) {
hls.trigger(Events.BUFFER_FLUSHING, {
Expand All @@ -898,8 +899,7 @@ export default class StreamController
event: Events.AUDIO_TRACK_SWITCHED,
data: AudioTrackSwitchedData,
) {
const trackId = data.id;
const altAudio = !!this.hls.audioTracks[trackId].url;
const altAudio = useAlternateAudio(data.url, this.hls);
if (altAudio) {
const videoBuffer = this.videoBuffer;
// if we switched on alternate audio, ensure that main fragment scheduling is synced with video sourcebuffer buffered
Expand Down
5 changes: 5 additions & 0 deletions src/utils/rendition-helper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { codecsSetSelectionPreferenceValue } from './codecs';
import { getVideoSelectionOptions } from './hdr';
import { logger } from './logger';
import type Hls from '../hls';
import type { Level, VideoRange } from '../types/level';
import type {
AudioSelectionOption,
Expand Down Expand Up @@ -500,3 +501,7 @@ function searchDownAndUpList(
}
return -1;
}

export function useAlternateAudio(audioTrackUrl: string, hls: Hls): boolean {
return !!audioTrackUrl && audioTrackUrl !== hls.levels[hls.loadLevel]?.uri;
}
Loading