Пример #1
0
 @Override
 public void setRequestProperty(String name, String value) {
   Assertions.checkNotNull(name);
   Assertions.checkNotNull(value);
   synchronized (requestProperties) {
     requestProperties.put(name, value);
   }
 }
Пример #2
0
 @Override
 public void clearRequestProperty(String name) {
   Assertions.checkNotNull(name);
   synchronized (requestProperties) {
     requestProperties.remove(name);
   }
 }
Пример #3
0
 /**
  * Returns a position converging to the {@code targetGranule} to which the {@link ExtractorInput}
  * has to seek and then be passed for another call until -1 is return. If -1 is returned the input
  * is at a position which is before the start of the page before the target page and at which it
  * is sensible to just skip pages to the target granule and pre-roll instead of doing another seek
  * request.
  *
  * @param targetGranule the target granule position to seek to.
  * @param input the {@link ExtractorInput} to read from.
  * @return the position to seek the {@link ExtractorInput} to for a next call or -1 if it's close
  *     enough to skip to the target page.
  * @throws IOException thrown if reading from the input fails.
  * @throws InterruptedException thrown if interrupted while reading from the input.
  */
 public long getNextSeekPosition(long targetGranule, ExtractorInput input)
     throws IOException, InterruptedException {
   Assertions.checkState(audioDataLength != C.LENGTH_UNBOUNDED && totalSamples != 0);
   OggUtil.populatePageHeader(input, pageHeader, headerArray, false);
   long granuleDistance = targetGranule - pageHeader.granulePosition;
   if (granuleDistance <= 0 || granuleDistance > MATCH_RANGE) {
     // estimated position too high or too low
     long offset = (pageHeader.bodySize + pageHeader.headerSize) * (granuleDistance <= 0 ? 2 : 1);
     return input.getPosition() - offset + (granuleDistance * audioDataLength / totalSamples);
   }
   // position accepted (below target granule and within MATCH_RANGE)
   input.resetPeekPosition();
   return -1;
 }
Пример #4
0
 /**
  * @param userAgent The User-Agent string that should be used.
  * @param contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the
  *     predicate then a {@link HttpDataSource.InvalidContentTypeException} is thrown from {@link
  *     #open(DataSpec)}.
  * @param listener An optional listener.
  * @param connectTimeoutMillis The connection timeout, in milliseconds. A timeout of zero is
  *     interpreted as an infinite timeout. Pass {@link #DEFAULT_CONNECT_TIMEOUT_MILLIS} to use the
  *     default value.
  * @param readTimeoutMillis The read timeout, in milliseconds. A timeout of zero is interpreted as
  *     an infinite timeout. Pass {@link #DEFAULT_READ_TIMEOUT_MILLIS} to use the default value.
  * @param allowCrossProtocolRedirects Whether cross-protocol redirects (i.e. redirects from HTTP
  *     to HTTPS and vice versa) are enabled.
  */
 public DefaultHttpDataSource(
     String userAgent,
     Predicate<String> contentTypePredicate,
     TransferListener listener,
     int connectTimeoutMillis,
     int readTimeoutMillis,
     boolean allowCrossProtocolRedirects) {
   this.userAgent = Assertions.checkNotEmpty(userAgent);
   this.contentTypePredicate = contentTypePredicate;
   this.listener = listener;
   this.requestProperties = new HashMap<>();
   this.connectTimeoutMillis = connectTimeoutMillis;
   this.readTimeoutMillis = readTimeoutMillis;
   this.allowCrossProtocolRedirects = allowCrossProtocolRedirects;
 }
Пример #5
0
  @Override
  public int readData(
      int track, long positionUs, MediaFormatHolder formatHolder, SampleHolder sampleHolder) {
    if (state == STATE_END_OF_STREAM) {
      return END_OF_STREAM;
    } else if (state == STATE_SEND_FORMAT) {
      formatHolder.format = format;
      state = STATE_SEND_SAMPLE;
      return FORMAT_READ;
    }

    Assertions.checkState(state == STATE_SEND_SAMPLE);
    if (!loadingFinished) {
      return NOTHING_READ;
    } else {
      sampleHolder.timeUs = 0;
      sampleHolder.size = sampleSize;
      sampleHolder.flags = C.SAMPLE_FLAG_SYNC;
      sampleHolder.ensureSpaceForWrite(sampleHolder.size);
      sampleHolder.data.put(sampleData, 0, sampleSize);
      state = STATE_END_OF_STREAM;
      return SAMPLE_READ;
    }
  }
Пример #6
0
 /**
  * Setup the seeker with the data it needs to to an educated guess of seeking positions.
  *
  * @param audioDataLength the length of the audio data (total bytes - header bytes).
  * @param totalSamples the total number of samples of audio data.
  */
 public void setup(long audioDataLength, long totalSamples) {
   Assertions.checkArgument(audioDataLength > 0 && totalSamples > 0);
   this.audioDataLength = audioDataLength;
   this.totalSamples = totalSamples;
 }
 private static int getManifestTrackKey(int elementIndex, int trackIndex) {
   Assertions.checkState(elementIndex <= 65536 && trackIndex <= 65536);
   return (elementIndex << 16) | trackIndex;
 }