Skip to content

Commit

Permalink
fix(Ads): Calculate the mimeType in an earlier step so that there is …
Browse files Browse the repository at this point in the history
…no impact on the ad playback (#7742)
  • Loading branch information
avelad authored Dec 11, 2024
1 parent 172e713 commit c113738
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
32 changes: 15 additions & 17 deletions lib/ads/interstitial_ad_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,13 +511,23 @@ shaka.ads.InterstitialAdManager = class {
/**
* @param {!Array.<shaka.extern.AdInterstitial>} interstitials
*/
addInterstitials(interstitials) {
async addInterstitials(interstitials) {
let cuepointsChanged = false;
for (const interstitial of interstitials) {
if (!interstitial.uri) {
shaka.log.alwaysWarn('Missing URL in interstitial', interstitial);
continue;
}
if (!interstitial.mimeType) {
try {
const netEngine = this.player_.getNetworkingEngine();
goog.asserts.assert(netEngine, 'Need networking engine');
// eslint-disable-next-line no-await-in-loop
interstitial.mimeType = await shaka.net.NetworkingUtils.getMimeType(
interstitial.uri, netEngine,
this.basePlayer_.getConfiguration().streaming.retryParameters);
} catch (error) {}
}
const interstitialId = interstitial.id || JSON.stringify(interstitial);
if (this.interstitialIds_.has(interstitialId)) {
continue;
Expand Down Expand Up @@ -653,25 +663,13 @@ shaka.ads.InterstitialAdManager = class {
* @param {number=} oncePlayed
* @private
*/
async setupAd_(interstitial, sequenceLength, adPosition, initialTime,
setupAd_(interstitial, sequenceLength, adPosition, initialTime,
oncePlayed = 0) {
shaka.log.info('Starting interstitial',
interstitial.startTime, 'at', this.lastTime_);

this.lastPlayedAd_ = interstitial;

let interstitialMimeType = interstitial.mimeType;
if (!interstitialMimeType) {
try {
const netEngine = this.player_.getNetworkingEngine();
goog.asserts.assert(netEngine, 'Need networking engine');
// eslint-disable-next-line require-atomic-updates
interstitialMimeType = await shaka.net.NetworkingUtils.getMimeType(
interstitial.uri, netEngine,
this.basePlayer_.getConfiguration().streaming.retryParameters);
} catch (error) {}
}

this.determineIfUsingBaseVideo_();
goog.asserts.assert(this.video_, 'Must have video');

Expand All @@ -698,9 +696,9 @@ shaka.ads.InterstitialAdManager = class {
}
}

if (interstitialMimeType) {
if (interstitialMimeType.startsWith('image/') ||
interstitialMimeType === 'text/html') {
if (interstitial.mimeType) {
if (interstitial.mimeType.startsWith('image/') ||
interstitial.mimeType === 'text/html') {
if (!interstitial.overlay) {
shaka.log.alwaysWarn('Unsupported interstitial', interstitial);
return;
Expand Down
18 changes: 9 additions & 9 deletions test/ads/interstitial_ad_manager_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ describe('Interstitial Ad manager', () => {
startTime: 0,
endTime: null,
uri: 'test.m3u8',
mimeType: null,
mimeType: 'application/x-mpegurl',
isSkippable: false,
skipOffset: null,
skipFor: null,
Expand Down Expand Up @@ -385,7 +385,7 @@ describe('Interstitial Ad manager', () => {
startTime: 0,
endTime: null,
uri: 'test.m3u8',
mimeType: null,
mimeType: 'application/x-mpegurl',
isSkippable: true,
skipOffset: 5,
skipFor: 10,
Expand Down Expand Up @@ -430,7 +430,7 @@ describe('Interstitial Ad manager', () => {
startTime: 0,
endTime: null,
uri: 'test.m3u8',
mimeType: null,
mimeType: 'application/x-mpegurl',
isSkippable: true,
skipOffset: 0,
skipFor: null,
Expand Down Expand Up @@ -475,7 +475,7 @@ describe('Interstitial Ad manager', () => {
startTime: 0,
endTime: null,
uri: 'test.m3u8',
mimeType: null,
mimeType: 'application/x-mpegurl',
isSkippable: true,
skipOffset: 0,
skipFor: null,
Expand Down Expand Up @@ -520,7 +520,7 @@ describe('Interstitial Ad manager', () => {
startTime: 0,
endTime: null,
uri: 'test.m3u8',
mimeType: null,
mimeType: 'application/x-mpegurl',
isSkippable: true,
skipOffset: 0,
skipFor: null,
Expand Down Expand Up @@ -565,7 +565,7 @@ describe('Interstitial Ad manager', () => {
startTime: 0,
endTime: null,
uri: 'test.m3u8',
mimeType: null,
mimeType: 'application/x-mpegurl',
isSkippable: true,
skipOffset: 0,
skipFor: null,
Expand Down Expand Up @@ -610,7 +610,7 @@ describe('Interstitial Ad manager', () => {
startTime: 0,
endTime: null,
uri: 'test.m3u8',
mimeType: null,
mimeType: 'application/x-mpegurl',
isSkippable: true,
skipOffset: 0,
skipFor: null,
Expand Down Expand Up @@ -655,7 +655,7 @@ describe('Interstitial Ad manager', () => {
startTime: 100,
endTime: 130,
uri: 'test.m3u8',
mimeType: null,
mimeType: 'application/x-mpegurl',
isSkippable: true,
skipOffset: 0,
skipFor: null,
Expand Down Expand Up @@ -710,7 +710,7 @@ describe('Interstitial Ad manager', () => {
startTime: 0,
endTime: null,
uri: 'ad.m3u8',
mimeType: null,
mimeType: 'application/x-mpegurl',
isSkippable: true,
skipOffset: 5,
skipFor: 10,
Expand Down

0 comments on commit c113738

Please sign in to comment.