437 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
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
tonihei
ba00798451 Make NalUnitTargetBuffer public
This class is a useful utility for custom TS parsers that operate
on NAL units.

PiperOrigin-RevId: 664795988
2024-08-19 07:23:05 -07:00
ibaker
91a95e23c9 Remove CueDecoder.decode overload without length & offset params
This method is only used in tests, so let's remove it and just test the
one that takes `length` and `offset`.

PiperOrigin-RevId: 663731139
2024-08-16 07:59:12 -07:00
rohks
50708f8c37 Add AmrExtractor tests with FLAG_ENABLE_CONSTANT_BITRATE_SEEKING_ALWAYS
PiperOrigin-RevId: 663320349
2024-08-15 08:53:28 -07:00
ibaker
ee27334f06 Rename Atom to Mp4Box, and move it to container module
This makes the class available to custom MP4-parsing implementations,
while also allowing it to be used by `muxer` in future.

'Box' is the term used throughout the ISO 14496-12 spec, while the
'Atom' nomenclature was used in an earlier form of the spec
(Quicktime).

This change moves it from `extractor.mp4.Atom` to `container.Mp4Box`,
to be consistent with existing MP4-specific types in the `container`
module like `Mp4TimestampData`.

PiperOrigin-RevId: 663274752
2024-08-15 05:44:32 -07:00
sheenachhabra
68eaa061e0 Add support for depth/editing file format in Mp4Extractor
PiperOrigin-RevId: 662956209
2024-08-14 09:55:01 -07:00
rohks
74cfd2ad79 Deduplicate AMR samples and use dump file prefix for unique names
AMR samples with identical data but different names, previously used to generate uniquely named dump files, have been deleted. Instead, `AssertionConfig` is now used to set the dump file prefix, ensuring files are generated with unique names.

PiperOrigin-RevId: 662883541
2024-08-14 05:36:26 -07:00
rohks
e9cfd72083 Enable CBR seeking for files with unknown length in AmrExtractor
Constant bit rate (CBR) seeking can be enabled even when the length of the file is not known.

Additionally, dump files for these files have been updated to accurately log the `position` when `timeUs` is set to `0`.

PiperOrigin-RevId: 662868607
2024-08-14 04:32:38 -07:00
ibaker
9d008da356 Remove unused Atom.ContainerAtom.getChildAtomOfTypeCount(int) method
This is in preparation for making this class public.

PiperOrigin-RevId: 662466043
2024-08-13 04:41:05 -07:00
ibaker
9dfd72b6c6 Move atom parsing logic from Atom to AtomParsers
This is groundwork to moving `Atom` to the `container` library, which
we want to do before making it public (so it can be used by `muxer` in
future).

PiperOrigin-RevId: 662453520
2024-08-13 03:50:40 -07:00
ibaker
f37f9690f4 Pass missing length into SubtitleParser from SubtitleExtractor
If the length of the `ExtractorInput` is not known then the
`subtitleData` field is re-sized by 1kB each time
(`SubtitleExtractor.DEFAULT_BUFFER_SIZE`), so the end of the array is
often not populated. This change ensures that `length` is propagated to
`SubtitleParser`, so that implementations don't try and parse the
garbage/zero bytes at the end of the array.

Discovered while investigating Issue: androidx/media#1516

#cherrypick

PiperOrigin-RevId: 661195634
2024-08-09 03:09:09 -07:00
kak
2202397758 Automated Code Change
PiperOrigin-RevId: 660491742
2024-08-07 12:28:25 -07:00
ibaker
3763e5bc1d Fix IndexOutOfBoundsException in LegacySubtitleUtil
This is caused when the requested "output start time" is equal to or
larger than the last event time in a `Subtitle` object.

This resolves the error in Issue: androidx/media#1516, but subtitles are still not
renderered (probably because the timestamps aren't what we expect
somewhere, but I need to investigate this part further).

#cherrypick

PiperOrigin-RevId: 660462720
2024-08-07 11:16:30 -07:00
rohks
bef134a093 Fix IndexSeekMap.getTimeUs() javadoc
PiperOrigin-RevId: 660376007
2024-08-07 07:11:43 -07:00
rohks
9bc199f107 Refactor IndexSeeker to utilize IndexSeekMap, removing redundant code
This is a no-op change.

PiperOrigin-RevId: 660370824
2024-08-07 06:51:42 -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
ibaker
b09cea9e3a Implement MP3 ConstantBitrateSeeker.getDataEndPosition()
This is needed to correctly handle files with trailing non-MP3 data
(which is indicated by the length in the `Info` frame being shorter than
the overall length of the file).

The test file was generated by appending 150kB of `DEADBEEF` onto the
end of `test-cbr-info-header.mp3`, and the test asserts that the
extracted samples are identical.

Issue: androidx/media#1480

#cherrypick

PiperOrigin-RevId: 658727595
2024-08-02 02:51:49 -07:00
Gaëtan Muller
71b8c32a6f Remove Multidex 2024-07-24 16:17:00 +01:00
ibaker
5fa9985ce6 Add H264_ prefix to NalUnitUtil.NAL_UNIT_TYPE_* constants
Also promote all H.265 constants to be public in `NalUnitUtil` with
`H265_` prefixes, for consistency.

A lot of these names are used in h.265 too (and `NalUnitUtil` handles
both), but with different values, so this rename aims to avoid
accidentally using an h.264 value in an h.265 context.

PiperOrigin-RevId: 651774188
2024-07-12 08:02:24 -07:00
Googler
735e0cf8a1 Add an MV-HEVC test to Mp4ExtractorParameterizedTest.
PiperOrigin-RevId: 651392787
2024-07-11 06:52:15 -07:00
ibaker
0ea555dae0 Stop using SubtitleTranscodingExtractor and deprecate it
The integration with `SubtitleTranscodingExtractorOutput` has been
moved inside the relevant `Extractor` implementations instead.

PiperOrigin-RevId: 651213564
2024-07-10 18:09:53 -07:00
Googler
f673ef43b4 Add support for SEI and vexu box parsing.
Stereo view information is stored in the 3D reference displays information SEI and the optional vexu box.  Parsing of the SEI and vexu box is added, and based on the parsed info, proper mapping of primary/secondary view to left/right eye is determined.

PiperOrigin-RevId: 651002190
2024-07-10 07:00:29 -07:00
andrewlewis
dcc3e439e2 Handle AVI containers with no keyframes in index
If there is no keyframe in the index assume that the first chunk has a
keyframe.

PiperOrigin-RevId: 650915467
2024-07-10 01:51:06 -07:00
dancho
6650270a4e MediaCodecVideoRenderer skips decoder inputs unused as reference
During a seek, or when playing a media with clipped start,
MCVR encounters preroll decode-only buffers that are not rendered.
Use C.BUFFER_FLAG_NO_OTHER_SAMPLE_DEPENDS_ON_THIS to determine
whether a decode-only buffer is unused as reference.
These buffers can be dropped before the decoder.
When this optimization is triggered, increment
decoderCounters.skippedInputBufferCount.

Tested in ExoPlayer demo app on "One hour frame counter (MP4)"
after enabling extractorsFactory.setMp4ExtractorFlags(
    FLAG_READ_WITHIN_GOP_SAMPLE_DEPENDENCIES);
Observe: "sib" increases on each seek.
PiperOrigin-RevId: 650566216
2024-07-09 03:43:06 -07:00
dancho
439536480b Parse the H264 bitstream of fMP4 files to identify sample dependencies
Changes to FragmentedMp4Extractor to parse additional sample dependency
information and mark output samples as "no other samples depend on this".
Only applies to H.264 tracks.
Controlled by new fMP4 flag: FLAG_READ_WITHIN_GOP_SAMPLE_DEPENDENCIES

PiperOrigin-RevId: 650538377
2024-07-09 01:53:51 -07:00
ktrajkovski
972007abef Add readLeb128 and readLeb128ToInt to ParsableByteArray.
Leb128 is a little-endian long of variable byte length. The format is used during the extraction of the size of the OBU configuration for the iacb configuration box.

PiperOrigin-RevId: 650295002
2024-07-08 10:29:42 -07:00