mirror of
https://github.com/androidx/media.git
synced 2025-05-07 23:50:44 +08:00
MatroskaExtractor naming cleanup
- Change sampleHasReferenceBlock to a block reading variable, which is what it is (the distinction didn't matter previously, but will do so when we add lacing support in full blocks because there wont be a 1:1 relationship any more. - Move sampleRead to be a reading state variable. - Stop abbreviating "additional" Issue: #3026 PiperOrigin-RevId: 284000937
This commit is contained in:
parent
bf495de529
commit
dd60bac07d
@ -224,7 +224,7 @@ public class MatroskaExtractor implements Extractor {
|
|||||||
* BlockAddID value for ITU T.35 metadata in a VP9 track. See also
|
* BlockAddID value for ITU T.35 metadata in a VP9 track. See also
|
||||||
* https://www.webmproject.org/docs/container/.
|
* https://www.webmproject.org/docs/container/.
|
||||||
*/
|
*/
|
||||||
private static final int BLOCK_ADD_ID_VP9_ITU_T_35 = 4;
|
private static final int BLOCK_ADDITIONAL_ID_VP9_ITU_T_35 = 4;
|
||||||
|
|
||||||
private static final int LACING_NONE = 0;
|
private static final int LACING_NONE = 0;
|
||||||
private static final int LACING_XIPH = 1;
|
private static final int LACING_XIPH = 1;
|
||||||
@ -332,7 +332,7 @@ public class MatroskaExtractor implements Extractor {
|
|||||||
private final ParsableByteArray subtitleSample;
|
private final ParsableByteArray subtitleSample;
|
||||||
private final ParsableByteArray encryptionInitializationVector;
|
private final ParsableByteArray encryptionInitializationVector;
|
||||||
private final ParsableByteArray encryptionSubsampleData;
|
private final ParsableByteArray encryptionSubsampleData;
|
||||||
private final ParsableByteArray blockAddData;
|
private final ParsableByteArray blockAdditionalData;
|
||||||
private ByteBuffer encryptionSubsampleDataBuffer;
|
private ByteBuffer encryptionSubsampleDataBuffer;
|
||||||
|
|
||||||
private long segmentContentSize;
|
private long segmentContentSize;
|
||||||
@ -360,6 +360,9 @@ public class MatroskaExtractor implements Extractor {
|
|||||||
private LongArray cueClusterPositions;
|
private LongArray cueClusterPositions;
|
||||||
private boolean seenClusterPositionForCurrentCuePoint;
|
private boolean seenClusterPositionForCurrentCuePoint;
|
||||||
|
|
||||||
|
// Reading state.
|
||||||
|
private boolean haveOutputSample;
|
||||||
|
|
||||||
// Block reading state.
|
// Block reading state.
|
||||||
private int blockState;
|
private int blockState;
|
||||||
private long blockTimeUs;
|
private long blockTimeUs;
|
||||||
@ -371,20 +374,19 @@ public class MatroskaExtractor implements Extractor {
|
|||||||
private int blockTrackNumberLength;
|
private int blockTrackNumberLength;
|
||||||
@C.BufferFlags
|
@C.BufferFlags
|
||||||
private int blockFlags;
|
private int blockFlags;
|
||||||
private int blockAddId;
|
private int blockAdditionalId;
|
||||||
|
private boolean blockHasReferenceBlock;
|
||||||
|
|
||||||
// Sample reading state.
|
// Sample reading state.
|
||||||
private int sampleBytesRead;
|
private int sampleBytesRead;
|
||||||
|
private int sampleBytesWritten;
|
||||||
|
private int sampleCurrentNalBytesRemaining;
|
||||||
private boolean sampleEncodingHandled;
|
private boolean sampleEncodingHandled;
|
||||||
private boolean sampleSignalByteRead;
|
private boolean sampleSignalByteRead;
|
||||||
private boolean sampleInitializationVectorRead;
|
|
||||||
private boolean samplePartitionCountRead;
|
private boolean samplePartitionCountRead;
|
||||||
private byte sampleSignalByte;
|
|
||||||
private int samplePartitionCount;
|
private int samplePartitionCount;
|
||||||
private int sampleCurrentNalBytesRemaining;
|
private byte sampleSignalByte;
|
||||||
private int sampleBytesWritten;
|
private boolean sampleInitializationVectorRead;
|
||||||
private boolean sampleRead;
|
|
||||||
private boolean sampleSeenReferenceBlock;
|
|
||||||
|
|
||||||
// Extractor outputs.
|
// Extractor outputs.
|
||||||
private ExtractorOutput extractorOutput;
|
private ExtractorOutput extractorOutput;
|
||||||
@ -412,7 +414,7 @@ public class MatroskaExtractor implements Extractor {
|
|||||||
subtitleSample = new ParsableByteArray();
|
subtitleSample = new ParsableByteArray();
|
||||||
encryptionInitializationVector = new ParsableByteArray(ENCRYPTION_IV_SIZE);
|
encryptionInitializationVector = new ParsableByteArray(ENCRYPTION_IV_SIZE);
|
||||||
encryptionSubsampleData = new ParsableByteArray();
|
encryptionSubsampleData = new ParsableByteArray();
|
||||||
blockAddData = new ParsableByteArray();
|
blockAdditionalData = new ParsableByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -446,9 +448,9 @@ public class MatroskaExtractor implements Extractor {
|
|||||||
@Override
|
@Override
|
||||||
public final int read(ExtractorInput input, PositionHolder seekPosition)
|
public final int read(ExtractorInput input, PositionHolder seekPosition)
|
||||||
throws IOException, InterruptedException {
|
throws IOException, InterruptedException {
|
||||||
sampleRead = false;
|
haveOutputSample = false;
|
||||||
boolean continueReading = true;
|
boolean continueReading = true;
|
||||||
while (continueReading && !sampleRead) {
|
while (continueReading && !haveOutputSample) {
|
||||||
continueReading = reader.read(input);
|
continueReading = reader.read(input);
|
||||||
if (continueReading && maybeSeekForCues(seekPosition, input.getPosition())) {
|
if (continueReading && maybeSeekForCues(seekPosition, input.getPosition())) {
|
||||||
return Extractor.RESULT_SEEK;
|
return Extractor.RESULT_SEEK;
|
||||||
@ -623,7 +625,7 @@ public class MatroskaExtractor implements Extractor {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ID_BLOCK_GROUP:
|
case ID_BLOCK_GROUP:
|
||||||
sampleSeenReferenceBlock = false;
|
blockHasReferenceBlock = false;
|
||||||
break;
|
break;
|
||||||
case ID_CONTENT_ENCODING:
|
case ID_CONTENT_ENCODING:
|
||||||
// TODO: check and fail if more than one content encoding is present.
|
// TODO: check and fail if more than one content encoding is present.
|
||||||
@ -681,7 +683,7 @@ public class MatroskaExtractor implements Extractor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// If the ReferenceBlock element was not found for this sample, then it is a keyframe.
|
// If the ReferenceBlock element was not found for this sample, then it is a keyframe.
|
||||||
if (!sampleSeenReferenceBlock) {
|
if (!blockHasReferenceBlock) {
|
||||||
blockFlags |= C.BUFFER_FLAG_KEY_FRAME;
|
blockFlags |= C.BUFFER_FLAG_KEY_FRAME;
|
||||||
}
|
}
|
||||||
commitSampleToOutput(tracks.get(blockTrackNumber), blockTimeUs);
|
commitSampleToOutput(tracks.get(blockTrackNumber), blockTimeUs);
|
||||||
@ -793,7 +795,7 @@ public class MatroskaExtractor implements Extractor {
|
|||||||
currentTrack.audioBitDepth = (int) value;
|
currentTrack.audioBitDepth = (int) value;
|
||||||
break;
|
break;
|
||||||
case ID_REFERENCE_BLOCK:
|
case ID_REFERENCE_BLOCK:
|
||||||
sampleSeenReferenceBlock = true;
|
blockHasReferenceBlock = true;
|
||||||
break;
|
break;
|
||||||
case ID_CONTENT_ENCODING_ORDER:
|
case ID_CONTENT_ENCODING_ORDER:
|
||||||
// This extractor only supports one ContentEncoding element and hence the order has to be 0.
|
// This extractor only supports one ContentEncoding element and hence the order has to be 0.
|
||||||
@ -935,7 +937,7 @@ public class MatroskaExtractor implements Extractor {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ID_BLOCK_ADD_ID:
|
case ID_BLOCK_ADD_ID:
|
||||||
blockAddId = (int) value;
|
blockAdditionalId = (int) value;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -1199,7 +1201,8 @@ public class MatroskaExtractor implements Extractor {
|
|||||||
if (blockState != BLOCK_STATE_DATA) {
|
if (blockState != BLOCK_STATE_DATA) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
handleBlockAdditionalData(tracks.get(blockTrackNumber), blockAddId, input, contentSize);
|
handleBlockAdditionalData(
|
||||||
|
tracks.get(blockTrackNumber), blockAdditionalId, input, contentSize);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new ParserException("Unexpected id: " + id);
|
throw new ParserException("Unexpected id: " + id);
|
||||||
@ -1207,11 +1210,12 @@ public class MatroskaExtractor implements Extractor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void handleBlockAdditionalData(
|
protected void handleBlockAdditionalData(
|
||||||
Track track, int blockAddId, ExtractorInput input, int contentSize)
|
Track track, int blockAdditionalId, ExtractorInput input, int contentSize)
|
||||||
throws IOException, InterruptedException {
|
throws IOException, InterruptedException {
|
||||||
if (blockAddId == BLOCK_ADD_ID_VP9_ITU_T_35 && CODEC_ID_VP9.equals(track.codecId)) {
|
if (blockAdditionalId == BLOCK_ADDITIONAL_ID_VP9_ITU_T_35
|
||||||
blockAddData.reset(contentSize);
|
&& CODEC_ID_VP9.equals(track.codecId)) {
|
||||||
input.readFully(blockAddData.data, 0, contentSize);
|
blockAdditionalData.reset(contentSize);
|
||||||
|
input.readFully(blockAdditionalData.data, 0, contentSize);
|
||||||
} else {
|
} else {
|
||||||
// Unhandled block additional data.
|
// Unhandled block additional data.
|
||||||
input.skipFully(contentSize);
|
input.skipFully(contentSize);
|
||||||
@ -1236,13 +1240,13 @@ public class MatroskaExtractor implements Extractor {
|
|||||||
|
|
||||||
if ((blockFlags & C.BUFFER_FLAG_HAS_SUPPLEMENTAL_DATA) != 0) {
|
if ((blockFlags & C.BUFFER_FLAG_HAS_SUPPLEMENTAL_DATA) != 0) {
|
||||||
// Append supplemental data.
|
// Append supplemental data.
|
||||||
int size = blockAddData.limit();
|
int blockAdditionalSize = blockAdditionalData.limit();
|
||||||
track.output.sampleData(blockAddData, size);
|
track.output.sampleData(blockAdditionalData, blockAdditionalSize);
|
||||||
sampleBytesWritten += size;
|
sampleBytesWritten += blockAdditionalSize;
|
||||||
}
|
}
|
||||||
track.output.sampleMetadata(timeUs, blockFlags, sampleBytesWritten, 0, track.cryptoData);
|
track.output.sampleMetadata(timeUs, blockFlags, sampleBytesWritten, 0, track.cryptoData);
|
||||||
}
|
}
|
||||||
sampleRead = true;
|
haveOutputSample = true;
|
||||||
resetSample();
|
resetSample();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1375,7 +1379,7 @@ public class MatroskaExtractor implements Extractor {
|
|||||||
|
|
||||||
if (track.maxBlockAdditionId > 0) {
|
if (track.maxBlockAdditionId > 0) {
|
||||||
blockFlags |= C.BUFFER_FLAG_HAS_SUPPLEMENTAL_DATA;
|
blockFlags |= C.BUFFER_FLAG_HAS_SUPPLEMENTAL_DATA;
|
||||||
blockAddData.reset();
|
blockAdditionalData.reset();
|
||||||
// If there is supplemental data, the structure of the sample data is:
|
// If there is supplemental data, the structure of the sample data is:
|
||||||
// sample size (4 bytes) || sample data || supplemental data
|
// sample size (4 bytes) || sample data || supplemental data
|
||||||
scratch.reset(/* limit= */ 4);
|
scratch.reset(/* limit= */ 4);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user