use of com.google.android.exoplayer2.C in project ExoPlayer by google.
the class VbriSeeker method create.
/**
* Returns a {@link VbriSeeker} for seeking in the stream, if required information is present.
* Returns {@code null} if not. On returning, {@code frame}'s position is not specified so the
* caller should reset it.
*
* @param inputLength The length of the stream in bytes, or {@link C#LENGTH_UNSET} if unknown.
* @param position The position of the start of this frame in the stream.
* @param mpegAudioHeader The MPEG audio header associated with the frame.
* @param frame The data in this audio frame, with its position set to immediately after the
* 'VBRI' tag.
* @return A {@link VbriSeeker} for seeking in the stream, or {@code null} if the required
* information is not present.
*/
@Nullable
public static VbriSeeker create(long inputLength, long position, MpegAudioUtil.Header mpegAudioHeader, ParsableByteArray frame) {
frame.skipBytes(10);
int numFrames = frame.readInt();
if (numFrames <= 0) {
return null;
}
int sampleRate = mpegAudioHeader.sampleRate;
long durationUs = Util.scaleLargeTimestamp(numFrames, C.MICROS_PER_SECOND * (sampleRate >= 32000 ? 1152 : 576), sampleRate);
int entryCount = frame.readUnsignedShort();
int scale = frame.readUnsignedShort();
int entrySize = frame.readUnsignedShort();
frame.skipBytes(2);
long minPosition = position + mpegAudioHeader.frameSize;
// Read table of contents entries.
long[] timesUs = new long[entryCount];
long[] positions = new long[entryCount];
for (int index = 0; index < entryCount; index++) {
timesUs[index] = (index * durationUs) / entryCount;
// Ensure positions do not fall within the frame containing the VBRI header. This constraint
// will normally only apply to the first entry in the table.
positions[index] = max(position, minPosition);
int segmentSize;
switch(entrySize) {
case 1:
segmentSize = frame.readUnsignedByte();
break;
case 2:
segmentSize = frame.readUnsignedShort();
break;
case 3:
segmentSize = frame.readUnsignedInt24();
break;
case 4:
segmentSize = frame.readUnsignedIntToInt();
break;
default:
return null;
}
position += segmentSize * scale;
}
if (inputLength != C.LENGTH_UNSET && inputLength != position) {
Log.w(TAG, "VBRI data size mismatch: " + inputLength + ", " + position);
}
return new VbriSeeker(timesUs, positions, durationUs, /* dataEndPosition= */
position);
}
use of com.google.android.exoplayer2.C in project ExoPlayer by google.
the class WavHeaderReader method readRf64SampleDataSize.
/**
* Reads the ds64 chunk defined in EBU - TECH 3306-2007, if present. If there is no such chunk,
* the input's position is left unchanged.
*
* @param input Input stream to read from. The position should point to the byte following the
* WAVE tag.
* @throws IOException If reading from the input fails.
* @return The value of the data size field in the ds64 chunk, or {@link C#LENGTH_UNSET} if there
* is no such chunk.
*/
public static long readRf64SampleDataSize(ExtractorInput input) throws IOException {
ParsableByteArray scratch = new ParsableByteArray(ChunkHeader.SIZE_IN_BYTES);
ChunkHeader chunkHeader = ChunkHeader.peek(input, scratch);
if (chunkHeader.id != WavUtil.DS64_FOURCC) {
input.resetPeekPosition();
return C.LENGTH_UNSET;
}
// RIFF size
input.advancePeekPosition(8);
scratch.setPosition(0);
input.peekFully(scratch.getData(), 0, 8);
long sampleDataSize = scratch.readLittleEndianLong();
input.skipFully(ChunkHeader.SIZE_IN_BYTES + (int) chunkHeader.size);
return sampleDataSize;
}
Aggregations