com.google.android.exoplayer2.source.chunk.ChunkSampleStream Java Examples

The following examples show how to use com.google.android.exoplayer2.source.chunk.ChunkSampleStream. 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: DashMediaPeriod.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void releaseDisabledStreams(
    TrackSelection[] selections, boolean[] mayRetainStreamFlags, SampleStream[] streams) {
  for (int i = 0; i < selections.length; i++) {
    if (selections[i] == null || !mayRetainStreamFlags[i]) {
      if (streams[i] instanceof ChunkSampleStream) {
        @SuppressWarnings("unchecked")
        ChunkSampleStream<DashChunkSource> stream =
            (ChunkSampleStream<DashChunkSource>) streams[i];
        stream.release(this);
      } else if (streams[i] instanceof EmbeddedSampleStream) {
        ((EmbeddedSampleStream) streams[i]).release();
      }
      streams[i] = null;
    }
  }
}
 
Example #2
Source File: DashMediaPeriod.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
private void releaseDisabledStreams(
    TrackSelection[] selections, boolean[] mayRetainStreamFlags, SampleStream[] streams) {
  for (int i = 0; i < selections.length; i++) {
    if (selections[i] == null || !mayRetainStreamFlags[i]) {
      if (streams[i] instanceof ChunkSampleStream) {
        @SuppressWarnings("unchecked")
        ChunkSampleStream<DashChunkSource> stream =
            (ChunkSampleStream<DashChunkSource>) streams[i];
        stream.release(this);
      } else if (streams[i] instanceof EmbeddedSampleStream) {
        ((EmbeddedSampleStream) streams[i]).release();
      }
      streams[i] = null;
    }
  }
}
 
Example #3
Source File: DashMediaPeriod.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private void releaseDisabledStreams(
    TrackSelection[] selections, boolean[] mayRetainStreamFlags, SampleStream[] streams) {
  for (int i = 0; i < selections.length; i++) {
    if (selections[i] == null || !mayRetainStreamFlags[i]) {
      if (streams[i] instanceof ChunkSampleStream) {
        @SuppressWarnings("unchecked")
        ChunkSampleStream<DashChunkSource> stream =
            (ChunkSampleStream<DashChunkSource>) streams[i];
        stream.release(this);
      } else if (streams[i] instanceof EmbeddedSampleStream) {
        ((EmbeddedSampleStream) streams[i]).release();
      }
      streams[i] = null;
    }
  }
}
 
Example #4
Source File: SsMediaPeriod.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private ChunkSampleStream<SsChunkSource> buildSampleStream(TrackSelection selection,
    long positionUs) {
  int streamElementIndex = trackGroups.indexOf(selection.getTrackGroup());
  SsChunkSource chunkSource =
      chunkSourceFactory.createChunkSource(
          manifestLoaderErrorThrower,
          manifest,
          streamElementIndex,
          selection,
          transferListener);
  return new ChunkSampleStream<>(
      manifest.streamElements[streamElementIndex].type,
      null,
      null,
      chunkSource,
      this,
      allocator,
      positionUs,
      loadErrorHandlingPolicy,
      eventDispatcher);
}
 
Example #5
Source File: DashMediaPeriod.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Updates the {@link DashManifest} and the index of this period in the manifest.
 *
 * @param manifest The updated manifest.
 * @param periodIndex the new index of this period in the updated manifest.
 */
public void updateManifest(DashManifest manifest, int periodIndex) {
  this.manifest = manifest;
  this.periodIndex = periodIndex;
  playerEmsgHandler.updateManifest(manifest);
  if (sampleStreams != null) {
    for (ChunkSampleStream<DashChunkSource> sampleStream : sampleStreams) {
      sampleStream.getChunkSource().updateManifest(manifest, periodIndex);
    }
    callback.onContinueLoadingRequested(this);
  }
  eventStreams = manifest.getPeriod(periodIndex).eventStreams;
  for (EventSampleStream eventSampleStream : eventSampleStreams) {
    for (EventStream eventStream : eventStreams) {
      if (eventStream.id().equals(eventSampleStream.eventStreamId())) {
        int lastPeriodIndex = manifest.getPeriodCount() - 1;
        eventSampleStream.updateEventStream(
            eventStream,
            /* eventStreamAppendable= */ manifest.dynamic && periodIndex == lastPeriodIndex);
        break;
      }
    }
  }
}
 
Example #6
Source File: DashMediaPeriod.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Updates the {@link DashManifest} and the index of this period in the manifest.
 *
 * @param manifest The updated manifest.
 * @param periodIndex the new index of this period in the updated manifest.
 */
public void updateManifest(DashManifest manifest, int periodIndex) {
  this.manifest = manifest;
  this.periodIndex = periodIndex;
  playerEmsgHandler.updateManifest(manifest);
  if (sampleStreams != null) {
    for (ChunkSampleStream<DashChunkSource> sampleStream : sampleStreams) {
      sampleStream.getChunkSource().updateManifest(manifest, periodIndex);
    }
    callback.onContinueLoadingRequested(this);
  }
  eventStreams = manifest.getPeriod(periodIndex).eventStreams;
  for (EventSampleStream eventSampleStream : eventSampleStreams) {
    for (EventStream eventStream : eventStreams) {
      if (eventStream.id().equals(eventSampleStream.eventStreamId())) {
        int lastPeriodIndex = manifest.getPeriodCount() - 1;
        eventSampleStream.updateEventStream(
            eventStream,
            /* eventStreamAppendable= */ manifest.dynamic && periodIndex == lastPeriodIndex);
        break;
      }
    }
  }
}
 
Example #7
Source File: DashMediaPeriod.java    From K-Sonic with MIT License 6 votes vote down vote up
private ChunkSampleStream<DashChunkSource> buildSampleStream(int adaptationSetIndex,
    TrackSelection selection, long positionUs) {
  AdaptationSet adaptationSet = adaptationSets.get(adaptationSetIndex);
  int embeddedTrackCount = 0;
  int[] embeddedTrackTypes = new int[2];
  boolean enableEventMessageTrack = hasEventMessageTrack(adaptationSet);
  if (enableEventMessageTrack) {
    embeddedTrackTypes[embeddedTrackCount++] = C.TRACK_TYPE_METADATA;
  }
  boolean enableCea608Track = hasCea608Track(adaptationSet);
  if (enableCea608Track) {
    embeddedTrackTypes[embeddedTrackCount++] = C.TRACK_TYPE_TEXT;
  }
  if (embeddedTrackCount < embeddedTrackTypes.length) {
    embeddedTrackTypes = Arrays.copyOf(embeddedTrackTypes, embeddedTrackCount);
  }
  DashChunkSource chunkSource = chunkSourceFactory.createDashChunkSource(
      manifestLoaderErrorThrower, manifest, periodIndex, adaptationSetIndex, selection,
      elapsedRealtimeOffset, enableEventMessageTrack, enableCea608Track);
  ChunkSampleStream<DashChunkSource> stream = new ChunkSampleStream<>(adaptationSet.type,
      embeddedTrackTypes, chunkSource, this, allocator, positionUs, minLoadableRetryCount,
      eventDispatcher);
  return stream;
}
 
Example #8
Source File: SsMediaPeriod.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
private ChunkSampleStream<SsChunkSource> buildSampleStream(TrackSelection selection,
    long positionUs) {
  int streamElementIndex = trackGroups.indexOf(selection.getTrackGroup());
  SsChunkSource chunkSource =
      chunkSourceFactory.createChunkSource(
          manifestLoaderErrorThrower,
          manifest,
          streamElementIndex,
          selection,
          transferListener);
  return new ChunkSampleStream<>(
      manifest.streamElements[streamElementIndex].type,
      null,
      null,
      chunkSource,
      this,
      allocator,
      positionUs,
      drmSessionManager,
      loadErrorHandlingPolicy,
      eventDispatcher);
}
 
Example #9
Source File: SsMediaPeriod.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private ChunkSampleStream<SsChunkSource> buildSampleStream(TrackSelection selection,
    long positionUs) {
  int streamElementIndex = trackGroups.indexOf(selection.getTrackGroup());
  SsChunkSource chunkSource =
      chunkSourceFactory.createChunkSource(
          manifestLoaderErrorThrower,
          manifest,
          streamElementIndex,
          selection,
          trackEncryptionBoxes,
          transferListener);
  return new ChunkSampleStream<>(
      manifest.streamElements[streamElementIndex].type,
      null,
      null,
      chunkSource,
      this,
      allocator,
      positionUs,
      minLoadableRetryCount,
      eventDispatcher);
}
 
Example #10
Source File: DashMediaPeriod.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void releaseDisabledStreams(
    TrackSelection[] selections, boolean[] mayRetainStreamFlags, SampleStream[] streams) {
  for (int i = 0; i < selections.length; i++) {
    if (selections[i] == null || !mayRetainStreamFlags[i]) {
      if (streams[i] instanceof ChunkSampleStream) {
        @SuppressWarnings("unchecked")
        ChunkSampleStream<DashChunkSource> stream =
            (ChunkSampleStream<DashChunkSource>) streams[i];
        stream.release(this);
      } else if (streams[i] instanceof EmbeddedSampleStream) {
        ((EmbeddedSampleStream) streams[i]).release();
      }
      streams[i] = null;
    }
  }
}
 
Example #11
Source File: DashMediaPeriod.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private void releaseDisabledStreams(
    TrackSelection[] selections, boolean[] mayRetainStreamFlags, SampleStream[] streams) {
  for (int i = 0; i < selections.length; i++) {
    if (selections[i] == null || !mayRetainStreamFlags[i]) {
      if (streams[i] instanceof ChunkSampleStream) {
        @SuppressWarnings("unchecked")
        ChunkSampleStream<DashChunkSource> stream =
            (ChunkSampleStream<DashChunkSource>) streams[i];
        stream.release(this);
      } else if (streams[i] instanceof EmbeddedSampleStream) {
        ((EmbeddedSampleStream) streams[i]).release();
      }
      streams[i] = null;
    }
  }
}
 
Example #12
Source File: SsMediaPeriod.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public void updateManifest(SsManifest manifest) {
  this.manifest = manifest;
  for (ChunkSampleStream<SsChunkSource> sampleStream : sampleStreams) {
    sampleStream.getChunkSource().updateManifest(manifest);
  }
  callback.onContinueLoadingRequested(this);
}
 
Example #13
Source File: DashMediaPeriod.java    From K-Sonic with MIT License 5 votes vote down vote up
@Override
public long seekToUs(long positionUs) {
  for (ChunkSampleStream<DashChunkSource> sampleStream : sampleStreams) {
    sampleStream.seekToUs(positionUs);
  }
  return positionUs;
}
 
Example #14
Source File: SsMediaPeriod.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public void release() {
  for (ChunkSampleStream<SsChunkSource> sampleStream : sampleStreams) {
    sampleStream.release();
  }
  callback = null;
  eventDispatcher.mediaPeriodReleased();
}
 
Example #15
Source File: SsMediaPeriod.java    From K-Sonic with MIT License 5 votes vote down vote up
public void updateManifest(SsManifest manifest) {
  this.manifest = manifest;
  for (ChunkSampleStream<SsChunkSource> sampleStream : sampleStreams) {
    sampleStream.getChunkSource().updateManifest(manifest);
  }
  callback.onContinueLoadingRequested(this);
}
 
Example #16
Source File: SsMediaPeriod.java    From K-Sonic with MIT License 5 votes vote down vote up
@Override
public long getBufferedPositionUs() {
  long bufferedPositionUs = Long.MAX_VALUE;
  for (ChunkSampleStream<SsChunkSource> sampleStream : sampleStreams) {
    long rendererBufferedPositionUs = sampleStream.getBufferedPositionUs();
    if (rendererBufferedPositionUs != C.TIME_END_OF_SOURCE) {
      bufferedPositionUs = Math.min(bufferedPositionUs, rendererBufferedPositionUs);
    }
  }
  return bufferedPositionUs == Long.MAX_VALUE ? C.TIME_END_OF_SOURCE : bufferedPositionUs;
}
 
Example #17
Source File: SsMediaPeriod.java    From K-Sonic with MIT License 5 votes vote down vote up
@Override
public long seekToUs(long positionUs) {
  for (ChunkSampleStream<SsChunkSource> sampleStream : sampleStreams) {
    sampleStream.seekToUs(positionUs);
  }
  return positionUs;
}
 
Example #18
Source File: DashMediaPeriod.java    From K-Sonic with MIT License 5 votes vote down vote up
@Override
public long getBufferedPositionUs() {
  long bufferedPositionUs = Long.MAX_VALUE;
  for (ChunkSampleStream<DashChunkSource> sampleStream : sampleStreams) {
    long rendererBufferedPositionUs = sampleStream.getBufferedPositionUs();
    if (rendererBufferedPositionUs != C.TIME_END_OF_SOURCE) {
      bufferedPositionUs = Math.min(bufferedPositionUs, rendererBufferedPositionUs);
    }
  }
  return bufferedPositionUs == Long.MAX_VALUE ? C.TIME_END_OF_SOURCE : bufferedPositionUs;
}
 
Example #19
Source File: SsMediaPeriod.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public long seekToUs(long positionUs) {
  for (ChunkSampleStream<SsChunkSource> sampleStream : sampleStreams) {
    sampleStream.seekToUs(positionUs);
  }
  return positionUs;
}
 
Example #20
Source File: SsMediaPeriod.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public long seekToUs(long positionUs) {
  for (ChunkSampleStream<SsChunkSource> sampleStream : sampleStreams) {
    sampleStream.seekToUs(positionUs);
  }
  return positionUs;
}
 
Example #21
Source File: SsMediaPeriod.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public void release() {
  for (ChunkSampleStream<SsChunkSource> sampleStream : sampleStreams) {
    sampleStream.release();
  }
  callback = null;
  eventDispatcher.mediaPeriodReleased();
}
 
Example #22
Source File: SsMediaPeriod.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public void updateManifest(SsManifest manifest) {
  this.manifest = manifest;
  for (ChunkSampleStream<SsChunkSource> sampleStream : sampleStreams) {
    sampleStream.getChunkSource().updateManifest(manifest);
  }
  callback.onContinueLoadingRequested(this);
}
 
Example #23
Source File: SsMediaPeriod.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public void updateManifest(SsManifest manifest) {
  this.manifest = manifest;
  for (ChunkSampleStream<SsChunkSource> sampleStream : sampleStreams) {
    sampleStream.getChunkSource().updateManifest(manifest);
  }
  callback.onContinueLoadingRequested(this);
}
 
Example #24
Source File: DashMediaPeriod.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
public void release() {
  playerEmsgHandler.release();
  for (ChunkSampleStream<DashChunkSource> sampleStream : sampleStreams) {
    sampleStream.release(this);
  }
  callback = null;
  eventDispatcher.mediaPeriodReleased();
}
 
Example #25
Source File: DashMediaPeriod.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public long getAdjustedSeekPositionUs(long positionUs, SeekParameters seekParameters) {
  for (ChunkSampleStream<DashChunkSource> sampleStream : sampleStreams) {
    if (sampleStream.primaryTrackType == C.TRACK_TYPE_VIDEO) {
      return sampleStream.getAdjustedSeekPositionUs(positionUs, seekParameters);
    }
  }
  return positionUs;
}
 
Example #26
Source File: DashMediaPeriod.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public long selectTracks(TrackSelection[] selections, boolean[] mayRetainStreamFlags,
    SampleStream[] streams, boolean[] streamResetFlags, long positionUs) {
  int[] streamIndexToTrackGroupIndex = getStreamIndexToTrackGroupIndex(selections);
  releaseDisabledStreams(selections, mayRetainStreamFlags, streams);
  releaseOrphanEmbeddedStreams(selections, streams, streamIndexToTrackGroupIndex);
  selectNewStreams(
      selections, streams, streamResetFlags, positionUs, streamIndexToTrackGroupIndex);

  ArrayList<ChunkSampleStream<DashChunkSource>> sampleStreamList = new ArrayList<>();
  ArrayList<EventSampleStream> eventSampleStreamList = new ArrayList<>();
  for (SampleStream sampleStream : streams) {
    if (sampleStream instanceof ChunkSampleStream) {
      @SuppressWarnings("unchecked")
      ChunkSampleStream<DashChunkSource> stream =
          (ChunkSampleStream<DashChunkSource>) sampleStream;
      sampleStreamList.add(stream);
    } else if (sampleStream instanceof EventSampleStream) {
      eventSampleStreamList.add((EventSampleStream) sampleStream);
    }
  }
  sampleStreams = newSampleStreamArray(sampleStreamList.size());
  sampleStreamList.toArray(sampleStreams);
  eventSampleStreams = new EventSampleStream[eventSampleStreamList.size()];
  eventSampleStreamList.toArray(eventSampleStreams);

  compositeSequenceableLoader =
      compositeSequenceableLoaderFactory.createCompositeSequenceableLoader(sampleStreams);
  return positionUs;
}
 
Example #27
Source File: DashMediaPeriod.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public synchronized void onSampleStreamReleased(ChunkSampleStream<DashChunkSource> stream) {
  PlayerTrackEmsgHandler trackEmsgHandler = trackEmsgHandlerBySampleStream.remove(stream);
  if (trackEmsgHandler != null) {
    trackEmsgHandler.release();
  }
}
 
Example #28
Source File: DashMediaPeriod.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public void release() {
  playerEmsgHandler.release();
  for (ChunkSampleStream<DashChunkSource> sampleStream : sampleStreams) {
    sampleStream.release(this);
  }
  callback = null;
  eventDispatcher.mediaPeriodReleased();
}
 
Example #29
Source File: DashMediaPeriod.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Updates the {@link DashManifest} and the index of this period in the manifest.
 *
 * @param manifest The updated manifest.
 * @param periodIndex the new index of this period in the updated manifest.
 */
public void updateManifest(DashManifest manifest, int periodIndex) {
  this.manifest = manifest;
  if (this.periodIndex != periodIndex) {
    eventDispatcher =
        eventDispatcher.withParameters(
            /* windowIndex= */ 0,
            eventDispatcher.mediaPeriodId.copyWithPeriodIndex(periodIndex),
            manifest.getPeriod(periodIndex).startMs);
  }
  this.periodIndex = periodIndex;
  playerEmsgHandler.updateManifest(manifest);
  if (sampleStreams != null) {
    for (ChunkSampleStream<DashChunkSource> sampleStream : sampleStreams) {
      sampleStream.getChunkSource().updateManifest(manifest, periodIndex);
    }
    callback.onContinueLoadingRequested(this);
  }
  eventStreams = manifest.getPeriod(periodIndex).eventStreams;
  for (EventSampleStream eventSampleStream : eventSampleStreams) {
    for (EventStream eventStream : eventStreams) {
      if (eventStream.id().equals(eventSampleStream.eventStreamId())) {
        eventSampleStream.updateEventStream(eventStream, manifest.dynamic);
        break;
      }
    }
  }
}
 
Example #30
Source File: DashMediaPeriod.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public long selectTracks(TrackSelection[] selections, boolean[] mayRetainStreamFlags,
    SampleStream[] streams, boolean[] streamResetFlags, long positionUs) {
  int[] streamIndexToTrackGroupIndex = getStreamIndexToTrackGroupIndex(selections);
  releaseDisabledStreams(selections, mayRetainStreamFlags, streams);
  releaseOrphanEmbeddedStreams(selections, streams, streamIndexToTrackGroupIndex);
  selectNewStreams(
      selections, streams, streamResetFlags, positionUs, streamIndexToTrackGroupIndex);

  ArrayList<ChunkSampleStream<DashChunkSource>> sampleStreamList = new ArrayList<>();
  ArrayList<EventSampleStream> eventSampleStreamList = new ArrayList<>();
  for (SampleStream sampleStream : streams) {
    if (sampleStream instanceof ChunkSampleStream) {
      @SuppressWarnings("unchecked")
      ChunkSampleStream<DashChunkSource> stream =
          (ChunkSampleStream<DashChunkSource>) sampleStream;
      sampleStreamList.add(stream);
    } else if (sampleStream instanceof EventSampleStream) {
      eventSampleStreamList.add((EventSampleStream) sampleStream);
    }
  }
  sampleStreams = newSampleStreamArray(sampleStreamList.size());
  sampleStreamList.toArray(sampleStreams);
  eventSampleStreams = new EventSampleStream[eventSampleStreamList.size()];
  eventSampleStreamList.toArray(eventSampleStreams);

  compositeSequenceableLoader =
      compositeSequenceableLoaderFactory.createCompositeSequenceableLoader(sampleStreams);
  return positionUs;
}