Search in sources :

Example 36 with Format

use of com.google.android.exoplayer2.Format in project AntennaPod by AntennaPod.

the class ExoPlayerWrapper method getAudioTracks.

@Override
public List<String> getAudioTracks() {
    List<String> trackNames = new ArrayList<>();
    TrackNameProvider trackNameProvider = new DefaultTrackNameProvider(context.getResources());
    for (Format format : getFormats()) {
        trackNames.add(trackNameProvider.getTrackName(format));
    }
    return trackNames;
}
Also used : DefaultTrackNameProvider(com.google.android.exoplayer2.ui.DefaultTrackNameProvider) Format(com.google.android.exoplayer2.Format) ArrayList(java.util.ArrayList) DefaultTrackNameProvider(com.google.android.exoplayer2.ui.DefaultTrackNameProvider) TrackNameProvider(com.google.android.exoplayer2.ui.TrackNameProvider)

Example 37 with Format

use of com.google.android.exoplayer2.Format in project AntennaPod by AntennaPod.

the class ExoPlayerWrapper method getFormats.

private List<Format> getFormats() {
    List<Format> formats = new ArrayList<>();
    MappingTrackSelector.MappedTrackInfo trackInfo = trackSelector.getCurrentMappedTrackInfo();
    if (trackInfo == null) {
        return Collections.emptyList();
    }
    TrackGroupArray trackGroups = trackInfo.getTrackGroups(getAudioRendererIndex());
    for (int i = 0; i < trackGroups.length; i++) {
        formats.add(trackGroups.get(i).getFormat(0));
    }
    return formats;
}
Also used : Format(com.google.android.exoplayer2.Format) MappingTrackSelector(com.google.android.exoplayer2.trackselection.MappingTrackSelector) ArrayList(java.util.ArrayList) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray)

Example 38 with Format

use of com.google.android.exoplayer2.Format in project ExoPlayer by google.

the class AudioTagPayloadReader method parsePayload.

@Override
protected void parsePayload(ParsableByteArray data, long timeUs) {
    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);
        Pair<Integer, Integer> audioParams = CodecSpecificDataUtil.parseAacAudioSpecificConfig(audioSpecificConfig);
        Format format = Format.createAudioSampleFormat(null, MimeTypes.AUDIO_AAC, null, Format.NO_VALUE, Format.NO_VALUE, audioParams.second, audioParams.first, Collections.singletonList(audioSpecificConfig), null, 0, null);
        output.format(format);
        hasOutputFormat = true;
    } 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);
    }
}
Also used : Format(com.google.android.exoplayer2.Format)

Example 39 with Format

use of com.google.android.exoplayer2.Format in project ExoPlayer by google.

the class Format method copyWithManifestFormatInfo.

public Format copyWithManifestFormatInfo(Format manifestFormat) {
    if (this == manifestFormat) {
        // No need to copy from ourselves.
        return this;
    }
    String id = manifestFormat.id;
    String codecs = this.codecs == null ? manifestFormat.codecs : this.codecs;
    int bitrate = this.bitrate == NO_VALUE ? manifestFormat.bitrate : this.bitrate;
    float frameRate = this.frameRate == NO_VALUE ? manifestFormat.frameRate : this.frameRate;
    @C.SelectionFlags int selectionFlags = this.selectionFlags | manifestFormat.selectionFlags;
    String language = this.language == null ? manifestFormat.language : this.language;
    DrmInitData drmInitData = manifestFormat.drmInitData != null ? manifestFormat.drmInitData : this.drmInitData;
    return new Format(id, containerMimeType, sampleMimeType, codecs, bitrate, maxInputSize, width, height, frameRate, rotationDegrees, pixelWidthHeightRatio, projectionData, stereoMode, channelCount, sampleRate, pcmEncoding, encoderDelay, encoderPadding, selectionFlags, language, accessibilityChannel, subsampleOffsetUs, initializationData, drmInitData, metadata);
}
Also used : DrmInitData(com.google.android.exoplayer2.drm.DrmInitData) MediaFormat(android.media.MediaFormat) SuppressLint(android.annotation.SuppressLint)

Example 40 with Format

use of com.google.android.exoplayer2.Format in project ExoPlayer by google.

the class SimpleDecoderAudioRenderer method onInputFormatChanged.

private void onInputFormatChanged(Format newFormat) throws ExoPlaybackException {
    Format oldFormat = inputFormat;
    inputFormat = newFormat;
    boolean drmInitDataChanged = !Util.areEqual(inputFormat.drmInitData, oldFormat == null ? null : oldFormat.drmInitData);
    if (drmInitDataChanged) {
        if (inputFormat.drmInitData != null) {
            if (drmSessionManager == null) {
                throw ExoPlaybackException.createForRenderer(new IllegalStateException("Media requires a DrmSessionManager"), getIndex());
            }
            pendingDrmSession = drmSessionManager.acquireSession(Looper.myLooper(), inputFormat.drmInitData);
            if (pendingDrmSession == drmSession) {
                drmSessionManager.releaseSession(pendingDrmSession);
            }
        } else {
            pendingDrmSession = null;
        }
    }
    if (decoderReceivedBuffers) {
        // Signal end of stream and wait for any final output buffers before re-initialization.
        decoderReinitializationState = REINITIALIZATION_STATE_SIGNAL_END_OF_STREAM;
    } else {
        // There aren't any final output buffers, so release the decoder immediately.
        releaseDecoder();
        maybeInitDecoder();
        audioTrackNeedsConfigure = true;
    }
    eventDispatcher.inputFormatChanged(newFormat);
}
Also used : Format(com.google.android.exoplayer2.Format)

Aggregations

Format (com.google.android.exoplayer2.Format)44 Point (android.graphics.Point)8 ArrayList (java.util.ArrayList)8 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)7 DataSpec (com.google.android.exoplayer2.upstream.DataSpec)5 SuppressLint (android.annotation.SuppressLint)4 MediaFormat (android.media.MediaFormat)4 ParserException (com.google.android.exoplayer2.ParserException)4 DrmInitData (com.google.android.exoplayer2.drm.DrmInitData)4 ParsableByteArray (com.google.android.exoplayer2.util.ParsableByteArray)4 TrackOutput (com.google.android.exoplayer2.extractor.TrackOutput)3 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)3 Representation (com.google.android.exoplayer2.source.dash.manifest.Representation)3 SchemeData (com.google.android.exoplayer2.drm.DrmInitData.SchemeData)2 MediaCodecInfo (com.google.android.exoplayer2.mediacodec.MediaCodecInfo)2 Metadata (com.google.android.exoplayer2.metadata.Metadata)2 ContainerMediaChunk (com.google.android.exoplayer2.source.chunk.ContainerMediaChunk)2 AdaptationSet (com.google.android.exoplayer2.source.dash.manifest.AdaptationSet)2 RangedUri (com.google.android.exoplayer2.source.dash.manifest.RangedUri)2 SingleSegmentBase (com.google.android.exoplayer2.source.dash.manifest.SegmentBase.SingleSegmentBase)2