Skip to content

Commit

Permalink
fix(Ads): Update Alternative MPD to match the latest spec (#7706)
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad authored Dec 4, 2024
1 parent 8566836 commit cd78811
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
6 changes: 4 additions & 2 deletions lib/ads/ad_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -844,14 +844,16 @@ shaka.ads.AdManager = class extends shaka.util.FakeEventTarget {
if (this.config_ && this.config_.disableDASHInterstitial) {
return;
}
if (region.schemeIdUri == 'urn:mpeg:dash:event:alternativeMPD:2022') {
const schemeIdUri = region.schemeIdUri;
if (schemeIdUri == 'urn:mpeg:dash:event:alternativeMPD:insert:2025' ||
schemeIdUri == 'urn:mpeg:dash:event:alternativeMPD:replace:2025') {
if (!this.interstitialAdManager_) {
this.initInterstitial(/* adContainer= */ null, basePlayer, baseVideo);
}
if (this.interstitialAdManager_) {
this.interstitialAdManager_.addRegion(region);
}
} else if (region.schemeIdUri == 'urn:mpeg:dash:event:2012' &&
} else if (schemeIdUri == 'urn:mpeg:dash:event:2012' &&
region.eventNode &&
shaka.util.TXml.findChild(region.eventNode, 'OverlayEvent')) {
if (!this.interstitialAdManager_) {
Expand Down
9 changes: 4 additions & 5 deletions lib/ads/interstitial_ad_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,11 @@ shaka.ads.InterstitialAdManager = class {
*/
addRegion(region) {
let alternativeMPDUri;
let alternativeMPDmode;
for (const node of region.eventNode.children) {
if (node.tagName == 'AlternativeMPD') {
const uri = node.attributes['uri'];
const mode = node.attributes['mode'];
if (uri) {
alternativeMPDUri = uri;
alternativeMPDmode = mode;
break;
}
}
Expand All @@ -333,8 +330,10 @@ shaka.ads.InterstitialAdManager = class {
shaka.log.alwaysWarn('Unsupported MPD alternate', region);
return;
}
const isReplace = alternativeMPDmode == 'replace';
const isInsert = alternativeMPDmode == 'insert';
const isReplace =
region.schemeIdUri == 'urn:mpeg:dash:event:alternativeMPD:replace:2025';
const isInsert =
region.schemeIdUri == 'urn:mpeg:dash:event:alternativeMPD:insert:2025';
if (!isReplace && !isInsert) {
shaka.log.warning('Unsupported MPD alternate', region);
return;
Expand Down
12 changes: 6 additions & 6 deletions test/ads/interstitial_ad_manager_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ describe('Interstitial Ad manager', () => {
it('supports alternative MPD', async () => {
const eventString = [
'<Event duration="1" id="PREROLL" presentationTime="0">',
'<AlternativeMPD mode="insert" uri="test.mpd"/>',
'<AlternativeMPD uri="test.mpd"/>',
'</Event>',
].join('');
const eventNode = TXml.parseXmlString(eventString);
Expand All @@ -741,7 +741,7 @@ describe('Interstitial Ad manager', () => {
startTime: 0,
endTime: 1,
id: 'PREROLL',
schemeIdUri: 'urn:mpeg:dash:event:alternativeMPD:2022',
schemeIdUri: 'urn:mpeg:dash:event:alternativeMPD:insert:2025',
eventNode,
eventElement: TXml.txmlNodeToDomElement(eventNode),
value: '',
Expand All @@ -765,7 +765,7 @@ describe('Interstitial Ad manager', () => {
it('ignore duplicate alternative MPD', async () => {
const eventString = [
'<Event duration="1" id="PREROLL" presentationTime="0">',
'<AlternativeMPD mode="insert" uri="test.mpd"/>',
'<AlternativeMPD uri="test.mpd"/>',
'</Event>',
].join('');
const eventNode = TXml.parseXmlString(eventString);
Expand All @@ -774,7 +774,7 @@ describe('Interstitial Ad manager', () => {
startTime: 0,
endTime: 1,
id: 'PREROLL',
schemeIdUri: 'urn:mpeg:dash:event:alternativeMPD:2022',
schemeIdUri: 'urn:mpeg:dash:event:alternativeMPD:insert:2025',
eventNode,
eventElement: TXml.txmlNodeToDomElement(eventNode),
value: '',
Expand All @@ -800,7 +800,7 @@ describe('Interstitial Ad manager', () => {
// It is not valid because it does not have an interstitial URL
const eventString = [
'<Event duration="1" id="PREROLL" presentationTime="0">',
'<AlternativeMPD mode="insert"/>',
'<AlternativeMPD/>',
'</Event>',
].join('');
const eventNode = TXml.parseXmlString(eventString);
Expand All @@ -809,7 +809,7 @@ describe('Interstitial Ad manager', () => {
startTime: 0,
endTime: 1,
id: 'PREROLL',
schemeIdUri: 'urn:mpeg:dash:event:alternativeMPD:2022',
schemeIdUri: 'urn:mpeg:dash:event:alternativeMPD:insert:2025',
eventNode,
eventElement: TXml.txmlNodeToDomElement(eventNode),
value: '',
Expand Down
4 changes: 2 additions & 2 deletions test/test/assets/dash-mpd-alternate/dash.mpd
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ For more info about this video, see https://github.com/Axinom/dash-test-vectors
</AdaptationSet>
</Period>
<Period id="1" duration="PT0H00M16.000S">
<EventStream schemeIdUri="urn:mpeg:dash:event:alternativeMPD:2022" timescale="10000000">
<EventStream schemeIdUri="urn:mpeg:dash:event:alternativeMPD:replace:2025" timescale="10000000">
<Event presentationTime="0" duration="20000000" id="1">
<AlternativeMPD uri="/base/test/test/assets/dash-multi-codec/dash.mpd" mode="replace" />
<AlternativeMPD uri="/base/test/test/assets/dash-multi-codec/dash.mpd"/>
</Event>
</EventStream>
<AdaptationSet segmentAlignment="true" group="1" maxWidth="1920" maxHeight="1080" maxFrameRate="24" par="16:9" lang="und">
Expand Down

0 comments on commit cd78811

Please sign in to comment.