Search in sources :

Example 1 with FakeSampleStreamItem.format

use of androidx.media3.test.utils.FakeSampleStream.FakeSampleStreamItem.format in project media by androidx.

the class FakeSampleStream method writeData.

/**
 * Writes all not yet written {@link FakeSampleStreamItem sample stream items} to the sample queue
 * starting at the given position.
 *
 * @param startPositionUs The start position, in microseconds.
 */
public void writeData(long startPositionUs) {
    if (sampleStreamItemsWritePosition == 0) {
        sampleQueue.setStartTimeUs(startPositionUs);
    }
    boolean writtenFirstFormat = false;
    @Nullable Format pendingFirstFormat = null;
    for (int i = 0; i < sampleStreamItems.size(); i++) {
        FakeSampleStreamItem fakeSampleStreamItem = sampleStreamItems.get(i);
        @Nullable FakeSampleStream.SampleInfo sampleInfo = fakeSampleStreamItem.sampleInfo;
        if (sampleInfo == null) {
            if (writtenFirstFormat) {
                sampleQueue.format(checkNotNull(fakeSampleStreamItem.format));
            } else {
                pendingFirstFormat = checkNotNull(fakeSampleStreamItem.format);
            }
            continue;
        }
        if ((sampleInfo.flags & C.BUFFER_FLAG_END_OF_STREAM) != 0) {
            loadingFinished = true;
            break;
        }
        if (sampleInfo.timeUs >= startPositionUs && i >= sampleStreamItemsWritePosition) {
            if (!writtenFirstFormat) {
                sampleQueue.format(checkNotNull(pendingFirstFormat));
                writtenFirstFormat = true;
            }
            sampleQueue.sampleData(new ParsableByteArray(sampleInfo.data), sampleInfo.data.length);
            sampleQueue.sampleMetadata(sampleInfo.timeUs, sampleInfo.flags, sampleInfo.data.length, /* offset= */
            0, /* cryptoData= */
            null);
        }
    }
    sampleStreamItemsWritePosition = sampleStreamItems.size();
}
Also used : ParsableByteArray(androidx.media3.common.util.ParsableByteArray) Format(androidx.media3.common.Format) Nullable(androidx.annotation.Nullable)

Aggregations

Nullable (androidx.annotation.Nullable)1 Format (androidx.media3.common.Format)1 ParsableByteArray (androidx.media3.common.util.ParsableByteArray)1