Skip to content

Render the first playable Linear creative of a VAST response - #1034

Open
mdanylov-sigma wants to merge 3 commits into
masterfrom
claude/android-parity-ios-1371
Open

mdanylov-sigma wants to merge 3 commits into
masterfrom
claude/android-parity-ios-1371

Conversation

@mdanylov-sigma

@mdanylov-sigma mdanylov-sigma commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

Android counterpart of prebid/prebid-mobile-ios#1371 (issue prebid/prebid-mobile-ios#1370), which notes that AdResponseParserVast.getMediaFileUrl has the same first-Linear behavior.

Problem

AdResponseParserVast reads each part of the video from a different place:

  • getMediaFileUrl returns null as soon as the first Linear creative has no supported media file, even when a later Linear has one.
  • When several Linear creatives have supported media files, it picks the largest file across all of them. getVideoDuration, getSkipOffset, the tracking events and the clicks all come from the first Linear.
  • getWidth()/getHeight() read ad 0 / creative 0 / media file 0, so the size is 0x0 when CompanionAds come first.
  • CreativeModelsMakerVast passes ad index 0 to every helper, so only the first ad of the response is looked at.

Results through CreativeModelsMakerVast on master:

Response Video model on master
unsupported Linear, then mp4 Linear (same ad) mediaUrl=null and the duration of the unsupported Linear. The load then fails in CreativeFactory with "Could not find MediaFile that is supported by this video player…"
mp4 Linear, then unsupported Linear (same ad) works
ad without a playable Linear, then ad with one mediaUrl=null, impression, Error URL and companion from the first ad
two playable Linears, 640x480 15s then 1280x720 30s video of the second Linear with the 15s duration of the first. That skews the max-duration check, the skip offset and quartile tracking

The crash fixed on iOS in prebid/prebid-mobile-ios#1369 (CompanionAds before Linear) does not happen on Android: these helpers already pick the Linear creative by type.

Fix

  • New private findPlayableLinear: the first Linear creative of an ad with a supported media file. The media file, its size, the duration, skip offset, tracking events, click trackers and click-through all come from it.
  • New getPlayableAdIndex(): the first ad of the last response with a playable Linear, or 0 if there is none. CreativeModelsMakerVast passes it instead of 0, so the impressions, Error URL, verification and companion come from that ad too.
  • New getBestMediaFile(index): the largest supported media file of that Linear (before, the largest across all Linears). The maker takes the URL and the size from it. Width and height are parsed leniently (0 when missing or not a number). The interstitial size follows the played video, so a landscape mp4 is no longer locked to portrait because of a portrait JS Linear. The ad-0 getWidth()/getHeight() are removed.
  • Without a playable Linear in any ad of the last response, CreativeModelsMakerVast fails before it reads the duration or the size. It requests the Error URIs with 403 and fails with the same NO_SUPPORTED_MEDIA_ERROR message that CreativeFactory gave later on master (iOS: "No Valid Media"). The CreativeFactory check stays as a safety net.
  • A selected Linear without a <Duration> element fails with "the Linear creative has no Duration" instead of an NPE ("Video failed: null"). An empty or whitespace-only <Duration> still loads as on master, with the duration unknown (-1).
  • The helpers that walk the wrapper chain (getImpressions, getAllTrackings, getClickTrackings, and getErrorUrls from Request the VAST Error URIs of a video ad that fails to load #1038) used the same index at every level. Now the index selects the ad of the last response. Each wrapper response contributes the Wrapper ad that VastParserExtractor followed: the first one with a VASTAdTagURI, the same lookup getVastUrl() uses. Before, it was always ad 0.

Differences from before and from iOS

Tests

New cases in CreativeModelsMakerVastTest. Every URL of a test Linear starts with its name, and every ad has its own Error, Impression and <AdVerifications>, so each assertion shows which creative a value came from:

Test master this PR
unsupportedLinearBeforeSupportedLinear mediaUrl=null, 10s, 720x1280 mp4 media, 1280x720 and interstitial size, 15s, skip offset, start tracker, click tracker and click-through of the mp4 Linear
supportedLinearBeforeUnsupportedLinear passes passes
twoPlayableLinears 720p video with the 15s duration the first Linear's video, duration and tracker
unplayableAdBeforePlayableAd mediaUrl=null, everything from ad 1 media, size, impression, Error URL, tracker, verification and companion from ad 2
wrapperThenPlayableSecondAd mediaUrl=null the wrapper's impression, tracker and Error URI, plus ad 2's
wrapperAdAfterInlineAd trackers of the wrapper response's InLine ad 0 trackers of the followed Wrapper ad
companionBeforeLinear 0x0 1280x720
noSupportedMedia a model with mediaUrl=null fails in the maker with NO_SUPPORTED_MEDIA_ERROR, Error URI requested with 403
linearWithoutDuration "Video failed: null" "the Linear creative has no Duration"
linearWithEmptyDuration loads, duration -1 loads, duration -1
  • 8 of the 10 new tests fail against master's AdResponseParserVast and CreativeModelsMakerVast. supportedLinearBeforeUnsupportedLinear and linearWithEmptyDuration assert behavior that stays the same
  • ./gradlew PrebidMobile-core:testReleaseUnitTest at 8c26f2ba (based on master 719370f1): 1711 tests, 0 failures

Independent of #1033 (VAST no-ad Error URIs): the two PRs touch different code and can merge in either order.

🤖 Generated with Claude Code

@YuriyVelichkoPI YuriyVelichkoPI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, the selection logic looks right to me and matches iOS #1371. For every response that loaded before, the new lookup picks the same ad and the same Linear, and getAdIndex keeps wrapper impressions, trackers and Error URIs as they were. The new tests make it easy to see which creative each value comes from. I ran CreativeModelsMakerVastTest plus the rendering.parser, rendering.loading and rendering.video tests on the PR head: 155 tests, 0 failures.

Before merge, please address the following. Details are in the inline comments.

  1. The video width/height still come from ad 0 / creative 0 / media file 0, not from the Linear that is played (CreativeModelsMakerVast.java:137-138, AdResponseParserVast.getWidth/getHeight). With Linear#1 = JS 720x1280 and Linear#2 = mp4 1280x720, the mp4 plays, but the model reports 720x1280. setInterstitialSize("720x1280") then matches VERTICAL_720x1280 and locks the interstitial to portrait for a landscape video. When ad 0 is a wrapper or CompanionAds comes first, the size is 0x0. I reproduced both the same-ad and the second-ad variant with a probe test. This path only becomes reachable with this PR, because master fails these loads.
  2. getVideoDuration NPE. A selected Linear without <Duration> throws, and the load fails with "Video failed: null".
  3. Wrapper responses always contribute ad 0 (getAdIndex), while VastParserExtractor follows the first Ad that has a Wrapper. If a wrapper response has an InLine ad 0 and the Wrapper at ad 1, impressions and trackers come from the wrong ad.
  4. Wrapper-level <AdVerifications> (VAST 4.1+) are ignored. Only the last response is read.
  5. No early "no valid media" validation. iOS fails early with a clear error when no playable Linear exists. Android should do the same, rather than failing later with a generic error.
  6. Tests: assert the size in unsupportedLinearBeforeSupportedLinear / unplayableAdBeforePlayableAd, using different dimensions per Linear, and assert that AdVerifications comes from the selected ad.
  7. Cleanup in getMediaFileUrl: the wrapper branch discards the recursive result, and there's a "meduaFile" typo.
  8. Rebase: the renderer-test commit (0080027a, InterstitialAdUnitTest / RewardedAdUnitTest) is already on master through #1055/#1057. A rebase would drop it.

videoModel.setName(VIDEO_CREATIVE_TAG);

videoModel.setMediaUrl(latestVastWrapperParser.getMediaFileUrl(latestVastWrapperParser, 0));
videoModel.setMediaUrl(latestVastWrapperParser.getMediaFileUrl(latestVastWrapperParser, adIndex));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The media URL now comes from the selected Linear, but the size set a few lines below (setWidth/setHeight(latestVastWrapperParser.getWidth()/getHeight()), lines 137-138) still reads getAds().get(0)...getCreatives().get(0)...getMediaFiles().get(0). With Linear#1 = application/javascript 720x1280 and Linear#2 = video/mp4 1280x720, we play the mp4 but report 720x1280. Line 235 then calls setInterstitialSize("720x1280"), InterstitialSizes.isPortrait matches VERTICAL_720x1280, and InterstitialLayoutConfigurator locks the interstitial to portrait while a landscape video plays letterboxed. When ad 0 is a wrapper ad or CompanionAds is listed first, the size is 0x0.

Could the width/height come from the MediaFile that getMediaFileUrl picks? For example, factor out a getBestMediaFile(adIndex) that returns the MediaFile, use getValue() for the URL and getWidth()/getHeight() (parsed defensively, 0 on error) for the model.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in b1a8dc7. The new AdResponseParserVast.getBestMediaFile(adIndex) returns the MediaFile that is played. The maker takes the URL from getValue(), and the size from parseDimension(getWidth()/getHeight()), which returns 0 for a blank or non-numeric value. So the interstitial size now follows the played video. I removed the ad-0 getWidth()/getHeight() from the parser, so nothing can read ad 0 by accident. The media file choice uses the same lenient parsing, so a malformed width no longer fails the load.

Tests: unsupportedLinearBeforeSupportedLinear now uses 720x1280 for the JS Linear and 1280x720 for the mp4, and asserts 1280x720 plus interstitialSize. unplayableAdBeforePlayableAd does the same across ads. The new companionBeforeLinear covers the CompanionAds-first case, which was 0x0 on master.

return creative.getLinear().getDuration().getValue();
}
}
return linear.getDuration().getValue();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linear.getDuration().getValue() has no null check. A Linear without <Duration> throws an NPE, makeModelsContinued catches it, and the load fails with "Video failed: null". On master this only applied to the first Linear. Now it applies to whichever Linear is selected. Please null-check it and fail with a clear message, or treat a missing duration as unplayable in findPlayableLinear.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in b1a8dc7. getVideoDuration returns null when the selected Linear has no <Duration>. The maker then fails with "Video failed: the Linear creative has no Duration" before it reads anything else. New test: linearWithoutDuration.

One difference from iOS: iOS also rejects a duration of 0 ("Creative duration is invalid"). On Android, 00:00:00 still loads as before, which I left alone in this PR.


// The index passed to the helpers below selects the ad of the last response in the wrapper chain.
// Wrapper responses contribute their first ad.
private static int getAdIndex(AdResponseParserVast parserVast, int index) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrapper responses always contribute ad 0 here, but VastParserExtractor follows the first Ad that has a Wrapper (getVastUrl()). If a wrapper response has an InLine ad 0 and the Wrapper at ad 1, impressions, trackers and Error URIs come from the InLine ad, not from the Wrapper that was actually followed. Please return the index of the followed Wrapper ad for non-last parsers.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in b1a8dc7. For a wrapper response, getAdIndex now returns the index of the Wrapper ad that VastParserExtractor follows. getVastUrl() uses the same lookup (getFollowedWrapperAdIndex: the first Wrapper ad with a VASTAdTagURI), so the two can't drift apart. New test: wrapperAdAfterInlineAd puts an InLine ad 0 and the Wrapper at ad 1, and checks that the impressions, the start tracker and the Error URIs come from the Wrapper.

final String vastClickThroughUrl = rootVastParser.getClickThroughUrl(rootVastParser, adIndex);
final String videoDuration = latestVastWrapperParser.getVideoDuration(latestVastWrapperParser, adIndex);
final String skipOffset = latestVastWrapperParser.getSkipOffset(latestVastWrapperParser, adIndex);
final AdVerifications adVerifications = rootVastParser.getAdVerification(latestVastWrapperParser, adIndex);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getAdVerification only reads the last response, so wrapper-level <AdVerifications> (VAST 4.1+) are dropped. Please collect verifications from every Wrapper in the chain as well as from the selected InLine ad.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd leave this out of this PR. It's pre-existing, and it isn't about which Linear gets played:

  • Android's Wrapper model doesn't parse <AdVerifications> at all, only <Extensions>. Supporting it means new parsing code, plus merging the Verification lists along the chain.
  • iOS doesn't do it either. VastParser sets verificationParameters only on InLine ads, and VastResponse.copyTracking doesn't copy them from wrappers.

It's a gap on both platforms, so I'd rather track it in a separate issue that covers Android and iOS. Should I open one? The selected InLine ad's verifications are covered here: inlineAd(...) now gives each ad its own <AdVerifications>, and unplayableAdBeforePlayableAd asserts that the model gets ad 2's.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened as #1066 (Android) and prebid/prebid-mobile-ios#1456 (iOS), cross-linked. Both list the code paths involved and a fix sketch, and leave open whether a vendor that appears at several levels of the chain is loaded once or every time.

* and then we get its meduaFile URL.
*/
if (wrappedVASTXml != null) {
wrappedVASTXml.getMediaFileUrl(wrappedVASTXml, index);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This recursive call's result is discarded, and the comment above still says "meduaFile". The method is only called on the last parser, so it behaves correctly today, but please drop the dead recursion (or use its result) and fix the typo while you're here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in b1a8dc7. getMediaFileUrl now returns the recursive result. The selection itself moved to getBestMediaFile/findBestMediaFile, and the typo is gone.


String endCardHtml = result.creativeModels.get(1).getHtml();
assertTrue(endCardHtml.contains("https://example.com/companion-2.png"));
assertFalse(endCardHtml.contains("https://example.com/companion-1.png"));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please extend these tests:

  • Give the two Linears/ads different dimensions and assert videoModel.getWidth()/getHeight() match the played mp4 (here and in testMakeModels_unsupportedLinearBeforeSupportedLinear).
  • Add an <AdVerifications> per ad in inlineAd(...) and assert videoModel.getAdVerifications() is ad 2's, since the description lists verification among the per-ad values.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in b1a8dc7. Both tests use 720x1280 for the unplayable Linear and 1280x720 for the mp4 and assert the model size. unsupportedLinearBeforeSupportedLinear also asserts interstitialSize. inlineAd(...) now gives each ad its own <AdVerifications>, and unplayableAdBeforePlayableAd asserts the vendor and JS resource of ad 2.

New cases: companionBeforeLinear, wrapperAdAfterInlineAd, noSupportedMedia (now fails early, with the 403 Error URI) and linearWithoutDuration.

when(mockBidResponse.getWinningBid()).thenReturn(mock(Bid.class));
final InterstitialController mockInterstitialController = mock(InterstitialController.class);
PrebidMobilePluginRenderer fakePrebidRenderer = FakePrebidMobilePluginRenderer.getFakePrebidRenderer(mockInterstitialController, null, true, PREBID_MOBILE_RENDERER_NAME, "1.0");
// A renderer whose name is already registered is ignored, so replace it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit (and the matching InterstitialAdUnitTest change) is already on master through #1055/#1057, so it merges as a no-op. Please rebase and drop it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebased onto master (719370f1). Git dropped 0080027a as already upstream. The PR is now the original change (aba1d506) plus the review fixes (b1a8dc7a).

mdanylov-sigma and others added 2 commits November 30, 2026 13:51
AdResponseParserVast read each part of the video from a different
place. getMediaFileUrl returned null as soon as the first Linear had no
supported media file, even when a later one had. With several playable
Linears it picked the largest file across all of them, while the
duration, skip offset, trackers and clicks came from the first Linear.
Only the first ad of the response was looked at.

The video now comes from the first Linear with a supported media file,
in the first ad of the last response that has one. The duration, skip
offset, tracking events, click trackers and click-through come from
that Linear, and the impressions, Error URL, verification and companion
from that ad. Wrapper responses keep contributing their first ad.
Without a playable Linear the first one is used, as before.

Matches prebid-mobile-ios #1371.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…re, followed wrapper ad

- The video width/height come from the MediaFile that is played, parsed
  defensively, instead of ad 0 / creative 0 / media file 0. The ad-0
  getWidth()/getHeight() of AdResponseParserVast are removed.
- Without a playable Linear, CreativeModelsMakerVast fails right away with
  NO_SUPPORTED_MEDIA_ERROR and requests the Error URIs with 403, like
  CreativeFactory did later on. The first-Linear fallback is gone.
- A selected Linear without <Duration> fails with a clear message
  instead of an NPE.
- Wrapper responses contribute the Wrapper ad that VastParserExtractor
  followed (the first one with a VASTAdTagURI), not ad 0.
- getMediaFileUrl returns the recursive result instead of dropping it.
- Tests: sizes per Linear, AdVerifications from the selected ad, CompanionAds
  first, Wrapper after an InLine ad, no media, no Duration.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mdanylov-sigma
mdanylov-sigma force-pushed the claude/android-parity-ios-1371 branch from 0080027 to b1a8dc7 Compare November 30, 2026 12:12
@mdanylov-sigma

Copy link
Copy Markdown
Collaborator Author

@YuriyVelichkoPI thanks for the review. Everything is in b1a8dc7, rebased onto master. Details are in the inline replies:

  1. Size: taken from the MediaFile that is played. The ad-0 getters are removed.
  2. Missing <Duration>: fails with a clear message instead of an NPE.
  3. Wrapper ad index: each wrapper response contributes the Wrapper ad that was followed.
  4. Wrapper-level <AdVerifications>: I'd keep this separate. Android's Wrapper doesn't parse them, and iOS doesn't collect them either. The inline reply has the details, and I can open an issue for both platforms.
  5. Early "no valid media": added. CreativeModelsMakerVast checks whether any ad of the last response has a playable Linear before reading the duration or the size. If none does, it requests the Error URIs with 403 through VideoCreativeModel.trackVastError and fails with the same NO_SUPPORTED_MEDIA_ERROR message CreativeFactory gave. The URIs are requested once, since no model reaches the factory. The factory check stays as a safety net. Test: noSupportedMedia.
  6. Tests: added as asked, plus companionBeforeLinear, wrapperAdAfterInlineAd and linearWithoutDuration.
  7. getMediaFileUrl: the recursion result is used now, and the typo is fixed.
  8. Rebase: done. 0080027a was dropped as already upstream.

./gradlew PrebidMobile-core:testReleaseUnitTest: 1710 tests, 0 failures. 8 of the 9 new CreativeModelsMakerVastTest cases fail against master's parser and maker. The PR description is updated to match.

@YuriyVelichkoPI YuriyVelichkoPI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick turnaround. Nearly everything from the last round is in:

  • The size now follows the played media file. I re-ran my JS 720x1280 → mp4 1280x720 probe, and it now gives 1280x720 / "1280x720" in both the same-ad and the second-ad case.
  • The early no-media failure keeps master's error type and message, and fires the Error URIs once with 403.
  • getFollowedWrapperAdIndex keeps getAdIndex and getVastUrl() in sync at every level of the chain.
  • The tests now show where each value comes from.

On the wrapper-level <AdVerifications>: agreed, it's pre-existing and separate from Linear selection, and #1066 / prebid/prebid-mobile-ios#1456 describe it well. Happy to defer it there.

One thing before merge: the Duration fix also rejects an empty <Duration>, and those ads load and play on master (duration -1 = unknown). Details inline. It's a one-line change.

I ran CreativeModelsMakerVastTest plus the rendering.parser, rendering.loading and rendering.video tests on b1a8dc7a: 168 tests, 0 failures. The branch merges cleanly onto current master.

final String skipOffset = latestVastWrapperParser.getSkipOffset(latestVastWrapperParser, adIndex);
final AdVerifications adVerifications = rootVastParser.getAdVerification(latestVastWrapperParser, adIndex);

if (Utils.isBlank(videoDuration)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isBlank also catches <Duration></Duration>, <Duration/> and whitespace-only values, because readText returns "" for them. On master those loaded: Utils.getMsFrom("") returns -1, the player treats that as "unknown" (AdViewProgressUpdateTask skips the VAST-duration cut-off), and the ad played. I checked with a probe on both heads: master loads all three with mediaDuration=-1, and this branch fails them with "the Linear creative has no Duration".

Could this be videoDuration == null, so that only a missing element fails? Please also add a test that an empty <Duration></Duration> loads.

If you'd rather reject empty durations on purpose (iOS rejects duration ≤ 0), that's fine too. In that case, please list it under "Differences" and add a test asserting the failure. Right now it's an unannounced behaviour change, and it doesn't match "00:00:00 still loads".

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks. Fixed in 8c26f2b. The check is now videoDuration == null, so only a missing <Duration> element fails. <Duration></Duration>, <Duration/> and a whitespace-only value load as on master, with mediaDuration=-1. The new linearWithEmptyDuration test covers all three. I kept master's behavior instead of following iOS's ≤ 0 rule, so nothing changes for those ads.

Only a missing <Duration> element fails the load. An empty or
whitespace-only one loads as on master, with the duration unknown (-1).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@YuriyVelichkoPI YuriyVelichkoPI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants