Commit d810352f by hoangtc Committed by Oliver Woodman

Refactor FlacBinarySearchSeeker.

Rewrite FlacBinarySearchSeeker and extract out the core binary search algorithm
into BinarySearchSeeker class so it can be re-used for other formats.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=206012900
parent 8952ccac
...@@ -67,6 +67,6 @@ public final class FlacBinarySearchSeekerTest extends InstrumentationTestCase { ...@@ -67,6 +67,6 @@ public final class FlacBinarySearchSeekerTest extends InstrumentationTestCase {
decoderJni.decodeMetadata(), /* firstFramePosition= */ 0, data.length, decoderJni); decoderJni.decodeMetadata(), /* firstFramePosition= */ 0, data.length, decoderJni);
seeker.setSeekTargetUs(/* timeUs= */ 1000); seeker.setSeekTargetUs(/* timeUs= */ 1000);
assertThat(seeker.hasPendingSeek()).isTrue(); assertThat(seeker.isSeeking()).isTrue();
} }
} }
...@@ -21,6 +21,7 @@ import android.support.annotation.IntDef; ...@@ -21,6 +21,7 @@ import android.support.annotation.IntDef;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.extractor.BinarySearchSeeker;
import com.google.android.exoplayer2.extractor.Extractor; import com.google.android.exoplayer2.extractor.Extractor;
import com.google.android.exoplayer2.extractor.ExtractorInput; import com.google.android.exoplayer2.extractor.ExtractorInput;
import com.google.android.exoplayer2.extractor.ExtractorOutput; import com.google.android.exoplayer2.extractor.ExtractorOutput;
...@@ -53,8 +54,7 @@ public final class FlacExtractor implements Extractor { ...@@ -53,8 +54,7 @@ public final class FlacExtractor implements Extractor {
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
@IntDef( @IntDef(
flag = true, flag = true,
value = {FLAG_DISABLE_ID3_METADATA} value = {FLAG_DISABLE_ID3_METADATA})
)
public @interface Flags {} public @interface Flags {}
/** /**
...@@ -79,6 +79,7 @@ public final class FlacExtractor implements Extractor { ...@@ -79,6 +79,7 @@ public final class FlacExtractor implements Extractor {
private ParsableByteArray outputBuffer; private ParsableByteArray outputBuffer;
private ByteBuffer outputByteBuffer; private ByteBuffer outputByteBuffer;
private BinarySearchSeeker.OutputFrameHolder outputFrameHolder;
private FlacStreamInfo streamInfo; private FlacStreamInfo streamInfo;
private Metadata id3Metadata; private Metadata id3Metadata;
...@@ -131,7 +132,7 @@ public final class FlacExtractor implements Extractor { ...@@ -131,7 +132,7 @@ public final class FlacExtractor implements Extractor {
decoderJni.setData(input); decoderJni.setData(input);
readPastStreamInfo(input); readPastStreamInfo(input);
if (flacBinarySearchSeeker != null && flacBinarySearchSeeker.hasPendingSeek()) { if (flacBinarySearchSeeker != null && flacBinarySearchSeeker.isSeeking()) {
return handlePendingSeek(input, seekPosition); return handlePendingSeek(input, seekPosition);
} }
...@@ -215,6 +216,7 @@ public final class FlacExtractor implements Extractor { ...@@ -215,6 +216,7 @@ public final class FlacExtractor implements Extractor {
outputFormat(streamInfo); outputFormat(streamInfo);
outputBuffer = new ParsableByteArray(streamInfo.maxDecodedFrameSize()); outputBuffer = new ParsableByteArray(streamInfo.maxDecodedFrameSize());
outputByteBuffer = ByteBuffer.wrap(outputBuffer.data); outputByteBuffer = ByteBuffer.wrap(outputBuffer.data);
outputFrameHolder = new BinarySearchSeeker.OutputFrameHolder(outputByteBuffer);
} }
private FlacStreamInfo decodeStreamInfo(ExtractorInput input) private FlacStreamInfo decodeStreamInfo(ExtractorInput input)
...@@ -277,9 +279,10 @@ public final class FlacExtractor implements Extractor { ...@@ -277,9 +279,10 @@ public final class FlacExtractor implements Extractor {
private int handlePendingSeek(ExtractorInput input, PositionHolder seekPosition) private int handlePendingSeek(ExtractorInput input, PositionHolder seekPosition)
throws InterruptedException, IOException { throws InterruptedException, IOException {
int seekResult = int seekResult =
flacBinarySearchSeeker.handlePendingSeek(input, seekPosition, outputByteBuffer); flacBinarySearchSeeker.handlePendingSeek(input, seekPosition, outputFrameHolder);
ByteBuffer outputByteBuffer = outputFrameHolder.byteBuffer;
if (seekResult == RESULT_CONTINUE && outputByteBuffer.limit() > 0) { if (seekResult == RESULT_CONTINUE && outputByteBuffer.limit() > 0) {
writeLastSampleToOutput(outputByteBuffer.limit(), decoderJni.getLastFrameTimestamp()); writeLastSampleToOutput(outputByteBuffer.limit(), outputFrameHolder.timeUs);
} }
return seekResult; return seekResult;
} }
......
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