396 Commits

Author SHA1 Message Date
jbibik
e51c293f75 Plumb SubtitleParser.Factory into MatroskaExtractor
MatroskaExtractor will no longer be wrapped in SubtitleTranscodingExtractor, but instead use SubtitleTranscodingExtractorOutput under the hood.

FLAG_EMIT_RAW_SUBTITLE_DATA flag will be used to toggle between subtitle parsing during extraction (before the sample queue) or during decoding (after the sample queue).

The new extractor dump files generated by `MatroskaExtractorTest` now follow the new parsing logic and hence have mimeType as `x-media3-cues`.

PiperOrigin-RevId: 598616231
2024-01-15 08:32:22 -08:00
jbibik
a88d8a415a Plumb SubtitleParser.Factory into AviExtractor
AviExtractor supports text tracks (`AviExtractor.FOURCC_txts` -> `C.TRACK_TYPE_TEXT`) with subtitles.

AviExtractor will no longer be wrapped in SubtitleTranscodingExtractor, but instead use SubtitleTranscodingExtractorOutput under the hood.

FLAG_EMIT_RAW_SUBTITLE_DATA flag will be used to toggle between subtitle parsing during extraction (before the sample queue) or during decoding (after the sample queue).

PiperOrigin-RevId: 598594981
2024-01-15 06:21:33 -08:00
ibaker
4061d476a1 MP3: Assume an Info header indicates CBR for seeking purposes
The seek table in a Xing/Info header is very imprecise (max resolution
of 255 to describe each of 100 byte positions in the file). Seeking
using a constant bitrate assumption is more accurate, especially for
longer files (which exacerbates the imprecision of the Info header).

VBR files should contain an Xing header, while an Info header is
identical but indicates the file is CBR.

Issue: androidx/media#878
PiperOrigin-RevId: 597827891
2024-01-12 06:48:00 -08:00
jbibik
a728ec8e67 Plumb SubtitleParser.Factory into TsExtractor
PiperOrigin-RevId: 597578122
2024-01-11 09:35:22 -08:00
rohks
0f33ef3906 Improve readability of constant numbers and documentation in DtsUtil
PiperOrigin-RevId: 597493602
2024-01-11 02:25:44 -08:00
ibaker
3f9e0540b7 Remove non-progressive limitation from DefaultMediaSourceFactory.experimentalParseSubtitlesDuringExtraction
This involves promoting `setTextTranscodingEnabled` to
`ExtractorsFactory`, and also making it experimental, to indicate it's a
short-lived method.

PiperOrigin-RevId: 597235252
2024-01-10 06:46:50 -08:00
jbibik
d6ef48fff8 Plumb SubtitleParser.Factory into Mp4Extractor
Mp4Extractor will no longer be wrapped in SubtitleTranscodingExtractor, but instead use SubtitleTranscodingExtractorOutput under the hood.

FLAG_EMIT_RAW_SUBTITLE_DATA flag will be used to toggle between subtitle parsing during extraction (before the sample queue) or during decoding (after the sample queue).

PiperOrigin-RevId: 597221831
2024-01-10 05:36:08 -08:00
ibaker
4fde35c9cc MP3: Extract Xing/Info parsing code from XingSeeker
This means in a later change we can still use some of the info for CBR
files, even if we want to ignore the imprecise table of contents and
seek based on a constant bitrate assumption instead.

PiperOrigin-RevId: 597193997
2024-01-10 03:00:30 -08:00
ibaker
143d782b1c Add private @SeekHeader IntDef to Mp3Extractor
Also use `switch` instead of `if-else`.

PiperOrigin-RevId: 597004322
2024-01-09 12:04:24 -08:00
ibaker
1c1d4d506d MP3: Correct duration calculation in XingSeeker
An audio file can only play sound between two PCM samples (the 'start'
and 'end' of section of a wave form). Therefore when calculating
duration from a count of PCM samples we need to subtract one first (the
'end' sample which has no duration of its own).

This only changes durations by one PCM sample (21us - 22us for 44.1kHz sample
rate).

PiperOrigin-RevId: 596990306
2024-01-09 11:16:49 -08:00
tonihei
ba8f55694a Set PCM encoding in Flac extractor
The extractor knows the PCM encoding of the losslessly
encoded data in the samples and should set it in the
Format to allow downstream components to use this information.

PiperOrigin-RevId: 596974863
2024-01-09 10:28:55 -08:00
ibaker
320dd32be9 Add extractor test for an MP3 file with Info header
Issue: androidx/media#878
PiperOrigin-RevId: 596957503
2024-01-09 09:30:21 -08:00
jbibik
da724c8cc4 Plumb SubtitleParser.Factory into FragmentedMp4Extractor
We introduce SubtitleParser.Factory that supports no formats to be used FragmentedMp4Extractors that will not do any subtitle parsing on the extraction side. We also slowly move away from using SubtitleTranscodingExtractor to SubtitleTranscodingExtractorOutput (hence making it public).

This is required by individual Extractor impls so that they can start using SubtitleTranscodingExtractorOutput rather than be wrapped by SubtitleTranscodingExtractor. The latter is to be deprecated after all the subtitle related Extractors have achieved this migration.

PiperOrigin-RevId: 596942147
2024-01-09 08:33:27 -08:00
Copybara-Service
6f8249184b Merge pull request #942 from datdoantelus:CC_708_parser_fix
PiperOrigin-RevId: 596836615
2024-01-09 00:25:58 -08:00
ibaker
62f6c64a91 Rename test.mp3 test asset to test-cbr-info-header.mp3
This file is CBR encoded with LAME, so it has an `Info` header (the CBR
equivalent to `Xing`).

A follow-up change will use this file in `Mp3ExtractorTest`.

Issue: androidx/media#878
PiperOrigin-RevId: 595938327
2024-01-05 02:31:20 -08:00
ibaker
1cb6865884 Remove CEA-6/708 support from DefaultSubtitleParserFactory
`Cea608Parser` and `Cea708Parser` don't currently work correctly on
their own without the re-ordering of input buffers implemented in
`CeaDecoder`, and it's not clear how we can properly do this re-ordering
during extraction. This change ensures that if 'parse subtitles
during extraction' is enabled, CEA-6/708 subs will be passed through
without transcoding and can then be decoded during rendering by
`Cea6/708Decoder`.

PiperOrigin-RevId: 595658628
2024-01-04 03:48:41 -08:00
Copybara-Service
8eda9f2ed2 Merge pull request #369 from Tolriq:fix_invalid_frames
PiperOrigin-RevId: 595650068
2024-01-04 03:02:29 -08:00
rohks
5970d2d586 Document and remove check for C.TIME_UNSET when consuming data in TS
PiperOrigin-RevId: 595647795
2024-01-04 02:50:04 -08:00
Ian Baker
0b482ef58c Remove columnLock, columnCount (unimplemented) and rowLock (always true)
Also add a release note and simplify the test by removing the garbage
prefix and suffix.
2024-01-03 17:49:35 +00:00
Ian Baker
04751a1cdb Format with google-java-format 2024-01-03 17:36:55 +00:00
datdoantelus
a58ddcfa23 Update test comment. 2024-01-03 17:36:55 +00:00
datdoantelus
28eb55c077 Use skipBits(2) instead of readBits for ignored bits.
Add singleServiceAndWindowDefinition_ignoreRowLock test to Cea708ParserTest
2024-01-03 17:36:55 +00:00
datdoantelus
8b39f7e287 Ignore rowLock and columnLock values as specified by ANSI/CTA-708-E S-2023 document (section 8.4.7) 2024-01-03 17:36:55 +00:00
Ian Baker
f935f59eaa Improve logging by including full stack trace, and add release note 2024-01-03 16:14:37 +00:00
Ian Baker
820278c564 Format with google-java-format 2024-01-03 15:49:43 +00:00
Tolriq
de772cfbf0 Catch errors and OOM when decoding ID3 frames.
Invalid frames have no impact on ExoPlayer ability to play the media and should not fail on errors.
Some tools can add 100Mb images in the tags that will trigger recoverable OOM with this fix.
2024-01-03 15:49:43 +00:00
ibaker
258ffa68b5 Add tests with out-of-order CEA-608 input buffers
The `Cea608DecoderTest` added here fails if re-ordering is removed from
`CeaDecoder`.

The `Cea608ParserTest` is added with `@Ignore` because there's currently
no re-ordering support in this part of the subtitle handling pipeline
(partly because there's no concept of 'current playback time', meaning
it's hard to know **when** to re-order).

PiperOrigin-RevId: 595320205
2024-01-03 00:45:31 -08:00
ibaker
7b450f0d0a Fix limit calculation to include offset in Cea6/708Parser.parse
PiperOrigin-RevId: 595007390
2024-01-01 20:22:27 -08:00
ibaker
64231ee079 Tweak SubtitleTranscodingTrackOutput.ensureSampleDataCapacity
This more closely matches the intended, documented behaviour of this
method. The previous implementation was incorrectly checking
`sampleDataEnd + newSampleSize`, but it's more correct to compare
`existingSampleDataLength + newSampleSize`, in order to handle the
case of non-zero `sampleDataStart`. We've already checked above whether
`newSampleSize` fits after `sampleDataEnd` without growing or
reshuffling the array, so no need to basically repeat that check.

In the case of handling one sample at a time, the previous
implementation resulted in `sampleData` growing by `sampleSize`
**every time** the pointers reached the end. With the new check for
`sampleDataStart == sampleDataEnd`, this is avoided by always writing
each new sample at the start of the array (because the previous sample
has already been consumed), meaning `sampleData` remains equal to
`sampleSize` without growing.

PiperOrigin-RevId: 593119927
2023-12-22 08:06:30 -08:00
ibaker
486230fbd7 Throw a clear error from Cea608/708Parser.parseToLegacySubtitle
This would have immediately exposed the mistakes fixed by
7ca26f898d

Issue: androidx/media#904
PiperOrigin-RevId: 592244943
2023-12-19 08:34:37 -08:00
tonihei
01578780a6 Use different wraparound assumptions for duration readers
The timestamp adjuster also estimates the number of wraparounds
of the 90Khz TS timestamp. It does that by assuming that a new
timestamp is always close to the previous one (in either direction).

This logic doesn't always work for duration estimates because the
timestamp at the end of the media is not close to the one at the
beginning and it may also never be less than the one at the beginning.

This can be fixed by introducing a new estimation model that assumes
the new timestamp is strictly greater than the previous one without
making the assumption that it has to be close to it.

Issue: androidx/media#855

#minor-release

PiperOrigin-RevId: 590936953
2023-12-14 07:47:11 -08:00
lpribanic
d52772dff8 Set image tile counts to what the manifest says
Vertical and horizontal tile counts inside Format used by ImageRenderer
used to be required to equal 1 and were set to 1 regardless of what
the manifest said.

This change removes the above requirement and sets the tile counts to
the values from the manifest.

PiperOrigin-RevId: 590608353
2023-12-13 08:37:06 -08:00
Copybara-Service
f465efeefd Merge pull request #864 from v-novaltd:dsparano-exo129_2
PiperOrigin-RevId: 590234505
2023-12-12 09:37:41 -08:00
ibaker
5580b78b13 Fix VorbisComment.populateMediaMetadata key comparison to ignore case
Issue: androidx/media#876

#minor-release

PiperOrigin-RevId: 590215918
2023-12-12 08:43:02 -08:00
ibaker
5266c71b3a Fix handling of multiple HEVC tracks in JPEG motion photos
The MP4 data in JPEG motion photos can contain multiple `video/hevc` tracks, but only the first is at a playable frame rate while the others are low-fps, high-res tracks designed for specific use-cases (not direct video playback).

ExoPlayer currently selects the unplayable track by default, because it
has a higher resolution. This change introduces a flag to
`Mp4Extractor` that results in the first video track being marked as
`ROLE_FLAG_MAIN`, and all subsequent video tracks `ROLE_FLAG_ALTERNATE`
- this then results in the playable lower-res track being selected by
default.

PiperOrigin-RevId: 589832072
2023-12-11 08:31:13 -08:00
tonihei
eb2092bc8b Formatting fixes and release notes 2023-12-11 15:12:50 +00:00
Daniele Sparano
6f5187a34b Format to wake up PR 2023-12-11 14:28:11 +00:00
Daniele Sparano
4a17ca7600 Add basic h264 sample unit test to ensure correct sample flags, including key frames 2023-12-11 14:28:11 +00:00
Daniele Sparano
d4af13803a Fix H264 reader key frame detection 2023-12-11 14:28:11 +00:00
ibaker
379cb3ba54 Tighten the handling of validDataChannelTimeoutMs in Cea608Parser
This matches the documented requirements for this parameter.

PiperOrigin-RevId: 589799256
2023-12-11 06:05:53 -08:00
ibaker
bd19953ac9 Split Cue.toBundle into serializable and binder-based variants
The serializable form is used when we need to serialize the result into
bytes in the sample queue. The binder-based (ultimately
filedescriptor-based) form is used for
session/controller IPC, in order to avoid sending the bitmap bytes over
the IPC.

Issue: androidx/media#836

#minor-release

PiperOrigin-RevId: 588420836
2023-12-06 07:35:34 -08:00
ibaker
6360082b87 Add extractor and playback tests for Pixel JPEG motion photo
This image has two video tracks in the MP4 data, one is a 'real' video
which we want to play by default, and the other is a low-fps video track
which isn't intended to be directly played, it's encoded in HEVC for
compression and decoding efficiency.

This test demonstrates ExoPlayer's current behaviour default extraction
and playback, which results in selecting the high-res, low-fps track
(actually single sample in this example), instead of playing the actual
video.

PiperOrigin-RevId: 588068908
2023-12-05 07:46:19 -08:00
michaelkatz
d1e38abf93 Limit processing Opus decode-only frames by seek-preroll in offload
As Opus decoders skip some bytes prior to playback during a seek, the renderer for bypass playback should send samples to the decoder even if they would be decode-only. However, the renderer should not send samples with time preceding that range. This change adds that constraint.

#minor-release

PiperOrigin-RevId: 588014983
2023-12-05 03:44:37 -08:00
tonihei
b1541b096f Map VORBIS channel layout to Android layout
Both the extension OPUS decoder and the OMX/C2 MediaCodec
implementations for OPUS and VORBIS decode into the channel
layout defined by VORBIS. See
https://www.xiph.org/vorbis/doc/Vorbis_I_spec.html#x1-140001.2.3

While this is technically correct for a stand-alone OPUS or VORBIS
decoder, it doesn't match the channel layout expected by Android.
See https://developer.android.com/reference/android/media/AudioFormat#channelMask

The fix is to apply the channel mapping after decoding if needed.
Also add e2e tests with audio dumps for the extension renderer,
including a new 5.1 channel test file.

Issue: google/ExoPlayer#8396

#minor-release

PiperOrigin-RevId: 588004832
2023-12-05 03:01:32 -08:00
ibaker
63062a9c10 Make CueSerializationTest more realistic
Serializing bitmap cues is currently broken, but this test is
incorrectly passing. This change makes two changes to introduce the same
failure (both changes are necessary, each one alone still passes):

1. Move from Robolectric to an instrumentation test.
2. Trigger the `Bitmap` to be serialized using a file descriptor, either
   by calling `Bitmap.asShared` in the test when constructing the `Cue`,
   or constructing the `Bitmap` from a 'real' image byte array instead a
   1x1 token image.

Issue: androidx/media#836
PiperOrigin-RevId: 585643486
2023-11-27 07:16:19 -08:00
jbibik
c0ef5f6de4 Serialize media3 custom Spans for Cue encoding/decoding
PiperOrigin-RevId: 585028521
2023-11-24 01:32:40 -08:00
Copybara-Service
fde142d66e Merge pull request #793 from androidx:mpegh_extractor_changes
PiperOrigin-RevId: 584291984
2023-11-21 05:07:27 -08:00
Rohit Singh
4c3ca9b6f4 update mhm1 mp4 samples and corresponding extractor dumps 2023-11-21 12:12:23 +00:00
ibaker
4bcb60d31d Add Cea708Decoder/ParserTest with a single, simple example
PiperOrigin-RevId: 584042033
2023-11-20 09:06:03 -08:00
jbibik
94e45eb4ad Migrate CEA-708 logic to a SubtitleParser implementation
This change is similar to 27caeb8038 (CEA-608), but is currently lacking unit tests.

PiperOrigin-RevId: 582585457
2023-11-15 01:38:56 -08:00