From d341f93c9091d371eba7d37faad2c76914d31a58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Velad=20Galv=C3=A1n?= Date: Thu, 9 Feb 2023 08:47:31 +0100 Subject: [PATCH] fix(Demo): Allow manifest type for DAI custom assets (#4977) Fixes https://github.com/shaka-project/shaka-player/issues/4887 --- demo/common/asset.js | 15 +++++++++++++++ demo/common/assets.js | 6 ++++-- demo/common/message_ids.js | 1 + demo/custom.js | 19 +++++++++++++++++++ demo/locales/en.json | 1 + demo/locales/source.json | 4 ++++ demo/main.js | 14 ++++++++++++++ externs/ima.js | 9 +++++++++ 8 files changed, 67 insertions(+), 2 deletions(-) diff --git a/demo/common/asset.js b/demo/common/asset.js index 7d39f25be3..272bbee2e6 100644 --- a/demo/common/asset.js +++ b/demo/common/asset.js @@ -76,6 +76,8 @@ const ShakaDemoAssetInfo = class { /** @type {?string} */ this.imaContentSrcId = null; /** @type {?string} */ + this.imaManifestType = null; + /** @type {?string} */ this.mimeType = null; @@ -256,6 +258,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 diff --git a/demo/common/assets.js b/demo/common/assets.js index d80190084f..4f8e74c67e 100644 --- a/demo/common/assets.js +++ b/demo/common/assets.js @@ -509,7 +509,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', @@ -519,7 +520,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', diff --git a/demo/common/message_ids.js b/demo/common/message_ids.js index 802ae86dfa..8608f5fc65 100644 --- a/demo/common/message_ids.js +++ b/demo/common/message_ids.js @@ -96,6 +96,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', diff --git a/demo/custom.js b/demo/custom.js index 99a742a6d3..1dd640262b 100644 --- a/demo/custom.js +++ b/demo/custom.js @@ -328,6 +328,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; } diff --git a/demo/locales/en.json b/demo/locales/en.json index 680a34cb0e..b0d1711b56 100644 --- a/demo/locales/en.json +++ b/demo/locales/en.json @@ -97,6 +97,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_MIN_BUFFER_TIME": "Ignore Min Buffer Time", "DEMO_IGNORE_TEXT_FAILURES": "Ignore Text Stream Failures", diff --git a/demo/locales/source.json b/demo/locales/source.json index 6009153570..a41532309d 100644 --- a/demo/locales/source.json +++ b/demo/locales/source.json @@ -391,6 +391,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)" diff --git a/demo/main.js b/demo/main.js index db7ac5faac..8b8cdb9de8 100644 --- a/demo/main.js +++ b/demo/main.js @@ -1502,6 +1502,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); diff --git a/externs/ima.js b/externs/ima.js index fa71e52d00..66b3db3591 100644 --- a/externs/ima.js +++ b/externs/ima.js @@ -501,6 +501,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 {};