897 Commits

Author SHA1 Message Date
claincly
a18d96c320 Fix blank video when switching on/off screen
This happens when using `ExoPlayer.setVideoEffects()`.

This CL also fixes the first frame not rendered problem, originally solved in
7e65cce967, but rolled back in 5056dfaa2b because the solution introduces
the flash that is observed in b/292111083.

Before media3 1.1 release, the output size of `VideoFrameProcessor` is not
reported to the app. This was changed later after introducing
`CompositingVideoSinkProvider`, where the video size after processing **is**
reported to the app. After this CL, the size is again, not reported.

PiperOrigin-RevId: 602345087
(cherry picked from commit dcae49a561d3dd0a67a44a913c063b0232bbc445)
2024-02-08 17:29:13 +00:00
tonihei
dfe47219f9 Update skip silence algorithm
The updated algorithm has two main improvements:
 - The silence padding is not constant but a ratio of the original
   silence (up to a defined max) to more naturally represent the
   original gaps.
 - The silence is not instantly going to zero, but uses a ramp down
   and up for a smooth volume transition and also retains a small
   percentage of the original noise for more natural "silences" that
   still contain some background noise.

#minor-release

Issue: google/ExoPlayer#7423
PiperOrigin-RevId: 602322442
(cherry picked from commit bb533332f4b6f46ac9d5ca17cb7943bd1bdb7dd2)
2024-02-08 17:29:12 +00:00
tonihei
4560611bd0 Remove misleading @CanIgnoreReturnValue
The return value of onConfigure must not be ignored as it specifies
the output format of the processor, which may be different from the
input format.

#minor-release

PiperOrigin-RevId: 601799440
(cherry picked from commit 2fc5590e7aa5890f22d020778f924e1586a3f3ba)
2024-02-08 17:29:12 +00:00
tonihei
4a7442ef3a Replace or suppress deprecated usages
Many usages are needed to support other deprecations and some
can be replaced by the recommended direct alternative.

Also replace links to deprecated/redirected dev site

PiperOrigin-RevId: 601795998
(cherry picked from commit ed5b7004b435f71c5a37f5db12c3641fbba9be48)
2024-02-08 17:29:12 +00:00
ibaker
4382aa0b34 Make Cea608Parser and Cea708Parser package-private
It's likely that we will merge these back into their `XXXDecoder`
implementations, but this smaller change allows us to avoid including
these public symbols in the upcoming release.

#minor-release

PiperOrigin-RevId: 601432629
(cherry picked from commit 12157a6b1aba2c59c54e6b7d34bad396008b5f29)
2024-01-25 16:20:26 +00:00
ibaker
8770286a8e Throw immediately from ExoPlayer.setVideoEffects() if dep not found
This method works by reflectively loading classes from the `lib-effect`
module, in order to avoid a hard dependency on this module for ExoPlayer
users that don't want video effect functionality. This change ensures
that a failure to load the necessary classes fails immediately, instead
of on a later thread inside `MediaCodecVideoRenderer` when the
reflection currently happens.

Also update the javadoc to make the dependency requirement clear.

#minor-release

PiperOrigin-RevId: 601387957
(cherry picked from commit a6812156e6ea5ea2dc45d222f402065c0da46b62)
2024-01-25 11:42:44 +00:00
jbibik
748fec1ac6 Add a setter of SubtitleParser.Factory to MediaSource.Factory
DASH: `DashMediaSource.Factory` would only propagate it to `DashChunkSource.Factory` -> `BundledChunkExtractor.Factory`

SS: `SSMediaSource.Factory` -> `SsChunkSource.Factory`

HLS: `HlsMediaSource.Factory` -> `HlsExtractorFactory`

Remove nullability of SubtitleParser.Factory across the stack

#minor-release

PiperOrigin-RevId: 601250013
(cherry picked from commit f103a2dcf565a311b94171e5714e4ee8ad8c5f65)
2024-01-25 11:42:44 +00:00
jbibik
0713d56efc Add setters of SubtitleParser.Factory and experimental toggle
The `SubtitleParser.Factory` is no longer @Nullable and the experimenting toggle is used to enable/disable the use of this factory for subtitle parsing during extraction.

The three places that will hold the "truth" for the `SubtitleParser.Factory` are: BundledChunkExtractor.Factory, SsChunkSource.Factory, DefaultHlsExtractorFactory

DASH: `DashMediaSource.Factory` would only propagate it to `DashChunkSource.Factory` -> `BundledChunkExtractor.Factory`

SS: `SSMediaSource.Factory` -> `SsChunkSource.Factory`

HLS: `HlsMediaSource.Factory` -> `HlsExtractorFactory`

#minor-release

PiperOrigin-RevId: 601151615
(cherry picked from commit 4d7b23f0d117a67df33f5cab25d5971a72dc8017)
2024-01-25 11:42:44 +00:00
jbibik
db420350f8 Remove SubtitleParser.Factory references from Hls/Ss/DashMediaPeriod
Those classes only needed to have access to a `SubtitleParser.Factory` to get a potentially updated `Format` for TrackGroups. The `SubtitleParser.Factory` was only used to check the support for the `mimeType` and getting some cue-related behaviour.

This introduced complexity in a way that both Periods and Extractors needed to have the same `SubtitleParser.Factory` in their individual stacks. To ensure that the sample queue would get the same transcoded/original format.

Instead, now we expose `getOutputTextFormat` methods on `ChunkExtractor.Factory`, `SsChunkSource.Factory` and `HlsExtractorFactory`. Those are the dependencies that Hls/Ss/DashMediaPeriod can make use of to delegate the format-updating logic to.

#minor-release

PiperOrigin-RevId: 601130714
(cherry picked from commit 966b7108976706c1b0a1a8a2b82ae8daa747bda3)
2024-01-25 11:42:44 +00:00
michaelkatz
db0262efdb Keep stream offset alive in ImageRenderer until stream transition
Fix modeled after OutputStreamInfo usage for stream offset in `MediaCodecRenderer`

PiperOrigin-RevId: 601109900
(cherry picked from commit 688622eb47ac707affa824d3d68f44755f947380)
2024-01-25 11:42:44 +00:00
ibaker
97b8f1add9 Add proguard keep rules for ExoPlayer.setVideoEffects
These symbols in `lib-effect` are referenced via reflection from
`CompositingVideoSinkProvider` in `lib-exoplayer` in order to avoid
a hard dependency from `lib-exoplayer` to `lib-effect`. Without this
keep rule, the symbols can get renamed by R8 resulting in the
invocations failing.

#minor-release

PiperOrigin-RevId: 601074636
(cherry picked from commit e5621cc70960bf76c5651f6f368f78aeacac82b3)
2024-01-25 11:42:44 +00:00
tianyifeng
3a222473e9 Internal change
PiperOrigin-RevId: 600784733
(cherry picked from commit 0c0b19e26e506763af95a53c916fdbf853f81cec)
2024-01-25 11:42:43 +00:00
ibaker
8e97895e9f Test parsing-during-extraction in ClippedPlaybackTest
We keep the previous parsing-during-rendering tests, even though they
can be a bit flaky, because this is an important regression test. The
regression risk is lower for this instrumentation test compared to
robolectric tests with different `ShadowLooper` behaviour.

#minor-release

PiperOrigin-RevId: 600781035
(cherry picked from commit a53f3451ddef819c5b0fb5ff1e9952a98a56bfc3)
2024-01-25 11:42:43 +00:00
tonihei
5ac0c8beee Fix cleared metadata when repeating the same item
Issue: androidx/media#1007

#minor-release

PiperOrigin-RevId: 600477540
(cherry picked from commit c6bf380d50d4601ce6ec567ebd56ccf5e36fa8cf)
2024-01-25 11:42:43 +00:00
tonihei
6632531c4a Catch exceptions when retrieving current device from audio manager
We can just continue to assume that we don't know the current device.
This case happens on the latest Robolectric release where this method
call isn't implemented yet. As we not generally assume that the
method can throw, this workaround can be removed once Robolectric
is updated again.

#minor-release

PiperOrigin-RevId: 600426851
(cherry picked from commit 81615dd5b56dddc008401a7a8513baf5336c01b6)
2024-01-25 11:42:43 +00:00
tonihei
5b7b19cf3c Add TODO about known feature gap in ImageRenderer
PiperOrigin-RevId: 600404546
(cherry picked from commit b84104e7a1479ef31c9c4b02154d0dd3b031b736)
2024-01-25 11:42:43 +00:00
tonihei
432cde6051 Use routed device in AudioCapabilities
From API 23, we may have a preferred device that is most likely used
as the output device.
From API 24, the AudioTrack tells us the actual routed device that is
used for output and we can listen to changes happening mid-playback.
From API 33, we can directly query the default device that will
be used for audio output for the current attributes.

If the routed device is known by any of the methods above, we can add
more targeted checks in methods like isBluetoothConnected to avoid
iterating over all devices that are not relevant.

The knowledge about the routed device will also be useful to check
advanced output capabilities in the future (e.g. for lossless
playback)

PiperOrigin-RevId: 600384923
(cherry picked from commit b1c954fa844e25f2c65f9f3865dbb62afaee592d)
2024-01-25 11:42:43 +00:00
huangdarwin
dcfa8c60ce Previewing: set VideoFrameReleaseControl after CVSP is created.
This allows us to inject a videoFrameProcessorFactory into
MediaCodecVideoRenderer, without issues about creating the
VideoFrameReleaseControl in the MediaCodecVideoRenderer.

Unfortunately, this does result in more complex CVSP state, where
VideoFrameReleaseControl is no longer final, may be null, and may potentially
change. However, this tries to be careful with assertions to guarantee good
state, and is cleaner than modifying the long-standing MediaCodecVideoRenderer
interface.

Tested that this works on the ExoPlayer demo with setVideoEffects applied, and
using a playlist with SDR->HDR and HDR->SDR items.

PiperOrigin-RevId: 599823412
(cherry picked from commit cb0f5a7fffdf519f5888255be7a5f3aefe5680a7)
2024-01-25 11:42:43 +00:00
ibaker
34a08e13fc Rollback of 406c0a15be
PiperOrigin-RevId: 599546140
2024-01-18 10:21:53 -08:00
huangdarwin
616cb943f0 Previewing: Allow inputColorInfo to change, from SDR to HDR.
This also fixes issue introduced by frames being released from a prior version of a
GlShaderProgram

Tested by seeking within a playlist with one SDR then one HDR video.

PiperOrigin-RevId: 599475959
2024-01-18 05:20:18 -08:00
christosts
0e66197419 Rename TimestampIterator argument name in queueInputBitmap()
#minor-release

PiperOrigin-RevId: 599460771
2024-01-18 04:01:27 -08:00
ibaker
406c0a15be CompositeSequenceableLoader: Prefer buffered position of A/V tracks
Preferring audio and video tracks matches logic we already have in
[`ProgressiveMediaPeriod.getBufferedPositionUs`](f6fe90f30b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/ProgressiveMediaPeriod.java (L403)).

PiperOrigin-RevId: 599154217
2024-01-17 06:33:14 -08:00
ibaker
80bfa819c0 Add method to TextRenderer to control whether decoding is done or not
When we default to 'parse during extraction', we will flip the default
of this, to ensure that apps know they are using an
incompatible/deprecated flow for subtitle handling.

PiperOrigin-RevId: 599109304
2024-01-17 02:51:48 -08:00
andrewlewis
fc9900c483 Document setVideoEffects surface limitation
`Surface`s don't expose their size via Java APIs. Recommend apps pass a
`SurfaceView` (which is preferable to `TextureView` as it's more efficient)
or `SurfaceHolder` so they benefit from the player automatically passing the
size down to the video renderer via `MSG_SET_VIDEO_OUTPUT_RESOLUTION`.

PiperOrigin-RevId: 598804258
2024-01-16 04:52:08 -08:00
christosts
2d89ffc682 Annotate CompositingVideoSinkProvider with RestrictTo
The class is public so that it can be used between different
packages but it is not meant to be used by apps.

PiperOrigin-RevId: 598792759
2024-01-16 03:52:41 -08:00
jbibik
e51c293f75 Plumb SubtitleParser.Factory into MatroskaExtractor
MatroskaExtractor will no longer be wrapped in SubtitleTranscodingExtractor, but instead use SubtitleTranscodingExtractorOutput under the hood.

FLAG_EMIT_RAW_SUBTITLE_DATA flag will be used to toggle between subtitle parsing during extraction (before the sample queue) or during decoding (after the sample queue).

The new extractor dump files generated by `MatroskaExtractorTest` now follow the new parsing logic and hence have mimeType as `x-media3-cues`.

PiperOrigin-RevId: 598616231
2024-01-15 08:32:22 -08:00
tofunmi
7f087243bb Add supportsMimeType API to bitmapLoader
PiperOrigin-RevId: 597942459
2024-01-12 13:49:38 -08:00
ibaker
d4be30b04d Mark CompositeSequenceableLoader final
Subclasses of this component can customize it by wrapping with the
decorator pattern, and a custom `CompositeSequencableLoaderFactory`
allows access to the list of delegate `SequenceableLoader` instances.

The `final` keyword was removed as part of <unknown commit> but this
component never ended up being subclassed within the library.

Making this class `final` makes upcoming changes easier to reason
about.

PiperOrigin-RevId: 597853429
2024-01-12 09:02:06 -08:00
christosts
5056dfaa2b Regression fix of ExoPlayer.setVideoEffects()
7e65cce967 introduced a regression on ExoPlayer.setVideoEffects()
where there is flash on the screen after the first few frames are shown.

Before 7e65cce967, the first frames of the content are missed, until
MediaCodecVideoRenderer sends the onVideoSizeChanged() callback. The
first frame is processed but not shown, the onVideoSizeChanged() is
triggered and the renderer receives a video output resolution message as
a response from the UI.

7e65cce967 fixed the missed first frames by setting a surface on the
CompositingVideoSinkProvider before the provider is initialized, and as
as result:
- the first frames are rendered
- the MediaCodecVideoRenderer sends the the onVideoSizeChanged() after
  frames are shown
- the UI sends a video output resolution change
- the MediaCodecVideoRenderer updates the CompositingVideoSinkProvider
  which causes the flash.

The underlying problem is with onVideoSizeChanged() not being
triggered early enough, before the first frame is shown.

Because the flashing is a regression, this commit is reverting
7e65cce967 but keeps the test that was added as ignored, so that the
test is re-enabled as soon as we address the underlying issue.

PiperOrigin-RevId: 597814013
2024-01-12 05:20:46 -08:00
lpribanic
e93188fe7f Crop and pass thumbnails to ImageOutput
Image grids are now cropped into tiles. The tiles are provided to
ImageOutput at their correct timestamps.

PiperOrigin-RevId: 597553029
2024-01-11 07:45:50 -08:00
tonihei
cd2d7f5da5 Forward getStreamKeys in ClippingMediaPeriod
Not doing this prevents downloads of clipped media.

PiperOrigin-RevId: 597541395
2024-01-11 06:48:52 -08:00
tianyifeng
733301d562 Remove the parameter PlayerId from PreloadMediaSource.Factory
Originally a `PlayerId` has to be passed and it should be the same id of the player who is going to play the sources, but it turns out to be unnecessary.

When preloading, we can set a `PlayerId.UNSET` inside of the `PreloadMediaSource`, as there is no ongoing playback. And when the source is handed over to player, player will set the player's `PlayerId`.

PiperOrigin-RevId: 597475119
2024-01-11 00:48:58 -08:00
ibaker
3f9e0540b7 Remove non-progressive limitation from DefaultMediaSourceFactory.experimentalParseSubtitlesDuringExtraction
This involves promoting `setTextTranscodingEnabled` to
`ExtractorsFactory`, and also making it experimental, to indicate it's a
short-lived method.

PiperOrigin-RevId: 597235252
2024-01-10 06:46:50 -08:00
tonihei
3596bc332d Use AudioAtributes when determining AudioCapabilities
The capabilities change depending on the attributes, so we should
pass down the actual attributes used during playback and update
the capabilities whenever these change.

PiperOrigin-RevId: 597197507
2024-01-10 03:17:54 -08:00
jbibik
da724c8cc4 Plumb SubtitleParser.Factory into FragmentedMp4Extractor
We introduce SubtitleParser.Factory that supports no formats to be used FragmentedMp4Extractors that will not do any subtitle parsing on the extraction side. We also slowly move away from using SubtitleTranscodingExtractor to SubtitleTranscodingExtractorOutput (hence making it public).

This is required by individual Extractor impls so that they can start using SubtitleTranscodingExtractorOutput rather than be wrapped by SubtitleTranscodingExtractor. The latter is to be deprecated after all the subtitle related Extractors have achieved this migration.

PiperOrigin-RevId: 596942147
2024-01-09 08:33:27 -08:00
ibaker
77f311917f Play clear samples in DRM content without keys by default
This behavior was previously available as opt-in via
`MediaItem.DrmConfiguration.Builder.setPlayClearContentWithoutKey` and
`DefaultDrmSessionManager.Builder.setPlayClearSamplesWithoutKeys`. This
change flips the default of both these properties to true.

This should speed up the time for playback to start when playing DRM
content with a 'clear lead' of unencrypted samples at the start.
Previously playback would wait until the keys for the later encrypted
samples were ready. The new behaviour could result in mid-playback
stalls/rebuffers if the keys are not ready yet by the transition from
clear to encrypted samples, but this is not really a regression since
previously playback wouldn't have started at all at this point.

PiperOrigin-RevId: 595992727
2024-01-05 07:46:25 -08:00
ibaker
62f6c64a91 Rename test.mp3 test asset to test-cbr-info-header.mp3
This file is CBR encoded with LAME, so it has an `Info` header (the CBR
equivalent to `Xing`).

A follow-up change will use this file in `Mp3ExtractorTest`.

Issue: androidx/media#878
PiperOrigin-RevId: 595938327
2024-01-05 02:31:20 -08:00
ibaker
a496bbd777 Add parentheses to fix UnexpectedLoaderException message logic
These were missing in 5211ff0dc1

Without these, the `": null"` is still logged (but the `"Unexpected
IllegalStateException"` bit is not), because the **whole** string
concatenation is compared to null as the boolean condition of the
ternary, and this condition is always false (the result of a string
concatentation is never `null`) i.e. (with excess parentheses for
clarity):

```
(("Unexpected " + cause.getClass().getSimpleName() + cause.getMessage()) != null)
    ? ": " + cause.getMessage()
    : ""
```

Also add a test because obviously this isn't as simple as I'd thought.

PiperOrigin-RevId: 593079975
2023-12-22 03:42:42 -08:00
ibaker
5211ff0dc1 Only append non-null exception messages in UnexpectedLoaderException
The previous code led me to misread this stack trace as a null pointer
exception, but it's really an index out of bounds exception:

```
Caused by: androidx.media3.exoplayer.upstream.Loader$UnexpectedLoaderException: Unexpected IllegalArgumentException: null
  at androidx.media3.exoplayer.upstream.Loader$LoadTask.run(Loader.java:435)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
  at java.lang.Thread.run(Thread.java:1012)
Caused by: java.lang.IllegalArgumentException
  at androidx.media3.common.util.Assertions.checkArgument(Assertions.java:40)
  at androidx.media3.common.util.ParsableByteArray.setPosition(ParsableByteArray.java:164)
  at androidx.media3.extractor.text.cea.Cea608Parser.parse(Cea608Parser.java:440)
```

PiperOrigin-RevId: 592876546
2023-12-21 09:09:41 -08:00
tonihei
98519931e7 Split creation of AudioCapabilitiesReceiver from instance access
getAudioCapabilities currently creates the receiver and returns
the current capabilities. This is error-prone because the
capabilities are also available as a class field.

This can made cleaner by letting the method just create the receiver
and all access to the capabilities can be made via class field.

PiperOrigin-RevId: 592591590
2023-12-20 10:12:27 -08:00
bachinger
36b7a49d52 Use factory to create media period holders in the queue
This is a refactoring that allows the `MediaPeriodQueue` to
create media period holders without all the collaborators
being passes in to `enqueueNextMediaPeriodHolder(...)`.

The factory is presumably also helpful in unit test to
know whether and when exactly a holder is created in
the preloading process.

PiperOrigin-RevId: 592301400
2023-12-19 11:55:13 -08:00
ibaker
7ca26f898d Fix 'legacy' CEA-608 and CEA-708 to use the Decoder impls
We deliberately left `Cea608Decoder` and `Cea708Decoder` intact when
creating the respective `SubtitleParser` implementations (in
27caeb8038
and
94e45eb4ad
respectively).

However we didn't correctly change the behaviour of
`SubtitleDecoderFactory.DEFAULT` in order to use these 'legacy'
implementations. We firstly left the `Cea608Decoder` instantiation
**after** the `DefaultSubtitleParserFactory.supportsFormat()` check,
meaning that code would never be reached (since `supportsFormat` now
returns true for CEA-608). Then in the second change (which was supposed
to only be about CEA-708) we removed all instantiations of **both**
`Cea608Decoder` and `Cea708Decoder`. This change puts the decoder
instantiations back and moves them above the
`DefaultSubtitleParserFactory.supportsFormat` check, meaning they will
be used in preference to `DelegatingSubtitleDecoder`.

This resolves the immediately-disappearing subtitles tracked by
Issue: androidx/media#904.
PiperOrigin-RevId: 592217937
2023-12-19 06:32:36 -08:00
tonihei
e10f96d6a6 Make some DefaultRenderersFactory methods final
These methods are just setters and not meant to be overridden.

PiperOrigin-RevId: 592193857
2023-12-19 04:38:57 -08:00
christosts
3bb233a911 Misc clean-ups in ImageRenderer
Add some missing empty lines and use checkStateNotNull() everywhere.

PiperOrigin-RevId: 592173300
2023-12-19 03:06:29 -08:00
tonihei
e5aa69237e Use CRYPTO_ASYNC mode for video from API 34
This allows us to remove the additional thread we create
for asynchronous buffer queuing and use a synchronized
queueing approach again.

This API looks strictly beneficial on all tested devices,
but since this code path in MediaCodec has not been used
widely, we leave an opt-out flag for now.

PiperOrigin-RevId: 591867472
2023-12-18 05:32:40 -08:00
tonihei
b7c3d83e51 Forward setParameters to AsynchronousMediaCodecBufferEnqueuer
The parameters may change the decoding behavior of the
following samples and it's suprising/wrong to apply them
from another thread where we can't guarantee from which
sample they apply.

PiperOrigin-RevId: 591808760
2023-12-18 00:37:21 -08:00
huangdarwin
236bad5597 Add access control modifier to variable.
PiperOrigin-RevId: 591302601
2023-12-15 10:57:53 -08:00
huangdarwin
7579693739 Effect: Move VideoFrameProcessor inputColorInfo interface to FrameInfo.
Move `inputColorInfo` from `VideoFrameProcessor`'s `Factory.create` to `FrameInfo`,
input via `registerInputStream`.

Also, manually tested on exoplayer demo that setVideoEffects still works.

PiperOrigin-RevId: 591273545
2023-12-15 09:17:39 -08:00
tonihei
f47c4e33ec Remove experimental synchronization on async buffer queuing
PiperOrigin-RevId: 591273508
2023-12-15 09:14:52 -08:00
bachinger
29d7dd1ec9 Keep selections for preloaded adaptive sample streams
When an adaptive source has been preloaded, the track selection
of the player should possibly not override the preloaded selection
to avoid discarding preloaded data.

PiperOrigin-RevId: 591256334
2023-12-15 08:09:22 -08:00