Skip to content

Commit

Permalink
fix(Demo): Allow manifest type for DAI custom assets (shaka-project#4977
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad committed Feb 9, 2023
1 parent 64e94f1 commit 1e50630
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 2 deletions.
15 changes: 15 additions & 0 deletions demo/common/asset.js
Expand Up @@ -76,6 +76,8 @@ const ShakaDemoAssetInfo = class {
/** @type {?string} */
this.imaContentSrcId = null;
/** @type {?string} */
this.imaManifestType = null;
/** @type {?string} */
this.mimeType = null;
/** @type {?string} */
this.mediaPlaylistFullMimeType = null;
Expand Down Expand Up @@ -267,6 +269,19 @@ const ShakaDemoAssetInfo = class {
return this;
}

/**
* @param {string} type
* @return {!ShakaDemoAssetInfo}
*/
setIMAManifestType(type) {
this.imaManifestType = type;
if (!this.features.includes(shakaAssets.Feature.ADS)) {
this.addFeature(shakaAssets.Feature.ADS);
}

return this;
}

/**
* @param {string} headerName
* @param {string} headerValue
Expand Down
6 changes: 4 additions & 2 deletions demo/common/assets.js
Expand Up @@ -540,7 +540,8 @@ shakaAssets.testAssets = [
.addFeature(shakaAssets.Feature.MP4)
.addFeature(shakaAssets.Feature.OFFLINE)
.setIMAContentSourceId('2528370')
.setIMAVideoId('tears-of-steel'),
.setIMAVideoId('tears-of-steel')
.setIMAManifestType('HLS'),
new ShakaDemoAssetInfo(
/* name= */ 'Tears of Steel (live, DASH, Server Side ads)',
/* iconUri= */ 'https://storage.googleapis.com/shaka-asset-icons/tears_of_steel.png',
Expand All @@ -550,7 +551,8 @@ shakaAssets.testAssets = [
.addFeature(shakaAssets.Feature.MP4)
.addFeature(shakaAssets.Feature.SUBTITLES)
.addFeature(shakaAssets.Feature.LIVE)
.setIMAAssetKey('PSzZMzAkSXCmlJOWDmRj8Q'),
.setIMAAssetKey('PSzZMzAkSXCmlJOWDmRj8Q')
.setIMAManifestType('DASH'),
new ShakaDemoAssetInfo(
/* name= */ 'Tears of Steel (multicodec, surround + stereo)',
/* iconUri= */ 'https://storage.googleapis.com/shaka-asset-icons/tears_of_steel.png',
Expand Down
1 change: 1 addition & 0 deletions demo/common/message_ids.js
Expand Up @@ -102,6 +102,7 @@ shakaDemo.MessageIds = {
ADS_TAB: 'DEMO_ADS_TAB',
IMA_ASSET_KEY: 'DEMO_IMA_ASSET_KEY',
IMA_CONTENT_SRC_ID: 'DEMO_IMA_CONTENT_SRC_ID',
IMA_MANIFEST_TYPE: 'DEMO_IMA_MANIFEST_TYPE',
IMA_VIDEO_ID: 'DEMO_IMA_VIDEO_ID',
CANCEL_BUTTON: 'DEMO_CANCEL_BUTTON',
CUSTOM_INTRO_ONE: 'DEMO_CUSTOM_INTRO_ONE',
Expand Down
19 changes: 19 additions & 0 deletions demo/custom.js
Expand Up @@ -362,6 +362,25 @@ shakaDemo.Custom = class {
this.makeField_(
container, assetKeyName, assetKeySetup, assetKeyChange);

// Make the manifest type field.
const manifestTypeSetup = (input, container) => {
if (assetInProgress.imaManifestType) {
input.value = assetInProgress.imaManifestType;
}

this.manifestField_.required =
this.checkManifestRequired_(assetInProgress);
};
const manifestTypeChange = (input) => {
assetInProgress.imaManifestType = input.value;
this.manifestField_.required =
this.checkManifestRequired_(assetInProgress);
};
const manifestTypeName = shakaDemoMain.getLocalizedString(
shakaDemo.MessageIds.IMA_MANIFEST_TYPE);
this.makeField_(
container, manifestTypeName, manifestTypeSetup, manifestTypeChange);

return adsDiv;
}

Expand Down
1 change: 1 addition & 0 deletions demo/locales/en.json
Expand Up @@ -107,6 +107,7 @@
"DEMO_IGNORE_HLS_TEXT_FAILURES": "Ignore HLS Text Stream Failures",
"DEMO_IMA_ASSET_KEY": "Asset key (for LIVE DAI Content)",
"DEMO_IMA_CONTENT_SRC_ID": "Content source ID (for VOD DAI Content)",
"DEMO_IMA_MANIFEST_TYPE": "Manifest type (for DAI Content)",
"DEMO_IMA_VIDEO_ID": "Video ID (for VOD DAI Content)",
"DEMO_IGNORE_MANIFEST_PROGRAM_DATE_TIME": "Ignore Program Date Time from manifest",
"DEMO_IGNORE_MIN_BUFFER_TIME": "Ignore Min Buffer Time",
Expand Down
4 changes: 4 additions & 0 deletions demo/locales/source.json
Expand Up @@ -435,6 +435,10 @@
"description": "The label on a field that allows users to provide a content source id for a custom asset.",
"message": "Asset key (for VOD DAI Content)"
},
"DEMO_IMA_MANIFEST_TYPE": {
"description": "The label on a field that allows users to provide a manifest type for a custom asset.",
"message": "Manifest type (for DAI Content)"
},
"DEMO_IMA_VIDEO_ID": {
"description": "The label on a field that allows users to provide a video id for a custom asset.",
"message": "Video ID (for VOD DAI Content)"
Expand Down
14 changes: 14 additions & 0 deletions demo/main.js
Expand Up @@ -1561,6 +1561,20 @@ shakaDemo.Main = class {
request.contentSourceId = asset.imaContentSrcId;
request.videoId = asset.imaVideoId;
}
switch (asset.imaManifestType) {
case 'DASH':
case 'dash':
case 'MPD':
case 'mpd':
request.format = google.ima.dai.api.StreamRequest.StreamFormat.DASH;
break;
case 'HLS':
case 'hls':
case 'M3U8':
case 'm3u8':
request.format = google.ima.dai.api.StreamRequest.StreamFormat.HLS;
break;
}

const uri = await adManager.requestServerSideStream(
request, /* backupUri= */ asset.manifestUri);
Expand Down
9 changes: 9 additions & 0 deletions externs/ima.js
Expand Up @@ -513,6 +513,15 @@ google.ima.dai.api.StreamRequest.prototype.streamActivityMonitorId;
google.ima.dai.api.StreamRequest.prototype.format;


/**
* @enum {string}
*/
google.ima.dai.api.StreamRequest.StreamFormat = {
DASH: 'dash',
HLS: 'hls',
};


/** @const */
google.ima.dai.api.VODStreamRequest =
class extends google.ima.dai.api.StreamRequest {};
Expand Down

0 comments on commit 1e50630

Please sign in to comment.