1300 Commits

Author SHA1 Message Date
tonihei
2bb719fd54 Remove obsolete TODO
The idea was to not even write any samples to SampleQueues as
they are not needed during the metadata extraction process.
However, this is not easily possible as long as we use our
existing Extractors and MediaSource/Periods for loading given
how deeply ingrained the extraction of samples is in these
classes. For most common formats like MP4, no samples will be
extracted anyway as they can finish the prepare step without
reading any samples.

PiperOrigin-RevId: 650529371
2024-07-09 01:18:01 -07:00
tianyifeng
58ff8fa3c2 Add onPreloadError method to PreloadMediaSource.PreloadControl
Upon the call of `PreloadMediaSource.preload`, the source will periodically check the source refresh or period loading error, and trigger `PreloadMediaSource.PreloadControl.onPreloadError`. For now, the `DefaultPreloadManager` will skip the problematic source and continue to preload the next source. The checking of the error will be terminated when the source stops preloading or releases.

PiperOrigin-RevId: 650195817
2024-07-08 04:06:32 -07:00
ibaker
bb2fd002ae Fix TTML handling of inherited percentage tts:fontSize values
The percentage should be interpreted as relative to the size of a parent
node.

This change makes this inheritance work correctly for percentages in
both the parent and child. It does not fix the case of a non-percentage
parent size with a percentage child size.

PiperOrigin-RevId: 649631055
2024-07-05 05:57:54 -07:00
Googler
0d4a785b61 Add support for parsing LHEVCConfigurationBox.
Parse LHEVCDecoderConfigurationRecord with the ‘lhvC’ type and set the corresponding sample mime type to video/mv-hevc.  With no MV-HEVC decoder available, fallback to single-layer HEVC decoding.

PiperOrigin-RevId: 649119173
2024-07-03 10:24:36 -07:00
claincly
8632c3add6 Fix not setting videoSinkNeedsRegisterInputStream when seeking
PiperOrigin-RevId: 649093092
2024-07-03 09:04:58 -07:00
kimvde
c832cf5a57 Clarify Javadoc of VideoSink
The VideoSink has an input and an output surface. Clarify which surface
the Javadoc is referring to. Also document that the VideoSink can be fed
with images, and that multiple renderers can feed the same sink.

PiperOrigin-RevId: 649052551
2024-07-03 06:31:40 -07:00
claincly
ed3a741601 Fix MCVR crash when seeking in HDR10 videos
MCVR crashed because MCVR registers a new input stream to VideoSink on every
`onOutputFormatChanged()`, assuming that `onOutputFormatChanged()` is only
invoked on media item transition. However, it can be called multiple times for
one media item.

PiperOrigin-RevId: 649050576
2024-07-03 06:22:44 -07:00
claincly
73da1c09bd Call onProcessedStreamChange() for every media item change
Added `MCR.experimentalEnableProcessedStreamChangedAtStart()` to guard this new
feature.

PiperOrigin-RevId: 648886533
2024-07-02 17:04:08 -07:00
tianyifeng
afe3826d7c Suppress the lint "WrongConstant" error
Lint somehow complains that the integer resulting from the bit-manipulation shouldn't be passed as an @IntDef parameter.

#cherrypick

PiperOrigin-RevId: 648687698
2024-07-02 05:49:23 -07:00
kimvde
a2087ba5bb Improve Javadoc of VideoSink.registerInputFrame/queueBitmap
Document that the stream must be registered before

PiperOrigin-RevId: 648648650
2024-07-02 02:50:02 -07:00
tianyifeng
7fb6eee920 Add PreloadException with initial subset of error codes
As the first version, the error codes only include the miscellaneous and IO errors, but are likely to be extended.

PiperOrigin-RevId: 648466385
2024-07-01 13:24:34 -07:00
ktrajkovski
e392084c4d Remove deprecated DrmSessionEventListener.onDrmSessionAcquired method.
#cherrypick

PiperOrigin-RevId: 647620751
2024-06-28 03:36:51 -07:00
michaelkatz
a58e77a5a6 Cache audio timestamp frame position across track transition reset
Upon track transition of offloaded playback of gapless tracks, the framework will reset the audiotrack frame position. The `AudioTrackPositionTracker`'s `AudioTimestampPoller` must be made to expect the reset and cache accumulated sum of `AudioTimestamp.framePosition`.

#cherrypick

PiperOrigin-RevId: 647294360
2024-06-27 06:27:32 -07:00
tonihei
727645179b Send pending updates before adding discontinuity for error
When handling a playback error that originates from a future item in
the playlist, we added support for jumping to that item first,
ensuring the errors 'happen' for the right 'current item'.
See 79b688ef30.

However, when we add this new position discontinuity to the
playback state, there may already be other position discontinuities
pending from other parts of the code that executed before the
error. As we can't control that in this case (because it's part
of a generic try/catch block), we need to send any pending
updates first before handling the new change.

Issue: androidx/media#1483
#cherrypick
PiperOrigin-RevId: 646968309
2024-06-26 09:09:01 -07:00
kimvde
25b8385cff Fix Javadoc of VideoSink.setStreamOffsetAndAdjustmentUs
PiperOrigin-RevId: 646942034
2024-06-26 07:40:26 -07:00
Ian Baker
a15710ba44 Reformat and add/remove some final keywords 2024-06-25 15:51:03 +01:00
Colin Kho
2ee69cb1f9 Avoid unnecessary getSystemService call on WifiLockManager and WakeLockManager if not enabled 2024-06-25 15:51:02 +01:00
rohks
12c42585d2 Use removeKey method instead of setting null for KEY_CODECS_STRING
Setting a `null` value doesn't remove the key as expected per the `MediaFormat` API documentation, using the `removeKey` method instead which is only available starting API level 29.

PiperOrigin-RevId: 646462402
2024-06-25 06:57:19 -07:00
ibaker
5fcc7433a1 Use MediaCodec.stop() before release() for surface switching bug
ExoPlayer used to call `stop()` before `release()`. This was removed in
<unknown commit>.

A framework bug introduced in Android 11 (API 30) resulted in some
DRM -> clear transitions failing during `MediaCodec.configure()`. An
investigation in Issue: google/ExoPlayer#8696 and b/191966399 identified that this was
due to `release()` returning 'too early' and the subsequent
`configure()` call was then trying to re-use a `Surface` that hadn't
been fully detached from the previous codec. This was fixed in
Android 13 (API 33) with http://r.android.com/2094347.

ExoPlayer worked around the framework bug by adding an arbitrary 50ms
sleep after a failed codec initialization, followed by retrying. This
was enough to resolve the problem in the test scenario on a OnePlus
AC2003.

Issue: androidx/media#1497 points out that 50ms might not be the appropriate delay
for all devices, so it's an incomplete fix. They suggested re-adding the
`MediaCodec.stop()` call instead. This also reliably resolves the issue
on the OnePlus AC2003 (with neither workaround in place, the problem
repros almost immediately).
PiperOrigin-RevId: 646461943
2024-06-25 06:54:45 -07:00
claincly
73bf852405 Make ExoPlayer.setVideoEffects() timestamp start from 0
This is consistent with `Transformer` and `CompositionPlayer`

Issue: androidx/media#1098
PiperOrigin-RevId: 646446824
2024-06-25 05:59:15 -07:00
tonihei
867410fece Rename DummyTrackOutput and DummyExtractorOutput
#cherrypick

PiperOrigin-RevId: 646434450
2024-06-25 05:07:56 -07:00
tonihei
18e631ff79 Add guard against additional tracks reported by Extractors
Extractors should not report additional tracks once they called
ExtractorOutput.endTracks. This causes thread safety issues in
ProgressiveMediaPeriod where the array of sample queues is
extended while the playback thread accesses the arrays.

Detecting this problem early is beneficial to avoid unexplained
exceptions later one. In most cases where this may happen (namely
TS extractors finding new tracks), it's better to ignore the new
tracks instead of failing completely. So this change adds a
warning log message and assigns a placeholder output.

Note: The same workaround already exists in HlsSampleStreamWrapper
and MediaExtractorCompat.

Issue: androidx/media#1476
#cherrypick
PiperOrigin-RevId: 646427213
2024-06-25 04:38:22 -07:00
Copybara-Service
0466728497 Merge pull request #1479 from dryganets:sdryanets/fix-handler-usage
PiperOrigin-RevId: 646402268
2024-06-25 02:56:09 -07:00
kimvde
304c4e41f8 Call VideoFrameReleaseControl.isReady from VideoSink when enabled
PiperOrigin-RevId: 646385384
2024-06-25 01:51:14 -07:00
Copybara-Service
b026271c84 Merge pull request #1416 from khouzam:customFormat
PiperOrigin-RevId: 646121082
2024-06-24 09:30:28 -07:00
tonihei
58864a4bb9 Additional variable changes + argument checks in HandlerWrapper 2024-06-24 16:42:02 +01:00
Sergei Dryganets
457deec4eb Stop using what == 0 for messages. 2024-06-24 16:26:27 +01:00
tonihei
71ef848ec3 Add fail-early checks for TrackSelectorResult correctness
The two arrays need to have the same length and the selection
must match in their nullness (unless for TYPE_NONE
renderers). Clarify this more clearly in the docs and add
new asssertions for it. This avoids that the player is failing
in obscure ways much later.

Issue: androidx/media#1473
#cherrypick
PiperOrigin-RevId: 646086833
2024-06-24 07:30:25 -07:00
tonihei
ada4dc982f Fix flakiness in MediaCodecVideoRendererTest
The test is flaky because the decoding process in the renderer
depends on some timing from MediaCodec beyond our control and
the new keyframe added in the test is sometimes 'dropped' when
it arrives too late.

We can fix this by controlling the test progress a bit more
tightly: first rendering with the same current time until the
key frame is processed and then start increasing the time
until we've reached the end.

#cherrypick

PiperOrigin-RevId: 646064352
2024-06-24 05:53:48 -07:00
Gilles Khouzam
d717a0c5d5 Add a CustomData field to the Format class
Summary:
    This change aims to add a generic `CustomData` field to the `Format` class.

    The intent is to allow ExoPlayer customers to add extra data to the Format class without forcing
    specific data to be included, impacting customers that do not need it and would allow for the data
    to be changed without requiring changes to the `Media3` codebase.
2024-06-24 09:43:00 +01:00
tonihei
e84bb0d21c Fix audio focus handling in ExoPlayerImpl
Some cases are not handled correctly at the moment:
 - Pausing during suppressed playback should not clear the
   suppression state.
 - Transient focus loss while paused should be reported as
   a playback suppression.

Issue: androidx/media#1436
#cherrypick
PiperOrigin-RevId: 644971218
2024-06-20 04:00:57 -07:00
tonihei
1d26d1891e Clarify that onPlayWhenReadyChanged can be called again with new reason
Sometimes the reason for the current state may change. If we don't
report this again, users have no way of knowing that the reason
changed.

Also adjust ExoPlayerImpl and MediaControllerImplBase accordingly.
SimpleBasePlayer already adheres to this logic.

#cherrypick

PiperOrigin-RevId: 644970236
2024-06-20 03:58:05 -07:00
tonihei
c0abd6f91e Move playWhenReadyChangeReason inside PlaybackInfo
This helps to keep the reason always together with the state it
is referring to, avoiding any side channels and making sure there
are no accidental inconsistencies.

#cherrypick

PiperOrigin-RevId: 644969317
2024-06-20 03:54:04 -07:00
kimvde
4751b80703 Call VideoFrameReleaseControl.join from VideoSink when enabled
PiperOrigin-RevId: 644738200
2024-06-19 07:09:38 -07:00
kimvde
d27549d29a Skip 4K export test on Pixel 3a
PiperOrigin-RevId: 644659699
2024-06-19 01:18:05 -07:00
tonihei
66c19390e2 Audio focus player command clean up
The 'player commands' returned to ExoPlayerImpl instruct the
player on how to treat the current audio focus state.

The current return value when playWhenReady==false is misleading
because it implies we are definitely not allowed to play as if
we've lost focus. Instead, we should return the actual player
command corresponding to the focus state we are in.

This has no practical effect in ExoPlayerImpl as we already
ignore the 'player command' completely  when playWhenReady=false.

To facilitate this change, we also introduce a new internal
state for FOCUS_NOT_REQUESTED to distinguish it from the state
in which we lost focus.

#cherrypick

PiperOrigin-RevId: 644416586
2024-06-18 09:42:26 -07:00
kimvde
ada7271974 Add a method to change the frame rate strategy from the VideoSink
PiperOrigin-RevId: 644373231
2024-06-18 07:11:58 -07:00
tonihei
e20e94fde2 Improve audio focus handling tests with ExoPlayer
There are a lot of tests for AudioFocusManager in isolation,
but almost none for the handling in ExoPlayer.

Add test coverage for all the common cases, including some
currently broken behavior that is indicated by TODOs.

PiperOrigin-RevId: 644319251
2024-06-18 03:24:21 -07:00
Copybara-Service
67a7b41fa7 Merge pull request #1437 from MGaetan89:add_exoplayer_setMaxSeekToPreviousPosition
PiperOrigin-RevId: 643987403
2024-06-17 06:38:02 -07:00
kimvde
eedfb9960e Reset release control from video sink when enabled
PiperOrigin-RevId: 643950097
2024-06-17 03:58:13 -07:00
tonihei
cd2250b5fa Formatting fixes and additional plumbin in legacy controller 2024-06-14 17:47:03 +01:00
Gaëtan Muller
6153b6d740 Add the ExoPlayer.Builder.setMaxSeekToPreviousPosition(long) method
This method allows customizing the maximum position when using `Player.seekToPrevious()`.

This commit also adds two new methods to `TestExoPlayerBuilder`:
- `setMaxSeekToPreviousPosition(long)`
- `getMaxSeekToPreviousPosition()`
2024-06-14 16:21:30 +01:00
bachinger
872d8f078b Rollback of cd9b914c42
PiperOrigin-RevId: 643329324
2024-06-14 06:42:31 -07:00
bachinger
cd9b914c42 Remove PreloadConfiguration from public API
This feature isn't completed, so we should remove
the public facing API to avoid confusion.

#minor-release

PiperOrigin-RevId: 643318692
2024-06-14 05:23:53 -07:00
rohks
df5352752f Add a drop-in replacement for MediaExtractor in Media3
This change introduces a new class in Media3 `MediaExtractorCompat`, designed to be a drop-in replacement for platform `MediaExtractor`. While not all APIs are currently supported, the core functionality for the most common use cases of `MediaExtractor` is now available. Full API compatibility will be achieved in the future.

PiperOrigin-RevId: 643045429
2024-06-13 10:33:38 -07:00
tonihei
ca51ed649b Fix single sample handling ProgressiveMediaPeriod when disabling tracks
When deselecting the single sample track and later re-selecting this
track, the current shortcuts in ProgressiveMediaPeriod don't handle
this case correctly and cause assertion failures.

In particular, this change fixes 3 issues:
 1. When re-selecting the single sample track, we have cleared the
    SampleQueue and need to reload the sample. The existing shortcut
    should only be applied to avoid the reload when starting from a
    non-zero position.
 2. When de-selecting the track, ProgressiveMediaPeriod is left in
    an inconsistent state where the sample queues are empty but
    loadingFinished is still true. Fix this by resetting
    loadingFinished to false.
 3. When seeking, we avoid reloading the stream if we can keep
    inside the existing samples. This logic assumes that all
    remaining samples will continue to be loaded in the queue.
    This condition isn't true though for single sample tracks
    that have been de-selected. They appear to support the seek
    inside the queue (=no seek necessary, always supported), but
    still require a new load if there is no ongoing one to load
    the sample. Fix this by checking this implicit assumption
    (still loading, or loading finished).

PiperOrigin-RevId: 642650248
2024-06-12 10:08:10 -07:00
tonihei
54f58cafed Clarify semantics of MSG_SET_IMAGE_OUTPUT
The value can be null, which isn't mentioned in the docs yet

PiperOrigin-RevId: 642622583
2024-06-12 08:30:31 -07:00
kimvde
6234a8bede Move usages of allowReleaseFirstFrameBeforeStarted inside sink
PiperOrigin-RevId: 642611061
2024-06-12 07:39:53 -07:00
bachinger
011ed909c0 Sync and map fatal and non-fatal errors from and to the legacy session
A fatal `PlaybackException` is mapped to a legacy playback state
in state `STATE_ERROR` with error code, message and extras. A
non-fatal error sent to controllers with `MediaSession.sendError`
is synced to the legacy session by setting error code and message
and merging the extras while preserving the rest of the state in
sync with the session player.

Vice versa, a `MediaController` connected to a legacy session receives
fatal errors through `Player.onPlayerErrorChanged()` and non-fatal errors
through `MediaController.Listener.onError()`.

Error codes are mapped in `LegacyConversions`. Values of error codes
in `@SessionError.ErrorCode` come from `@PlaybackExceptino.ErrorCode`
with the exception of `@SessionError.ERROR_IO` and
`@SessionError.ERROR_UNKNOWN`. These already exist in
`@PlaybackException.ErrorCode` and are mapped accordingly to avoid
semantic duplicates.

PiperOrigin-RevId: 642595517
2024-06-12 06:26:00 -07:00
claincly
f2bdc08b24 Fix minor timestamp handling issue
- Video release should check for buffer timestamp (which is renderer-offsetted), rather than the frame timestamp
- ImageRenderer should report ended after all of it's outputs are released, rather than when finished consuming its input.

Add tests for timestamp handling

PiperOrigin-RevId: 642587290
2024-06-12 05:43:22 -07:00