Java Code Examples for com.google.android.exoplayer2.extractor.SeekMap#getDurationUs()

The following examples show how to use com.google.android.exoplayer2.extractor.SeekMap#getDurationUs() . 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: TestUtil.java    From ExoPlayer-Offline with Apache License 2.0 5 votes vote down vote up
/**
 * Asserts that {@code extractor} consumes {@code sampleFile} successfully and its output equals
 * to a prerecorded output dump file with the name {@code sampleFile} + "{@value
 * #DUMP_EXTENSION}". If {@code simulateUnknownLength} is true and {@code sampleFile} + "{@value
 * #UNKNOWN_LENGTH_EXTENSION}" exists, it's preferred.
 *
 * @param extractor The {@link Extractor} to be tested.
 * @param sampleFile The path to the input sample.
 * @param fileData Content of the input file.
 * @param instrumentation To be used to load the sample file.
 * @param simulateIOErrors If true simulates IOErrors.
 * @param simulateUnknownLength If true simulates unknown input length.
 * @param simulatePartialReads If true simulates partial reads.
 * @return The {@link FakeExtractorOutput} used in the test.
 * @throws IOException If reading from the input fails.
 * @throws InterruptedException If interrupted while reading from the input.
 */
public static FakeExtractorOutput assertOutput(Extractor extractor, String sampleFile,
    byte[] fileData, Instrumentation instrumentation, boolean simulateIOErrors,
    boolean simulateUnknownLength, boolean simulatePartialReads) throws IOException,
    InterruptedException {
  FakeExtractorInput input = new FakeExtractorInput.Builder().setData(fileData)
      .setSimulateIOErrors(simulateIOErrors)
      .setSimulateUnknownLength(simulateUnknownLength)
      .setSimulatePartialReads(simulatePartialReads).build();

  Assert.assertTrue(sniffTestData(extractor, input));
  input.resetPeekPosition();
  FakeExtractorOutput extractorOutput = consumeTestData(extractor, input, 0, true);

  if (simulateUnknownLength
      && assetExists(instrumentation, sampleFile + UNKNOWN_LENGTH_EXTENSION)) {
    extractorOutput.assertOutput(instrumentation, sampleFile + UNKNOWN_LENGTH_EXTENSION);
  } else {
    extractorOutput.assertOutput(instrumentation, sampleFile + ".0" + DUMP_EXTENSION);
  }

  SeekMap seekMap = extractorOutput.seekMap;
  if (seekMap.isSeekable()) {
    long durationUs = seekMap.getDurationUs();
    for (int j = 0; j < 4; j++) {
      long timeUs = (durationUs * j) / 3;
      long position = seekMap.getPosition(timeUs);
      input.setPosition((int) position);
      for (int i = 0; i < extractorOutput.numberOfTracks; i++) {
        extractorOutput.trackOutputs.valueAt(i).clear();
      }

      consumeTestData(extractor, input, timeUs, extractorOutput, false);
      extractorOutput.assertOutput(instrumentation, sampleFile + '.' + j + DUMP_EXTENSION);
    }
  }

  return extractorOutput;
}
 
Example 2
Source File: ProgressiveMediaPeriod.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
private void maybeFinishPrepare() {
  SeekMap seekMap = this.seekMap;
  if (released || prepared || !sampleQueuesBuilt || seekMap == null) {
    return;
  }
  for (SampleQueue sampleQueue : sampleQueues) {
    if (sampleQueue.getUpstreamFormat() == null) {
      return;
    }
  }
  loadCondition.close();
  int trackCount = sampleQueues.length;
  TrackGroup[] trackArray = new TrackGroup[trackCount];
  boolean[] trackIsAudioVideoFlags = new boolean[trackCount];
  durationUs = seekMap.getDurationUs();
  for (int i = 0; i < trackCount; i++) {
    Format trackFormat = sampleQueues[i].getUpstreamFormat();
    String mimeType = trackFormat.sampleMimeType;
    boolean isAudio = MimeTypes.isAudio(mimeType);
    boolean isAudioVideo = isAudio || MimeTypes.isVideo(mimeType);
    trackIsAudioVideoFlags[i] = isAudioVideo;
    haveAudioVideoTracks |= isAudioVideo;
    IcyHeaders icyHeaders = this.icyHeaders;
    if (icyHeaders != null) {
      if (isAudio || sampleQueueTrackIds[i].isIcyTrack) {
        Metadata metadata = trackFormat.metadata;
        trackFormat =
            trackFormat.copyWithMetadata(
                metadata == null
                    ? new Metadata(icyHeaders)
                    : metadata.copyWithAppendedEntries(icyHeaders));
      }
      if (isAudio
          && trackFormat.bitrate == Format.NO_VALUE
          && icyHeaders.bitrate != Format.NO_VALUE) {
        trackFormat = trackFormat.copyWithBitrate(icyHeaders.bitrate);
      }
    }
    trackArray[i] = new TrackGroup(trackFormat);
  }
  isLive = length == C.LENGTH_UNSET && seekMap.getDurationUs() == C.TIME_UNSET;
  dataType = isLive ? C.DATA_TYPE_MEDIA_PROGRESSIVE_LIVE : C.DATA_TYPE_MEDIA;
  preparedState =
      new PreparedState(seekMap, new TrackGroupArray(trackArray), trackIsAudioVideoFlags);
  prepared = true;
  listener.onSourceInfoRefreshed(durationUs, seekMap.isSeekable(), isLive);
  Assertions.checkNotNull(callback).onPrepared(this);
}
 
Example 3
Source File: ProgressiveMediaPeriod.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
private void maybeFinishPrepare() {
  SeekMap seekMap = this.seekMap;
  if (released || prepared || !sampleQueuesBuilt || seekMap == null) {
    return;
  }
  for (SampleQueue sampleQueue : sampleQueues) {
    if (sampleQueue.getUpstreamFormat() == null) {
      return;
    }
  }
  loadCondition.close();
  int trackCount = sampleQueues.length;
  TrackGroup[] trackArray = new TrackGroup[trackCount];
  boolean[] trackIsAudioVideoFlags = new boolean[trackCount];
  durationUs = seekMap.getDurationUs();
  for (int i = 0; i < trackCount; i++) {
    Format trackFormat = sampleQueues[i].getUpstreamFormat();
    String mimeType = trackFormat.sampleMimeType;
    boolean isAudio = MimeTypes.isAudio(mimeType);
    boolean isAudioVideo = isAudio || MimeTypes.isVideo(mimeType);
    trackIsAudioVideoFlags[i] = isAudioVideo;
    haveAudioVideoTracks |= isAudioVideo;
    IcyHeaders icyHeaders = this.icyHeaders;
    if (icyHeaders != null) {
      if (isAudio || sampleQueueTrackIds[i].isIcyTrack) {
        Metadata metadata = trackFormat.metadata;
        trackFormat =
            trackFormat.copyWithMetadata(
                metadata == null
                    ? new Metadata(icyHeaders)
                    : metadata.copyWithAppendedEntries(icyHeaders));
      }
      if (isAudio
          && trackFormat.bitrate == Format.NO_VALUE
          && icyHeaders.bitrate != Format.NO_VALUE) {
        trackFormat = trackFormat.copyWithBitrate(icyHeaders.bitrate);
      }
    }
    trackArray[i] = new TrackGroup(trackFormat);
  }
  dataType =
      length == C.LENGTH_UNSET && seekMap.getDurationUs() == C.TIME_UNSET
          ? C.DATA_TYPE_MEDIA_PROGRESSIVE_LIVE
          : C.DATA_TYPE_MEDIA;
  preparedState =
      new PreparedState(seekMap, new TrackGroupArray(trackArray), trackIsAudioVideoFlags);
  prepared = true;
  listener.onSourceInfoRefreshed(durationUs, seekMap.isSeekable());
  Assertions.checkNotNull(callback).onPrepared(this);
}
 
Example 4
Source File: ProgressiveMediaPeriod.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
private void maybeFinishPrepare() {
  SeekMap seekMap = this.seekMap;
  if (released || prepared || !sampleQueuesBuilt || seekMap == null) {
    return;
  }
  for (SampleQueue sampleQueue : sampleQueues) {
    if (sampleQueue.getUpstreamFormat() == null) {
      return;
    }
  }
  loadCondition.close();
  int trackCount = sampleQueues.length;
  TrackGroup[] trackArray = new TrackGroup[trackCount];
  boolean[] trackIsAudioVideoFlags = new boolean[trackCount];
  durationUs = seekMap.getDurationUs();
  for (int i = 0; i < trackCount; i++) {
    Format trackFormat = sampleQueues[i].getUpstreamFormat();
    String mimeType = trackFormat.sampleMimeType;
    boolean isAudio = MimeTypes.isAudio(mimeType);
    boolean isAudioVideo = isAudio || MimeTypes.isVideo(mimeType);
    trackIsAudioVideoFlags[i] = isAudioVideo;
    haveAudioVideoTracks |= isAudioVideo;
    IcyHeaders icyHeaders = this.icyHeaders;
    if (icyHeaders != null) {
      if (isAudio || sampleQueueTrackIds[i].isIcyTrack) {
        Metadata metadata = trackFormat.metadata;
        trackFormat =
            trackFormat.copyWithMetadata(
                metadata == null
                    ? new Metadata(icyHeaders)
                    : metadata.copyWithAppendedEntries(icyHeaders));
      }
      if (isAudio
          && trackFormat.bitrate == Format.NO_VALUE
          && icyHeaders.bitrate != Format.NO_VALUE) {
        trackFormat = trackFormat.copyWithBitrate(icyHeaders.bitrate);
      }
    }
    trackArray[i] = new TrackGroup(trackFormat);
  }
  dataType =
      length == C.LENGTH_UNSET && seekMap.getDurationUs() == C.TIME_UNSET
          ? C.DATA_TYPE_MEDIA_PROGRESSIVE_LIVE
          : C.DATA_TYPE_MEDIA;
  preparedState =
      new PreparedState(seekMap, new TrackGroupArray(trackArray), trackIsAudioVideoFlags);
  prepared = true;
  listener.onSourceInfoRefreshed(durationUs, seekMap.isSeekable());
  Assertions.checkNotNull(callback).onPrepared(this);
}