Java Code Examples for com.google.android.exoplayer2.util.Assertions#checkIndex()

The following examples show how to use com.google.android.exoplayer2.util.Assertions#checkIndex() . 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: DashMediaSource.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Window getWindow(
    int windowIndex, Window window, boolean setTag, long defaultPositionProjectionUs) {
  Assertions.checkIndex(windowIndex, 0, 1);
  long windowDefaultStartPositionUs = getAdjustedWindowDefaultStartPositionUs(
      defaultPositionProjectionUs);
  Object tag = setTag ? windowTag : null;
  boolean isDynamic =
      manifest.dynamic
          && manifest.minUpdatePeriodMs != C.TIME_UNSET
          && manifest.durationMs == C.TIME_UNSET;
  return window.set(
      tag,
      presentationStartTimeMs,
      windowStartTimeMs,
      /* isSeekable= */ true,
      isDynamic,
      windowDefaultStartPositionUs,
      windowDurationUs,
      /* firstPeriodIndex= */ 0,
      /* lastPeriodIndex= */ getPeriodCount() - 1,
      offsetInFirstPeriodUs);
}
 
Example 2
Source File: Timeline.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Converts (windowIndex, windowPositionUs) to the corresponding (periodUid, periodPositionUs).
 *
 * @param window A {@link Window} that may be overwritten.
 * @param period A {@link Period} that may be overwritten.
 * @param windowIndex The window index.
 * @param windowPositionUs The window time, or {@link C#TIME_UNSET} to use the window's default
 *     start position.
 * @param defaultPositionProjectionUs If {@code windowPositionUs} is {@link C#TIME_UNSET}, the
 *     duration into the future by which the window's position should be projected.
 * @return The corresponding (periodUid, periodPositionUs), or null if {@code #windowPositionUs}
 *     is {@link C#TIME_UNSET}, {@code defaultPositionProjectionUs} is non-zero, and the window's
 *     position could not be projected by {@code defaultPositionProjectionUs}.
 */
@Nullable
public final Pair<Object, Long> getPeriodPosition(
    Window window,
    Period period,
    int windowIndex,
    long windowPositionUs,
    long defaultPositionProjectionUs) {
  Assertions.checkIndex(windowIndex, 0, getWindowCount());
  getWindow(windowIndex, window, false, defaultPositionProjectionUs);
  if (windowPositionUs == C.TIME_UNSET) {
    windowPositionUs = window.getDefaultPositionUs();
    if (windowPositionUs == C.TIME_UNSET) {
      return null;
    }
  }
  int periodIndex = window.firstPeriodIndex;
  long periodPositionUs = window.getPositionInFirstPeriodUs() + windowPositionUs;
  long periodDurationUs = getPeriod(periodIndex, period, /* setIds= */ true).getDurationUs();
  while (periodDurationUs != C.TIME_UNSET && periodPositionUs >= periodDurationUs
      && periodIndex < window.lastPeriodIndex) {
    periodPositionUs -= periodDurationUs;
    periodDurationUs = getPeriod(++periodIndex, period, /* setIds= */ true).getDurationUs();
  }
  return Pair.create(Assertions.checkNotNull(period.uid), periodPositionUs);
}
 
Example 3
Source File: Timeline.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Converts (windowIndex, windowPositionUs) to the corresponding (periodUid, periodPositionUs).
 *
 * @param window A {@link Window} that may be overwritten.
 * @param period A {@link Period} that may be overwritten.
 * @param windowIndex The window index.
 * @param windowPositionUs The window time, or {@link C#TIME_UNSET} to use the window's default
 *     start position.
 * @param defaultPositionProjectionUs If {@code windowPositionUs} is {@link C#TIME_UNSET}, the
 *     duration into the future by which the window's position should be projected.
 * @return The corresponding (periodUid, periodPositionUs), or null if {@code #windowPositionUs}
 *     is {@link C#TIME_UNSET}, {@code defaultPositionProjectionUs} is non-zero, and the window's
 *     position could not be projected by {@code defaultPositionProjectionUs}.
 */
@Nullable
public final Pair<Object, Long> getPeriodPosition(
    Window window,
    Period period,
    int windowIndex,
    long windowPositionUs,
    long defaultPositionProjectionUs) {
  Assertions.checkIndex(windowIndex, 0, getWindowCount());
  getWindow(windowIndex, window, false, defaultPositionProjectionUs);
  if (windowPositionUs == C.TIME_UNSET) {
    windowPositionUs = window.getDefaultPositionUs();
    if (windowPositionUs == C.TIME_UNSET) {
      return null;
    }
  }
  int periodIndex = window.firstPeriodIndex;
  long periodPositionUs = window.getPositionInFirstPeriodUs() + windowPositionUs;
  long periodDurationUs = getPeriod(periodIndex, period, /* setIds= */ true).getDurationUs();
  while (periodDurationUs != C.TIME_UNSET && periodPositionUs >= periodDurationUs
      && periodIndex < window.lastPeriodIndex) {
    periodPositionUs -= periodDurationUs;
    periodDurationUs = getPeriod(++periodIndex, period, /* setIds= */ true).getDurationUs();
  }
  return Pair.create(Assertions.checkNotNull(period.uid), periodPositionUs);
}
 
Example 4
Source File: DashMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Window getWindow(
    int windowIndex, Window window, boolean setTag, long defaultPositionProjectionUs) {
  Assertions.checkIndex(windowIndex, 0, 1);
  long windowDefaultStartPositionUs = getAdjustedWindowDefaultStartPositionUs(
      defaultPositionProjectionUs);
  Object tag = setTag ? windowTag : null;
  return window.set(
      tag,
      presentationStartTimeMs,
      windowStartTimeMs,
      /* isSeekable= */ true,
      manifest.dynamic,
      windowDefaultStartPositionUs,
      windowDurationUs,
      /* firstPeriodIndex= */ 0,
      /* lastPeriodIndex= */ getPeriodCount() - 1,
      offsetInFirstPeriodUs);
}
 
Example 5
Source File: Timeline.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Converts (windowIndex, windowPositionUs) to the corresponding (periodIndex, periodPositionUs).
 *
 * @param window A {@link Window} that may be overwritten.
 * @param period A {@link Period} that may be overwritten.
 * @param windowIndex The window index.
 * @param windowPositionUs The window time, or {@link C#TIME_UNSET} to use the window's default
 *     start position.
 * @param defaultPositionProjectionUs If {@code windowPositionUs} is {@link C#TIME_UNSET}, the
 *     duration into the future by which the window's position should be projected.
 * @return The corresponding (periodIndex, periodPositionUs), or null if {@code #windowPositionUs}
 *     is {@link C#TIME_UNSET}, {@code defaultPositionProjectionUs} is non-zero, and the window's
 *     position could not be projected by {@code defaultPositionProjectionUs}.
 */
public final Pair<Integer, Long> getPeriodPosition(Window window, Period period, int windowIndex,
    long windowPositionUs, long defaultPositionProjectionUs) {
  Assertions.checkIndex(windowIndex, 0, getWindowCount());
  getWindow(windowIndex, window, false, defaultPositionProjectionUs);
  if (windowPositionUs == C.TIME_UNSET) {
    windowPositionUs = window.getDefaultPositionUs();
    if (windowPositionUs == C.TIME_UNSET) {
      return null;
    }
  }
  int periodIndex = window.firstPeriodIndex;
  long periodPositionUs = window.getPositionInFirstPeriodUs() + windowPositionUs;
  long periodDurationUs = getPeriod(periodIndex, period).getDurationUs();
  while (periodDurationUs != C.TIME_UNSET && periodPositionUs >= periodDurationUs
      && periodIndex < window.lastPeriodIndex) {
    periodPositionUs -= periodDurationUs;
    periodDurationUs = getPeriod(++periodIndex, period).getDurationUs();
  }
  return Pair.create(periodIndex, periodPositionUs);
}
 
Example 6
Source File: DashMediaSource.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
@Override
public Window getWindow(int windowIndex, Window window, long defaultPositionProjectionUs) {
  Assertions.checkIndex(windowIndex, 0, 1);
  long windowDefaultStartPositionUs = getAdjustedWindowDefaultStartPositionUs(
      defaultPositionProjectionUs);
  return window.set(
      Window.SINGLE_WINDOW_UID,
      windowTag,
      manifest,
      presentationStartTimeMs,
      windowStartTimeMs,
      /* isSeekable= */ true,
      /* isDynamic= */ isMovingLiveWindow(manifest),
      /* isLive= */ manifest.dynamic,
      windowDefaultStartPositionUs,
      windowDurationUs,
      /* firstPeriodIndex= */ 0,
      /* lastPeriodIndex= */ getPeriodCount() - 1,
      offsetInFirstPeriodUs);
}
 
Example 7
Source File: Timeline.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Converts (windowIndex, windowPositionUs) to the corresponding (periodUid, periodPositionUs).
 *
 * @param window A {@link Window} that may be overwritten.
 * @param period A {@link Period} that may be overwritten.
 * @param windowIndex The window index.
 * @param windowPositionUs The window time, or {@link C#TIME_UNSET} to use the window's default
 *     start position.
 * @param defaultPositionProjectionUs If {@code windowPositionUs} is {@link C#TIME_UNSET}, the
 *     duration into the future by which the window's position should be projected.
 * @return The corresponding (periodUid, periodPositionUs), or null if {@code #windowPositionUs}
 *     is {@link C#TIME_UNSET}, {@code defaultPositionProjectionUs} is non-zero, and the window's
 *     position could not be projected by {@code defaultPositionProjectionUs}.
 */
@Nullable
public final Pair<Object, Long> getPeriodPosition(
    Window window,
    Period period,
    int windowIndex,
    long windowPositionUs,
    long defaultPositionProjectionUs) {
  Assertions.checkIndex(windowIndex, 0, getWindowCount());
  getWindow(windowIndex, window, defaultPositionProjectionUs);
  if (windowPositionUs == C.TIME_UNSET) {
    windowPositionUs = window.getDefaultPositionUs();
    if (windowPositionUs == C.TIME_UNSET) {
      return null;
    }
  }
  int periodIndex = window.firstPeriodIndex;
  long periodPositionUs = window.getPositionInFirstPeriodUs() + windowPositionUs;
  long periodDurationUs = getPeriod(periodIndex, period, /* setIds= */ true).getDurationUs();
  while (periodDurationUs != C.TIME_UNSET && periodPositionUs >= periodDurationUs
      && periodIndex < window.lastPeriodIndex) {
    periodPositionUs -= periodDurationUs;
    periodDurationUs = getPeriod(++periodIndex, period, /* setIds= */ true).getDurationUs();
  }
  return Pair.create(Assertions.checkNotNull(period.uid), periodPositionUs);
}
 
Example 8
Source File: DashMediaSource.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@Override
public Period getPeriod(int periodIndex, Period period, boolean setIdentifiers) {
  Assertions.checkIndex(periodIndex, 0, getPeriodCount());
  Object id = setIdentifiers ? manifest.getPeriod(periodIndex).id : null;
  Object uid = setIdentifiers ? (firstPeriodId + periodIndex) : null;
  return period.set(id, uid, 0, manifest.getPeriodDurationUs(periodIndex),
      C.msToUs(manifest.getPeriod(periodIndex).startMs - manifest.getPeriod(0).startMs)
          - offsetInFirstPeriodUs);
}
 
Example 9
Source File: Cea708Decoder.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public static int getArgbColorFromCeaColor(int red, int green, int blue, int opacity) {
  Assertions.checkIndex(red, 0, 4);
  Assertions.checkIndex(green, 0, 4);
  Assertions.checkIndex(blue, 0, 4);
  Assertions.checkIndex(opacity, 0, 4);

  int alpha;
  switch (opacity) {
    case 0:
    case 1:
      // Note the value of '1' is actually FLASH, but we don't support that.
      alpha = 255;
      break;
    case 2:
      alpha = 127;
      break;
    case 3:
      alpha = 0;
      break;
    default:
      alpha = 255;
  }

  // TODO: Add support for the Alternative Minimum Color List or the full 64 RGB combinations.

  // Return values based on the Minimum Color List
  return Color.argb(alpha,
      (red > 1 ? 255 : 0),
      (green > 1 ? 255 : 0),
      (blue > 1 ? 255 : 0));
}
 
Example 10
Source File: DashMediaSource.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Period getPeriod(int periodIndex, Period period, boolean setIdentifiers) {
  Assertions.checkIndex(periodIndex, 0, getPeriodCount());
  Object id = setIdentifiers ? manifest.getPeriod(periodIndex).id : null;
  Object uid = setIdentifiers ? (firstPeriodId + periodIndex) : null;
  return period.set(id, uid, 0, manifest.getPeriodDurationUs(periodIndex),
      C.msToUs(manifest.getPeriod(periodIndex).startMs - manifest.getPeriod(0).startMs)
          - offsetInFirstPeriodUs);
}
 
Example 11
Source File: DashMediaSource.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Period getPeriod(int periodIndex, Period period, boolean setIdentifiers) {
  Assertions.checkIndex(periodIndex, 0, getPeriodCount());
  Object id = setIdentifiers ? manifest.getPeriod(periodIndex).id : null;
  Object uid = setIdentifiers ? (firstPeriodId + periodIndex) : null;
  return period.set(id, uid, 0, manifest.getPeriodDurationUs(periodIndex),
      C.msToUs(manifest.getPeriod(periodIndex).startMs - manifest.getPeriod(0).startMs)
          - offsetInFirstPeriodUs);
}
 
Example 12
Source File: SinglePeriodTimeline.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Window getWindow(
    int windowIndex, Window window, boolean setTag, long defaultPositionProjectionUs) {
  Assertions.checkIndex(windowIndex, 0, 1);
  Object tag = setTag ? this.tag : null;
  long windowDefaultStartPositionUs = this.windowDefaultStartPositionUs;
  if (isDynamic && defaultPositionProjectionUs != 0) {
    if (windowDurationUs == C.TIME_UNSET) {
      // Don't allow projection into a window that has an unknown duration.
      windowDefaultStartPositionUs = C.TIME_UNSET;
    } else {
      windowDefaultStartPositionUs += defaultPositionProjectionUs;
      if (windowDefaultStartPositionUs > windowDurationUs) {
        // The projection takes us beyond the end of the window.
        windowDefaultStartPositionUs = C.TIME_UNSET;
      }
    }
  }
  return window.set(
      tag,
      presentationStartTimeMs,
      windowStartTimeMs,
      isSeekable,
      isDynamic,
      windowDefaultStartPositionUs,
      windowDurationUs,
      0,
      0,
      windowPositionInPeriodUs);
}
 
Example 13
Source File: DashMediaSource.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Object getUidOfPeriod(int periodIndex) {
  Assertions.checkIndex(periodIndex, 0, getPeriodCount());
  return firstPeriodId + periodIndex;
}
 
Example 14
Source File: SinglePeriodTimeline.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
@Override
public Object getUidOfPeriod(int periodIndex) {
  Assertions.checkIndex(periodIndex, 0, 1);
  return UID;
}
 
Example 15
Source File: SinglePeriodTimeline.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Period getPeriod(int periodIndex, Period period, boolean setIds) {
  Assertions.checkIndex(periodIndex, 0, 1);
  Object uid = setIds ? UID : null;
  return period.set(/* id= */ null, uid, 0, periodDurationUs, -windowPositionInPeriodUs);
}
 
Example 16
Source File: SinglePeriodTimeline.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Object getUidOfPeriod(int periodIndex) {
  Assertions.checkIndex(periodIndex, 0, 1);
  return UID;
}
 
Example 17
Source File: SinglePeriodTimeline.java    From K-Sonic with MIT License 4 votes vote down vote up
@Override
public Period getPeriod(int periodIndex, Period period, boolean setIds) {
  Assertions.checkIndex(periodIndex, 0, 1);
  Object id = setIds ? ID : null;
  return period.set(id, id, 0, periodDurationUs, -windowPositionInPeriodUs);
}
 
Example 18
Source File: SinglePeriodTimeline.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
@Override
public Period getPeriod(int periodIndex, Period period, boolean setIds) {
  Assertions.checkIndex(periodIndex, 0, 1);
  Object uid = setIds ? UID : null;
  return period.set(/* id= */ null, uid, 0, periodDurationUs, -windowPositionInPeriodUs);
}
 
Example 19
Source File: DashMediaSource.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Object getUidOfPeriod(int periodIndex) {
  Assertions.checkIndex(periodIndex, 0, getPeriodCount());
  return firstPeriodId + periodIndex;
}
 
Example 20
Source File: SinglePeriodTimeline.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Object getUidOfPeriod(int periodIndex) {
  Assertions.checkIndex(periodIndex, 0, 1);
  return UID;
}