Repository navigation
Render the first playable Linear creative of a VAST response - #1034
mdanylov-sigma wants to merge 3 commits into
Conversation
d569758 to
d38aae7
Compare
YuriyVelichkoPI
left a comment
There was a problem hiding this comment.
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.
- 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). WithLinear#1= JS 720x1280 andLinear#2= mp4 1280x720, the mp4 plays, but the model reports 720x1280.setInterstitialSize("720x1280")then matchesVERTICAL_720x1280and 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. getVideoDurationNPE. A selected Linear without<Duration>throws, and the load fails with "Video failed: null".- Wrapper responses always contribute ad 0 (
getAdIndex), whileVastParserExtractorfollows the first Ad that has aWrapper. If a wrapper response has an InLine ad 0 and the Wrapper at ad 1, impressions and trackers come from the wrong ad. - Wrapper-level
<AdVerifications>(VAST 4.1+) are ignored. Only the last response is read. - 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.
- Tests: assert the size in
unsupportedLinearBeforeSupportedLinear/unplayableAdBeforePlayableAd, using different dimensions per Linear, and assert thatAdVerificationscomes from the selected ad. - Cleanup in
getMediaFileUrl: the wrapper branch discards the recursive result, and there's a "meduaFile" typo. - 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)); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I'd leave this out of this PR. It's pre-existing, and it isn't about which Linear gets played:
- Android's
Wrappermodel doesn't parse<AdVerifications>at all, only<Extensions>. Supporting it means new parsing code, plus merging theVerificationlists along the chain. - iOS doesn't do it either.
VastParsersetsverificationParametersonly on InLine ads, andVastResponse.copyTrackingdoesn'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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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")); |
There was a problem hiding this comment.
Please extend these tests:
- Give the two Linears/ads different dimensions and assert
videoModel.getWidth()/getHeight()match the played mp4 (here and intestMakeModels_unsupportedLinearBeforeSupportedLinear). - Add an
<AdVerifications>per ad ininlineAd(...)and assertvideoModel.getAdVerifications()is ad 2's, since the description lists verification among the per-ad values.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Rebased onto master (719370f1). Git dropped 0080027a as already upstream. The PR is now the original change (aba1d506) plus the review fixes (b1a8dc7a).
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>
0080027 to
b1a8dc7
Compare
|
@YuriyVelichkoPI thanks for the review. Everything is in b1a8dc7, rebased onto master. Details are in the inline replies:
|
YuriyVelichkoPI
left a comment
There was a problem hiding this comment.
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.
getFollowedWrapperAdIndexkeepsgetAdIndexandgetVastUrl()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)) { |
There was a problem hiding this comment.
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".
There was a problem hiding this comment.
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>
Android counterpart of prebid/prebid-mobile-ios#1371 (issue prebid/prebid-mobile-ios#1370), which notes that
AdResponseParserVast.getMediaFileUrlhas the same first-Linear behavior.Problem
AdResponseParserVastreads each part of the video from a different place:getMediaFileUrlreturns null as soon as the first Linear creative has no supported media file, even when a later Linear has one.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.CreativeModelsMakerVastpasses ad index0to every helper, so only the first ad of the response is looked at.Results through
CreativeModelsMakerVaston master:mediaUrl=nulland the duration of the unsupported Linear. The load then fails inCreativeFactorywith "Could not find MediaFile that is supported by this video player…"mediaUrl=null, impression, Error URL and companion from the first adThe 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
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.getPlayableAdIndex(): the first ad of the last response with a playable Linear, or 0 if there is none.CreativeModelsMakerVastpasses it instead of0, so the impressions, Error URL, verification and companion come from that ad too.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-0getWidth()/getHeight()are removed.CreativeModelsMakerVastfails before it reads the duration or the size. It requests the Error URIs with 403 and fails with the sameNO_SUPPORTED_MEDIA_ERRORmessage thatCreativeFactorygave later on master (iOS: "No Valid Media"). TheCreativeFactorycheck stays as a safety net.<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).getImpressions,getAllTrackings,getClickTrackings, andgetErrorUrlsfrom 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 thatVastParserExtractorfollowed: the first one with aVASTAdTagURI, the same lookupgetVastUrl()uses. Before, it was always ad 0.Differences from before and from iOS
00:00:00, as before.<AdVerifications>(VAST 4.1) are not collected, same as on iOS: only the selected InLine ad's verifications are used. Android'sWrappermodel doesn't parse them. That gap exists on both platforms and is tracked in VAST: Wrapper-level<AdVerifications>are never loaded into the Open Measurement session #1066 and VAST: Wrapper-level<AdVerifications>are never loaded into the Open Measurement session prebid-mobile-ios#1456.VideoCreativeModel.auidstill comes from the first ad of the root response. Nothing reads it.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:unsupportedLinearBeforeSupportedLinearmediaUrl=null, 10s, 720x1280starttracker, click tracker and click-through of the mp4 LinearsupportedLinearBeforeUnsupportedLineartwoPlayableLinearsunplayableAdBeforePlayableAdmediaUrl=null, everything from ad 1wrapperThenPlayableSecondAdmediaUrl=nullwrapperAdAfterInlineAdcompanionBeforeLinearnoSupportedMediamediaUrl=nullNO_SUPPORTED_MEDIA_ERROR, Error URI requested with 403linearWithoutDurationlinearWithEmptyDuration-1-1AdResponseParserVastandCreativeModelsMakerVast.supportedLinearBeforeUnsupportedLinearandlinearWithEmptyDurationassert behavior that stays the same./gradlew PrebidMobile-core:testReleaseUnitTestat8c26f2ba(based on master719370f1): 1711 tests, 0 failuresIndependent of #1033 (VAST no-ad Error URIs): the two PRs touch different code and can merge in either order.
🤖 Generated with Claude Code