Search in sources :

Example 1 with EnsuresNonNullIf

use of org.checkerframework.checker.nullness.qual.EnsuresNonNullIf in project ExoPlayer by google.

the class DefaultDrmSession method openInternal.

// Internal methods.
/**
 * Try to open a session, do provisioning if necessary.
 *
 * @return true on success, false otherwise.
 */
@EnsuresNonNullIf(result = true, expression = "sessionId")
private boolean openInternal() {
    if (isOpen()) {
        // Already opened
        return true;
    }
    try {
        sessionId = mediaDrm.openSession();
        mediaDrm.setPlayerIdForSession(sessionId, playerId);
        cryptoConfig = mediaDrm.createCryptoConfig(sessionId);
        state = STATE_OPENED;
        // Capture state into a local so a consistent value is seen by the lambda.
        int localState = state;
        dispatchEvent(eventDispatcher -> eventDispatcher.drmSessionAcquired(localState));
        Assertions.checkNotNull(sessionId);
        return true;
    } catch (NotProvisionedException e) {
        provisioningManager.provisionRequired(this);
    } catch (Exception e) {
        onError(e, DrmUtil.ERROR_SOURCE_EXO_MEDIA_DRM);
    }
    return false;
}
Also used : NotProvisionedException(android.media.NotProvisionedException) SuppressLint(android.annotation.SuppressLint) NotProvisionedException(android.media.NotProvisionedException) IOException(java.io.IOException) EnsuresNonNullIf(org.checkerframework.checker.nullness.qual.EnsuresNonNullIf)

Example 2 with EnsuresNonNullIf

use of org.checkerframework.checker.nullness.qual.EnsuresNonNullIf in project ExoPlayer by google.

the class VorbisReader method readHeaders.

@Override
@EnsuresNonNullIf(expression = "#3.format", result = false)
protected boolean readHeaders(ParsableByteArray packet, long position, SetupData setupData) throws IOException {
    if (vorbisSetup != null) {
        checkNotNull(setupData.format);
        return false;
    }
    vorbisSetup = readSetupHeaders(packet);
    if (vorbisSetup == null) {
        return true;
    }
    VorbisSetup vorbisSetup = this.vorbisSetup;
    VorbisUtil.VorbisIdHeader idHeader = vorbisSetup.idHeader;
    ArrayList<byte[]> codecInitializationData = new ArrayList<>();
    codecInitializationData.add(idHeader.data);
    codecInitializationData.add(vorbisSetup.setupHeaderData);
    @Nullable Metadata metadata = VorbisUtil.parseVorbisComments(ImmutableList.copyOf(vorbisSetup.commentHeader.comments));
    setupData.format = new Format.Builder().setSampleMimeType(MimeTypes.AUDIO_VORBIS).setAverageBitrate(idHeader.bitrateNominal).setPeakBitrate(idHeader.bitrateMaximum).setChannelCount(idHeader.channels).setSampleRate(idHeader.sampleRate).setInitializationData(codecInitializationData).setMetadata(metadata).build();
    return true;
}
Also used : Format(com.google.android.exoplayer2.Format) ArrayList(java.util.ArrayList) Metadata(com.google.android.exoplayer2.metadata.Metadata) Nullable(androidx.annotation.Nullable) VorbisUtil(com.google.android.exoplayer2.extractor.VorbisUtil) EnsuresNonNullIf(org.checkerframework.checker.nullness.qual.EnsuresNonNullIf)

Example 3 with EnsuresNonNullIf

use of org.checkerframework.checker.nullness.qual.EnsuresNonNullIf in project ExoPlayer by google.

the class FlacReader method readHeaders.

@Override
@EnsuresNonNullIf(expression = "#3.format", result = false)
protected boolean readHeaders(ParsableByteArray packet, long position, SetupData setupData) {
    byte[] data = packet.getData();
    @Nullable FlacStreamMetadata streamMetadata = this.streamMetadata;
    if (streamMetadata == null) {
        streamMetadata = new FlacStreamMetadata(data, 17);
        this.streamMetadata = streamMetadata;
        byte[] metadata = Arrays.copyOfRange(data, 9, packet.limit());
        setupData.format = streamMetadata.getFormat(metadata, /* id3Metadata= */
        null);
        return true;
    }
    if ((data[0] & 0x7F) == FlacConstants.METADATA_TYPE_SEEK_TABLE) {
        SeekTable seekTable = FlacMetadataReader.readSeekTableMetadataBlock(packet);
        streamMetadata = streamMetadata.copyWithSeekTable(seekTable);
        this.streamMetadata = streamMetadata;
        flacOggSeeker = new FlacOggSeeker(streamMetadata, seekTable);
        return true;
    }
    if (isAudioPacket(data)) {
        if (flacOggSeeker != null) {
            flacOggSeeker.setFirstFrameOffset(position);
            setupData.oggSeeker = flacOggSeeker;
        }
        checkNotNull(setupData.format);
        return false;
    }
    return true;
}
Also used : SeekTable(com.google.android.exoplayer2.extractor.FlacStreamMetadata.SeekTable) Nullable(androidx.annotation.Nullable) FlacStreamMetadata(com.google.android.exoplayer2.extractor.FlacStreamMetadata) EnsuresNonNullIf(org.checkerframework.checker.nullness.qual.EnsuresNonNullIf)

Example 4 with EnsuresNonNullIf

use of org.checkerframework.checker.nullness.qual.EnsuresNonNullIf in project ExoPlayer by google.

the class OggExtractor method sniffInternal.

@EnsuresNonNullIf(expression = "streamReader", result = true)
private boolean sniffInternal(ExtractorInput input) throws IOException {
    OggPageHeader header = new OggPageHeader();
    if (!header.populate(input, true) || (header.type & 0x02) != 0x02) {
        return false;
    }
    int length = min(header.bodySize, MAX_VERIFICATION_BYTES);
    ParsableByteArray scratch = new ParsableByteArray(length);
    input.peekFully(scratch.getData(), 0, length);
    if (FlacReader.verifyBitstreamType(resetPosition(scratch))) {
        streamReader = new FlacReader();
    } else if (VorbisReader.verifyBitstreamType(resetPosition(scratch))) {
        streamReader = new VorbisReader();
    } else if (OpusReader.verifyBitstreamType(resetPosition(scratch))) {
        streamReader = new OpusReader();
    } else {
        return false;
    }
    return true;
}
Also used : ParsableByteArray(com.google.android.exoplayer2.util.ParsableByteArray) EnsuresNonNullIf(org.checkerframework.checker.nullness.qual.EnsuresNonNullIf)

Aggregations

EnsuresNonNullIf (org.checkerframework.checker.nullness.qual.EnsuresNonNullIf)4 Nullable (androidx.annotation.Nullable)2 SuppressLint (android.annotation.SuppressLint)1 NotProvisionedException (android.media.NotProvisionedException)1 Format (com.google.android.exoplayer2.Format)1 FlacStreamMetadata (com.google.android.exoplayer2.extractor.FlacStreamMetadata)1 SeekTable (com.google.android.exoplayer2.extractor.FlacStreamMetadata.SeekTable)1 VorbisUtil (com.google.android.exoplayer2.extractor.VorbisUtil)1 Metadata (com.google.android.exoplayer2.metadata.Metadata)1 ParsableByteArray (com.google.android.exoplayer2.util.ParsableByteArray)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1