Search in sources :

Example 26 with Format

use of io.atlasmap.v2.Format in project ExoPlayer by google.

the class LibvpxVideoRenderer method onInputFormatChanged.

private void onInputFormatChanged(Format newFormat) throws ExoPlaybackException {
    Format oldFormat = format;
    format = newFormat;
    boolean drmInitDataChanged = !Util.areEqual(format.drmInitData, oldFormat == null ? null : oldFormat.drmInitData);
    if (drmInitDataChanged) {
        if (format.drmInitData != null) {
            if (drmSessionManager == null) {
                throw ExoPlaybackException.createForRenderer(new IllegalStateException("Media requires a DrmSessionManager"), getIndex());
            }
            pendingDrmSession = drmSessionManager.acquireSession(Looper.myLooper(), format.drmInitData);
            if (pendingDrmSession == drmSession) {
                drmSessionManager.releaseSession(pendingDrmSession);
            }
        } else {
            pendingDrmSession = null;
        }
    }
    eventDispatcher.inputFormatChanged(format);
}
Also used : Format(com.google.android.exoplayer2.Format)

Example 27 with Format

use of io.atlasmap.v2.Format in project ExoPlayer by google.

the class AdaptiveTrackSelection method updateSelectedTrack.

@Override
public void updateSelectedTrack(long bufferedDurationUs) {
    long nowMs = SystemClock.elapsedRealtime();
    // Get the current and ideal selections.
    int currentSelectedIndex = selectedIndex;
    Format currentFormat = getSelectedFormat();
    int idealSelectedIndex = determineIdealSelectedIndex(nowMs);
    Format idealFormat = getFormat(idealSelectedIndex);
    // Assume we can switch to the ideal selection.
    selectedIndex = idealSelectedIndex;
    // Revert back to the current selection if conditions are not suitable for switching.
    if (currentFormat != null && !isBlacklisted(selectedIndex, nowMs)) {
        if (idealFormat.bitrate > currentFormat.bitrate && bufferedDurationUs < minDurationForQualityIncreaseUs) {
            // The ideal track is a higher quality, but we have insufficient buffer to safely switch
            // up. Defer switching up for now.
            selectedIndex = currentSelectedIndex;
        } else if (idealFormat.bitrate < currentFormat.bitrate && bufferedDurationUs >= maxDurationForQualityDecreaseUs) {
            // The ideal track is a lower quality, but we have sufficient buffer to defer switching
            // down for now.
            selectedIndex = currentSelectedIndex;
        }
    }
    // If we adapted, update the trigger.
    if (selectedIndex != currentSelectedIndex) {
        reason = C.SELECTION_REASON_ADAPTIVE;
    }
}
Also used : Format(com.google.android.exoplayer2.Format)

Example 28 with Format

use of io.atlasmap.v2.Format in project ExoPlayer by google.

the class AdaptiveTrackSelection method determineIdealSelectedIndex.

/**
   * Computes the ideal selected index ignoring buffer health.
   *
   * @param nowMs The current time in the timebase of {@link SystemClock#elapsedRealtime()}, or
   *     {@link Long#MIN_VALUE} to ignore blacklisting.
   */
private int determineIdealSelectedIndex(long nowMs) {
    long bitrateEstimate = bandwidthMeter.getBitrateEstimate();
    long effectiveBitrate = bitrateEstimate == BandwidthMeter.NO_ESTIMATE ? maxInitialBitrate : (long) (bitrateEstimate * bandwidthFraction);
    int lowestBitrateNonBlacklistedIndex = 0;
    for (int i = 0; i < length; i++) {
        if (nowMs == Long.MIN_VALUE || !isBlacklisted(i, nowMs)) {
            Format format = getFormat(i);
            if (format.bitrate <= effectiveBitrate) {
                return i;
            } else {
                lowestBitrateNonBlacklistedIndex = i;
            }
        }
    }
    return lowestBitrateNonBlacklistedIndex;
}
Also used : Format(com.google.android.exoplayer2.Format)

Example 29 with Format

use of io.atlasmap.v2.Format in project ExoPlayer by google.

the class DefaultTrackSelector method selectAudioTrack.

// Audio track selection implementation.
protected TrackSelection selectAudioTrack(TrackGroupArray groups, int[][] formatSupport, String preferredAudioLanguage, boolean exceedRendererCapabilitiesIfNecessary) {
    TrackGroup selectedGroup = null;
    int selectedTrackIndex = 0;
    int selectedTrackScore = 0;
    for (int groupIndex = 0; groupIndex < groups.length; groupIndex++) {
        TrackGroup trackGroup = groups.get(groupIndex);
        int[] trackFormatSupport = formatSupport[groupIndex];
        for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
            if (isSupported(trackFormatSupport[trackIndex], exceedRendererCapabilitiesIfNecessary)) {
                Format format = trackGroup.getFormat(trackIndex);
                boolean isDefault = (format.selectionFlags & C.SELECTION_FLAG_DEFAULT) != 0;
                int trackScore;
                if (formatHasLanguage(format, preferredAudioLanguage)) {
                    if (isDefault) {
                        trackScore = 4;
                    } else {
                        trackScore = 3;
                    }
                } else if (isDefault) {
                    trackScore = 2;
                } else {
                    trackScore = 1;
                }
                if (isSupported(trackFormatSupport[trackIndex], false)) {
                    trackScore += WITHIN_RENDERER_CAPABILITIES_BONUS;
                }
                if (trackScore > selectedTrackScore) {
                    selectedGroup = trackGroup;
                    selectedTrackIndex = trackIndex;
                    selectedTrackScore = trackScore;
                }
            }
        }
    }
    return selectedGroup == null ? null : new FixedTrackSelection(selectedGroup, selectedTrackIndex);
}
Also used : Format(com.google.android.exoplayer2.Format) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) Point(android.graphics.Point)

Example 30 with Format

use of io.atlasmap.v2.Format in project ExoPlayer by google.

the class DefaultTrackSelector method selectOtherTrack.

// General track selection methods.
protected TrackSelection selectOtherTrack(int trackType, TrackGroupArray groups, int[][] formatSupport, boolean exceedRendererCapabilitiesIfNecessary) {
    TrackGroup selectedGroup = null;
    int selectedTrackIndex = 0;
    int selectedTrackScore = 0;
    for (int groupIndex = 0; groupIndex < groups.length; groupIndex++) {
        TrackGroup trackGroup = groups.get(groupIndex);
        int[] trackFormatSupport = formatSupport[groupIndex];
        for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
            if (isSupported(trackFormatSupport[trackIndex], exceedRendererCapabilitiesIfNecessary)) {
                Format format = trackGroup.getFormat(trackIndex);
                boolean isDefault = (format.selectionFlags & C.SELECTION_FLAG_DEFAULT) != 0;
                int trackScore = isDefault ? 2 : 1;
                if (isSupported(trackFormatSupport[trackIndex], false)) {
                    trackScore += WITHIN_RENDERER_CAPABILITIES_BONUS;
                }
                if (trackScore > selectedTrackScore) {
                    selectedGroup = trackGroup;
                    selectedTrackIndex = trackIndex;
                    selectedTrackScore = trackScore;
                }
            }
        }
    }
    return selectedGroup == null ? null : new FixedTrackSelection(selectedGroup, selectedTrackIndex);
}
Also used : Format(com.google.android.exoplayer2.Format) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) Point(android.graphics.Point)

Aggregations

Format (com.google.android.exoplayer2.Format)38 AtlasMapping (io.atlasmap.v2.AtlasMapping)7 Point (android.graphics.Point)6 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)6 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 Validation (io.atlasmap.v2.Validation)4 AtlasMappingUtil (io.atlasmap.core.AtlasMappingUtil)3 DefaultAtlasConversionService (io.atlasmap.core.DefaultAtlasConversionService)3 AtlasModuleDetail (io.atlasmap.spi.AtlasModuleDetail)3 AtlasModuleMode (io.atlasmap.spi.AtlasModuleMode)3 AtlasModelFactory (io.atlasmap.v2.AtlasModelFactory)3 DataSource (io.atlasmap.v2.DataSource)3 DataSourceType (io.atlasmap.v2.DataSourceType)3 FieldType (io.atlasmap.v2.FieldType)3 Mapping (io.atlasmap.v2.Mapping)3 MappingType (io.atlasmap.v2.MappingType)3 MockField (io.atlasmap.v2.MockField)3 ValidationScope (io.atlasmap.v2.ValidationScope)3 ValidationStatus (io.atlasmap.v2.ValidationStatus)3