594 Commits

Author SHA1 Message Date
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
ibaker
d0b757886e Fix handling of length-delimited NAL units with 1 or 2 byte length
ExoPlayer assumed 4-bytes for length in two places (by assuming the
length is the same as the 4-byte NAL start code):

1. In `AvcConfig` we transform length-delimited to start-delimited
   before writing into `initializationData`, and then skip
   'nal unit length field' bytes when parsing from `initializationData`
   (when we should skip 'start code length' bytes instead).

2. In `Mp4Extractor.readSample` we modify the local variable
   `sampleSize` to fix the difference between length field length and
   start code length, but **only on the first attempt to read a
   sample**. If we are resuming in the middle of reading a sample (after
   a recoverable I/O error), this fix for `sampleSize` is not done,
   which means we end up missing the last 2-3 bytes of the sample when
   the NAL length is 1-2 bytes.
     * This is fixed by moving the `sampleSize` 'fixing' code to outside
       the `if (sampleCurrentNalBytesRemaining == 0)` block.
     * `FragmentedMp4Extractor` has very similar code, but uses a
       field for `sampleSize`, rather than a local, so doesn't look
       vulnerable to the same problem (though I haven't totally
       tested this).

This change adds a test file with 2-byte NAL lengths, generated by
hacking the media3 muxer to emit 2-byte NAL lengths and transforming
`sample.mp4` using the transformer demo app.

PiperOrigin-RevId: 713709203
2025-01-09 10:06:13 -08:00
dancho
cd511ea60b Add a test file for FragmentedMp4 captions
The previous FragmentedMp4 captions test asset doesn't have captions.
Fix a bug where captions before extractor seek were output after.

PiperOrigin-RevId: 713665817
2025-01-09 07:35:21 -08:00
michaelkatz
314413365b Implement transfer of resources API for renderer pre-warming
At the point of playing period transition pre-warming has completed and the renderers should receive necessary resources for playback. This CL adds the `Renderer.MessageType` `MSG_TRANSFER_RESOURCES` to direct a renderer to transfer relevant resources to another renderer.

PiperOrigin-RevId: 713372754
2025-01-08 12:12:48 -08:00
dancho
0cf52ed45d Read sample dependencies for H.265 in MP4
Add a new Mp4Extractor.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: 713248154
2025-01-08 04:55:31 -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
ibaker
31e5142b72 Restrict SubRip and WebVTT parsing to exactly 3 decimal places
We previously parsed an arbitrary number of decimal places, but assumed
the value was in milliseconds, which doesn't make sense if there is
greater or fewer than 3. This change restricts the parsing to match
exactly 3, meaning the millisecond assumption is always true.

The WebVTT spec requires there to be exactly 3 decimal places:
https://www.w3.org/TR/webvtt1/#webvtt-timestamp

The SubRip spec is less clearly defined, but the Wikipedia article
defines it as having exactly 3 decimal places
(https://en.wikipedia.org/wiki/SubRip#Format) and ExoPlayer has always
assumed 3 decimal places (anything else is already handled incorrectly),
so this change just ensures we don't show subtitles at the wrong time.

Issue: androidx/media#1997
PiperOrigin-RevId: 712885023
2025-01-07 06:13:15 -08:00
Googler
b2aa8d6d21 Add sample rate fallback to AudioSampleExporter
After this change, if the sample rate supported by the encoder differs from the requested sample rate and enableFallback is true, the AudioSampleExporter will convert audio to a sample rate supported by the encoder. This fixes a bug where the audio track is distorted when an unsupported sample rate is requested.

PiperOrigin-RevId: 712822358
2025-01-07 01:52:57 -08:00
Olivier Jouvenaux
82bed39140 Add unit tests for TTML region attrs in style, chained styles UT 2025-01-06 15:13:32 +00:00
Olivier Jouvenaux
026700a9d9 Add unit tests for region attrs in style 2025-01-06 15:13:32 +00:00
dancho
9b71f2a3ba Mp4Extractor: allow zero length NAL units
Some videos include zero length NAL units in the
length-delimited MP4 samples.
Empty NAL units are not spec-compliant (see ISO/IEC 14496-15 section 4.3.3.3),
but other players are able to play these videos (with warnings or errors).

With this change, we check track.sampleTable.sizes[sampleIndex] before
reading a byte from the NAL unit itself.

PiperOrigin-RevId: 711720621
2025-01-03 05:21:10 -08:00
Googler
2caa0d39eb Mp4Extractor: Update APV clip
Replaced an existing APV file as bitstream syntax has now changed and
previous clip is not a valid bitstream anymore.

This clip was provided by the openAPV team and is under BSD-3 license.

PiperOrigin-RevId: 711318578
2025-01-01 22:34:31 -08:00
rohks
ca58867816 Hard-code channel count and sample rate for AMR-NB and AMR-WB
AMR-NB and AMR-WB are inherently mono, so channel count is set to 1. Sample rate is also hard-coded to adhere to codec standards.

Also removed unused parameter `hasAdditionalViews` in `StriData`.

#cherrypick

PiperOrigin-RevId: 707606245
2024-12-18 11:03:26 -08:00
Googler
2d37823695 Add VP9 Mp4 clip to Mp4MuxerEndToEndParameterizedAndroidTest
The dump file for VP9 mp4 clips varied across SDK versions due to inconsistent CSDs from the platform extractor. By replacing the platform extractor with `MediaExtractorCompat`, the Media3 extractor will provide consistent CSDs across all SDK versions.

PiperOrigin-RevId: 707509473
2024-12-18 05:16:55 -08:00
Googler
6d2331fd13 Add ApvC codec support to Mp4Muxer.
PiperOrigin-RevId: 707482517
2024-12-18 03:38:20 -08:00
Googler
9b628d4542 Update Muxer Test with MediaExtractorCompact
Replace Platform extractor with MediaExtractorCompact in AndroidMuxerTestUtils.

PiperOrigin-RevId: 707469755
2024-12-18 02:50:11 -08:00
andrewlewis
da05a1a66b Fix handling of CBR audio in some AVI files
Before this change, the value of the `dwLength` in the stream header was
interpreted as the number of chunks in the file. Seeking and timestamp
calculation use the media duration and total chunk count. However, in some
files the `dwLength` field appears not to store the number of chunks. For
example, there are CBR MP3 and AC3 files where this field seems to store the
total number of bytes of compressed media instead. That caused seeking and
timestamp calculation to give much smaller values than expected (because the
`dwLength` is very large), which broke seeking.

Work around this using the `idx1` index header if present. We only support
audio formats where every audio sample is a sync sample in AVI, and all chunks
should therefore be listed in this index. Based on testing on many sample AVI
files this gives a reliable total chunk count and fixes seeking.

The test media file is a transcoded version of Big Buck Bunny but manually
edited to overwrite the length, rate and sample size header files to simulate
the error case.

PiperOrigin-RevId: 705103651
2024-12-11 07:43:57 -08:00
dancho
f55e0f3a3f VideoFrameProcessorTestRunner add support for portrait video
Fixes test failures due to differences test util bug that introduced
a crop in external texture sampling

PiperOrigin-RevId: 705061267
2024-12-11 04:45:12 -08:00
michaelkatz
987869e456 Implement secondary renderer feature for pre-warming
`RenderersFactory#createSecondaryRenderer` can be implemented to provide secondary renderers for pre-warming. These renderers must match their primaries in terms of reported track type support and `RendererCapabilities`.

If a secondary renderer is provided, ExoPlayer will enable it for a subsequent media item as soon as its `MediaPeriod` is prepared. This will cause the renderer to start decoding and processing content so that it is ready to play as soon as playback transitions to that media item.

PiperOrigin-RevId: 704326302
2024-12-09 10:07:33 -08:00
sheenachhabra
0a75447785 Rename terminologies as per the MP4-AT spec
https://developer.android.com/media/platform/mp4-at-file-format

PiperOrigin-RevId: 703531148
2024-12-06 09:58:11 -08:00
rohks
b816e2f284 Add E2E test for DASH stream with CMCD enabled and init segment
The test complements the existing E2E test for HLS in `HlsPlaybackTest` by verifying similar functionality for DASH in `DashPlaybackTest`.

PiperOrigin-RevId: 703454388
2024-12-06 04:39:14 -08:00
ibaker
18d156fe3c Configure ProgressiveMediaSource with a Format for subtitles
This means we can complete preparation (and trigger track selection)
before opening a `DataSource`, which then means we only end up loading
the data for a selected subtitle track (instead of all tracks as
currently happens).

By making preparation trivial in this case (with no reasonable cause
of error), we can also remove the `suppressPrepareError` option added in
b3290eff10.

This change also fixes the implementation of
`ProgressiveMediaPeriod.maybeStartDeferredRetry` to only short-circuit
return `false` if the chosen track is not audio or video **and** there
is at least one audio or video track in this period.

Issue: androidx/media#1721
PiperOrigin-RevId: 702275968
2024-12-03 03:40:49 -08:00
Googler
19b276d6a7 Allow track selection parameters to be set in ExoPlayerAssetLoader.
PiperOrigin-RevId: 701926949
2024-12-02 05:04:26 -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
ibaker
b19b6ccc60 MP3 VBRI: Use sampleCountToDurationUs() and samplesPerFrame
PiperOrigin-RevId: 700340564
2024-11-26 07:52:18 -08:00
ibaker
46578ee0a6 MP3: Use bytes field from VBRI frame instead of deriving from ToC
The previous code assumed that the `VBRI` Table of Contents (ToC)
covers all the MP3 data in the file. In a file with an invalid VBRI ToC
where this isn't the case, this results in playback silently stopping
mid-playback (and either advancing to the next item, or continuing to
count up the playback clock forever). This change considers the `bytes`
field to determine the end of the MP3 data, in addition to deriving it
from the ToC. If they disagree we log a warning and take the max value.
This is because we handle accidentally reading non-MP3 data at the end
(or hitting EoF) better than stopping reading valid MP3 data partway
through.

Issue: androidx/media#1904

#cherrypick

PiperOrigin-RevId: 700319250
2024-11-26 06:18:29 -08:00