899 Commits

Author SHA1 Message Date
ivanbuper
79b61d05a6 Rollback of 492574bded
PiperOrigin-RevId: 721758531
2025-01-31 06:56:13 -08:00
tonihei
6b31b4620c Move NetworkTypeObserver operations off main thread
PiperOrigin-RevId: 721291681
2025-01-30 01:17:22 -08:00
rohks
c9a936e153 Bump Media3 version to 1.6.0-alpha02
#cherrypick

PiperOrigin-RevId: 720990835
2025-01-29 08:43:21 -08:00
ivanbuper
fc6df77831 Remove deprecated androidx.media3.exoplayer.audio.SonicAudioProcessor
Also, make `androidx.media3.common.audio.SonicAudioProcessor` final.

PiperOrigin-RevId: 720987023
2025-01-29 08:30:09 -08:00
dancho
bb37aad170 Add an option to use different texture filtering
Add an option to GlMatrixTransformation to choose the OpenGL texture
minification filter.
When mipmaps are requested, mipmaps are generated with
`glGenerateMipmap()`.

PiperOrigin-RevId: 720629807
2025-01-28 10:44:26 -08:00
tonihei
ddcf455d03 Convert context dependent TrackSelectionParameters to boolean
This avoids that these settings have to be resolved inline,
potentially blocking the main thread. They can be resolved at
the time of track selection on a background thread instead.

As a side effect, we can also remove the context parameter from
the Builder. Having the Context in the Builder is also a bad sign
in the first place because it implies the potentially blocking
calls can happen.

PiperOrigin-RevId: 720523139
2025-01-28 04:26:15 -08:00
ibaker
1772050ece Remove confusing null from ParserException.getMessage()
When reading quickly this suggests something 'real' was null (similar to
a `NullPointerException`), but it's actually just the message from the
superclass.

Seen in stack trace in Issue: androidx/media#2074:

```
Caused by: androidx.media3.common.ParserException: null {contentIsMalformed=true, dataType=1}
```

PiperOrigin-RevId: 719240235
2025-01-24 03:55:19 -08:00
tonihei
190563b8eb Move StreamVolumeManager system calls to playback thread
This requires some additional state handling to update the full
state atomically and guess placeholder states while updates are
in progress, using the newly added BackgroundThreadStateHander.

Some tests also needed to be adjusted to account for the fact
that the actual audio system change doesn't happen inline
anymore.

PiperOrigin-RevId: 716702141
2025-01-17 09:47:33 -08:00
tonihei
297b2b9956 Add util to handle background state updates and placeholder states.
This is a common pattern in media3 libraries where tasks are handled on a
background thread, but the calling thread sees an immediate state update
with a best-guess placeholder. This makes the integration for the caller
very easy as the API surface appears to be synchronous.

This util is a helper class to handle this logic and test it separately.

PiperOrigin-RevId: 716233966
2025-01-16 07:53:15 -08:00
Googler
492574bded Rollback of 871381288c
PiperOrigin-RevId: 715891934
2025-01-15 12:08:40 -08:00
claincly
e9e0569425 Integrate MultiInputVideoGraph in CompositionPlayer
Currently doesn't support image/video transitions

PiperOrigin-RevId: 715393251
2025-01-14 08:33:39 -08:00
Copybara-Service
d18ad57e30 Merge pull request #1979 from wischnow:main
PiperOrigin-RevId: 714911017
2025-01-13 04:09:58 -08:00
dancho
8b33a0a50f Add a ChunkExtractor API to select codecs for sample dependency parsing
Deprecate BundledChunkExtractor.experimentalParseWithinGopSampleDependencies
in favour of
ChunkExtractor.experimentalSetCodecsToParseWithinGopSampleDependencies
which takes a VideoCodecFlags IntDef flags that represent a set of codecs.

Add a DASH test using the new API with an H.265 video.

PiperOrigin-RevId: 714901602
2025-01-13 03:30:10 -08:00
Ian Baker
8520c66fd8 Add some nullness annotations, re-jig some logic and reformat 2025-01-10 16:02:24 +00:00
Sven Wischnowsky
3cd0e1ad3d Add maybeInflate() which inflates only if the source buffer starts with the INFLATE_HEADER 2025-01-10 16:02:24 +00:00
tonihei
71cb246913 Fix bug where changing index does not reevaluate derived metadata
When the current MediaMetadata is automatically derived from the
MediaItem and Tracks, the result may change when state.buildUpon()
is used and new input data is provided (e.g. new current index).
To avoid reusing the previously derived MediaMetadata, we need to
reset it to null and re-evaluate it on every call to build()

Issue: androidx/media#1940
PiperOrigin-RevId: 714021424
2025-01-10 05:59:45 -08:00
tonihei
c3b13a60a3 Mark internal BasePlayer.seekTo method as @ForOverride
This method is not meant to be called directly, it only needs to
be implemented by subclasses.

PiperOrigin-RevId: 714000806
2025-01-10 04:32:32 -08:00
tonihei
b9d12837b4 Use live providers in CompositionPlayer to remove workaround
When CompositionPlayer added repeat modes in d0afb96c40, it
changed the logic in SimpleBasePlayer to workaround the specific
scenario in CompositionPlayer that didn't seem to work correctly.
The workaround is not really generically applicable though. The
source of the original problem was that the position values of
all state objects were connected to the "live" source of the
current player so that the repetition case couldn't be detected
(the position before and after the seek looked the same). The
solution is to use the newly added LivePositionSuppliers and
disconnect them before seeking.

PiperOrigin-RevId: 713659638
2025-01-09 07:10:14 -08:00
tonihei
9608ae4e3d Add LivePositionSupplier util to SimpleBasePlayer
In some cases the position is supplied from a "live" source
that keeps changing its value at repeated calls. This typically
happens when forwarding to another backend with unpredictable
position values. The problem is that as soon as the backend
system has a position discontinuity, any previously created
PositionSupplier now returns a position that no longer makes
sense in the context of the State object it belongs to.

ForwardingSimpleBasePlayer already works around this issue by
having a util class to disconnect these live sources. This
change moves the same util to SimpleBasePlayer itself so it
can be reused by other implementations.

PiperOrigin-RevId: 713658046
2025-01-09 07:05:21 -08:00
dancho
b54d8737cf Add number of temporal layers to Format
The number of temporal sub-layers is required for
H.265 non-reference frame identification as
only frames from the highest temporal sub-layer can be
discarded.

PiperOrigin-RevId: 713247354
2025-01-08 04:50:45 -08:00
ivanbuper
871381288c Use static methods for getSpeedAdjustedTimeAsync and getMediaDurationUs
This change simplifies SpeedChangingAudioProcessor by removing unneeded
heuristics and synchronization added as workarounds to estimate input
and output frame counts.

The synchronization between the video processing and audio processing
threads cannot be completely removed yet because the static methods
depend on the input sample rate for the calculations. However, once
`SpeedChangingAudioProcessor` has been configured, then
`#getSpeedAdjustedTimeAsync()` should invoke the callback immediately.

PiperOrigin-RevId: 712893246
2025-01-07 06:49:49 -08:00
Copybara-Service
38363acc8d Merge pull request #1785 from DolbyLaboratories:dlb/dovi-supplemental-codecs/dev
PiperOrigin-RevId: 712867412
2025-01-07 04:58:21 -08:00
ivanbuper
7ecaebe3d6 Fix underflow in Sonic#getOutputSize() after #queueEndOfStream()
For the [0.5; 1) speed range, the combination of having a "slow down"
speed (i.e. more output frames than input frames), and Sonic potentially
needing to copy more input frames that are available in the input buffer
can lead to an unexpected underflow.

Specifically, the underflow happens in Sonic#queueEndOfStream() when the
following conditions are met (skipping some minor ones):

1. `inputFrameCount < remainingInputToCopyFrameCount`
2. `0.5f <= speed < 1`.
3. `outputFrameCount <
    (inputFrameCount / remainingInputToCopyFrameCount) / 2`.

This underflow caused `SonicAudioProcessor#isEnded()` to return a false
negative (because `getOutputSize() != 0`), which would stall the
`DefaultAudioSink` waiting for processing to end after EOS.

In practical terms, the underflow is relatively easy to reproduce if we
consume all of Sonic's output and then immediately queue EOS without
queueing any more input in between. This should cause both
`inputFrameCount` and `outputFrameCount` to drop to 0.

PiperOrigin-RevId: 711773565
2025-01-03 09:26:32 -08:00
ivanbuper
682889f91d Implement Sonic method to get input frame count from output frame count
The static method can estimate the number of input frames needed to get
a given number of output frames with a given Sonic configuration.

This CL is prework to remove the dependency of
`SpeedChangingAudioProcessor#getMediaDurationUs()` on non-static output
based heuristics and simplify `SpeedChangingAudioProcessor`.

PiperOrigin-RevId: 711446999
2025-01-02 09:36:12 -08:00
ivanbuper
48e3c6fd75 Rollback of f60d2b4146
PiperOrigin-RevId: 710998501
2024-12-31 10:26:16 -08:00
ivanbuper
d6e4642bcf Rollback of 5ab9a7856f
PiperOrigin-RevId: 710770581
2024-12-30 12:24:05 -08:00
rohks
506bc91dd8 Bump Media3 version to 1.6.0-alpha01
PiperOrigin-RevId: 707896534
2024-12-19 06:45:57 -08:00
ybai001
1ac847ad60 Update code according to review result 2024-12-19 16:28:33 +08:00
shahddaghash
c3b58f2434 Bump Media3 version to 1.5.1
PiperOrigin-RevId: 707576152
2024-12-18 09:29:43 -08:00
bachinger
aa2ee8f702 Add client side post roll placeholder
PiperOrigin-RevId: 707142019
2024-12-17 09:59:16 -08:00
ibaker
32ab258c43 Use Build.MANUFACTURER instead of Util alias in AudioCapabilities
It seems that changes via Robolectric's `ShadowBuild.setManufacturer()`
and similar methods don't propagate correctly (or quickly?) to these
aliases.

This change resolves a failure caused by different test ordering in
`AudioCapabilitiesTest` in order to unblock the 1.6.0-alpha01 release.
A follow-up change will migrate other usages from `Util.XXX` to
`Build.XXX`.

PiperOrigin-RevId: 707125446
2024-12-17 09:10:40 -08:00
tonihei
2d11a339de Import AudioManagerCompat and AudioFocusRequest from androidx.media
Both classes provide utilities widely used by apps that are not
yet available in Media3. This change imports the existing logic as
it is with style adjustments to the Media3 codebase.

PiperOrigin-RevId: 707067512
2024-12-17 06:14:36 -08:00
bachinger
3fe1f2a734 Add adId to AdGroup
PiperOrigin-RevId: 706761644
2024-12-16 10:47:17 -08:00
sheenachhabra
319ac2e5af Remove Parcelable interface from Metadata and Metadata.Entry
`Parcelable` is not safe for IPCs between binaries with potentially
different class definitions (e.g. two apps built from different versions
of media3).

If we get a use case to bundle metadata, then the `Metadata` and
`Metadata.Entry` classes needs to provide a `toBundle()` method.

PiperOrigin-RevId: 706678892
2024-12-16 05:58:02 -08:00
sheenachhabra
1326a92350 Do not bundle metadata when creating Format bundle
Metadata does not provide a `toBundle` method. It implements
`Parcelable` which is not safe for IPCs between binaries with
potentially different class definitions (e.g. two apps built from
different versions of media3).

If we get a use case to bundle metadata as well, then the `Metadata`
class needs to provide a `toBundle()` method.

PiperOrigin-RevId: 705920231
2024-12-13 10:12:37 -08:00
bachinger
83b5eb0040 Add HlsInterstitialsAdsLoader
Reads HLS interstitials information from the playlist and
populates the `AdPlaybackState` accordingly to play the ads.

An app can register a `Listener` to be informed about ad
related events.

Only VOD streams are supported and X-ASSET-LIST attibutes
are ignored with this change.

PiperOrigin-RevId: 705604201
2024-12-12 13:04:10 -08:00
Googler
3936c27b6d Don't check codec's profile for MV-HEVC video.
Currently as there is no formal support for MV-HEVC within Android framework, the profile is not correctly specified by the underlying codec; just assume the profile obtained from the MV-HEVC sample is supported.

PiperOrigin-RevId: 705164738
2024-12-11 10:59:26 -08:00
ibaker
ef19740c92 Remove Forwarding from assertForwardingClassOverridesAllMethods
And use it in a "non-forwarding" context in
`DefaultAnalyticsCollectorTest`.

PiperOrigin-RevId: 704331859
2024-12-09 10:22:06 -08:00
Googler
5ab9a7856f Rollback of 646a6352a2
PiperOrigin-RevId: 702960045
2024-12-04 20:36:15 -08:00
Googler
f60d2b4146 Rollback of 66e8b53b43
PiperOrigin-RevId: 702943864
2024-12-04 19:22:54 -08:00
ibaker
9828d104b5 Improve reflective instantiation in ForwardingFoo test util
This code previously passed null or 'default' for every parameter.
Now it tries to mock non-final types, and recursively constructor final
types if possible, eventually giving up and passing null instead.

The previous null-passing behaviour led to a quite confusing failure in
`ForwardingPlayer.addListener` when writing 25c927e9f3 due to an NPE
when trying to compare parameter equality in `Mockito.verify` [1].
With this change, the failure is much clearer [2].

There's a relatively simple case this code still doesn't handle: A final
type like `PlaybackParameters` where the constructor parameters **have**
to be non-default primitives (greater than zero in that case).

-------

[1]

```
java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:569)
	at androidx.media3.test.utils.TestUtil.assertForwardingClassForwardsAllMethodsExcept(TestUtil.java:687)
	at androidx.media3.common.ForwardingPlayerTest.forwardingPlayer_forwardsAllPlayerMethods(ForwardingPlayerTest.java:110)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:569)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.robolectric.RobolectricTestRunner$HelperTestRunner$1.evaluate(RobolectricTestRunner.java:588)
	at org.robolectric.internal.SandboxTestRunner$2.lambda$evaluate$2(SandboxTestRunner.java:290)
	at org.robolectric.internal.bytecode.Sandbox.lambda$runOnMainThread$0(Sandbox.java:101)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:840)
Caused by: java.lang.NullPointerException: Cannot invoke "Object.hashCode()" because "this.listener" is null
	at androidx.media3.common.ForwardingPlayer$ForwardingListener.hashCode(ForwardingPlayer.java:1140)
	at java.base/java.lang.Object.toString(Object.java:256)
	at java.base/java.lang.String.valueOf(String.java:4220)
	at org.mockito.internal.verification.argumentmatching.ArgumentMatchingTool.toStringEquals(ArgumentMatchingTool.java:54)
	at org.mockito.internal.verification.argumentmatching.ArgumentMatchingTool.getSuspiciouslyNotMatchingArgsIndexes(ArgumentMatchingTool.java:36)
	at org.mockito.internal.verification.checkers.MissingInvocationChecker.checkMissingInvocation(MissingInvocationChecker.java:45)
	at org.mockito.internal.verification.Times.verify(Times.java:37)
	at org.mockito.internal.verification.MockAwareVerificationMode.verify(MockAwareVerificationMode.java:30)
	at org.mockito.internal.handler.MockHandlerImpl.handle(MockHandlerImpl.java:75)
	at org.mockito.internal.handler.NullResultGuardian.handle(NullResultGuardian.java:29)
	at org.mockito.internal.handler.InvocationNotifierHandler.handle(InvocationNotifierHandler.java:34)
	at org.mockito.internal.creation.bytebuddy.MockMethodInterceptor.doIntercept(MockMethodInterceptor.java:82)
	at org.mockito.internal.creation.bytebuddy.MockMethodInterceptor.doIntercept(MockMethodInterceptor.java:56)
	at org.mockito.internal.creation.bytebuddy.MockMethodInterceptor$DispatcherDefaultingToRealMethod.interceptAbstract(MockMethodInterceptor.java:161)
	at androidx.media3.common.Player$MockitoMock$1276619531.addListener(Unknown Source)
	... 22 more
```

----

[2]

```
Argument(s) are different! Wanted:
player.addListener(
    Mock for Listener, hashCode: 107929032
);
-> at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Actual invocations have different arguments:
player.addListener(
    androidx.media3.common.ForwardingPlayer$ForwardingListener@af47cec0
);
-> at androidx.media3.common.ForwardingPlayer.addListener(ForwardingPlayer.java:81)
```

PiperOrigin-RevId: 702378861
2024-12-03 10:10:39 -08:00
claincly
675c1d898a Move interface locations
PiperOrigin-RevId: 702096389
2024-12-02 15:03:37 -08:00
ibaker
25c927e9f3 Standardize ForwardingXXX tests
Add missing ones for `ForwardingExtractorInput` and `ForwardingSeekMap`.
`ForwardingTimeline` is a bit more fiddly, so it's left for a follow-up
change.

PiperOrigin-RevId: 701988492
2024-12-02 09:12:53 -08:00
dancho
6e29b96337 Add support for extracting HDR frames as HLG Bitmaps
* Add GlUtils to create RGB10_A2 textures.
* Add OETF conversion to FrameReadingGlShaderProgram.
* Add FrameExtractor configuration API to request HDR output: API 34+

PiperOrigin-RevId: 700738895
2024-11-27 10:18:57 -08:00
Copybara-Service
bff5523bb6 Merge pull request #1823 from MGaetan89:remove_outdated_sdk_check
PiperOrigin-RevId: 700706152
2024-11-27 08:16:02 -08:00
ibaker
60133b0c7e Recommend ForwardingSimpleBasePlayer in ForwardingPlayer javadoc
Also add an explicit warning about how fiddly `ForwardingPlayer` can be
to use correctly.

PiperOrigin-RevId: 700698032
2024-11-27 07:42:24 -08:00
Gaëtan Muller
2fc379a61b Fix documentation for Format.Builder.setTileCountHorizontal and Format.Builder.setTileCountVertical 2024-11-26 10:05:16 +00:00
ibaker
827966b7a4 Add pixel aspect ratio to Format.toLogString
#cherrypick

PiperOrigin-RevId: 698770714
2024-11-21 07:21:11 -08:00
shahddaghash
73c4bb6e1f Bump Media3 version to 1.5.0
PiperOrigin-RevId: 698761734
2024-11-21 06:47:36 -08:00
sheenachhabra
407bc4fec9 Manage all color value conversions in ColorInfo class
This CL also aligns supported color space in `media3 common` and `media3 muxer`.

Earlier `muxer` would take even those values which are considered invalid
in `media3` in general.

Earlier muxer would throw if a given `color standard` is not recognized
but with the new change, it will rather put default `unspecified` value.

#cherrypick

PiperOrigin-RevId: 698683312
2024-11-21 01:09:02 -08:00