Make constructor clearer

This commit is contained in:
Julian Cable 2017-01-11 23:11:32 +00:00
parent 8ae8ac79bc
commit d71707f220
3 changed files with 16 additions and 17 deletions

View file

@ -25,6 +25,7 @@ import com.google.android.exoplayer2.text.webvtt.Mp4WebvttDecoder;
import com.google.android.exoplayer2.text.webvtt.WebvttDecoder;
import com.google.android.exoplayer2.util.MimeTypes;
import java.io.UnsupportedEncodingException;
import java.util.List;
import static android.R.attr.initialKeyguardLayout;
@ -83,9 +84,9 @@ public interface SubtitleDecoderFactory {
}
if(clazz == SSADecoder.class) {
byte[] header = format.initializationData.get(1);
byte[] dialogueFormat = format.initializationData.get(0);
return clazz.asSubclass(SubtitleDecoder.class).getConstructor(byte[].class, byte[].class)
.newInstance(header, dialogueFormat);
String dlgfmt = new String(format.initializationData.get(0), "UTF-8");
return clazz.asSubclass(SubtitleDecoder.class).getConstructor(byte[].class, String.class)
.newInstance(header, dlgfmt);
}
if (clazz == Cea608Decoder.class) {
return clazz.asSubclass(SubtitleDecoder.class).getConstructor(String.class, Integer.TYPE)

View file

@ -70,20 +70,16 @@ public class SSADecoder extends SimpleSubtitleDecoder {
private String[] dialogueFormat = null;
private String[] styleFormat = null;
private Map<String,Style> styles = new HashMap<>();
private final static long _1e6 = 1000000;
public SSADecoder() {
super("SSADecoder");
}
public SSADecoder(byte[] header, byte[] dialogueFormatBytes) {
public SSADecoder(byte[] header, String dlgfmt) {
super("SSADecoder");
decodeHeader(header, header.length);
try {
dialogueFormat = parseKeys(new String(dialogueFormatBytes, "UTF-8"));
}
catch (UnsupportedEncodingException e) {
// can't happen?
}
dialogueFormat = parseKeys(dlgfmt);
}
/**
@ -203,7 +199,7 @@ public class SSADecoder extends SimpleSubtitleDecoder {
s.append(",");
long endUs = durationUs; // + blockTimeUs
if (endUs == C.TIME_UNSET) {
endUs = 2000000; // 2 second default duration
endUs = 2*_1e6; // 2 second default duration
}
s.append(SSADecoder.formatTimeCode(endUs));
s.append(",");
@ -213,13 +209,13 @@ public class SSADecoder extends SimpleSubtitleDecoder {
}
public static String formatTimeCode(long tc_us) {
long seconds = tc_us / 1000000;
long us = tc_us - 1000000*seconds;
long seconds = tc_us / _1e6;
long us = tc_us - _1e6*seconds;
long minutes = seconds / 60;
seconds -= 60 * minutes;
long hours = minutes / 60;
minutes -= 60*hours;
double sec = seconds + ((float)us)/1000000.0;
double sec = seconds + ((float)us)/_1e6;
return String.format(Locale.US, "%01d:%02d:%06.3f", hours, minutes, sec);
}
@ -228,8 +224,8 @@ public class SSADecoder extends SimpleSubtitleDecoder {
long hours = Long.parseLong(p[0]);
long minutes = Long.parseLong(p[1]);
float seconds = Float.parseFloat(p[2]);
float us = 1000000*seconds;
float us = _1e6*seconds;
long lus = ((long)us);
return lus + 1000000 * (60 * (minutes + 60 * hours));
return lus + _1e6 * (60 * (minutes + 60 * hours));
}
}

View file

@ -12,6 +12,7 @@ import java.util.List;
import java.util.Map;
import static android.R.attr.start;
import static android.os.Build.VERSION_CODES.N;
/**
* Created by cablej01 on 26/12/2016.
@ -92,6 +93,7 @@ public class SSASubtitle implements Subtitle {
int layer = Integer.parseInt(ev.get("layer"));
String effect = ev.get("effect");
String text = ev.get("text").replaceAll("\\\\N", "\n");
text = text.replaceAll("\\\\n", "\n");
String simpleText = text.replaceAll("\\{[^{]*\\}", "");
//Cue cue = new SSACue(text, style, layer, effect);
Cue cue = new Cue(simpleText);
@ -99,7 +101,7 @@ public class SSASubtitle implements Subtitle {
cueTimesUs.add(start);
cues.add(cue);
// add null cue to remove this cue after it's duration
long end = SSADecoder.parseTimecode(ev.get("end"));
long end = 10*SSADecoder.parseTimecode(ev.get("end"));
cueTimesUs.add(end);
cues.add(null);
}