302 Commits

Author SHA1 Message Date
olly
ac8d80a044 DownloadService: Attempt to clarify the static map
PiperOrigin-RevId: 463315188
2022-08-08 08:05:10 +00:00
ibaker
2deb435625 Annotate methods that always return this with @CanIgnoreReturnValue
It's always safe to ignore the result of these methods, because the
caller already has a reference to the returned value.

PiperOrigin-RevId: 462388947
2022-08-08 07:55:25 +00:00
olly
649b70f935 Expand setOutputSurface workaround to more FireOS devices
Issue: google/ExoPlayer#10454
PiperOrigin-RevId: 462375294
2022-08-08 07:54:20 +00:00
ibaker
e1fde5d530 Add fail-fast null checks to the stable Player API
This will help developers self-diagnose issues like Issue: google/ExoPlayer#10392
where the NPE occurs far from the original null value because a field
gets assigned to null.

This change aims to ensure that every stable method on Player,
ExoPlayer and ExoPlayer.Builder that takes a non-null type will fail
with an NPE before returning.

#minor-release

PiperOrigin-RevId: 461846580
2022-07-21 12:46:05 +00:00
tonihei
adc50515e9 Fix setDataSourceFactory handling in DefaultMediaSourceFactory
The call doesn't currently reset the already loaded suppliers and
factories. Also fix the supplier loading code to use a local copy
of the current dataSourceFactory to avoid leaking an updated
instance to a later invocation.

Issue: androidx/media#116

#minor-release

PiperOrigin-RevId: 460721541
2022-07-13 17:48:16 +00:00
tonihei
9a616c0cee Use SingleThreadExecutor to release AudioTracks
We currently start a simple Thread to release AudioTracks
asynchronously. If many AudioTracks are released at the same
time, this may lead to OOM situations because we attempt to
create multiple new threads.

This can be improved by using a shared SingleThreadExecutor.
In the simple case of one simmultaneous release, it's exactly
the same behavior as before: create a thread and release it
as soon as it's done. For multiple simultanous releases we
get the advantage of sharing a single thread to avoid creating
more than one at the same time.

Issue: google/ExoPlayer#10057
PiperOrigin-RevId: 460698942
2022-07-13 17:47:20 +00:00
tonihei
549496f1fa Add method to check if tunneling is enabled.
Issue: google/ExoPlayer#2518
PiperOrigin-RevId: 460482615
2022-07-13 17:36:42 +00:00
tonihei
223922fb11 Fix DefaultAudioSinkTest flakiness.
Some calls to handleBuffer return false while a previous
flush is still handled in the background.

Fix this by either asserting the method returns true if
we don't expect any delay, or calling it repeatedly until
it returns true (within a timeout).

PiperOrigin-RevId: 460474419
2022-07-13 17:34:49 +00:00
ibaker
ad46cb1c81 Group COMMAND_SET_MEDIA_ITEM and COMMAND_CHANGE_MEDIA_ITEMS together
I don't think it's useful to keep these in numerical order, it makes
more sense to keep them grouped into a 'logical' ordering.

#minor-release

PiperOrigin-RevId: 460453464
2022-07-12 15:14:12 +00:00
rohks
05e728a31e Add tests for extracting MP4 with large bitrates
Also added the test to `MP4PlaybackTest`.

PiperOrigin-RevId: 459492188
2022-07-07 16:49:08 +00:00
christosts
cb87b7432f Add missing Nullable annotation
PiperOrigin-RevId: 459485334
2022-07-07 16:47:17 +00:00
tonihei
a83ab05aec Don't block AudioTrack when waiting for previous release
We wait until a previous AudioTrack has been released before
creating a new one. This is currently done with a thread
block operation, which may cause ANRs in the extreme case
when someone attempts to release the player while this is
still blocked.

The problem can be avoided by just returning false from
DefaultAudioSink.handleBuffer to try again until the previous
AudioTrack is released.

Reproduction steps to force the issue:
1. Add Thread.sleep(10000); to the AudioTrack release thread.
2. Add this to the demo app:
    private int positionMs = 0;

    Handler handler = new Handler();
    handler.post(new Runnable() {
      @Override
      public void run() {
        player.seekTo(positionMs++);
        if (positionMs == 10) {
          player.release();
        } else {
          handler.postDelayed(this, 1000);
        }
      }
3. Observe Player release timeout exception.

These steps can't be easily captured in a unit test as we can't
artifically delay the AudioTrack release from the test.

Issue: google/ExoPlayer#10057
PiperOrigin-RevId: 459468912
2022-07-07 16:46:24 +00:00
tonihei
656eaf74d1 Exclude HEVC 10bit profile on Pixel 1.
This profile is declared as supported although it isn't.

Issue: google/ExoPlayer#10345
Issue: google/ExoPlayer#3537

#minor-release

PiperOrigin-RevId: 459205512
2022-07-07 16:41:34 +00:00
tonihei
ceb23e69bb Only consider enabled tracks in ProgressiveMediaPeriod.bufferedPosition
ProgressiveMediaPeriod loads all available tracks into SampleStreams
(because it needs to read the data anyway and it allows easy activation
of tracks without reloading). However, the SampleStreams for disabled
tracks are not read and no one if waiting for them.

The buffered position is used for user-visible state (e.g. in the UI)
and to check how much data is already buffered to decide when to stop
buffering (using LoadControl). Both values benefit from only
using the actually enabled tracks to better reflect what is available
for playback at the moment.

Issue:Issue: google/ExoPlayer#10361
PiperOrigin-RevId: 458475038
2022-07-04 19:53:18 +00:00
rohks
621617f981 Make MetadataRenderer configurable to output metadata early.
PiperOrigin-RevId: 457974611
2022-07-04 19:42:59 +00:00
ibaker
6f9ce4056c Consider shuffle order in Timeline.equals()
Previously two timelines that differed only in shuffle order were
considered equal, which resulted in no call to
Player.Listener.onTimelineChanged when calling
ExoPlayer.setShuffleOrder. This in turn resulted in no call to
MediaControllerCompat.Callback.onQueueChanged.

Also make a small fix inside ExoPlayerImpl.setShuffleOrder, to ensure
that the new shuffle order is used when constructing the masked
timeline.

Issue: google/ExoPlayer#9889
#minor-release
PiperOrigin-RevId: 457703727
2022-07-04 19:41:19 +00:00
ibaker
2a2d9e360b Use a helper function and Truth Correspondence instead of NoUidTimeline
NoUidTimeline still exists as a private detail of TestUtil, but it no
longer extends ForwardingTimeline because the interactions are quite
hard to reason about.

#minor-release

PiperOrigin-RevId: 457703593
2022-07-04 19:40:35 +00:00
rohks
b2831d8559 Add timestamp to Metadata
`MetadataRenderer` is updated to output `Metadata` with its presentation time, in microseconds.

PiperOrigin-RevId: 457444718
2022-07-04 19:36:57 +00:00
tonihei
5c2752b4a9 Clean up offload state tracking
1. The offloadSchedulingEnabled value doesn't need to be in
   PlaybackInfo because it's never updated in EPII.
2. The sleepingForOffload value in EPII wasn't updated explicitly
   (just via the return value of a method). It was also only
   meant to be enabled while the player is actively playing, but
   confusingly triggered from a path where the player may
   theoretically be buffering as well.
3. The offload sleeping (=not scheduling doSomeWork) was interwoven
   into the actual scheduling code making it slightly hard to follow.
   This can be improved slightly by keeping the offload sleeping
   decision and the scheduling separate.

PiperOrigin-RevId: 457427293
2022-07-04 19:36:04 +00:00
tonihei
8e716d6804 Rename shouldUseDummySurface to shouldUsePlaceholderSurface
This was likely missed in 33373d0d0a.

PiperOrigin-RevId: 457422574
2022-06-27 10:44:56 +01:00
olly
1d2ad39a4d Inform ProgressiveMediaPeriod of known length earlier
PiperOrigin-RevId: 456753343
2022-06-27 10:40:21 +01:00
rohks
74d61bbffb Add timestamp to CueGroup
`TextRenderer` is updated to output `CueGroup`, which contains the presentation time of the cues, in microseconds.

PiperOrigin-RevId: 456531399
2022-06-27 10:38:20 +01:00
tonihei
a7649b639c Clear pending doSomeWork messages when sleeping for offload
The offload sleeping stops as soon as a new DO_SOME_WORK message
is handled (because this indicates an expected change in rendering
and we want to stop sleeping until we know it's safe to do so).

Every exit path from doSomeWork needs to clear other pending
DO_SOME_WORK messages as these requests have already been handled by
the current method invocation. This currently doesn't happen from the
offload sleeping return path and a previously queued DO_SOME_WORK
message can immediately wake up the rendering loop again.

Fix this by moving the message removal to the beginning of the
doSomeWork method (as it prevents forgetting it in one of the
exit paths later).

PiperOrigin-RevId: 456259715
2022-06-27 10:36:06 +01:00
christosts
12e7562730 Misc javadoc fix.
PiperOrigin-RevId: 455157744
2022-06-15 18:54:44 +00:00
tonihei
646bf565c3 Update initial bitrate estimates
#minor-release

PiperOrigin-RevId: 455140203
2022-06-15 16:41:10 +00:00
olly
691b392b24 Don't export broadcast receivers that don't require it
Issue: google/ExoPlayer#10287
PiperOrigin-RevId: 455131138
2022-06-15 15:34:53 +00:00
christosts
118d689a08 Spatializer: Assume linear channel count for E-AC3 JOC streams
#minor-release

PiperOrigin-RevId: 454884692
2022-06-14 17:11:00 +00:00
tonihei
e8bcdf437e Use correct placeholder PlayerID value in test
The default constructor is only allowed to be called on
API < 32 and the test should use the defined UNSET constant
to be API independent.

#minor-release

PiperOrigin-RevId: 454568893
2022-06-13 11:14:17 +00:00
ibaker
8c63ba6fdb Remove ExoPlayerTest.PlayerStateGrabber
It's no longer needed

PiperOrigin-RevId: 454161070
2022-06-13 11:13:18 +00:00
ibaker
222faa96d0 Ensure DRAIN_ACTION_FLUSH_AND_UPDATE_DRM_SESSION is always executed
`codecDrainAction` is set to `DRAIN_ACTION_NONE` in 3 places in
`MediaCodecRenderer`:
* The constructor (so there's no prior state to worry about)
* `updateDrmSessionV23()`: Where `mediaCrypto` is reconfigured based
  on `sourceDrmSession` and `codecDrmSession` is also updated to
  `sourceDrmSession`.
* `resetCodecStateForFlush()`: Where (before this change) the action
  is unconditionally set back to `DRAIN_ACTION_NONE` and so any
  required updated implied by
  `DRAIN_ACTION_FLUSH_AND_UPDATE_DRM_SESSION` is not done.

This change ensures that `flushOrReleaseCodec()` handles
`DRAIN_ACTION_FLUSH_AND_UPDATE_DRM_SESSION` before calling .

This probably also resolves Issue: google/ExoPlayer#10274

#minor-release

PiperOrigin-RevId: 454114428
2022-06-13 11:10:43 +00:00
hschlueter
cc1f32d094 Make GlUtil.GlException checked and remove flag to disable it.
Transformer always enabled glAssertionsEnabled, so there should
be no functional change.

ExoPlayer previously disabled glAssertionsEnabled, so GlUtil logged
GlExceptions instead of throwing them. The GlExceptions are now
caught and logged by the callers so that there should also be no
functional change overall.

This change also replaces EGLSurfaceTexture#GlException with
GlUtil#GlException.

PiperOrigin-RevId: 453963741
2022-06-09 18:47:46 +00:00
christosts
e2f0fd7673 DefaultTrackSelector: Constrain audio channel count
The track selector will select multi-channel formats when those can be
spatialized, otherwise the selector will prefer stereo/mono audio
tracks. When the device supports audio spatialization (Android 12L+),
the DefaultTrackSelector will monitor for changes in the platform
Spatializer and trigger a new track selection upon a
Spatializer change event.

Devices with a `television` UI mode are excluded from audio channel
count constraints.

#minor-release

PiperOrigin-RevId: 453957269
2022-06-09 17:51:42 +00:00
tonihei
5333c67d08 Add COMMAND_SET_MEDIA_ITEM to Player.Commands
Some Player implementations have no playlist capability but can still
set a MediaItem for playback. Examples are a MediaController connected
to a legacy MediaSession, ExoPlayer up to 2.12 or MediaPlayer.

To indicate this capability, we need an allowed command in addition
to COMMAND_CHANGE_MEDIA_ITEMS that just allows to set a single item
that replaces everything that is currently played.

#minor-release

PiperOrigin-RevId: 453879626
2022-06-09 17:46:14 +00:00
christosts
8697338233 Audio passthrough: handle unset audio format channel count
With HLS chunkless preparation, audio formats may have no value
for channel count. In this case, the DefaultAudioSink will either query
the platform for a supported channel count (API 29+) or assume a max
channel count based on the encoding spec in order to decide whether the
audio format can be played with audio passthrough.

Issue: google/ExoPlayer#10204

#minor-release

PiperOrigin-RevId: 453644548
2022-06-09 17:43:21 +00:00
ibaker
4a6f431f01 Clarify that ShuffleOrder must be consistent in both directions
#minor-release

PiperOrigin-RevId: 453622964
2022-06-09 17:39:13 +00:00
christosts
62497f23fd Minor fix: remove final from methods of final class
#minor-release

PiperOrigin-RevId: 453408087
2022-06-07 16:31:58 +00:00
ibaker
814e43dbb9 Use a shared keyForField implementation in track selection parameters
The current setup with distinct, private `keyForField` implementations,
leaves open the (theoretical) possibility of a clash in the `Bundle`
keys used by the superclass and subclass. This change brings
consistency with our only other extensible `Bundleable` type
(`PlaybackException`).

#minor-release

PiperOrigin-RevId: 453385875
2022-06-07 16:31:09 +00:00
ibaker
247c2d845d Rename DefaultTrackSelector.ParametersBuilder to Parameters.Builder
We generally nest the `Builder` for `Foo` inside `Foo`. In this case,
there's already a `DefaultTrackSelector.Parameters.Builder` type visible
to a developer, it just happens to be the 'common'
`TrackSelectorParameters.Builder`, so using it is a bit weird. For
example this code snippet doesn't compile because
`DefaultTrackSelector.Parameters.Builder#build()` returns
`TrackSelectionParameters`. This CL fixes that problem and the code
snippet now compiles.

```java
DefaultTrackSelector.Parameters params =
   new DefaultTrackSelector.Parameters.Builder(context).build()
```

#minor-release

PiperOrigin-RevId: 453215702
2022-06-07 16:29:17 +00:00
ibaker
b8ca5b8951 Add @deprecated javadoc to all @Deprecated @Override methods
This ensures the 'use X instead' message is easily visible in the
generated HTML for the overriding method. Currently it's not, e.g.:
https://exoplayer.dev/doc/reference/com/google/android/exoplayer2/BasePlayer.html#getCurrentWindowIndex()

#minor-release

PiperOrigin-RevId: 452002224
2022-05-31 10:44:48 +00:00
ibaker
cad1440e66 Wrap framework AudioAttributes in new AudioAttributesV21 class
PiperOrigin-RevId: 451831531
2022-05-30 16:44:27 +00:00
bachinger
01412f4a57 Unconditionally sleep for offload
Unconditionally sleep for offload, if the audio buffer is full.
Previously ExoPlayer would not sleep if the expected wake-up was
in 2s. This was to prevent underrun if the wake-up was delayed.

Experiments have shown that the wakup audio buffer is far more
than 2s (around 1min). Additionally,
the metric was incorrect because it measured both,
AudioTrack + DSP.

Finally, this metric was erroneous after a gapless transition,
when the head position would reset to 0 and thus the computed
delay until next wakeup was too large.

PiperOrigin-RevId: 451383701
2022-05-30 16:38:14 +00:00
ibaker
8f3b4f590f Fix typos flagged by lint
PiperOrigin-RevId: 451135097
2022-05-30 16:30:11 +00:00
ibaker
26a1817ebf Rollback of e01bb47263
*** Original commit ***

Rollback of 07302a23bd

*** Original commit ***

Remove `@Nullable` from `MediaSource.Factory` setters

The null-behaviour of these methods creates a minimization footgun,
because **any** call to these setters will prevent R8 from removing
the default implementation (even if it's never used by the app) - this
is because R8 can't tell the default imple...

***

PiperOrigin-RevId: 450453325
2022-05-23 17:12:22 +01:00
bachinger
a8a4faa28c Do not setOffloadEndOfStream if AudioTrack is not playing
AudioTrack.setOffloadEndOfStream should be called after a track
has been buffered. Additionally, the AudioTrack must be playing.

It has been observed that for very short media (<1s), the AudioTrack
might not have started immediately after the read that buffered
the audio.

In such a situation, calling AudioTrack.setOffloadEndOfStream throws
and playback fails.

Avoid this failure by checking that the AudioTrack is playing before
calling setOffloadEndOfStream.

This means that very short gapless media will not be gapless, this was
deemed acceptable given that such very short media should be very rare
in offload.

PiperOrigin-RevId: 450431146
2022-05-23 15:13:43 +01:00
ibaker
89194dee59 Add DefaultMediaSourceFactory.setDataSourceFactory
Also add this to the stable API instead of the constructor that takes
`DataSource.Factory`.

PiperOrigin-RevId: 450414119
2022-05-23 13:26:05 +01:00
ibaker
1d139174fd Rollback of 07302a23bd5894d57514c68b2db499ac46726e77
*** Original commit ***

Remove `@Nullable` from `MediaSource.Factory` setters

The null-behaviour of these methods creates a minimization footgun,
because **any** call to these setters will prevent R8 from removing
the default implementation (even if it's never used by the app) - this
is because R8 can't tell the default implementation is only used if the
parameter is `null`.

PiperOrigin-RevId: 450410833
2022-05-23 13:01:22 +01:00
ibaker
07302a23bd Remove @Nullable from MediaSource.Factory setters
The null-behaviour of these methods creates a minimization footgun,
because **any** call to these setters will prevent R8 from removing
the default implementation (even if it's never used by the app) - this
is because R8 can't tell the default implementation is only used if the
parameter is `null`.

PiperOrigin-RevId: 450386627
2022-05-24 11:07:07 +01:00
tonihei
38b1338844 Remove 5G-NSA detection on API 29/30.
This detection relies on an unsupported workaround and may trigger
permission warnings in tools analyzing permission usage although
no permission is needed or requested by app code.

Given the majority of 5G-NSA playbacks are on API 31+ by now,
we can remove this path to avoid the permission confusion and the
unsupported detection workaround.

PiperOrigin-RevId: 450382586
2022-05-24 11:06:09 +01:00
ibaker
994c33f56f Fix comment in MediaCodecRenderer
This constant name was updated in 1bcf1cf9f7

PiperOrigin-RevId: 449969093
2022-05-24 11:04:05 +01:00
rohks
001090cc43 Migrate leaf listeners of Player to new onCues override
PiperOrigin-RevId: 449587030
2022-05-24 11:02:03 +01:00