Skip to content

Commit

Permalink
Merge pull request #1116 from AkamaiDASH/development
Browse files Browse the repository at this point in the history
Fix for #1088 and Fix for #1115
  • Loading branch information
Dan Sparacio authored and Dan Sparacio committed Feb 3, 2016
2 parents 90f5948 + d24e547 commit 343d95b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 43 deletions.
2 changes: 1 addition & 1 deletion src/dash/controllers/RepresentationController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 0 additions & 4 deletions src/streaming/MediaPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -97,7 +96,6 @@ function MediaPlayer() {
protectionController,
metricsReportingController,
adapter,
domStorage,
metricsModel,
mediaPlayerModel,
errHandler,
Expand Down Expand Up @@ -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()});

Expand Down Expand Up @@ -183,7 +180,6 @@ function MediaPlayer() {
playbackInitialized = true;
log('Playback Initialized');
createControllers();
domStorage.checkInitialBitrate();
if (typeof source === 'string') {
streamController.load(source);
} else {
Expand Down
20 changes: 12 additions & 8 deletions src/streaming/controllers/AbrController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -69,7 +70,8 @@ function AbrController() {
manifestModel,
manifestExt,
videoModel,
mediaPlayerModel;
mediaPlayerModel,
domStorage;

function setup() {
autoSwitchBitrate = {video: true, audio: true};
Expand All @@ -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();
Expand Down Expand Up @@ -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;

Expand All @@ -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];
}

/**
Expand Down
48 changes: 18 additions & 30 deletions src/streaming/utils/DOMStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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
Expand Down Expand Up @@ -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
};
Expand Down

0 comments on commit 343d95b

Please sign in to comment.