当前位置: 首页>>代码示例>>Java>>正文


Java ExtractorInput.skipFully方法代码示例

本文整理汇总了Java中com.google.android.exoplayer2.extractor.ExtractorInput.skipFully方法的典型用法代码示例。如果您正苦于以下问题:Java ExtractorInput.skipFully方法的具体用法?Java ExtractorInput.skipFully怎么用?Java ExtractorInput.skipFully使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.android.exoplayer2.extractor.ExtractorInput的用法示例。


在下文中一共展示了ExtractorInput.skipFully方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sniff

import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
@Override
public boolean sniff(ExtractorInput input) throws IOException, InterruptedException {
  byte[] buffer = tsPacketBuffer.data;
  input.peekFully(buffer, 0, BUFFER_SIZE);
  for (int j = 0; j < TS_PACKET_SIZE; j++) {
    for (int i = 0; true; i++) {
      if (i == BUFFER_PACKET_COUNT) {
        input.skipFully(j);
        return true;
      }
      if (buffer[j + i * TS_PACKET_SIZE] != TS_SYNC_BYTE) {
        break;
      }
    }
  }
  return false;
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:18,代码来源:TsExtractor.java

示例2: read

import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
/**
 * @see Extractor#read(ExtractorInput, PositionHolder)
 */
final int read(ExtractorInput input, PositionHolder seekPosition)
    throws IOException, InterruptedException {
  switch (state) {
    case STATE_READ_HEADERS:
      return readHeaders(input);
    case STATE_SKIP_HEADERS:
      input.skipFully((int) payloadStartPosition);
      state = STATE_READ_PAYLOAD;
      return Extractor.RESULT_CONTINUE;
    case STATE_READ_PAYLOAD:
      return readPayload(input, seekPosition);
    default:
      // Never happens.
      throw new IllegalStateException();
  }
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:20,代码来源:StreamReader.java

示例3: readAtomPayload

import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
/**
 * Processes the atom payload. If {@link #atomData} is null and the size is at or above the
 * threshold {@link #RELOAD_MINIMUM_SEEK_DISTANCE}, {@code true} is returned and the caller should
 * restart loading at the position in {@code positionHolder}. Otherwise, the atom is read/skipped.
 */
private boolean readAtomPayload(ExtractorInput input, PositionHolder positionHolder)
    throws IOException, InterruptedException {
  long atomPayloadSize = atomSize - atomHeaderBytesRead;
  long atomEndPosition = input.getPosition() + atomPayloadSize;
  boolean seekRequired = false;
  if (atomData != null) {
    input.readFully(atomData.data, atomHeaderBytesRead, (int) atomPayloadSize);
    if (atomType == Atom.TYPE_ftyp) {
      isQuickTime = processFtypAtom(atomData);
    } else if (!containerAtoms.isEmpty()) {
      containerAtoms.peek().add(new Atom.LeafAtom(atomType, atomData));
    }
  } else {
    // We don't need the data. Skip or seek, depending on how large the atom is.
    if (atomPayloadSize < RELOAD_MINIMUM_SEEK_DISTANCE) {
      input.skipFully((int) atomPayloadSize);
    } else {
      positionHolder.position = input.getPosition() + atomPayloadSize;
      seekRequired = true;
    }
  }
  processAtomEnded(atomEndPosition);
  return seekRequired && parserState != STATE_READING_SAMPLE;
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:30,代码来源:Mp4Extractor.java

示例4: readEncryptionData

import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
private void readEncryptionData(ExtractorInput input) throws IOException, InterruptedException {
  TrackBundle nextTrackBundle = null;
  long nextDataOffset = Long.MAX_VALUE;
  int trackBundlesSize = trackBundles.size();
  for (int i = 0; i < trackBundlesSize; i++) {
    TrackFragment trackFragment = trackBundles.valueAt(i).fragment;
    if (trackFragment.sampleEncryptionDataNeedsFill
        && trackFragment.auxiliaryDataPosition < nextDataOffset) {
      nextDataOffset = trackFragment.auxiliaryDataPosition;
      nextTrackBundle = trackBundles.valueAt(i);
    }
  }
  if (nextTrackBundle == null) {
    parserState = STATE_READING_SAMPLE_START;
    return;
  }
  int bytesToSkip = (int) (nextDataOffset - input.getPosition());
  if (bytesToSkip < 0) {
    throw new ParserException("Offset to encryption data was negative.");
  }
  input.skipFully(bytesToSkip);
  nextTrackBundle.fragment.fillEncryptionData(input);
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:24,代码来源:FragmentedMp4Extractor.java

示例5: maybeResyncToNextLevel1Element

import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
/**
 * Does a byte by byte search to try and find the next level 1 element. This method is called if
 * some invalid data is encountered in the parser.
 *
 * @param input The {@link ExtractorInput} from which data has to be read.
 * @return id of the next level 1 element that has been found.
 * @throws EOFException If the end of input was encountered when searching for the next level 1
 *     element.
 * @throws IOException If an error occurs reading from the input.
 * @throws InterruptedException If the thread is interrupted.
 */
private long maybeResyncToNextLevel1Element(ExtractorInput input) throws IOException,
    InterruptedException {
  input.resetPeekPosition();
  while (true) {
    input.peekFully(scratch, 0, MAX_ID_BYTES);
    int varintLength = VarintReader.parseUnsignedVarintLength(scratch[0]);
    if (varintLength != C.LENGTH_UNSET && varintLength <= MAX_ID_BYTES) {
      int potentialId = (int) VarintReader.assembleVarint(scratch, varintLength, false);
      if (output.isLevel1Element(potentialId)) {
        input.skipFully(varintLength);
        return potentialId;
      }
    }
    input.skipFully(1);
  }
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:28,代码来源:DefaultEbmlReader.java

示例6: readTagData

import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
/**
 * 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) {
    audioReader.consume(prepareTagData(input), tagTimestampUs);
  } else if (tagType == TAG_TYPE_VIDEO && videoReader != null) {
    videoReader.consume(prepareTagData(input), tagTimestampUs);
  } else if (tagType == TAG_TYPE_SCRIPT_DATA && metadataReader != null) {
    metadataReader.consume(prepareTagData(input), tagTimestampUs);
  } else {
    input.skipFully(tagDataSize);
    wasConsumed = false;
  }
  bytesToNextTagHeader = 4; // There's a 4 byte previous tag size before the next header.
  parserState = STATE_SKIPPING_TO_TAG_HEADER;
  return wasConsumed;
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:25,代码来源:FlvExtractor.java

示例7: read

import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
/**
 * @see Extractor#read(ExtractorInput, PositionHolder)
 */
final int read(ExtractorInput input, PositionHolder seekPosition)
    throws IOException, InterruptedException {
  switch (state) {
    case STATE_READ_HEADERS:
      return readHeaders(input);

    case STATE_SKIP_HEADERS:
      input.skipFully((int) payloadStartPosition);
      state = STATE_READ_PAYLOAD;
      return Extractor.RESULT_CONTINUE;

    case STATE_READ_PAYLOAD:
      return readPayload(input, seekPosition);

    default:
      // Never happens.
      throw new IllegalStateException();
  }
}
 
开发者ID:jcodeing,项目名称:K-Sonic,代码行数:23,代码来源:StreamReader.java

示例8: skipToData

import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
/**
 * Skips to the data in the given WAV input stream and returns its data size. After calling, the
 * input stream's position will point to the start of sample data in the WAV.
 * <p>
 * If an exception is thrown, the input position will be left pointing to a chunk header.
 *
 * @param input Input stream to skip to the data chunk in. Its peek position must be pointing to
 *     a valid chunk header.
 * @param wavHeader WAV header to populate with data bounds.
 * @throws ParserException If an error occurs parsing chunks.
 * @throws IOException If reading from the input fails.
 * @throws InterruptedException If interrupted while reading from input.
 */
public static void skipToData(ExtractorInput input, WavHeader wavHeader)
    throws IOException, InterruptedException {
  Assertions.checkNotNull(input);
  Assertions.checkNotNull(wavHeader);

  // Make sure the peek position is set to the read position before we peek the first header.
  input.resetPeekPosition();

  ParsableByteArray scratch = new ParsableByteArray(ChunkHeader.SIZE_IN_BYTES);
  // Skip all chunks until we hit the data header.
  ChunkHeader chunkHeader = ChunkHeader.peek(input, scratch);
  while (chunkHeader.id != Util.getIntegerCodeForString("data")) {
    Log.w(TAG, "Ignoring unknown WAV chunk: " + chunkHeader.id);
    long bytesToSkip = ChunkHeader.SIZE_IN_BYTES + chunkHeader.size;
    // Override size of RIFF chunk, since it describes its size as the entire file.
    if (chunkHeader.id == Util.getIntegerCodeForString("RIFF")) {
      bytesToSkip = ChunkHeader.SIZE_IN_BYTES + 4;
    }
    if (bytesToSkip > Integer.MAX_VALUE) {
      throw new ParserException("Chunk is too large (~2GB+) to skip; id: " + chunkHeader.id);
    }
    input.skipFully((int) bytesToSkip);
    chunkHeader = ChunkHeader.peek(input, scratch);
  }
  // Skip past the "data" header.
  input.skipFully(ChunkHeader.SIZE_IN_BYTES);

  wavHeader.setDataBounds(input.getPosition(), chunkHeader.size);
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:43,代码来源:WavHeaderReader.java

示例9: skipToNextPage

import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
/**
 * Skips to the next page. Searches for the next page header.
 *
 * @param input The {@code ExtractorInput} to skip to the next page.
 * @param until Searches until this position.
 * @return true if the next page is found.
 * @throws IOException thrown if peeking/reading from the input fails.
 * @throws InterruptedException thrown if interrupted while peeking/reading from the input.
 */
//@VisibleForTesting
boolean skipToNextPage(ExtractorInput input, long until)
    throws IOException, InterruptedException {
  until = Math.min(until + 3, endPosition);
  byte[] buffer = new byte[2048];
  int peekLength = buffer.length;
  while (true) {
    if (input.getPosition() + peekLength > until) {
      // Make sure to not peek beyond the end of the input.
      peekLength = (int) (until - input.getPosition());
      if (peekLength < 4) {
        // Not found until end.
        return false;
      }
    }
    input.peekFully(buffer, 0, peekLength, false);
    for (int i = 0; i < peekLength - 3; i++) {
      if (buffer[i] == 'O' && buffer[i + 1] == 'g' && buffer[i + 2] == 'g'
          && buffer[i + 3] == 'S') {
        // Match! Skip to the start of the pattern.
        input.skipFully(i);
        return true;
      }
    }
    // Overlap by not skipping the entire peekLength.
    input.skipFully(peekLength - 3);
  }
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:38,代码来源:DefaultOggSeeker.java

示例10: readGranuleOfLastPage

import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
/**
 * Skips to the last Ogg page in the stream and reads the header's granule field which is the
 * total number of samples per channel.
 *
 * @param input The {@link ExtractorInput} to read from.
 * @return the total number of samples of this input.
 * @throws IOException thrown if reading from the input fails.
 * @throws InterruptedException thrown if interrupted while reading from the input.
 */
//@VisibleForTesting
long readGranuleOfLastPage(ExtractorInput input)
    throws IOException, InterruptedException {
  skipToNextPage(input);
  pageHeader.reset();
  while ((pageHeader.type & 0x04) != 0x04 && input.getPosition() < endPosition) {
    pageHeader.populate(input, false);
    input.skipFully(pageHeader.headerSize + pageHeader.bodySize);
  }
  return pageHeader.granulePosition;
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:21,代码来源:DefaultOggSeeker.java

示例11: skipToPageOfGranule

import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
/**
 * Skips to the position of the start of the page containing the {@code targetGranule} and
 * returns the granule of the page previous to the target page.
 *
 * @param input the {@link ExtractorInput} to read from.
 * @param targetGranule the target granule.
 * @param currentGranule the current granule or -1 if it's unknown.
 * @return the granule of the prior page or the {@code currentGranule} if there isn't a prior
 *     page.
 * @throws ParserException thrown if populating the page header fails.
 * @throws IOException thrown if reading from the input fails.
 * @throws InterruptedException thrown if interrupted while reading from the input.
 */
//@VisibleForTesting
long skipToPageOfGranule(ExtractorInput input, long targetGranule, long currentGranule)
    throws IOException, InterruptedException {
  pageHeader.populate(input, false);
  while (pageHeader.granulePosition < targetGranule) {
    input.skipFully(pageHeader.headerSize + pageHeader.bodySize);
    // Store in a member field to be able to resume after IOExceptions.
    currentGranule = pageHeader.granulePosition;
    // Peek next header.
    pageHeader.populate(input, false);
  }
  input.resetPeekPosition();
  return currentGranule;
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:28,代码来源:DefaultOggSeeker.java

示例12: readAtomPayload

import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
private void readAtomPayload(ExtractorInput input) throws IOException, InterruptedException {
  int atomPayloadSize = (int) atomSize - atomHeaderBytesRead;
  if (atomData != null) {
    input.readFully(atomData.data, Atom.HEADER_SIZE, atomPayloadSize);
    onLeafAtomRead(new LeafAtom(atomType, atomData), input.getPosition());
  } else {
    input.skipFully(atomPayloadSize);
  }
  processAtomEnded(input.getPosition());
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:11,代码来源:FragmentedMp4Extractor.java

示例13: readSample

import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
private int readSample(ExtractorInput extractorInput) throws IOException, InterruptedException {
  if (sampleBytesRemaining == 0) {
    extractorInput.resetPeekPosition();
    if (!extractorInput.peekFully(scratch.data, 0, 4, true)) {
      return RESULT_END_OF_INPUT;
    }
    scratch.setPosition(0);
    int sampleHeaderData = scratch.readInt();
    if ((sampleHeaderData & HEADER_MASK) != (synchronizedHeaderData & HEADER_MASK)
        || MpegAudioHeader.getFrameSize(sampleHeaderData) == C.LENGTH_UNSET) {
      // We have lost synchronization, so attempt to resynchronize starting at the next byte.
      extractorInput.skipFully(1);
      synchronizedHeaderData = 0;
      return RESULT_CONTINUE;
    }
    MpegAudioHeader.populateHeader(sampleHeaderData, synchronizedHeader);
    if (basisTimeUs == C.TIME_UNSET) {
      basisTimeUs = seeker.getTimeUs(extractorInput.getPosition());
      if (forcedFirstSampleTimestampUs != C.TIME_UNSET) {
        long embeddedFirstSampleTimestampUs = seeker.getTimeUs(0);
        basisTimeUs += forcedFirstSampleTimestampUs - embeddedFirstSampleTimestampUs;
      }
    }
    sampleBytesRemaining = synchronizedHeader.frameSize;
  }
  int bytesAppended = trackOutput.sampleData(extractorInput, sampleBytesRemaining, true);
  if (bytesAppended == C.RESULT_END_OF_INPUT) {
    return RESULT_END_OF_INPUT;
  }
  sampleBytesRemaining -= bytesAppended;
  if (sampleBytesRemaining > 0) {
    return RESULT_CONTINUE;
  }
  long timeUs = basisTimeUs + (samplesRead * C.MICROS_PER_SECOND / synchronizedHeader.sampleRate);
  trackOutput.sampleMetadata(timeUs, C.BUFFER_FLAG_KEY_FRAME, synchronizedHeader.frameSize, 0,
      null);
  samplesRead += synchronizedHeader.samplesPerFrame;
  sampleBytesRemaining = 0;
  return RESULT_CONTINUE;
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:41,代码来源:Mp3Extractor.java

示例14: loadMedia

import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
private void loadMedia() throws IOException, InterruptedException {
  // If we previously fed part of this chunk to the extractor, we need to skip it this time. For
  // encrypted content we need to skip the data by reading it through the source, so as to ensure
  // correct decryption of the remainder of the chunk. For clear content, we can request the
  // remainder of the chunk directly.
  DataSpec loadDataSpec;
  boolean skipLoadedBytes;
  if (isEncrypted) {
    loadDataSpec = dataSpec;
    skipLoadedBytes = bytesLoaded != 0;
  } else {
    loadDataSpec = Util.getRemainderDataSpec(dataSpec, bytesLoaded);
    skipLoadedBytes = false;
  }
  if (!isMasterTimestampSource) {
    timestampAdjuster.waitUntilInitialized();
  } else if (timestampAdjuster.getFirstSampleTimestampUs() == TimestampAdjuster.DO_NOT_OFFSET) {
    // We're the master and we haven't set the desired first sample timestamp yet.
    timestampAdjuster.setFirstSampleTimestampUs(startTimeUs);
  }
  try {
    ExtractorInput input = new DefaultExtractorInput(dataSource,
        loadDataSpec.absoluteStreamPosition, dataSource.open(loadDataSpec));
    if (extractor == null) {
      // Media segment format is packed audio.
      long id3Timestamp = peekId3PrivTimestamp(input);
      extractor = buildPackedAudioExtractor(id3Timestamp != C.TIME_UNSET
          ? timestampAdjuster.adjustTsTimestamp(id3Timestamp) : startTimeUs);
    }
    if (skipLoadedBytes) {
      input.skipFully(bytesLoaded);
    }
    try {
      int result = Extractor.RESULT_CONTINUE;
      while (result == Extractor.RESULT_CONTINUE && !loadCanceled) {
        result = extractor.read(input, null);
      }
    } finally {
      bytesLoaded = (int) (input.getPosition() - dataSpec.absoluteStreamPosition);
    }
  } finally {
    Util.closeQuietly(dataSource);
  }
  loadCompleted = true;
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:46,代码来源:HlsMediaChunk.java

示例15: getNextSeekPosition

import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
/**
 * Returns a position converging to the {@code targetGranule} to which the {@link ExtractorInput}
 * has to seek and then be passed for another call until a negative number is returned. If a
 * negative number is returned the input is at a position which is 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
 *     -(currentGranule + 2) 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.
 */
//@VisibleForTesting
public long getNextSeekPosition(long targetGranule, ExtractorInput input)
    throws IOException, InterruptedException {
  if (start == end) {
    return -(startGranule + 2);
  }

  long initialPosition = input.getPosition();
  if (!skipToNextPage(input, end)) {
    if (start == initialPosition) {
      throw new IOException("No ogg page can be found.");
    }
    return start;
  }

  pageHeader.populate(input, false);
  input.resetPeekPosition();

  long granuleDistance = targetGranule - pageHeader.granulePosition;
  int pageSize = pageHeader.headerSize + pageHeader.bodySize;
  if (granuleDistance < 0 || granuleDistance > MATCH_RANGE) {
    if (granuleDistance < 0) {
      end = initialPosition;
      endGranule = pageHeader.granulePosition;
    } else {
      start = input.getPosition() + pageSize;
      startGranule = pageHeader.granulePosition;
      if (end - start + pageSize < MATCH_BYTE_RANGE) {
        input.skipFully(pageSize);
        return -(startGranule + 2);
      }
    }

    if (end - start < MATCH_BYTE_RANGE) {
      end = start;
      return start;
    }

    long offset = pageSize * (granuleDistance <= 0 ? 2 : 1);
    long nextPosition = input.getPosition() - offset
        + (granuleDistance * (end - start) / (endGranule - startGranule));

    nextPosition = Math.max(nextPosition, start);
    nextPosition = Math.min(nextPosition, end - 1);
    return nextPosition;
  }

  // position accepted (before target granule and within MATCH_RANGE)
  input.skipFully(pageSize);
  return -(pageHeader.granulePosition + 2);
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:66,代码来源:DefaultOggSeeker.java


注:本文中的com.google.android.exoplayer2.extractor.ExtractorInput.skipFully方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。