Skip to content

Commit d628ada

Browse files
committed
Refactor DTS audio mime type checks and fix effectively private warnings
1 parent 5625cbd commit d628ada

3 files changed

Lines changed: 33 additions & 30 deletions

File tree

libraries/extractor/src/main/java/androidx/media3/extractor/DtsUtil.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,15 @@ private DtsHeader(
244244
/** Header size length table for DTS UHD. See ETSI TS 103 491 V1.2.1 (2019-05), Section 6.4.3. */
245245
private static final int[] UHD_HEADER_SIZE_LENGTH_TABLE = new int[] {5, 8, 10, 12};
246246

247+
/**
248+
* Returns whether {@code mimeType} is {@link MimeTypes#AUDIO_DTS} or {@link
249+
* MimeTypes#AUDIO_DTS_HD}.
250+
*/
251+
public static boolean isDtsBaseAudioMimeType(@Nullable String mimeType) {
252+
return Objects.equals(mimeType, MimeTypes.AUDIO_DTS)
253+
|| Objects.equals(mimeType, MimeTypes.AUDIO_DTS_HD);
254+
}
255+
247256
/**
248257
* Returns the {@link FrameType} if {@code word} is a DTS sync word, otherwise {@link
249258
* #FRAME_TYPE_UNKNOWN}.

libraries/extractor/src/main/java/androidx/media3/extractor/mp4/FragmentedMp4Extractor.java

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1852,18 +1852,13 @@ private boolean readSample(ExtractorInput input) throws IOException {
18521852
}
18531853
}
18541854
} else {
1855-
if (trackBundle.pendingFormat != null
1856-
&& (Objects.equals(track.format.sampleMimeType, MimeTypes.AUDIO_DTS)
1857-
|| Objects.equals(track.format.sampleMimeType, MimeTypes.AUDIO_DTS_HD))) {
1855+
Format pendingFormat = trackBundle.pendingFormat;
1856+
if (pendingFormat != null && DtsUtil.isDtsBaseAudioMimeType(track.format.sampleMimeType)) {
18581857
trackBundle.baseFormat =
18591858
DtsUtil.updateFormatWithDtsHdInfo(input, sampleSize, trackBundle.baseFormat);
1860-
Format pendingFormat =
1861-
trackBundle
1862-
.baseFormat
1863-
.buildUpon()
1864-
.setDrmInitData(trackBundle.pendingFormat.drmInitData)
1865-
.build();
1866-
trackBundle.output.format(pendingFormat);
1859+
Format outputFormat =
1860+
trackBundle.baseFormat.buildUpon().setDrmInitData(pendingFormat.drmInitData).build();
1861+
trackBundle.output.format(outputFormat);
18671862
trackBundle.pendingFormat = null;
18681863
}
18691864
while (sampleBytesWritten < sampleSize) {
@@ -2317,15 +2312,16 @@ private static final class TrackBundle {
23172312
public int currentTrackRunIndex;
23182313
public int firstSampleToOutputIndex;
23192314

2315+
private final ParsableByteArray encryptionSignalByte;
2316+
private final ParsableByteArray defaultInitializationVector;
2317+
23202318
/**
23212319
* A {@link Format} that needs to be passed to {@link #output}, after being possibly modified
23222320
* based on sample data, before {@link TrackOutput#sampleMetadata} is called.
23232321
*/
2324-
@Nullable public Format pendingFormat;
2322+
@Nullable private Format pendingFormat;
23252323

23262324
private Format baseFormat;
2327-
private final ParsableByteArray encryptionSignalByte;
2328-
private final ParsableByteArray defaultInitializationVector;
23292325

23302326
private boolean currentlyInFragment;
23312327

@@ -2342,8 +2338,7 @@ public TrackBundle(
23422338
scratch = new ParsableByteArray();
23432339
encryptionSignalByte = new ParsableByteArray(1);
23442340
defaultInitializationVector = new ParsableByteArray();
2345-
if (Objects.equals(baseFormat.sampleMimeType, MimeTypes.AUDIO_DTS)
2346-
|| Objects.equals(baseFormat.sampleMimeType, MimeTypes.AUDIO_DTS_HD)) {
2341+
if (DtsUtil.isDtsBaseAudioMimeType(baseFormat.sampleMimeType)) {
23472342
pendingFormat = baseFormat;
23482343
}
23492344
reset(moovSampleTable, defaultSampleValues);

libraries/extractor/src/main/java/androidx/media3/extractor/mp4/Mp4Extractor.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -749,10 +749,9 @@ private void processMoovAtom(ContainerBox moov) throws ParserException {
749749
// DTS-HD and DTS Express. So we store the format with a placeholder MIME for now, and then
750750
// update the MIME type and pass it to TrackOutput.format(...) based on the info in the first
751751
// sample.
752-
boolean needSamplesForMime =
752+
boolean needsSamplesForMimeType =
753753
Objects.equals(track.format.sampleMimeType, MimeTypes.AUDIO_MPEG)
754-
|| Objects.equals(track.format.sampleMimeType, MimeTypes.AUDIO_DTS)
755-
|| Objects.equals(track.format.sampleMimeType, MimeTypes.AUDIO_DTS_HD);
754+
|| DtsUtil.isDtsBaseAudioMimeType(track.format.sampleMimeType);
756755
boolean needsChapterMetadata = false;
757756
if (!omitTrackSampleTable && track.chapterTrackId != C.INDEX_UNSET) {
758757
for (TrackSampleTable chapterSampleTable : chapterSampleTables) {
@@ -762,7 +761,7 @@ private void processMoovAtom(ContainerBox moov) throws ParserException {
762761
}
763762
}
764763
}
765-
if (needSamplesForMime || needsChapterMetadata) {
764+
if (needsSamplesForMimeType || needsChapterMetadata) {
766765
mp4Track.pendingFormat = format;
767766
} else {
768767
mp4Track.trackOutput.format(format);
@@ -1018,15 +1017,16 @@ private int readSample(ExtractorInput input, PositionHolder positionHolder) thro
10181017
.build()
10191018
: pendingFormat);
10201019
track.pendingFormat = null;
1021-
} else if (track.pendingFormat != null
1022-
&& (Objects.equals(track.track.format.sampleMimeType, MimeTypes.AUDIO_DTS)
1023-
|| Objects.equals(track.track.format.sampleMimeType, MimeTypes.AUDIO_DTS_HD))) {
1020+
} else {
10241021
Format pendingFormat = track.pendingFormat;
1025-
track.trackOutput.format(
1026-
DtsUtil.updateFormatWithDtsHdInfo(input, sampleSize, pendingFormat));
1027-
track.pendingFormat = null;
1028-
} else if (trueHdSampleRechunker != null) {
1029-
trueHdSampleRechunker.startSample(input);
1022+
if (pendingFormat != null
1023+
&& DtsUtil.isDtsBaseAudioMimeType(track.track.format.sampleMimeType)) {
1024+
track.trackOutput.format(
1025+
DtsUtil.updateFormatWithDtsHdInfo(input, sampleSize, pendingFormat));
1026+
track.pendingFormat = null;
1027+
} else if (trueHdSampleRechunker != null) {
1028+
trueHdSampleRechunker.startSample(input);
1029+
}
10301030
}
10311031

10321032
while (sampleBytesWritten < sampleSize) {
@@ -1119,8 +1119,7 @@ private int readQuickTimeChapters(ExtractorInput input, PositionHolder seekPosit
11191119
// determine the exact MIME type). We have now applied the chapter metadata, so we can
11201120
// output the format, unless it is also MPEG or DTS audio.
11211121
if (Objects.equals(updatedFormat.sampleMimeType, MimeTypes.AUDIO_MPEG)
1122-
|| Objects.equals(updatedFormat.sampleMimeType, MimeTypes.AUDIO_DTS)
1123-
|| Objects.equals(updatedFormat.sampleMimeType, MimeTypes.AUDIO_DTS_HD)) {
1122+
|| DtsUtil.isDtsBaseAudioMimeType(updatedFormat.sampleMimeType)) {
11241123
track.pendingFormat = updatedFormat;
11251124
} else {
11261125
track.trackOutput.format(updatedFormat);
@@ -1384,7 +1383,7 @@ private static final class Mp4Track {
13841383
* A {@link Format} that needs to be passed to {@link #trackOutput}, after being possibly
13851384
* modified based on sample data, before {@link TrackOutput#sampleMetadata} is called.
13861385
*/
1387-
@Nullable public Format pendingFormat;
1386+
@Nullable private Format pendingFormat;
13881387

13891388
public Mp4Track(Track track, TrackSampleTable sampleTable, TrackOutput trackOutput) {
13901389
this.track = track;

0 commit comments

Comments
 (0)