Search in sources :

Example 1 with FlacStreamMetadata

use of com.google.android.exoplayer2.extractor.FlacStreamMetadata in project ExoPlayer by google.

the class FlacExtractor method outputFormat.

private static void outputFormat(FlacStreamMetadata streamMetadata, @Nullable Metadata metadata, TrackOutput output) {
    Format mediaFormat = new Format.Builder().setSampleMimeType(MimeTypes.AUDIO_RAW).setAverageBitrate(streamMetadata.getDecodedBitrate()).setPeakBitrate(streamMetadata.getDecodedBitrate()).setMaxInputSize(streamMetadata.getMaxDecodedFrameSize()).setChannelCount(streamMetadata.channels).setSampleRate(streamMetadata.sampleRate).setPcmEncoding(getPcmEncoding(streamMetadata.bitsPerSample)).setMetadata(metadata).build();
    output.format(mediaFormat);
}
Also used : Format(com.google.android.exoplayer2.Format)

Example 2 with FlacStreamMetadata

use of com.google.android.exoplayer2.extractor.FlacStreamMetadata in project ExoPlayer by google.

the class LibflacAudioRenderer method supportsFormatInternal.

@Override
@C.FormatSupport
protected int supportsFormatInternal(Format format) {
    if (!FlacLibrary.isAvailable() || !MimeTypes.AUDIO_FLAC.equalsIgnoreCase(format.sampleMimeType)) {
        return C.FORMAT_UNSUPPORTED_TYPE;
    }
    // Compute the format that the FLAC decoder will output.
    Format outputFormat;
    if (format.initializationData.isEmpty()) {
        // The initialization data might not be set if the format was obtained from a manifest (e.g.
        // for DASH playbacks) rather than directly from the media. In this case we assume
        // ENCODING_PCM_16BIT. If the actual encoding is different then playback will still succeed as
        // long as the AudioSink supports it, which will always be true when using DefaultAudioSink.
        outputFormat = Util.getPcmFormat(C.ENCODING_PCM_16BIT, format.channelCount, format.sampleRate);
    } else {
        int streamMetadataOffset = STREAM_MARKER_SIZE + METADATA_BLOCK_HEADER_SIZE;
        FlacStreamMetadata streamMetadata = new FlacStreamMetadata(format.initializationData.get(0), streamMetadataOffset);
        outputFormat = getOutputFormat(streamMetadata);
    }
    if (!sinkSupportsFormat(outputFormat)) {
        return C.FORMAT_UNSUPPORTED_SUBTYPE;
    } else if (format.cryptoType != C.CRYPTO_TYPE_NONE) {
        return C.FORMAT_UNSUPPORTED_DRM;
    } else {
        return C.FORMAT_HANDLED;
    }
}
Also used : Format(com.google.android.exoplayer2.Format) FlacStreamMetadata(com.google.android.exoplayer2.extractor.FlacStreamMetadata)

Example 3 with FlacStreamMetadata

use of com.google.android.exoplayer2.extractor.FlacStreamMetadata in project ExoPlayer by google.

the class FlacMetadataReaderTest method readMetadataBlock_streamInfoBlock_setsStreamMetadata.

@Test
public void readMetadataBlock_streamInfoBlock_setsStreamMetadata() throws Exception {
    ExtractorInput input = buildExtractorInput("media/flac/bear.flac");
    input.skipFully(FlacConstants.STREAM_MARKER_SIZE);
    FlacStreamMetadataHolder metadataHolder = new FlacStreamMetadataHolder(/* flacStreamMetadata= */
    null);
    FlacMetadataReader.readMetadataBlock(input, metadataHolder);
    assertThat(metadataHolder.flacStreamMetadata).isNotNull();
    assertThat(metadataHolder.flacStreamMetadata.sampleRate).isEqualTo(48000);
}
Also used : FlacStreamMetadataHolder(com.google.android.exoplayer2.extractor.FlacMetadataReader.FlacStreamMetadataHolder) FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput) Test(org.junit.Test)

Example 4 with FlacStreamMetadata

use of com.google.android.exoplayer2.extractor.FlacStreamMetadata in project ExoPlayer by google.

the class FlacMetadataReaderTest method readMetadataBlock_updatesReadPositionAndAlignsPeekPosition.

@Test
public void readMetadataBlock_updatesReadPositionAndAlignsPeekPosition() throws Exception {
    ExtractorInput input = buildExtractorInput("media/flac/bear.flac");
    input.skipFully(FlacConstants.STREAM_MARKER_SIZE);
    // Advance peek position after metadata block.
    input.advancePeekPosition(FlacConstants.STREAM_INFO_BLOCK_SIZE + 1);
    FlacMetadataReader.readMetadataBlock(input, new FlacStreamMetadataHolder(/* flacStreamMetadata= */
    null));
    assertThat(input.getPosition()).isNotEqualTo(0);
    assertThat(input.getPeekPosition()).isEqualTo(input.getPosition());
}
Also used : FlacStreamMetadataHolder(com.google.android.exoplayer2.extractor.FlacMetadataReader.FlacStreamMetadataHolder) FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput) Test(org.junit.Test)

Example 5 with FlacStreamMetadata

use of com.google.android.exoplayer2.extractor.FlacStreamMetadata in project ExoPlayer by google.

the class FlacMetadataReaderTest method readMetadataBlock_nonStreamInfoBlockWithNullStreamMetadata_throwsException.

@Test
public void readMetadataBlock_nonStreamInfoBlockWithNullStreamMetadata_throwsException() throws Exception {
    ExtractorInput input = buildExtractorInput("media/flac/bear.flac");
    // Skip to seek table block.
    input.skipFully(FlacConstants.STREAM_MARKER_SIZE + FlacConstants.STREAM_INFO_BLOCK_SIZE);
    assertThrows(IllegalArgumentException.class, () -> FlacMetadataReader.readMetadataBlock(input, new FlacStreamMetadataHolder(/* flacStreamMetadata= */
    null)));
}
Also used : FlacStreamMetadataHolder(com.google.android.exoplayer2.extractor.FlacMetadataReader.FlacStreamMetadataHolder) FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)20 FlacStreamMetadataHolder (com.google.android.exoplayer2.extractor.FlacMetadataReader.FlacStreamMetadataHolder)16 FakeExtractorInput (com.google.android.exoplayer2.testutil.FakeExtractorInput)16 SampleNumberHolder (com.google.android.exoplayer2.extractor.FlacFrameReader.SampleNumberHolder)9 ParsableByteArray (com.google.android.exoplayer2.util.ParsableByteArray)7 Metadata (com.google.android.exoplayer2.metadata.Metadata)5 Nullable (androidx.annotation.Nullable)4 ArrayList (java.util.ArrayList)4 FlacStreamMetadata (com.google.android.exoplayer2.extractor.FlacStreamMetadata)3 VorbisComment (com.google.android.exoplayer2.metadata.vorbis.VorbisComment)3 Format (com.google.android.exoplayer2.Format)2 OutputFrameHolder (com.google.android.exoplayer2.ext.flac.FlacBinarySearchSeeker.OutputFrameHolder)1 SeekTable (com.google.android.exoplayer2.extractor.FlacStreamMetadata.SeekTable)1 SeekMap (com.google.android.exoplayer2.extractor.SeekMap)1 PictureFrame (com.google.android.exoplayer2.metadata.flac.PictureFrame)1 ParsableBitArray (com.google.android.exoplayer2.util.ParsableBitArray)1 ImmutableList (com.google.common.collect.ImmutableList)1 IOException (java.io.IOException)1 List (java.util.List)1 EnsuresNonNull (org.checkerframework.checker.nullness.qual.EnsuresNonNull)1