130 Commits

Author SHA1 Message Date
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
ibaker
2520dd12f9 Fix EMSG typo in HlsChunkSource and ChunkSampleStream
PiperOrigin-RevId: 678870309
2024-09-25 15:33:22 -07:00
kak
2202397758 Automated Code Change
PiperOrigin-RevId: 660491742
2024-08-07 12:28:25 -07:00
tonihei
867410fece Rename DummyTrackOutput and DummyExtractorOutput
#cherrypick

PiperOrigin-RevId: 646434450
2024-06-25 05:07:56 -07:00
rohks
d4802a429b Fix bug where enabling CMCD for HLS live streams causes error
Determine `nextMediaSequence` and `nextPartIndex` based on the last `SegmentBaseHolder` instance, as it can update `mediaSequence` and `partIndex` depending on whether the HLS playlist has trailing parts or not.

Issue: androidx/media#1395
PiperOrigin-RevId: 642961141
2024-06-13 06:12:08 -07:00
tianyifeng
86a60e6ec2 Schedule refresh for all the playing playlists for HLS live stream
Issue: androidx/media#1240
PiperOrigin-RevId: 642927082
2024-06-13 03:52:16 -07:00
rohks
438279a3a0 Remove unnecessary throws Exception from HlsChunkSourceTest
PiperOrigin-RevId: 640552488
2024-06-05 09:35:53 -07:00
rohks
387153fcf2 Fix CMCD data assignment for init segment
The CMCD data was incorrectly added to the `dataSpec` of the media segment instead of the init segment.

Also relaxed the condition for playbackRate to be C.RATE_UNSET when creating an instance of CmcdData.Factory as there was nothing enforcing this check.

#minor-release

PiperOrigin-RevId: 639046080
2024-05-31 08:42:53 -07:00
rohks
8c8bf1334e Use INDEX_UNSET instead of LENGTH_UNSET for next media sequence/part
Both constants have the same value, but the method returning initial values for the media sequence/part uses `INDEX_UNSET`, so it makes sense to use it.

PiperOrigin-RevId: 638673282
2024-05-30 09:10:09 -07:00
ibaker
0352db9a37 Default to parse subtitles while extracting, instead of while rendering
To override this change, and go back to parsing during rendering,
apps must make two method calls:

1. `MediaSource.Factory.experimentalParseSubtitlesDuringExtraction(false)`
2. `TextRenderer.experimentalSetLegacyDecodingEnabled(true)`

PiperOrigin-RevId: 634262798
2024-05-16 01:42:56 -07:00
tianyifeng
e180e263a5 Refresh HlsMediaPlaylist with delivery directives when possible
When refreshing the media playlist, we should try to request via a url with [delivery directives](https://datatracker.ietf.org/doc/html/draft-pantos-hls-rfc8216bis#section-6.2.5). However, when initially loading the media playlist or when the last loading with delivery directives encountered an error, we should not allow using those directives.

PiperOrigin-RevId: 629060177
2024-04-29 07:24:35 -07:00
tianyifeng
50fefe698d Avoid non-primary playlists continuously reloading for LL-HLS streams
For LL-HLS, the non-primary playlists originally keep reloading even after the primary playlist has been changed to another one. The reason being this is to check if the hinted(#EXT-X-PRELOAD-HINT) resource has been published or removed. If removed, the loading of it should be canceled, per the suggestion in the HLS spec:

"A Client SHOULD cancel a request for a hinted resource if it is not present in a subsequent Playlist update, such as in an EXT-X-PRELOAD-HINT tag or as part of another tag such as EXT-X-PART.  The client SHOULD ignore the results of such requests."

However, keeping the non-primary playlists reloading is not optimal. As a solution, we trigger the playlist reloading only when there is a preload chunk loading instead of every time after we have processed the playlist. Compared to the original implementation, this will save the requests of reloading non-primary playlist after we have taken action upon the preload chunk being published or removed.

Issue: androidx/media#1240
PiperOrigin-RevId: 626038032
2024-04-18 08:11:19 -07:00
bachinger
5a84e09a0e Use zero offset when delegating EMSG sample data
When delegating EMSG samples in `HlsSampleStreamWrapper`,
the offset passed into `sampleMetadata(..)` of the delegate
`TrackOutput` must be zero because it is called immediately
after `sampleData(..)` is called.

The condition to trigger this issue is that more than one
metadata samples are pending in `pendingMetadataSampleInfos`
of `FragmentedMp4Extractor` which produces non-zero offsets.

Issue: androidx/media#1002
Issue: androidx/media#1203
PiperOrigin-RevId: 623210835
2024-04-09 10:32:35 -07:00
tonihei
73c0ebb214 Additional clean-up and formatting 2024-03-25 15:02:31 +00:00
Juan Carlos Penalver
e9e47f4fe6 Removing id from Label and ensuring label/labels consistency in Format.Builder. 2024-03-25 12:00:14 +00:00
Juan Carlos Penalver
63fb68e99e Reverting breaking changes by keeping label and adding labels. 2024-03-25 12:00:14 +00:00
Juan Carlos Penalver
df763220c8 Replacing label with a list of Label elements in Format. 2024-03-25 12:00:14 +00:00
ibaker
3a7a665d5d Rollback of 406c0a15be
PiperOrigin-RevId: 605015994
2024-02-07 09:56:59 -08:00
ibaker
7ebfed505c Stop double-encoding CMCD query parameters
`Uri.appendQueryParameter` is documented to encode its arguments, so
calling `Uri.encode` beforehand results in double-encoding.

Issue: androidx/media#1075

#minor-release

PiperOrigin-RevId: 604995441
2024-02-07 08:44:33 -08:00
bachinger
138532e3fd Fix the regex used for validating custom CMCD key names
Relax the regex to only check for hyphen which is required by the specification.

Issue: androidx/media#1028
#minor-release
PiperOrigin-RevId: 604719300
2024-02-06 11:59:20 -08:00
tonihei
e3e57c9b99 Fix HlsPlaybackTest flakiness
The new test introduced in 45bd5c6f0a is flaky because we only
wait until the media is fully buffered. However, we can't fully
control how much of this data is initially read by the Robolectric
codec and thus the output dump files (containing these codec
interactions) are flaky.

This can be fixed by fully playing the media once and then seeking
back instead.

#minor-release

PiperOrigin-RevId: 603324068
2024-02-01 03:58:37 -08:00
tonihei
b768ac791a Add e2e test for seeking to beginning of chunk 2024-01-31 11:53:55 +00:00
Gareth Fenn
173dbc87a2 Seek at a chunk level when seeking to chunk start positions
This avoids issues that can arise due to the slight discrepancies between
chunk start times (obtained from the manifest of segment index) and
the timestamps of the samples contained within those chunks.
2024-01-30 09:24:08 +00:00
tonihei
ed5b7004b4 Replace or suppress deprecated usages
Many usages are needed to support other deprecations and some
can be replaced by the recommended direct alternative.

Also replace links to deprecated/redirected dev site

PiperOrigin-RevId: 601795998
2024-01-26 10:06:18 -08:00
jbibik
f103a2dcf5 Add a setter of SubtitleParser.Factory to MediaSource.Factory
DASH: `DashMediaSource.Factory` would only propagate it to `DashChunkSource.Factory` -> `BundledChunkExtractor.Factory`

SS: `SSMediaSource.Factory` -> `SsChunkSource.Factory`

HLS: `HlsMediaSource.Factory` -> `HlsExtractorFactory`

Remove nullability of SubtitleParser.Factory across the stack

#minor-release

PiperOrigin-RevId: 601250013
2024-01-24 15:19:50 -08:00
jbibik
4d7b23f0d1 Add setters of SubtitleParser.Factory and experimental toggle
The `SubtitleParser.Factory` is no longer @Nullable and the experimenting toggle is used to enable/disable the use of this factory for subtitle parsing during extraction.

The three places that will hold the "truth" for the `SubtitleParser.Factory` are: BundledChunkExtractor.Factory, SsChunkSource.Factory, DefaultHlsExtractorFactory

DASH: `DashMediaSource.Factory` would only propagate it to `DashChunkSource.Factory` -> `BundledChunkExtractor.Factory`

SS: `SSMediaSource.Factory` -> `SsChunkSource.Factory`

HLS: `HlsMediaSource.Factory` -> `HlsExtractorFactory`

#minor-release

PiperOrigin-RevId: 601151615
2024-01-24 09:55:49 -08:00
jbibik
966b710897 Remove SubtitleParser.Factory references from Hls/Ss/DashMediaPeriod
Those classes only needed to have access to a `SubtitleParser.Factory` to get a potentially updated `Format` for TrackGroups. The `SubtitleParser.Factory` was only used to check the support for the `mimeType` and getting some cue-related behaviour.

This introduced complexity in a way that both Periods and Extractors needed to have the same `SubtitleParser.Factory` in their individual stacks. To ensure that the sample queue would get the same transcoded/original format.

Instead, now we expose `getOutputTextFormat` methods on `ChunkExtractor.Factory`, `SsChunkSource.Factory` and `HlsExtractorFactory`. Those are the dependencies that Hls/Ss/DashMediaPeriod can make use of to delegate the format-updating logic to.

#minor-release

PiperOrigin-RevId: 601130714
2024-01-24 08:40:39 -08:00
ibaker
34a08e13fc Rollback of 406c0a15be
PiperOrigin-RevId: 599546140
2024-01-18 10:21:53 -08:00
ibaker
406c0a15be CompositeSequenceableLoader: Prefer buffered position of A/V tracks
Preferring audio and video tracks matches logic we already have in
[`ProgressiveMediaPeriod.getBufferedPositionUs`](f6fe90f30b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/ProgressiveMediaPeriod.java (L403)).

PiperOrigin-RevId: 599154217
2024-01-17 06:33:14 -08:00
jbibik
59afb4fb01 Plumb SubtitleParser.Factory into WebvttExtractor
WebvttExtractor will no longer be wrapped in SubtitleTranscodingExtractor, but instead use SubtitleTranscodingExtractorOutput under the hood.

A new constructor will take a boolean parameter to toggle between subtitle parsing during extraction (before the sample queue) or during decoding (after the sample queue).

PiperOrigin-RevId: 597604942
2024-01-11 11:13:08 -08:00
jbibik
a728ec8e67 Plumb SubtitleParser.Factory into TsExtractor
PiperOrigin-RevId: 597578122
2024-01-11 09:35:22 -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
ibaker
770ca66fbc Fix HLS CEA-608 when parsing during extraction
HLS distinguishes between 'subtitles' (WebVTT or TTML distributed in
separate files with their own playlist) and 'captions' (CEA-608 or 708,
distributed muxed into the video file).

The format transformation added in 7b762642db
only applies to subtitles and not captions. This change makes the same
transformation for caption formats.

This resolves an error like:

```
SampleQueueMappingException: Unable to bind a sample queue to TrackGroup with MIME type application/cea-608.
```

Also add two playback tests for HLS CEA-608, one that parses during
decoding (old way) and one during extraction (new way). Adding these
tests is what alerted me to this issue.

PiperOrigin-RevId: 592571284
2023-12-20 08:52:39 -08:00
rohks
7f6596bab2 Fix sending negative bufferedDurationUs to CmcdData.Factory
When track is changed during playback, `playbackPositionUs` may be in middle of a chunk and `loadPositionUs` should be the start of that chunk. In this situation `loadPositionUs` can be less than the current `playbackPositionUs`, resulting into negative `bufferedDurationUs`. It translates to having no buffer and hence we should send `0` for `bufferedDurationUs` when creating new instances of `CmcdData.Factory`.

Issue: androidx/media#888

#minor-release

PiperOrigin-RevId: 591099785
2023-12-14 17:39:41 -08:00
jbibik
03564fdbc6 Promote method to control subtitle parsing to MediaSource.Factory
PiperOrigin-RevId: 586361222
2023-11-29 09:12:04 -08:00
tonihei
5eb6a889a7 Adjust Javadoc
PiperOrigin-RevId: 583965332
2023-11-20 02:54:57 -08:00
jbibik
b750ad50f9 Add subtitle parsing support in HLS for TS files
PiperOrigin-RevId: 582714493
2023-11-15 10:00:03 -08:00
jbibik
b23b1bb693 Add HLS support for parsing TTML subs muxed into MP4 during extraction
This removes the flakiness of the HLS playback test as well.

Previously, this flow only worked for standalone WebVTT subtitles (7b762642db)

PiperOrigin-RevId: 582359383
2023-11-14 10:10:44 -08:00
jbibik
67f770a786 Add HLS playback test with TTML subtitles muxed into MP4
The test is hidden behind the `@Ignore` annotation due to some
flakiness. However, it will be removed when the subtitle parsing is
moved to a pre-sample-queue architecture.

The test media was created with:

```shell
$ cp ../../dash/standalone-ttml/sample.xml sample.ttml
$ MP4Box -add sample.ttml sample.text.mp4
$ MP4Box -frag 10000 sample.text.mp4
$ rm sample.ttml
```

PiperOrigin-RevId: 582347113
2023-11-14 09:31:09 -08:00
tonihei
b570c72588 Normalize MIME types when accepting user or media input
MIME types are case-insensitive, but none of the many existing
comparisons across our code base take this into account. The
code can be made more robust by normalizing all MIME types at the
moment they are first set into a class/builder and adding toLowerCase
as part of the normalization.

Most concretely, this fixes an issue with playing HLS streams via
the IMA SDK where the stream MIME type is indicated with all lower
case "application/x-mpegurl", which failed the MIME type comparison
in DefaultMediaSourceFactory.

PiperOrigin-RevId: 582317261
2023-11-14 07:40:15 -08:00
jbibik
089910546f Fix the asset and dump file names for the standalone Webvtt-HLS test
PiperOrigin-RevId: 580125493
2023-11-07 04:02:34 -08:00
jbibik
7b762642db Add experimental opt-in to parse HLS subtitles during extraction
PiperOrigin-RevId: 578524318
2023-11-01 08:25:37 -07:00
ibaker
841cdf170b Reduce HlsMediaPeriod to package-private visibility
This type shouldn't be directly depended on from outside the HLS
package.

PiperOrigin-RevId: 577833188
2023-10-30 07:17:52 -07:00
jbibik
1359b0147d Add an HLS End-to-End test with WebVtt sidecar subtitles
These subtitles are parsed using the old-flow, i.e. after decoding.

PiperOrigin-RevId: 577452579
2023-10-28 06:15:24 -07:00
tianyifeng
58a63c82aa Calculate HLS live playlist refresh interval accurately
Previously, we calculated the next playlist reload time by adding the target duration (or half of it, depending on whether there is a real update in the new playlist snapshot) from the last load completion time, which makes the reload interval as long as `targetDuration(or half of it) + lastLoadDuration`. While still complying to the standard that "the client MUST wait for at least the target duration before attempting to reload the Playlist file again", this could cause buffering when the playback position is close to the end of live window. This change is to calculate the reload interval accurately by not adding the term `lastLoadDuration`.

Issue: androidx/media#663

#minor-release

PiperOrigin-RevId: 573300009
2023-10-13 13:06:46 -07:00
rohks
206a663dca Add functionality to transmit CMCD data using query parameters
Currently, we only support sending Common Media Client Data (CMCD) data through custom HTTP request headers, added capability to configure and transmit it as HTTP query parameters.

PiperOrigin-RevId: 561591246
2023-08-31 02:11:12 -07:00
rohks
e0d3cad8bb Add fields next object request (nor) and next range request (nrr)
Added this CMCD-Request fields to Common Media Client Data (CMCD) logging.

PiperOrigin-RevId: 558317146
2023-08-22 15:25:03 +01:00
rohks
b6b16b2895 Sort Common Media Client Data keys to reduce fingerprinting surface
Based on the Common Media Client Data (CMCD) specification key-value pairs should be sequenced in alphabetical order of the key name in order to reduce the fingerprinting surface exposed by the player.

PiperOrigin-RevId: 558296264
2023-08-22 15:23:33 +01:00
rohks
afb8d6c9e2 Make custom data adhere to Common Media Client Data(CMCD) specification
Added more comprehensive Javadoc around setting custom data and verification on key format.

Changed adding custom data as a `String` to `List<String>`. This would enable us to sort all keys to reduce the fingerprinting surface.

PiperOrigin-RevId: 558291240
2023-08-22 15:22:08 +01:00
rohks
4282a6ecd7 Add buffer starvation(bs), deadline(dl), playback rate(pr), startup(su)
Enhanced the Common Media Client Data (CMCD) logging by incorporating additional fields:
* buffer starvation (bs) : CMCD-Status
* deadline (dl) and startup (su) : CMCD-Request
* playback rate (pr) : CMCD-Session

PiperOrigin-RevId: 555553357
2023-08-11 20:23:23 +00:00