Search in sources :

Example 1 with AudioFormat

use of com.google.android.exoplayer2.audio.AudioProcessor.AudioFormat in project ExoPlayer by google.

the class DefaultTrackSelectorTest method selectTracksSelectTrackWithSelectionFlag.

/**
 * Tests that track selector will select audio track with {@link C#SELECTION_FLAG_DEFAULT} given
 * default values of {@link Parameters}.
 */
@Test
public void selectTracksSelectTrackWithSelectionFlag() throws Exception {
    Format.Builder formatBuilder = AUDIO_FORMAT.buildUpon();
    Format audioFormat = formatBuilder.setSelectionFlags(0).build();
    Format formatWithSelectionFlag = formatBuilder.setSelectionFlags(C.SELECTION_FLAG_DEFAULT).build();
    TrackGroupArray trackGroups = wrapFormats(audioFormat, formatWithSelectionFlag);
    TrackSelectorResult result = trackSelector.selectTracks(new RendererCapabilities[] { ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES }, trackGroups, periodId, TIMELINE);
    assertFixedSelection(result.selections[0], trackGroups, formatWithSelectionFlag);
}
Also used : Format(com.google.android.exoplayer2.Format) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) Test(org.junit.Test)

Example 2 with AudioFormat

use of com.google.android.exoplayer2.audio.AudioProcessor.AudioFormat in project ExoPlayer by google.

the class SonicAudioProcessorTest method doesNotSupportNon16BitInput.

@Test
public void doesNotSupportNon16BitInput() throws Exception {
    try {
        sonicAudioProcessor.configure(new AudioFormat(/* sampleRate= */
        44100, /* channelCount= */
        2, /* encoding= */
        C.ENCODING_PCM_8BIT));
        fail();
    } catch (UnhandledAudioFormatException e) {
    // Expected.
    }
    try {
        sonicAudioProcessor.configure(new AudioFormat(/* sampleRate= */
        44100, /* channelCount= */
        2, /* encoding= */
        C.ENCODING_PCM_24BIT));
        fail();
    } catch (UnhandledAudioFormatException e) {
    // Expected.
    }
    try {
        sonicAudioProcessor.configure(new AudioFormat(/* sampleRate= */
        44100, /* channelCount= */
        2, /* encoding= */
        C.ENCODING_PCM_32BIT));
        fail();
    } catch (UnhandledAudioFormatException e) {
    // Expected.
    }
}
Also used : UnhandledAudioFormatException(com.google.android.exoplayer2.audio.AudioProcessor.UnhandledAudioFormatException) AudioFormat(com.google.android.exoplayer2.audio.AudioProcessor.AudioFormat) Test(org.junit.Test)

Example 3 with AudioFormat

use of com.google.android.exoplayer2.audio.AudioProcessor.AudioFormat in project ExoPlayer by google.

the class AudioTagPayloadReader method parseHeader.

@Override
protected boolean parseHeader(ParsableByteArray data) throws UnsupportedFormatException {
    if (!hasParsedAudioDataHeader) {
        int header = data.readUnsignedByte();
        audioFormat = (header >> 4) & 0x0F;
        if (audioFormat == AUDIO_FORMAT_MP3) {
            int sampleRateIndex = (header >> 2) & 0x03;
            int sampleRate = AUDIO_SAMPLING_RATE_TABLE[sampleRateIndex];
            Format format = new Format.Builder().setSampleMimeType(MimeTypes.AUDIO_MPEG).setChannelCount(1).setSampleRate(sampleRate).build();
            output.format(format);
            hasOutputFormat = true;
        } else if (audioFormat == AUDIO_FORMAT_ALAW || audioFormat == AUDIO_FORMAT_ULAW) {
            String mimeType = audioFormat == AUDIO_FORMAT_ALAW ? MimeTypes.AUDIO_ALAW : MimeTypes.AUDIO_MLAW;
            Format format = new Format.Builder().setSampleMimeType(mimeType).setChannelCount(1).setSampleRate(8000).build();
            output.format(format);
            hasOutputFormat = true;
        } else if (audioFormat != AUDIO_FORMAT_AAC) {
            throw new UnsupportedFormatException("Audio format not supported: " + audioFormat);
        }
        hasParsedAudioDataHeader = true;
    } else {
        // Skip header if it was parsed previously.
        data.skipBytes(1);
    }
    return true;
}
Also used : Format(com.google.android.exoplayer2.Format)

Example 4 with AudioFormat

use of com.google.android.exoplayer2.audio.AudioProcessor.AudioFormat in project ExoPlayer by google.

the class AudioTagPayloadReader method parsePayload.

@Override
protected boolean parsePayload(ParsableByteArray data, long timeUs) throws ParserException {
    if (audioFormat == AUDIO_FORMAT_MP3) {
        int sampleSize = data.bytesLeft();
        output.sampleData(data, sampleSize);
        output.sampleMetadata(timeUs, C.BUFFER_FLAG_KEY_FRAME, sampleSize, 0, null);
        return true;
    } else {
        int packetType = data.readUnsignedByte();
        if (packetType == AAC_PACKET_TYPE_SEQUENCE_HEADER && !hasOutputFormat) {
            // Parse the sequence header.
            byte[] audioSpecificConfig = new byte[data.bytesLeft()];
            data.readBytes(audioSpecificConfig, 0, audioSpecificConfig.length);
            AacUtil.Config aacConfig = AacUtil.parseAudioSpecificConfig(audioSpecificConfig);
            Format format = new Format.Builder().setSampleMimeType(MimeTypes.AUDIO_AAC).setCodecs(aacConfig.codecs).setChannelCount(aacConfig.channelCount).setSampleRate(aacConfig.sampleRateHz).setInitializationData(Collections.singletonList(audioSpecificConfig)).build();
            output.format(format);
            hasOutputFormat = true;
            return false;
        } else if (audioFormat != AUDIO_FORMAT_AAC || packetType == AAC_PACKET_TYPE_AAC_RAW) {
            int sampleSize = data.bytesLeft();
            output.sampleData(data, sampleSize);
            output.sampleMetadata(timeUs, C.BUFFER_FLAG_KEY_FRAME, sampleSize, 0, null);
            return true;
        } else {
            return false;
        }
    }
}
Also used : AacUtil(com.google.android.exoplayer2.audio.AacUtil) Format(com.google.android.exoplayer2.Format)

Example 5 with AudioFormat

use of com.google.android.exoplayer2.audio.AudioProcessor.AudioFormat in project ExoPlayer by google.

the class MediaMetricsListener method maybeReportTrackChanges.

private void maybeReportTrackChanges(Player player, Events events, long realtimeMs) {
    if (events.contains(EVENT_TRACKS_CHANGED)) {
        TracksInfo tracksInfo = player.getCurrentTracksInfo();
        boolean isVideoSelected = tracksInfo.isTypeSelected(C.TRACK_TYPE_VIDEO);
        boolean isAudioSelected = tracksInfo.isTypeSelected(C.TRACK_TYPE_AUDIO);
        boolean isTextSelected = tracksInfo.isTypeSelected(C.TRACK_TYPE_TEXT);
        if (isVideoSelected || isAudioSelected || isTextSelected) {
            // Ignore updates with insufficient information where no tracks are selected.
            if (!isVideoSelected) {
                maybeUpdateVideoFormat(realtimeMs, /* videoFormat= */
                null, C.SELECTION_REASON_UNKNOWN);
            }
            if (!isAudioSelected) {
                maybeUpdateAudioFormat(realtimeMs, /* audioFormat= */
                null, C.SELECTION_REASON_UNKNOWN);
            }
            if (!isTextSelected) {
                maybeUpdateTextFormat(realtimeMs, /* textFormat= */
                null, C.SELECTION_REASON_UNKNOWN);
            }
        }
    }
    if (canReportPendingFormatUpdate(pendingVideoFormat) && pendingVideoFormat.format.height != Format.NO_VALUE) {
        maybeUpdateVideoFormat(realtimeMs, pendingVideoFormat.format, pendingVideoFormat.selectionReason);
        pendingVideoFormat = null;
    }
    if (canReportPendingFormatUpdate(pendingAudioFormat)) {
        maybeUpdateAudioFormat(realtimeMs, pendingAudioFormat.format, pendingAudioFormat.selectionReason);
        pendingAudioFormat = null;
    }
    if (canReportPendingFormatUpdate(pendingTextFormat)) {
        maybeUpdateTextFormat(realtimeMs, pendingTextFormat.format, pendingTextFormat.selectionReason);
        pendingTextFormat = null;
    }
}
Also used : TracksInfo(com.google.android.exoplayer2.TracksInfo)

Aggregations

Format (com.google.android.exoplayer2.Format)3 Test (org.junit.Test)3 AudioFormat (com.google.android.exoplayer2.audio.AudioProcessor.AudioFormat)2 TracksInfo (com.google.android.exoplayer2.TracksInfo)1 AacUtil (com.google.android.exoplayer2.audio.AacUtil)1 UnhandledAudioFormatException (com.google.android.exoplayer2.audio.AudioProcessor.UnhandledAudioFormatException)1 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)1