mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Remove FlacExtractor from nullness blacklist
PiperOrigin-RevId: 256526365
This commit is contained in:
parent
948d69b774
commit
0f364dfffc
@ -40,6 +40,7 @@ android {
|
|||||||
dependencies {
|
dependencies {
|
||||||
implementation project(modulePrefix + 'library-core')
|
implementation project(modulePrefix + 'library-core')
|
||||||
implementation 'androidx.annotation:annotation:1.0.2'
|
implementation 'androidx.annotation:annotation:1.0.2'
|
||||||
|
compileOnly 'org.checkerframework:checker-qual:' + checkerframeworkVersion
|
||||||
androidTestImplementation project(modulePrefix + 'testutils')
|
androidTestImplementation project(modulePrefix + 'testutils')
|
||||||
androidTestImplementation 'androidx.test:runner:' + androidXTestVersion
|
androidTestImplementation 'androidx.test:runner:' + androidXTestVersion
|
||||||
testImplementation project(modulePrefix + 'testutils-robolectric')
|
testImplementation project(modulePrefix + 'testutils-robolectric')
|
||||||
|
@ -43,6 +43,9 @@ import java.lang.annotation.Retention;
|
|||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import org.checkerframework.checker.nullness.qual.EnsuresNonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Facilitates the extraction of data from the FLAC container format.
|
* Facilitates the extraction of data from the FLAC container format.
|
||||||
@ -75,17 +78,17 @@ public final class FlacExtractor implements Extractor {
|
|||||||
*/
|
*/
|
||||||
private static final byte[] FLAC_SIGNATURE = {'f', 'L', 'a', 'C', 0, 0, 0, 0x22};
|
private static final byte[] FLAC_SIGNATURE = {'f', 'L', 'a', 'C', 0, 0, 0, 0x22};
|
||||||
|
|
||||||
|
private final ParsableByteArray outputBuffer;
|
||||||
private final Id3Peeker id3Peeker;
|
private final Id3Peeker id3Peeker;
|
||||||
private final boolean id3MetadataDisabled;
|
private final boolean id3MetadataDisabled;
|
||||||
|
|
||||||
@Nullable private FlacDecoderJni decoderJni;
|
@Nullable private FlacDecoderJni decoderJni;
|
||||||
@Nullable private ExtractorOutput extractorOutput;
|
private @MonotonicNonNull ExtractorOutput extractorOutput;
|
||||||
@Nullable private TrackOutput trackOutput;
|
private @MonotonicNonNull TrackOutput trackOutput;
|
||||||
|
|
||||||
private boolean streamInfoDecoded;
|
private boolean streamInfoDecoded;
|
||||||
@Nullable private FlacStreamInfo streamInfo;
|
private @MonotonicNonNull FlacStreamInfo streamInfo;
|
||||||
@Nullable private ParsableByteArray outputBuffer;
|
private @MonotonicNonNull OutputFrameHolder outputFrameHolder;
|
||||||
@Nullable private OutputFrameHolder outputFrameHolder;
|
|
||||||
|
|
||||||
@Nullable private Metadata id3Metadata;
|
@Nullable private Metadata id3Metadata;
|
||||||
@Nullable private FlacBinarySearchSeeker binarySearchSeeker;
|
@Nullable private FlacBinarySearchSeeker binarySearchSeeker;
|
||||||
@ -101,6 +104,7 @@ public final class FlacExtractor implements Extractor {
|
|||||||
* @param flags Flags that control the extractor's behavior.
|
* @param flags Flags that control the extractor's behavior.
|
||||||
*/
|
*/
|
||||||
public FlacExtractor(int flags) {
|
public FlacExtractor(int flags) {
|
||||||
|
outputBuffer = new ParsableByteArray();
|
||||||
id3Peeker = new Id3Peeker();
|
id3Peeker = new Id3Peeker();
|
||||||
id3MetadataDisabled = (flags & FLAG_DISABLE_ID3_METADATA) != 0;
|
id3MetadataDisabled = (flags & FLAG_DISABLE_ID3_METADATA) != 0;
|
||||||
}
|
}
|
||||||
@ -132,12 +136,12 @@ public final class FlacExtractor implements Extractor {
|
|||||||
id3Metadata = peekId3Data(input);
|
id3Metadata = peekId3Data(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
decoderJni.setData(input);
|
FlacDecoderJni decoderJni = initDecoderJni(input);
|
||||||
try {
|
try {
|
||||||
decodeStreamInfo(input);
|
decodeStreamInfo(input);
|
||||||
|
|
||||||
if (binarySearchSeeker != null && binarySearchSeeker.isSeeking()) {
|
if (binarySearchSeeker != null && binarySearchSeeker.isSeeking()) {
|
||||||
return handlePendingSeek(input, seekPosition);
|
return handlePendingSeek(input, seekPosition, outputBuffer, outputFrameHolder, trackOutput);
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuffer outputByteBuffer = outputFrameHolder.byteBuffer;
|
ByteBuffer outputByteBuffer = outputFrameHolder.byteBuffer;
|
||||||
@ -194,6 +198,17 @@ public final class FlacExtractor implements Extractor {
|
|||||||
return id3Peeker.peekId3Data(input, id3FramePredicate);
|
return id3Peeker.peekId3Data(input, id3FramePredicate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EnsuresNonNull({"decoderJni", "extractorOutput", "trackOutput"}) // Ensures initialized.
|
||||||
|
@SuppressWarnings({"contracts.postcondition.not.satisfied"})
|
||||||
|
private FlacDecoderJni initDecoderJni(ExtractorInput input) {
|
||||||
|
FlacDecoderJni decoderJni = Assertions.checkNotNull(this.decoderJni);
|
||||||
|
decoderJni.setData(input);
|
||||||
|
return decoderJni;
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequiresNonNull({"decoderJni", "extractorOutput", "trackOutput"}) // Requires initialized.
|
||||||
|
@EnsuresNonNull({"streamInfo", "outputFrameHolder"}) // Ensures StreamInfo decoded.
|
||||||
|
@SuppressWarnings({"contracts.postcondition.not.satisfied"})
|
||||||
private void decodeStreamInfo(ExtractorInput input) throws InterruptedException, IOException {
|
private void decodeStreamInfo(ExtractorInput input) throws InterruptedException, IOException {
|
||||||
if (streamInfoDecoded) {
|
if (streamInfoDecoded) {
|
||||||
return;
|
return;
|
||||||
@ -214,14 +229,19 @@ public final class FlacExtractor implements Extractor {
|
|||||||
binarySearchSeeker =
|
binarySearchSeeker =
|
||||||
outputSeekMap(decoderJni, streamInfo, input.getLength(), extractorOutput);
|
outputSeekMap(decoderJni, streamInfo, input.getLength(), extractorOutput);
|
||||||
outputFormat(streamInfo, id3MetadataDisabled ? null : id3Metadata, trackOutput);
|
outputFormat(streamInfo, id3MetadataDisabled ? null : id3Metadata, trackOutput);
|
||||||
outputBuffer = new ParsableByteArray(streamInfo.maxDecodedFrameSize());
|
outputBuffer.reset(streamInfo.maxDecodedFrameSize());
|
||||||
outputFrameHolder = new OutputFrameHolder(ByteBuffer.wrap(outputBuffer.data));
|
outputFrameHolder = new OutputFrameHolder(ByteBuffer.wrap(outputBuffer.data));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int handlePendingSeek(ExtractorInput input, PositionHolder seekPosition)
|
@RequiresNonNull("binarySearchSeeker")
|
||||||
|
private int handlePendingSeek(
|
||||||
|
ExtractorInput input,
|
||||||
|
PositionHolder seekPosition,
|
||||||
|
ParsableByteArray outputBuffer,
|
||||||
|
OutputFrameHolder outputFrameHolder,
|
||||||
|
TrackOutput trackOutput)
|
||||||
throws InterruptedException, IOException {
|
throws InterruptedException, IOException {
|
||||||
Assertions.checkNotNull(binarySearchSeeker);
|
|
||||||
int seekResult = binarySearchSeeker.handlePendingSeek(input, seekPosition, outputFrameHolder);
|
int seekResult = binarySearchSeeker.handlePendingSeek(input, seekPosition, outputFrameHolder);
|
||||||
ByteBuffer outputByteBuffer = outputFrameHolder.byteBuffer;
|
ByteBuffer outputByteBuffer = outputFrameHolder.byteBuffer;
|
||||||
if (seekResult == RESULT_CONTINUE && outputByteBuffer.limit() > 0) {
|
if (seekResult == RESULT_CONTINUE && outputByteBuffer.limit() > 0) {
|
||||||
@ -270,7 +290,7 @@ public final class FlacExtractor implements Extractor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void outputFormat(
|
private static void outputFormat(
|
||||||
FlacStreamInfo streamInfo, Metadata metadata, TrackOutput output) {
|
FlacStreamInfo streamInfo, @Nullable Metadata metadata, TrackOutput output) {
|
||||||
Format mediaFormat =
|
Format mediaFormat =
|
||||||
Format.createAudioSampleFormat(
|
Format.createAudioSampleFormat(
|
||||||
/* id= */ null,
|
/* id= */ null,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user