2293 Commits

Author SHA1 Message Date
jbibik
9ace81bf2f Move PlayerExtensions into common-ktx module
For now, the only extension function on the `Player` has been used in a Compose demo. It can be promoted to a proper module where in the future other extension functions will reside. Given that `Player` is in `androidx.media3.common`, the corresponding KTX library for it is `androidx.media3.common-ktx`

To start using the new `suspend fun listen`, one must add `androidx.media3:media3-common-ktx` as a Gradle dependency and `import androidx.media3.common.listen`

PiperOrigin-RevId: 658771029
2024-08-02 06:24:10 -07:00
ibaker
b09cea9e3a Implement MP3 ConstantBitrateSeeker.getDataEndPosition()
This is needed to correctly handle files with trailing non-MP3 data
(which is indicated by the length in the `Info` frame being shorter than
the overall length of the file).

The test file was generated by appending 150kB of `DEADBEEF` onto the
end of `test-cbr-info-header.mp3`, and the test asserts that the
extracted samples are identical.

Issue: androidx/media#1480

#cherrypick

PiperOrigin-RevId: 658727595
2024-08-02 02:51:49 -07:00
dancho
6e678e511b Enable experimentalRepeatInputBitmapWithoutResampling
Speed up image to video export by default.

PiperOrigin-RevId: 657958037
2024-07-31 04:40:29 -07:00
rohks
32c9d62d39 Add DataSource contract tests to verify offset and position
These tests addresses two identified gaps in the contract:
 - Ensures that the output buffer offset passed to the `DataSource.read` method is correctly applied.
 - Verifies that the position within the input stream is properly incremented when reading in two parts.

PiperOrigin-RevId: 656358935
2024-07-26 05:14:51 -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
tianyifeng
d70ff7e4d2 Fix the release notes for 1.4.0 stable release
#cherrypick

PiperOrigin-RevId: 655558346
2024-07-24 07:31:39 -07:00
dancho
9a42d03466 Enable experimentalAdjustSurfaceTextureTransformationMatrix
PiperOrigin-RevId: 655231134
2024-07-23 11:11:14 -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
50f9f35353 Guard timeline access in ImaSSAIMS against empty timelines
All methods check if the player is currently handling the ad source
by calling isCurrentAdPlaying(). This method was missing a check
for empty timelines that throws an exception when trying to access
a non-existent period.

Also add this check to two methods that assume the current item
is the ads source, but didn't check it yet.

PiperOrigin-RevId: 653963557
2024-07-19 04:27:36 -07:00
tianyifeng
1cbcd20851 Fix the release notes for 1.4.0 stable release
#cherrypick

PiperOrigin-RevId: 653640574
2024-07-18 09:06:22 -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
tianyifeng
68e8d9cb68 Merge release notes for media3 1.4.0 stable release
#cherrypick

PiperOrigin-RevId: 653261278
2024-07-17 09:38:23 -07:00
tonihei
a86b5f065f Move release note to right section
The change is purely video releated.

PiperOrigin-RevId: 653229546
2024-07-17 07:41:15 -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
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
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
tianyifeng
7aa70a5f2f Add Listener to BasePreloadManager to propagate preload events to apps
PiperOrigin-RevId: 651421044
2024-07-11 08:36:41 -07:00
ibaker
240b6fd606 Fix 'duplicate class' error caused by incomplete kt stdlib metadata
When testing locally it seemed that upgrading KGP to `1.9.20` resolved
this, but testing again confirms this was incorrect, so the problem
was reintroduced in 00d1e70a34.

This change reverts back to KGP `1.9.0` (since upgrading didn't help)
and instead implements the workaround suggested in
https://issuetracker.google.com/278545487. The workaround is now in
the `lib-common` `build.gradle` file, which is transitively depended
on by all modules (and therefore all apps that use this library), so
there's no need for any developer action, and so the release note is
removed.

Issue: androidx/media#1262
PiperOrigin-RevId: 651066418
2024-07-10 10:20:12 -07:00
ibaker
c64dacf3df Transform double-tap of HEADSETHOOK to skip-to-next
As reported in Issue: androidx/media#1493 we already use `HEADSETHOOK` to start
waiting for a double-tap, but we don't consider it for the second tap.

Similarly, we previously considered `PLAY` for the second tap, but not the first.
Only `HEADSETHOOK` and `PLAY_PAUSE` are
[documented](https://developer.android.com/reference/androidx/media3/session/MediaSession#media-key-events-mapping)
to transform double-tap to `seekToNext`. So this change removes the
`PLAY` detection from the second tap.

#cherrypick

PiperOrigin-RevId: 651017522
2024-07-10 07:52:18 -07:00
ibaker
00d1e70a34 Rollback of 91633e6ae3
PiperOrigin-RevId: 650620012
2024-07-09 07:29:57 -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
dancho
7d4f623b00 Fix RELEASENOTES merge conflict
PiperOrigin-RevId: 650551156
2024-07-09 02:43:03 -07:00
dancho
439536480b Parse the H264 bitstream of fMP4 files to identify sample dependencies
Changes to FragmentedMp4Extractor to parse additional sample dependency
information and mark output samples as "no other samples depend on this".
Only applies to H.264 tracks.
Controlled by new fMP4 flag: FLAG_READ_WITHIN_GOP_SAMPLE_DEPENDENCIES

PiperOrigin-RevId: 650538377
2024-07-09 01:53:51 -07:00
andrewlewis
74c06dc2f4 Add SurfaceAssetLoader
This supports queueing input to Transformer via a `Surface`.

PiperOrigin-RevId: 650318396
2024-07-08 11:33:05 -07:00
ibaker
5dd377fb7b Rollback of 91633e6ae3
PiperOrigin-RevId: 650312000
2024-07-08 11:15:18 -07:00
bachinger
06d61ffaaa Allow an app to decide to not start the service
Once a service is started as a foreground service, it must
be started into the foreground. This means an app can not
suppress a play command arriving from the `MediaButtonReceiver`
once the receiver has started the service.

This change adds a method to the `MediaButtonReceiver` that
allows app to suppress starting the service to not get into
this situation of wanting to suppress the play command after
the service is already started.

Issue: androidx/media#1528
PiperOrigin-RevId: 650280025
2024-07-08 09:44:30 -07:00
okunhardt
91633e6ae3 Update HttpEngineDataSource to require at least S extension 7.
This earlier version supports [HttpEngine](https://developer.android.com/reference/android/net/http/HttpEngine) and thus this change allows more devices to use HttpEngine.

This fixes Issue: androidx/media#1262, which suggests to do this.

PiperOrigin-RevId: 650224711
2024-07-08 06:13:24 -07:00
tianyifeng
58ff8fa3c2 Add onPreloadError method to PreloadMediaSource.PreloadControl
Upon the call of `PreloadMediaSource.preload`, the source will periodically check the source refresh or period loading error, and trigger `PreloadMediaSource.PreloadControl.onPreloadError`. For now, the `DefaultPreloadManager` will skip the problematic source and continue to preload the next source. The checking of the error will be terminated when the source stops preloading or releases.

PiperOrigin-RevId: 650195817
2024-07-08 04:06:32 -07:00
tonihei
f55c09cfe2 Add ForwardingSimpleBasePlayer
This utility helps apps to forward to another Player while overriding
selected behavior or state values. The advantage to a ForwardingPlayer
is that the SimpleBasePlayer base class keeps ensuring correctness,
listener handling etc.

The default forwarding logic tries to stay as close as possible to the
original method calls, even if not strictly required by the Player
interface (e.g. calling single item addMediaItem instead of
addMediaItems if only one item is added).

Issue: androidx/media#1183
PiperOrigin-RevId: 650155924
2024-07-08 01:15:16 -07:00
tonihei
b2585aad0f Allow externally provided Timeline in SimpleBasePlayer.State
The Timeline, Tracks and MediaMetadata are currently provided
with a list of MediaItemData objects, that are a declarative
version of these classes. This works well for cases where
SimpleBasePlayer is used for external systems or custom players
that don't have a Timeline object available already. However,
this makes it really hard to provide the data if the app already
has a Timeline, currently requiring to convert it back and forth
to a list of MediaItemData.

This change adds an override for `State.Builder.setPlaylist`
that allows to set these 3 objects directly without going
through MediaItemData. The conversion only happens when needed
(e.g. when modifying the playlist).

PiperOrigin-RevId: 649667983
2024-07-05 09:39:49 -07:00
tonihei
fafd927702 Replace SimpleBasePlayer.State.playlist by getter
The value is basically a duplicate of the information stored
in the timeline field. Reducing the source of truth to the
single Timeline also allows acceptance of other Timelines in the
future that don't necessarily have the helper structure of
the playlist.

To allow apps to retrieve the current playlist as it is, we
add a getter instead.

PiperOrigin-RevId: 649667281
2024-07-05 09:35:44 -07:00
dancho
40a5d31753 Parse the H264 bitstream of mp4 files to identify sample dependencies
Changes to Mp4Extractor to parse additional sample dependency information
and mark output samples as "no other sample depend on this".
Only applies to H.264 tracks.
Controlled by new mp4 flag: FLAG_READ_WITHIN_GOP_SAMPLE_DEPENDENCIES

PiperOrigin-RevId: 649640184
2024-07-05 06:45:40 -07:00
ibaker
bb2fd002ae Fix TTML handling of inherited percentage tts:fontSize values
The percentage should be interpreted as relative to the size of a parent
node.

This change makes this inheritance work correctly for percentages in
both the parent and child. It does not fix the case of a non-percentage
parent size with a percentage child size.

PiperOrigin-RevId: 649631055
2024-07-05 05:57:54 -07:00
rohks
adf1c7915d Add FileDescriptorDataSource
This is a new `DataSource` that can be used to read from a `FileDescriptor`.

Limitations:
- The provided file descriptor must be seekable via lseek.
- There's no way to duplicate a file descriptor with an independent position (it
  would be necessary instead for the app to provide a new FD). Therefore this
  implementation will only work if there's one open data source for a given file
  descriptor at a time.
PiperOrigin-RevId: 649443584
2024-07-04 10:24:25 -07:00
ibaker
b7f317e650 Remove deprecation note from release notes
This was added in 0b96f4372f
but isn't needed. The deprecation annotation is self-documenting.

PiperOrigin-RevId: 649419778
2024-07-04 08:19:59 -07:00
andrewlewis
0b96f4372f Rollback of 95260e28a5
PiperOrigin-RevId: 649003095
2024-07-03 02:52:00 -07:00
claincly
73da1c09bd Call onProcessedStreamChange() for every media item change
Added `MCR.experimentalEnableProcessedStreamChangedAtStart()` to guard this new
feature.

PiperOrigin-RevId: 648886533
2024-07-02 17:04:08 -07:00
tianyifeng
9277a34253 Update release notes for 1.4.0-rc01
#cherrypick

PiperOrigin-RevId: 648745388
2024-07-02 09:37:05 -07:00
andrewlewis
3b7d59ef4f Rollback of 95260e28a5
PiperOrigin-RevId: 648708459
2024-07-02 07:16:27 -07:00
andrewlewis
95260e28a5 Add input type for automatic frame registration
Deprecate `setInputDefaultBufferSize` and `setRequireRegisteringAllInputFrames`
as the new input stream type replaces these (as far as we know they are always
used together).

This is in preparation for supporting asset loaders signaling that they require
these features, specifically for recording from a surface.

PiperOrigin-RevId: 648686087
2024-07-02 05:41:23 -07:00
ibaker
711d18de03 Fix index out of bounds exception when a Subtitle is empty
Issue: androidx/media#1516

#cherrypick

PiperOrigin-RevId: 648416119
2024-07-01 10:40:15 -07:00
bachinger
70c063905c Improve automatic error replication for legacy browsers
This change extends the error replication to a given set of
error codes (not only authentication error), but only
replicates an error if the caller of the service `Callback`
is a legacy controller. It also makes error replication
configurable so that apps can opt-out and report errors
manually instead, or define the error codes for which
replication is enabled.

The change also removes the restriction of `sendError` only
being available for Media3 controllers. Instead, sending an
error to a legacy controller updates the platform playback
state in the same way as sending the error to the media
notification controller.

#cherrypick

PiperOrigin-RevId: 648399237
2024-07-01 09:47:25 -07:00
ktrajkovski
e4d4a776c3 Remove deprecated hasPreviousWindow() and hasPrevious() methods.
Use Player.hasPreviousMediaItem() and Player.seekToPreviousMediaItem() instead.

PiperOrigin-RevId: 647664991
2024-06-28 07:02:33 -07:00
ktrajkovski
e392084c4d Remove deprecated DrmSessionEventListener.onDrmSessionAcquired method.
#cherrypick

PiperOrigin-RevId: 647620751
2024-06-28 03:36:51 -07:00
ktrajkovski
47b1ca18ed Remove deprecated Player#hasPrevious() method.
Use Player#hasPreviousMediaItem() instead.

#cherrypick

PiperOrigin-RevId: 647336042
2024-06-27 09:04:21 -07:00
michaelkatz
304bcfc852 Fix spelling typo in 1.4.0-beta01 release notes
PiperOrigin-RevId: 647327810
2024-06-27 08:35:06 -07:00
tonihei
727645179b Send pending updates before adding discontinuity for error
When handling a playback error that originates from a future item in
the playlist, we added support for jumping to that item first,
ensuring the errors 'happen' for the right 'current item'.
See 79b688ef30.

However, when we add this new position discontinuity to the
playback state, there may already be other position discontinuities
pending from other parts of the code that executed before the
error. As we can't control that in this case (because it's part
of a generic try/catch block), we need to send any pending
updates first before handling the new change.

Issue: androidx/media#1483
#cherrypick
PiperOrigin-RevId: 646968309
2024-06-26 09:09:01 -07:00
claincly
73bf852405 Make ExoPlayer.setVideoEffects() timestamp start from 0
This is consistent with `Transformer` and `CompositionPlayer`

Issue: androidx/media#1098
PiperOrigin-RevId: 646446824
2024-06-25 05:59:15 -07:00