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; ...@@ -88,7 +88,7 @@ import java.util.Collections;
appendData(data, bytesToRead); appendData(data, bytesToRead);
bytesRead += bytesToRead; bytesRead += bytesToRead;
if (bytesRead == sampleSize) { if (bytesRead == sampleSize) {
commitSample(true); commitSample(C.SAMPLE_FLAG_SYNC);
timeUs += frameDurationUs; timeUs += frameDurationUs;
bytesRead = 0; bytesRead = 0;
state = STATE_FINDING_SYNC; state = STATE_FINDING_SYNC;
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package com.google.android.exoplayer.hls.parser; package com.google.android.exoplayer.hls.parser;
import com.google.android.exoplayer.C;
import com.google.android.exoplayer.MediaFormat; import com.google.android.exoplayer.MediaFormat;
import com.google.android.exoplayer.mp4.Mp4Util; import com.google.android.exoplayer.mp4.Mp4Util;
import com.google.android.exoplayer.upstream.BufferPool; import com.google.android.exoplayer.upstream.BufferPool;
...@@ -88,7 +89,7 @@ import java.util.List; ...@@ -88,7 +89,7 @@ import java.util.List;
if (isKeyframe && !hasMediaFormat() && sps.isCompleted() && pps.isCompleted()) { if (isKeyframe && !hasMediaFormat() && sps.isCompleted() && pps.isCompleted()) {
parseMediaFormat(sps, pps); parseMediaFormat(sps, pps);
} }
commitSample(isKeyframe, nalUnitOffsetInData); commitSample(isKeyframe ? C.SAMPLE_FLAG_SYNC : 0, nalUnitOffsetInData);
} }
startSample(pesTimeUs, nalUnitOffsetInData); startSample(pesTimeUs, nalUnitOffsetInData);
isKeyframe = false; isKeyframe = false;
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package com.google.android.exoplayer.hls.parser; package com.google.android.exoplayer.hls.parser;
import com.google.android.exoplayer.C;
import com.google.android.exoplayer.MediaFormat; import com.google.android.exoplayer.MediaFormat;
import com.google.android.exoplayer.upstream.BufferPool; import com.google.android.exoplayer.upstream.BufferPool;
import com.google.android.exoplayer.util.ParsableByteArray; import com.google.android.exoplayer.util.ParsableByteArray;
...@@ -41,7 +42,7 @@ import com.google.android.exoplayer.util.ParsableByteArray; ...@@ -41,7 +42,7 @@ import com.google.android.exoplayer.util.ParsableByteArray;
@Override @Override
public void packetFinished() { public void packetFinished() {
commitSample(true); commitSample(C.SAMPLE_FLAG_SYNC);
} }
} }
...@@ -19,8 +19,11 @@ import com.google.android.exoplayer.C; ...@@ -19,8 +19,11 @@ import com.google.android.exoplayer.C;
import com.google.android.exoplayer.MediaFormat; import com.google.android.exoplayer.MediaFormat;
import com.google.android.exoplayer.SampleHolder; import com.google.android.exoplayer.SampleHolder;
import com.google.android.exoplayer.upstream.BufferPool; import com.google.android.exoplayer.upstream.BufferPool;
import com.google.android.exoplayer.upstream.DataSource;
import com.google.android.exoplayer.util.ParsableByteArray; import com.google.android.exoplayer.util.ParsableByteArray;
import java.io.IOException;
/** /**
* Wraps a {@link RollingSampleBuffer}, adding higher level functionality such as enforcing that * 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 * 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; ...@@ -186,16 +189,24 @@ import com.google.android.exoplayer.util.ParsableByteArray;
rollingBuffer.startSample(sampleTimeUs, offset); 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) { protected void appendData(ParsableByteArray buffer, int length) {
rollingBuffer.appendData(buffer, length); rollingBuffer.appendData(buffer, length);
} }
protected void commitSample(boolean isKeyframe) { protected void commitSample(int flags) {
commitSample(isKeyframe, 0); commitSample(flags, 0, null);
}
protected void commitSample(int flags, int offset) {
commitSample(flags, offset, null);
} }
protected void commitSample(boolean isKeyframe, int offset) { protected void commitSample(int flags, int offset, byte[] encryptionKey) {
rollingBuffer.commitSample(isKeyframe, offset); rollingBuffer.commitSample(flags, offset, encryptionKey);
writingSample = false; writingSample = false;
} }
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package com.google.android.exoplayer.hls.parser; package com.google.android.exoplayer.hls.parser;
import com.google.android.exoplayer.C;
import com.google.android.exoplayer.MediaFormat; import com.google.android.exoplayer.MediaFormat;
import com.google.android.exoplayer.text.eia608.Eia608Parser; import com.google.android.exoplayer.text.eia608.Eia608Parser;
import com.google.android.exoplayer.upstream.BufferPool; import com.google.android.exoplayer.upstream.BufferPool;
...@@ -59,7 +60,7 @@ import com.google.android.exoplayer.util.ParsableByteArray; ...@@ -59,7 +60,7 @@ import com.google.android.exoplayer.util.ParsableByteArray;
if (Eia608Parser.isSeiMessageEia608(payloadType, payloadSize, seiBuffer)) { if (Eia608Parser.isSeiMessageEia608(payloadType, payloadSize, seiBuffer)) {
startSample(pesTimeUs); startSample(pesTimeUs);
appendData(seiBuffer, payloadSize); appendData(seiBuffer, payloadSize);
commitSample(true); commitSample(C.SAMPLE_FLAG_SYNC);
} else { } else {
seiBuffer.skip(payloadSize); 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