Java Code Examples for com.google.android.exoplayer2.util.Util#nullSafeArrayCopy()

The following examples show how to use com.google.android.exoplayer2.util.Util#nullSafeArrayCopy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AdPlaybackState.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/** Returns an instance with the specified ad URI. */
@CheckResult
public AdPlaybackState withAdUri(int adGroupIndex, int adIndexInAdGroup, Uri uri) {
  AdGroup[] adGroups = Util.nullSafeArrayCopy(this.adGroups, this.adGroups.length);
  adGroups[adGroupIndex] = adGroups[adGroupIndex].withAdUri(uri, adIndexInAdGroup);
  return new AdPlaybackState(adGroupTimesUs, adGroups, adResumePositionUs, contentDurationUs);
}
 
Example 2
Source File: AdPlaybackState.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/** Returns an instance with the specified ad marked as played. */
@CheckResult
public AdPlaybackState withPlayedAd(int adGroupIndex, int adIndexInAdGroup) {
  AdGroup[] adGroups = Util.nullSafeArrayCopy(this.adGroups, this.adGroups.length);
  adGroups[adGroupIndex] = adGroups[adGroupIndex].withAdState(AD_STATE_PLAYED, adIndexInAdGroup);
  return new AdPlaybackState(adGroupTimesUs, adGroups, adResumePositionUs, contentDurationUs);
}
 
Example 3
Source File: AdPlaybackState.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/** Returns an instance with the specified ad marked as skipped. */
@CheckResult
public AdPlaybackState withSkippedAd(int adGroupIndex, int adIndexInAdGroup) {
  AdGroup[] adGroups = Util.nullSafeArrayCopy(this.adGroups, this.adGroups.length);
  adGroups[adGroupIndex] = adGroups[adGroupIndex].withAdState(AD_STATE_SKIPPED, adIndexInAdGroup);
  return new AdPlaybackState(adGroupTimesUs, adGroups, adResumePositionUs, contentDurationUs);
}
 
Example 4
Source File: AdPlaybackState.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/** Returns an instance with the specified ad marked as having a load error. */
@CheckResult
public AdPlaybackState withAdLoadError(int adGroupIndex, int adIndexInAdGroup) {
  AdGroup[] adGroups = Util.nullSafeArrayCopy(this.adGroups, this.adGroups.length);
  adGroups[adGroupIndex] = adGroups[adGroupIndex].withAdState(AD_STATE_ERROR, adIndexInAdGroup);
  return new AdPlaybackState(adGroupTimesUs, adGroups, adResumePositionUs, contentDurationUs);
}
 
Example 5
Source File: AdPlaybackState.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * Returns an instance with all ads in the specified ad group skipped (except for those already
 * marked as played or in the error state).
 */
@CheckResult
public AdPlaybackState withSkippedAdGroup(int adGroupIndex) {
  AdGroup[] adGroups = Util.nullSafeArrayCopy(this.adGroups, this.adGroups.length);
  adGroups[adGroupIndex] = adGroups[adGroupIndex].withAllAdsSkipped();
  return new AdPlaybackState(adGroupTimesUs, adGroups, adResumePositionUs, contentDurationUs);
}
 
Example 6
Source File: AdPlaybackState.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/** Returns an instance with the specified ad durations, in microseconds. */
@CheckResult
public AdPlaybackState withAdDurationsUs(long[][] adDurationUs) {
  AdGroup[] adGroups = Util.nullSafeArrayCopy(this.adGroups, this.adGroups.length);
  for (int adGroupIndex = 0; adGroupIndex < adGroupCount; adGroupIndex++) {
    adGroups[adGroupIndex] = adGroups[adGroupIndex].withAdDurationsUs(adDurationUs[adGroupIndex]);
  }
  return new AdPlaybackState(adGroupTimesUs, adGroups, adResumePositionUs, contentDurationUs);
}
 
Example 7
Source File: HlsMediaPeriod.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
@Override
public long selectTracks(
    @NullableType TrackSelection[] selections,
    boolean[] mayRetainStreamFlags,
    @NullableType SampleStream[] streams,
    boolean[] streamResetFlags,
    long positionUs) {
  // Map each selection and stream onto a child period index.
  int[] streamChildIndices = new int[selections.length];
  int[] selectionChildIndices = new int[selections.length];
  for (int i = 0; i < selections.length; i++) {
    streamChildIndices[i] = streams[i] == null ? C.INDEX_UNSET
        : streamWrapperIndices.get(streams[i]);
    selectionChildIndices[i] = C.INDEX_UNSET;
    if (selections[i] != null) {
      TrackGroup trackGroup = selections[i].getTrackGroup();
      for (int j = 0; j < sampleStreamWrappers.length; j++) {
        if (sampleStreamWrappers[j].getTrackGroups().indexOf(trackGroup) != C.INDEX_UNSET) {
          selectionChildIndices[i] = j;
          break;
        }
      }
    }
  }

  boolean forceReset = false;
  streamWrapperIndices.clear();
  // Select tracks for each child, copying the resulting streams back into a new streams array.
  SampleStream[] newStreams = new SampleStream[selections.length];
  @NullableType SampleStream[] childStreams = new SampleStream[selections.length];
  @NullableType TrackSelection[] childSelections = new TrackSelection[selections.length];
  int newEnabledSampleStreamWrapperCount = 0;
  HlsSampleStreamWrapper[] newEnabledSampleStreamWrappers =
      new HlsSampleStreamWrapper[sampleStreamWrappers.length];
  for (int i = 0; i < sampleStreamWrappers.length; i++) {
    for (int j = 0; j < selections.length; j++) {
      childStreams[j] = streamChildIndices[j] == i ? streams[j] : null;
      childSelections[j] = selectionChildIndices[j] == i ? selections[j] : null;
    }
    HlsSampleStreamWrapper sampleStreamWrapper = sampleStreamWrappers[i];
    boolean wasReset = sampleStreamWrapper.selectTracks(childSelections, mayRetainStreamFlags,
        childStreams, streamResetFlags, positionUs, forceReset);
    boolean wrapperEnabled = false;
    for (int j = 0; j < selections.length; j++) {
      SampleStream childStream = childStreams[j];
      if (selectionChildIndices[j] == i) {
        // Assert that the child provided a stream for the selection.
        Assertions.checkNotNull(childStream);
        newStreams[j] = childStream;
        wrapperEnabled = true;
        streamWrapperIndices.put(childStream, i);
      } else if (streamChildIndices[j] == i) {
        // Assert that the child cleared any previous stream.
        Assertions.checkState(childStream == null);
      }
    }
    if (wrapperEnabled) {
      newEnabledSampleStreamWrappers[newEnabledSampleStreamWrapperCount] = sampleStreamWrapper;
      if (newEnabledSampleStreamWrapperCount++ == 0) {
        // The first enabled wrapper is responsible for initializing timestamp adjusters. This
        // way, if enabled, variants are responsible. Else audio renditions. Else text renditions.
        sampleStreamWrapper.setIsTimestampMaster(true);
        if (wasReset || enabledSampleStreamWrappers.length == 0
            || sampleStreamWrapper != enabledSampleStreamWrappers[0]) {
          // The wrapper responsible for initializing the timestamp adjusters was reset or
          // changed. We need to reset the timestamp adjuster provider and all other wrappers.
          timestampAdjusterProvider.reset();
          forceReset = true;
        }
      } else {
        sampleStreamWrapper.setIsTimestampMaster(false);
      }
    }
  }
  // Copy the new streams back into the streams array.
  System.arraycopy(newStreams, 0, streams, 0, newStreams.length);
  // Update the local state.
  enabledSampleStreamWrappers =
      Util.nullSafeArrayCopy(newEnabledSampleStreamWrappers, newEnabledSampleStreamWrapperCount);
  compositeSequenceableLoader =
      compositeSequenceableLoaderFactory.createCompositeSequenceableLoader(
          enabledSampleStreamWrappers);
  return positionUs;
}