Skip to content

Commit

Permalink
feat(dash): Parse label from DASH manifest AdaptationSet
Browse files Browse the repository at this point in the history
  • Loading branch information
Sevag Simonian committed Feb 8, 2019
1 parent 10b59e8 commit 85fceeb
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 25 deletions.
53 changes: 33 additions & 20 deletions contrib/akamai/controlbar/ControlBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,31 +281,29 @@ var ControlBar = function (dashjsMediaPlayer, displayUTCTimeCodes) {
if (!isNaN(ctrlWidth)) {
left -= ctrlWidth / 2;
}

var scale = (videoContainerRect.height * maxPercentageThumbnailScreen)/thumbnail.height;
if (scale > maximumScale) {
scale = maximumScale;
}

// Set thumbnail control position
thumbnailContainer.style.left = left + 'px';
thumbnailContainer.style.display = '';
thumbnailContainer.style.bottom += Math.round(videoControllerRect.height + bottomMarginThumbnail ) + 'px';
thumbnailContainer.style.height = Math.round(thumbnail.height) + 'px';

var backgroundStyle = 'url("' + thumbnail.url + '") ' + (thumbnail.x > 0 ? '-' + thumbnail.x : '0') +
'px ' + (thumbnail.y > 0 ? '-' + thumbnail.y : '0') + 'px';
thumbnailElem.style.background = backgroundStyle;
thumbnailElem.style.width = thumbnail.width + 'px';
thumbnailElem.style.height = thumbnail.height + 'px';
thumbnailElem.style.transform = 'scale(' + scale + ',' + scale + ')';

if (thumbnailTimeLabel) {
thumbnailTimeLabel.textContent = displayUTCTimeCodes ? player.formatUTC(mouseTime) : player.convertToTimeCode(mouseTime);
}
});


},

onSeekBarMouseMoveOut = function (e) {
Expand Down Expand Up @@ -442,7 +440,16 @@ var ControlBar = function (dashjsMediaPlayer, displayUTCTimeCodes) {
// Subtitles/Captions Menu //XXX we need to add two layers for captions & subtitles if present.
if (!captionMenu) {
var contentFunc = function (element, index) {
return isNaN(index) ? "OFF" : element.lang + " : " + element.kind;
if (isNaN(index)) {
return "OFF";
}

var label = getLabelForLocale(element.labels);
if (label) {
return label + " : " + element.kind;
}

return element.lang + " : " + element.kind;
}
captionMenu = createMenu({menuType: 'caption', arr: e.tracks}, contentFunc);

Expand All @@ -456,7 +463,6 @@ var ControlBar = function (dashjsMediaPlayer, displayUTCTimeCodes) {
},

onStreamInitialized = function (e) {

updateDuration();

var contentFunc;
Expand Down Expand Up @@ -495,7 +501,7 @@ var ControlBar = function (dashjsMediaPlayer, displayUTCTimeCodes) {

if (availableTracks.audio.length > 1 || availableTracks.video.length > 1) {
contentFunc = function (element) {
return 'Language: ' + element.lang + ' - Role: ' + element.roles[0];
return getLabelForLocale(element.labels) || 'Language: ' + element.lang + ' - Role: ' + element.roles[0];
}
trackSwitchMenu = createMenu(availableTracks, contentFunc);
var func = function () {
Expand All @@ -515,7 +521,6 @@ var ControlBar = function (dashjsMediaPlayer, displayUTCTimeCodes) {
},

createMenu = function (info, contentFunc) {

var menuType = info.menuType;
var el = document.createElement("div");
el.id = menuType + "Menu";
Expand Down Expand Up @@ -584,7 +589,6 @@ var ControlBar = function (dashjsMediaPlayer, displayUTCTimeCodes) {
},

getMenuContent = function (type, arr, contentFunc) {

var content = [];
arr.forEach(function (element, index) {
content.push(contentFunc(element, index));
Expand All @@ -595,8 +599,25 @@ var ControlBar = function (dashjsMediaPlayer, displayUTCTimeCodes) {
return content;
},

createMediaTypeMenu = function (type) {
getBrowserLocale = function() {
return (navigator.languages && navigator.languages.length) ? navigator.languages : [navigator.language];
},

getLabelForLocale = function (labels) {
var locales = getBrowserLocale();

for (var i = 0; i < labels.length; i++) {
for (var j = 0; j < locales.length; j++) {
if (labels[i].lang && locales[j] && locales[j].indexOf(labels[i].lang) > -1) {
return labels[i].text;
}
}
}

return labels.length === 1 ? labels[0].text : null;
},

createMediaTypeMenu = function (type) {
var div = document.createElement("div");
var title = document.createElement("div");
var content = document.createElement("ul");
Expand All @@ -616,9 +637,7 @@ var ControlBar = function (dashjsMediaPlayer, displayUTCTimeCodes) {
},

createMenuContent = function (menu, arr, mediaType, name) {

for (var i = 0; i < arr.length; i++) {

var item = document.createElement("li");
item.id = name + "Item_" + i;
item.index = i;
Expand Down Expand Up @@ -650,9 +669,7 @@ var ControlBar = function (dashjsMediaPlayer, displayUTCTimeCodes) {
return menu;
},


onMenuClick = function (menu, btn) {

if (menu.classList.contains("hide")) {
menu.classList.remove("hide");
menu.onmouseleave = function (e) {
Expand All @@ -665,9 +682,7 @@ var ControlBar = function (dashjsMediaPlayer, displayUTCTimeCodes) {
positionMenu(menu, btn);
},


setMenuItemsState = function (value, type) {

var self = typeof value === 'number' ? document.getElementById(type + "Item_" + value) : this,
nodes = self.parentElement.children;

Expand All @@ -681,7 +696,6 @@ var ControlBar = function (dashjsMediaPlayer, displayUTCTimeCodes) {
self.classList.remove("menu-item-unselected");
self.classList.add("menu-item-selected");


if (type === undefined) { // User clicked so type is part of item binding.
switch (self.name) {
case 'video-bitrate-list':
Expand Down Expand Up @@ -877,7 +891,6 @@ var ControlBar = function (dashjsMediaPlayer, displayUTCTimeCodes) {
},

destroy: function () {

this.reset();

playPauseBtn.removeEventListener("click", onPlayPauseClick);
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ declare namespace dashjs {
type: 'video' | 'audio' | 'text' | 'fragmentedText' | 'embeddedText' | null;
streamInfo: StreamInfo | null;
representationCount: number;
labels: string[];
lang: string | null;
viewpoint: any | undefined | null;
accessibility: any[] | null;
Expand Down
1 change: 1 addition & 0 deletions src/dash/DashAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ function DashAdapter() {
mediaInfo.type = adaptation.type;
mediaInfo.streamInfo = convertPeriodToStreamInfo(adaptation.period);
mediaInfo.representationCount = dashManifestModel.getRepresentationCount(realAdaptation);
mediaInfo.labels = dashManifestModel.getLabelsForAdaptation(realAdaptation);
mediaInfo.lang = dashManifestModel.getLanguageForAdaptation(realAdaptation);
viewpoint = dashManifestModel.getViewpointForAdaptation(realAdaptation);
mediaInfo.viewpoint = viewpoint ? viewpoint.value : undefined;
Expand Down
18 changes: 18 additions & 0 deletions src/dash/models/DashManifestModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,23 @@ function DashManifestModel(config) {
return adaptation[DashConstants.CENC_DEFAULT_KID];
}

function getLabelsForAdaptation(adaptation) {
if (!adaptation.Label_asArray || !adaptation.Label_asArray.length) {
return [];
}

const labelArray = [];

for (let i = 0; i < adaptation.Label_asArray.length; i++) {
labelArray.push({
lang: adaptation.Label_asArray[i].lang,
text: adaptation.Label_asArray[i].__text || adaptation.Label_asArray[i]
});
}

return labelArray;
}

function getContentProtectionData(adaptation) {
if (!adaptation || !adaptation.hasOwnProperty(DashConstants.CONTENTPROTECTION_ASARRAY) || adaptation.ContentProtection_asArray.length === 0) {
return null;
Expand Down Expand Up @@ -1016,6 +1033,7 @@ function DashManifestModel(config) {
getCodec: getCodec,
getMimeType: getMimeType,
getKID: getKID,
getLabelsForAdaptation: getLabelsForAdaptation,
getContentProtectionData: getContentProtectionData,
getIsDynamic: getIsDynamic,
getIsDVB: getIsDVB,
Expand Down
2 changes: 1 addition & 1 deletion src/streaming/text/TextController.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ function TextController() {
for (let i = 0; i < fragmentedTracks.length; i++) {
let mediaInfo = fragmentedTracks[i];
if (currentTrackInfo.lang === mediaInfo.lang && currentTrackInfo.index === mediaInfo.index &&
(mediaInfo.id ? currentTrackInfo.label === mediaInfo.id : currentTrackInfo.label === mediaInfo.index)) {
(mediaInfo.id ? currentTrackInfo.id === mediaInfo.id : currentTrackInfo.id === mediaInfo.index)) {
let currentFragTrack = mediaController.getCurrentTrackFor(Constants.FRAGMENTED_TEXT, streamController.getActiveStreamInfo());
if (mediaInfo !== currentFragTrack) {
fragmentModel.abortRequests();
Expand Down
3 changes: 2 additions & 1 deletion src/streaming/text/TextSourceBuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ function TextSourceBuffer() {

textTrackInfo.captionData = captionData;
textTrackInfo.lang = mediaInfo.lang;
textTrackInfo.label = mediaInfo.id ? mediaInfo.id : mediaInfo.index; // AdaptationSet id (an unsigned int) as it's optionnal parameter, use mediaInfo.index
textTrackInfo.labels = mediaInfo.labels;
textTrackInfo.id = mediaInfo.id ? mediaInfo.id : mediaInfo.index; // AdaptationSet id (an unsigned int) as it's optional parameter, use mediaInfo.index
textTrackInfo.index = mediaInfo.index; // AdaptationSet index in manifest
textTrackInfo.isTTML = checkTTML();
textTrackInfo.defaultTrack = getIsDefault(mediaInfo);
Expand Down
6 changes: 3 additions & 3 deletions src/streaming/text/TextTracks.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function TextTracks() {

function createTrackForUserAgent (i) {
const kind = textTrackQueue[i].kind;
const label = textTrackQueue[i].label !== undefined ? textTrackQueue[i].label : textTrackQueue[i].lang;
const label = textTrackQueue[i].id !== undefined ? textTrackQueue[i].id : textTrackQueue[i].lang;
const lang = textTrackQueue[i].lang;
const isTTML = textTrackQueue[i].isTTML;
const isEmbedded = textTrackQueue[i].isEmbedded;
Expand Down Expand Up @@ -488,7 +488,7 @@ function TextTracks() {

function getTrackByIdx(idx) {
return idx >= 0 && textTrackQueue[idx] ?
videoModel.getTextTrack(textTrackQueue[idx].kind, textTrackQueue[idx].label, textTrackQueue[idx].lang, textTrackQueue[idx].isTTML, textTrackQueue[idx].isEmbedded) : null;
videoModel.getTextTrack(textTrackQueue[idx].kind, textTrackQueue[idx].id, textTrackQueue[idx].lang, textTrackQueue[idx].isTTML, textTrackQueue[idx].isEmbedded) : null;
}

function getCurrentTrackIdx() {
Expand All @@ -498,7 +498,7 @@ function TextTracks() {
function getTrackIdxForId(trackId) {
let idx = -1;
for (let i = 0; i < textTrackQueue.length; i++) {
if (textTrackQueue[i].label === trackId) {
if (textTrackQueue[i].id === trackId) {
idx = i;
break;
}
Expand Down

0 comments on commit 85fceeb

Please sign in to comment.