119 Commits

Author SHA1 Message Date
tonihei
47021c8777 Account for missing preroll when converting adPodIndex to adGroupIndex
IMA always starts midrolls at index 1. So if there is no preroll ad,
the ad group index in AdPlaybackState is off by 1 all the time, and
may also lead to ArrayIndexOutOfBoundsExceptions when trying to access
the last midroll ad

Issue: androidx/media#1741
PiperOrigin-RevId: 682324368
2024-10-04 08:11:04 -07:00
Gaëtan Muller
71b8c32a6f Remove Multidex 2024-07-24 16:17:00 +01:00
tonihei
50f9f35353 Guard timeline access in ImaSSAIMS against empty timelines
All methods check if the player is currently handling the ad source
by calling isCurrentAdPlaying(). This method was missing a check
for empty timelines that throws an exception when trying to access
a non-existent period.

Also add this check to two methods that assume the current item
is the ads source, but didn't check it yet.

PiperOrigin-RevId: 653963557
2024-07-19 04:27:36 -07:00
ibaker
f554c12099 Remove Bundleable type & Bundleable.Creator<Foo> CREATOR fields
This interface is not used in the library. Callers can use the
`Bundle toBundle()` and `static Foo fromBundle(Bundle)` methods
defined directly on each type instead.

PiperOrigin-RevId: 642271609
2024-06-11 08:05:32 -07:00
ibaker
861e8218c0 Bump IMA dependency to 3.33.0 to fix NPE with data:// URIs
Issue: androidx/media#700
PiperOrigin-RevId: 632135478
2024-05-09 06:59:53 -07:00
tonihei
7cf2fd9486 Postpone AdTagLoader listener deregistration to receive final error
When the AdTagLoader is deactivated because of a player error, the
error callback is already pending on the app's main thread, but not
yet executed. This means the VideoAdPlayerCallback instances
registered in AdTagLoader won't receive this error event if the
Player.Listener is immediately removed from AdTagLoader.

This can be fixed by postponing the deregistration until after
already pending messages have been handled. As this means other
callbacks can be triggered now with player==null, this check needs
to be added to other callbacks to avoid handling stale events.

Issue: androidx/media#1334
PiperOrigin-RevId: 630068222
2024-05-02 08:19:04 -07:00
bachinger
e866cb02d6 Make replaceAdTagParameters unstable API for now
PiperOrigin-RevId: 627323264
2024-04-23 03:04:51 -07:00
Googler
a43ffa8898 Add replaceAdTagParameters() to ImaServerSideAdInsertion.AdsLoader.
PiperOrigin-RevId: 627114711
2024-04-22 12:09:59 -07:00
bachinger
09f2cda43c Promote IMA DAI API to stable
PiperOrigin-RevId: 626064956
2024-04-18 09:49:48 -07:00
bachinger
4777d62d31 Rollback of 8e2869278c
PiperOrigin-RevId: 607264513
2024-02-15 02:35:12 -08:00
asinclair
8e2869278c Internal Cleanup
PiperOrigin-RevId: 607117264
2024-02-14 15:06:10 -08:00
tonihei
ed5b7004b4 Replace or suppress deprecated usages
Many usages are needed to support other deprecations and some
can be replaced by the recommended direct alternative.

Also replace links to deprecated/redirected dev site

PiperOrigin-RevId: 601795998
2024-01-26 10:06:18 -08:00
Googler
807d98a3d6 Update IMA README to include link to supported platforms
PiperOrigin-RevId: 601720412
2024-01-26 03:44:24 -08:00
tonihei
9bf1852069 Set MIME type from IMA SDK on ads MediaItem
This helps to play ads where the file extension is not sufficient
to deduce the correct source in DefaultMediaSourceFactory.

PiperOrigin-RevId: 582340114
2023-11-14 09:12:07 -08:00
tonihei
03a23bef8f Use full MediaItem to define ad playbacks
Currently, ads are only defined by a single URL, which makes it
impossible to define additional fields needed to play ads correctly.

This can be fixed by using a full MediaItem in AdPlaybackState,
replacing the previous Uri field.

PiperOrigin-RevId: 582331588
2023-11-14 08:35:14 -08:00
tonihei
312203d38b Deprecate Bundleable and Bundleable.Creator
Both interfaces are not really needed as the methods can be called
on the respective classes directly. This also avoid error-prone
situations where classes define to/fromBundle methods with parameters
that should be used instead of the parameter-less version.

Also deprecate all existing CREATOR static instances and make the
corresponding fromBundle method public where needed.

PiperOrigin-RevId: 579189766
2023-11-03 08:27:21 -07:00
rohks
b4d03a9515 Bump IMA SDK version to 3.31.0
#minor-change

PiperOrigin-RevId: 567282094
2023-09-21 05:54:13 -07:00
bachinger
3911c9d0c7 Add StreamEventListener for IMA SSAI source
Issue: androidx/media#555
PiperOrigin-RevId: 561711428
2023-08-31 11:29:29 -07:00
Googler
4c3ad641c0 Release StreamManager before calling AdsLoader.destroy()
PiperOrigin-RevId: 561678438
2023-08-31 09:37:27 -07:00
tonihei
7899241daf Fix period indexing for multi-period DASH DAI live streams
The period index was calculated relative to the contentTimeline
of the DAI stream, but then used with the full timeline of the
player. This means it currently only works when the stream is the
only or first item in the playlist.

Issue: androidx/media#571
PiperOrigin-RevId: 560023412
2023-08-25 02:05:46 -07:00
bachinger
2386b7e944 Some JavaDoc fixes in ImaServerSideAdInsertionMediaSource
Issue: androidx/media#555
PiperOrigin-RevId: 558097690
2023-08-18 15:25:41 +01:00
rohks
38eabdc9fc Bump IMA SDK version to 3.30.3
#minor-change

PiperOrigin-RevId: 555130308
2023-08-10 12:18:00 +00:00
tonihei
20d2ce7ce8 Verify source is not released before updating ad playback state
Updates to the ad playback state are posted on the main handler,
so they may arrive after the source has already been released
(=the internal MediaSource is null). This can cause NPEs.

PiperOrigin-RevId: 555102426
2023-08-10 12:13:12 +00:00
tonihei
3d4bd7ce19 Make MediaItems updateable
This changes all MediaSources in our library to allow updates to
their MediaItems (if supported).

Issue: google/ExoPlayer#9978
Issue: androidx/media#33
PiperOrigin-RevId: 546808812
2023-07-13 15:26:30 +01:00
tonihei
2322462404 Do not trim audio samples by changing their timestamp
MP4 edit lists sometimes ask to start playback between two samples.
If this happens, we currently change the timestamp of the first
sample to zero to trim it (e.g. to display the first frame for a
slightly shorter period of time). However, we can't do this to audio
samples are they have an inherent duration and trimming them this
way is not possible.

#minor-release

PiperOrigin-RevId: 543420218
2023-06-29 22:50:04 +00:00
bachinger
cd604e7ead Fix splitting ad playback state for partial ad group when joining
This change addresses the case when the user joins the live stream
on an ad period but the metadata for the ad period is not emitted.
This results in inserting a partial ad group.

In this case the ad group duration is longer than the partial ad
group. If now the partial ad group ends at the period before the
last period of the window (unknown duration), the splitting algorithm
didn't recognize that the ad group already ended and made the last
period wrongly an ad period.

This change handles this edge case by counting the mapped ads in
the partial ad group to detect this situation and stops splitting.

#minor-release

PiperOrigin-RevId: 539102785
2023-06-10 20:23:56 +00:00
bachinger
a67ce066df Enable re-preparing the ImaSSAIMediaSource
#minor-release

PiperOrigin-RevId: 538927855
2023-06-09 13:59:59 +00:00
ibaker
7e6dae7b31 Remove exoplayer2-only javadoc machinery from media3
This introduces whitespace-only changes in exoplayer2 due to the way
copybara stripping works.

PiperOrigin-RevId: 537296933
2023-06-05 09:47:58 +00:00
ibaker
d5f9cf4f19 Add singleVariant publishing config to all published gradle files
Docs:
* https://developer.android.com/build/publish-library/configure-pub-variants#single-pub-var
* https://developer.android.com/reference/tools/gradle-api/8.0/com/android/build/api/dsl/PublishingOptions

This resolves the following warning from Android Gradle Plugin 7.2.2 and
helps unblock the upgrade to AGP 8.0.1:

> Software Components will not be created automatically for Maven
> publishing from Android Gradle Plugin 8.0. To opt-in to the future
> behavior, set the Gradle property
> `android.disableAutomaticComponentCreation=true` in the
> `gradle.properties` file or use the new publishing DSL.
>
> Affected Modules: `lib-cast`, `lib-common`, `lib-container`,
> `lib-database`, `lib-datasource`, `lib-datasource-cronet`,
> `lib-datasource-okhttp`, `lib-datasource-rtmp`, `lib-decoder`,
> `lib-effect`, `lib-exoplayer`, `lib-exoplayer-all (legacy)`,
> `lib-exoplayer-dash`, `lib-exoplayer-hls`, `lib-exoplayer-ima`,
> `lib-exoplayer-rtsp`, `lib-exoplayer-smoothstreaming`,
> `lib-exoplayer-workmanager`, `lib-extractor`, `lib-media2 (legacy)`,
> `lib-mediasession (legacy)`, `lib-muxer`, `lib-session`,
> `lib-transformer`, `lib-ui`, `lib-ui-leanback`, `test-utils`,
> `test-utils-robolectric`

Issue: androidx/media#409
PiperOrigin-RevId: 533464133
2023-05-19 17:22:21 +01:00
ibaker
b3db85133a Add android.namespace to all build.gradle files
This is a pre-requisite for the Android Studio upgrade assistant to
upgrade from AGP 7.2.2 to 8.0.1, otherwise it fails and complains
this is missing.

Issue: androidx/media#409
PiperOrigin-RevId: 533463246
2023-05-19 17:19:15 +01:00
bachinger
dab1353aad Enable live DASH stream for IMA DAI
This change enables the IMA extension to play live DASH streams
with DAI support. Samples streams can be found and played in the
main demo app.

Issue: google/ExoPlayer#10912
#minor-release
PiperOrigin-RevId: 532407708
2023-05-17 08:38:06 +01:00
bachinger
511b1358cd Downgrade IMA SDK to 3.29.0
#minor-release

PiperOrigin-RevId: 529710928
2023-05-05 16:53:06 +00:00
tonihei
889f435a49 Update dependencies to latest versions
The only dependencies that are not updated are the ones that need
to be kept in sync with other system (like Android source tree) or
would require a Kotlin dependency in common or exoplayer modules.

As a side effect, some demo apps now need a Kotlin config and some
additional modules require desugaring/multidex logic. To simplify
the setup, the desugaring and multidex steps are added to the common
config.

PiperOrigin-RevId: 527243950
2023-04-26 15:49:57 +01:00
bachinger
85fb32d70f Use withLivePostrollPlaeholderAppended to add placeholder
PiperOrigin-RevId: 525177113
2023-04-18 18:14:32 +01:00
ibaker
b834e49f9f Use @link instead of @value
Dackka doesn't support `@value`

#minor-release

PiperOrigin-RevId: 524309695
2023-04-17 17:10:49 +01:00
bachinger
76e195ff5a Correct ad durations when timeline moves more than a single period
This change improves `ImaUtil.maybeCorrectPreviouslyUnknownAdDuration` to
handles the case when the timeline moves forward more than a single period
while an ad group with unknown period duration is being played.

PiperOrigin-RevId: 522292612
2023-04-11 10:30:27 +01:00
bachinger
e4194fc862 Make period durations of FakeMultiPeriodLiveTimeline configurable
PiperOrigin-RevId: 522046876
2023-04-05 15:27:31 +01:00
bachinger
e6b9bde1dd Use SKIPPED ad status when a playing ad period has been removed
PiperOrigin-RevId: 521476767
2023-04-05 15:43:17 +01:00
bachinger
95e0763ef1 Add live ad breaks for DASH multi-period streams
This includes:

- Add an ad for each LOADED event of the SDK by taking the duration
  of the ad from the media structure to exactly match the start position
  of ads and then use `addLiveAdBreak()` that is used for HLS live already.
- When the refreshed content timeline arrives, possibly correct
  the duration of an ad that has been inserted while the period duration was
  still unknown (last period of the live timeline).
- When an ad period is removed the ad group needs to be put into a condition
  that allows continuing playback.

PiperOrigin-RevId: 520919236
2023-04-05 15:39:11 +01:00
rohks
766e7d7d35 Add media3 guide entries in README files
PiperOrigin-RevId: 520650881
2023-03-30 17:28:03 +00:00
rohks
6a928805d4 Fix javadoc links in media README files
Also fixed the javadoc link in devsite and removed javadoc links from decoder extensions as it is not published yet on developer.android.com.

#minor-release

PiperOrigin-RevId: 520636868
2023-03-30 17:26:40 +00:00
bachinger
f599a9b8f9 Keep content timeline and ad playback states together
For multi-period live streams the content timeline for
which the global ad playback state has been split needs
to be kept together to not run into a race between
timeline refreshes and ad events.

PiperOrigin-RevId: 520358964
2023-03-30 17:23:14 +00:00
bachinger
331d5479e6 Do not use content timeline to calculate current position
In multi-period live streams, we can't use the content timeline if we want to
lookup a period from the public timeline by index or uid because it may be
that the content timeline has already been refreshed in the
`ImaServerSideAdInsertionMediaSource` but hasn't yet arrived in `ExoPlayerImpl`.

This change is taking the current position that needs to be reported
to the SDK every 200ms is not relying on the content timeline.

PiperOrigin-RevId: 520328126
2023-03-30 17:21:55 +00:00
tonihei
6952771e2f Remove remaining references to exoplayer.dev
PiperOrigin-RevId: 520314781
2023-03-30 17:20:36 +00:00
bachinger
0a2a20d4fb Skip played live ad media periods
This change makes sure that live ad periods that are played are
skip when attempted to be added to the queue. To make this work
the existing filter logic had to be take into account the content
resume offset that live periods use.

PiperOrigin-RevId: 518068138
2023-03-21 14:20:43 +00:00
bachinger
d1534680e9 Support splitting the ad playback state for live streams
This change does basically three things in preparation of a follow
up CL that will insert ad breaks into multi-period live windows.

- Make sure that only `AdPlaybackState`s of multi-period streams
  are passed to `ImaUtil.splitAdPlaybackStateForPeriods()` from
  the media source.
- Enhance the splitting algorithm in ImaUtil to support live windows.
  Roughly, this includes calculating the window start position in the
  UNIX epoch context, handling the end period with an unknown duration
  and taking the `adResumePosition` of an ad group into account that
  affects the ad group start positions (`adGroup.timeUs`).
- Append a placeholder postroll ad group to the ad playback state of
  each period in a live stream to allow immediate transition to an
  ad that's inserted by an ad event from the SDK.

PiperOrigin-RevId: 516167958
2023-03-14 07:52:58 +00:00
bachinger
c0a8b944a6 Use the ad group time as content position while playing an ad
The value returned by `player.getContentPosition()` is calculated
in the timeline based on the position of the first period in the
window. In a single period live stream this position is advanced
when the live window advances on timeline refresh.

This calculation has produced slightly varying values below 1000
us which are likely caused by us/ms truncations for public API
values that we use in the IMASSAIMediaSource.

However, `AdGroup.timeUs` is the (recorded) content position at the
moment when the first ad of the an ad group has been inserted. While
playing an ad, we can always use this value instead of
`getContentPosition()` to not require recalculation.

#minor-release

PiperOrigin-RevId: 515093177
2023-03-14 07:45:41 +00:00
bachinger
51929625cf Add ad event listeners in the Looper event of the ad manager callback
#minor-release

PiperOrigin-RevId: 509189206
2023-02-13 12:26:04 +00:00
bachinger
afa3c628c1 Create an AdEventListener for each supported stream type
This is a refactoring to separate and simplify the logic
of VOD and live streams when handling IMA ad events. An
additional listener will be required for DASH live stream
in a follow-up CL.

PiperOrigin-RevId: 507435741
2023-02-08 14:00:33 +00:00
christosts
5f6e172c8f Suppress warnings in ImaUtil
ImaUtil calls VideoProgressUpdate.equals() which is annotated as hidden,
which causes lint errors with gradle.

#minor-release

PiperOrigin-RevId: 504306210
2023-01-25 18:41:55 +00:00