619 Commits

Author SHA1 Message Date
rohks
2a4cbc3be4 Fix parsing of language code in mdhd box
Language codes in the `mdhd` box are stored as three 5-bit values, each representing a letter ('a' to 'z') using an offset of `0x60`. If the decoded characters are not in this range, the language should be treated as undefined.

PiperOrigin-RevId: 738470544
2025-03-19 11:17:33 -07:00
rohks
88da587b0a Parse btrt box in BoxParser to get bitrate information for Mp4 files
PiperOrigin-RevId: 738370142
2025-03-19 06:23:46 -07:00
Googler
0c78bae111 Add API to set resolution that respects orientation
This method allows a single Presentation Effect to resize portrait and landscape videos to a fixed resolution, while maintaining their orientations.

PiperOrigin-RevId: 737652909
2025-03-17 09:58:56 -07:00
michaelkatz
4932300b9a Reduce flakiness for ServerSideAdInsertion±MediaSourceTest past SDK 30
PiperOrigin-RevId: 737631774
2025-03-17 08:56:14 -07:00
ibaker
8837ab2564 Add support for 32-bit FLAC files in the built-in FLAC extractor
Without this, 32-bit files fail to play with `Playback stuck buffering
and not loading`. With this change, playback works on devices where the
`MediaCodec` FLAC decoder supports 32-bit, and crashes on devices with a
`MediaCodec` FLAC decoder that does not support 32-bit.

A follow-up change will aim to transform the 'unsupported' case from a
crash into a report that the track format is not supported.

32-bit support was only fully incorporated into the spec when RFC 9639
was [published in December
2024](https://xiph.org/flac/2024/12/19/rfc-9639-published.html), and
it was been supported by `libflac` (for encode and decode) [since
September 2022](https://xiph.org/flac/2022/09/09/flac-1-4-0-released.html).
The original version of this `FlacExtractor` was written before either
of these, so only supported up to 24-bit.

Issue: androidx/media#2197
PiperOrigin-RevId: 737559285
2025-03-17 04:05:09 -07:00
ibaker
de9216462d Dump per-channel PCM data in CapturingAudioSink
This more clearly shows when a diff is on specific channels, or as a
result of channels being swapped.

PiperOrigin-RevId: 736920754
2025-03-14 11:05:31 -07:00
ibaker
df489e2f94 Special-case empty and all-zero buffers in CapturingAudioSink dumps
These are common in robolectric playback tests, because our
`ShadowMediaCodecConfig` always returns empty buffers when 'decoding'
audio.

PiperOrigin-RevId: 736836767
2025-03-14 06:05:32 -07:00
tonihei
d37f05238a Check language/role flags before merging adaptation sets
The spec technically allows to mark adaptation sets with the switching
property if they allow seamless switching with non-overlapping
segments. This is typically only used for compatible content (e.g.
different codecs), but the spec allows it to be used for other
content as well (e.g. different languages, roles). ExoPlayer's concept
of a TrackGroup only allows formats with the same language and role
flags to be merged, so we should check that before merging.

Issue: androidx/media#2222

#cherrypick

PiperOrigin-RevId: 736564055
2025-03-13 10:54:17 -07:00
ibaker
dfebe72b6a Add 32-bit FLAC test files, and use them in some tests
The matroska file works without further changes. The FLAC container
file works with `lib-flac-decoder` depending on a bundled `libflac`
implementation, but not when using
`androidx.media3.extractor.flac.FlacExtractor` with a `MediaCodec` FLAC
decoder because the media3 extractor doesn't support 32-bit FLAC yet.
The fix for that is in a follow-up change.

`bear_32bit.flac` was generated from `bear.flac` with `ffmpeg`:

```shell
$ ffmpeg \
    -i bear.flac \
    -c:a flac \
    -sample_fmt s32 \
    -strict experimental \
    bear_32bit.flac
```

`bear-flac-32bit.mka` was generated by re-muxing `bear_32bit.flac`,
also with `ffmpeg` (trying to convert `bear-flac-24bit.mka` to 32-bit
didn't work, the resulting file was still 24-bit):

```shell
$ ffmpeg \
    -i ../flac/bear_32bit.flac \
    -c:a copy \
    bear-flac-32bit.mka
```

Issue: androidx/media#2197
PiperOrigin-RevId: 736552251
2025-03-13 10:21:18 -07:00
ibaker
99767c6e25 Use info from unseekable Xing frame when falling back to CBR seeking
This change uses the duration and byte count of the Xing frame, if
they're present, to estimate the bitrate of the stream. The seeking
will still be inaccurate (because we're doing CBR seeking in a VBR
stream), but it will be more accurate than basing the bitrate on the
first MP3 frame we read. It will also mean the duration reported is
accurate.

This change also ensures that if the Xing frame contains the number of
audio bytes but no ToC, the audio data length is still propagated into
the `XingSeeker` (and therefore into the `ConstantBitrateSeeker` too).

Issue: androidx/media#2194
PiperOrigin-RevId: 736100104
2025-03-12 05:50:35 -07:00
shahddaghash
1918a256cc Add a test for playing CompositionPlayer again after playback ends
A problem was discovered in Composition demo app where after playing a composition using CompositionPlayer, pressing the "play" button again would not restart the playback. This issue has been resolved, just adding a test to make sure we're not missing any regressions.

PiperOrigin-RevId: 735793488
2025-03-11 09:59:53 -07:00
ibaker
168c464095 Add cbr-always test for new asset with Xing frame without ToC
Issue: androidx/media#2194
PiperOrigin-RevId: 735382972
2025-03-10 08:22:49 -07:00
ibaker
96d98a24fc Add MP3 test asset with Xing header but no Table of Contents
These tests show the current behaviour:
1. Without customization: not seekable
2. With 'enable CBR' flag:
   * File length known: seekable but duration very incorrect
   * File length unknown: not seekable (even though the Xing frame
     contains the number of bytes in the mp3 stream).

Follow-up test changes will:
1. Add a test for the cbr-always case for this file (branched from the
   files submitted in this change).
2. Add a new similar test asset with no ToC but with trailing garbage
   bytes, to verify that the length from the Xing frame is used.

Then follow-up implementation changes will update Mp3Extractor to use
duration and byte length from a Xing frame when falling back to CBR
seeking.

Issue: androidx/media#2194
PiperOrigin-RevId: 734164879
2025-03-06 09:01:40 -08:00
Googler
8ea49025aa FragmentedMp4Muxer: Update FragmentedMp4MuxerEndToEndTest
Update Test to test all supported mimeTypes in `FragmentedMp4Muxer`.

PiperOrigin-RevId: 732187238
2025-02-28 10:43:50 -08:00
tonihei
796df136d7 Update CapturingAudioSink to dump after audio processors
This ensures data modifications like channel mapping or
bitrate changes are correctly captured in the dump files.

PiperOrigin-RevId: 732129701
2025-02-28 07:21:54 -08:00
sheenachhabra
d16fdcb8cc Reset maxTrackDurationUs when a new fragment is written
When there is both audio and video track, then fragment
creation is driven by video track (a combination of duration
so far + next key frame). But if there is no video track, then
the duration so far drives the fragment creation.

Due to bug, when there is only audio track, only first
fragment was created as expected and then a new fragment is
created for every audio sample.

#cherrypick

PiperOrigin-RevId: 731257696
2025-02-26 04:18:49 -08:00
dancho
da402cfd64 Add experimentalSetCodecsToParseWithinGopSampleDependencies to HLS
HLS extractors were missing
experimentalSetCodecsToParseWithinGopSampleDependencies prior to this patch.

PiperOrigin-RevId: 730878460
2025-02-25 07:31:30 -08:00
Copybara-Service
85467b9b57 Merge pull request #2145 from v-novaltd:dsparano-exo328
PiperOrigin-RevId: 730853667
2025-02-25 06:05:18 -08:00
tonihei
94e8a64938 Add more dump file changes 2025-02-25 12:50:20 +00:00
ibaker
fe19d8c9be Fix casting in ParsableByteArray.peekCharacterAndSize
This was introduced in 841bdc6efe.

There's no need to cast the `char` (2 bytes) down to a `byte` in order
to pack it into an `int` (4 bytes) alongside a short (2 bytes).

We also don't need to use `short` to track the character count (max 4
with UTF-8) - a single byte is enough. This change also uses
`Ints.fromBytes` to avoid having to reason about how casting &
bit-shifting interact.

This change introduces a test which reproduces the failure reported in
Issue: androidx/media#2167.

#cherrypick

PiperOrigin-RevId: 730809219
2025-02-25 03:18:30 -08:00
tonihei
6121445718 Remove gitattributes and some formatting changes 2025-02-21 11:57:20 +00:00
Daniele Sparano
d81321174e Fix CRLF mismatch failing tests in Windows 2025-02-21 11:46:09 +00:00
Daniele Sparano
07150b816f Fix h264 and h265 dumps 2025-02-21 11:46:09 +00:00
Daniele Sparano
82ba4060a4 Update H265 ts dump files 2025-02-21 11:46:08 +00:00
Daniele Sparano
4015db57a5 Update dumps of ts tests 2025-02-21 11:46:08 +00:00
sheenachhabra
abe836d9cd Add sample_no_bframes.mp4 to FragmentedMp4MuxerEndToEndTest
This adds a test coverage for the case when sample size changes
after AnnexB to Avcc conversion.

PiperOrigin-RevId: 728121319
2025-02-18 02:48:12 -08:00
Googler
653470f73b Update CSD and apvC box logic
Update the CSD to contain only the APVDecoderConfigurationRecord and the apvC box to be a full box. The apv clip is also updated to be consistent with the new [specification](https://github.com/AcademySoftwareFoundation/openapv/blob/main/readme/apv_isobmff.md#isobmff-binding-for-apv).

The clip is provided by the openAPV team under BSD-3 license.

PiperOrigin-RevId: 727868656
2025-02-17 08:11:00 -08:00
rohks
e9df85b48d Add contract tests for DRM and logging to MediaExtractorContractTest
Added tests for APIs `getDrmInitData()`, `getPsshInfo()`, `getLogSessionId()` and `setLogSessionId(LogSessionId)`.

The Widevine encrypted sample was created from already existing `sample_fragmented.mp4` using `mp4encrypt`.

PiperOrigin-RevId: 726881977
2025-02-14 05:05:51 -08:00
Googler
aa6183e883 Update EncoderPerformanceAnalysisTest
PiperOrigin-RevId: 725150395
2025-02-10 03:48:38 -08:00
Googler
0ba3bf66c6 Add raw audio support to Mp4Muxer.
The fourcc used is `sowt` for little endian 16 bit PCM and `twos` for big endian 16 bit PCM.

PiperOrigin-RevId: 724391195
2025-02-07 10:26:48 -08:00
dancho
65e7b599d8 AV1 treat show_existing_frame headers as not depended on
PiperOrigin-RevId: 724300793
2025-02-07 04:49:10 -08:00
dancho
a80e7be029 MCVR support skipping parts of AV1 input buffers
AV1 input buffers contain multiple compressed pictures.
Enable skipping only the last showable frame, while leaving
any reference pictures to be decoded later, as part of
the next decoder input buffer.

Partial skipping of AV1 input buffer is only applied when:
* fewer than 8 OBUs are delayed
* there's likely to be enough capacity in the decoder input buffer
  for the next frame

PiperOrigin-RevId: 723496060
2025-02-05 07:09:20 -08:00
dancho
2fe92bfca5 Use the AV1 sample dependency parser in MCVR
Parsing AV1 bitstreams allows us to identify frames that are
not used as reference, and improve seeking or frame dropping
behavior.

The AV1 bitstream format is relatively quick to parse

PiperOrigin-RevId: 723462680
2025-02-05 04:51:02 -08:00
dancho
f8f66bdfaa Mp4Muxer: disable sample batching and copying by default.
When sample batching is disabled, copying of the ByteBuffer data
is not necessary as samples are written as they arrive.
Copying of the BufferInfo is necessary because the info is needed
for writing the moov atom.

The input ByteBuffer can be in little endian order, or have its
position set. AnnexBUtils now ensures big endian order before
inspecting bytes, and supports reading from a non-zero position.

This change reduces the amount of memory allocations by Mp4Muxer
in its default configuration

PiperOrigin-RevId: 723401822
2025-02-05 01:05:22 -08:00
rohks
e15438322d Fix ArrayIndexOutOfBoundsException in MP4 edit lists
The exception occurred when an edit list started at a non-sync frame with no preceding sync frame. The fix searches forward for the next sync frame in such cases, preventing the out-of-bounds access.

Issue: androidx/media#2062

#cherrypick

PiperOrigin-RevId: 720642687
2025-01-28 11:13:38 -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
ibaker
a7a5d6e92b Suppress (and log) subtitle errors in SubtitleTranscodingTrackOutput
This is equivalent to the error suppression for legacy subtitles in
`TextRenderer`:
76088cd6af/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/text/TextRenderer.java (L357-L359)

This new suppression only affects errors thrown from files with
subtitles muxed together with audio/video. Standalone subtitle
files, and containers containing only text tracks, are handled
by the existing error suppression/reporting added in
49dec5db8b.

Issue: androidx/media#2052
PiperOrigin-RevId: 718930243
2025-01-23 10:49:23 -08:00
ibaker
9bb254f697 Skip SSA cues where end time is before or equal to start time
The file in Issue: androidx/media#2052 contains a cue with the following timecode:

```
0:00:00:00,0:00:00:00
```

The content of this cue seems to be some 'converted by' metadata, i.e.
it's basically a comment and clearly not intended to be shown on
screen (since it has zero duration).

There is some fiddly logic later in `SsaParser` to support overlapping
cues with the old `Subtitle` structure [1], and this logic gets tripped
up by the start and end time being equal, which results in a
**single**, empty `List<Cue>` being added - which trips up another
assumption that every SSA cue line results in at least two `List<Cue>`
entries (one containing the cue text, and another containing an empty
list to signal the end of the cues).

This fiddly logic is no longer required, because overlapping
`CuesWithTiming` objects can now be merged in `TextRenderer`, so there
is a possible future simplification to `SsaParser` which removes a lot
of this complexity.

[1] Added in <unknown commit>

PiperOrigin-RevId: 718380386
2025-01-22 07:41:24 -08:00
Copybara-Service
fda8b8a35d Merge pull request #2023 from DolbyLaboratories:dlb/dovi-format/dev
PiperOrigin-RevId: 716226613
2025-01-16 07:26:46 -08:00
claincly
1732892927 Add tests for multi input video
PiperOrigin-RevId: 716208222
2025-01-16 06:19:47 -08:00
ibaker
736c7528cb Ignore EOS buffer timestamps in CeaDecoder.queueInputBuffer
This is aligned with the documentation of `MediaCodec` which says the
timestamp of a buffer with `BUFFER_FLAG_END_OF_STREAM` should be
ignored:
https://developer.android.com/reference/android/media/MediaCodec#end-of-stream-handling

Add a test that exercises this by clipping off the end of a sample with
CEA-608 captions, because this creates an EOS-flagged buffer with a
non-EOS timestamp.

Also add a straightforward playback test for the
`fragmented_captions.mp4` sample.

PiperOrigin-RevId: 715716036
2025-01-15 02:40:07 -08:00
ibaker
a4d28b4f10 Add PGS test file
Transformed from `sample_with_srt.mkv` and provided in
https://github.com/androidx/media/pull/1979#issuecomment-2574007148

PiperOrigin-RevId: 714955725
2025-01-13 07:14:13 -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
sheenachhabra
36be62ee8c Skip duplicate chunks in stsc box writing
Earlier muxer wrote a different entry for every chunk but as
per the spec (ISO 14496-12) exact same chunks can be combined
and only the first chunk number can be written.

PiperOrigin-RevId: 714154531
2025-01-10 13:27:02 -08:00
Ian Baker
6291cfda86 Fix dump file to match @GraphicsMode(NATIVE) 2025-01-10 17:35:56 +00:00
Ian Baker
6658dc097b Rename new fixed test file to old name, and add output dump 2025-01-10 16:02:24 +00:00
Sven Wischnowsky
90c91fa5d7 Fixed subtitle track length. 2025-01-10 16:02:24 +00:00
Sven Wischnowsky
0254b2d16e Add Vobsub sample file 2025-01-10 16:02:24 +00:00
dancho
c26a633d83 Read sample dependencies for H.265 in FragmentedMp4
Add a new flag to FragmentedMp4Extractor
FLAG_READ_WITHIN_GOP_SAMPLE_DEPENDENCIES_H265
Read two bytes from H.265 videos to determine NAL unit type and
temporal layer id.

PiperOrigin-RevId: 714046987
2025-01-10 07:39:37 -08:00