818 Commits

Author SHA1 Message Date
loliball
921b7a58c8 Fix wav format pcm encoding detection error
(cherry picked from commit 8a9aec9c40df6eccf8dce88ccb7089147ae9ffef)
2024-10-13 14:54:24 +08:00
ivanbuper
7e023f915b Use BigDecimal as speed parameter for RandomParameterizedSonicTest
This change simplifies conversions to `BigDecimal` and rounding to a set
number of decimal places.

PiperOrigin-RevId: 684890287
2024-10-11 11:00:44 -07:00
ivanbuper
337e59e733 Move util methods in SpeedChangingAudioProcessorto Util
This CL is prework for implementing
`RandomParameterizedSpeedChangingAudioProcessorTest`, which will build
on logic present in `RandomParameterizedSonicTest`.

This is a non-functional change.

PiperOrigin-RevId: 684838017
2024-10-11 08:02:40 -07:00
ivanbuper
984b0bb31a Avoid dropped output frames on SpeedChangingAudioProcessor
Inconsistent rounding modes between `currentTimeUs` and
`bytesUntilNextSpeedChange` would cause `SpeedChangingAudioProcessor`
to miss calling `queueEndOfStream()` on `SonicAudioProcessor` on a speed
change, and thus the final output samples of that `SonicAudioProcessor`
"configuration" would be missed.

This change is also a partial revert of 971486f5f9, which fixed a hang
of `SpeedChangingAudioProcessor`, but introduced the dropped output
frames issue fixed in this CL (see b/372203420). To avoid reintroducing
the hang, we are now ignoring any mid-sample speed changes and will only
apply speed changes that are effective at a whole sample position.

PiperOrigin-RevId: 684824218
2024-10-11 07:01:59 -07:00
ivanbuper
3818e103e6 Rename timeUs to currentTimeUs
This is a non-functional refactor.

PiperOrigin-RevId: 684408479
2024-10-10 05:36:44 -07:00
ibaker
b6d0540059 Use scaleLargeTimestamp in TimestampAdjuster
This helps avoid overflows in intermediate calculations.

Verified the value in the test using `BigInteger`:

```
jshell> BigInteger.valueOf(1L << 52).multiply(BigInteger.valueOf(90000)).divide(BigInteger.valueOf(1000000))
$3 ==> 405323966463344
```

Issue: androidx/media#1763

#cherrypick

PiperOrigin-RevId: 684028178
2024-10-09 07:27:53 -07:00
ibaker
2c46cea088 Use RoundingMode.DOWN in Util.scaleLargeTimestamp and friends
The implementation of these methods was updated from direct java integer
arithmetic in 885ddb167e.
In this change, `RoundingMode.FLOOR` was used to try and maintain
compatibility with java integer division. This was incorrect, because
java integer division uses `DOWN` (i.e. towards zero), rather than
`FLOOR` (i.e. towards negative infinity) semantics.

This change fixes the compatibility.

The dump file changes in this CL relate to tests that exercise edit
list behaviour. This involves manipulating negative timestamps, which
explains why they are impacted by this change.

PiperOrigin-RevId: 684013175
2024-10-09 06:24:26 -07:00
ivanbuper
af922fbcb0 Fix truncation error accumulation on Sonic's time stretching algorithm
This CL also fixes EOS handling to account for not-yet-copied samples in
`remainingInputToCopyFrameCount`, which would throw off the final output
sample count calculation.

For testing, we allow a tolerance of 0.000017% drift between expected
and actual number of output samples. The value was obtained from running
100 iterations of `timeStretching_returnsExpectedNumberOfSamples()` and
calculating the average delta percentage between expected and actual
number of output samples. Roughly, this means a tolerance of 40 samples
on a 90 min mono stream @48KHz.

PiperOrigin-RevId: 683133461
2024-10-07 04:59:54 -07:00
michaelkatz
09a5ef505b Assign the C.TRACK_TYPE_METADATA type to icy or vnd.dvb.ait tracks
The MetadataRenderer by default supports icy and vnd.dvb.ait content. Those tracks should therefore be set with the `C.TrackType` `TRACK_TYPE_METADATA` rather than `TRACK_TYPE_UNKNOWN`.

PiperOrigin-RevId: 679132680
2024-09-26 07:02:53 -07:00
bachinger
686c3fe7f5 Add media item command buttons for Media3 controllers
Note that unlike the legacy implementation, custom media items
commands can be used for any media items with Media3 API. This
includes `MediaItem` instances that are received from sources
different to `MediaLibraryService` methods.

Hence when connected against a Media3 session these custom commands
can be used with a `MediaController` as well as with a `MediaBrowser`.

Interoperability with `MediaBrowserServiceCompat` will
be added in a follow up CL.

Issue: androidx/media#1474
#cherrypick
PiperOrigin-RevId: 678782860
2024-09-25 11:36:11 -07:00
ivanbuper
3d3ec85c12 Setup basic testing for Sonic and assert expected sample count drift
This CL adds `SonicTest` and `RandomParameterizedSonicTest` as
initial basic unit testing for `Sonic.java`. The tested scenarios
do not necessarily verify a correct implementation of Sonic, but rather
hope to catch any behaviour change from the current implementation.

The change includes a small fix for a lossy simplification and also
checks whether the output sample count matches the expected drift from
the truncation accumulation error present in Sonic's resampler. This is
important as pre-work for fixing issues with unexpected durations within
`SonicAudioProcessor` and `SpeedChangingAudioProcessor` that cause AV
sync issues for speed changing effects.

This is a partial roll forward of e88d6fe459, which was rolled back in
873d485056.

PiperOrigin-RevId: 677756854
2024-09-23 05:53:58 -07:00
dancho
17e1d37112 Fix GL filtering algorithm used when experimental fix is disabled
When working on SurfaceTexture crop fix, we accidentally switched
to GL_NEAREST resampling.

PiperOrigin-RevId: 677751819
2024-09-23 05:34:30 -07:00
ibaker
3e8ecbf564 Remove @DoNotInline annotations
This is no longer needed now our `compileSdk` implies a new-enough AGP
which does this out-lining automatically via R8. See also
https://issuetracker.google.com/345472586#comment7

There's no plan to remove the `ApiXXX` classes, but no new ones need
to be added.

PiperOrigin-RevId: 675940634
2024-09-18 04:47:39 -07:00
ivanbuper
873d485056 Rollback of e88d6fe459
PiperOrigin-RevId: 675525508
2024-09-17 05:25:07 -07:00
Googler
011659b326 Add profile and level for H263 codec.
To support for 3gpp h263 codec in Mp4Muxer currently profile and level is hardcoded and provided to h263 box. Parse profile and level from MediaFormat and use those value to write h263 box.

PiperOrigin-RevId: 675004590
2024-09-15 22:09:38 -07:00
ivanbuper
e88d6fe459 Fix truncation error acumulation for Sonic's resampling algorithm
Sonic would accumulate truncation errors on float to int conversions
that caused the final output sample count to drift noticeably, by
hundreds of samples on streams of a few minutes of length. The fix now
keeps track of the truncation error and compensates for it.

Other small fixes include eliminating lossy operations (e.g. int
division) and using doubles instead of floats for resampling where
helpful.

This CL also introduces `SonicParameterizedTest`, which helps test
resampling on an arbitrary number of randomly generated parameters,
with random sample data. `SonicParameterizedTest` uses `BigDecimal`s
for calculating sample count values, as to avoid precision issues with
large sample counts.

PiperOrigin-RevId: 673852768
2024-09-12 08:14:25 -07:00
rohks
f133e8d1f2 Fix preroll sample handling for non-keyframe media start positions
When processing edit lists in MP4 files, the media start position may be a non-keyframe. To ensure proper playback, the decoder must preroll to the preceding keyframe, as these preroll samples are essential for decoding but are not rendered.

Issue: google/ExoPlayer#1659

#cherrypick

PiperOrigin-RevId: 673457615
2024-09-11 11:02:39 -07:00
sheenachhabra
327b1c8ad8 Move getCodecProfileAndLevel to CodecSpecificDataUtil
`Muxer` module needs to use this method, hence moved to common.

This CL also makes `getHevcProfileAndLevel` public because this is used
in `MediaCodecUtil`.

PiperOrigin-RevId: 671739166
2024-09-06 06:52:29 -07:00
ibaker
6822818549 Fix Format.toLogString handling of new Format.labels field
Before this, because `Label.toString()` isn't implemented, the logged info
wasn't that useful:

```
labels=[androidx.media3.common.Label@6caac039]
```

With this change it's more useful:

```
labels=[en: english]
```
PiperOrigin-RevId: 671029474
2024-09-04 11:02:36 -07:00
ivanbuper
9562c976a9 Bump Media3 version to 1.5.0-alpha01
PiperOrigin-RevId: 670535221
2024-09-03 06:40:01 -07:00
ibaker
4562c781ed Update minSdk values in UtilTest
These were missed when upgrading to both SDK 19 and 21, but they now
cause failures like:

```
Caused by: java.lang.RuntimeException: Failed to parse package buildout/intermediates/apk_for_local_test/debugUnitTest/packageDebugUnitTestForUnitTest/apk-for-local-test.ap_: buildout/intermediates/apk_for_local_test/debugUnitTest/packageDebugUnitTestForUnitTest/apk-for-local-test.ap_ (at Binary XML file line #20): Requires newer sdk version #21 (current version is #19)
    at org.robolectric.shadows.ShadowPackageParser.callParsePackage(ShadowPackageParser.java:61)
    ... 20 more
```

#cherrypick

PiperOrigin-RevId: 670241471
2024-09-02 09:34:15 -07:00
dancho
207684ca66 Prototype frame extraction based on analyzer mode
Make ByteBufferGlEffect public.
Build a speed test, and end to end test that verify
frames can be copied to CPU-accessible ByteBuffer

PiperOrigin-RevId: 670213343
2024-09-02 07:34:33 -07:00
dancho
dc9854cc5b Add GlRect helper class
Adds a class that represents an image rectangle
in OpenGL coordinate convention.

android.graphics.Rect puts (0, 0) as the top-left corner:
it enforces `Rect.top <= Rect.bottom` and this matches
`android.graphics.Bitmap` coordinates: docs https://developer.android.com/reference/android/graphics/Rect

This is different from OpenGL coordinates where (0, 0) is
at the bottom-left corner. I.e. GlRect.bottom <= GlRect.top: docs https://registry.khronos.org/OpenGL-Refpages/es3.0/html/glReadPixels.xhtml

The reason for this change is to allow a public API GlRect
getScaledRegion() which selects a region of pixels of a GL texture
to be copied to CPU memory.

PiperOrigin-RevId: 669231826
2024-08-30 01:13:22 -07:00
Copybara-Service
39ed9cf88d Merge pull request #1652 from MiSikora:ms/vtt-speaker
PiperOrigin-RevId: 668976037
2024-08-29 10:08:13 -07:00
Ian Baker
c78ac6e784 Remove intdef value list from javadoc 2024-08-29 16:45:10 +01:00
Copybara-Service
e30161656e Merge pull request #1667 from JaroslavHerber:patch-1
PiperOrigin-RevId: 668905162
2024-08-29 05:57:59 -07:00
Jaro
02fa4b0f9c Remove obsolete semicolon 2024-08-29 12:25:19 +01:00
ibaker
05cbbffbd7 Add a space in the ParserException message
PiperOrigin-RevId: 668870991
2024-08-29 03:51:40 -07:00
Ian Baker
a4aa975a26 Reformat and tweak javadoc 2024-08-29 10:25:06 +01:00
Michał Sikora
24bbe6d921 Rename VTT voice span speakerName to name 2024-08-29 10:25:06 +01:00
Michał Sikora
ce52fc77ec Remove VTT voice span classes 2024-08-29 10:25:06 +01:00
Michał Sikora
108a5ca2f5 Remove language span marker interface 2024-08-29 10:25:06 +01:00
Michał Sikora
d6f08a6237 Add VTT voice spans to cues 2024-08-29 10:25:06 +01:00
dancho
563eb963fd Make ByteBufferConcurrentEffect asynchronous
* Changes to GlUtil to manage Pixel Buffer Objects and asynchronous
GPU -> CPU glReadPixels
* Make ByteBufferConcurrentEffect non-blocking

PiperOrigin-RevId: 667908805
2024-08-27 02:58:51 -07:00
tianyifeng
829cad6912 Bump media3 version to 1.4.1
#cherrypick

PiperOrigin-RevId: 666347191
2024-08-22 07:49:33 -07:00
kak
0060ff2028 Automated Code Change
PiperOrigin-RevId: 666338281
2024-08-22 07:19:57 -07:00
dancho
6e0e2d0cee Add QueuingGlShaderProgram for effects that run outside GL context
Implement a QueuingGlShaderProgram which queues up OpenGL frames and allows
asynchronous execution of effects that operate on video frames without a
performance penalty.

PiperOrigin-RevId: 666326611
2024-08-22 06:38:28 -07:00
Googler
6b56f12f15 AtomParser: Update initialization data to CodecPrivate format for Vp9
PiperOrigin-RevId: 666188937
2024-08-21 22:33:28 -07:00
Googler
65a471e3db Automated Code Change
PiperOrigin-RevId: 661516063
2024-08-09 21:18:31 -07:00
claincly
8f8e48731e Add a method to disallow VFP destroying shared eglContext
Previously in MultiInputVideoGraph, each VFP would destroy the shared
eglContext, such that the same eglContext object is destroyed multiple times.

Adding a flag to disallow this.

The alternative being we could add a flag on the VFP constructor, but I think
that is too subscriptive (meaning if we later might want to add another boolean
to control another GL behaviour, multiple booleans would make the class less
reason-able), and would incur a lot of code changes at places.

PiperOrigin-RevId: 660354367
2024-08-07 05:50:32 -07:00
rohks
a087f82fa8 Make IndexSeekMap dynamic, allowing seek points to be added later
PiperOrigin-RevId: 660324829
2024-08-07 03:57:51 -07:00
kak
399f48ab42 Automated Code Change
PiperOrigin-RevId: 658829974
2024-08-02 10:29:47 -07:00
ktrajkovski
20df8b282a Collect configuration values in IamfDecoder.
Instead of hard-coding values in multiple files, all default values are declared in `IamfDecoder`. Additionally, the max number of frames used for output buffer initialisation is fetched from `libiamf` native functions.

PiperOrigin-RevId: 658772175
2024-08-02 06:30:34 -07:00
dancho
ddc86686b7 Experimental flag to limit the number of frames in encoder
Transformer.experimentalSetMaxFramesInEncoder controls max number
of frames in encoder.

VideoFrameProcessor now allows delayed releasing of frames to Surface,
while still using the original presentation time.

VideoSampleExporter can now configure video graphs to not render frames
automatically to output surface.

VideoSampleExporter.VideoGraphWrapper tracks how many frames are ready
to be rendered to Surface, and how many frames are already in-use by encoder.

PiperOrigin-RevId: 658429969
2024-08-01 09:33:16 -07:00
sheenachhabra
9d14b91d94 Dump auxiliaryTrackType in a string format
PiperOrigin-RevId: 658372776
2024-08-01 05:59:54 -07:00
claincly
f3bf4ad5fe Disable frame dropping on sm-x200@API34
From debug trace when decoding a 30fps video, the decoder output

```
"0us",
"33366us",
"66733us",
"100100us",
"133466us",
"166833us",
"200200us",
```

But the frame processor only received, despite setting `ALLOW_FRAME_DROP`:

```
"0us",
"166833us",
"200200us",
```

PiperOrigin-RevId: 658079749
2024-07-31 11:30:18 -07:00
dancho
3f49f5c157 Check for EGL_NO_SURFACE and similar in GlUtil
`== null` does not check for equality with
EGL_NO_SURFACE, EGL_NO_CONTEXT, or EGL_NO_DISPLAY.

PiperOrigin-RevId: 657651835
2024-07-30 10:49:06 -07:00
Googler
b77f1d0f99 Add support for Audio Vorbis codec in Mp4Muxer.
Update esdsBox to support muxing of files encoded with Vorbis audio codec .

PiperOrigin-RevId: 655159074
2024-07-23 07:39:26 -07:00
tianyifeng
3c9332bb48 Update media3 version for 1.4.0 stable release
#cherrypick

PiperOrigin-RevId: 653654999
2024-07-18 09:43:16 -07:00
samrobinson
d0afb96c40 Implement repeat mode for CompositionPlayer.
-----

Context:
* Each sequence is wrapped as a single MediaSource, each being played
by an underlying ExoPlayer.
* Repeat mode is typically implemented in Players as a seek to the next
item in the playlist.

-----

This CL:

Repeat mode is triggered by listening for when the main input player
sees a play when ready change due to the end of the media item.

There is a slight delay at the end of the playback, before it repeats.
Setting repeat mode on the underlying players addresses this, but means
that the players will seek without waiting for the CompositionPlayer,
and as such previewAudioPipeline does not get the correct signals
around blocking/flushing.

PreviewAudioPipeline - The seek position can validly be C.TIME_UNSET,
however preview pipeline did not handle this case.

CompositionPlayer getContentPosition is given (through a lambda) as a
supplier to the State object, which means any comparisons between
previous/new state for this value does not work. In SimpleBasePlayer,
there is logic to use the positionDiscontinuityPositionUs for the
position change (see getPositionInfo called from
updateStateAndInformListeners), however this logic is not considered in
getMediaItemTransitionReason, so a condition needed to be added for
this case.

-----

Tests:
* Dump files clearly show the position and data is repeated.
* Assertions on the reasons for transitions or position
discontinuities.
PiperOrigin-RevId: 653210278
2024-07-17 06:22:02 -07:00