Search in sources :

Example 31 with C

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);
}
Also used : SeekPoint(com.google.android.exoplayer2.extractor.SeekPoint) Nullable(androidx.annotation.Nullable)

Example 32 with C

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;
}
Also used : ParsableByteArray(com.google.android.exoplayer2.util.ParsableByteArray)

Aggregations

Test (org.junit.Test)14 BaseUrl (com.google.android.exoplayer2.source.dash.manifest.BaseUrl)6 Format (com.google.android.exoplayer2.Format)5 SeekPoint (com.google.android.exoplayer2.extractor.SeekPoint)5 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)4 IOException (java.io.IOException)4 Nullable (androidx.annotation.Nullable)3 RendererCapabilities (com.google.android.exoplayer2.RendererCapabilities)3 HashMap (java.util.HashMap)3 Metadata (com.google.android.exoplayer2.metadata.Metadata)2 EventStream (com.google.android.exoplayer2.source.dash.manifest.EventStream)2 InterruptedIOException (java.io.InterruptedIOException)2 TargetApi (android.annotation.TargetApi)1 Activity (android.app.Activity)1 ActivityManager (android.app.ActivityManager)1 Application (android.app.Application)1 UiModeManager (android.app.UiModeManager)1 Context (android.content.Context)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1