4556 Commits

Author SHA1 Message Date
Andrew Lewis
e58ffc0682 Merge pull request #9893 from moneytoo:mkv-vtt
PiperOrigin-RevId: 424382031
2022-01-28 09:33:35 +00:00
tonihei
caa0a09c2f Finish pending session if there is one before creating a new one.
PiperOrigin-RevId: 423819515
2022-01-25 19:45:46 +00:00
kimvde
5e583d34ee Fix Javadoc formatting
#minor-release

PiperOrigin-RevId: 423314840
2022-01-25 19:37:38 +00:00
bachinger
e2cf266b1c Set the next live ad in ad group to avoid rebuffering
To avoid the `MediaPeriodQueue`to discard the reading period, we can set the next ad of an ad group early and then (possibly) only change it's duration once we receive the actual duration. This way we avoid a rebuffering as a result of the reading period being discarded.

The change also takes care to properly set ad break and their durations when we join the live stream at the moment when an ad is playing.

PiperOrigin-RevId: 423163467
2022-01-25 19:17:42 +00:00
tonihei
7c60e67f84 End finished sessions on timeline updates.
We currently only end sessions on Timeline updates if the associated media
is no longer in the playlist. But we should also end all sessions that are
finished as a result of the timeline update (similar to how this is done for
discontinuities). This issue was introduced by 394ab7bcfd

PiperOrigin-RevId: 423075855
2022-01-25 19:13:49 +00:00
tonihei
301fcd649a Ensure network transfers are associated with the right session
We currently don't check which session is causing a network transfer
(it could be a preloaded item in a playlist). To clearly associate
network transfer data with sessions, we need to keep track of
transferred bytes and transfer time per session.

PiperOrigin-RevId: 422867845
2022-01-25 19:05:44 +00:00
christosts
4502a1ee63 Extend support for audio spatialization in MediaCodecAudioRenderer
With this change, the MediaCodecAudioRenderer configures the MediaCodec
to not downmix audio only if spatialization can be applied. This way,
decoders who are downmixing by default are left doing so when
spatialization cannot be applied. The renderer re-initializes the codec
when spatialization properties change mid-playback.

PiperOrigin-RevId: 422822952
2022-01-25 18:57:50 +00:00
tonihei
b2ecce4d07 Reset some state values when a session is finished.
Currently, we keep the values for dropped/played frames, audio underruns
and current formats from the last session, causing double reporting
of counters and wrong track change reasons for formats. All these
values should be reset when the active session is finished, so that the
new session can start from scratch.

PiperOrigin-RevId: 422798406
2022-01-25 18:49:27 +00:00
tonihei
d15350ab01 Avoid ending session early if an unrelated other session is finished
Currently, we always end the current session if onSessionFinished is
called. However, the finished session may not be the active one (for
example when discarding prebuffered items in a playlist). To make this
code more robust, we can save the active session id explicitly and only
end this session.

PiperOrigin-RevId: 422788542
2022-01-25 18:45:28 +00:00
bachinger
7ba79cfa42 Split ad playback state and recalculate window and period duriations
This change enables the ImaServerSideAdInsertionMediaSource for multi-period content. The global ad playback state is split into pieces for each period and the window and period durations are calculated accordingly in the ServerSideAdInsertionTimeline.

For multi-period live content (DASH), the ad playback state is not set with this change. This is deferred to a follow up CL. Splitting is very tricky. For each timeline update the windowStartTimeUs may vary for some milliseconds relative to the start of the period.positionInWindowUs. This requires to either introduce some fuzzy logic or to choose a different approach than for multi-period VOD. Because mistakes within the playback states of subsequent moving live windows produces crashes, it seems sensible to defer this for now and keep this change in a separate future CL (unblock further work, easy to rollback).

In this state, live DASH stream are working and the ad overlay is placed over the player correctly bu the SDK. However, ads are not reported by the position discontinuity event. Similarly, the player.isPlayingAd() does never returns true when a ad period is playing.

PiperOrigin-RevId: 422539770
2022-01-25 18:23:00 +00:00
aquilescanta
25a362ec67 Remove last SampleQueue.release allocation
By making AllocationNode fields non-final

PiperOrigin-RevId: 422403816
2022-01-25 18:10:29 +00:00
tonihei
789b574be1 Use Util method to infer stream type instead of just mime type.
The MediaMetricsListener currently just looks at the mime type and
doesn't use the inference based on the URI if no mime type is set.

Also change default type to OTHER to avoid classifying streams from
URLs without clear file extension as progressive.

PiperOrigin-RevId: 422373381
2022-01-25 17:57:54 +00:00
tonihei
b3981be8b9 Limit adaptive selections to same level of decoder support
Adaptive video and audio selections will be limited to formats with
the same level of DecoderSupport and HardwareAccelatationSupport, unless
specifically allowed by new flags.

If different levels of decoder support are available, prefer primary
over fallback decoders and hardware-accelerated over software decoders
(in this order). For video, also prefer more efficient codecs, if both
are supported by hardware-accelerated primary decoders.

Issue: google/ExoPlayer#4835
Issue: google/ExoPlayer#9565
PiperOrigin-RevId: 422345048
2022-01-17 14:40:57 +00:00
tonihei
327ec97e58 Reorder adaptive video track preferences.
This change moves the video track selection to the generic
selection method introcuced for audio and text. This ensures
we can apply the same criteria for fixed and adaptive video
track selections. Implicitly, this reorders the preferences
for adaptive tracks to give non-quality preferences (like
preferred MIME type or preferred role flags) a higher priority
than number of tracks in the selection.

Issue: google/ExoPlayer#9519
PiperOrigin-RevId: 422310902
2022-01-17 14:20:21 +00:00
tonihei
3f47da1fd6 Reset readingPositionUs in BaseRenderer.enable
This does currently only happen by chance in replaceStream (called from
enable) if the stream previosly played read until C.TIME_END_OF_SOURCE.

enable already makes all changes done in resetPosition (except resetting
the reading position), so it's less error-prone and makes the intention
clearer if the same code is called from both enable and resetPosition.

The effect of this bug was quite limited because the numerical value
of readingPositionUs was only relevant for periods with changing
durations and server-side inserted ads.

PiperOrigin-RevId: 422300690
2022-01-17 14:15:48 +00:00
olly
d0c13733e4 Don't sample VSYNC when not started
PiperOrigin-RevId: 421855453
2022-01-17 14:11:04 +00:00
tonihei
d2d6227188 De-duplicate track selection code.
We currently run (almost) the same code for all track types.
De-duplicate this by using a single method that takes functional
interfaces for track-type dependent logic.

This has the benefit that all track-type dependent logic is
contained within their subclasses and the generic logic doesn't
need to make any assumption about the eligibility of tracks for
selection or adaptation, and doesn't need to access Parameters.

Make this change for audio and text only for now. Video can
be updated in a subsequent change.

PiperOrigin-RevId: 421811411
2022-01-17 13:51:18 +00:00
ibaker
a01ead0283 Fix deprecation suppression in RendererCapabilities
This string is case-sensitive.

PiperOrigin-RevId: 421781437
2022-01-14 15:26:18 +00:00
ibaker
a36e0cf255 Promote MappedTrackInfo.RendererSupport IntDef to public
This is referred to from the public API surface, so it should also be
public: https://exoplayer.dev/doc/reference/com/google/android/exoplayer2/trackselection/MappingTrackSelector.MappedTrackInfo.html#getRendererSupport(int)

#minor-release

PiperOrigin-RevId: 421578232
2022-01-14 15:18:26 +00:00
aquilescanta
8d81bd58d8 Remove Allocator.release(Allocation[]) and references
PiperOrigin-RevId: 421530365
2022-01-14 15:02:22 +00:00
hschlueter
755df46a6b Remove Transformer-specific things from MediaCodecAdapter.
PiperOrigin-RevId: 421514944
2022-01-14 14:58:40 +00:00
tonihei
b09b8dc2ab Disable live speed adjustment where it has no benefit
Live speed adjustment is used for all live playback at the moment,
but has no user visible effect if the media is not played with low
latency. To avoid unnecessary adjustment during playback without
benefit, this change restricts the live speed adjustment to cases
where either the user requested a speed value in the MediaItem or the
media specifically defined a low-latency stream.

Issue: google/ExoPlayer#9329
PiperOrigin-RevId: 421514283
2022-01-14 14:54:49 +00:00
tonihei
b77204eb4d Update test relying on network type detection to run on all API levels.
This ensures we test the API level specific logic, in particular
around 5G-NSA detection.

Robolectric has a remaining bug that it doesn't support listening
to service state changes. Hence, we need to ignore some tests on
these API levels still until this is fixed.

PiperOrigin-RevId: 421505951
2022-01-14 14:50:58 +00:00
tonihei
607ef989fb Fix decoder fallback logic for Dolby Atmos and Dolby Vision.
The media codec renderers have fallback logic in getDecoderInfos
to assume that E-AC3 decoders can handle the 2D version of E-AC3-JOC and
that H264/H265 decoders can handle some base layer of Dolby Vision
content. Both fallbacks are useful if there is no decoder for the
enhanced Dolby formats.

Both fallbacks are not applied during track selection at the moment
because the separate MediaCodecInfo.isCodecSupported method verifies
that the mime type corresponding to format.codecs is the same as the
decoder mime type (which isn't true for the fallback case).

To fix the fallback logic, we can just completely remove this additional
check because it's not needed in the context of this method that is only
called after we already established that the decoder can handle the
format.sampleMimeType.

In addition, we need to map the Dolby Vision profiles to the equivalent
H264/H265 profile to make the codec profile comparison sensible again.

PiperOrigin-RevId: 420959104
2022-01-14 14:20:08 +00:00
aquilescanta
c3b470f308 Remove most allocations in SampleQueue.release
SampleQueues may be released in the context of a finally block
after an out of memory error. Allocating in that scenario can
throw yet a new OutOfMemoryError. By safely releasing SampleQueue
memory, we increase the possibility of handling the error
gracefully.

PiperOrigin-RevId: 420859022
2022-01-14 14:16:26 +00:00
olly
8c89c9c688 Require playback to be stuck for a minimum period before failing
PiperOrigin-RevId: 420738165
2022-01-14 14:12:26 +00:00
andrewlewis
0af7f5c287 Fix spherical scene rendering
The draw method was disabling vertex attrib arrays but not re-enabling them. Remove the call to disable the vertex attrib arrays so that then remain enabled after the program is created.

Manually verified by setting the surface type to spherical in the demo app and playing a spherical sample video.

Issue: google/ExoPlayer#9782
PiperOrigin-RevId: 420707503
2022-01-10 12:49:46 +00:00
ibaker
93af4ad4a7 Add tests for DefaultTrackSelector handling of forced & default tracks
Issue: google/ExoPlayer#9797
PiperOrigin-RevId: 420707176
2022-01-10 12:46:08 +00:00
aquilescanta
9dbace132a Fix AllocationNode javadoc and simplify internal state
Remove wasInitialized in favor of using allocation's nullability to
represent the initialization state.

PiperOrigin-RevId: 420011311
2022-01-07 16:31:29 +00:00
olly
a57245e782 Fix 1 ErrorProneStyle finding:
* @Override is not a TYPE_USE annotation, so should appear before any modifiers and after Javadocs. @CryptoType is a TYPE_USE annotation, so should appear after modifiers and directly before the type.

PiperOrigin-RevId: 418811744
2022-01-04 14:00:44 +00:00
aquilescanta
e54e02fdcf Pre-allocate availableAllocations to prevent a re-size in release
PiperOrigin-RevId: 418022431
2022-01-04 14:00:44 +00:00
ibaker
5e8d1eb7f3 Add MediaSource.Factory and deprecate MediaSourceFactory
This more closely matches the pattern we have for all implementations
except DefaultMediaSourceFactory (e.g. ProgressiveMediaSource.Factory)
and other factory interfaces like (Http)DataSource.Factory.

PiperOrigin-RevId: 417826803
2022-01-04 12:51:47 +00:00
ibaker
bb1357b678 Delete deprecated methods from MediaSourceFactory
Some have been deprecated since 2.13.0
([commit](5b9fa7d7d9)):
* `setDrmSessionManager(DrmSessionManager)`
* `setDrmHttpDataSourceFactory(HttpDataSource.Factory)`
* `setDrmUserAgent(String)`

And the rest have been deprecated since 2.12.0
([commit](d1bbd3507a)):
* `setStreamKeys(List<String>)`
* `createMediaSource(Uri)`

PiperOrigin-RevId: 417622794
2021-12-21 17:26:06 +00:00
ibaker
e3548f267c Migrate usages of deprecated MediaSourceFactory methods
PiperOrigin-RevId: 417428182
2021-12-21 17:10:54 +00:00
bachinger
e5ec6b31b2 Store adPlaybackStates and shared periods by period UID
To support multi-period content we need to store AdPlaybackStates and
SharedMediaPeriod by the periodUid as a key. While after this no-op CL,
we still only support single-period content, storing these resources by
periodUid is the ground work for multi-period support being added in an
follow-up CL.

PiperOrigin-RevId: 416836445
2021-12-20 13:52:46 +00:00
ibaker
c1f878deb1 Move DefaultMediaSourceFactory.AdsLoaderProvider to AdsLoader.Provider
Keep the old interface deprecated so any app code implementing it by
name (rather than with a lambda) will continue to work.

PiperOrigin-RevId: 416816566
2021-12-20 12:54:56 +00:00
tonihei
9d463725fb Exclude last chunk when applying fraction for live quality increase
We check the fraction of the available duration we have already
buffered for live streams to see if we can increase the quality.
This fraction compares against the overall available media duration
at the time of the track selection, which by definition can't include
one of the availabe chunks (as this is the one we want to load next).

That means, for example, that for a reasonable live offset of 3 segments
we can at most reach a fraction of 0.66, which is less than our default
threshold of 0.75, meaning we can never switch up.

By subtracting one chunk duration from the available duration, we make
this comparison fair again and allow all live streams (regardless of
live offset) to reach up to 100% buffered data (which is above our
default value of 75%), so that they can increase the quality.

Issue: google/ExoPlayer#9784
PiperOrigin-RevId: 416791033
2021-12-20 12:36:43 +00:00
christosts
b5206b8e05 Add getMetrics() in MediaCodecAdapter
Before the introduction of the MediaCodecAdapter, users could get
access directly to the MediaCodec instance from
MediaCodecRenderer.getCodec() and then retrieve the codec metrics.

This change exposes MediaCodec.getMetrics() on the MediaCodecAdapter.

Issue: google/ExoPlayer#9766

#minor-release

PiperOrigin-RevId: 416343023
2021-12-15 12:22:35 +00:00
tonihei
a6c26d04fa Remove condition that is always false.
The same condition is checked further up on L497 already.

PiperOrigin-RevId: 416324687
2021-12-14 17:54:47 +00:00
bachinger
f038258522 Add AdPlaybackStateUpdater
PiperOrigin-RevId: 416314200
2021-12-14 17:51:03 +00:00
tonihei
27b52bca41 Rollback of bf1224186c
*** Original commit ***

Rollback of 0aa23b08b1

*** Original commit ***

Add capability flags for hardware and decoder support

Issue: google/ExoPlayer#9565

***

***

PiperOrigin-RevId: 416285603
2021-12-14 16:10:42 +00:00
tonihei
c5d94c8667 Rollback of 3a7f7e81d7
*** Original commit ***

Rollback of 27f905f571

*** Original commit ***

Don't sort decoders by format support in supportsFormat

This is a no-op change that updates supportsFormat to use the
decoder list before it's reordered by format support. Instead,
supportsFormat iterates through the decoders listed in their
original priority order as specified by the MediaCodecSelector.
The end result is identical.

This is n...

***

PiperOrigin-RevId: 416269130
2021-12-14 16:06:46 +00:00
olly
3a7f7e81d7 Rollback of 27f905f571
*** Original commit ***

Don't sort decoders by format support in supportsFormat

This is a no-op change that updates supportsFormat to use the
decoder list before it's reordered by format support. Instead,
supportsFormat iterates through the decoders listed in their
original priority order as specified by the MediaCodecSelector.
The end result is identical.

This is necessary groundwork for a subsequent change that will
indicate in Capabilities whether the decoder that suppports the
format is the primary one as specifi

***

PiperOrigin-RevId: 416170612
2021-12-14 16:02:56 +00:00
olly
bf1224186c Rollback of 0aa23b08b1
*** Original commit ***

Add capability flags for hardware and decoder support

Issue: google/ExoPlayer#9565

***

PiperOrigin-RevId: 416170329
2021-12-14 15:58:17 +00:00
christosts
40bd99a3cd Load the Spatializer API with reflection
This change adds a delegate class that loads and forwards calls
to a Spatializer with reflection, so that we can use the Spatializer
API before we update the compile SDK target to 32.

PiperOrigin-RevId: 416027289
2021-12-14 10:30:35 +00:00
ibaker
7fca1a0876 Make DecoderCountersUtil error message clearer
By including the full counters in the failure message we have a clearer
insight into the cause of the failure.

PiperOrigin-RevId: 415982732
2021-12-13 12:21:09 +00:00
krocard
ddf05a9466 Rollback of 2674e05589
*** Original commit ***

Make audio track min buffer size configurable.

Move the code in its own class as DefaultAudioTrack
is getting very big. It also help for testability.

The new class is easily configurable and highly tested.
Manual test was used to catch any regression.

https://github.com/google/ExoPlayer/issues/8891

***

PiperOrigin-RevId: 415469179
2021-12-10 17:25:53 +00:00
krocard
2674e05589 Make audio track min buffer size configurable.
Move the code in its own class as DefaultAudioTrack
is getting very big. It also help for testability.

The new class is easily configurable and highly tested.
Manual test was used to catch any regression.

https://github.com/google/ExoPlayer/issues/8891

PiperOrigin-RevId: 415268938
2021-12-10 16:46:50 +00:00
olly
0aa23b08b1 Add capability flags for hardware and decoder support
Issue: google/ExoPlayer#9565
PiperOrigin-RevId: 415235358
2021-12-10 16:42:44 +00:00
krocard
2ad9a2e6a5 Do not allow null for DefaultAudioSink capabilities
Null was equivalent to DEFAULT_AUDIO_CAPABILITIES.
In favor of null safety, remove the null state.

PiperOrigin-RevId: 415037404
2021-12-10 16:38:59 +00:00