本文整理汇总了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");
}
}
示例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);
}