Commit becc6fca by Oliver Woodman

Enhance SampleQueue/RollingSampleBuffer to support other use cases.

- This is a step toward hopefully converging HLS and CHUNK packages.
- Add support for encrypted samples.
- Add support for appending from a DataSource.
parent 5d045715
......@@ -88,7 +88,7 @@ import java.util.Collections;
appendData(data, bytesToRead);
bytesRead += bytesToRead;
if (bytesRead == sampleSize) {
commitSample(true);
commitSample(C.SAMPLE_FLAG_SYNC);
timeUs += frameDurationUs;
bytesRead = 0;
state = STATE_FINDING_SYNC;
......
......@@ -15,6 +15,7 @@
*/
package com.google.android.exoplayer.hls.parser;
import com.google.android.exoplayer.C;
import com.google.android.exoplayer.MediaFormat;
import com.google.android.exoplayer.mp4.Mp4Util;
import com.google.android.exoplayer.upstream.BufferPool;
......@@ -88,7 +89,7 @@ import java.util.List;
if (isKeyframe && !hasMediaFormat() && sps.isCompleted() && pps.isCompleted()) {
parseMediaFormat(sps, pps);
}
commitSample(isKeyframe, nalUnitOffsetInData);
commitSample(isKeyframe ? C.SAMPLE_FLAG_SYNC : 0, nalUnitOffsetInData);
}
startSample(pesTimeUs, nalUnitOffsetInData);
isKeyframe = false;
......
......@@ -15,6 +15,7 @@
*/
package com.google.android.exoplayer.hls.parser;
import com.google.android.exoplayer.C;
import com.google.android.exoplayer.MediaFormat;
import com.google.android.exoplayer.upstream.BufferPool;
import com.google.android.exoplayer.util.ParsableByteArray;
......@@ -41,7 +42,7 @@ import com.google.android.exoplayer.util.ParsableByteArray;
@Override
public void packetFinished() {
commitSample(true);
commitSample(C.SAMPLE_FLAG_SYNC);
}
}
......@@ -19,8 +19,11 @@ import com.google.android.exoplayer.C;
import com.google.android.exoplayer.MediaFormat;
import com.google.android.exoplayer.SampleHolder;
import com.google.android.exoplayer.upstream.BufferPool;
import com.google.android.exoplayer.upstream.DataSource;
import com.google.android.exoplayer.util.ParsableByteArray;
import java.io.IOException;
/**
* Wraps a {@link RollingSampleBuffer}, adding higher level functionality such as enforcing that
* the first sample returned from the queue is a keyframe, allowing splicing to another queue, and
......@@ -186,16 +189,24 @@ import com.google.android.exoplayer.util.ParsableByteArray;
rollingBuffer.startSample(sampleTimeUs, offset);
}
protected int appendData(DataSource dataSource, int length) throws IOException {
return rollingBuffer.appendData(dataSource, length);
}
protected void appendData(ParsableByteArray buffer, int length) {
rollingBuffer.appendData(buffer, length);
}
protected void commitSample(boolean isKeyframe) {
commitSample(isKeyframe, 0);
protected void commitSample(int flags) {
commitSample(flags, 0, null);
}
protected void commitSample(int flags, int offset) {
commitSample(flags, offset, null);
}
protected void commitSample(boolean isKeyframe, int offset) {
rollingBuffer.commitSample(isKeyframe, offset);
protected void commitSample(int flags, int offset, byte[] encryptionKey) {
rollingBuffer.commitSample(flags, offset, encryptionKey);
writingSample = false;
}
......
......@@ -15,6 +15,7 @@
*/
package com.google.android.exoplayer.hls.parser;
import com.google.android.exoplayer.C;
import com.google.android.exoplayer.MediaFormat;
import com.google.android.exoplayer.text.eia608.Eia608Parser;
import com.google.android.exoplayer.upstream.BufferPool;
......@@ -59,7 +60,7 @@ import com.google.android.exoplayer.util.ParsableByteArray;
if (Eia608Parser.isSeiMessageEia608(payloadType, payloadSize, seiBuffer)) {
startSample(pesTimeUs);
appendData(seiBuffer, payloadSize);
commitSample(true);
commitSample(C.SAMPLE_FLAG_SYNC);
} else {
seiBuffer.skip(payloadSize);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment