Search in sources :

Example 21 with Format

use of org.geotoolkit.wps.xml.v200.Format in project ExoPlayer by google.

the class MediaFormatUtilTest method createMediaFormatFromFormat_withPopulatedFormat_generatesExpectedEntries.

@Test
public void createMediaFormatFromFormat_withPopulatedFormat_generatesExpectedEntries() {
    Format format = new Format.Builder().setAverageBitrate(1).setChannelCount(2).setColorInfo(new ColorInfo(/* colorSpace= */
    C.COLOR_SPACE_BT601, /* colorRange= */
    C.COLOR_RANGE_FULL, /* colorTransfer= */
    C.COLOR_TRANSFER_HLG, new byte[] { 3 })).setSampleMimeType(MimeTypes.VIDEO_H264).setCodecs("avc.123").setFrameRate(4).setWidth(5).setHeight(6).setInitializationData(ImmutableList.of(new byte[] { 7 }, new byte[] { 8 })).setPcmEncoding(C.ENCODING_PCM_8BIT).setLanguage("en").setMaxInputSize(9).setRotationDegrees(10).setSampleRate(11).setAccessibilityChannel(12).setSelectionFlags(C.SELECTION_FLAG_AUTOSELECT | C.SELECTION_FLAG_DEFAULT | C.SELECTION_FLAG_FORCED).setEncoderDelay(13).setEncoderPadding(14).setPixelWidthHeightRatio(.5f).build();
    MediaFormat mediaFormat = MediaFormatUtil.createMediaFormatFromFormat(format);
    assertThat(mediaFormat.getInteger(MediaFormat.KEY_BIT_RATE)).isEqualTo(format.bitrate);
    assertThat(mediaFormat.getInteger(MediaFormat.KEY_CHANNEL_COUNT)).isEqualTo(format.channelCount);
    ColorInfo colorInfo = Assertions.checkNotNull(format.colorInfo);
    assertThat(mediaFormat.getInteger(MediaFormat.KEY_COLOR_TRANSFER)).isEqualTo(colorInfo.colorTransfer);
    assertThat(mediaFormat.getInteger(MediaFormat.KEY_COLOR_RANGE)).isEqualTo(colorInfo.colorRange);
    assertThat(mediaFormat.getInteger(MediaFormat.KEY_COLOR_STANDARD)).isEqualTo(colorInfo.colorSpace);
    assertThat(mediaFormat.getByteBuffer(MediaFormat.KEY_HDR_STATIC_INFO).array()).isEqualTo(colorInfo.hdrStaticInfo);
    assertThat(mediaFormat.getString(MediaFormat.KEY_MIME)).isEqualTo(format.sampleMimeType);
    assertThat(mediaFormat.getString(MediaFormat.KEY_CODECS_STRING)).isEqualTo(format.codecs);
    assertThat(mediaFormat.getFloat(MediaFormat.KEY_FRAME_RATE)).isEqualTo(format.frameRate);
    assertThat(mediaFormat.getInteger(MediaFormat.KEY_WIDTH)).isEqualTo(format.width);
    assertThat(mediaFormat.getInteger(MediaFormat.KEY_HEIGHT)).isEqualTo(format.height);
    assertThat(mediaFormat.getByteBuffer("csd-0").array()).isEqualTo(format.initializationData.get(0));
    assertThat(mediaFormat.getByteBuffer("csd-1").array()).isEqualTo(format.initializationData.get(1));
    assertThat(mediaFormat.getInteger(MediaFormat.KEY_PCM_ENCODING)).isEqualTo(format.pcmEncoding);
    assertThat(mediaFormat.getInteger(MediaFormatUtil.KEY_PCM_ENCODING_EXTENDED)).isEqualTo(format.pcmEncoding);
    assertThat(mediaFormat.getString(MediaFormat.KEY_LANGUAGE)).isEqualTo(format.language);
    assertThat(mediaFormat.getInteger(MediaFormat.KEY_MAX_INPUT_SIZE)).isEqualTo(format.maxInputSize);
    assertThat(mediaFormat.getInteger(MediaFormat.KEY_ROTATION)).isEqualTo(format.rotationDegrees);
    assertThat(mediaFormat.getInteger(MediaFormat.KEY_SAMPLE_RATE)).isEqualTo(format.sampleRate);
    assertThat(mediaFormat.getInteger(MediaFormat.KEY_CAPTION_SERVICE_NUMBER)).isEqualTo(format.accessibilityChannel);
    assertThat(mediaFormat.getInteger(MediaFormat.KEY_IS_AUTOSELECT)).isNotEqualTo(0);
    assertThat(mediaFormat.getInteger(MediaFormat.KEY_IS_DEFAULT)).isNotEqualTo(0);
    assertThat(mediaFormat.getInteger(MediaFormat.KEY_IS_FORCED_SUBTITLE)).isNotEqualTo(0);
    assertThat(mediaFormat.getInteger(MediaFormat.KEY_ENCODER_DELAY)).isEqualTo(format.encoderDelay);
    assertThat(mediaFormat.getInteger(MediaFormat.KEY_ENCODER_PADDING)).isEqualTo(format.encoderPadding);
    float calculatedPixelAspectRatio = (float) mediaFormat.getInteger(MediaFormat.KEY_PIXEL_ASPECT_RATIO_WIDTH) / mediaFormat.getInteger(MediaFormat.KEY_PIXEL_ASPECT_RATIO_HEIGHT);
    assertThat(calculatedPixelAspectRatio).isWithin(.0001f).of(format.pixelWidthHeightRatio);
    assertThat(mediaFormat.getFloat(MediaFormatUtil.KEY_PIXEL_WIDTH_HEIGHT_RATIO_FLOAT)).isEqualTo(format.pixelWidthHeightRatio);
}
Also used : MediaFormat(android.media.MediaFormat) Format(com.google.android.exoplayer2.Format) MediaFormat(android.media.MediaFormat) ColorInfo(com.google.android.exoplayer2.video.ColorInfo) Test(org.junit.Test)

Example 22 with Format

use of org.geotoolkit.wps.xml.v200.Format in project ExoPlayer by google.

the class TrackGroupTest method roundTripViaBundle_ofTrackGroup_yieldsEqualInstance.

@Test
public void roundTripViaBundle_ofTrackGroup_yieldsEqualInstance() {
    Format.Builder formatBuilder = new Format.Builder();
    Format format1 = formatBuilder.setSampleMimeType(MimeTypes.VIDEO_H264).build();
    Format format2 = formatBuilder.setSampleMimeType(MimeTypes.AUDIO_AAC).build();
    String id = "abc";
    TrackGroup trackGroupToBundle = new TrackGroup(id, format1, format2);
    TrackGroup trackGroupFromBundle = TrackGroup.CREATOR.fromBundle(trackGroupToBundle.toBundle());
    assertThat(trackGroupFromBundle).isEqualTo(trackGroupToBundle);
}
Also used : Format(com.google.android.exoplayer2.Format) Test(org.junit.Test)

Example 23 with Format

use of org.geotoolkit.wps.xml.v200.Format 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 24 with Format

use of org.geotoolkit.wps.xml.v200.Format 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 25 with Format

use of org.geotoolkit.wps.xml.v200.Format in project ExoPlayer by google.

the class ProgressiveMediaPeriod method maybeFinishPrepare.

private void maybeFinishPrepare() {
    if (released || prepared || !sampleQueuesBuilt || seekMap == null) {
        return;
    }
    for (SampleQueue sampleQueue : sampleQueues) {
        if (sampleQueue.getUpstreamFormat() == null) {
            return;
        }
    }
    loadCondition.close();
    int trackCount = sampleQueues.length;
    TrackGroup[] trackArray = new TrackGroup[trackCount];
    boolean[] trackIsAudioVideoFlags = new boolean[trackCount];
    for (int i = 0; i < trackCount; i++) {
        Format trackFormat = Assertions.checkNotNull(sampleQueues[i].getUpstreamFormat());
        @Nullable String mimeType = trackFormat.sampleMimeType;
        boolean isAudio = MimeTypes.isAudio(mimeType);
        boolean isAudioVideo = isAudio || MimeTypes.isVideo(mimeType);
        trackIsAudioVideoFlags[i] = isAudioVideo;
        haveAudioVideoTracks |= isAudioVideo;
        @Nullable IcyHeaders icyHeaders = this.icyHeaders;
        if (icyHeaders != null) {
            if (isAudio || sampleQueueTrackIds[i].isIcyTrack) {
                @Nullable Metadata metadata = trackFormat.metadata;
                if (metadata == null) {
                    metadata = new Metadata(icyHeaders);
                } else {
                    metadata = metadata.copyWithAppendedEntries(icyHeaders);
                }
                trackFormat = trackFormat.buildUpon().setMetadata(metadata).build();
            }
            // an average or peak bitrate of its own.
            if (isAudio && trackFormat.averageBitrate == Format.NO_VALUE && trackFormat.peakBitrate == Format.NO_VALUE && icyHeaders.bitrate != Format.NO_VALUE) {
                trackFormat = trackFormat.buildUpon().setAverageBitrate(icyHeaders.bitrate).build();
            }
        }
        trackFormat = trackFormat.copyWithCryptoType(drmSessionManager.getCryptoType(trackFormat));
        trackArray[i] = new TrackGroup(/* id= */
        Integer.toString(i), trackFormat);
    }
    trackState = new TrackState(new TrackGroupArray(trackArray), trackIsAudioVideoFlags);
    prepared = true;
    Assertions.checkNotNull(callback).onPrepared(this);
}
Also used : Metadata(com.google.android.exoplayer2.metadata.Metadata) IcyHeaders(com.google.android.exoplayer2.metadata.icy.IcyHeaders) Format(com.google.android.exoplayer2.Format) Nullable(androidx.annotation.Nullable)

Aggregations

Format (com.google.android.exoplayer2.Format)313 Test (org.junit.Test)132 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)66 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)60 Nullable (androidx.annotation.Nullable)47 RendererCapabilities (com.google.android.exoplayer2.RendererCapabilities)37 ArrayList (java.util.ArrayList)31 MediaFormat (android.media.MediaFormat)24 Data (org.geotoolkit.wps.xml.v200.Data)19 HashMap (java.util.HashMap)16 Format (org.geotoolkit.wps.xml.v200.Format)16 SuppressLint (android.annotation.SuppressLint)15 Point (android.graphics.Point)15 Capabilities (com.google.android.exoplayer2.RendererCapabilities.Capabilities)12 UnconvertibleObjectException (org.apache.sis.util.UnconvertibleObjectException)12 DecoderReuseEvaluation (com.google.android.exoplayer2.decoder.DecoderReuseEvaluation)11 Metadata (com.google.android.exoplayer2.metadata.Metadata)11 ImmutableList (com.google.common.collect.ImmutableList)11 ComplexData (org.geotoolkit.wps.xml.v200.ComplexData)9 C (com.google.android.exoplayer2.C)8