302 Commits

Author SHA1 Message Date
tonihei
6caaf58d40 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-25 18:02:43 +00:00
tonihei
b208d6d26e 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-11 13:47:17 +00:00
aquilescanta
66aa1faf7e 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-11 13:46:10 +00:00
olly
c19d1da6ed Require playback to be stuck for a minimum period before failing
PiperOrigin-RevId: 420738165
2022-01-11 13:45:08 +00:00
andrewlewis
ede93022c7 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-11 13:40:45 +00:00
ibaker
055df87c8b Add tests for DefaultTrackSelector handling of forced & default tracks
Issue: google/ExoPlayer#9797
PiperOrigin-RevId: 420707176
2022-01-11 13:39:42 +00:00
aquilescanta
0eeea1e523 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-11 13:27:31 +00:00
olly
c5aa869730 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-05 12:14:58 +00:00
aquilescanta
6ee7cdf968 Pre-allocate availableAllocations to prevent a re-size in release
PiperOrigin-RevId: 418022431
2022-01-05 12:14:58 +00:00
ibaker
34a1f884dc 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-05 10:51:41 +00:00
ibaker
58db50699f Support simple ad serving with the stable API
This involves stabilising AdsLoader and ImaAdsLoader, as well
as (Default)MediaSourceFactory and the following methods on
ExoPlayer.Builder:
* setMediaSourceFactory
* setAdsLoaderProvider
* setAdViewProvider

Most of ImaAdsLoader.Builder and (Default)MediaSourceFactory remain
unstable for now.

PiperOrigin-RevId: 417814106
2022-01-05 10:49:42 +00:00
ibaker
cee7e8e2db 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
2022-01-05 10:44:23 +00:00
ibaker
691f9c50cf Migrate usages of deprecated MediaSourceFactory methods
PiperOrigin-RevId: 417428182
2022-01-05 10:40:02 +00:00
andrewlewis
d159634b5e Fix location of common module doc-files
For the media3 codebase the timeline images need to be under the common module.

Verified results in an empty commit for ExoPlayer GitHub.

PiperOrigin-RevId: 416850853
2022-01-05 10:35:40 +00:00
bachinger
f352836bde 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
2022-01-05 10:33:39 +00:00
ibaker
2fad15a815 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
2022-01-05 10:32:22 +00:00
tonihei
e76925c6fc 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
2022-01-05 10:27:32 +00:00
christosts
531ff0e19d 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
2022-01-05 10:17:49 +00:00
tonihei
89b47413af Remove condition that is always false.
The same condition is checked further up on L497 already.

PiperOrigin-RevId: 416324687
2022-01-05 10:15:24 +00:00
bachinger
51237e8aef Add AdPlaybackStateUpdater
PiperOrigin-RevId: 416314200
2022-01-05 10:12:24 +00:00
tonihei
be01fc7651 Rollback of f713ca6d13
*** Original commit ***

Rollback of 3c4c1f4774

*** Original commit ***

Add capability flags for hardware and decoder support

Issue: google/ExoPlayer#9565

***

***

PiperOrigin-RevId: 416285603
2022-01-05 10:08:14 +00:00
tonihei
38a0f60b8e Rollback of de83033ffc
*** Original commit ***

Rollback of d7867800dc

*** 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
2022-01-05 10:07:15 +00:00
olly
de83033ffc Rollback of d7867800dc
*** 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
2022-01-05 10:05:38 +00:00
olly
f713ca6d13 Rollback of 3c4c1f4774
*** Original commit ***

Add capability flags for hardware and decoder support

Issue: google/ExoPlayer#9565

***

PiperOrigin-RevId: 416170329
2022-01-05 10:04:26 +00:00
christosts
d90f5f37ef 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
2022-01-05 10:01:59 +00:00
ibaker
1fa69a9080 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
2022-01-05 09:55:44 +00:00
krocard
63935887b6 Rollback of 34108c6c92
*** 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 11:25:46 +00:00
krocard
34108c6c92 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 11:18:13 +00:00
olly
3c4c1f4774 Add capability flags for hardware and decoder support
Issue: google/ExoPlayer#9565
PiperOrigin-RevId: 415235358
2021-12-10 11:16:34 +00:00
krocard
68522f5301 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 11:15:27 +00:00
olly
d7867800dc 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 specified by the MediaCodecSelector
(i.e., the one at index=0 in the lists that are now used).

Issue: google/ExoPlayer#9565
PiperOrigin-RevId: 414971986
2021-12-10 11:11:46 +00:00
bachinger
1218f56db6 Support IMA DAI streams for HLS
PiperOrigin-RevId: 414804513
2021-12-10 11:08:45 +00:00
ibaker
d0c59eb5f1 Rename DecoderCounters#inputBufferCount to queuedInputBufferCount
This more accurately reflects the value stored in this field.

PiperOrigin-RevId: 414762892
2021-12-10 11:07:24 +00:00
christosts
87510592bb Configure MediaCodec in API 32+ to always output 99 channels
Configure MediaCodec in API 32+ to always output 99 channels
so that we use the audio is spatialized, if the platform can apply
spatialization to it.

In a follow-up change, the output channel count will be set based on the
device's spatialization capabilities.

PiperOrigin-RevId: 414751543
2021-12-10 11:06:08 +00:00
krocard
341bb57498 Add a builder to DefaultAudioSink
`DefaultAudioSink` already has 3 telescoping
constructors and an other one would be have been
needed to add a buffer size tuning option.

PiperOrigin-RevId: 414703366
2021-12-07 17:37:45 +00:00
ibaker
dcc69056bf Fix how drop-to-keyframe events are recorded in DecoderCounters
The existing code creates an imbalance between `inputBufferCount` and
`droppedBufferCount` by adding 'dropped source buffers' to
`droppedBufferCount` but not to `inputBufferCount`. This results in
assertion failures in `DashTestRunner`.

PiperOrigin-RevId: 414672175
2021-12-07 17:37:45 +00:00
ibaker
0b09ac5bb0 Migrate usages of Timeline#getPeriodPosition to getPeriodPositionUs
#minor-release

PiperOrigin-RevId: 414671861
2021-12-07 17:37:45 +00:00
ibaker
97294f0693 Retry creating a MediaCodec instance in MediaCodecRenderer
It's been observed that some devices fail when releasing a secure codec
attached to a surface and immediately trying to create a new codec
(secure or insecure) attached to the same surface. This change catches
all exceptions thrown during codec creation, sleeps for a short time,
and then retries the codec creation. This is observed to fix the problem
(we believe this is because it allows enough time for some background
part of the previous codec release operation to complete).

This change should have no effect on the control flow when codec
creation succeeds first time. It will introduce a slight delay when
creating the preferred codec fails (while we sleep and retry), which
will either delay propagating a permanent error or attempting to
initialize a fallback decoder. We can't avoid the extra delay to
instantiating the fallback decoder because we can't know whether we
expect the second attempt to create the preferred decoder to succeed or
fail. The benefit to always retrying the preferred decoder creation
(fixing playback failures) outweighs the unfortunate additional delay
to instantiating fallback decoders.

Issue: google/ExoPlayer#8696
#minor-release
PiperOrigin-RevId: 414671743
2021-12-07 17:37:45 +00:00
ibaker
59d98b9a4e Add MediaItem.SubtitleConfiguration#id field
Issue: google/ExoPlayer#9673

#minor-release

PiperOrigin-RevId: 414413320
2021-12-07 17:37:31 +00:00
olly
f2ad8ccd3c Shorten log tags to 23 char limit
When calling Android's Log class directly, there's a LongLogTag
lint check that detects tags over the 23 char limit, however it
cannot detect long log tags in ExoPlayer due to the way that we
log via our own Log class. This commit adds @Size annotations to
enforce the same rule.

PiperOrigin-RevId: 413976364
2021-12-07 17:37:31 +00:00
andrewlewis
aae9ebaa7e Apply MTK E-AC3 workaround before API 24
On the Sony Android TV device where this was originally reproducible on
Android L, on Android N there is an E-AC3 decoder listed which handles
the stream correctly. The workaround is harmless anyway but adding the
API version restriction means it will be obvious it can be removed once
we bump our min API to 24 or above in the future.

PiperOrigin-RevId: 413967443
2021-12-07 17:37:07 +00:00
olly
244777234b Refine HW/SW codec approximation for API level 28 and earlier
Hardware audio decoders aren't really a thing, particularly on older
devices. SOC vendors do sometimes provide their own software decoders
though. Hence we update the approximation to assume that audio
decoders on older devices are software.

PiperOrigin-RevId: 413757859
2021-12-07 16:44:25 +00:00
tonihei
417c242625 Prohibit duplicate TrackGroups in TrackGroupArray
Allowing duplicate groups caused some other code working with the
array to use reference equality comparison. This is error-prone,
easily forgotten (e.g. when using the TrackGroups in a map) and
causes bugs when TrackGroups are serialized to disk or to another
process.

All TrackGroups created by ExoPlayer are already unique and custom
code creating TrackGroupArrays with identical groups can easily
distringuish them by adding an id to each group.

Issue: google/ExoPlayer#9718
PiperOrigin-RevId: 413617005
2021-12-02 11:56:42 +00:00
tonihei
f1a5825d73 Add optional id to TrackGroup.
This allows to give TrackGroups an identifier. The underlying goal is
to provide a way to make otherwise identical TrackGroups
distinguishable.

Also set this id in all internal sources that may produce identical
TrackGroups in certain edge cases.

Issue: google/ExoPlayer#9718
PiperOrigin-RevId: 413430719
2021-12-02 11:56:42 +00:00
tonihei
805d3b763d Update track selection to prefer content over technical preferences.
Currently we prefer technical preferences set in the Parameters over
content preferences implied by the media. It proably makes more
sense in the opposite order to avoid the situation where a
non-default track (e.g. commentary) is selected just because it
better matches some technical criteria.

Also add comments explaining the track selection logic stages.

PiperOrigin-RevId: 412840962
2021-12-02 11:55:55 +00:00
huangdarwin
60ce9ae345 Misc refactoring.
Use @VisibleForTesting and add some comments for GL code.

Refactoring change only. No functional changes intended

PiperOrigin-RevId: 412428196
2021-12-02 11:55:44 +00:00
huangdarwin
f0fcad16a9 GL: Remove redundant use() call.
This is already called in GlUtil.Program().

Tested by confirming that the demo-gl target still runs as expected.

Refactoring change only. No intended functional changes.

PiperOrigin-RevId: 412308564
2021-12-02 11:55:44 +00:00
tonihei
a7d7c7b73a Add preferredVideoRoleFlags to TrackSelectionParameters.
And also tweak existing role flag logic to strictly prefer perfect
matches over partial matches.

Caveat: Video role flags only supported for fixed track selections
(same issue as Issue: google/ExoPlayer#9519).

Issue: google/ExoPlayer#9402
PiperOrigin-RevId: 412292835
2021-12-02 11:55:44 +00:00
tonihei
965062857d Move MediaMetricsListener creation to static constructor method.
This allows to check if the media metrics service is available outside
the actual constructor and to fail gracefully if it is missing.

PiperOrigin-RevId: 412232425
2021-12-02 10:14:27 +00:00
tonihei
736ea9a148 Remove ExoPlayerImpl inheritance from BasePlayer.
This inheritance is really confusing because ExoPlayerImpl is not
a full Player interface implementation. It also claims to be an
ExoPlayer implementation in the Javadoc which isn't true in its
current state.

Removing the inheritance also allows to clean up some unused methods.

PiperOrigin-RevId: 411756963
2021-12-02 10:05:29 +00:00