mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Use Util.maybeInflate()
This commit is contained in:
parent
3cd0e1ad3d
commit
f52d98eafd
@ -49,8 +49,6 @@ public final class PgsParser implements SubtitleParser {
|
|||||||
private static final int SECTION_TYPE_IDENTIFIER = 0x16;
|
private static final int SECTION_TYPE_IDENTIFIER = 0x16;
|
||||||
private static final int SECTION_TYPE_END = 0x80;
|
private static final int SECTION_TYPE_END = 0x80;
|
||||||
|
|
||||||
private static final byte INFLATE_HEADER = 0x78;
|
|
||||||
|
|
||||||
private final ParsableByteArray buffer;
|
private final ParsableByteArray buffer;
|
||||||
private final ParsableByteArray inflatedBuffer;
|
private final ParsableByteArray inflatedBuffer;
|
||||||
private final CueBuilder cueBuilder;
|
private final CueBuilder cueBuilder;
|
||||||
@ -76,7 +74,12 @@ public final class PgsParser implements SubtitleParser {
|
|||||||
Consumer<CuesWithTiming> output) {
|
Consumer<CuesWithTiming> output) {
|
||||||
buffer.reset(data, /* limit= */ offset + length);
|
buffer.reset(data, /* limit= */ offset + length);
|
||||||
buffer.setPosition(offset);
|
buffer.setPosition(offset);
|
||||||
maybeInflateData(buffer);
|
if (inflater == null) {
|
||||||
|
inflater = new Inflater();
|
||||||
|
}
|
||||||
|
if (Util.maybeInflate(buffer, inflatedBuffer, inflater)) {
|
||||||
|
buffer.reset(inflatedBuffer.getData(), inflatedBuffer.limit());
|
||||||
|
}
|
||||||
cueBuilder.reset();
|
cueBuilder.reset();
|
||||||
ArrayList<Cue> cues = new ArrayList<>();
|
ArrayList<Cue> cues = new ArrayList<>();
|
||||||
while (buffer.bytesLeft() >= 3) {
|
while (buffer.bytesLeft() >= 3) {
|
||||||
@ -89,17 +92,6 @@ public final class PgsParser implements SubtitleParser {
|
|||||||
new CuesWithTiming(cues, /* startTimeUs= */ C.TIME_UNSET, /* durationUs= */ C.TIME_UNSET));
|
new CuesWithTiming(cues, /* startTimeUs= */ C.TIME_UNSET, /* durationUs= */ C.TIME_UNSET));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void maybeInflateData(ParsableByteArray buffer) {
|
|
||||||
if (buffer.bytesLeft() > 0 && buffer.peekUnsignedByte() == INFLATE_HEADER) {
|
|
||||||
if (inflater == null) {
|
|
||||||
inflater = new Inflater();
|
|
||||||
}
|
|
||||||
if (Util.inflate(buffer, inflatedBuffer, inflater)) {
|
|
||||||
buffer.reset(inflatedBuffer.getData(), inflatedBuffer.limit());
|
|
||||||
} // else assume data is not compressed.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private static Cue readNextSection(ParsableByteArray buffer, CueBuilder cueBuilder) {
|
private static Cue readNextSection(ParsableByteArray buffer, CueBuilder cueBuilder) {
|
||||||
int limit = buffer.limit();
|
int limit = buffer.limit();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user