Commit d10c811b by olly Committed by Oliver Woodman

Fix Tx3g decoding

Issue #1712

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=129869936
parent cd4cc1dc
......@@ -18,6 +18,7 @@ package com.google.android.exoplayer2.text.tx3g;
import com.google.android.exoplayer2.text.Cue;
import com.google.android.exoplayer2.text.SimpleSubtitleDecoder;
import com.google.android.exoplayer2.text.Subtitle;
import com.google.android.exoplayer2.util.ParsableByteArray;
/**
* A {@link SimpleSubtitleDecoder} for tx3g.
......@@ -26,13 +27,21 @@ import com.google.android.exoplayer2.text.Subtitle;
*/
public final class Tx3gDecoder extends SimpleSubtitleDecoder {
private final ParsableByteArray parsableByteArray;
public Tx3gDecoder() {
super("Tx3gDecoder");
parsableByteArray = new ParsableByteArray();
}
@Override
protected Subtitle decode(byte[] bytes, int length) {
String cueText = new String(bytes, 0, length);
parsableByteArray.reset(bytes, length);
int textLength = parsableByteArray.readUnsignedShort();
if (textLength == 0) {
return Tx3gSubtitle.EMPTY;
}
String cueText = parsableByteArray.readString(textLength);
return new Tx3gSubtitle(new Cue(cueText));
}
......
......@@ -26,12 +26,18 @@ import java.util.List;
*/
/* package */ final class Tx3gSubtitle implements Subtitle {
public static final Tx3gSubtitle EMPTY = new Tx3gSubtitle();
private final List<Cue> cues;
public Tx3gSubtitle(Cue cue) {
this.cues = Collections.singletonList(cue);
}
private Tx3gSubtitle() {
this.cues = Collections.emptyList();
}
@Override
public int getNextEventTimeIndex(long timeUs) {
return timeUs < 0 ? 0 : -1;
......
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