1300 Commits

Author SHA1 Message Date
ktrajkovski
01593a9c1f Replace RuntimeException with IllegalStateException.
Refactor to replace instances of `RuntimeException` with `IllegalStateException`.
This change ensures exceptions can be handled more specifically without
unintended catches of unrelated exceptions.

PiperOrigin-RevId: 658337459
2024-08-01 03:20:54 -07:00
Ian Baker
c637774cc2 Take Executor instead of ExecutorService
This also avoids shutting down the externally-provided ExecutorService,
which we shouldn't do (since we don't really own it, and didn't create
it).
2024-07-31 10:37:14 +01:00
Ian Baker
ff22838c0d Add javadoc summary fragment 2024-07-31 10:00:01 +01:00
Colin Kho
68e65ec884 Allow custom ExecutorService to be supplied to the Loader 2024-07-30 13:20:30 -07:00
ktrajkovski
04bfeec751 Add decoding functions to IamfDecoder and LibiamfAudioRender.
PiperOrigin-RevId: 657621223
2024-07-30 09:33:31 -07:00
Copybara-Service
e9787c4196 Merge pull request #1566 from colinkho:main
PiperOrigin-RevId: 657571792
2024-07-30 06:42:22 -07:00
rohks
8b7b1b51a9 Add MediaDataSourceAdapter
Added a new data source which acts an adapter to read media data from platform `MediaDataSource`. This enables adding the `setDataSource(MediaDataSource)` API to `MediaExtractorCompat`.

PiperOrigin-RevId: 657564901
2024-07-30 06:16:30 -07:00
rohks
867e9ea2da Add APIs to set data source using content URI, file path or HTTP URL
Added three `setDataSource` APIs in `MediaExtractorCompat`:
- `setDataSource(Context context, Uri uri, @Nullable Map<String, String> headers)` to set data source with a content URI and optional headers.
- `setDataSource(String path)` to set data source using a file path or HTTP URL.
- `setDataSource(String path, @Nullable Map<String, String> headers)` to set data source using a file path or HTTP URL with optional headers.

PiperOrigin-RevId: 657563973
2024-07-30 06:12:56 -07:00
Ian Baker
335d5e7a1d Add some tests to TrackSelectionUtilTest 2024-07-29 15:12:23 +01:00
Colin Kho
0ead7bb221 Refactor getMaxVideoSizeInViewport into TrackSelectionUtil so it can be reused in external code 2024-07-29 15:12:23 +01:00
Googler
f6dc02fa6a Unsuppress/suppress playback on suitable media output updates
PiperOrigin-RevId: 657111555
2024-07-29 01:43:46 -07:00
Copybara-Service
ccf704b30b Merge pull request #1549 from MGaetan89:min_sdk_21
PiperOrigin-RevId: 656358426
2024-07-26 05:11:46 -07:00
Googler
300453820c Selectable builtin speaker support for Wear OS
The builtin speaker is to be supported as a suitable output when that is deliberately selected for the media playback by the user in Wear OS.

PiperOrigin-RevId: 655950824
2024-07-25 07:42:31 -07:00
rohks
80202bc9f2 Use getDeclaredLength() for setting length of AssetFileDescriptor
Should have been part of the change: 0ac90855b4.

PiperOrigin-RevId: 655873821
2024-07-25 02:05:14 -07:00
tianyifeng
edd3a3f349 Fix bug where BasePreloadManager.Listener invokes from incorrect thread
The DefaultPreloadManagerTest didn't to catch this because we use main looper as the preload looper in the tests. This CL also improves the tests by assigning the preload looper with one that corresponds to a different thread.

PiperOrigin-RevId: 655664189
2024-07-24 12:41:21 -07:00
Gaëtan Muller
28edfcbb69 Remove unnecessary SDK_INT checks 2024-07-24 16:17:01 +01:00
Gaëtan Muller
7289764a65 Remove unnecessary @RequiresApi 2024-07-24 16:17:00 +01:00
Gaëtan Muller
71b8c32a6f Remove Multidex 2024-07-24 16:17:00 +01:00
kimvde
da4c962e09 Rename VideoSink methods
This is following a renaming of registerInputFrame to handleInputFrame.
- queueInputBitmap is renamed to handleInputBitmap for consistency with
  handleInputFrame.
- registerInputStream is renamed to onInputStreamChanged for consistency
  with media3 method names.

PiperOrigin-RevId: 655529699
2024-07-24 05:56:17 -07:00
rohks
0ac90855b4 Use getDeclaredLength() in setDataSource for AssetFileDescriptor
Aligns `MediaExtractorCompat` with platform behavior by using `getDeclaredLength()`
instead of `getLength()` when setting the data source. This ensures compatibility
with asset files where the length is not predefined, even though it may result
in reading across multiple logical files when backed by the same physical file.

PiperOrigin-RevId: 655153390
2024-07-23 07:17:52 -07:00
kimvde
225d336713 Remove VideoSinkProvider parameter from renderers
PiperOrigin-RevId: 655073481
2024-07-23 01:41:30 -07:00
tonihei
6147050b90 Delay flush after AudioTrack pause to ramp down volume
AudioTrack automatically ramps down volume when pausing. However,
when this happens as part of a AudioSink.flush() operation, we
need to postpone the actual flush() until the ramp down finished
in the audio system. Otherwise audio is just cut off, creating pop
sounds.

Delaying the release is fine now, because DefaultAudioSink starts
creating a new track immediately without waiting for the previous
track to be released.

Also using the opportunity to add more comments about related quirks
of the AudioTrack flush/release handling for more context.

PiperOrigin-RevId: 654794818
2024-07-22 09:58:53 -07:00
tonihei
0a8ca18305 Create new AudioTrack without waiting for previous released tracks
We currently wait until a previous AudioTrack from the same
DefaultAudioSink is released on a background thread before attempting
to initialize a new AudioTrack. This is done to avoid issues where
the releasing track blocks some shared audio memory, preventing a new
track from being created.

The current solution has two main shortcomings:
 - In most cases, the system can easily handle multiple AudioTracks
   and waiting for the release just causes unnecessary delays (e.g.
   when seeking).
 - It only waits for a previous track from the same DefaultAudioSink,
   not accounting for any other tracks that may be in the process of
   being released from other players.

To improve on both shortcomings, we can
 (1) move the check for "is releasing tracks and thus may block shared
 memory" to the static release infrastructure to be shared across all
 player instances.
 (2) optimistically create a new AudioTrack immediately without waiting
 for the previous one to be fully released.
 (3) extend the existing retry logic that already retries failed
 attempts for 100ms to only start the timer when ongoing releases are
 done. This ensures we really waited until we have all shared resources
 we can get before giving up completely. This also acts as a replacement
 for change (2) to handle situations where creating a second track is
 genuinely not possible. Also increase threshold to 200ms as the new
 unit test is falky on a real device with just 100ms (highlighting that
 the device needed more than 100ms to clean up internal resources).

PiperOrigin-RevId: 654053123
2024-07-19 10:41:17 -07:00
rohks
0def3b215c Add APIs to set data source using AssetFileDescriptor & FileDescriptor
Introduced three `setDataSource` APIs in `MediaExtractorCompat`, enabling the use of `AssetFileDescriptor` and `FileDescriptor` to set the data source.

PiperOrigin-RevId: 653957035
2024-07-19 04:00:44 -07:00
jbibik
4ba7fd0ace Fix javadoc formatting from backticks to tags
PiperOrigin-RevId: 653629763
2024-07-18 08:34:56 -07:00
tonihei
f7a726bb11 Add MediaCodec loudness controller for API35+
This controller connects the audio output to the MediaCodec so
that it can automatically propagate CTA-2075 loudness metadata.

PiperOrigin-RevId: 653628503
2024-07-18 08:31:14 -07:00
tonihei
54f5e0729e Support detached surface mode from API 35
This replaces the existing PlaceholderSurface mode with a more
efficient solution that doesn't require a GL texture or a new
thread.

PiperOrigin-RevId: 653537596
2024-07-18 02:29:57 -07:00
dancho
c05a5c6237 Rollback of 9151dbf9e6
PiperOrigin-RevId: 653192624
2024-07-17 05:08:52 -07:00
rohks
ded66debc3 Retry alternative addresses on timeout in SNTP client
Changed the default timeout for SNTP requests to 1 second.

Issue: androidx/media#1540
PiperOrigin-RevId: 652897579
2024-07-16 10:38:10 -07:00
tonihei
b4975a1b49 Remove unused field in MediaCodecAdapter
The field is always 0 as the only publicly accessible creator
methods set it to zero in all cases.

PiperOrigin-RevId: 652858810
2024-07-16 08:42:48 -07:00
ibaker
99679645fc Add a test for MediaCodecRenderer handling of IllegalStateException
This is a regression test for the bug introduced in bb9ff30c3a
which was manually spotted and fixed in 0d2bf49d6a.

Reverting the fix causes this test to fail.

This test is a bit hacky because we have to munge the stack trace of
the `IllegalStateException` to make it look like it was thrown from
inside `MediaCodec`. We deliberately do this 'badly' (e.g. using
`fakeMethod`) to avoid a future reader being confused by a
fake-but-plausible stack trace.

PiperOrigin-RevId: 652820878
2024-07-16 06:47:31 -07:00
tonihei
d4c6e39dfb Further unapplied rotation clean-up
Now the value is guaranteed to be zero (see bb9ff30c3a), we can
remove the rotation handling for it in the UI module. We can also
enforce the documentation more clearly by not even setting the
value to anything other than zero.

PiperOrigin-RevId: 652772091
2024-07-16 03:35:46 -07:00
rohks
c60baabb1c Allow changing SNTP client timeout
Added a method to set the timeout for the SNTP request.

Also changed the default timeout to 5s instead of 10s as it seemed quite high.

Issue: androidx/media#1540
PiperOrigin-RevId: 652566008
2024-07-15 12:36:30 -07:00
tonihei
0d2bf49d6a Partially revert MediaCodecException detection
The change in bb9ff30c3a removed the detection util completely,
but even on API21+, the codec exceptions can be thrown as
IllegalStateException and we should reinstate this check to
correctly classify the exceptions.

PiperOrigin-RevId: 652557091
2024-07-15 12:06:22 -07:00
ibaker
bb9ff30c3a Remove dead code related to MediaCodec now minSdk is 21
This removes several workarounds that are no longer needed, including
`codecNeedsMonoChannelCountWorkaround` which has been permanently
disabled since the (incomplete) minSdk 19 clean-up in fb7438378d.

PiperOrigin-RevId: 652495578
2024-07-15 08:51:35 -07:00
dancho
bfe4824bfd Rollback of 9151dbf9e6
PiperOrigin-RevId: 652443920
2024-07-15 05:14:58 -07:00
tonihei
c510ab81bb Update compileSdk to 35
This should have no influence on app behavior and other policies
and just allows code to depend on new API 35 platform symbols.

PiperOrigin-RevId: 652414026
2024-07-15 02:45:55 -07:00
tonihei
e96ca5a242 Decouple displaySurface from placeholderSurface
We currently use displaySurface == placeholderSurface IF codec != null
as a signal that the codec is configured with a placeholder. In the
future, this placeholder might not be needed and we can decouple this
state a bit better by leaving displaySurface == null in this case and
only using placeholderSurface instead of null when setting a Surface
to the codec.

PiperOrigin-RevId: 652391729
2024-07-15 01:04:48 -07:00
ibaker
d035b745cd Remove dead code from ExoPlayerImpl now minSdk is 21
PiperOrigin-RevId: 651815091
2024-07-12 10:27:49 -07:00
ibaker
6a9ff95bf0 Bump minSdk to 21 and remove resulting simple dead code
All other AndroidX libraries have already increased their min SDK to
21.

This change renames private symbols to remove `V21` suffixes and
similar, but doesn't change public or protected symbols with similar
names, to avoid needless breakages/churn on users of the library.

Some of the dead code removal is more complex, so I've split it out
into follow-up changes to make it easier to review.

PiperOrigin-RevId: 651776556
2024-07-12 08:11:01 -07:00
dancho
9151dbf9e6 Avoid decoder input skipping close to media end duration
MediaCodecRenderer might not be able to determine whether a sample
is last in time. Do not use decoder input skipping optimization
for buffers close to media end duration in order to ensure
last frame is rendered.

PiperOrigin-RevId: 651757814
2024-07-12 06:44:51 -07:00
Googler
4c4e24db60 Recognize QC's MV-HEVC decoder.
PiperOrigin-RevId: 651539516
2024-07-11 14:40:39 -07:00
tianyifeng
7aa70a5f2f Add Listener to BasePreloadManager to propagate preload events to apps
PiperOrigin-RevId: 651421044
2024-07-11 08:36:41 -07:00
ibaker
0ea555dae0 Stop using SubtitleTranscodingExtractor and deprecate it
The integration with `SubtitleTranscodingExtractorOutput` has been
moved inside the relevant `Extractor` implementations instead.

PiperOrigin-RevId: 651213564
2024-07-10 18:09:53 -07:00
kimvde
21992bff33 Call getFrameReleaseAction from VideoSink when enabled
VideoSink.registerInputFrame is now called for every input frame (not
only the ones that should be rendered to the input surface) because it's
the VideoSink that decides whether it wants the frame to be rendered.

PiperOrigin-RevId: 651049851
2024-07-10 09:33:11 -07:00
dancho
0ff9e0723d Expose fMP4 FLAG_READ_WITHIN_GOP_SAMPLE_DEPENDENCIES to DASH
In order for DASH playback to benefit from
FLAG_READ_WITHIN_GOP_SAMPLE_DEPENDENCIES, the fMP4 extractor flag
must be set. The smallest API change that allows this is to add an
experimental method to BundledChunkExtractor.

Add a dash end-to-end test to verify that video frames are skipped at
decoder input.

PiperOrigin-RevId: 651046676
2024-07-10 09:23:35 -07:00
tonihei
e8778d77fa Document Renderer and BaseRenderer in more detail
PiperOrigin-RevId: 651008509
2024-07-10 07:24:02 -07:00
tonihei
b145a9b35e Limit maximum number of parallel metadata retrievals.
The operation almost always acquires resources straight-away,
for example a new thread or file access. This means starting
many metadata retrievals in parallel easily causes resource
contention. This problem can be alleviated by limiting the
maximum number of parallel retrievals.

Local testing showed a 20% speedup for local file retrievals
when limited to 5 in parallel. Any more parallel retrievals
did not show any improvement or started getting slower again
the more operations are allowed.

PiperOrigin-RevId: 650674685
2024-07-09 10:25:20 -07:00
tonihei
5777e30979 Reuse thread in MetadataRetriever
MetadataRetriever is often used in a loop to retrieve data about many
items in a directory for example. In such cases, it's wasteful to
start a new 'playback' thread for each retrieval, in particular since
this thread is doing almost nothing (just triggering loads and handling
events). This change re-uses an existing thread if one exists already.

PiperOrigin-RevId: 650633343
2024-07-09 08:15:45 -07:00
dancho
6650270a4e MediaCodecVideoRenderer skips decoder inputs unused as reference
During a seek, or when playing a media with clipped start,
MCVR encounters preroll decode-only buffers that are not rendered.
Use C.BUFFER_FLAG_NO_OTHER_SAMPLE_DEPENDS_ON_THIS to determine
whether a decode-only buffer is unused as reference.
These buffers can be dropped before the decoder.
When this optimization is triggered, increment
decoderCounters.skippedInputBufferCount.

Tested in ExoPlayer demo app on "One hour frame counter (MP4)"
after enabling extractorsFactory.setMp4ExtractorFlags(
    FLAG_READ_WITHIN_GOP_SAMPLE_DEPENDENCIES);
Observe: "sib" increases on each seek.
PiperOrigin-RevId: 650566216
2024-07-09 03:43:06 -07:00