Skip to content

Commit

Permalink
Merge pull request #2447 from MolotovTv/optimizeGetRepresentationsFor…
Browse files Browse the repository at this point in the history
…Adaptation

getRepresentationsForAdaptation optimization
  • Loading branch information
epiclabsDASH committed Apr 16, 2018
2 parents e53f1a2 + 9cddda9 commit b4b0a84
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 30 deletions.
64 changes: 40 additions & 24 deletions src/dash/models/DashManifestModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,27 +396,47 @@ function DashManifestModel(config) {
isInteger(index) ? adaptation.Representation_asArray[index] : null;
}

function getRepresentationsForAdaptation(voAdaptation) {
const voRepresentations = [];
let voRepresentation,
initialization,
segmentInfo,
processedRealAdaptation,
realRepresentation,
i,
s;

function getRealAdaptationFor(voAdaptation) {
if (voAdaptation && voAdaptation.period && isInteger(voAdaptation.period.index)) {
const periodArray = voAdaptation.period.mpd.manifest.Period_asArray[voAdaptation.period.index];
if (periodArray && periodArray.AdaptationSet_asArray && isInteger(voAdaptation.index)) {
processedRealAdaptation = processAdaptation(periodArray.AdaptationSet_asArray[voAdaptation.index]);
return processAdaptation(periodArray.AdaptationSet_asArray[voAdaptation.index]);
}
}
}

function isLastRepeatAttributeValid(segmentTimeline) {
let s = segmentTimeline.S_asArray[segmentTimeline.S_asArray.length - 1];
return !s.hasOwnProperty('r') || s.r >= 0;
}

function getUseCalculatedLiveEdgeTimeForAdaptation(voAdaptation) {
let realRepresentation = getRealAdaptationFor(voAdaptation).Representation_asArray[0];
let segmentInfo;
if (realRepresentation.hasOwnProperty(DashConstants.SEGMENT_LIST)) {
segmentInfo = realRepresentation.SegmentList;
return segmentInfo.hasOwnProperty(DashConstants.SEGMENT_TIMELINE) ?
isLastRepeatAttributeValid(segmentInfo.SegmentTimeline) :
true;
} else if (realRepresentation.hasOwnProperty(DashConstants.SEGMENT_TEMPLATE)) {
segmentInfo = realRepresentation.SegmentTemplate;
if (segmentInfo.hasOwnProperty(DashConstants.SEGMENT_TIMELINE)) {
return isLastRepeatAttributeValid(segmentInfo.SegmentTimeline);
}
}

return false;
}

function getRepresentationsForAdaptation(voAdaptation) {
const voRepresentations = [];
const processedRealAdaptation = getRealAdaptationFor(voAdaptation);
let segmentInfo;

if (processedRealAdaptation && processedRealAdaptation.Representation_asArray) {
for (i = 0; processedRealAdaptation && i < processedRealAdaptation.Representation_asArray.length; i++) {
realRepresentation = processedRealAdaptation.Representation_asArray[i];
voRepresentation = new Representation();
for (let i = 0, len = processedRealAdaptation.Representation_asArray.length; i < len; ++i) {
const realRepresentation = processedRealAdaptation.Representation_asArray[i];
const voRepresentation = new Representation();
voRepresentation.index = i;
voRepresentation.adaptation = voAdaptation;

Expand Down Expand Up @@ -444,6 +464,7 @@ function DashManifestModel(config) {
if (realRepresentation.hasOwnProperty(DashConstants.MAX_PLAYOUT_RATE)) {
voRepresentation.maxPlayoutRate = realRepresentation.maxPlayoutRate;
}

if (realRepresentation.hasOwnProperty(DashConstants.SEGMENT_BASE)) {
segmentInfo = realRepresentation.SegmentBase;
voRepresentation.segmentInfoType = DashConstants.SEGMENT_BASE;
Expand All @@ -452,10 +473,7 @@ function DashManifestModel(config) {

if (segmentInfo.hasOwnProperty(DashConstants.SEGMENT_TIMELINE)) {
voRepresentation.segmentInfoType = DashConstants.SEGMENT_TIMELINE;
s = segmentInfo.SegmentTimeline.S_asArray[segmentInfo.SegmentTimeline.S_asArray.length - 1];
if (!s.hasOwnProperty('r') || s.r >= 0) {
voRepresentation.useCalculatedLiveEdgeTime = true;
}
voRepresentation.useCalculatedLiveEdgeTime = isLastRepeatAttributeValid(segmentInfo.SegmentTimeline);
} else {
voRepresentation.segmentInfoType = DashConstants.SEGMENT_LIST;
voRepresentation.useCalculatedLiveEdgeTime = true;
Expand All @@ -465,10 +483,7 @@ function DashManifestModel(config) {

if (segmentInfo.hasOwnProperty(DashConstants.SEGMENT_TIMELINE)) {
voRepresentation.segmentInfoType = DashConstants.SEGMENT_TIMELINE;
s = segmentInfo.SegmentTimeline.S_asArray[segmentInfo.SegmentTimeline.S_asArray.length - 1];
if (!s.hasOwnProperty('r') || s.r >= 0) {
voRepresentation.useCalculatedLiveEdgeTime = true;
}
voRepresentation.useCalculatedLiveEdgeTime = isLastRepeatAttributeValid(segmentInfo.SegmentTimeline);
} else {
voRepresentation.segmentInfoType = DashConstants.SEGMENT_TEMPLATE;
}
Expand All @@ -485,7 +500,7 @@ function DashManifestModel(config) {

if (segmentInfo) {
if (segmentInfo.hasOwnProperty(DashConstants.INITIALIZATION)) {
initialization = segmentInfo.Initialization;
let initialization = segmentInfo.Initialization;

if (initialization.hasOwnProperty(DashConstants.SOURCE_URL)) {
voRepresentation.initialization = initialization.sourceURL;
Expand Down Expand Up @@ -1000,7 +1015,8 @@ function DashManifestModel(config) {
getUTCTimingSources: getUTCTimingSources,
getBaseURLsFromElement: getBaseURLsFromElement,
getRepresentationSortFunction: getRepresentationSortFunction,
getLocation: getLocation
getLocation: getLocation,
getUseCalculatedLiveEdgeTimeForAdaptation: getUseCalculatedLiveEdgeTimeForAdaptation
};

return instance;
Expand Down
8 changes: 2 additions & 6 deletions src/streaming/controllers/StreamController.js
Original file line number Diff line number Diff line change
Expand Up @@ -598,13 +598,9 @@ function StreamController() {
adapter.getMediaInfoForType(streamInfo, Constants.AUDIO)
);

let voAdaptation,
useCalculatedLiveEdgeTime;

let useCalculatedLiveEdgeTime;
if (mediaInfo) {
voAdaptation = adapter.getDataForMedia(mediaInfo);
useCalculatedLiveEdgeTime = dashManifestModel.getRepresentationsForAdaptation(voAdaptation)[0].useCalculatedLiveEdgeTime;

useCalculatedLiveEdgeTime = dashManifestModel.getUseCalculatedLiveEdgeTimeForAdaptation(adapter.getDataForMedia(mediaInfo));
if (useCalculatedLiveEdgeTime) {
log('SegmentTimeline detected using calculated Live Edge Time');
mediaPlayerModel.setUseManifestDateHeaderTimeSource(false);
Expand Down

0 comments on commit b4b0a84

Please sign in to comment.