mirror of
https://github.com/androidx/media.git
synced 2025-05-21 23:56:32 +08:00
Remove zero-args ParsableByteArray#reset() method
It's potentially confusing that this resets both position & limit, so require callers to pass `limit` explicitly, or call setPosition(0) if that's actually what they intended. This makes enforcing the limit in an upcoming change slightly safer. PiperOrigin-RevId: 323340485
This commit is contained in:
parent
ce2e6e2fd6
commit
7083dbf7b4
@ -67,12 +67,6 @@ public final class ParsableByteArray {
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
/** Sets the position and limit to zero. */
|
||||
public void reset() {
|
||||
position = 0;
|
||||
limit = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the position to zero and the limit to the specified value. If the limit exceeds the
|
||||
* capacity, {@code data} is replaced with a new array of sufficient size.
|
||||
|
@ -187,7 +187,7 @@ public final class FlacExtractor implements Extractor {
|
||||
}
|
||||
currentFrameFirstSampleNumber = timeUs == 0 ? 0 : SAMPLE_NUMBER_UNKNOWN;
|
||||
currentFrameBytesWritten = 0;
|
||||
buffer.reset();
|
||||
buffer.reset(/* limit= */ 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1104,7 +1104,7 @@ public class MatroskaExtractor implements Extractor {
|
||||
blockTrackNumberLength = varintReader.getLastLength();
|
||||
blockDurationUs = C.TIME_UNSET;
|
||||
blockState = BLOCK_STATE_HEADER;
|
||||
scratch.reset();
|
||||
scratch.reset(/* limit= */ 0);
|
||||
}
|
||||
|
||||
Track track = tracks.get(blockTrackNumber);
|
||||
@ -1422,7 +1422,7 @@ public class MatroskaExtractor implements Extractor {
|
||||
|
||||
if (track.maxBlockAdditionId > 0) {
|
||||
blockFlags |= C.BUFFER_FLAG_HAS_SUPPLEMENTAL_DATA;
|
||||
blockAdditionalData.reset();
|
||||
blockAdditionalData.reset(/* limit= */ 0);
|
||||
// If there is supplemental data, the structure of the sample data is:
|
||||
// sample size (4 bytes) || sample data || supplemental data
|
||||
scratch.reset(/* limit= */ 4);
|
||||
@ -1520,7 +1520,7 @@ public class MatroskaExtractor implements Extractor {
|
||||
samplePartitionCount = 0;
|
||||
sampleSignalByte = (byte) 0;
|
||||
sampleInitializationVectorRead = false;
|
||||
sampleStrippedBytes.reset();
|
||||
sampleStrippedBytes.reset(/* limit= */ 0);
|
||||
}
|
||||
|
||||
private void writeSubtitleSampleData(ExtractorInput input, byte[] samplePrefix, int size)
|
||||
|
@ -40,7 +40,7 @@ import java.util.Arrays;
|
||||
*/
|
||||
public void reset() {
|
||||
pageHeader.reset();
|
||||
packetArray.reset();
|
||||
packetArray.reset(/* limit= */ 0);
|
||||
currentSegmentIndex = C.INDEX_UNSET;
|
||||
populated = false;
|
||||
}
|
||||
@ -61,7 +61,7 @@ import java.util.Arrays;
|
||||
|
||||
if (populated) {
|
||||
populated = false;
|
||||
packetArray.reset();
|
||||
packetArray.reset(/* limit= */ 0);
|
||||
}
|
||||
|
||||
while (!populated) {
|
||||
|
@ -106,7 +106,7 @@ import java.io.IOException;
|
||||
Assertions.checkArgument(input.getPosition() == input.getPeekPosition());
|
||||
while ((limit == C.POSITION_UNSET || input.getPosition() + CAPTURE_PATTERN_SIZE < limit)
|
||||
&& peekSafely(input, scratch.getData(), 0, CAPTURE_PATTERN_SIZE, /* quiet= */ true)) {
|
||||
scratch.reset();
|
||||
scratch.reset(/* limit= */ CAPTURE_PATTERN_SIZE);
|
||||
if (scratch.readUnsignedInt() == CAPTURE_PATTERN) {
|
||||
input.resetPeekPosition();
|
||||
return true;
|
||||
@ -132,7 +132,7 @@ import java.io.IOException;
|
||||
*/
|
||||
public boolean populate(ExtractorInput input, boolean quiet) throws IOException {
|
||||
reset();
|
||||
scratch.reset();
|
||||
scratch.reset(/* limit= */ EMPTY_PAGE_HEADER_SIZE);
|
||||
if (!peekSafely(input, scratch.getData(), 0, EMPTY_PAGE_HEADER_SIZE, quiet)
|
||||
|| scratch.readUnsignedInt() != CAPTURE_PATTERN) {
|
||||
return false;
|
||||
@ -156,7 +156,7 @@ import java.io.IOException;
|
||||
headerSize = EMPTY_PAGE_HEADER_SIZE + pageSegmentCount;
|
||||
|
||||
// calculate total size of header including laces
|
||||
scratch.reset();
|
||||
scratch.reset(/* limit= */ pageSegmentCount);
|
||||
input.peekFully(scratch.getData(), 0, pageSegmentCount);
|
||||
for (int i = 0; i < pageSegmentCount; i++) {
|
||||
laces[i] = scratch.readUnsignedByte();
|
||||
|
@ -72,7 +72,7 @@ public final class RawCcExtractor implements Extractor {
|
||||
|
||||
@Override
|
||||
public boolean sniff(ExtractorInput input) throws IOException {
|
||||
dataScratch.reset();
|
||||
dataScratch.reset(/* limit= */ HEADER_SIZE);
|
||||
input.peekFully(dataScratch.getData(), 0, HEADER_SIZE);
|
||||
return dataScratch.readInt() == HEADER_ID;
|
||||
}
|
||||
@ -118,7 +118,7 @@ public final class RawCcExtractor implements Extractor {
|
||||
}
|
||||
|
||||
private boolean parseHeader(ExtractorInput input) throws IOException {
|
||||
dataScratch.reset();
|
||||
dataScratch.reset(/* limit= */ HEADER_SIZE);
|
||||
if (input.readFully(dataScratch.getData(), 0, HEADER_SIZE, true)) {
|
||||
if (dataScratch.readInt() != HEADER_ID) {
|
||||
throw new IOException("Input not RawCC");
|
||||
@ -132,14 +132,15 @@ public final class RawCcExtractor implements Extractor {
|
||||
}
|
||||
|
||||
private boolean parseTimestampAndSampleCount(ExtractorInput input) throws IOException {
|
||||
dataScratch.reset();
|
||||
if (version == 0) {
|
||||
dataScratch.reset(/* limit= */ TIMESTAMP_SIZE_V0 + 1);
|
||||
if (!input.readFully(dataScratch.getData(), 0, TIMESTAMP_SIZE_V0 + 1, true)) {
|
||||
return false;
|
||||
}
|
||||
// version 0 timestamps are 45kHz, so we need to convert them into us
|
||||
timestampUs = dataScratch.readUnsignedInt() * 1000 / 45;
|
||||
} else if (version == 1) {
|
||||
dataScratch.reset(/* limit= */ TIMESTAMP_SIZE_V1 + 1);
|
||||
if (!input.readFully(dataScratch.getData(), 0, TIMESTAMP_SIZE_V1 + 1, true)) {
|
||||
return false;
|
||||
}
|
||||
@ -156,7 +157,7 @@ public final class RawCcExtractor implements Extractor {
|
||||
@RequiresNonNull("trackOutput")
|
||||
private void parseSamples(ExtractorInput input) throws IOException {
|
||||
for (; remainingSampleCount > 0; remainingSampleCount--) {
|
||||
dataScratch.reset();
|
||||
dataScratch.reset(/* limit= */ 3);
|
||||
input.readFully(dataScratch.getData(), 0, 3);
|
||||
|
||||
trackOutput.sampleData(dataScratch, 3);
|
||||
|
@ -239,7 +239,7 @@ public final class TsExtractor implements Extractor {
|
||||
if (timeUs != 0 && tsBinarySearchSeeker != null) {
|
||||
tsBinarySearchSeeker.setSeekTargetUs(timeUs);
|
||||
}
|
||||
tsPacketBuffer.reset();
|
||||
tsPacketBuffer.reset(/* limit= */ 0);
|
||||
continuityCounters.clear();
|
||||
for (int i = 0; i < tsPayloadReaders.size(); i++) {
|
||||
tsPayloadReaders.valueAt(i).seek();
|
||||
|
Loading…
x
Reference in New Issue
Block a user