Skip to content

Conversation

@krseager
Copy link
Collaborator

@krseager krseager commented Oct 13, 2025

This PR will implement smooth audio track switching.

Why is this Pull Request needed?

  • Currently Switching audio tracks causes the Audio Buffer to be flushed immediately upon AUDIO_TRACK_SWITCHING event being fired. This leads to buffering being induced every single time when audio track is switched.
  • The solution now provides a new API for setting the nextAudioTrack, which allows you to utilize existing audio track switching behavior OR to use this new API that automatically schedules the next audio track.

Are there any points in the code the reviewer needs to double check?

  • Ensure API documentation is clear
  • Ensure stream-controller and base-stream-controller refactor does not break anything
  • Ensure new AudioSelectionOption is clear and makes sense

Resolves issues:

  • N/A (Let me know if I need to create an issue for this before merging the PR)

Checklist

  • changes have been done against master branch, and PR does not conflict
  • new unit / functional tests have been added (whenever applicable)
  • API or design changes are documented in API.md

@krseager krseager marked this pull request as ready for review October 20, 2025 15:33
@robwalch robwalch added this to the 1.7.0 milestone Oct 27, 2025
@robwalch robwalch self-requested a review October 27, 2025 22:27
@krseager krseager marked this pull request as draft November 3, 2025 15:59
Kyle Seager added 3 commits November 5, 2025 12:02
# Conflicts:
#	src/controller/stream-controller.ts
…smux complete, which is before buffering the new audio track's audio segment
@krseager krseager marked this pull request as ready for review November 7, 2025 15:18
Comment on lines 35 to 36
nextAudioTrackSwitchingSafetyDelay?: number;
nextAudioTrackBufferFlushDelay?: number;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AudioSelectionOption is intended to describe the preferred audio of the user, not how to get the option or switch between options. AudioSelectionOption should remain limited to a subset of MediaPlaylist attributes and audio characteristic adjacent properties.

If these new options are necessary, then they should be added to HlsConfig with defaults. Since I don't see any defaults, are they even necessary?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just removed nextAudioTrackSwitchingSafetyDelay & renamed nextAudioTrackBufferFlushDelay to nextAudioTrackBufferFlushForwardOffset to be more accurate and put that into HlsConfig with a default value.

) {
const previousFrag = this.fragPlaying;

super.checkFragmentChanged(type);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having audio-stream-controller pass in AUDIO and stream-controller pass in MAIN, you can use this.playlistType in the base checkFragmentChanged method. (I'm assuming that only the fragment type relevant to each controller is ever checked.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

const track = this.switchingTrack;
if (track) {
this.bufferedTrack = track;
this.switchingTrack = null;
Copy link
Collaborator Author

@krseager krseager Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure no issues are encountered from this change with LL-HLS

@krseager
Copy link
Collaborator Author

Add unit tests before aproving/merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

2 participants