/** * Discards samples from the write side of the buffer. * * @param discardFromIndex The absolute index of the first sample to be discarded. */ public void discardUpstreamSamples(int discardFromIndex) { totalBytesWritten = infoQueue.discardUpstreamSamples(discardFromIndex); dropUpstreamFrom(totalBytesWritten); }
/** * Skips the current sample. */ public void skipSample() { long nextOffset = infoQueue.moveToNextSample(); dropDownstreamTo(nextOffset); }
private ExtractingLoadable createLoadableFromPositionUs(long positionUs) { return new ExtractingLoadable(uri, dataSource, extractorHolder, allocator, requestedBufferSize, seekMap.getPosition(positionUs)); }
/** * Attempts to skip to the keyframe before the specified time, if it's present in the buffer. * * @param timeUs The seek time. * @return True if the skip was successful. False otherwise. */ public boolean skipToKeyframeBefore(long timeUs) { long nextOffset = infoQueue.skipToKeyframeBefore(timeUs); if (nextOffset == -1) { return false; } dropDownstreamTo(nextOffset); return true; }
@Override public boolean sniff(ExtractorInput input) throws IOException, InterruptedException { byte[] scratch = new byte[1]; for (int i = 0; i < 5; i++) { input.peekFully(scratch, 0, 1); if ((scratch[0] & 0xFF) != 0x47) { return false; } input.advancePeekPosition(TS_PACKET_SIZE - 1); } return true; }
/** * Discards samples from the write side of the queue. * * @param discardFromIndex The absolute index of the first sample to be discarded. */ public void discardUpstreamSamples(int discardFromIndex) { rollingBuffer.discardUpstreamSamples(discardFromIndex); largestParsedTimestampUs = rollingBuffer.peekSample(sampleInfoHolder) ? sampleInfoHolder.timeUs : Long.MIN_VALUE; }
@Override public void init(ExtractorOutput output) { this.output = output; output.seekMap(SeekMap.UNSEEKABLE); }
/** * Attempts to skip to the keyframe before the specified time, if it's present in the buffer. * * @param timeUs The seek time. * @return True if the skip was successful. False otherwise. */ public boolean skipToKeyframeBefore(long timeUs) { return rollingBuffer.skipToKeyframeBefore(timeUs); }
/** * Fills {@code holder} with information about the current sample, but does not write its data. * <p> * The fields set are {@link SampleHolder#size}, {@link SampleHolder#timeUs} and * {@link SampleHolder#flags}. * * @param holder The holder into which the current sample information should be written. * @return True if the holder was filled. False if there is no current sample. */ public boolean peekSample(SampleHolder holder) { return infoQueue.peekSample(holder, extrasHolder); }
private void outputSample(int offset) { int flags = sampleIsKeyframe ? C.SAMPLE_FLAG_SYNC : 0; int size = (int) (nalUnitStartPosition - samplePosition); output.sampleMetadata(sampleTimeUs, flags, size, offset, null); }
/** * Returns the current absolute write index. */ public int getWriteIndex() { return rollingBuffer.getWriteIndex(); }
@Override public void readFully(byte[] target, int offset, int length) throws IOException, InterruptedException { readFully(target, offset, length, false); }
/** * Returns the current absolute read index. */ public int getReadIndex() { return infoQueue.getReadIndex(); }
/** * True if at least one sample can be read from the queue. False otherwise. */ public boolean isEmpty() { return !advanceToEligibleSample(); }
@Override public int sampleData(ExtractorInput input, int length, boolean allowEndOfInput) throws IOException, InterruptedException { return rollingBuffer.appendData(input, length, allowEndOfInput); }
/** * Returns the current absolute write index. */ public int getWriteIndex() { return infoQueue.getWriteIndex(); }
@Override public void sampleMetadata(long timeUs, int flags, int size, int offset, byte[] encryptionKey) { super.sampleMetadata(timeUs, flags, size, offset, encryptionKey); extractedSampleCount++; }
/** * Returns the current absolute read index. */ public int getReadIndex() { return rollingBuffer.getReadIndex(); }