Skip to content

Commit

Permalink
Remove settings methods from MediaPlayer
Browse files Browse the repository at this point in the history
  • Loading branch information
jeoliva committed Mar 14, 2019
1 parent 78e482c commit ba6d344
Show file tree
Hide file tree
Showing 29 changed files with 514 additions and 1,878 deletions.
23 changes: 19 additions & 4 deletions contrib/akamai/controlbar/ControlBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,11 @@ var ControlBar = function (dashjsMediaPlayer, displayUTCTimeCodes) {
return idx;

} else if (menuType === "bitrate") {
return player.getAutoSwitchQualityFor(mediaType) ? 0 : player.getQualityFor(mediaType);
var cfg = player.getSettings();
if (cfg.streaming && cfg.streaming.abr && cfg.streaming.abr.initialBitrate) {
return cfg.streaming.abr.initialBitrate['mediaType'] | 0;
}
return 0;
} else if (menuType === "caption") {
var idx = player.getCurrentTextTrackIndex() + 1;

Expand Down Expand Up @@ -697,13 +701,24 @@ var ControlBar = function (dashjsMediaPlayer, displayUTCTimeCodes) {
switch (self.name) {
case 'video-bitrate-list':
case 'audio-bitrate-list':
var cfg = {
'streaming': {
'abr': {
'autoSwitchBitrate': {
}
}
}
};
if (self.index > 0) {
if (player.getAutoSwitchQualityFor(self.mediaType)) {
player.setAutoSwitchQualityFor(self.mediaType, false);
var cfg = player.getSettings();
if (cfg && cfg.streaming && cfg.streaming.abr && cfg.streaming.abr.initialBitrate && cfg.streaming.abr.autoSwitchBitrate[self.mediaType]) {
cfg.streaming.abr.autoSwitchBitrate[self.mediaType] = true;
player.updateSettings(cfg);
}
player.setQualityFor(self.mediaType, self.index - 1);
} else {
player.setAutoSwitchQualityFor(self.mediaType, true);
cfg.streaming.abr.autoSwitchBitrate[self.mediaType] = true;
player.updateSettings(cfg);
}
break;
case 'caption-list' :
Expand Down
169 changes: 99 additions & 70 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,103 @@ declare namespace dashjs {
contentProtection: any | null;
}

export class MediaPlayerSettingClass {
debug: {
logLevel: LogLevel;
};
streaming: {
metricsMaxListDepth: number;
abandonLoadTimeout: number;
liveDelayFragmentCount: number;
liveDelay: number;
scheduleWhilePaused: boolean;
fastSwitchEnabled: boolean;
bufferPruningInterval: number;
bufferToKeep: number;
bufferAheadToKeep: number;
jumpGaps: boolean;
smallGapLimit: number;
stableBufferTime: number;
bufferTimeAtTopQuality: number;
bufferTimeAtTopQualityLongForm: number;
longFormContentDurationThreshold: number;
wallclockTimeUpdateInterval: number;
lowLatencyEnabled: boolean;
keepProtectionMediaKeys: boolean;
useManifestDateHeaderTimeSource: boolean;
segmentOverlapToleranceTime: number;
useSuggestedPresentationDelay: boolean;
manifestUpdateRetryInterval: number;
liveCatchUpMinDrift: number;
liveCatchUpMaxDrift: number;
liveCatchUpPlaybackRate: number;
lastBitrateCachingInfo: {
enabled: boolean;
ttl: number;
};
lastMediaSettingsCachingInfo: {
enabled: boolean;
ttl: number;
};
cacheLoadThresholds: {
video: number;
audio: number;
};
retryIntervals: {
'MPD': number;
'XLinkExpansion': number;
'MediaSegment': number;
'InitializationSegment': number;
'BitstreamSwitchingSegment': number;
'IndexSegment': number;
'other': number;
};
retryAttempts: {
'MPD': number;
'XLinkExpansion': number;
'MediaSegment': number;
'InitializationSegment': number;
'BitstreamSwitchingSegment': number;
'IndexSegment': number;
'other': number;
};
abr: {
movingAverageMethod: 'slidingWindow' | 'ewma';
ABRStrategy: 'abrDynamic' | 'abrBola';
bandwidthSafetyFactor: number;
useDefaultABRRules: boolean;
useBufferOccupancyABR: boolean;
useDeadTimeLatency: boolean;
limitBitrateByPortal: boolean;
usePixelRatioInLimitBitrateByPortal: boolean;
maxBitrate: {
audio: number;
video: number;
};
minBitrate: {
audio: number;
video: number;
};
maxRepresentationRatio: {
audio: number;
video: number;
};
initialBitrate: {
audio: number;
video: number;
};
initialRepresentationRatio: {
audio: number;
video: number;
};
autoSwitchBitrate: {
audio: boolean;
video: boolean;
};
}
}
}

export interface MediaPlayerClass {
initialize(view?: HTMLElement, source?: string, autoPlay?: boolean): void;
on(type: AstInFutureEvent['type'], listener: (e: AstInFutureEvent) => void, scope?: object): void;
Expand Down Expand Up @@ -149,32 +246,14 @@ declare namespace dashjs {
getTTMLRenderingDiv(): HTMLDivElement | null;
getVideoElement(): HTMLVideoElement;
getSource(): string | object;
setLiveDelayFragmentCount(value: number): void;
setLiveDelay(value: number): void;
getLiveDelay(): number | undefined;
useSuggestedPresentationDelay(value: boolean): void;
enableLastBitrateCaching(enable: boolean, ttl?: number): void;
enableLastMediaSettingsCaching(enable: boolean, ttl?: number): void;
setMaxAllowedBitrateFor(type: 'video' | 'audio', value: number): void;
getMaxAllowedBitrateFor(type: 'video' | 'audio'): number;
getTopBitrateInfoFor(type: 'video' | 'audio'): BitrateInfo;
setMinAllowedBitrateFor(type: 'video' | 'audio', value: number): void;
getMinAllowedBitrateFor(type: 'video' | 'audio'): number;
setMaxAllowedRepresentationRatioFor(type: 'video' | 'audio', value: number): void;
getMaxAllowedRepresentationRatioFor(type: 'video' | 'audio'): number;
setAutoPlay(value: boolean): void;
getAutoPlay(): boolean;
setScheduleWhilePaused(value: boolean): void;
getScheduleWhilePaused(): boolean;
getDashMetrics(): DashMetrics;
getMetricsFor(type: 'video' | 'audio' | 'text' | 'stream'): MetricsList | null;
getQualityFor(type: 'video' | 'audio' | 'image'): number;
setQualityFor(type: 'video' | 'audio' | 'image', value: number): void;
updatePortalSize(): void;
getLimitBitrateByPortal(): any;
setLimitBitrateByPortal(value: boolean): void;
getUsePixelRatioInLimitBitrateByPortal(): any;
setUsePixelRatioInLimitBitrateByPortal(value: boolean): void;
enableText(enable: boolean): void;
setTextTrack(idx: number): void;
getTextDefaultLanguage(): string | undefined;
Expand All @@ -183,10 +262,6 @@ declare namespace dashjs {
setTextDefaultEnabled(enable: boolean): void;
getThumbnail(time: number): Thumbnail;
getBitrateInfoListFor(type: 'video' | 'audio' | 'image'): BitrateInfo[];
setInitialBitrateFor(type: 'video' | 'audio', value: number): void;
getInitialBitrateFor(type: 'video' | 'audio'): number;
setInitialRepresentationRatioFor(type: 'video' | 'audio', value: number): void;
getInitialRepresentationRatioFor(type: 'video' | 'audio'): number;
getStreamsFromManifest(manifest: object): StreamInfo[];
getTracksFor(type: 'video' | 'audio' | 'text' | 'fragmentedText'): MediaInfo[];
getTracksForTypeFromManifest(type: 'video' | 'audio' | 'text' | 'fragmentedText', manifest: object, streamInfo: StreamInfo): MediaInfo[];
Expand All @@ -198,78 +273,32 @@ declare namespace dashjs {
setTrackSwitchModeFor(type: 'video' | 'audio', mode: TrackSwitchMode): void;
setSelectionModeForInitialTrack(mode: TrackSelectionMode): void;
getSelectionModeForInitialTrack(): TrackSelectionMode;
getAutoSwitchQuality(): boolean;
setAutoSwitchQuality(value: boolean): void;
setFastSwitchEnabled(value: boolean): void;
getFastSwitchEnabled(): boolean;
getAutoSwitchQualityFor(type: 'video' | 'audio'): boolean;
setAutoSwitchQualityFor(type: 'video' | 'audio', value: boolean): void;
enableBufferOccupancyABR(value: boolean): void;
setBandwidthSafetyFactor(value: number): void;
getBandwidthSafetyFactor(): number;
setAbandonLoadTimeout(value: number): void;
retrieveManifest(url: string, callback: (manifest: object | null, error: any) => void): void;
addUTCTimingSource(schemeIdUri: string, value: string): void;
removeUTCTimingSource(schemeIdUri: string, value: string): void;
clearDefaultUTCTimingSources(): void;
restoreDefaultUTCTimingSources(): void;
setBufferToKeep(value: number): void;
setBufferPruningInterval(value: number): void;
setStableBufferTime(value: number): void;
setBufferTimeAtTopQuality(value: number): void;
setFragmentLoaderRetryAttempts(value: number): void;
setFragmentLoaderRetryInterval(value: number): void;
setXHRWithCredentialsForType(type: string, value: boolean): void;
getXHRWithCredentialsForType(type: string): boolean;
setBufferTimeAtTopQualityLongForm(value: number): void;
setLongFormContentDurationThreshold(value: number): void;
setCacheLoadThresholdForType(type: 'video' | 'audio', value: number): void;
getProtectionController(): ProtectionController;
attachProtectionController(value: ProtectionController): void;
setProtectionData(value: ProtectionData): void;
enableManifestDateHeaderTimeSource(value: boolean): void;
displayCaptionsOnTop(value: boolean): void;
attachTTMLRenderingDiv(div: HTMLDivElement): void;
getCurrentTextTrackIndex(): number;
setJumpGaps(value: boolean): void;
getJumpGaps(): boolean;
setSmallGapLimit(value: number): void;
getSmallGapLimit(): number;
preload(): void;
reset(): void;
addABRCustomRule(type: string, rulename: string, rule: object): void;
removeABRCustomRule(rulename: string): void;
removeAllABRCustomRule(): void;
getLowLatencyEnabled(): boolean;
setLowLatencyEnabled(value: boolean): void;
enableLowLatencyCatchUp(value: boolean): void;
getLowLatencyMinDrift(): number;
setLowLatencyMinDrift(value: number): void;
getLowLatencyMaxDriftBeforeSeeking(): number;
setLowLatencyMaxDriftBeforeSeeking(value: number): void;
getUseDeadTimeLatencyForAbr(): boolean;
setUseDeadTimeLatencyForAbr(value: boolean): void;
getCurrentLiveLatency(): number;
enableForcedTextStreaming(value: boolean): void;
isTextEnabled(): boolean;
getBufferTimeAtTopQualityLongForm(): number;
setMovingAverageMethod(value: string): void;
getMovingAverageMethod(): string;
setABRStrategy(value: string): void;
getABRStrategy(): string;
useDefaultABRRules(value: boolean): void;
getAverageThroughput(value: number): void;
setBufferAheadToKeep(value: number): void;
getStableBufferTime(): number;
getBufferTimeAtTopQuality(): number;
setManifestLoaderRetryAttempts(value: number): void;
setManifestLoaderRetryInterval(value: number): void;
setManifestUpdateRetryInterval(value: number): void;
getManifestUpdateRetryInterval(): number;
setSegmentOverlapToleranceTime(value: number): void;
keepProtectionMediaKeys(value: boolean): void;
getSettings(): object;
updateSettings(settingsObj: object);
getSettings(): MediaPlayerSettingClass;
updateSettings(settings: MediaPlayerSettingClass);
resetSettings(): void;
}

Expand Down
8 changes: 7 additions & 1 deletion samples/advanced/abr/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@
player = dashjs.MediaPlayer().create();

// don't use dash.js default rules
player.useDefaultABRRules(false);
player.updateSettings({
'streaming': {
'abr': {
'useDefaultABRRules': false
}
}
});

// add my custom quality switch rule. Look at LowestBitrateRule.js to know more
// about the structure of a custom rule
Expand Down
2 changes: 1 addition & 1 deletion samples/advanced/listening-to-SCTE-EMSG-events.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

function init() {
player = dashjs.MediaPlayer().create();
player.getDebug().setLogToBrowserConsole(false);
player.updateSettings({ 'debug': { 'logLevel': dashjs.Debug.LOG_LEVEL_NONE }});
player.on(SCHEMEIDURI, showEvent);
player.initialize(document.querySelector("video"), URL, true);
}
Expand Down
5 changes: 2 additions & 3 deletions samples/advanced/monitoring.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
video = document.querySelector("video");
player = dashjs.MediaPlayer().create();
player.initialize(video, url, true);
player.getDebug().setLogToBrowserConsole(false);
player.on(dashjs.MediaPlayer.events["PLAYBACK_ENDED"], function() {
clearInterval(eventPoller);
clearInterval(bitrateCalculator);
Expand All @@ -33,8 +32,8 @@

if (dashMetrics && streamInfo) {
const periodIdx = streamInfo.index;
var repSwitch = dashMetrics.getCurrentRepresentationSwitch(metrics);
var bufferLevel = dashMetrics.getCurrentBufferLevel(metrics);
var repSwitch = dashMetrics.getCurrentRepresentationSwitch('video', true);
var bufferLevel = dashMetrics.getCurrentBufferLevel('video', true);
var bitrate = repSwitch ? Math.round(dashAdapter.getBandwidthForRepresentation(repSwitch.to, periodIdx) / 1000) : NaN;
document.getElementById('bufferLevel').innerText = bufferLevel + " secs";
document.getElementById('reportedBitrate').innerText = bitrate + " Kbps";
Expand Down
6 changes: 5 additions & 1 deletion samples/control/logging.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
player = dashjs.MediaPlayer().create();
player.initialize(video, url, true);
// Can be LOG_LEVEL_NONE, LOG_LEVEL_FATAL, LOG_LEVEL_ERROR, LOG_LEVEL_WARNING, LOG_LEVEL_INFO or LOG_LEVEL_DEBUG
player.getDebug().setLogLevel(dashjs.Debug.LOG_LEVEL_INFO);
player.updateSettings({
'debug': {
'logLevel': dashjs.Debug.LOG_LEVEL_INFO
}
});
}
</script>

Expand Down
Loading

0 comments on commit ba6d344

Please sign in to comment.