22296 Commits

Author SHA1 Message Date
ibaker
de9216462d Dump per-channel PCM data in CapturingAudioSink
This more clearly shows when a diff is on specific channels, or as a
result of channels being swapped.

PiperOrigin-RevId: 736920754
2025-03-14 11:05:31 -07:00
ibaker
800a66a8ca Remove unnecessary @SuppressWarnings("unused")
PiperOrigin-RevId: 736919032
2025-03-14 11:01:03 -07:00
tonihei
6b1a2aff98 Cleanup some dead code and lint warnings in session compat code
PiperOrigin-RevId: 736861977
2025-03-14 07:54:41 -07:00
ibaker
df489e2f94 Special-case empty and all-zero buffers in CapturingAudioSink dumps
These are common in robolectric playback tests, because our
`ShadowMediaCodecConfig` always returns empty buffers when 'decoding'
audio.

PiperOrigin-RevId: 736836767
2025-03-14 06:05:32 -07:00
Googler
641434ff31 Synthesize CSD data from AV1 sample in Muxer.
Synthesize CSD data from the key frame bit stream if CSD is not available for AV1 in Muxer.

PiperOrigin-RevId: 736815774
2025-03-14 04:16:21 -07:00
ibaker
fe8163838e Update Format.pcmEncoding docs to include lossless compression
This field has been used for encoded FLAC data since ba8f55694a

PiperOrigin-RevId: 736811640
2025-03-14 04:00:30 -07:00
tonihei
54c64b41c4 Add toString to TrackGroup(Array)
These classes are often logged in error messages or tests. The
current output is just the hash code which makes it hard to debug.

PiperOrigin-RevId: 736799086
2025-03-14 02:58:06 -07:00
tonihei
d37f05238a Check language/role flags before merging adaptation sets
The spec technically allows to mark adaptation sets with the switching
property if they allow seamless switching with non-overlapping
segments. This is typically only used for compatible content (e.g.
different codecs), but the spec allows it to be used for other
content as well (e.g. different languages, roles). ExoPlayer's concept
of a TrackGroup only allows formats with the same language and role
flags to be merged, so we should check that before merging.

Issue: androidx/media#2222

#cherrypick

PiperOrigin-RevId: 736564055
2025-03-13 10:54:17 -07:00
ibaker
412ba2e201 Replace links to xiph.org/flac/format.html with RFC 9639
PiperOrigin-RevId: 736564046
2025-03-13 10:52:33 -07:00
ibaker
dfebe72b6a Add 32-bit FLAC test files, and use them in some tests
The matroska file works without further changes. The FLAC container
file works with `lib-flac-decoder` depending on a bundled `libflac`
implementation, but not when using
`androidx.media3.extractor.flac.FlacExtractor` with a `MediaCodec` FLAC
decoder because the media3 extractor doesn't support 32-bit FLAC yet.
The fix for that is in a follow-up change.

`bear_32bit.flac` was generated from `bear.flac` with `ffmpeg`:

```shell
$ ffmpeg \
    -i bear.flac \
    -c:a flac \
    -sample_fmt s32 \
    -strict experimental \
    bear_32bit.flac
```

`bear-flac-32bit.mka` was generated by re-muxing `bear_32bit.flac`,
also with `ffmpeg` (trying to convert `bear-flac-24bit.mka` to 32-bit
didn't work, the resulting file was still 24-bit):

```shell
$ ffmpeg \
    -i ../flac/bear_32bit.flac \
    -c:a copy \
    bear-flac-32bit.mka
```

Issue: androidx/media#2197
PiperOrigin-RevId: 736552251
2025-03-13 10:21:18 -07:00
tonihei
41722be02e Clarify that method can only be called after onCreate
And improve error message if access to the notification controller
happens without a base context.

#cherrypick

PiperOrigin-RevId: 736545574
2025-03-13 10:05:30 -07:00
ivanbuper
d777a11840 Move createCodecProfileLevel() to MediaCodecUtil and simplify usages
This is a non-functional change.

PiperOrigin-RevId: 736534306
2025-03-13 09:34:10 -07:00
tonihei
816d5cb86b Refine logic of when to skip placeholder surface buffers
We want to skip the buffers in sync with playback, which
only makes progress once started. This means we can simplify
the logic to only apply the 30ms threashold when started
(which was indirectly the threashold used already because the
frame release would return TRY_AGAIN_LATER).

This means we can remove the
shouldSkipLateBuffersWhileUsingPlaceholderSurface as it was
only used in tests to prevent skipping while we were not
started.

PiperOrigin-RevId: 736533043
2025-03-13 09:31:17 -07:00
tianyifeng
6edb687aef Do not dump buffers not fully consumed repeatedly in CapturingAudioSink
#cherrypick

PiperOrigin-RevId: 736495022
2025-03-13 07:19:01 -07:00
claincly
4991e623c9 Use the actual render time in VideoFrameMetadataListener
This listener is used by apps to associate render timestamp and presentation
timestamp when using a SurfaceTexture, so this timestamp must match up with
what's set in `eglPresentationTimeANDROID`.

PiperOrigin-RevId: 736494784
2025-03-13 07:17:18 -07:00
ibaker
aa6d8a7666 Set connection & read timeout in HTTP data source contract tests
This timeout can be very low in these tests because we are always
trying to connect to an in-process `MockWebServer`. With the default
timeout value any 'resource not found' tests which use a domain that
can't be connected to take the max timeout (between 8s and 16s depending
on the HTTP stack).

PiperOrigin-RevId: 736466854
2025-03-13 05:16:59 -07:00
ivanbuper
6d00fe58b5 Remove deprecated BaseAudioProcessor in exoplayer module
`BaseAudioProcessor` was moved to `common` over two years ago.

PiperOrigin-RevId: 736179562
2025-03-12 10:27:24 -07:00
kimvde
03892cc1b5 VideoSink: merge setStreamStartPositionUs and onInputStreamChanged
setStreamStartPositionUs and onInputStreamChanged should both be called
when the stream changes.

PiperOrigin-RevId: 736121598
2025-03-12 07:17:41 -07:00
ibaker
99767c6e25 Use info from unseekable Xing frame when falling back to CBR seeking
This change uses the duration and byte count of the Xing frame, if
they're present, to estimate the bitrate of the stream. The seeking
will still be inaccurate (because we're doing CBR seeking in a VBR
stream), but it will be more accurate than basing the bitrate on the
first MP3 frame we read. It will also mean the duration reported is
accurate.

This change also ensures that if the Xing frame contains the number of
audio bytes but no ToC, the audio data length is still propagated into
the `XingSeeker` (and therefore into the `ConstantBitrateSeeker` too).

Issue: androidx/media#2194
PiperOrigin-RevId: 736100104
2025-03-12 05:50:35 -07:00
shahddaghash
1918a256cc Add a test for playing CompositionPlayer again after playback ends
A problem was discovered in Composition demo app where after playing a composition using CompositionPlayer, pressing the "play" button again would not restart the playback. This issue has been resolved, just adding a test to make sure we're not missing any regressions.

PiperOrigin-RevId: 735793488
2025-03-11 09:59:53 -07:00
michaelkatz
2729dbb8a9 Limit dynamic scheduling interval by the audio track buffer size
In certain bluetooth playback scenarios, it was found that the delta of audio duration written by the AudioSink from the current playback position was greater than the size of the audio track buffer, causing underruns.

The solution is to utilize the audio track buffer size as an upper limit for an audio renderer's getDurationToProgress.

PiperOrigin-RevId: 735761604
2025-03-11 08:16:22 -07:00
bachinger
a7c727e2f3 Add test case for live pre-roll
PiperOrigin-RevId: 735736616
2025-03-11 06:38:18 -07:00
bachinger
593c6fa1e8 Map live interstitials to ad playback state
After this change, updates of the live HLS playlists are  reflected
in the ad playback state. Interstitials are inserted into new
or existing ad groups according to the current ad playback state.

PiperOrigin-RevId: 735733207
2025-03-11 06:22:58 -07:00
ibaker
ecac78f630 MP3 CBR fallback: Remove null check and add a comment
PiperOrigin-RevId: 735708126
2025-03-11 04:35:08 -07:00
claincly
44b3a43652 Use VideoGraph as top level component
...and reduce the number of classes/interfaces

PiperOrigin-RevId: 735451687
2025-03-10 11:30:20 -07:00
kimvde
ce59680d0f Always call onProcessedStreamChanged for first stream for effects
Before this CL:
- MediaCodecVideoRenderer.onProcessedStreamChanged was called for the
  first stream in CompositionPlayer.
- MediaCodecVideoRenderer.onProcessedStreamChanged was NOT called for
  the first stream in ExoPlayer.setVideoEffects.

This discrepancy was adding some complexity to the code, making it less robust.

PiperOrigin-RevId: 735439320
2025-03-10 10:58:23 -07:00
ibaker
e8842b939c Prevent ParsableByteArray.bytesLeft() returning a negative value
PiperOrigin-RevId: 735417945
2025-03-10 10:03:21 -07:00
shahddaghash
a110b02142 Move TestTransformerBuilder to test-util
This improves consistency by grouping it with other test builders and resolves a missing build rule, ensuring developers can properly use it for testing.

PiperOrigin-RevId: 735396181
2025-03-10 08:59:54 -07:00
ibaker
168c464095 Add cbr-always test for new asset with Xing frame without ToC
Issue: androidx/media#2194
PiperOrigin-RevId: 735382972
2025-03-10 08:22:49 -07:00
ivanbuper
06163f3dfa Add float PCM support to TrimmingAudioProcessor
This was requested in Issue: androidx/media#2191.

PiperOrigin-RevId: 735375746
2025-03-10 07:59:36 -07:00
tonihei
222950cfd1 Make foreground service timeout configurable
This allows apps to set a shorter timeout if so desired.

Issue: androidx/media#2206

#cherrypick

PiperOrigin-RevId: 735360459
2025-03-10 07:00:47 -07:00
sheenachhabra
66995a8816 Add checkNotNull for all getVideoCapabilities and similar calls
PiperOrigin-RevId: 735358217
2025-03-10 06:50:54 -07:00
kimvde
15fa27cd9a Split VideoSink.setStreamTimestampInfo
This is a step towards merging setStreamStartPositionUs with
onInputStreamChanged, which makes sense as the start position can only
change on stream change.

PiperOrigin-RevId: 735309009
2025-03-10 03:24:04 -07:00
kimvde
a4442a6cc5 Always signal stream changes through render control in DefaultVideoSink
This is part of an effort to remove VideoSink.onRendererEnabled,
which is a step towards making the VideoSink interface renderer
agnostic. The plan is to merge onRendererEnabled, setStreamTimestampInfo
and onInputStreamChanged into a single method in VideoSink.

This change is a no-op refactoring

PiperOrigin-RevId: 735293983
2025-03-10 02:19:23 -07:00
tonihei
91ecc16198 Ensure notification is removed when shouldShowNotification==false
We currently combine stopping the FGS and optionally removing the
notification in one method, which unnecessarily gates its logic on
checking the desired foreground state again. This causes a bug where
the notification should be removed (because shouldShowNotification
returns false), but stays visible because the service is allowed
to stay in the foreground and the notification removal code is not
triggered.

#cherrypick

Issue: androidx/media#2211
PiperOrigin-RevId: 735126704
2025-03-09 09:15:29 -07:00
shahddaghash
8702554591 Remove setVideoEffects_failsWithoutLibEffectsDep test
Removed test that attempted to verify behavior when the lib-effect dependency is missing. This is because it fails when adding lib-transformer to test-util dependency. The introduction of lib-transformer brought in lib-effect as a transitive dependency, which conflicted with the test's expectation of the class not being present.

PiperOrigin-RevId: 734547629
2025-03-07 07:18:19 -08:00
shahddaghash
bf2e338fc2 Increase the buffer size for TestUtil.addAudioDecoders/Encoders
This is a step towards unifying ShadowMediaCodecConfig for ExoPlayer and Transcoding tests.

The buffer size for ExoPlayer's CodecConfig is set to 150_000. This is because some test media has samples larger than 100kB. We can increase the buffer size for Transcoding-related codec configurations.

PiperOrigin-RevId: 734297632
2025-03-06 14:54:07 -08:00
shahddaghash
cfbd6c5493 Add ability to force Transformer failure in Robolectric tests
When `forceTransformerToFail` is set to true, the builder will use a `FailingMuxerFactory` which creates a `FailingMuxer` that throws a `MuxerException` when attempting to write sample data. This ensures Transformer will fail as muxers are used for all cases (transmuxing and transcoding).

PiperOrigin-RevId: 734281681
2025-03-06 14:10:01 -08:00
jbibik
8dcfa1afbe [ui-compose] Move ComposeBom from implementation to api
PlayerSurface exposing the Modifier argument means the gradle dependency needs to be stricter

#cherrypick

PiperOrigin-RevId: 734237616
2025-03-06 12:09:48 -08:00
ibaker
96d98a24fc Add MP3 test asset with Xing header but no Table of Contents
These tests show the current behaviour:
1. Without customization: not seekable
2. With 'enable CBR' flag:
   * File length known: seekable but duration very incorrect
   * File length unknown: not seekable (even though the Xing frame
     contains the number of bytes in the mp3 stream).

Follow-up test changes will:
1. Add a test for the cbr-always case for this file (branched from the
   files submitted in this change).
2. Add a new similar test asset with no ToC but with trailing garbage
   bytes, to verify that the length from the Xing frame is used.

Then follow-up implementation changes will update Mp3Extractor to use
duration and byte length from a Xing frame when falling back to CBR
seeking.

Issue: androidx/media#2194
PiperOrigin-RevId: 734164879
2025-03-06 09:01:40 -08:00
michaelkatz
03a0fb4219 Create API enabling use of MediaCodec.BUFFER_FLAG_DECODE_ONLY
If feature is enabled, MediaCodecVideoRenderer will include the `MediaCodec.BUFFER_FLAG_DECODE_ONLY` flag when queuing decode-only input buffers. This flag will signal the decoder to skip the decode-only buffers thereby resulting in faster seeking.

PiperOrigin-RevId: 734152464
2025-03-06 08:25:01 -08:00
shahddaghash
c030e49dd6 Refactor ShadowMediaCodec to be used for transcoding cases
This is a step towards unifying ShadowMediaCodecConfig for ExoPlayer and Transcoding tests.

This change includes extracting encoder/decoder configurtion logic to a static method that can be called by `ShadowMediaCodecConfig.CodecImpl#configure()` and `TestUtil#addCodec()`.

This is a non-functional refactor.

PiperOrigin-RevId: 734137675
2025-03-06 07:38:41 -08:00
tianyifeng
c95516f0ab Fix proguard-rules.txt path reference in DefaultDownloaderFactory
PiperOrigin-RevId: 734111303
2025-03-06 06:04:47 -08:00
kimvde
377136419d MCVR: call VideoSink.setStreamTimestampInfo on stream change
The start position and buffer adjustement are only allowed to change
when the stream changes so it makes more sense to call
setStreamTimestampInfo when the stream changes.

This is part of an effort to simplify stream change notification to the
video sink, to ease implementation of multi sequences preview.

PiperOrigin-RevId: 734062686
2025-03-06 02:55:41 -08:00
kimvde
ab2affa5a5 Remove references to renderer from VideoFrameReleaseControl's Javadoc
This is a step towards removing the assumption that there is only one
sequence and therefore one renderer feeding data to DefaultVideoSink and
VideoFrameReleaseControl.

PiperOrigin-RevId: 734062629
2025-03-06 02:53:58 -08:00
kimvde
7e6089d3aa VideoFrameReleaseControl: merge onEnabled and onProcessedStreamChange
This is a step towards removing the assumption that there is only one
sequence and therefore one renderer feeding data to DefaultVideoSink and
VideoFrameReleaseControl.

This is a no-op refactoring.

PiperOrigin-RevId: 734044100
2025-03-06 01:48:18 -08:00
ivanbuper
f996a5e3e4 Add support for FLOAT_PCM in ChannelMappingAudioProcessor
This was requested in Issue: androidx/media#2191 for playback of Opus and Vorbis
files with more than two channels with a float PCM pipeline.

Also, add ChannelMappingAudioProcessorTest.

PiperOrigin-RevId: 733766680
2025-03-05 09:39:36 -08:00
ibaker
d7574ffd66 Add ParsableByteArray.peekCodePoint and deprecate peekChar(Charset)
This is analagous to `String.codePointAt` and similar methods. By
dealing only in unicode code points, and returning an `int`, we can
avoid having to reason about how to handle UTF-8 code units that
require two UTF-16 code units (each one a Java `char`) to represent
them.

The zero-arg `peekChar` method remains undeprecated, because it behaves
as "you'd expect" when compared to `peekUnsignedByte` (always reads two
big-endian bytes).

PiperOrigin-RevId: 733752645
2025-03-05 08:55:32 -08:00
michaelkatz
d7163534ff Use ExoPlaybackException.MediaPeriodId in prewarming error handling
With using the `MediaPeriodId` from the `ExoPlaybackException`, ExoPlayerImplInternal can set the same id to the renderer group(primary and secondary).

Tested with `ExoPlayerWithPrewarmingRenderersTest` error-based unit tests like `play_errorByPrewarmingSecondaryRendererAfterAdvancingReadingPeriod_doesNotResetPrimaryRenderer`. If the media period was not set in BaseRenderer then the exception would have the incorrect mediaperiod, attribute the error to the non-prewarming renderer, and the test would fail.

PiperOrigin-RevId: 733744777
2025-03-05 08:32:16 -08:00
jbibik
bc9a974e07 Align release notes labels spelling
PiperOrigin-RevId: 733717073
2025-03-05 07:00:00 -08:00