com.google.android.exoplayer2.extractor.SeekMap Java Examples

The following examples show how to use com.google.android.exoplayer2.extractor.SeekMap. 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: DefaultDashChunkSource.java    From K-Sonic with MIT License 6 votes vote down vote up
@Override
public void onChunkLoadCompleted(Chunk chunk) {
  if (chunk instanceof InitializationChunk) {
    InitializationChunk initializationChunk = (InitializationChunk) chunk;
    RepresentationHolder representationHolder =
        representationHolders[trackSelection.indexOf(initializationChunk.trackFormat)];
    // The null check avoids overwriting an index obtained from the manifest with one obtained
    // from the stream. If the manifest defines an index then the stream shouldn't, but in cases
    // where it does we should ignore it.
    if (representationHolder.segmentIndex == null) {
      SeekMap seekMap = representationHolder.extractorWrapper.getSeekMap();
      if (seekMap != null) {
        representationHolder.segmentIndex = new DashWrappingSegmentIndex((ChunkIndex) seekMap);
      }
    }
  }
}
 
Example #2
Source File: AdtsExtractor.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private void maybeOutputSeekMap(
    long inputLength, boolean canUseConstantBitrateSeeking, boolean readEndOfStream) {
  if (hasOutputSeekMap) {
    return;
  }
  boolean useConstantBitrateSeeking = canUseConstantBitrateSeeking && averageFrameSize > 0;
  if (useConstantBitrateSeeking
      && reader.getSampleDurationUs() == C.TIME_UNSET
      && !readEndOfStream) {
    // Wait for the sampleDurationUs to be available, or for the end of the stream to be reached,
    // before creating seek map.
    return;
  }

  ExtractorOutput extractorOutput = Assertions.checkNotNull(this.extractorOutput);
  if (useConstantBitrateSeeking && reader.getSampleDurationUs() != C.TIME_UNSET) {
    extractorOutput.seekMap(getConstantBitrateSeekMap(inputLength));
  } else {
    extractorOutput.seekMap(new SeekMap.Unseekable(C.TIME_UNSET));
  }
  hasOutputSeekMap = true;
}
 
Example #3
Source File: DefaultDashChunkSource.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onChunkLoadCompleted(Chunk chunk) {
  if (chunk instanceof InitializationChunk) {
    InitializationChunk initializationChunk = (InitializationChunk) chunk;
    int trackIndex = trackSelection.indexOf(initializationChunk.trackFormat);
    RepresentationHolder representationHolder = representationHolders[trackIndex];
    // The null check avoids overwriting an index obtained from the manifest with one obtained
    // from the stream. If the manifest defines an index then the stream shouldn't, but in cases
    // where it does we should ignore it.
    if (representationHolder.segmentIndex == null) {
      SeekMap seekMap = representationHolder.extractorWrapper.getSeekMap();
      if (seekMap != null) {
        representationHolders[trackIndex] =
            representationHolder.copyWithNewSegmentIndex(
                new DashWrappingSegmentIndex(
                    (ChunkIndex) seekMap,
                    representationHolder.representation.presentationTimeOffsetUs));
      }
    }
  }
  if (playerTrackEmsgHandler != null) {
    playerTrackEmsgHandler.onChunkLoadCompleted(chunk);
  }
}
 
Example #4
Source File: DefaultDashChunkSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onChunkLoadCompleted(Chunk chunk) {
  if (chunk instanceof InitializationChunk) {
    InitializationChunk initializationChunk = (InitializationChunk) chunk;
    int trackIndex = trackSelection.indexOf(initializationChunk.trackFormat);
    RepresentationHolder representationHolder = representationHolders[trackIndex];
    // The null check avoids overwriting an index obtained from the manifest with one obtained
    // from the stream. If the manifest defines an index then the stream shouldn't, but in cases
    // where it does we should ignore it.
    if (representationHolder.segmentIndex == null) {
      SeekMap seekMap = representationHolder.extractorWrapper.getSeekMap();
      if (seekMap != null) {
        representationHolders[trackIndex] =
            representationHolder.copyWithNewSegmentIndex(
                new DashWrappingSegmentIndex(
                    (ChunkIndex) seekMap,
                    representationHolder.representation.presentationTimeOffsetUs));
      }
    }
  }
  if (playerTrackEmsgHandler != null) {
    playerTrackEmsgHandler.onChunkLoadCompleted(chunk);
  }
}
 
Example #5
Source File: TsExtractor.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private void maybeOutputSeekMap(long inputLength) {
  if (!hasOutputSeekMap) {
    hasOutputSeekMap = true;
    if (durationReader.getDurationUs() != C.TIME_UNSET) {
      tsBinarySearchSeeker =
          new TsBinarySearchSeeker(
              durationReader.getPcrTimestampAdjuster(),
              durationReader.getDurationUs(),
              inputLength,
              pcrPid);
      output.seekMap(tsBinarySearchSeeker.getSeekMap());
    } else {
      output.seekMap(new SeekMap.Unseekable(durationReader.getDurationUs()));
    }
  }
}
 
Example #6
Source File: FlacExtractor.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Outputs a {@link SeekMap} and returns a {@link FlacBinarySearchSeeker} if one is required to
 * handle seeks.
 */
@Nullable
private static FlacBinarySearchSeeker outputSeekMap(
    FlacDecoderJni decoderJni,
    FlacStreamMetadata streamMetadata,
    long streamLength,
    ExtractorOutput output) {
  boolean haveSeekTable = decoderJni.getSeekPoints(/* timeUs= */ 0) != null;
  FlacBinarySearchSeeker binarySearchSeeker = null;
  SeekMap seekMap;
  if (haveSeekTable) {
    seekMap = new FlacSeekMap(streamMetadata.durationUs(), decoderJni);
  } else if (streamLength != C.LENGTH_UNSET) {
    long firstFramePosition = decoderJni.getDecodePosition();
    binarySearchSeeker =
        new FlacBinarySearchSeeker(streamMetadata, firstFramePosition, streamLength, decoderJni);
    seekMap = binarySearchSeeker.getSeekMap();
  } else {
    seekMap = new SeekMap.Unseekable(streamMetadata.durationUs());
  }
  output.seekMap(seekMap);
  return binarySearchSeeker;
}
 
Example #7
Source File: FlvExtractor.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Reads the body of a tag from the provided {@link ExtractorInput}.
 *
 * @param input The {@link ExtractorInput} from which to read.
 * @return True if the data was consumed by a reader. False if it was skipped.
 * @throws IOException If an error occurred reading or parsing data from the source.
 * @throws InterruptedException If the thread was interrupted.
 */
private boolean readTagData(ExtractorInput input) throws IOException, InterruptedException {
  boolean wasConsumed = true;
  if (tagType == TAG_TYPE_AUDIO && audioReader != null) {
    ensureReadyForMediaOutput();
    audioReader.consume(prepareTagData(input), mediaTagTimestampOffsetUs + tagTimestampUs);
  } else if (tagType == TAG_TYPE_VIDEO && videoReader != null) {
    ensureReadyForMediaOutput();
    videoReader.consume(prepareTagData(input), mediaTagTimestampOffsetUs + tagTimestampUs);
  } else if (tagType == TAG_TYPE_SCRIPT_DATA && !outputSeekMap) {
    metadataReader.consume(prepareTagData(input), tagTimestampUs);
    long durationUs = metadataReader.getDurationUs();
    if (durationUs != C.TIME_UNSET) {
      extractorOutput.seekMap(new SeekMap.Unseekable(durationUs));
      outputSeekMap = true;
    }
  } else {
    input.skipFully(tagDataSize);
    wasConsumed = false;
  }
  bytesToNextTagHeader = 4; // There's a 4 byte previous tag size before the next header.
  state = STATE_SKIPPING_TO_TAG_HEADER;
  return wasConsumed;
}
 
Example #8
Source File: AmrExtractor.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
private void maybeOutputSeekMap(long inputLength, int sampleReadResult) {
  if (hasOutputSeekMap) {
    return;
  }

  if ((flags & FLAG_ENABLE_CONSTANT_BITRATE_SEEKING) == 0
      || inputLength == C.LENGTH_UNSET
      || (firstSampleSize != C.LENGTH_UNSET && firstSampleSize != currentSampleSize)) {
    seekMap = new SeekMap.Unseekable(C.TIME_UNSET);
    extractorOutput.seekMap(seekMap);
    hasOutputSeekMap = true;
  } else if (numSamplesWithSameSize >= NUM_SAME_SIZE_CONSTANT_BIT_RATE_THRESHOLD
      || sampleReadResult == RESULT_END_OF_INPUT) {
    seekMap = getConstantBitrateSeekMap(inputLength);
    extractorOutput.seekMap(seekMap);
    hasOutputSeekMap = true;
  }
}
 
Example #9
Source File: FlacExtractor.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Outputs a {@link SeekMap} and returns a {@link FlacBinarySearchSeeker} if one is required to
 * handle seeks.
 */
@Nullable
private static FlacBinarySearchSeeker outputSeekMap(
    FlacDecoderJni decoderJni,
    FlacStreamMetadata streamMetadata,
    long streamLength,
    ExtractorOutput output) {
  boolean haveSeekTable = decoderJni.getSeekPoints(/* timeUs= */ 0) != null;
  FlacBinarySearchSeeker binarySearchSeeker = null;
  SeekMap seekMap;
  if (haveSeekTable) {
    seekMap = new FlacSeekMap(streamMetadata.durationUs(), decoderJni);
  } else if (streamLength != C.LENGTH_UNSET) {
    long firstFramePosition = decoderJni.getDecodePosition();
    binarySearchSeeker =
        new FlacBinarySearchSeeker(streamMetadata, firstFramePosition, streamLength, decoderJni);
    seekMap = binarySearchSeeker.getSeekMap();
  } else {
    seekMap = new SeekMap.Unseekable(streamMetadata.durationUs());
  }
  output.seekMap(seekMap);
  return binarySearchSeeker;
}
 
Example #10
Source File: AmrExtractor.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void maybeOutputSeekMap(long inputLength, int sampleReadResult) {
  if (hasOutputSeekMap) {
    return;
  }

  if ((flags & FLAG_ENABLE_CONSTANT_BITRATE_SEEKING) == 0
      || inputLength == C.LENGTH_UNSET
      || (firstSampleSize != C.LENGTH_UNSET && firstSampleSize != currentSampleSize)) {
    seekMap = new SeekMap.Unseekable(C.TIME_UNSET);
    extractorOutput.seekMap(seekMap);
    hasOutputSeekMap = true;
  } else if (numSamplesWithSameSize >= NUM_SAME_SIZE_CONSTANT_BIT_RATE_THRESHOLD
      || sampleReadResult == RESULT_END_OF_INPUT) {
    seekMap = getConstantBitrateSeekMap(inputLength);
    extractorOutput.seekMap(seekMap);
    hasOutputSeekMap = true;
  }
}
 
Example #11
Source File: DefaultDashChunkSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onChunkLoadCompleted(Chunk chunk) {
  if (chunk instanceof InitializationChunk) {
    InitializationChunk initializationChunk = (InitializationChunk) chunk;
    int trackIndex = trackSelection.indexOf(initializationChunk.trackFormat);
    RepresentationHolder representationHolder = representationHolders[trackIndex];
    // The null check avoids overwriting an index obtained from the manifest with one obtained
    // from the stream. If the manifest defines an index then the stream shouldn't, but in cases
    // where it does we should ignore it.
    if (representationHolder.segmentIndex == null) {
      SeekMap seekMap = representationHolder.extractorWrapper.getSeekMap();
      if (seekMap != null) {
        representationHolders[trackIndex] =
            representationHolder.copyWithNewSegmentIndex(
                new DashWrappingSegmentIndex(
                    (ChunkIndex) seekMap,
                    representationHolder.representation.presentationTimeOffsetUs));
      }
    }
  }
  if (playerTrackEmsgHandler != null) {
    playerTrackEmsgHandler.onChunkLoadCompleted(chunk);
  }
}
 
Example #12
Source File: AdtsExtractor.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private void maybeOutputSeekMap(
    long inputLength, boolean canUseConstantBitrateSeeking, boolean readEndOfStream) {
  if (hasOutputSeekMap) {
    return;
  }
  boolean useConstantBitrateSeeking = canUseConstantBitrateSeeking && averageFrameSize > 0;
  if (useConstantBitrateSeeking
      && reader.getSampleDurationUs() == C.TIME_UNSET
      && !readEndOfStream) {
    // Wait for the sampleDurationUs to be available, or for the end of the stream to be reached,
    // before creating seek map.
    return;
  }

  ExtractorOutput extractorOutput = Assertions.checkNotNull(this.extractorOutput);
  if (useConstantBitrateSeeking && reader.getSampleDurationUs() != C.TIME_UNSET) {
    extractorOutput.seekMap(getConstantBitrateSeekMap(inputLength));
  } else {
    extractorOutput.seekMap(new SeekMap.Unseekable(C.TIME_UNSET));
  }
  hasOutputSeekMap = true;
}
 
Example #13
Source File: FlvExtractor.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Reads the body of a tag from the provided {@link ExtractorInput}.
 *
 * @param input The {@link ExtractorInput} from which to read.
 * @return True if the data was consumed by a reader. False if it was skipped.
 * @throws IOException If an error occurred reading or parsing data from the source.
 * @throws InterruptedException If the thread was interrupted.
 */
private boolean readTagData(ExtractorInput input) throws IOException, InterruptedException {
  boolean wasConsumed = true;
  if (tagType == TAG_TYPE_AUDIO && audioReader != null) {
    ensureReadyForMediaOutput();
    audioReader.consume(prepareTagData(input), mediaTagTimestampOffsetUs + tagTimestampUs);
  } else if (tagType == TAG_TYPE_VIDEO && videoReader != null) {
    ensureReadyForMediaOutput();
    videoReader.consume(prepareTagData(input), mediaTagTimestampOffsetUs + tagTimestampUs);
  } else if (tagType == TAG_TYPE_SCRIPT_DATA && !outputSeekMap) {
    metadataReader.consume(prepareTagData(input), tagTimestampUs);
    long durationUs = metadataReader.getDurationUs();
    if (durationUs != C.TIME_UNSET) {
      extractorOutput.seekMap(new SeekMap.Unseekable(durationUs));
      outputSeekMap = true;
    }
  } else {
    input.skipFully(tagDataSize);
    wasConsumed = false;
  }
  bytesToNextTagHeader = 4; // There's a 4 byte previous tag size before the next header.
  state = STATE_SKIPPING_TO_TAG_HEADER;
  return wasConsumed;
}
 
Example #14
Source File: TsExtractor.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
private void maybeOutputSeekMap(long inputLength) {
  if (!hasOutputSeekMap) {
    hasOutputSeekMap = true;
    if (durationReader.getDurationUs() != C.TIME_UNSET) {
      tsBinarySearchSeeker =
          new TsBinarySearchSeeker(
              durationReader.getPcrTimestampAdjuster(),
              durationReader.getDurationUs(),
              inputLength,
              pcrPid);
      output.seekMap(tsBinarySearchSeeker.getSeekMap());
    } else {
      output.seekMap(new SeekMap.Unseekable(durationReader.getDurationUs()));
    }
  }
}
 
Example #15
Source File: PsExtractor.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private void maybeOutputSeekMap(long inputLength) {
  if (!hasOutputSeekMap) {
    hasOutputSeekMap = true;
    if (durationReader.getDurationUs() != C.TIME_UNSET) {
      psBinarySearchSeeker =
          new PsBinarySearchSeeker(
              durationReader.getScrTimestampAdjuster(),
              durationReader.getDurationUs(),
              inputLength);
      output.seekMap(psBinarySearchSeeker.getSeekMap());
    } else {
      output.seekMap(new SeekMap.Unseekable(durationReader.getDurationUs()));
    }
  }
}
 
Example #16
Source File: RawCcExtractor.java    From K-Sonic with MIT License 5 votes vote down vote up
@Override
public void init(ExtractorOutput output) {
  output.seekMap(new SeekMap.Unseekable(C.TIME_UNSET));
  trackOutput = output.track(0, C.TRACK_TYPE_TEXT);
  output.endTracks();
  trackOutput.format(format);
}
 
Example #17
Source File: RawCcExtractor.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void init(ExtractorOutput output) {
  output.seekMap(new SeekMap.Unseekable(C.TIME_UNSET));
  trackOutput = output.track(0, C.TRACK_TYPE_TEXT);
  output.endTracks();
  trackOutput.format(format);
}
 
Example #18
Source File: StreamReader.java    From K-Sonic with MIT License 5 votes vote down vote up
private int readPayload(ExtractorInput input, PositionHolder seekPosition)
    throws IOException, InterruptedException {
  long position = oggSeeker.read(input);
  if (position >= 0) {
    seekPosition.position = position;
    return Extractor.RESULT_SEEK;
  } else if (position < -1) {
    onSeekEnd(-(position + 2));
  }
  if (!seekMapSet) {
    SeekMap seekMap = oggSeeker.createSeekMap();
    extractorOutput.seekMap(seekMap);
    seekMapSet = true;
  }

  if (lengthOfReadPacket > 0 || oggPacket.populate(input)) {
    lengthOfReadPacket = 0;
    ParsableByteArray payload = oggPacket.getPayload();
    long granulesInPacket = preparePayload(payload);
    if (granulesInPacket >= 0 && currentGranule + granulesInPacket >= targetGranule) {
      // calculate time and send payload data to codec
      long timeUs = convertGranuleToTime(currentGranule);
      trackOutput.sampleData(payload, payload.limit());
      trackOutput.sampleMetadata(timeUs, C.BUFFER_FLAG_KEY_FRAME, payload.limit(), 0, null);
      targetGranule = -1;
    }
    currentGranule += granulesInPacket;
  } else {
    state = STATE_END_OF_INPUT;
    return Extractor.RESULT_END_OF_INPUT;
  }
  return Extractor.RESULT_CONTINUE;
}
 
Example #19
Source File: ProgressiveMediaPeriod.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public long getAdjustedSeekPositionUs(long positionUs, SeekParameters seekParameters) {
  SeekMap seekMap = getPreparedState().seekMap;
  if (!seekMap.isSeekable()) {
    // Treat all seeks into non-seekable media as being to t=0.
    return 0;
  }
  SeekPoints seekPoints = seekMap.getSeekPoints(positionUs);
  return Util.resolveSeekPositionUs(
      positionUs, seekParameters, seekPoints.first.timeUs, seekPoints.second.timeUs);
}
 
Example #20
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 #21
Source File: PsExtractor.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private void maybeOutputSeekMap(long inputLength) {
  if (!hasOutputSeekMap) {
    hasOutputSeekMap = true;
    if (durationReader.getDurationUs() != C.TIME_UNSET) {
      psBinarySearchSeeker =
          new PsBinarySearchSeeker(
              durationReader.getScrTimestampAdjuster(),
              durationReader.getDurationUs(),
              inputLength);
      output.seekMap(psBinarySearchSeeker.getSeekMap());
    } else {
      output.seekMap(new SeekMap.Unseekable(durationReader.getDurationUs()));
    }
  }
}
 
Example #22
Source File: StreamReader.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private int readPayload(ExtractorInput input, PositionHolder seekPosition)
    throws IOException, InterruptedException {
  long position = oggSeeker.read(input);
  if (position >= 0) {
    seekPosition.position = position;
    return Extractor.RESULT_SEEK;
  } else if (position < -1) {
    onSeekEnd(-(position + 2));
  }
  if (!seekMapSet) {
    SeekMap seekMap = oggSeeker.createSeekMap();
    extractorOutput.seekMap(seekMap);
    seekMapSet = true;
  }

  if (lengthOfReadPacket > 0 || oggPacket.populate(input)) {
    lengthOfReadPacket = 0;
    ParsableByteArray payload = oggPacket.getPayload();
    long granulesInPacket = preparePayload(payload);
    if (granulesInPacket >= 0 && currentGranule + granulesInPacket >= targetGranule) {
      // calculate time and send payload data to codec
      long timeUs = convertGranuleToTime(currentGranule);
      trackOutput.sampleData(payload, payload.limit());
      trackOutput.sampleMetadata(timeUs, C.BUFFER_FLAG_KEY_FRAME, payload.limit(), 0, null);
      targetGranule = -1;
    }
    currentGranule += granulesInPacket;
  } else {
    state = STATE_END_OF_INPUT;
    return Extractor.RESULT_END_OF_INPUT;
  }
  return Extractor.RESULT_CONTINUE;
}
 
Example #23
Source File: ProgressiveMediaPeriod.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private void startLoading() {
  ExtractingLoadable loadable =
      new ExtractingLoadable(
          uri, dataSource, extractorHolder, /* extractorOutput= */ this, loadCondition);
  if (prepared) {
    SeekMap seekMap = getPreparedState().seekMap;
    Assertions.checkState(isPendingReset());
    if (durationUs != C.TIME_UNSET && pendingResetPositionUs > durationUs) {
      loadingFinished = true;
      pendingResetPositionUs = C.TIME_UNSET;
      return;
    }
    loadable.setLoadPosition(
        seekMap.getSeekPoints(pendingResetPositionUs).first.position, pendingResetPositionUs);
    pendingResetPositionUs = C.TIME_UNSET;
  }
  extractedSamplesCountAtStartOfLoad = getExtractedSamplesCount();
  long elapsedRealtimeMs =
      loader.startLoading(
          loadable, this, loadErrorHandlingPolicy.getMinimumLoadableRetryCount(dataType));
  eventDispatcher.loadStarted(
      loadable.dataSpec,
      C.DATA_TYPE_MEDIA,
      C.TRACK_TYPE_UNKNOWN,
      /* trackFormat= */ null,
      C.SELECTION_REASON_UNKNOWN,
      /* trackSelectionData= */ null,
      /* mediaStartTimeUs= */ loadable.seekTimeUs,
      durationUs,
      elapsedRealtimeMs);
}
 
Example #24
Source File: MatroskaExtractor.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Builds a {@link SeekMap} from the recently gathered Cues information.
 *
 * @return The built {@link SeekMap}. The returned {@link SeekMap} may be unseekable if cues
 *     information was missing or incomplete.
 */
private SeekMap buildSeekMap() {
  if (segmentContentPosition == C.POSITION_UNSET || durationUs == C.TIME_UNSET
      || cueTimesUs == null || cueTimesUs.size() == 0
      || cueClusterPositions == null || cueClusterPositions.size() != cueTimesUs.size()) {
    // Cues information is missing or incomplete.
    cueTimesUs = null;
    cueClusterPositions = null;
    return new SeekMap.Unseekable(durationUs);
  }
  int cuePointsSize = cueTimesUs.size();
  int[] sizes = new int[cuePointsSize];
  long[] offsets = new long[cuePointsSize];
  long[] durationsUs = new long[cuePointsSize];
  long[] timesUs = new long[cuePointsSize];
  for (int i = 0; i < cuePointsSize; i++) {
    timesUs[i] = cueTimesUs.get(i);
    offsets[i] = segmentContentPosition + cueClusterPositions.get(i);
  }
  for (int i = 0; i < cuePointsSize - 1; i++) {
    sizes[i] = (int) (offsets[i + 1] - offsets[i]);
    durationsUs[i] = timesUs[i + 1] - timesUs[i];
  }
  sizes[cuePointsSize - 1] =
      (int) (segmentContentPosition + segmentContentSize - offsets[cuePointsSize - 1]);
  durationsUs[cuePointsSize - 1] = durationUs - timesUs[cuePointsSize - 1];
  cueTimesUs = null;
  cueClusterPositions = null;
  return new ChunkIndex(sizes, offsets, durationsUs, timesUs);
}
 
Example #25
Source File: MatroskaExtractor.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Builds a {@link SeekMap} from the recently gathered Cues information.
 *
 * @return The built {@link SeekMap}. The returned {@link SeekMap} may be unseekable if cues
 *     information was missing or incomplete.
 */
private SeekMap buildSeekMap() {
  if (segmentContentPosition == C.POSITION_UNSET || durationUs == C.TIME_UNSET
      || cueTimesUs == null || cueTimesUs.size() == 0
      || cueClusterPositions == null || cueClusterPositions.size() != cueTimesUs.size()) {
    // Cues information is missing or incomplete.
    cueTimesUs = null;
    cueClusterPositions = null;
    return new SeekMap.Unseekable(durationUs);
  }
  int cuePointsSize = cueTimesUs.size();
  int[] sizes = new int[cuePointsSize];
  long[] offsets = new long[cuePointsSize];
  long[] durationsUs = new long[cuePointsSize];
  long[] timesUs = new long[cuePointsSize];
  for (int i = 0; i < cuePointsSize; i++) {
    timesUs[i] = cueTimesUs.get(i);
    offsets[i] = segmentContentPosition + cueClusterPositions.get(i);
  }
  for (int i = 0; i < cuePointsSize - 1; i++) {
    sizes[i] = (int) (offsets[i + 1] - offsets[i]);
    durationsUs[i] = timesUs[i + 1] - timesUs[i];
  }
  sizes[cuePointsSize - 1] =
      (int) (segmentContentPosition + segmentContentSize - offsets[cuePointsSize - 1]);
  durationsUs[cuePointsSize - 1] = durationUs - timesUs[cuePointsSize - 1];
  cueTimesUs = null;
  cueClusterPositions = null;
  return new ChunkIndex(sizes, offsets, durationsUs, timesUs);
}
 
Example #26
Source File: MatroskaExtractor.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Builds a {@link SeekMap} from the recently gathered Cues information.
 *
 * @return The built {@link SeekMap}. The returned {@link SeekMap} may be unseekable if cues
 *     information was missing or incomplete.
 */
private SeekMap buildSeekMap() {
  if (segmentContentPosition == C.POSITION_UNSET || durationUs == C.TIME_UNSET
      || cueTimesUs == null || cueTimesUs.size() == 0
      || cueClusterPositions == null || cueClusterPositions.size() != cueTimesUs.size()) {
    // Cues information is missing or incomplete.
    cueTimesUs = null;
    cueClusterPositions = null;
    return new SeekMap.Unseekable(durationUs);
  }
  int cuePointsSize = cueTimesUs.size();
  int[] sizes = new int[cuePointsSize];
  long[] offsets = new long[cuePointsSize];
  long[] durationsUs = new long[cuePointsSize];
  long[] timesUs = new long[cuePointsSize];
  for (int i = 0; i < cuePointsSize; i++) {
    timesUs[i] = cueTimesUs.get(i);
    offsets[i] = segmentContentPosition + cueClusterPositions.get(i);
  }
  for (int i = 0; i < cuePointsSize - 1; i++) {
    sizes[i] = (int) (offsets[i + 1] - offsets[i]);
    durationsUs[i] = timesUs[i + 1] - timesUs[i];
  }
  sizes[cuePointsSize - 1] =
      (int) (segmentContentPosition + segmentContentSize - offsets[cuePointsSize - 1]);
  durationsUs[cuePointsSize - 1] = durationUs - timesUs[cuePointsSize - 1];
  cueTimesUs = null;
  cueClusterPositions = null;
  return new ChunkIndex(sizes, offsets, durationsUs, timesUs);
}
 
Example #27
Source File: FlacDecoderJni.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps a seek position in microseconds to the corresponding {@link SeekMap.SeekPoints} in the
 * stream.
 *
 * @param timeUs A seek position in microseconds.
 * @return The corresponding {@link SeekMap.SeekPoints} obtained from the seek table, or {@code
 *     null} if the stream doesn't have a seek table.
 */
@Nullable
public SeekMap.SeekPoints getSeekPoints(long timeUs) {
  long[] seekPoints = new long[4];
  if (!flacGetSeekPoints(nativeDecoderContext, timeUs, seekPoints)) {
    return null;
  }
  SeekPoint firstSeekPoint = new SeekPoint(seekPoints[0], seekPoints[1]);
  SeekPoint secondSeekPoint =
      seekPoints[2] == seekPoints[0]
          ? firstSeekPoint
          : new SeekPoint(seekPoints[2], seekPoints[3]);
  return new SeekMap.SeekPoints(firstSeekPoint, secondSeekPoint);
}
 
Example #28
Source File: ProgressiveMediaPeriod.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private void startLoading() {
  ExtractingLoadable loadable =
      new ExtractingLoadable(
          uri, dataSource, extractorHolder, /* extractorOutput= */ this, loadCondition);
  if (prepared) {
    SeekMap seekMap = getPreparedState().seekMap;
    Assertions.checkState(isPendingReset());
    if (durationUs != C.TIME_UNSET && pendingResetPositionUs > durationUs) {
      loadingFinished = true;
      pendingResetPositionUs = C.TIME_UNSET;
      return;
    }
    loadable.setLoadPosition(
        seekMap.getSeekPoints(pendingResetPositionUs).first.position, pendingResetPositionUs);
    pendingResetPositionUs = C.TIME_UNSET;
  }
  extractedSamplesCountAtStartOfLoad = getExtractedSamplesCount();
  long elapsedRealtimeMs =
      loader.startLoading(
          loadable, this, loadErrorHandlingPolicy.getMinimumLoadableRetryCount(dataType));
  eventDispatcher.loadStarted(
      loadable.dataSpec,
      C.DATA_TYPE_MEDIA,
      C.TRACK_TYPE_UNKNOWN,
      /* trackFormat= */ null,
      C.SELECTION_REASON_UNKNOWN,
      /* trackSelectionData= */ null,
      /* mediaStartTimeUs= */ loadable.seekTimeUs,
      durationUs,
      elapsedRealtimeMs);
}
 
Example #29
Source File: RawCcExtractor.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void init(ExtractorOutput output) {
  output.seekMap(new SeekMap.Unseekable(C.TIME_UNSET));
  trackOutput = output.track(0, C.TRACK_TYPE_TEXT);
  output.endTracks();
  trackOutput.format(format);
}
 
Example #30
Source File: FlacExtractor.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void outputSeekMap(ExtractorInput input, FlacStreamInfo streamInfo) {
  boolean hasSeekTable = decoderJni.getSeekPosition(0) != -1;
  SeekMap seekMap =
      hasSeekTable
          ? new FlacSeekMap(streamInfo.durationUs(), decoderJni)
          : getSeekMapForNonSeekTableFlac(input, streamInfo);
  extractorOutput.seekMap(seekMap);
}