Commit 7aeeb8dd by krocard Committed by Ian Baker

Minor refactor in Matroska extractor

#exofixit

PiperOrigin-RevId: 346975740
parent 297c2bf9
...@@ -720,11 +720,13 @@ public class MatroskaExtractor implements Extractor { ...@@ -720,11 +720,13 @@ public class MatroskaExtractor implements Extractor {
break; break;
case ID_CUES: case ID_CUES:
if (!sentSeekMap) { if (!sentSeekMap) {
extractorOutput.seekMap(buildSeekMap()); extractorOutput.seekMap(buildSeekMap(cueTimesUs, cueClusterPositions));
sentSeekMap = true; sentSeekMap = true;
} else { } else {
// We have already built the cues. Ignore. // We have already built the cues. Ignore.
} }
this.cueTimesUs = null;
this.cueClusterPositions = null;
break; break;
case ID_BLOCK_GROUP: case ID_BLOCK_GROUP:
if (blockState != BLOCK_STATE_DATA) { if (blockState != BLOCK_STATE_DATA) {
...@@ -769,20 +771,16 @@ public class MatroskaExtractor implements Extractor { ...@@ -769,20 +771,16 @@ public class MatroskaExtractor implements Extractor {
} }
break; break;
case ID_TRACK_ENTRY: case ID_TRACK_ENTRY:
if (currentTrack == null) { Track currentTrack = checkStateNotNull(this.currentTrack);
throw new ParserException("TrackEntry ends without matching start"); if (currentTrack.codecId == null) {
throw new ParserException("CodecId is missing in TrackEntry element");
} else { } else {
Track currentTrack = this.currentTrack; if (isCodecSupported(currentTrack.codecId)) {
if (currentTrack.codecId == null) { currentTrack.initializeOutput(extractorOutput, currentTrack.number);
throw new ParserException("CodecId is missing in TrackEntry element"); tracks.put(currentTrack.number, currentTrack);
} else {
if (isCodecSupported(currentTrack.codecId)) {
currentTrack.initializeOutput(extractorOutput, currentTrack.number);
tracks.put(currentTrack.number, currentTrack);
}
} }
} }
currentTrack = null; this.currentTrack = null;
break; break;
case ID_TRACKS: case ID_TRACKS:
if (tracks.size() == 0) { if (tracks.size() == 0) {
...@@ -1735,15 +1733,12 @@ public class MatroskaExtractor implements Extractor { ...@@ -1735,15 +1733,12 @@ public class MatroskaExtractor implements Extractor {
* @return The built {@link SeekMap}. The returned {@link SeekMap} may be unseekable if cues * @return The built {@link SeekMap}. The returned {@link SeekMap} may be unseekable if cues
* information was missing or incomplete. * information was missing or incomplete.
*/ */
private SeekMap buildSeekMap() { private SeekMap buildSeekMap(
LongArray cueTimesUs = this.cueTimesUs; @Nullable LongArray cueTimesUs, @Nullable LongArray cueClusterPositions) {
LongArray cueClusterPositions = this.cueClusterPositions;
if (segmentContentPosition == C.POSITION_UNSET || durationUs == C.TIME_UNSET if (segmentContentPosition == C.POSITION_UNSET || durationUs == C.TIME_UNSET
|| cueTimesUs == null || cueTimesUs.size() == 0 || cueTimesUs == null || cueTimesUs.size() == 0
|| cueClusterPositions == null || cueClusterPositions.size() != cueTimesUs.size()) { || cueClusterPositions == null || cueClusterPositions.size() != cueTimesUs.size()) {
// Cues information is missing or incomplete. // Cues information is missing or incomplete.
this.cueTimesUs = null;
this.cueClusterPositions = null;
return new SeekMap.Unseekable(durationUs); return new SeekMap.Unseekable(durationUs);
} }
int cuePointsSize = cueTimesUs.size(); int cuePointsSize = cueTimesUs.size();
...@@ -1772,8 +1767,6 @@ public class MatroskaExtractor implements Extractor { ...@@ -1772,8 +1767,6 @@ public class MatroskaExtractor implements Extractor {
timesUs = Arrays.copyOf(timesUs, timesUs.length - 1); timesUs = Arrays.copyOf(timesUs, timesUs.length - 1);
} }
this.cueTimesUs = null;
this.cueClusterPositions = null;
return new ChunkIndex(sizes, offsets, durationsUs, timesUs); return new ChunkIndex(sizes, offsets, durationsUs, timesUs);
} }
...@@ -2231,10 +2224,11 @@ public class MatroskaExtractor implements Extractor { ...@@ -2231,10 +2224,11 @@ public class MatroskaExtractor implements Extractor {
break; break;
case CODEC_ID_ASS: case CODEC_ID_ASS:
mimeType = MimeTypes.TEXT_SSA; mimeType = MimeTypes.TEXT_SSA;
initializationData = ImmutableList.of(SSA_DIALOGUE_FORMAT, getCodecPrivate(codecId));
break; break;
case CODEC_ID_VOBSUB: case CODEC_ID_VOBSUB:
mimeType = MimeTypes.APPLICATION_VOBSUB; mimeType = MimeTypes.APPLICATION_VOBSUB;
initializationData = Collections.singletonList(getCodecPrivate(codecId)); initializationData = ImmutableList.of(getCodecPrivate(codecId));
break; break;
case CODEC_ID_PGS: case CODEC_ID_PGS:
mimeType = MimeTypes.APPLICATION_PGS; mimeType = MimeTypes.APPLICATION_PGS;
...@@ -2317,12 +2311,9 @@ public class MatroskaExtractor implements Extractor { ...@@ -2317,12 +2311,9 @@ public class MatroskaExtractor implements Extractor {
.setProjectionData(projectionData) .setProjectionData(projectionData)
.setStereoMode(stereoMode) .setStereoMode(stereoMode)
.setColorInfo(colorInfo); .setColorInfo(colorInfo);
} else if (MimeTypes.APPLICATION_SUBRIP.equals(mimeType)) { } else if (MimeTypes.APPLICATION_SUBRIP.equals(mimeType)
type = C.TRACK_TYPE_TEXT; || MimeTypes.TEXT_SSA.equals(mimeType)
} else if (MimeTypes.TEXT_SSA.equals(mimeType)) { || MimeTypes.APPLICATION_VOBSUB.equals(mimeType)
type = C.TRACK_TYPE_TEXT;
initializationData = ImmutableList.of(SSA_DIALOGUE_FORMAT, getCodecPrivate(codecId));
} else if (MimeTypes.APPLICATION_VOBSUB.equals(mimeType)
|| MimeTypes.APPLICATION_PGS.equals(mimeType) || MimeTypes.APPLICATION_PGS.equals(mimeType)
|| MimeTypes.APPLICATION_DVBSUBS.equals(mimeType)) { || MimeTypes.APPLICATION_DVBSUBS.equals(mimeType)) {
type = C.TRACK_TYPE_TEXT; type = C.TRACK_TYPE_TEXT;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment