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


Java ParsableByteArray.readLittleEndianUnsignedShort方法代码示例

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


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

示例1: parseMsAcmCodecPrivate

import com.google.android.exoplayer2.util.ParsableByteArray; //导入方法依赖的package包/类
/**
 * Parses an MS/ACM codec private, returning whether it indicates PCM audio.
 *
 * @return Whether the codec private indicates PCM audio.
 * @throws ParserException If a parsing error occurs.
 */
private static boolean parseMsAcmCodecPrivate(ParsableByteArray buffer) throws ParserException {
  try {
    int formatTag = buffer.readLittleEndianUnsignedShort();
    if (formatTag == WAVE_FORMAT_PCM) {
      return true;
    } else if (formatTag == WAVE_FORMAT_EXTENSIBLE) {
      buffer.setPosition(WAVE_FORMAT_SIZE + 6); // unionSamples(2), channelMask(4)
      return buffer.readLong() == WAVE_SUBFORMAT_PCM.getMostSignificantBits()
          && buffer.readLong() == WAVE_SUBFORMAT_PCM.getLeastSignificantBits();
    } else {
      return false;
    }
  } catch (ArrayIndexOutOfBoundsException e) {
    throw new ParserException("Error parsing MS/ACM codec private");
  }
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:23,代码来源:MatroskaExtractor.java

示例2: peek

import com.google.android.exoplayer2.util.ParsableByteArray; //导入方法依赖的package包/类
/**
 * Peeks and returns a {@code WavHeader}.
 *
 * @param input Input stream to peek the WAV header from.
 * @throws ParserException If the input file is an incorrect RIFF WAV.
 * @throws IOException If peeking from the input fails.
 * @throws InterruptedException If interrupted while peeking from input.
 * @return A new {@code WavHeader} peeked from {@code input}, or null if the input is not a
 *     supported WAV format.
 */
public static WavHeader peek(ExtractorInput input) throws IOException, InterruptedException {
  Assertions.checkNotNull(input);

  // Allocate a scratch buffer large enough to store the format chunk.
  ParsableByteArray scratch = new ParsableByteArray(16);

  // Attempt to read the RIFF chunk.
  ChunkHeader chunkHeader = ChunkHeader.peek(input, scratch);
  if (chunkHeader.id != Util.getIntegerCodeForString("RIFF")) {
    return null;
  }

  input.peekFully(scratch.data, 0, 4);
  scratch.setPosition(0);
  int riffFormat = scratch.readInt();
  if (riffFormat != Util.getIntegerCodeForString("WAVE")) {
    Log.e(TAG, "Unsupported RIFF format: " + riffFormat);
    return null;
  }

  // Skip chunks until we find the format chunk.
  chunkHeader = ChunkHeader.peek(input, scratch);
  while (chunkHeader.id != Util.getIntegerCodeForString("fmt ")) {
    input.advancePeekPosition((int) chunkHeader.size);
    chunkHeader = ChunkHeader.peek(input, scratch);
  }

  Assertions.checkState(chunkHeader.size >= 16);
  input.peekFully(scratch.data, 0, 16);
  scratch.setPosition(0);
  int type = scratch.readLittleEndianUnsignedShort();
  int numChannels = scratch.readLittleEndianUnsignedShort();
  int sampleRateHz = scratch.readLittleEndianUnsignedIntToInt();
  int averageBytesPerSecond = scratch.readLittleEndianUnsignedIntToInt();
  int blockAlignment = scratch.readLittleEndianUnsignedShort();
  int bitsPerSample = scratch.readLittleEndianUnsignedShort();

  int expectedBlockAlignment = numChannels * bitsPerSample / 8;
  if (blockAlignment != expectedBlockAlignment) {
    throw new ParserException("Expected block alignment: " + expectedBlockAlignment + "; got: "
        + blockAlignment);
  }

  @C.PcmEncoding int encoding = Util.getPcmEncoding(bitsPerSample);
  if (encoding == C.ENCODING_INVALID) {
    Log.e(TAG, "Unsupported WAV bit depth: " + bitsPerSample);
    return null;
  }

  if (type != TYPE_PCM && type != TYPE_WAVE_FORMAT_EXTENSIBLE) {
    Log.e(TAG, "Unsupported WAV format type: " + type);
    return null;
  }

  // If present, skip extensionSize, validBitsPerSample, channelMask, subFormatGuid, ...
  input.advancePeekPosition((int) chunkHeader.size - 16);

  return new WavHeader(numChannels, sampleRateHz, averageBytesPerSecond, blockAlignment,
      bitsPerSample, encoding);
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:71,代码来源:WavHeaderReader.java


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