6072 Commits

Author SHA1 Message Date
sheenachhabra
04b999914a Use muxer.BufferInfo class in Muxer.java
This is to remove dependency on `MediaCodec` from `muxer module`.

PiperOrigin-RevId: 755885374
2025-05-07 09:27:40 -07:00
tonihei
b03b22575f More safely clean potential dangling references from binder stubs
Binder stubs are GC roots and may be accidentally kept long after
the surrounding objects are gone (this is partially outside our
control, e.g. another app keeps a MediaController).

To prevent memory leaks, these binder stubs need to stop referencing
other instances whose data may be kept as well.

 - All stubs except one already use a WeakReference for the main
   owning class, which is cleared as soon as the class is released.
   - This change replace the AtomicReference in ExtraSession with
     a WeakReference to make it safer.
 - If the stub holds lists of data, these should be all cleared when
   released. This wasn't done in all cases yet.
 - Some local fields for MediaSessionManager can be removed entirely
   by just accessing the static variable on demand.

PiperOrigin-RevId: 755879020
2025-05-07 09:10:27 -07:00
ibaker
1cef4ed9df Log non-square pixel aspect ratio in EventLogger
Also include `w=` and `h=` in video and surface size logging.

PiperOrigin-RevId: 755821356
2025-05-07 06:09:57 -07:00
kimvde
a5346600a2 MultipleInputVideoGraph: rely on queueInputTexture() return value
Before, we were using a boolean to wait for the input stream to be
fully registered to the CompositionVideoFrameProcessor before queueing
an input texture. This should instead be done by checking the return
value of queueInputTexture().

Also fix a few small stylistic issues.

PiperOrigin-RevId: 755770940
2025-05-07 03:15:07 -07:00
kimvde
c628027b6b Remove usage of deprecated RENDER_OUTPUT_FRAME_IMMEDIATELY
PiperOrigin-RevId: 755766598
2025-05-07 03:01:25 -07:00
Googler
faa0644ed1 Add an AndroidTest for FinalShaderProgramWrapper
PiperOrigin-RevId: 755389859
2025-05-06 08:51:31 -07:00
Googler
cc8992410a Add cause constructor to GlException
PiperOrigin-RevId: 755383268
2025-05-06 08:31:47 -07:00
tonihei
fbee549f74 Improve detection of advancing timestamp in AudioTimestampPoller
We currently accept any difference in reported frame position
as an "advancing timestamp". However, we don't check if the
resulting position is actually advancing or was only slightly
corrected, but is not yet advancing reliably.

This results in AV sync issues if the timestamp is used too early
while it's not actually advancing yet, and the potential correction
is only read 10 seconds later when we query the timestamp again.

The fix is to check whether the timestamp is actually advancing
as expected (the resulting position from the previous and the
current snapshot don't differ by more than 1ms). To avoid
permanent polling in 10ms intervals for devices that never report
a reliable timestamp, we introduce another timeout after which we
give up.

PiperOrigin-RevId: 755373666
2025-05-06 08:04:19 -07:00
tonihei
0dc5ed19e2 Improve timestamp smoothing in AudioTrackPositionTracker
The position tracker has two different position sources,
getPlaybackHeadPosition and getTimestamp. Whenever we switch
between these sources, we smooth out the position differences
over a period of one second.

This has two problems:

 1. The smoothing duration is 1 sec regardless of the actual
    position difference. So for small differences, assuming
    the new timestamp is more correct, we needlessly keep
    the tracker with a position offset for longer. For large
    differences, the smoothing may result in an extremely
    large speedup (up to 5x in theory, for a max allowed diff
    of 5 seconds smoothed over a 1 second real time period).

    The solution to this issue is to adjust the smoothing
    period to the actual difference by using a maximum
    speedup/slowdown set to 10% at the moment. Smaller
    differences are corrected faster and larger differences
    are corrected in a slightly smoother way without speeding
    up drastically. We still need an upper bound though (set
    to 1 second difference) where plainly jumping to the correct
    position is likely a better user experience than having a lenghty
    smoothing.

 2. The smoothing is only applied when switching between position
    sources. That means any position drift or jump coming from the
    same source is always taken as it is without any smoothing. This
    is problematic for the getTimstamp-based position in particular
    as it is only sampled every 10 seconds.

    The solution to this problem is to entirely remove the condition
    that smoothing only happens when switching between position
    sources. Instead we can always check whether the position drift
    compared to the last known position is more than the maximum allowed
    speedup/slowdown of 10% and if so, start applying smoothing.

    This helps to smooth out the position progress at the start of
    playback and after resumption when we switch between the position
    sources and both sources are not super reliable yet and it also
    helps for unexpected jumps in the position of getTimestamp later
    on during playback.

PiperOrigin-RevId: 755348271
2025-05-06 06:36:10 -07:00
dancho
07b278a884 Read spsData.decodedWidth and decodedHeight for MPEG-TS and H.265
Disables codec reuse and adaptation when the crop rect,
but not the decoded resolution changes.

PiperOrigin-RevId: 755315182
2025-05-06 04:37:14 -07:00
dancho
e9b2ded810 Rollback of a78d0c3994
PiperOrigin-RevId: 755302920
2025-05-06 03:54:45 -07:00
tonihei
ffb8d3ca66 Refactor AudioTimestampPoller to a smaller API surface
This moves the position estimation and plausibility checks inside
the class.

Mostly a no-op change, except that the plausible checks now use
the estimated timestamp from getTimestamp and the playback head
position to make them actually comparable. Before, we were comparing
the last snapshot states which may not necessarily be close together.
Given the large error threshold of 5 seconds, this shouldn't make
a practical difference though, just avoids noise and confusion.

PiperOrigin-RevId: 754035464
2025-05-02 09:44:43 -07:00
claincly
def4794d96 Split initializing CompositionPlayerInternal and setting composition
PiperOrigin-RevId: 753976959
2025-05-02 06:18:20 -07:00
dancho
ef39fc70d9 Disable codec reuse when only crop rect changes
Work around a bug where MediaCodec fails to adapt between
formats that have the same decoded picture resolution but
different crop.

Add a playlist of two MP4 files that reproduce the issue.

This CL implements the workaround for H.265 and Mp4

PiperOrigin-RevId: 753976872
2025-05-02 06:16:11 -07:00
michaelkatz
52d9cfdcb7 Add plumbing of ScrubbingModeParameters from ExoPlayer to Renderers
PiperOrigin-RevId: 753959866
2025-05-02 05:09:04 -07:00
tonihei
aabf840d1d Update Uri shared to platform mediasession to only use RequestMetadata
This already the case for the platform Queue's MediaDescription, but
we currently use the localConfiguration.uri for the platform
MediaMetadata field even though we intentionally strip locaConfiguration
fields before sharing with other apps.

PiperOrigin-RevId: 753952733
2025-05-02 04:35:58 -07:00
ivanbuper
bd24ec08d1 Add test to catch single asset audio sequence underruns
This test previews a composition containing only a single audio asset
sequence. The audio asset is a 1s, stereo, locally available WAV file.
Catching an underrun in this test is a likely indication of something
being seriously wrong with the device's state or a performance
regression on the audio pipeline.

This test is a verification of the fix in 2e20d35c3d. Without this fix
the newly added test fails because MediaCodecAudioRenderer attempts to
use dynamic scheduling with AudioGraphInputAudioSync
(which is unsupported) after EoS is signalled.

PiperOrigin-RevId: 753552825
2025-05-01 05:33:15 -07:00
ivanbuper
e06e9b4cc9 Detect underruns with AudioTrack#getUnderrunCount() in DefaultAudioSink
Prior to this change, DefaultAudioSink (via AudioTrackPositionTracker)
would use best-effort logic to infer underruns in the underlying
AudioTrack. This logic would miss underrun events (e.g. newly added test
fails if run without any changes to AudioTrackPositionTracker).

This change should help more accurately detect regressions in the audio
pipeline.

PiperOrigin-RevId: 753550187
2025-05-01 05:20:02 -07:00
tonihei
8bcef5df6d Add static completion ratio to media resumption
This allows to show a seekbar on the resumption notification
after reboot.

PiperOrigin-RevId: 753538903
2025-05-01 04:30:29 -07:00
sheenachhabra
d2fcf0c4eb Make Muxer interface extend AutoCloseable
PiperOrigin-RevId: 753534910
2025-05-01 04:15:29 -07:00
shahddaghash
7c13204c3b Use imageDurationMs to determine image asset loading
Updated the createAssetLoader method to directly use the `mediaItem.localConfiguration.imageDurationMs` to determine if an ImageAssetLoader should be created for an image. This is specifically used for determining whether a motion photo should be treated as an image or as a video.

PiperOrigin-RevId: 753235616
2025-04-30 11:03:33 -07:00
Copybara-Service
acdc71bb63 Merge pull request #2386 from DolbyLaboratories:dlb/cmcd/nullable-configuration
PiperOrigin-RevId: 753210729
2025-04-30 10:04:01 -07:00
sheenachhabra
bfb8c5c237 Fix muxer interface java doc
PiperOrigin-RevId: 753203794
2025-04-30 09:45:50 -07:00
ibaker
8dc8003afc Deprecate Util.compareLong in favour of Long.compare
The `Long` method was only added in API 19, so wasn't previously
usable when ExoPlayer's minSdk was 16.

PiperOrigin-RevId: 753185351
2025-04-30 08:50:22 -07:00
Copybara-Service
df41f6b041 Merge pull request #2387 from DolbyLaboratories:dlb/cmcd/pr-key-not-allowed
PiperOrigin-RevId: 753181724
2025-04-30 08:40:00 -07:00
ibaker
c137d27850 Add support for S_TEXT/SSA CodecId in MKV files
This change renames the existing `sample_with_ssa_subtitles.mkv` test
file (with `S_TEXT/ASS` codec ID) to `sample_with_ass_subtitles.mkv`
(so the file name matches the codec ID), and forks a new test file
called `sample_with_ssa_subtitles.mkv` with the `S_TEXT/SSA` codec ID.
`MatroskaExtractorTest` then asserts that both these files produce
identical dump files.

Issue: androidx/media#2384
PiperOrigin-RevId: 753164883
2025-04-30 07:48:25 -07:00
Copybara-Service
e4b23f6b6c Merge pull request #2377 from bubenheimer:handleSetDeviceVolume_flags
PiperOrigin-RevId: 753132783
2025-04-30 05:52:20 -07:00
jbibik
49d929b212 [ui-compose] Eliminate race condition in PresentationState
PresentationState creation and listener registration are not an atomic operation. This happens because the LaunchedEffect which starts the listen-to-Player-Events coroutine can be pre-empted with other side effects, including the ones that change something in the Player.

rememberPresentationState function creates a PresentationState object and initialises it with the correct fresh values pulled out of the Player. The subscription to Player events with a registration of a Listener (via PresentationState.observe()) is not immediate. It *returns* immediately, but is instead scheduled to happen later, although within the same Handler message. Other LaunchedEffects could have been scheduled earlier and could take place between the button state creation and listener subscription.

This is not a problem if no changes to the player happen, but if we miss the relevant player events, we might end up with a UI that is out of sync with reality. The way to fix this is to pull the latest values out of the Player on demand upon starting to listen to Player events.

PiperOrigin-RevId: 753129489
2025-04-30 05:39:15 -07:00
Mattias Buelens
ec01011374 Fix CMCD sending pr=0.00 even when key is not allowed 2025-04-30 14:28:20 +02:00
Mattias Buelens
a019de887c Allow CmcdConfiguration.Factory to return null to disable CMCD 2025-04-30 14:19:20 +02:00
tonihei
deb466c496 Add artwork to stored preferences
This allows it to be displayed after reboot when we can't reload
it safely over network.

PiperOrigin-RevId: 753122948
2025-04-30 05:13:05 -07:00
sheenachhabra
8d87a69351 Rollback of a31c7ad9a8
PiperOrigin-RevId: 753104435
2025-04-30 04:01:19 -07:00
jbibik
16c071109a [ui-compose] Make PlayerSurface accept a nullable Player
`PlayerSurface` is just an `AndroidView` composable wrapping `SurfaceView` and `TextureView`. It uses the `Player` passed to it to set the `SurfaceHolder`s from those `SurfaceView`/`TextureView` objects. However, it does not technically need the Player to be created - the result will just be an empty Surface.

Add an optimisation to PlayerSurfaceInternal that avoids preemptive clearing of the Surface on the old Player. This helps avoid a costly creation of a surface placeholder right before (potentially) assigning the new Surface to that player.

PiperOrigin-RevId: 752840145
2025-04-29 12:34:35 -07:00
Uli Bubenheimer
0d2b831c94 Add missing @C.VolumeFlags for SimpleBasePlayer.handleSetDeviceVolume 2025-04-29 17:27:54 +01:00
bachinger
965fc81f08 Convert ResultReceivers before sending to legacy app
PiperOrigin-RevId: 752739239
2025-04-29 08:11:21 -07:00
ibaker
e5d3236649 Use ReorderingBufferQueue in H.262 UserDataReader
Issue: androidx/media#2372
PiperOrigin-RevId: 752721649
2025-04-29 07:13:02 -07:00
ibaker
49064c4b82 Stabilize the ExoPlayer.Builder.setSeekForward/BackIncrementMs APIs
The equivalent getters are already stable on `Player`.

Issue: androidx/media#2286
PiperOrigin-RevId: 752686185
2025-04-29 05:02:03 -07:00
ibaker
5775abd7e3 Rename ReorderingSeiMessageQueue to remove reference to SEI
In a follow-up change I am going to use this class in a non-SEI context
for H.262 'user data'.

Issue: androidx/media#2372
PiperOrigin-RevId: 752683541
2025-04-29 04:52:03 -07:00
kimvde
721f3c517b Increase test timeout on emulator
CompositionMultipleSequencePlaybackTest is flaky on emulator because
the pipeline is slow on these devices.

PiperOrigin-RevId: 752667954
2025-04-29 03:51:08 -07:00
kimvde
293c55e062 Adapt InputVideoSink.onInputStreamChanged for CompositionPlayer
The output of CompositionPlayer should be considered as a single clip
(not a playlist) so we should only propagate the first stream change
event in that case.

PiperOrigin-RevId: 752661523
2025-04-29 03:23:42 -07:00
Googler
cfa13e9616 Update Boxes to support writing negative timestamps to edit list
Previously when there were negative timestamps, the tkhd duration was incorrectly equal to the full track duration rather than the presentation duration of the edit list. From the [docs](https://developer.apple.com/documentation/quicktime-file-format/track_header_atom/duration) - "The value of this field is equal to the sum of the durations of all of the track’s edits".

PiperOrigin-RevId: 752655137
2025-04-29 02:59:28 -07:00
kimvde
48832cbbc4 Remove unused setter in PlaybackVideoGraphWrapper.Builder
PiperOrigin-RevId: 752639277
2025-04-29 01:57:12 -07:00
ibaker
ecfd9d1e92 Clear TextRenderer.streamError when disabling or changing stream
Previously a stream error from one playlist item was incorrectly
preserved when switching to the next one, resulting in playback hanging.

Issue: androidx/media#2328
PiperOrigin-RevId: 752624979
2025-04-29 01:05:21 -07:00
kimvde
4d7046c187 Fix failing test
This was introduced by 0f08c97221.

PiperOrigin-RevId: 752273544
2025-04-28 05:52:48 -07:00
kimvde
0f08c97221 Handle rendering in VideoGraph time
Before this CL, the buffer adjustment (which allows to convert from
ExoPlayer time to VideoGraph time) was added to the frame timestamps
before feeding them to the VideoGraph, and then subtracted at the
VideoGraph output. The playback position and stream start position used
for rendering were in ExoPlayer time.

This doesn't work for multi-sequence though because the adjustment might
be different depending on the player (after a seek for example).

To solve this problem, this CL handles rendering in VideoGraph time
instead of ExoPlayer time. More concretely, the VideoGraph output
timestamps are unchanged, and the playback position and stream start
position are converted to VideoGraph time.

PiperOrigin-RevId: 752260744
2025-04-28 04:59:13 -07:00
kimvde
8968d9fa45 Remove VideoSinkProvider
PiperOrigin-RevId: 752227606
2025-04-28 02:48:06 -07:00
ibaker
170098b400 Fix SSA and SRT to display an in-progress cue when enabling subtitles
Issue: androidx/media#2309
PiperOrigin-RevId: 751424941
2025-04-25 08:27:44 -07:00
jbibik
35303c94a1 [ui-compose] Refactor PlayerSurface to use Kotlin function references
PiperOrigin-RevId: 751424812
2025-04-25 08:25:35 -07:00
claincly
09ce64ec21 Share some code for setting video output
The code for setting the video output is almost the same across both places,
with one callsite supporting less types of video output. I think it's still
better to share the code, to minimize the margin for mistake later.

PiperOrigin-RevId: 751423005
2025-04-25 08:20:33 -07:00
ibaker
8bf658cd79 Remove some hard-coding of file and content URI schemes
PiperOrigin-RevId: 751417429
2025-04-25 08:05:22 -07:00