467 Commits

Author SHA1 Message Date
rohks
c3d4a3d683 Set container MIME type for extractors in ts module
PiperOrigin-RevId: 696882489
2024-11-15 07:37:43 -08:00
rohks
68c0b8115f Set container MIME type for Flv, Matroska, and image extractors
Image extractors (e.g., `PngExtractor`) use `SingleSampleExtractor`
for extraction.

PiperOrigin-RevId: 696869657
2024-11-15 06:42:12 -08:00
ibaker
e6448f3498 Don't assume MP4 keyframe metadata is correct for CEA re-ordering
The content in Issue: androidx/media#1863 has every sample incorrectly marked as a
sync sample in the MP4 metadata, which results in flushing the
re-ordering queue on every sample, so nothing gets re-ordered, so the
subtitles are garbled.

There are currently two "uses" for this call on every keyframe:
1. It offers a safety valve if we don't read a `maxNumReorderSamples`
value from the video. Without this, the queue will just keep growing
and end up swallowing all subtitle data (similar to the bug fixed by
39c734963f).

2. When we do read (or infer) a `maxNumReorderSamples` it means we can
emit samples from the queue slightly earlier - but this is pretty
marginal, given i think the max possible value for
`maxNumReorderSamples` is 16, so the most benefit we would get is 16
frames (~0.53s at 30fps) - in most cases we will have more than 0.5s
of buffer ahead of the playback position, so the subtitles will still
get shown at the right time with no problem.

(1) is resolved in this change by setting the queue size to zero (no
reordering) if we don't have a value for `maxNumReorderSamples`.

(2) has minimal impact, so we just accept it.

We may be able to inspect the NAL unit to determine IDR vs non-IDR
instead - we will consider this as a follow-up change, but given the
minimal impact of (2) we may not pursue this.

#cherrypick

PiperOrigin-RevId: 696583702
2024-11-14 11:05:02 -08:00
rohks
2379d0f18c Set container MIME type for audio-only extractors
PiperOrigin-RevId: 696560053
2024-11-14 10:03:17 -08:00
rohks
93b4c6ef47 Set container MIME type in Mp4Extractor and FragmentedMp4Extractor
PiperOrigin-RevId: 696513199
2024-11-14 07:23:22 -08:00
Copybara-Service
74611bbdc0 Merge pull request #1265 from DolbyLaboratories:dlb/ac4-level4/dev_new2
PiperOrigin-RevId: 696157037
2024-11-13 09:08:22 -08:00
ibaker
0f96ad247d Fix 'narrowing conversion' warning in FragmentedMp4Extractor
PiperOrigin-RevId: 696119977
2024-11-13 07:08:12 -08:00
Googler
838c621d00 Add support to ApvC codec in Mp4Extractor
PiperOrigin-RevId: 695819965
2024-11-12 11:59:56 -08:00
ibaker
19b38c83b6 Handle C.TIME_END_OF_SOURCE buffer timestamps in CeaDecoder
The behaviour was changed in 1.4.0 with 0f42dd4752,
so that the buffer timestamp is compared to `outputStartTimeUs` when
deciding whether to discard a "decode only" buffer before decoding
(instead of the deprecated/removed `isDecodeOnly` property). This breaks
when the buffer timestamp is `TIME_END_OF_SOURCE` (which is
`Long.MIN_VALUE`), because `TIME_END_OF_SOURCE < outputStartTimeUs` is
always true, so the end-of-stream buffer is never passed to the decoder
and on to `TextRenderer` where it is used to
[set `inputStreamEnded = true`](40f187e4b4/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/text/TextRenderer.java (L434-L436))
and so playback hangs.

#cherrypick

Issue: androidx/media#1863
PiperOrigin-RevId: 695767247
2024-11-12 09:38:44 -08:00
ibaker
ab723fc8ff Mark every media3-cues sample as a keyframe
This format doesn't require any context from previous samples, so every
sample is a keyframe.

PiperOrigin-RevId: 693658370
2024-11-06 03:15:59 -08:00
ibaker
286273c10e Enable lint in tests for modules that require no fixes
PiperOrigin-RevId: 693313908
2024-11-05 05:40:03 -08:00
rohks
15583f7c64 Set track duration in AmrExtractor, Mp3Extractor and OggExtractor
PiperOrigin-RevId: 691433024
2024-10-30 08:46:45 -07:00
ibaker
27371db225 Support CEA-608 subtitles in Dolby Vision
Issue: androidx/media#1820

#cherrypick

PiperOrigin-RevId: 691378476
2024-10-30 05:18:14 -07:00
rohks
b1f2efd218 Fix handling of cues that exceed total duration in MatroskaExtractor
Adjusted logic to accurately calculate sizes and durations for the last valid cue point when cue timestamps are greater than the total duration.

Fixes the issue where the reported duration of the MKV file was greater than the total duration specified by the duration element. Verified this using `mkvinfo` and `mediainfo` tools.

PiperOrigin-RevId: 690961276
2024-10-29 04:18:38 -07:00
ibaker
39c734963f H264Reader: Add missing propagation of max_num_reorder_frames
This method is already called below in the
`else if (sps.isCompleted())` block which applies when
`hasOutputFormat == true`, but this is only ever entered if we are
parsing SPS and PPS NAL units **after** we've emitted a format, which
is only the case if
`DefaultTsPayloadReaderFactory.FLAG_DETECT_ACCESS_UNITS` is set (which
it isn't by default).

The equivalent call in `H265Reader` is already inside the
`if (!hasOutputFormat)` block, so doesn't need a similar fix.

#cherrypick

PiperOrigin-RevId: 689809529
2024-10-25 09:13:53 -07:00
rohks
e25bc2c1a5 Populate track duration(s) in Avi, Flac and Wav extractors
PiperOrigin-RevId: 689716977
2024-10-25 03:03:08 -07:00
rohks
e677c8dccd Fix duration calculation for AVI files
The duration is now correctly calculated as the maximum of all track durations, instead of being overwritten by the last track's value. This aligns with how other Extractor implementations handle durations for multiple tracks.

PiperOrigin-RevId: 688896743
2024-10-23 03:34:04 -07:00
rohks
7545a8929b Add support for identifying h263 box in MP4 files for H.263 video
Issue: androidx/media#1821

#cherrypick

PiperOrigin-RevId: 688570141
2024-10-22 09:02:33 -07:00
rohks
e926b0df1e Populate track duration in Mp4Extractor and FragmentedMp4Extractor
PiperOrigin-RevId: 688125056
2024-10-21 07:16:34 -07:00
rohks
847c1252e2 Add default method durationUs(long) in TrackOutput
The method allows extractors to set track duration when available. The `default` implementation does nothing, allowing implementers of `TrackOutput` to override it if they need to handle track duration.

Implemented it in `FakeExtractor` to print track duration in dump files.

PiperOrigin-RevId: 688110288
2024-10-21 06:18:00 -07:00
rohks
457bc55a4d Fix media duration parsing in mdhd box of MP4 files to handle -1 values
Treats the media duration as unknown (`C.TIME_UNSET`) when all bytes are `-1` to prevent exceptions during playback.

Issue: androidx/media#1819

#cherrypick

PiperOrigin-RevId: 688103949
2024-10-21 05:54:44 -07:00
ibaker
49337d9667 Fix some markdown-in-javadoc
PiperOrigin-RevId: 687354846
2024-10-18 10:48:43 -07:00
rohks
692f1c78b3 Add ForwardingTrackOutput implementation
This allows users to extend and customize specific methods of the `TrackOutput` implementation while inheriting default behaviors for others.

PiperOrigin-RevId: 686454360
2024-10-16 04:20:33 -07:00
rohks
91c56335ef Handle out-of-order frames in endIndices for MP4 with edit list
Updated logic to walk forward in the timestamps array to include all frames within the valid edit duration, accounting for out-of-order frames. This ensures that no frames with timestamps less than `editMediaTime` + `editDuration` are incorrectly excluded.

Issue: androidx/media#1797
PiperOrigin-RevId: 686075680
2024-10-15 06:09:15 -07:00
Copybara-Service
4df9d4e146 Merge pull request #1792 from DolbyLaboratories:dlb/elst-handling/dev
PiperOrigin-RevId: 685851466
2024-10-14 15:20:17 -07:00
ybai001
3f4a16555d Bugfix: segment_duration and media_time use different unit 2024-10-09 16:54:59 +08:00
ibaker
546d7da2f2 Fix Fmp4Extractor.init to use text transcoding ExtractorOutput
This was missed in da724c8cc4

I tried to write a test for this, but got stuck crafting valid test
data. I was able to create a new fragmented MP4 file containing only a
TTML track:

```shell
$ MP4Box -add simple.ttml -frag 2000 sample_fragmented_ttml.mp4
```

Then I tried naively removing the `ftyp` and `moov` boxes with a hex
editor, but using this in `FragmentedMp4ExtractorNoSniffingTest` gave
me an `EOFException` that I didn't get to the root cause of.

Issue: androidx/media#1779

#cherrypick

PiperOrigin-RevId: 683667850
2024-10-08 10:11:18 -07:00
rohks
72ab282c0d Ignore channelCount and sampleRate values read from iamf box
As per the IAMF spec (https://aomediacodec.github.io/iamf/#iasampleentry-section), `channelCount` and `sampleRate` SHALL be set to `0` and ignored.

#cherrypick

PiperOrigin-RevId: 683648991
2024-10-08 09:18:44 -07:00
ibaker
abfeea518e Ensure consistent ExtractorOutput usage in WebvttExtractor
This change is a no-op, because
`SubtitleTranscodingExtractorOutput.seekMap` forwards directly to the
delegate implementation, but it seems clearer to always use the
wrapper.

Also remove a no-op assignment in `MatroskaExtractor`.

This is a follow-up to Issue: androidx/media#1779 where I manually checked every
implementation of `Extractor.init` for a similar mistake.

#cherrypick

PiperOrigin-RevId: 683607090
2024-10-08 07:04:50 -07:00
tonihei
f7af58951d Allow signed TTML region origins
The origin may be negative if the subtitle starts off-screen
but extends into the screen for example.

TTML1 defines `tts:origin` in terms of
[`length`](https://www.w3.org/TR/2018/REC-ttml1-20181108/#style-value-length),
which allows a prefix of `+`, `-` or nothing, and it's the
[same in TTML2](https://www.w3.org/TR/2018/REC-ttml2-20181108/#style-value-length).

PiperOrigin-RevId: 682379845
2024-10-04 10:58:42 -07:00
rohks
ecb0024a0b Improve frame rate calculation by using media duration from mdhd box
- Added logic to parse media duration from the `mdhd` box for accurate frame rate calculation.
- Fallbacks to track duration from `tkhd` when `mdhd` contains invalid or missing data.
- Avoids incorrect frame rate calculations in MP4 files with an edit list (`elst`) box.
- Adds frame rate calculations for partially fragmented MP4 files.
- Verified accuracy with tools like `mediainfo` and `ffprobe`.

Issue: androidx/media#1531

**Note**: The slight difference in frame rate values in dump files that aren’t MP4s with an edit list or fragmented MP4s isn’t due to differences in `tkhd` and `mdhd` duration values (which should be identical for non-edited or non-fragmented files). Rather, it’s because they are calculated using different timescales. The `mvhd` box defines a global movie timescale, which is used for the track's `tkhd` duration. Meanwhile, each track’s `mdhd` box defines its own timescale specific to its content type, which we now use for more accurate frame rate calculation.

PiperOrigin-RevId: 676046744
2024-09-18 10:42:11 -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
ibaker
551cbadafc Gracefully handle unexpected non-MP3 trailing data
The `bear-cbr-no-seek-table-trailing-garbage.mp3` test file was generated by appending 150kB of `0xDEADBEEF` onto the end of `bear-cbr-variable-frame-size-no-seek-table.mp3`.

Issue: androidx/media#1563

#cherrypick

PiperOrigin-RevId: 670131828
2024-09-02 02:10:13 -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
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
cd47e2a134 Remove redundant test 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
d6f08a6237 Add VTT voice spans to cues 2024-08-29 10:25:06 +01:00
Googler
6b56f12f15 AtomParser: Update initialization data to CodecPrivate format for Vp9
PiperOrigin-RevId: 666188937
2024-08-21 22:33:28 -07:00
sheenachhabra
875953f971 Add Mp4Extractor test for interleaved editable video tracks file
PiperOrigin-RevId: 665800463
2024-08-21 03:34:28 -07:00
rohks
f52ca07446 Add option to enable index-based seeking in AmrExtractor
This allows seek operations in files that were previously unseekable, particularly those with variable bitrate (VBR) or constant bitrate (CBR) with silence frames.

New samples for tests were created by adding silence frames to existing narrowband and wideband versions.

PiperOrigin-RevId: 665349241
2024-08-20 07:17:26 -07:00
Ian Baker
2e49e91c84 Rename to singular BoxParser for consistency with other types like ColorParser 2024-08-20 11:11:14 +01:00
Ian Baker
77f3ef9b25 Add @UnstableApi annotation 2024-08-20 11:09:50 +01:00
Ian Baker
2dd6794ba0 More atom -> box updates in public API surface 2024-08-20 11:09:50 +01:00
Colin Kho
3a95b24afc Rename BoxParsers tag from AtomParsers to BoxParsers 2024-08-20 11:09:50 +01:00
Colin Kho
6ba9c9ff9e Rename AtomParsers to BoxParsers 2024-08-20 11:09:50 +01:00
Colin Kho
0b5443c450 Make Extractor/Mp4 Atom Parsing code reusable by external custom mp4 extractors 2024-08-20 11:09:50 +01:00
claincly
677f8ad9f4 Fix edge case: no frame between trim position and the next sync sample
PiperOrigin-RevId: 664841893
2024-08-19 09:32:32 -07:00