diff --git a/src/dash/controllers/RepresentationController.js b/src/dash/controllers/RepresentationController.js index 866c51e19f..59894b8dac 100644 --- a/src/dash/controllers/RepresentationController.js +++ b/src/dash/controllers/RepresentationController.js @@ -155,7 +155,7 @@ function RepresentationController() { availableRepresentations = updateRepresentations(adaptation); - if (data === null) { + if (data === null && type !== 'fragmentedText') { averageThroughput = abrController.getAverageThroughput(type); bitrate = averageThroughput || abrController.getInitialBitrateFor(type, streamInfo); quality = abrController.getQualityForBitrate(streamProcessor.getMediaInfo(), bitrate); diff --git a/src/streaming/MediaPlayer.js b/src/streaming/MediaPlayer.js index bd103080f1..ce7e4818db 100644 --- a/src/streaming/MediaPlayer.js +++ b/src/streaming/MediaPlayer.js @@ -36,7 +36,6 @@ import ManifestLoader from './ManifestLoader.js'; import LiveEdgeFinder from './LiveEdgeFinder.js'; import ErrorHandler from './ErrorHandler.js'; import Capabilities from './utils/Capabilities.js'; -import DOMStorage from './utils/DOMStorage.js'; import TextTrackExtensions from './extensions/TextTrackExtensions.js'; import SourceBufferExtensions from './extensions/SourceBufferExtensions.js'; import VirtualBuffer from './utils/VirtualBuffer.js'; @@ -97,7 +96,6 @@ function MediaPlayer() { protectionController, metricsReportingController, adapter, - domStorage, metricsModel, mediaPlayerModel, errHandler, @@ -140,7 +138,6 @@ function MediaPlayer() { mediaController.initialize(); manifestExt = DashManifestExtensions(context).getInstance(); metricsExt = DashMetricsExtensions(context).getInstance(); - domStorage = DOMStorage(context).getInstance(); metricsModel = MetricsModel(context).getInstance(); metricsModel.setConfig({adapter: createAdaptor()}); @@ -183,7 +180,6 @@ function MediaPlayer() { playbackInitialized = true; log('Playback Initialized'); createControllers(); - domStorage.checkInitialBitrate(); if (typeof source === 'string') { streamController.load(source); } else { diff --git a/src/streaming/controllers/AbrController.js b/src/streaming/controllers/AbrController.js index 207263ca8d..9e0b0c22d5 100644 --- a/src/streaming/controllers/AbrController.js +++ b/src/streaming/controllers/AbrController.js @@ -31,6 +31,7 @@ import SwitchRequest from '../rules/SwitchRequest'; import BitrateInfo from '../vo/BitrateInfo.js'; +import DOMStorage from '../utils/DOMStorage.js'; import ABRRulesCollection from '../rules/abr/ABRRulesCollection.js'; import MediaPlayerModel from '../models/MediaPlayerModel.js'; import FragmentModel from '../models/FragmentModel.js'; @@ -69,7 +70,8 @@ function AbrController() { manifestModel, manifestExt, videoModel, - mediaPlayerModel; + mediaPlayerModel, + domStorage; function setup() { autoSwitchBitrate = {video: true, audio: true}; @@ -82,6 +84,7 @@ function AbrController() { abandonmentStateDict = {}; streamProcessorDict = {}; limitBitrateByPortal = false; + domStorage = DOMStorage(context).getInstance(); mediaPlayerModel = MediaPlayerModel(context).getInstance(); manifestModel = ManifestModel(context).getInstance(); manifestExt = DashManifestExtensions(context).getInstance(); @@ -129,13 +132,11 @@ function AbrController() { * @memberof AbrController# */ function getInitialBitrateFor(type) { - let initialBitrate; - if (!bitrateDict.hasOwnProperty(type)) { - if (!ratioDict.hasOwnProperty(type)) { - bitrateDict[type] = (type === 'video') ? DEFAULT_VIDEO_BITRATE : DEFAULT_AUDIO_BITRATE; - } else { + let saveBitrate = domStorage.getSavedBitrateSettings(type); + if (!bitrateDict.hasOwnProperty(type)) { + if (ratioDict.hasOwnProperty(type)) { let manifest = manifestModel.getValue(); let representation = manifestExt.getAdaptationForType(manifest, 0, type).Representation; @@ -144,11 +145,14 @@ function AbrController() { } else { bitrateDict[type] = 0; } + } else if (!isNaN(saveBitrate)) { + bitrateDict[type] = saveBitrate; + } else { + bitrateDict[type] = (type === 'video') ? DEFAULT_VIDEO_BITRATE : DEFAULT_AUDIO_BITRATE; } } - initialBitrate = bitrateDict[type]; - return initialBitrate; + return bitrateDict[type]; } /** diff --git a/src/streaming/utils/DOMStorage.js b/src/streaming/utils/DOMStorage.js index 83981f8543..c9387cf21a 100644 --- a/src/streaming/utils/DOMStorage.js +++ b/src/streaming/utils/DOMStorage.js @@ -28,7 +28,6 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -import AbrController from '../controllers/AbrController.js'; import FactoryMaker from '../../core/FactoryMaker.js'; import MediaPlayerModel from '../models/MediaPlayerModel.js'; import Debug from '../../core/Debug.js'; @@ -47,12 +46,10 @@ function DOMStorage() { let instance, supported, - abrController, mediaPlayerModel; function setup() { mediaPlayerModel = MediaPlayerModel(context).getInstance(); - abrController = AbrController(context).getInstance(); } //type can be local, session @@ -109,37 +106,28 @@ function DOMStorage() { return settings; } - function checkInitialBitrate() { - ['video', 'audio'].forEach(function (value) { - //first make sure player has not explicitly set a starting bit rate - if (abrController.getInitialBitrateFor(value) === undefined) { - //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 not, - // it uses the default video and audio value in AbrController - if (isSupported(STORAGE_TYPE_LOCAL) && mediaPlayerModel.getLastBitrateCachingInfo().enabled ) { - var key = value === 'video' ? LOCAL_STORAGE_VIDEO_BITRATE_KEY : LOCAL_STORAGE_AUDIO_BITRATE_KEY; - var obj = JSON.parse(localStorage.getItem(key)) || {}; - var isExpired = (new Date().getTime() - parseInt(obj.timestamp, 10)) >= mediaPlayerModel.getLastBitrateCachingInfo().ttl || false; - var bitrate = parseInt(obj.bitrate, 10); - - if (!isNaN(bitrate) && !isExpired) { - abrController.setInitialBitrateFor(value, bitrate); - log('Last bitrate played for ' + value + ' was ' + bitrate); - } else if (isExpired) { - localStorage.removeItem(key); - } - } - //check again to see if local storage value was set, if not set default value for startup. - if (abrController.getInitialBitrateFor(value) === undefined) { - abrController.setInitialBitrateFor(value, AbrController['DEFAULT_' + value.toUpperCase() + '_BITRATE']); - } + function getSavedBitrateSettings(type) { + 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 (isSupported(STORAGE_TYPE_LOCAL) && mediaPlayerModel.getLastBitrateCachingInfo().enabled ) { + var key = type === 'video' ? LOCAL_STORAGE_VIDEO_BITRATE_KEY : LOCAL_STORAGE_AUDIO_BITRATE_KEY; + var obj = JSON.parse(localStorage.getItem(key)) || {}; + var isExpired = (new Date().getTime() - parseInt(obj.timestamp, 10)) >= mediaPlayerModel.getLastBitrateCachingInfo().ttl || false; + var bitrate = parseInt(obj.bitrate, 10); + + if (!isNaN(bitrate) && !isExpired) { + savedBitrate = bitrate; + log('Last save bitrate for ' + type + ' was ' + bitrate); + } else if (isExpired) { + localStorage.removeItem(key); } - - }, this); + } + return savedBitrate; } instance = { - checkInitialBitrate: checkInitialBitrate, + getSavedBitrateSettings: getSavedBitrateSettings, getSavedMediaSettings: getSavedMediaSettings, isSupported: isSupported };