Skip to content

Commit

Permalink
[DRAFT] API enhancements for audio and subtitle track selection
Browse files Browse the repository at this point in the history
Resolves #5532
  • Loading branch information
robwalch committed Oct 13, 2023
1 parent 470a29f commit cb9e845
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
7 changes: 6 additions & 1 deletion api-extractor/report/hls.js.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1625,6 +1625,10 @@ class Hls implements HlsEventEmitter {
// (undocumented)
removeLevel(levelIndex: any, urlId?: number): void;
resumeBuffering(): void;
// Warning: (ae-forgotten-export) The symbol "AudioSelectionOption" needs to be exported by the entry point hls.d.ts
setAudioOption(audioOption: MediaPlaylist | AudioSelectionOption): MediaPlaylist | null;
// Warning: (ae-forgotten-export) The symbol "SubtitleSelectionOption" needs to be exported by the entry point hls.d.ts
setSubtitleOption(audioOption: MediaPlaylist | SubtitleSelectionOption): MediaPlaylist | null;
get startLevel(): number;
// Warning: (ae-setter-with-docs) The doc comment for the property "startLevel" must appear on the getter, not the setter.
set startLevel(newLevel: number);
Expand Down Expand Up @@ -1657,6 +1661,7 @@ export interface HlsChunkPerformanceTiming extends HlsPerformanceTiming {
executeStart: number;
}

// Warning: (ae-forgotten-export) The symbol "SelectionPreferences" needs to be exported by the entry point hls.d.ts
// Warning: (ae-missing-release-tag) "HlsConfig" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
Expand Down Expand Up @@ -1692,7 +1697,7 @@ export type HlsConfig = {
fpsController: typeof FPSController;
progressive: boolean;
lowLatencyMode: boolean;
} & ABRControllerConfig & BufferControllerConfig & CapLevelControllerConfig & EMEControllerConfig & FPSControllerConfig & LevelControllerConfig & MP4RemuxerConfig & StreamControllerConfig & LatencyControllerConfig & MetadataControllerConfig & TimelineControllerConfig & TSDemuxerConfig & HlsLoadPolicies & FragmentLoaderConfig & PlaylistLoaderConfig;
} & ABRControllerConfig & BufferControllerConfig & CapLevelControllerConfig & EMEControllerConfig & FPSControllerConfig & LevelControllerConfig & MP4RemuxerConfig & StreamControllerConfig & SelectionPreferences & LatencyControllerConfig & MetadataControllerConfig & TimelineControllerConfig & TSDemuxerConfig & HlsLoadPolicies & FragmentLoaderConfig & PlaylistLoaderConfig;

// Warning: (ae-missing-release-tag) "HlsEventEmitter" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
Expand Down
10 changes: 10 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ import type {
LoaderResponse,
PlaylistLoaderContext,
} from './types/loader';
import type {
AudioSelectionOption,
SubtitleSelectionOption,
} from './types/media-playlist';

export type ABRControllerConfig = {
abrEwmaFastLive: number;
Expand Down Expand Up @@ -217,6 +221,11 @@ export type StreamControllerConfig = {
testBandwidth: boolean;
};

export type SelectionPreferences = {
audioPreference?: AudioSelectionOption;
subtitlePreference?: SubtitleSelectionOption;
};

export type LatencyControllerConfig = {
liveSyncDurationCount: number;
liveMaxLatencyDurationCount: number;
Expand Down Expand Up @@ -298,6 +307,7 @@ export type HlsConfig = {
LevelControllerConfig &
MP4RemuxerConfig &
StreamControllerConfig &
SelectionPreferences &
LatencyControllerConfig &
MetadataControllerConfig &
TimelineControllerConfig &
Expand Down
25 changes: 24 additions & 1 deletion src/hls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ import type CMCDController from './controller/cmcd-controller';
import type EMEController from './controller/eme-controller';
import type SubtitleTrackController from './controller/subtitle-track-controller';
import type { ComponentAPI, NetworkComponentAPI } from './types/component-api';
import type { MediaPlaylist } from './types/media-playlist';
import type {
AudioSelectionOption,
MediaPlaylist,
SubtitleSelectionOption,
} from './types/media-playlist';
import type { HlsConfig } from './config';
import type { BufferInfo } from './utils/buffer-helper';
import type AudioStreamController from './controller/audio-stream-controller';
Expand Down Expand Up @@ -771,6 +775,25 @@ export default class Hls implements HlsEventEmitter {
return this.streamController.getMainFwdBufferInfo();
}

/**
* Find and select the best matching audio track, making a level switch when a Group change is necessary.
* Returns the selected track, or null when no matching track could be found.
*/
public setAudioOption(
audioOption: MediaPlaylist | AudioSelectionOption,
): MediaPlaylist | null {
return null;
}
/**
* Find and select the best matching subtitle track, making a level switch when a Group change is necessary.
* Returns the selected track, or null when no matching track could be found.
*/
public setSubtitleOption(
audioOption: MediaPlaylist | SubtitleSelectionOption,
): MediaPlaylist | null {
return null;
}

/**
* Get the complete list of audio tracks across all media groups
*/
Expand Down
16 changes: 16 additions & 0 deletions src/types/media-playlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,22 @@ export type SubtitlePlaylistType = 'SUBTITLES' | 'CLOSED-CAPTIONS';

export type MediaPlaylistType = MainPlaylistType | SubtitlePlaylistType;

export type AudioSelectionOption = {
lang?: string;
characteristics?: string;
channels?: string;
name?: string;
audioCodec?: string;
groupId?: string;
};

export type SubtitleSelectionOption = {
lang?: string;
characteristics?: string;
name?: string;
groupId?: string;
};

// audioTracks, captions and subtitles returned by `M3U8Parser.parseMasterPlaylistMedia`
export interface MediaPlaylist extends Omit<LevelParsed, 'attrs'> {
attrs: MediaAttributes;
Expand Down

0 comments on commit cb9e845

Please sign in to comment.