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


Java ExtractorInput.getLength方法代码示例

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


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

示例1: read

import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
@Override
public int read(ExtractorInput input, PositionHolder seekPosition)
    throws IOException, InterruptedException {
  int currentFileSize = (int) input.getLength();

  // Increase the size of sampleData if necessary.
  if (sampleSize == sampleData.length) {
    sampleData = Arrays.copyOf(sampleData,
        (currentFileSize != C.LENGTH_UNSET ? currentFileSize : sampleData.length) * 3 / 2);
  }

  // Consume to the input.
  int bytesRead = input.read(sampleData, sampleSize, sampleData.length - sampleSize);
  if (bytesRead != C.RESULT_END_OF_INPUT) {
    sampleSize += bytesRead;
    if (currentFileSize == C.LENGTH_UNSET || sampleSize != currentFileSize) {
      return Extractor.RESULT_CONTINUE;
    }
  }

  // We've reached the end of the input, which corresponds to the end of the current file.
  processSample();
  return Extractor.RESULT_END_OF_INPUT;
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:25,代码来源:WebvttExtractor.java

示例2: readHeaders

import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
private int readHeaders(ExtractorInput input) throws IOException, InterruptedException {
  boolean readingHeaders = true;
  while (readingHeaders) {
    if (!oggPacket.populate(input)) {
      state = STATE_END_OF_INPUT;
      return Extractor.RESULT_END_OF_INPUT;
    }
    lengthOfReadPacket = input.getPosition() - payloadStartPosition;

    readingHeaders = readHeaders(oggPacket.getPayload(), payloadStartPosition, setupData);
    if (readingHeaders) {
      payloadStartPosition = input.getPosition();
    }
  }

  sampleRate = setupData.format.sampleRate;
  if (!formatSet) {
    trackOutput.format(setupData.format);
    formatSet = true;
  }

  if (setupData.oggSeeker != null) {
    oggSeeker = setupData.oggSeeker;
  } else if (input.getLength() == C.LENGTH_UNSET) {
    oggSeeker = new UnseekableOggSeeker();
  } else {
    OggPageHeader firstPayloadPageHeader = oggPacket.getPageHeader();
    oggSeeker = new DefaultOggSeeker(payloadStartPosition, input.getLength(), this,
        firstPayloadPageHeader.headerSize + firstPayloadPageHeader.bodySize,
        firstPayloadPageHeader.granulePosition);
  }

  setupData = null;
  state = STATE_READ_PAYLOAD;
  // First payload packet. Trim the payload array of the ogg packet after headers have been read.
  oggPacket.trimPayload();
  return Extractor.RESULT_CONTINUE;
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:39,代码来源:StreamReader.java

示例3: readHeaders

import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
private int readHeaders(ExtractorInput input) throws IOException, InterruptedException {
  boolean readingHeaders = true;
  while (readingHeaders) {
    if (!oggPacket.populate(input)) {
      state = STATE_END_OF_INPUT;
      return Extractor.RESULT_END_OF_INPUT;
    }
    lengthOfReadPacket = input.getPosition() - payloadStartPosition;

    readingHeaders = readHeaders(oggPacket.getPayload(), payloadStartPosition, setupData);
    if (readingHeaders) {
      payloadStartPosition = input.getPosition();
    }
  }

  sampleRate = setupData.format.sampleRate;
  if (!formatSet) {
    trackOutput.format(setupData.format);
    formatSet = true;
  }

  if (setupData.oggSeeker != null) {
    oggSeeker = setupData.oggSeeker;
  } else if (input.getLength() == C.LENGTH_UNSET) {
    oggSeeker = new UnseekableOggSeeker();
  } else {
    OggPageHeader firstPayloadPageHeader = oggPacket.getPageHeader();
    oggSeeker = new DefaultOggSeeker(payloadStartPosition, input.getLength(), this,
        firstPayloadPageHeader.headerSize + firstPayloadPageHeader.bodySize,
        firstPayloadPageHeader.granulePosition);
  }

  setupData = null;
  state = STATE_READ_PAYLOAD;
  return Extractor.RESULT_CONTINUE;
}
 
开发者ID:jcodeing,项目名称:K-Sonic,代码行数:37,代码来源:StreamReader.java

示例4: readHeaders

import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
private int readHeaders(ExtractorInput input) throws IOException, InterruptedException {
  boolean readingHeaders = true;
  while (readingHeaders) {
    if (!oggPacket.populate(input)) {
      state = STATE_END_OF_INPUT;
      return Extractor.RESULT_END_OF_INPUT;
    }
    lengthOfReadPacket = input.getPosition() - payloadStartPosition;

    readingHeaders = readHeaders(oggPacket.getPayload(), payloadStartPosition, setupData);
    if (readingHeaders) {
      payloadStartPosition = input.getPosition();
    }
  }

  sampleRate = setupData.format.sampleRate;
  if (!formatSet) {
    trackOutput.format(setupData.format);
    formatSet = true;
  }

  if (setupData.oggSeeker != null) {
    oggSeeker = setupData.oggSeeker;
  } else if (input.getLength() == C.LENGTH_UNSET) {
    oggSeeker = new UnseekableOggSeeker();
  } else {
    oggSeeker = new DefaultOggSeeker(payloadStartPosition, input.getLength(), this);
  }

  setupData = null;
  state = STATE_READ_PAYLOAD;
  return Extractor.RESULT_CONTINUE;
}
 
开发者ID:zhanglibin123488,项目名称:videoPickPlayer,代码行数:34,代码来源:StreamReader.java

示例5: skipToNextPage

import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
private static void skipToNextPage(ExtractorInput extractorInput)
    throws IOException, InterruptedException {
  DefaultOggSeeker oggSeeker = new DefaultOggSeeker(0, extractorInput.getLength(),
      new FlacReader());
  while (true) {
    try {
      oggSeeker.skipToNextPage(extractorInput);
      break;
    } catch (FakeExtractorInput.SimulatedIOException e) { /* ignored */ }
  }
}
 
开发者ID:zhanglibin123488,项目名称:videoPickPlayer,代码行数:12,代码来源:DefaultOggSeekerUtilMethodsTest.java

示例6: skipToPageOfGranule

import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
private void skipToPageOfGranule(ExtractorInput input, long granule,
    long elapsedSamplesExpected) throws IOException, InterruptedException {
  DefaultOggSeeker oggSeeker = new DefaultOggSeeker(0, input.getLength(), new FlacReader());
  while (true) {
    try {
      assertEquals(elapsedSamplesExpected, oggSeeker.skipToPageOfGranule(input, granule, -1));
      return;
    } catch (FakeExtractorInput.SimulatedIOException e) {
      input.resetPeekPosition();
    }
  }
}
 
开发者ID:zhanglibin123488,项目名称:videoPickPlayer,代码行数:13,代码来源:DefaultOggSeekerUtilMethodsTest.java

示例7: populate

import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
/**
 * Peeks an Ogg page header and updates this {@link OggPageHeader}.
 *
 * @param input the {@link ExtractorInput} to read from.
 * @param quiet if {@code true} no Exceptions are thrown but {@code false} is return if something
 *    goes wrong.
 * @return {@code true} if the read was successful. {@code false} if the end of the input was
 *    encountered having read no data.
 * @throws IOException thrown if reading data fails or the stream is invalid.
 * @throws InterruptedException thrown if thread is interrupted when reading/peeking.
 */
public boolean populate(ExtractorInput input, boolean quiet)
    throws IOException, InterruptedException {
  scratch.reset();
  reset();
  boolean hasEnoughBytes = input.getLength() == C.LENGTH_UNSET
      || input.getLength() - input.getPeekPosition() >= EMPTY_PAGE_HEADER_SIZE;
  if (!hasEnoughBytes || !input.peekFully(scratch.data, 0, EMPTY_PAGE_HEADER_SIZE, true)) {
    if (quiet) {
      return false;
    } else {
      throw new EOFException();
    }
  }
  if (scratch.readUnsignedInt() != TYPE_OGGS) {
    if (quiet) {
      return false;
    } else {
      throw new ParserException("expected OggS capture pattern at begin of page");
    }
  }

  revision = scratch.readUnsignedByte();
  if (revision != 0x00) {
    if (quiet) {
      return false;
    } else {
      throw new ParserException("unsupported bit stream revision");
    }
  }
  type = scratch.readUnsignedByte();

  granulePosition = scratch.readLittleEndianLong();
  streamSerialNumber = scratch.readLittleEndianUnsignedInt();
  pageSequenceNumber = scratch.readLittleEndianUnsignedInt();
  pageChecksum = scratch.readLittleEndianUnsignedInt();
  pageSegmentCount = scratch.readUnsignedByte();
  headerSize = EMPTY_PAGE_HEADER_SIZE + pageSegmentCount;

  // calculate total size of header including laces
  scratch.reset();
  input.peekFully(scratch.data, 0, pageSegmentCount);
  for (int i = 0; i < pageSegmentCount; i++) {
    laces[i] = scratch.readUnsignedByte();
    bodySize += laces[i];
  }

  return true;
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:60,代码来源:OggPageHeader.java

示例8: sniffInternal

import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
private static boolean sniffInternal(ExtractorInput input, boolean fragmented)
    throws IOException, InterruptedException {
  long inputLength = input.getLength();
  int bytesToSearch = (int) (inputLength == C.LENGTH_UNSET || inputLength > SEARCH_LENGTH
      ? SEARCH_LENGTH : inputLength);

  ParsableByteArray buffer = new ParsableByteArray(64);
  int bytesSearched = 0;
  boolean foundGoodFileType = false;
  boolean isFragmented = false;
  while (bytesSearched < bytesToSearch) {
    // Read an atom header.
    int headerSize = Atom.HEADER_SIZE;
    buffer.reset(headerSize);
    input.peekFully(buffer.data, 0, headerSize);
    long atomSize = buffer.readUnsignedInt();
    int atomType = buffer.readInt();
    if (atomSize == Atom.LONG_SIZE_PREFIX) {
      headerSize = Atom.LONG_HEADER_SIZE;
      input.peekFully(buffer.data, Atom.HEADER_SIZE, Atom.LONG_HEADER_SIZE - Atom.HEADER_SIZE);
      buffer.setLimit(Atom.LONG_HEADER_SIZE);
      atomSize = buffer.readUnsignedLongToLong();
    }

    if (atomSize < headerSize) {
      // The file is invalid because the atom size is too small for its header.
      return false;
    }
    bytesSearched += headerSize;

    if (atomType == Atom.TYPE_moov) {
      // Check for an mvex atom inside the moov atom to identify whether the file is fragmented.
      continue;
    }

    if (atomType == Atom.TYPE_moof || atomType == Atom.TYPE_mvex) {
      // The movie is fragmented. Stop searching as we must have read any ftyp atom already.
      isFragmented = true;
      break;
    }

    if (bytesSearched + atomSize - headerSize >= bytesToSearch) {
      // Stop searching as peeking this atom would exceed the search limit.
      break;
    }

    int atomDataSize = (int) (atomSize - headerSize);
    bytesSearched += atomDataSize;
    if (atomType == Atom.TYPE_ftyp) {
      // Parse the atom and check the file type/brand is compatible with the extractors.
      if (atomDataSize < 8) {
        return false;
      }
      buffer.reset(atomDataSize);
      input.peekFully(buffer.data, 0, atomDataSize);
      int brandsCount = atomDataSize / 4;
      for (int i = 0; i < brandsCount; i++) {
        if (i == 1) {
          // This index refers to the minorVersion, not a brand, so skip it.
          buffer.skipBytes(4);
        } else if (isCompatibleBrand(buffer.readInt())) {
          foundGoodFileType = true;
          break;
        }
      }
      if (!foundGoodFileType) {
        // The types were not compatible and there is only one ftyp atom, so reject the file.
        return false;
      }
    } else if (atomDataSize != 0) {
      // Skip the atom.
      input.advancePeekPosition(atomDataSize);
    }
  }
  return foundGoodFileType && fragmented == isFragmented;
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:77,代码来源:Sniffer.java

示例9: sniff

import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
/**
 * @see com.google.android.exoplayer2.extractor.Extractor#sniff(ExtractorInput)
 */
public boolean sniff(ExtractorInput input) throws IOException, InterruptedException {
  long inputLength = input.getLength();
  int bytesToSearch = (int) (inputLength == C.LENGTH_UNSET || inputLength > SEARCH_LENGTH
      ? SEARCH_LENGTH : inputLength);
  // Find four bytes equal to ID_EBML near the start of the input.
  input.peekFully(scratch.data, 0, 4);
  long tag = scratch.readUnsignedInt();
  peekLength = 4;
  while (tag != ID_EBML) {
    if (++peekLength == bytesToSearch) {
      return false;
    }
    input.peekFully(scratch.data, 0, 1);
    tag = (tag << 8) & 0xFFFFFF00;
    tag |= scratch.data[0] & 0xFF;
  }

  // Read the size of the EBML header and make sure it is within the stream.
  long headerSize = readUint(input);
  long headerStart = peekLength;
  if (headerSize == Long.MIN_VALUE
      || (inputLength != C.LENGTH_UNSET && headerStart + headerSize >= inputLength)) {
    return false;
  }

  // Read the payload elements in the EBML header.
  while (peekLength < headerStart + headerSize) {
    long id = readUint(input);
    if (id == Long.MIN_VALUE) {
      return false;
    }
    long size = readUint(input);
    if (size < 0 || size > Integer.MAX_VALUE) {
      return false;
    }
    if (size != 0) {
      input.advancePeekPosition((int) size);
      peekLength += size;
    }
  }
  return peekLength == headerStart + headerSize;
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:46,代码来源:Sniffer.java

示例10: setupSeeker

import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
/**
 * Returns a {@link Seeker} to seek using metadata read from {@code input}, which should provide
 * data from the start of the first frame in the stream. On returning, the input's position will
 * be set to the start of the first frame of audio.
 *
 * @param input The {@link ExtractorInput} from which to read.
 * @throws IOException Thrown if there was an error reading from the stream. Not expected if the
 *     next two frames were already peeked during synchronization.
 * @throws InterruptedException Thrown if reading from the stream was interrupted. Not expected if
 *     the next two frames were already peeked during synchronization.
 * @return a {@link Seeker}.
 */
private Seeker setupSeeker(ExtractorInput input) throws IOException, InterruptedException {
  // Read the first frame which may contain a Xing or VBRI header with seeking metadata.
  ParsableByteArray frame = new ParsableByteArray(synchronizedHeader.frameSize);
  input.peekFully(frame.data, 0, synchronizedHeader.frameSize);

  long position = input.getPosition();
  long length = input.getLength();
  int headerData = 0;
  Seeker seeker = null;

  // Check if there is a Xing header.
  int xingBase = (synchronizedHeader.version & 1) != 0
      ? (synchronizedHeader.channels != 1 ? 36 : 21) // MPEG 1
      : (synchronizedHeader.channels != 1 ? 21 : 13); // MPEG 2 or 2.5
  if (frame.limit() >= xingBase + 4) {
    frame.setPosition(xingBase);
    headerData = frame.readInt();
  }
  if (headerData == XING_HEADER || headerData == INFO_HEADER) {
    seeker = XingSeeker.create(synchronizedHeader, frame, position, length);
    if (seeker != null && !gaplessInfoHolder.hasGaplessInfo()) {
      // If there is a Xing header, read gapless playback metadata at a fixed offset.
      input.resetPeekPosition();
      input.advancePeekPosition(xingBase + 141);
      input.peekFully(scratch.data, 0, 3);
      scratch.setPosition(0);
      gaplessInfoHolder.setFromXingHeaderValue(scratch.readUnsignedInt24());
    }
    input.skipFully(synchronizedHeader.frameSize);
  } else if (frame.limit() >= 40) {
    // Check if there is a VBRI header.
    frame.setPosition(36); // MPEG audio header (4 bytes) + 32 bytes.
    headerData = frame.readInt();
    if (headerData == VBRI_HEADER) {
      seeker = VbriSeeker.create(synchronizedHeader, frame, position, length);
      input.skipFully(synchronizedHeader.frameSize);
    }
  }

  if (seeker == null || (!seeker.isSeekable()
      && (flags & FLAG_ENABLE_CONSTANT_BITRATE_SEEKING) != 0)) {
    // Repopulate the synchronized header in case we had to skip an invalid seeking header, which
    // would give an invalid CBR bitrate.
    input.resetPeekPosition();
    input.peekFully(scratch.data, 0, 4);
    scratch.setPosition(0);
    MpegAudioHeader.populateHeader(scratch.readInt(), synchronizedHeader);
    seeker = new ConstantBitrateSeeker(input.getPosition(), synchronizedHeader.bitrate, length);
  }

  return seeker;
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:65,代码来源:Mp3Extractor.java

示例11: sniff

import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
/**
 * @see Extractor#sniff
 */
public boolean sniff(ExtractorInput input) throws IOException, InterruptedException {
  long inputLength = input.getLength();
  int bytesToSearch = (int) (inputLength == C.LENGTH_UNSET || inputLength > SEARCH_LENGTH
      ? SEARCH_LENGTH : inputLength);
  // Find four bytes equal to ID_EBML near the start of the input.
  input.peekFully(scratch.data, 0, 4);
  long tag = scratch.readUnsignedInt();
  peekLength = 4;
  while (tag != ID_EBML) {
    if (++peekLength == bytesToSearch) {
      return false;
    }
    input.peekFully(scratch.data, 0, 1);
    tag = (tag << 8) & 0xFFFFFF00;
    tag |= scratch.data[0] & 0xFF;
  }

  // Read the size of the EBML header and make sure it is within the stream.
  long headerSize = readUint(input);
  long headerStart = peekLength;
  if (headerSize == Long.MIN_VALUE
      || (inputLength != C.LENGTH_UNSET && headerStart + headerSize >= inputLength)) {
    return false;
  }

  // Read the payload elements in the EBML header.
  while (peekLength < headerStart + headerSize) {
    long id = readUint(input);
    if (id == Long.MIN_VALUE) {
      return false;
    }
    long size = readUint(input);
    if (size < 0 || size > Integer.MAX_VALUE) {
      return false;
    }
    if (size != 0) {
      input.advancePeekPosition((int) size);
      peekLength += size;
    }
  }
  return peekLength == headerStart + headerSize;
}
 
开发者ID:zhanglibin123488,项目名称:videoPickPlayer,代码行数:46,代码来源:Sniffer.java

示例12: setupSeeker

import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
/**
 * Returns a {@link Seeker} to seek using metadata read from {@code input}, which should provide
 * data from the start of the first frame in the stream. On returning, the input's position will
 * be set to the start of the first frame of audio.
 *
 * @param input The {@link ExtractorInput} from which to read.
 * @throws IOException Thrown if there was an error reading from the stream. Not expected if the
 *     next two frames were already peeked during synchronization.
 * @throws InterruptedException Thrown if reading from the stream was interrupted. Not expected if
 *     the next two frames were already peeked during synchronization.
 * @return a {@link Seeker}.
 */
private Seeker setupSeeker(ExtractorInput input) throws IOException, InterruptedException {
  // Read the first frame which may contain a Xing or VBRI header with seeking metadata.
  ParsableByteArray frame = new ParsableByteArray(synchronizedHeader.frameSize);
  input.peekFully(frame.data, 0, synchronizedHeader.frameSize);

  long position = input.getPosition();
  long length = input.getLength();
  int headerData = 0;
  Seeker seeker = null;

  // Check if there is a Xing header.
  int xingBase = (synchronizedHeader.version & 1) != 0
      ? (synchronizedHeader.channels != 1 ? 36 : 21) // MPEG 1
      : (synchronizedHeader.channels != 1 ? 21 : 13); // MPEG 2 or 2.5
  if (frame.limit() >= xingBase + 4) {
    frame.setPosition(xingBase);
    headerData = frame.readInt();
  }
  if (headerData == XING_HEADER || headerData == INFO_HEADER) {
    seeker = XingSeeker.create(synchronizedHeader, frame, position, length);
    if (seeker != null && !gaplessInfoHolder.hasGaplessInfo()) {
      // If there is a Xing header, read gapless playback metadata at a fixed offset.
      input.resetPeekPosition();
      input.advancePeekPosition(xingBase + 141);
      input.peekFully(scratch.data, 0, 3);
      scratch.setPosition(0);
      gaplessInfoHolder.setFromXingHeaderValue(scratch.readUnsignedInt24());
    }
    input.skipFully(synchronizedHeader.frameSize);
  } else if (frame.limit() >= 40) {
    // Check if there is a VBRI header.
    frame.setPosition(36); // MPEG audio header (4 bytes) + 32 bytes.
    headerData = frame.readInt();
    if (headerData == VBRI_HEADER) {
      seeker = VbriSeeker.create(synchronizedHeader, frame, position, length);
      input.skipFully(synchronizedHeader.frameSize);
    }
  }

  if (seeker == null) {
    // Repopulate the synchronized header in case we had to skip an invalid seeking header, which
    // would give an invalid CBR bitrate.
    input.resetPeekPosition();
    input.peekFully(scratch.data, 0, 4);
    scratch.setPosition(0);
    MpegAudioHeader.populateHeader(scratch.readInt(), synchronizedHeader);
    seeker = new ConstantBitrateSeeker(input.getPosition(), synchronizedHeader.bitrate, length);
  }

  return seeker;
}
 
开发者ID:zhanglibin123488,项目名称:videoPickPlayer,代码行数:64,代码来源:Mp3Extractor.java


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