Search in sources :

Example 41 with RequiresNonNull

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

the class AdtsReader method parseAdtsHeader.

/**
 * Parses the sample header.
 */
@RequiresNonNull("output")
private void parseAdtsHeader() throws ParserException {
    adtsScratch.setPosition(0);
    if (!hasOutputFormat) {
        int audioObjectType = adtsScratch.readBits(2) + 1;
        if (audioObjectType != 2) {
            // The stream indicates AAC-Main (1), AAC-SSR (3) or AAC-LTP (4). When the stream indicates
            // AAC-Main it's more likely that the stream contains HE-AAC (5), which cannot be
            // represented correctly in the 2 bit audio_object_type field in the ADTS header. In
            // practice when the stream indicates AAC-SSR or AAC-LTP it more commonly contains AAC-LC or
            // HE-AAC. Since most Android devices don't support AAC-Main, AAC-SSR or AAC-LTP, and since
            // indicating AAC-LC works for HE-AAC streams, we pretend that we're dealing with AAC-LC and
            // hope for the best. In practice this often works.
            // See: https://github.com/google/ExoPlayer/issues/774
            // See: https://github.com/google/ExoPlayer/issues/1383
            Log.w(TAG, "Detected audio object type: " + audioObjectType + ", but assuming AAC LC.");
            audioObjectType = 2;
        }
        adtsScratch.skipBits(5);
        int channelConfig = adtsScratch.readBits(3);
        byte[] audioSpecificConfig = AacUtil.buildAudioSpecificConfig(audioObjectType, firstFrameSampleRateIndex, channelConfig);
        AacUtil.Config aacConfig = AacUtil.parseAudioSpecificConfig(audioSpecificConfig);
        Format format = new Format.Builder().setId(formatId).setSampleMimeType(MimeTypes.AUDIO_AAC).setCodecs(aacConfig.codecs).setChannelCount(aacConfig.channelCount).setSampleRate(aacConfig.sampleRateHz).setInitializationData(Collections.singletonList(audioSpecificConfig)).setLanguage(language).build();
        // In this class a sample is an access unit, but the MediaFormat sample rate specifies the
        // number of PCM audio samples per second.
        sampleDurationUs = (C.MICROS_PER_SECOND * 1024) / format.sampleRate;
        output.format(format);
        hasOutputFormat = true;
    } else {
        adtsScratch.skipBits(10);
    }
    adtsScratch.skipBits(4);
    int sampleSize = adtsScratch.readBits(13) - 2 - /* the sync word */
    HEADER_SIZE;
    if (hasCrc) {
        sampleSize -= CRC_SIZE;
    }
    setReadingSampleState(output, sampleDurationUs, 0, sampleSize);
}
Also used : AacUtil(com.google.android.exoplayer2.audio.AacUtil) Format(com.google.android.exoplayer2.Format) RequiresNonNull(org.checkerframework.checker.nullness.qual.RequiresNonNull)

Example 42 with RequiresNonNull

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

the class LatmReader method parseStreamMuxConfig.

/**
 * Parses a StreamMuxConfig as defined in ISO/IEC 14496-3:2009 Section 1.7.3.1, Table 1.42.
 */
@RequiresNonNull("output")
private void parseStreamMuxConfig(ParsableBitArray data) throws ParserException {
    int audioMuxVersion = data.readBits(1);
    audioMuxVersionA = audioMuxVersion == 1 ? data.readBits(1) : 0;
    if (audioMuxVersionA == 0) {
        if (audioMuxVersion == 1) {
            // Skip taraBufferFullness.
            latmGetValue(data);
        }
        if (!data.readBit()) {
            throw ParserException.createForMalformedContainer(/* message= */
            null, /* cause= */
            null);
        }
        numSubframes = data.readBits(6);
        int numProgram = data.readBits(4);
        int numLayer = data.readBits(3);
        if (numProgram != 0 || numLayer != 0) {
            throw ParserException.createForMalformedContainer(/* message= */
            null, /* cause= */
            null);
        }
        if (audioMuxVersion == 0) {
            int startPosition = data.getPosition();
            int readBits = parseAudioSpecificConfig(data);
            data.setPosition(startPosition);
            byte[] initData = new byte[(readBits + 7) / 8];
            data.readBits(initData, 0, readBits);
            Format format = new Format.Builder().setId(formatId).setSampleMimeType(MimeTypes.AUDIO_AAC).setCodecs(codecs).setChannelCount(channelCount).setSampleRate(sampleRateHz).setInitializationData(Collections.singletonList(initData)).setLanguage(language).build();
            if (!format.equals(this.format)) {
                this.format = format;
                sampleDurationUs = (C.MICROS_PER_SECOND * 1024) / format.sampleRate;
                output.format(format);
            }
        } else {
            int ascLen = (int) latmGetValue(data);
            int bitsRead = parseAudioSpecificConfig(data);
            // fillBits.
            data.skipBits(ascLen - bitsRead);
        }
        parseFrameLength(data);
        otherDataPresent = data.readBit();
        otherDataLenBits = 0;
        if (otherDataPresent) {
            if (audioMuxVersion == 1) {
                otherDataLenBits = latmGetValue(data);
            } else {
                boolean otherDataLenEsc;
                do {
                    otherDataLenEsc = data.readBit();
                    otherDataLenBits = (otherDataLenBits << 8) + data.readBits(8);
                } while (otherDataLenEsc);
            }
        }
        boolean crcCheckPresent = data.readBit();
        if (crcCheckPresent) {
            // crcCheckSum.
            data.skipBits(8);
        }
    } else {
        // This is not defined by ISO/IEC 14496-3:2009.
        throw ParserException.createForMalformedContainer(/* message= */
        null, /* cause= */
        null);
    }
}
Also used : Format(com.google.android.exoplayer2.Format) RequiresNonNull(org.checkerframework.checker.nullness.qual.RequiresNonNull)

Example 43 with RequiresNonNull

use of org.checkerframework.checker.nullness.qual.RequiresNonNull in project beam by apache.

the class ExternalTest method expandMultiOutputTest.

@Test
@Category({ ValidatesRunner.class, UsesCrossLanguageTransforms.class })
@RequiresNonNull("localExpansionAddr")
public void expandMultiOutputTest() {
    PCollectionTuple pTuple = testPipeline.apply(Create.of(1, 2, 3, 4, 5, 6)).apply(External.of(TEST_URN_MULTI, new byte[] {}, localExpansionAddr).withMultiOutputs());
    PAssert.that(pTuple.get(new TupleTag<Integer>("even") {
    })).containsInAnyOrder(2, 4, 6);
    PAssert.that(pTuple.get(new TupleTag<Integer>("odd") {
    })).containsInAnyOrder(1, 3, 5);
    pipelineResult = testPipeline.run();
}
Also used : PCollectionTuple(org.apache.beam.sdk.values.PCollectionTuple) Category(org.junit.experimental.categories.Category) Test(org.junit.Test) RequiresNonNull(org.checkerframework.checker.nullness.qual.RequiresNonNull)

Aggregations

RequiresNonNull (org.checkerframework.checker.nullness.qual.RequiresNonNull)43 Nullable (androidx.annotation.Nullable)12 Format (com.google.android.exoplayer2.Format)10 SuppressLint (android.annotation.SuppressLint)4 TrackOutput (com.google.android.exoplayer2.extractor.TrackOutput)3 MediaPeriodId (com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)3 IOException (java.io.IOException)3 ByteBuffer (java.nio.ByteBuffer)3 Intent (android.content.Intent)2 Paint (android.graphics.Paint)2 Uri (android.net.Uri)2 Bundle (android.os.Bundle)2 TextPaint (android.text.TextPaint)2 DecoderInputBuffer (com.google.android.exoplayer2.decoder.DecoderInputBuffer)2 DefaultExtractorInput (com.google.android.exoplayer2.extractor.DefaultExtractorInput)2 Transformer (com.google.android.exoplayer2.transformer.Transformer)2 EnsuresNonNull (org.checkerframework.checker.nullness.qual.EnsuresNonNull)2 UnderlyingAST (org.checkerframework.dataflow.cfg.UnderlyingAST)2 SpecialBlock (org.checkerframework.dataflow.cfg.block.SpecialBlock)2 TypeSystemError (org.checkerframework.javacutil.TypeSystemError)2