com.google.android.exoplayer2.trackselection.TrackSelectorResult Java Examples

The following examples show how to use com.google.android.exoplayer2.trackselection.TrackSelectorResult. 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: PlaybackInfo.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates empty dummy playback info which can be used for masking as long as no real playback
 * info is available.
 *
 * @param startPositionUs The start position at which playback should start, in microseconds.
 * @param emptyTrackSelectorResult An empty track selector result with null entries for each
 *     renderer.
 * @return A dummy playback info.
 */
public static PlaybackInfo createDummy(
    long startPositionUs, TrackSelectorResult emptyTrackSelectorResult) {
  return new PlaybackInfo(
      Timeline.EMPTY,
      /* manifest= */ null,
      DUMMY_MEDIA_PERIOD_ID,
      startPositionUs,
      /* contentPositionUs =*/ C.TIME_UNSET,
      Player.STATE_IDLE,
      /* isLoading= */ false,
      TrackGroupArray.EMPTY,
      emptyTrackSelectorResult,
      DUMMY_MEDIA_PERIOD_ID,
      startPositionUs,
      /* totalBufferedDurationUs= */ 0,
      startPositionUs);
}
 
Example #2
Source File: PlaybackInfo.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates empty dummy playback info which can be used for masking as long as no real playback
 * info is available.
 *
 * @param startPositionUs The start position at which playback should start, in microseconds.
 * @param emptyTrackSelectorResult An empty track selector result with null entries for each
 *     renderer.
 * @return A dummy playback info.
 */
public static PlaybackInfo createDummy(
    long startPositionUs, TrackSelectorResult emptyTrackSelectorResult) {
  return new PlaybackInfo(
      Timeline.EMPTY,
      /* manifest= */ null,
      DUMMY_MEDIA_PERIOD_ID,
      startPositionUs,
      /* contentPositionUs= */ C.TIME_UNSET,
      Player.STATE_IDLE,
      /* isLoading= */ false,
      TrackGroupArray.EMPTY,
      emptyTrackSelectorResult,
      DUMMY_MEDIA_PERIOD_ID,
      startPositionUs,
      /* totalBufferedDurationUs= */ 0,
      startPositionUs);
}
 
Example #3
Source File: ExoPlayerImplInternal.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private void enableRenderers(boolean[] rendererWasEnabledFlags, int totalEnabledRendererCount)
    throws ExoPlaybackException {
  enabledRenderers = new Renderer[totalEnabledRendererCount];
  int enabledRendererCount = 0;
  TrackSelectorResult trackSelectorResult = queue.getPlayingPeriod().getTrackSelectorResult();
  // Reset all disabled renderers before enabling any new ones. This makes sure resources released
  // by the disabled renderers will be available to renderers that are being enabled.
  for (int i = 0; i < renderers.length; i++) {
    if (!trackSelectorResult.isRendererEnabled(i)) {
      renderers[i].reset();
    }
  }
  // Enable the renderers.
  for (int i = 0; i < renderers.length; i++) {
    if (trackSelectorResult.isRendererEnabled(i)) {
      enableRenderer(i, rendererWasEnabledFlags[i], enabledRendererCount++);
    }
  }
}
 
Example #4
Source File: PlaybackInfo.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Copies playback info with new track information.
 *
 * @param trackGroups New track groups. See {@link #trackGroups}.
 * @param trackSelectorResult New track selector result. See {@link #trackSelectorResult}.
 * @return Copied playback info with new track information.
 */
@CheckResult
public PlaybackInfo copyWithTrackInfo(
    TrackGroupArray trackGroups, TrackSelectorResult trackSelectorResult) {
  return new PlaybackInfo(
      timeline,
      manifest,
      periodId,
      startPositionUs,
      contentPositionUs,
      playbackState,
      isLoading,
      trackGroups,
      trackSelectorResult,
      loadingMediaPeriodId,
      bufferedPositionUs,
      totalBufferedDurationUs,
      positionUs);
}
 
Example #5
Source File: ExoPlayerImplInternal.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
private void enableRenderers(boolean[] rendererWasEnabledFlags, int totalEnabledRendererCount)
    throws ExoPlaybackException {
  enabledRenderers = new Renderer[totalEnabledRendererCount];
  int enabledRendererCount = 0;
  TrackSelectorResult trackSelectorResult = queue.getPlayingPeriod().getTrackSelectorResult();
  // Reset all disabled renderers before enabling any new ones. This makes sure resources released
  // by the disabled renderers will be available to renderers that are being enabled.
  for (int i = 0; i < renderers.length; i++) {
    if (!trackSelectorResult.isRendererEnabled(i)) {
      renderers[i].reset();
    }
  }
  // Enable the renderers.
  for (int i = 0; i < renderers.length; i++) {
    if (trackSelectorResult.isRendererEnabled(i)) {
      enableRenderer(i, rendererWasEnabledFlags[i], enabledRendererCount++);
    }
  }
}
 
Example #6
Source File: MediaPeriodHolder.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new holder with information required to play it as part of a timeline.
 *
 * @param rendererCapabilities The renderer capabilities.
 * @param rendererPositionOffsetUs The renderer time of the start of the period, in microseconds.
 * @param trackSelector The track selector.
 * @param allocator The allocator.
 * @param mediaSource The media source that produced the media period.
 * @param info Information used to identify this media period in its timeline period.
 * @param emptyTrackSelectorResult A {@link TrackSelectorResult} with empty selections for each
 *     renderer.
 */
public MediaPeriodHolder(
    RendererCapabilities[] rendererCapabilities,
    long rendererPositionOffsetUs,
    TrackSelector trackSelector,
    Allocator allocator,
    MediaSource mediaSource,
    MediaPeriodInfo info,
    TrackSelectorResult emptyTrackSelectorResult) {
  this.rendererCapabilities = rendererCapabilities;
  this.rendererPositionOffsetUs = rendererPositionOffsetUs;
  this.trackSelector = trackSelector;
  this.mediaSource = mediaSource;
  this.uid = info.id.periodUid;
  this.info = info;
  this.trackGroups = TrackGroupArray.EMPTY;
  this.trackSelectorResult = emptyTrackSelectorResult;
  sampleStreams = new SampleStream[rendererCapabilities.length];
  mayRetainStreamFlags = new boolean[rendererCapabilities.length];
  mediaPeriod =
      createMediaPeriod(
          info.id, mediaSource, allocator, info.startPositionUs, info.endPositionUs);
}
 
Example #7
Source File: MediaPeriodHolder.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Selects tracks for the period and returns the new result if the selection changed. Must only be
 * called if {@link #prepared} is {@code true}.
 *
 * @param playbackSpeed The current playback speed.
 * @param timeline The current {@link Timeline}.
 * @return The {@link TrackSelectorResult} if the result changed. Or null if nothing changed.
 * @throws ExoPlaybackException If an error occurs during track selection.
 */
@Nullable
public TrackSelectorResult selectTracks(float playbackSpeed, Timeline timeline)
    throws ExoPlaybackException {
  TrackSelectorResult selectorResult =
      trackSelector.selectTracks(rendererCapabilities, getTrackGroups(), info.id, timeline);
  if (selectorResult.isEquivalent(trackSelectorResult)) {
    return null;
  }
  for (TrackSelection trackSelection : selectorResult.selections.getAll()) {
    if (trackSelection != null) {
      trackSelection.onPlaybackSpeed(playbackSpeed);
    }
  }
  return selectorResult;
}
 
Example #8
Source File: PlaybackInfo.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Creates empty dummy playback info which can be used for masking as long as no real playback
 * info is available.
 *
 * @param startPositionUs The start position at which playback should start, in microseconds.
 * @param emptyTrackSelectorResult An empty track selector result with null entries for each
 *     renderer.
 * @return A dummy playback info.
 */
public static PlaybackInfo createDummy(
    long startPositionUs, TrackSelectorResult emptyTrackSelectorResult) {
  return new PlaybackInfo(
      Timeline.EMPTY,
      DUMMY_MEDIA_PERIOD_ID,
      startPositionUs,
      /* contentPositionUs= */ C.TIME_UNSET,
      Player.STATE_IDLE,
      /* playbackError= */ null,
      /* isLoading= */ false,
      TrackGroupArray.EMPTY,
      emptyTrackSelectorResult,
      DUMMY_MEDIA_PERIOD_ID,
      startPositionUs,
      /* totalBufferedDurationUs= */ 0,
      startPositionUs);
}
 
Example #9
Source File: PlaybackInfo.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates empty dummy playback info which can be used for masking as long as no real playback
 * info is available.
 *
 * @param startPositionUs The start position at which playback should start, in microseconds.
 * @param emptyTrackSelectorResult An empty track selector result with null entries for each
 *     renderer.
 * @return A dummy playback info.
 */
public static PlaybackInfo createDummy(
    long startPositionUs, TrackSelectorResult emptyTrackSelectorResult) {
  return new PlaybackInfo(
      Timeline.EMPTY,
      /* manifest= */ null,
      DUMMY_MEDIA_PERIOD_ID,
      startPositionUs,
      /* contentPositionUs= */ C.TIME_UNSET,
      Player.STATE_IDLE,
      /* isLoading= */ false,
      TrackGroupArray.EMPTY,
      emptyTrackSelectorResult,
      DUMMY_MEDIA_PERIOD_ID,
      startPositionUs,
      /* totalBufferedDurationUs= */ 0,
      startPositionUs);
}
 
Example #10
Source File: PlaybackInfo.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Copies playback info with new track information.
 *
 * @param trackGroups New track groups. See {@link #trackGroups}.
 * @param trackSelectorResult New track selector result. See {@link #trackSelectorResult}.
 * @return Copied playback info with new track information.
 */
@CheckResult
public PlaybackInfo copyWithTrackInfo(
    TrackGroupArray trackGroups, TrackSelectorResult trackSelectorResult) {
  return new PlaybackInfo(
      timeline,
      manifest,
      periodId,
      startPositionUs,
      contentPositionUs,
      playbackState,
      isLoading,
      trackGroups,
      trackSelectorResult,
      loadingMediaPeriodId,
      bufferedPositionUs,
      totalBufferedDurationUs,
      positionUs);
}
 
Example #11
Source File: PlaybackInfo.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public PlaybackInfo copyWithTrackInfo(
    TrackGroupArray trackGroups, TrackSelectorResult trackSelectorResult) {
  return new PlaybackInfo(
      timeline,
      manifest,
      periodId,
      startPositionUs,
      contentPositionUs,
      playbackState,
      isLoading,
      trackGroups,
      trackSelectorResult,
      loadingMediaPeriodId,
      bufferedPositionUs,
      totalBufferedDurationUs,
      positionUs);
}
 
Example #12
Source File: MediaPeriodHolder.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Selects tracks for the period and returns the new result if the selection changed. Must only be
 * called if {@link #prepared} is {@code true}.
 *
 * @param playbackSpeed The current playback speed.
 * @param timeline The current {@link Timeline}.
 * @return The {@link TrackSelectorResult} if the result changed. Or null if nothing changed.
 * @throws ExoPlaybackException If an error occurs during track selection.
 */
@Nullable
public TrackSelectorResult selectTracks(float playbackSpeed, Timeline timeline)
    throws ExoPlaybackException {
  TrackSelectorResult selectorResult =
      trackSelector.selectTracks(rendererCapabilities, getTrackGroups(), info.id, timeline);
  if (selectorResult.isEquivalent(trackSelectorResult)) {
    return null;
  }
  for (TrackSelection trackSelection : selectorResult.selections.getAll()) {
    if (trackSelection != null) {
      trackSelection.onPlaybackSpeed(playbackSpeed);
    }
  }
  return selectorResult;
}
 
Example #13
Source File: PlaybackInfo.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public PlaybackInfo copyWithTrackInfo(
    TrackGroupArray trackGroups, TrackSelectorResult trackSelectorResult) {
  return new PlaybackInfo(
      timeline,
      manifest,
      periodId,
      startPositionUs,
      contentPositionUs,
      playbackState,
      isLoading,
      trackGroups,
      trackSelectorResult,
      loadingMediaPeriodId,
      bufferedPositionUs,
      totalBufferedDurationUs,
      positionUs);
}
 
Example #14
Source File: PlaybackInfo.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates empty dummy playback info which can be used for masking as long as no real playback
 * info is available.
 *
 * @param startPositionUs The start position at which playback should start, in microseconds.
 * @param emptyTrackSelectorResult An empty track selector result with null entries for each
 *     renderer.
 * @return A dummy playback info.
 */
public static PlaybackInfo createDummy(
    long startPositionUs, TrackSelectorResult emptyTrackSelectorResult) {
  return new PlaybackInfo(
      Timeline.EMPTY,
      /* manifest= */ null,
      DUMMY_MEDIA_PERIOD_ID,
      startPositionUs,
      /* contentPositionUs =*/ C.TIME_UNSET,
      Player.STATE_IDLE,
      /* isLoading= */ false,
      TrackGroupArray.EMPTY,
      emptyTrackSelectorResult,
      DUMMY_MEDIA_PERIOD_ID,
      startPositionUs,
      /* totalBufferedDurationUs= */ 0,
      startPositionUs);
}
 
Example #15
Source File: ExoPlayerImplInternal.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private void enableRenderers(boolean[] rendererWasEnabledFlags, int totalEnabledRendererCount)
    throws ExoPlaybackException {
  enabledRenderers = new Renderer[totalEnabledRendererCount];
  int enabledRendererCount = 0;
  TrackSelectorResult trackSelectorResult = queue.getPlayingPeriod().getTrackSelectorResult();
  // Reset all disabled renderers before enabling any new ones. This makes sure resources released
  // by the disabled renderers will be available to renderers that are being enabled.
  for (int i = 0; i < renderers.length; i++) {
    if (!trackSelectorResult.isRendererEnabled(i)) {
      renderers[i].reset();
    }
  }
  // Enable the renderers.
  for (int i = 0; i < renderers.length; i++) {
    if (trackSelectorResult.isRendererEnabled(i)) {
      enableRenderer(i, rendererWasEnabledFlags[i], enabledRendererCount++);
    }
  }
}
 
Example #16
Source File: PlaybackInfo.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Copies playback info with new track information.
 *
 * @param trackGroups New track groups. See {@link #trackGroups}.
 * @param trackSelectorResult New track selector result. See {@link #trackSelectorResult}.
 * @return Copied playback info with new track information.
 */
@CheckResult
public PlaybackInfo copyWithTrackInfo(
    TrackGroupArray trackGroups, TrackSelectorResult trackSelectorResult) {
  return new PlaybackInfo(
      timeline,
      periodId,
      startPositionUs,
      contentPositionUs,
      playbackState,
      playbackError,
      isLoading,
      trackGroups,
      trackSelectorResult,
      loadingMediaPeriodId,
      bufferedPositionUs,
      totalBufferedDurationUs,
      positionUs);
}
 
Example #17
Source File: MediaPeriodHolder.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private void enableTrackSelectionsInResult() {
  TrackSelectorResult trackSelectorResult = this.trackSelectorResult;
  if (!isLoadingMediaPeriod() || trackSelectorResult == null) {
    return;
  }
  for (int i = 0; i < trackSelectorResult.length; i++) {
    boolean rendererEnabled = trackSelectorResult.isRendererEnabled(i);
    TrackSelection trackSelection = trackSelectorResult.selections.get(i);
    if (rendererEnabled && trackSelection != null) {
      trackSelection.enable();
    }
  }
}
 
Example #18
Source File: PlaybackInfo.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public PlaybackInfo(
    Timeline timeline,
    @Nullable Object manifest,
    MediaPeriodId periodId,
    long startPositionUs,
    long contentPositionUs,
    int playbackState,
    boolean isLoading,
    TrackGroupArray trackGroups,
    TrackSelectorResult trackSelectorResult,
    MediaPeriodId loadingMediaPeriodId,
    long bufferedPositionUs,
    long totalBufferedDurationUs,
    long positionUs) {
  this.timeline = timeline;
  this.manifest = manifest;
  this.periodId = periodId;
  this.startPositionUs = startPositionUs;
  this.contentPositionUs = contentPositionUs;
  this.playbackState = playbackState;
  this.isLoading = isLoading;
  this.trackGroups = trackGroups;
  this.trackSelectorResult = trackSelectorResult;
  this.loadingMediaPeriodId = loadingMediaPeriodId;
  this.bufferedPositionUs = bufferedPositionUs;
  this.totalBufferedDurationUs = totalBufferedDurationUs;
  this.positionUs = positionUs;
}
 
Example #19
Source File: MediaPeriodHolder.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * For each renderer of type {@link C#TRACK_TYPE_NONE} that was enabled, we will associate it with
 * a dummy {@link EmptySampleStream}.
 */
private void associateNoSampleRenderersWithEmptySampleStream(
    @NullableType SampleStream[] sampleStreams) {
  TrackSelectorResult trackSelectorResult = Assertions.checkNotNull(this.trackSelectorResult);
  for (int i = 0; i < rendererCapabilities.length; i++) {
    if (rendererCapabilities[i].getTrackType() == C.TRACK_TYPE_NONE
        && trackSelectorResult.isRendererEnabled(i)) {
      sampleStreams[i] = new EmptySampleStream();
    }
  }
}
 
Example #20
Source File: PlaybackInfo.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create playback info.
 *
 * @param timeline See {@link #timeline}.
 * @param manifest See {@link #manifest}.
 * @param periodId See {@link #periodId}.
 * @param startPositionUs See {@link #startPositionUs}.
 * @param contentPositionUs See {@link #contentPositionUs}.
 * @param playbackState See {@link #playbackState}.
 * @param isLoading See {@link #isLoading}.
 * @param trackGroups See {@link #trackGroups}.
 * @param trackSelectorResult See {@link #trackSelectorResult}.
 * @param loadingMediaPeriodId See {@link #loadingMediaPeriodId}.
 * @param bufferedPositionUs See {@link #bufferedPositionUs}.
 * @param totalBufferedDurationUs See {@link #totalBufferedDurationUs}.
 * @param positionUs See {@link #positionUs}.
 */
public PlaybackInfo(
    Timeline timeline,
    @Nullable Object manifest,
    MediaPeriodId periodId,
    long startPositionUs,
    long contentPositionUs,
    int playbackState,
    boolean isLoading,
    TrackGroupArray trackGroups,
    TrackSelectorResult trackSelectorResult,
    MediaPeriodId loadingMediaPeriodId,
    long bufferedPositionUs,
    long totalBufferedDurationUs,
    long positionUs) {
  this.timeline = timeline;
  this.manifest = manifest;
  this.periodId = periodId;
  this.startPositionUs = startPositionUs;
  this.contentPositionUs = contentPositionUs;
  this.playbackState = playbackState;
  this.isLoading = isLoading;
  this.trackGroups = trackGroups;
  this.trackSelectorResult = trackSelectorResult;
  this.loadingMediaPeriodId = loadingMediaPeriodId;
  this.bufferedPositionUs = bufferedPositionUs;
  this.totalBufferedDurationUs = totalBufferedDurationUs;
  this.positionUs = positionUs;
}
 
Example #21
Source File: ExoPlayerImplInternal.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private void notifyTrackSelectionDiscontinuity() {
  MediaPeriodHolder periodHolder = queue.getFrontPeriod();
  while (periodHolder != null) {
    TrackSelectorResult trackSelectorResult = periodHolder.getTrackSelectorResult();
    if (trackSelectorResult != null) {
      TrackSelection[] trackSelections = trackSelectorResult.selections.getAll();
      for (TrackSelection trackSelection : trackSelections) {
        if (trackSelection != null) {
          trackSelection.onDiscontinuity();
        }
      }
    }
    periodHolder = periodHolder.getNext();
  }
}
 
Example #22
Source File: MediaPeriodHolder.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Handles period preparation.
 *
 * @param playbackSpeed The current playback speed.
 * @param timeline The current {@link Timeline}.
 * @throws ExoPlaybackException If an error occurs during track selection.
 */
public void handlePrepared(float playbackSpeed, Timeline timeline) throws ExoPlaybackException {
  prepared = true;
  trackGroups = mediaPeriod.getTrackGroups();
  TrackSelectorResult selectorResult =
      Assertions.checkNotNull(selectTracks(playbackSpeed, timeline));
  long newStartPositionUs =
      applyTrackSelection(
          selectorResult, info.startPositionUs, /* forceRecreateStreams= */ false);
  rendererPositionOffsetUs += info.startPositionUs - newStartPositionUs;
  info = info.copyWithStartPositionUs(newStartPositionUs);
}
 
Example #23
Source File: MediaPeriodHolder.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Handles period preparation.
 *
 * @param playbackSpeed The current playback speed.
 * @param timeline The current {@link Timeline}.
 * @throws ExoPlaybackException If an error occurs during track selection.
 */
public void handlePrepared(float playbackSpeed, Timeline timeline) throws ExoPlaybackException {
  prepared = true;
  trackGroups = mediaPeriod.getTrackGroups();
  TrackSelectorResult selectorResult =
      Assertions.checkNotNull(selectTracks(playbackSpeed, timeline));
  long newStartPositionUs =
      applyTrackSelection(
          selectorResult, info.startPositionUs, /* forceRecreateStreams= */ false);
  rendererPositionOffsetUs += info.startPositionUs - newStartPositionUs;
  info = info.copyWithStartPositionUs(newStartPositionUs);
}
 
Example #24
Source File: MediaPeriodHolder.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * For each renderer of type {@link C#TRACK_TYPE_NONE} that was enabled, we will associate it with
 * a dummy {@link EmptySampleStream}.
 */
private void associateNoSampleRenderersWithEmptySampleStream(
    @NullableType SampleStream[] sampleStreams) {
  TrackSelectorResult trackSelectorResult = Assertions.checkNotNull(this.trackSelectorResult);
  for (int i = 0; i < rendererCapabilities.length; i++) {
    if (rendererCapabilities[i].getTrackType() == C.TRACK_TYPE_NONE
        && trackSelectorResult.isRendererEnabled(i)) {
      sampleStreams[i] = new EmptySampleStream();
    }
  }
}
 
Example #25
Source File: MediaPeriodHolder.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private void disableTrackSelectionsInResult() {
  TrackSelectorResult trackSelectorResult = this.trackSelectorResult;
  if (!isLoadingMediaPeriod() || trackSelectorResult == null) {
    return;
  }
  for (int i = 0; i < trackSelectorResult.length; i++) {
    boolean rendererEnabled = trackSelectorResult.isRendererEnabled(i);
    TrackSelection trackSelection = trackSelectorResult.selections.get(i);
    if (rendererEnabled && trackSelection != null) {
      trackSelection.disable();
    }
  }
}
 
Example #26
Source File: MediaPeriodHolder.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private void enableTrackSelectionsInResult() {
  TrackSelectorResult trackSelectorResult = this.trackSelectorResult;
  if (!isLoadingMediaPeriod() || trackSelectorResult == null) {
    return;
  }
  for (int i = 0; i < trackSelectorResult.length; i++) {
    boolean rendererEnabled = trackSelectorResult.isRendererEnabled(i);
    TrackSelection trackSelection = trackSelectorResult.selections.get(i);
    if (rendererEnabled && trackSelection != null) {
      trackSelection.enable();
    }
  }
}
 
Example #27
Source File: PlaybackInfo.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create playback info.
 *
 * @param timeline See {@link #timeline}.
 * @param manifest See {@link #manifest}.
 * @param periodId See {@link #periodId}.
 * @param startPositionUs See {@link #startPositionUs}.
 * @param contentPositionUs See {@link #contentPositionUs}.
 * @param playbackState See {@link #playbackState}.
 * @param isLoading See {@link #isLoading}.
 * @param trackGroups See {@link #trackGroups}.
 * @param trackSelectorResult See {@link #trackSelectorResult}.
 * @param loadingMediaPeriodId See {@link #loadingMediaPeriodId}.
 * @param bufferedPositionUs See {@link #bufferedPositionUs}.
 * @param totalBufferedDurationUs See {@link #totalBufferedDurationUs}.
 * @param positionUs See {@link #positionUs}.
 */
public PlaybackInfo(
    Timeline timeline,
    @Nullable Object manifest,
    MediaPeriodId periodId,
    long startPositionUs,
    long contentPositionUs,
    int playbackState,
    boolean isLoading,
    TrackGroupArray trackGroups,
    TrackSelectorResult trackSelectorResult,
    MediaPeriodId loadingMediaPeriodId,
    long bufferedPositionUs,
    long totalBufferedDurationUs,
    long positionUs) {
  this.timeline = timeline;
  this.manifest = manifest;
  this.periodId = periodId;
  this.startPositionUs = startPositionUs;
  this.contentPositionUs = contentPositionUs;
  this.playbackState = playbackState;
  this.isLoading = isLoading;
  this.trackGroups = trackGroups;
  this.trackSelectorResult = trackSelectorResult;
  this.loadingMediaPeriodId = loadingMediaPeriodId;
  this.bufferedPositionUs = bufferedPositionUs;
  this.totalBufferedDurationUs = totalBufferedDurationUs;
  this.positionUs = positionUs;
}
 
Example #28
Source File: MediaPeriodQueue.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * Enqueues a new media period holder based on the specified information as the new loading media
 * period, and returns it.
 *
 * @param rendererCapabilities The renderer capabilities.
 * @param trackSelector The track selector.
 * @param allocator The allocator.
 * @param mediaSource The media source that produced the media period.
 * @param info Information used to identify this media period in its timeline period.
 * @param emptyTrackSelectorResult A {@link TrackSelectorResult} with empty selections for each
 *     renderer.
 */
public MediaPeriodHolder enqueueNextMediaPeriodHolder(
    RendererCapabilities[] rendererCapabilities,
    TrackSelector trackSelector,
    Allocator allocator,
    MediaSource mediaSource,
    MediaPeriodInfo info,
    TrackSelectorResult emptyTrackSelectorResult) {
  long rendererPositionOffsetUs =
      loading == null
          ? (info.id.isAd() && info.contentPositionUs != C.TIME_UNSET
              ? info.contentPositionUs
              : 0)
          : (loading.getRendererOffset() + loading.info.durationUs - info.startPositionUs);
  MediaPeriodHolder newPeriodHolder =
      new MediaPeriodHolder(
          rendererCapabilities,
          rendererPositionOffsetUs,
          trackSelector,
          allocator,
          mediaSource,
          info,
          emptyTrackSelectorResult);
  if (loading != null) {
    loading.setNext(newPeriodHolder);
  } else {
    playing = newPeriodHolder;
    reading = newPeriodHolder;
  }
  oldFrontPeriodUid = null;
  loading = newPeriodHolder;
  length++;
  return newPeriodHolder;
}
 
Example #29
Source File: ExoPlayerImplInternal.java    From K-Sonic with MIT License 5 votes vote down vote up
public boolean selectTracks() throws ExoPlaybackException {
  TrackSelectorResult selectorResult = trackSelector.selectTracks(rendererCapabilities,
      mediaPeriod.getTrackGroups());
  if (selectorResult.isEquivalent(periodTrackSelectorResult)) {
    return false;
  }
  trackSelectorResult = selectorResult;
  return true;
}
 
Example #30
Source File: ExoPlayerImplInternal.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private void notifyTrackSelectionDiscontinuity() {
  MediaPeriodHolder periodHolder = queue.getFrontPeriod();
  while (periodHolder != null) {
    TrackSelectorResult trackSelectorResult = periodHolder.getTrackSelectorResult();
    if (trackSelectorResult != null) {
      TrackSelection[] trackSelections = trackSelectorResult.selections.getAll();
      for (TrackSelection trackSelection : trackSelections) {
        if (trackSelection != null) {
          trackSelection.onDiscontinuity();
        }
      }
    }
    periodHolder = periodHolder.getNext();
  }
}