Commit 7083dbf7 by ibaker Committed by Oliver Woodman

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
parent ce2e6e2f
...@@ -67,12 +67,6 @@ public final class ParsableByteArray { ...@@ -67,12 +67,6 @@ public final class ParsableByteArray {
this.limit = limit; 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 * 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. * capacity, {@code data} is replaced with a new array of sufficient size.
......
...@@ -187,7 +187,7 @@ public final class FlacExtractor implements Extractor { ...@@ -187,7 +187,7 @@ public final class FlacExtractor implements Extractor {
} }
currentFrameFirstSampleNumber = timeUs == 0 ? 0 : SAMPLE_NUMBER_UNKNOWN; currentFrameFirstSampleNumber = timeUs == 0 ? 0 : SAMPLE_NUMBER_UNKNOWN;
currentFrameBytesWritten = 0; currentFrameBytesWritten = 0;
buffer.reset(); buffer.reset(/* limit= */ 0);
} }
@Override @Override
......
...@@ -1104,7 +1104,7 @@ public class MatroskaExtractor implements Extractor { ...@@ -1104,7 +1104,7 @@ public class MatroskaExtractor implements Extractor {
blockTrackNumberLength = varintReader.getLastLength(); blockTrackNumberLength = varintReader.getLastLength();
blockDurationUs = C.TIME_UNSET; blockDurationUs = C.TIME_UNSET;
blockState = BLOCK_STATE_HEADER; blockState = BLOCK_STATE_HEADER;
scratch.reset(); scratch.reset(/* limit= */ 0);
} }
Track track = tracks.get(blockTrackNumber); Track track = tracks.get(blockTrackNumber);
...@@ -1422,7 +1422,7 @@ public class MatroskaExtractor implements Extractor { ...@@ -1422,7 +1422,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;
blockAdditionalData.reset(); blockAdditionalData.reset(/* limit= */ 0);
// 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);
...@@ -1520,7 +1520,7 @@ public class MatroskaExtractor implements Extractor { ...@@ -1520,7 +1520,7 @@ public class MatroskaExtractor implements Extractor {
samplePartitionCount = 0; samplePartitionCount = 0;
sampleSignalByte = (byte) 0; sampleSignalByte = (byte) 0;
sampleInitializationVectorRead = false; sampleInitializationVectorRead = false;
sampleStrippedBytes.reset(); sampleStrippedBytes.reset(/* limit= */ 0);
} }
private void writeSubtitleSampleData(ExtractorInput input, byte[] samplePrefix, int size) private void writeSubtitleSampleData(ExtractorInput input, byte[] samplePrefix, int size)
......
...@@ -40,7 +40,7 @@ import java.util.Arrays; ...@@ -40,7 +40,7 @@ import java.util.Arrays;
*/ */
public void reset() { public void reset() {
pageHeader.reset(); pageHeader.reset();
packetArray.reset(); packetArray.reset(/* limit= */ 0);
currentSegmentIndex = C.INDEX_UNSET; currentSegmentIndex = C.INDEX_UNSET;
populated = false; populated = false;
} }
...@@ -61,7 +61,7 @@ import java.util.Arrays; ...@@ -61,7 +61,7 @@ import java.util.Arrays;
if (populated) { if (populated) {
populated = false; populated = false;
packetArray.reset(); packetArray.reset(/* limit= */ 0);
} }
while (!populated) { while (!populated) {
......
...@@ -106,7 +106,7 @@ import java.io.IOException; ...@@ -106,7 +106,7 @@ import java.io.IOException;
Assertions.checkArgument(input.getPosition() == input.getPeekPosition()); Assertions.checkArgument(input.getPosition() == input.getPeekPosition());
while ((limit == C.POSITION_UNSET || input.getPosition() + CAPTURE_PATTERN_SIZE < limit) while ((limit == C.POSITION_UNSET || input.getPosition() + CAPTURE_PATTERN_SIZE < limit)
&& peekSafely(input, scratch.getData(), 0, CAPTURE_PATTERN_SIZE, /* quiet= */ true)) { && peekSafely(input, scratch.getData(), 0, CAPTURE_PATTERN_SIZE, /* quiet= */ true)) {
scratch.reset(); scratch.reset(/* limit= */ CAPTURE_PATTERN_SIZE);
if (scratch.readUnsignedInt() == CAPTURE_PATTERN) { if (scratch.readUnsignedInt() == CAPTURE_PATTERN) {
input.resetPeekPosition(); input.resetPeekPosition();
return true; return true;
...@@ -132,7 +132,7 @@ import java.io.IOException; ...@@ -132,7 +132,7 @@ import java.io.IOException;
*/ */
public boolean populate(ExtractorInput input, boolean quiet) throws IOException { public boolean populate(ExtractorInput input, boolean quiet) throws IOException {
reset(); reset();
scratch.reset(); scratch.reset(/* limit= */ EMPTY_PAGE_HEADER_SIZE);
if (!peekSafely(input, scratch.getData(), 0, EMPTY_PAGE_HEADER_SIZE, quiet) if (!peekSafely(input, scratch.getData(), 0, EMPTY_PAGE_HEADER_SIZE, quiet)
|| scratch.readUnsignedInt() != CAPTURE_PATTERN) { || scratch.readUnsignedInt() != CAPTURE_PATTERN) {
return false; return false;
...@@ -156,7 +156,7 @@ import java.io.IOException; ...@@ -156,7 +156,7 @@ import java.io.IOException;
headerSize = EMPTY_PAGE_HEADER_SIZE + pageSegmentCount; headerSize = EMPTY_PAGE_HEADER_SIZE + pageSegmentCount;
// calculate total size of header including laces // calculate total size of header including laces
scratch.reset(); scratch.reset(/* limit= */ pageSegmentCount);
input.peekFully(scratch.getData(), 0, pageSegmentCount); input.peekFully(scratch.getData(), 0, pageSegmentCount);
for (int i = 0; i < pageSegmentCount; i++) { for (int i = 0; i < pageSegmentCount; i++) {
laces[i] = scratch.readUnsignedByte(); laces[i] = scratch.readUnsignedByte();
......
...@@ -72,7 +72,7 @@ public final class RawCcExtractor implements Extractor { ...@@ -72,7 +72,7 @@ public final class RawCcExtractor implements Extractor {
@Override @Override
public boolean sniff(ExtractorInput input) throws IOException { public boolean sniff(ExtractorInput input) throws IOException {
dataScratch.reset(); dataScratch.reset(/* limit= */ HEADER_SIZE);
input.peekFully(dataScratch.getData(), 0, HEADER_SIZE); input.peekFully(dataScratch.getData(), 0, HEADER_SIZE);
return dataScratch.readInt() == HEADER_ID; return dataScratch.readInt() == HEADER_ID;
} }
...@@ -118,7 +118,7 @@ public final class RawCcExtractor implements Extractor { ...@@ -118,7 +118,7 @@ public final class RawCcExtractor implements Extractor {
} }
private boolean parseHeader(ExtractorInput input) throws IOException { private boolean parseHeader(ExtractorInput input) throws IOException {
dataScratch.reset(); dataScratch.reset(/* limit= */ HEADER_SIZE);
if (input.readFully(dataScratch.getData(), 0, HEADER_SIZE, true)) { if (input.readFully(dataScratch.getData(), 0, HEADER_SIZE, true)) {
if (dataScratch.readInt() != HEADER_ID) { if (dataScratch.readInt() != HEADER_ID) {
throw new IOException("Input not RawCC"); throw new IOException("Input not RawCC");
...@@ -132,14 +132,15 @@ public final class RawCcExtractor implements Extractor { ...@@ -132,14 +132,15 @@ public final class RawCcExtractor implements Extractor {
} }
private boolean parseTimestampAndSampleCount(ExtractorInput input) throws IOException { private boolean parseTimestampAndSampleCount(ExtractorInput input) throws IOException {
dataScratch.reset();
if (version == 0) { if (version == 0) {
dataScratch.reset(/* limit= */ TIMESTAMP_SIZE_V0 + 1);
if (!input.readFully(dataScratch.getData(), 0, TIMESTAMP_SIZE_V0 + 1, true)) { if (!input.readFully(dataScratch.getData(), 0, TIMESTAMP_SIZE_V0 + 1, true)) {
return false; return false;
} }
// version 0 timestamps are 45kHz, so we need to convert them into us // version 0 timestamps are 45kHz, so we need to convert them into us
timestampUs = dataScratch.readUnsignedInt() * 1000 / 45; timestampUs = dataScratch.readUnsignedInt() * 1000 / 45;
} else if (version == 1) { } else if (version == 1) {
dataScratch.reset(/* limit= */ TIMESTAMP_SIZE_V1 + 1);
if (!input.readFully(dataScratch.getData(), 0, TIMESTAMP_SIZE_V1 + 1, true)) { if (!input.readFully(dataScratch.getData(), 0, TIMESTAMP_SIZE_V1 + 1, true)) {
return false; return false;
} }
...@@ -156,7 +157,7 @@ public final class RawCcExtractor implements Extractor { ...@@ -156,7 +157,7 @@ public final class RawCcExtractor implements Extractor {
@RequiresNonNull("trackOutput") @RequiresNonNull("trackOutput")
private void parseSamples(ExtractorInput input) throws IOException { private void parseSamples(ExtractorInput input) throws IOException {
for (; remainingSampleCount > 0; remainingSampleCount--) { for (; remainingSampleCount > 0; remainingSampleCount--) {
dataScratch.reset(); dataScratch.reset(/* limit= */ 3);
input.readFully(dataScratch.getData(), 0, 3); input.readFully(dataScratch.getData(), 0, 3);
trackOutput.sampleData(dataScratch, 3); trackOutput.sampleData(dataScratch, 3);
......
...@@ -239,7 +239,7 @@ public final class TsExtractor implements Extractor { ...@@ -239,7 +239,7 @@ public final class TsExtractor implements Extractor {
if (timeUs != 0 && tsBinarySearchSeeker != null) { if (timeUs != 0 && tsBinarySearchSeeker != null) {
tsBinarySearchSeeker.setSeekTargetUs(timeUs); tsBinarySearchSeeker.setSeekTargetUs(timeUs);
} }
tsPacketBuffer.reset(); tsPacketBuffer.reset(/* limit= */ 0);
continuityCounters.clear(); continuityCounters.clear();
for (int i = 0; i < tsPayloadReaders.size(); i++) { for (int i = 0; i < tsPayloadReaders.size(); i++) {
tsPayloadReaders.valueAt(i).seek(); tsPayloadReaders.valueAt(i).seek();
......
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