Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support changing ad break positions #5067

Closed
Romantic-LiXuefeng opened this issue Nov 7, 2018 · 6 comments
Closed

Support changing ad break positions #5067

Romantic-LiXuefeng opened this issue Nov 7, 2018 · 6 comments

Comments

@Romantic-LiXuefeng
Copy link

This is reproducible as below configured in the media.exolist.json.
{
"name": "VMAP pre-, mid- and post-rolls, single ads",
"uri": "http://192.168.75.251:8081/test/hls/multirate/multirate.m3u8",
"ad_tag_uri": "https://pubads.g.doubleclick.net/gampad/ads?sz=640x480&iu=/124319096/external/ad_rule_samples&ciu_szs=300x250&ad_rule=1&impl=s&gdfp_req=1&env=vp&output=vmap&unviewed_position_start=1&cust_params=deployment%3Ddevsite%26sample_ar%3Dpremidpost&cmsid=496&vid=short_onecue&correlator="
},

@tonihei
Copy link
Collaborator

tonihei commented Nov 7, 2018

The midroll position is defined in the data of your ad tag uri (at 15 seconds in the example you provided).

If your question is related to configure the server to generate these ad tags, that goes beyond what we can answer here. I suppose the server should know the content duration before generating ad tags for it. @andrewlewis may be able to clarify if that's wrong.

If the problem is that you don't control the content but need to know the duration before constructing the AdsMediaSource, then it's just not possible without loading at least some part of the media. We plan to release a metadata extractor some time soon which helps you with that. Until then, you can just prepare the media without ads in the background and wait until the duration becomes known.

@tonihei tonihei self-assigned this Nov 7, 2018
@Romantic-LiXuefeng
Copy link
Author

Romantic-LiXuefeng commented Nov 7, 2018

@tonihei This is my use case:
Our Ad server and content server is separate, the ad server can't get the content duration advance. the ad server only provide the pre_ad ,mid_ad,post_ad 's url and duration. Where to insert the mid_ad
is decided by the player. But we can't new the AdPlaybackState if we don't known the mid_ad insert position.
This is my test code:

  1. I used a FixedAdsLoader that configure the play ads from given URLs known in advance. I just use the C.TIME_UNSET as the mid_ad place holder

// init the ad playback state with adGroupTimesUs
adPlaybackState = new AdPlaybackState(0, C.TIME_UNSET);
// add the uri of the first ad of the pre_ad group
adPlaybackState = adPlaybackState.withAdUri(0, 0, Uri.parse("www.xxx.com/test.m3u8"));
// add the uri of the first ad of the mid_ad group
adPlaybackState = adPlaybackState.withAdUri(1, 0, Uri.parse("https:www.xxx.com/dizzy.mp4"));
// pass to AdsLoader.EventListener
updateAdPlaybackState();

  1. prepare the media without ads in the background and wait until the duration becomes known.
  2. when onTimelineChanged() the content duration is known, we update the mid_ad group timeUS.

Modifying the code like this, we are not sure if it will affect the playback process of the player. Help you give some advice.
questions:
If the mid_ad insert position is less than the player buffer position.Will it cause problems?

@tonihei
Copy link
Collaborator

tonihei commented Nov 7, 2018

Thanks for the clarification.

Using C.TIME_UNSET as the ad group position is probably not a good idea because we don't support that in the player. Also, we currently don't support changing the ad position dynamically. However, we are planning to add support for this soon anyway and we can use this issue to track this.

Besides that, you could try to wrap the content source in a another media source which lets you access the content timeline: new AdsMediaSource(new WrapperSource(contentMediaSource), ...)
The wrapper source can implemented similar to the deprecated ImaAdsMediaSource but with a custom callback or access method to the timeline of content source. That allows you to wait until the content timeline is ready (but before the final timeline is published) and to create the AdPlaybackState only then.

@Romantic-LiXuefeng
Copy link
Author

@tonihei As you said, i custom a wrapper source to container the content media source.

@OverRide
public void onSourceInfoRefreshed(MediaSource source, Timeline timeline, Object manifest) {
Assertions.checkArgument(timeline.getPeriodCount() == 1);
long durationUs = timeline.getWindow(0,new Timeline.Window()).durationUs;
if (durationUs != C.TIME_UNSET){
Log.e(TAG,"the content duration = [" + durationUs + "]");
refreshSourceInfo(timeline, manifest);
}else {
// wait the content duration
Log.e(TAG,"the content duration has not known");
}
}
#######
In the callback {onSourceInfoRefreshed}, The HLS format could get the durations when the callback was called, but the mp4 format could get the duration. Is there any way to get the ExtractMediaSource duration ?

@tonihei
Copy link
Collaborator

tonihei commented Nov 8, 2018

Is there any way to get the ExtractMediaSource duration?

Not yet, sorry. This is an enhancement currently tracked by #4727.

@tonihei tonihei changed the title Question: Before the content has been played, I can't get the duration of the content,how to decide the mid ad insert position? Support changing ad break positions Feb 8, 2019
kim-vde pushed a commit that referenced this issue May 11, 2021
The player already supports changing durations of periods and ads.
The only thing not yet supported is a change in ad break positions
which changes the duration of clipped content ending in an ad break.

Adding support for this requires updating the end position in
MediaPeriodInfo and changing the clip end position of the respective
ClippingMediaPeriod.

Issue: #5067
PiperOrigin-RevId: 373139724
@christosts
Copy link
Contributor

christosts commented Aug 9, 2021

Closing issue as it has been marked fixed in 08fb7bd. The commit will be included in release 2.15.0

@google google locked and limited conversation to collaborators Oct 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants