Fix Tx3g decoding

Issue #1712

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=129869936
This commit is contained in:
olly 2016-08-10 08:44:14 -07:00 committed by Oliver Woodman
parent cd4cc1dc14
commit d10c811bd8
2 changed files with 16 additions and 1 deletions

View File

@ -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));
}

View File

@ -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;