Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Use lastBitrateCachingInfo.enabled and lastMediaSettingsCachingInfo.e… #3953

Merged
merged 2 commits into from
Jun 2, 2022
Merged
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
31 changes: 20 additions & 11 deletions src/streaming/utils/DOMStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import Debug from '../../core/Debug';
import Constants from '../constants/Constants';

const legacyKeysAndReplacements = [
{ oldKey: 'dashjs_vbitrate', newKey: 'dashjs_video_bitrate' },
{ oldKey: 'dashjs_abitrate', newKey: 'dashjs_audio_bitrate' },
{ oldKey: 'dashjs_vbitrate', newKey: 'dashjs_video_bitrate' },
{ oldKey: 'dashjs_abitrate', newKey: 'dashjs_audio_bitrate' },
{ oldKey: 'dashjs_vsettings', newKey: 'dashjs_video_settings' },
{ oldKey: 'dashjs_asettings', newKey: 'dashjs_audio_settings' }
];
Expand Down Expand Up @@ -136,9 +136,14 @@ function DOMStorage(config) {
}

function getSavedMediaSettings(type) {
checkConfig();

if (!settings.get().streaming.lastMediaSettingsCachingInfo.enabled) {
return null;
}

let mediaSettings = null;

checkConfig();
//Checks local storage to see if there is valid, non-expired media settings
if (canStore(STORAGE_TYPE_LOCAL, LAST_MEDIA_SETTINGS)) {
const key = LOCAL_STORAGE_SETTINGS_KEY_TEMPLATE.replace(/\?/, type);
Expand All @@ -159,10 +164,14 @@ function DOMStorage(config) {
}

function getSavedBitrateSettings(type) {
let savedBitrate = NaN;

checkConfig();

if (!settings.get().streaming.lastBitrateCachingInfo.enabled) {
return NaN;
}

let savedBitrate = NaN;

//Checks local storage to see if there is valid, non-expired bit rate
//hinting from the last play session to use as a starting bit rate.
if (canStore(STORAGE_TYPE_LOCAL, LAST_BITRATE)) {
Expand All @@ -189,7 +198,7 @@ function DOMStorage(config) {
if (canStore(STORAGE_TYPE_LOCAL, LAST_MEDIA_SETTINGS)) {
const key = LOCAL_STORAGE_SETTINGS_KEY_TEMPLATE.replace(/\?/, type);
try {
localStorage.setItem(key, JSON.stringify({settings: value, timestamp: getTimestamp()}));
localStorage.setItem(key, JSON.stringify({ settings: value, timestamp: getTimestamp() }));
} catch (e) {
logger.error(e.message);
}
Expand All @@ -200,18 +209,18 @@ function DOMStorage(config) {
if (canStore(STORAGE_TYPE_LOCAL, LAST_BITRATE) && bitrate) {
const key = LOCAL_STORAGE_BITRATE_KEY_TEMPLATE.replace(/\?/, type);
try {
localStorage.setItem(key, JSON.stringify({bitrate: bitrate.toFixed(3), timestamp: getTimestamp()}));
localStorage.setItem(key, JSON.stringify({ bitrate: bitrate.toFixed(3), timestamp: getTimestamp() }));
} catch (e) {
logger.error(e.message);
}
}
}

instance = {
getSavedBitrateSettings: getSavedBitrateSettings,
setSavedBitrateSettings: setSavedBitrateSettings,
getSavedMediaSettings: getSavedMediaSettings,
setSavedMediaSettings: setSavedMediaSettings
getSavedBitrateSettings,
setSavedBitrateSettings,
getSavedMediaSettings,
setSavedMediaSettings
};

setup();
Expand Down