543 Commits

Author SHA1 Message Date
Daniele Sparano
4adbeed6f6 Handle 4 byte start code prefix, ensure non empty samples 2025-02-21 11:46:08 +00:00
Daniele Sparano
dbf864fd69 Handle 4 byte start code prefix, ensure non empty samples, fix timestamp on very last sample on synthesized empty pusi 2025-02-21 11:46:08 +00: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
ibaker
2155c37b08 Switch most intra-lib deps from implementation to api
In all these cases I found at least one public method that takes or
returns a type from the dependency, or a type that inherits from a type
defined in the dependency.

PiperOrigin-RevId: 726130595
2025-02-12 11:29:50 -08:00
ibaker
5e6fb88372 Add missing LINT.If/ThenChange comments
PiperOrigin-RevId: 724291745
2025-02-07 04:10:41 -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
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
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
dancho
1892435fb3 Parse within GOP sample dependencies in ExtractorsFactory
Add helper methods to Mp4Extractor and FragmentedMp4Extractor
to convert between VideoCodecFlags and *ExtractorFlags

PiperOrigin-RevId: 715307495
2025-01-14 03:16:49 -08:00
Copybara-Service
d18ad57e30 Merge pull request #1979 from wischnow:main
PiperOrigin-RevId: 714911017
2025-01-13 04:09:58 -08:00
dancho
93f9e6574c Add missing Mp4Extractor.Flags to IntDef
PiperOrigin-RevId: 714084405
2025-01-10 09:54:19 -08:00
ibaker
e61b521b4a Clear SEI reordering queue when seeking in MPEG-TS files
This avoids outputting spurious samples after the seek.

PiperOrigin-RevId: 714082343
2025-01-10 09:45:21 -08:00
Ian Baker
77790df5a2 Plumb palette through as a method parameter to satisfy nullness checker 2025-01-10 17:17:28 +00:00
Ian Baker
b2f9c1e252 Reformat with google-java-format 2025-01-10 16:02:24 +00:00
Ian Baker
ce0512845f Fix lint/style issues, and log exception 2025-01-10 16:02:24 +00:00
Sven Wischnowsky
47a5166a1d Small fix for an off-by-two error. 2025-01-10 16:02:24 +00:00
Ian Baker
671810235f Assorted nullness and control flow clean-ups 2025-01-10 16:02:24 +00:00
Ian Baker
8520c66fd8 Add some nullness annotations, re-jig some logic and reformat 2025-01-10 16:02:24 +00:00
Sven Wischnowsky
391b72e257 Various cleanup and improvements as suggested by mainainer. 2025-01-10 16:02:24 +00:00
Sven Wischnowsky
f52d98eafd Use Util.maybeInflate() 2025-01-10 16:02:24 +00:00
Sven Wischnowsky
250bc86669 Add comments about needing the size in the IDX file. 2025-01-10 16:02:24 +00:00
Sven Wischnowsky
27a6883768 Another small fix 2025-01-10 16:02:24 +00:00
Sven Wischnowsky
7fbf511d30 Small fix 2025-01-10 16:02:23 +00:00
Sven Wischnowsky
721776c30e Support for Vobsub subtitles 2025-01-10 16:02:23 +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
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
dancho
281a0e7ac8 Populate HevcConfig with number of temporal layers
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: 713242894
2025-01-08 04:31:24 -08:00
ybai001
d16d80ca49 Update Dolby Vision format handling
* Add the missing DV profile 10 handling
* Set DV codec string instead of compatible format codec string in MP4 extractor
2025-01-08 10:40:03 +08:00
dancho
229aadc91b Update javadoc for FLAG_READ_WITHIN_GOP_SAMPLE_DEPENDENCIES
Reflects that FLAG_READ_WITHIN_GOP_SAMPLE_DEPENDENCIES only parses
H.264 bitstream, and that H.265 parsing will be controlled with
another flag.

PiperOrigin-RevId: 712921990
2025-01-07 08:33:14 -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
Copybara-Service
8fe0b7ac69 Merge pull request #1987 from ojoNetgem:Support_for_origin_and_extent_declared_in_ttml_styles
PiperOrigin-RevId: 712554507
2025-01-06 09:30:15 -08:00
Ian Baker
8d9cb7e5d0 Resolve some TODO comments that are now fixed by the new parsing support 2025-01-06 15:13:32 +00:00
Ian Baker
618c2cf952 Add a release note and format with google-java-format 2025-01-06 15:13:32 +00: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
Olivier Jouvenaux
fbd6dfa439 Add support for TTML origin and extent attributes defined in style instead of region 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
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
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
tonihei
3e3cd8e6ac Fix Javadoc reference link for VORBIS mapping
PiperOrigin-RevId: 704737734
2024-12-10 09:27:36 -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
sheenachhabra
e017213ee8 Fix some MP4-AT file format related naming
Also add spec link in the code.

PiperOrigin-RevId: 704329143
2024-12-09 10:14:34 -08:00
andrewlewis
fc3f096888 Fix handling of 'no chunk readers' in AVI
Before this change the chunk readers array was accessed out of bounds in files
for which no chunk readers are created.

PiperOrigin-RevId: 704323919
2024-12-09 10:01:13 -08:00