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);
}
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;
}
}
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);
}
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());
}
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)));
}
Aggregations