Fix Tx3g decoding
Issue #1712 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=129869936
This commit is contained in:
parent
cd4cc1dc14
commit
d10c811bd8
@ -18,6 +18,7 @@ package com.google.android.exoplayer2.text.tx3g;
|
|||||||
import com.google.android.exoplayer2.text.Cue;
|
import com.google.android.exoplayer2.text.Cue;
|
||||||
import com.google.android.exoplayer2.text.SimpleSubtitleDecoder;
|
import com.google.android.exoplayer2.text.SimpleSubtitleDecoder;
|
||||||
import com.google.android.exoplayer2.text.Subtitle;
|
import com.google.android.exoplayer2.text.Subtitle;
|
||||||
|
import com.google.android.exoplayer2.util.ParsableByteArray;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link SimpleSubtitleDecoder} for tx3g.
|
* A {@link SimpleSubtitleDecoder} for tx3g.
|
||||||
@ -26,13 +27,21 @@ import com.google.android.exoplayer2.text.Subtitle;
|
|||||||
*/
|
*/
|
||||||
public final class Tx3gDecoder extends SimpleSubtitleDecoder {
|
public final class Tx3gDecoder extends SimpleSubtitleDecoder {
|
||||||
|
|
||||||
|
private final ParsableByteArray parsableByteArray;
|
||||||
|
|
||||||
public Tx3gDecoder() {
|
public Tx3gDecoder() {
|
||||||
super("Tx3gDecoder");
|
super("Tx3gDecoder");
|
||||||
|
parsableByteArray = new ParsableByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Subtitle decode(byte[] bytes, int length) {
|
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));
|
return new Tx3gSubtitle(new Cue(cueText));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,12 +26,18 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
/* package */ final class Tx3gSubtitle implements Subtitle {
|
/* package */ final class Tx3gSubtitle implements Subtitle {
|
||||||
|
|
||||||
|
public static final Tx3gSubtitle EMPTY = new Tx3gSubtitle();
|
||||||
|
|
||||||
private final List<Cue> cues;
|
private final List<Cue> cues;
|
||||||
|
|
||||||
public Tx3gSubtitle(Cue cue) {
|
public Tx3gSubtitle(Cue cue) {
|
||||||
this.cues = Collections.singletonList(cue);
|
this.cues = Collections.singletonList(cue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Tx3gSubtitle() {
|
||||||
|
this.cues = Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getNextEventTimeIndex(long timeUs) {
|
public int getNextEventTimeIndex(long timeUs) {
|
||||||
return timeUs < 0 ? 0 : -1;
|
return timeUs < 0 ? 0 : -1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user