Commit d71707f2 by Julian Cable

Make constructor clearer

parent 8ae8ac79
...@@ -25,6 +25,7 @@ import com.google.android.exoplayer2.text.webvtt.Mp4WebvttDecoder; ...@@ -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.text.webvtt.WebvttDecoder;
import com.google.android.exoplayer2.util.MimeTypes; import com.google.android.exoplayer2.util.MimeTypes;
import java.io.UnsupportedEncodingException;
import java.util.List; import java.util.List;
import static android.R.attr.initialKeyguardLayout; import static android.R.attr.initialKeyguardLayout;
...@@ -83,9 +84,9 @@ public interface SubtitleDecoderFactory { ...@@ -83,9 +84,9 @@ public interface SubtitleDecoderFactory {
} }
if(clazz == SSADecoder.class) { if(clazz == SSADecoder.class) {
byte[] header = format.initializationData.get(1); byte[] header = format.initializationData.get(1);
byte[] dialogueFormat = format.initializationData.get(0); String dlgfmt = new String(format.initializationData.get(0), "UTF-8");
return clazz.asSubclass(SubtitleDecoder.class).getConstructor(byte[].class, byte[].class) return clazz.asSubclass(SubtitleDecoder.class).getConstructor(byte[].class, String.class)
.newInstance(header, dialogueFormat); .newInstance(header, dlgfmt);
} }
if (clazz == Cea608Decoder.class) { if (clazz == Cea608Decoder.class) {
return clazz.asSubclass(SubtitleDecoder.class).getConstructor(String.class, Integer.TYPE) return clazz.asSubclass(SubtitleDecoder.class).getConstructor(String.class, Integer.TYPE)
......
...@@ -70,20 +70,16 @@ public class SSADecoder extends SimpleSubtitleDecoder { ...@@ -70,20 +70,16 @@ public class SSADecoder extends SimpleSubtitleDecoder {
private String[] dialogueFormat = null; private String[] dialogueFormat = null;
private String[] styleFormat = null; private String[] styleFormat = null;
private Map<String,Style> styles = new HashMap<>(); private Map<String,Style> styles = new HashMap<>();
private final static long _1e6 = 1000000;
public SSADecoder() { public SSADecoder() {
super("SSADecoder"); super("SSADecoder");
} }
public SSADecoder(byte[] header, byte[] dialogueFormatBytes) { public SSADecoder(byte[] header, String dlgfmt) {
super("SSADecoder"); super("SSADecoder");
decodeHeader(header, header.length); decodeHeader(header, header.length);
try { dialogueFormat = parseKeys(dlgfmt);
dialogueFormat = parseKeys(new String(dialogueFormatBytes, "UTF-8"));
}
catch (UnsupportedEncodingException e) {
// can't happen?
}
} }
/** /**
...@@ -203,7 +199,7 @@ public class SSADecoder extends SimpleSubtitleDecoder { ...@@ -203,7 +199,7 @@ public class SSADecoder extends SimpleSubtitleDecoder {
s.append(","); s.append(",");
long endUs = durationUs; // + blockTimeUs long endUs = durationUs; // + blockTimeUs
if (endUs == C.TIME_UNSET) { 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(SSADecoder.formatTimeCode(endUs));
s.append(","); s.append(",");
...@@ -213,13 +209,13 @@ public class SSADecoder extends SimpleSubtitleDecoder { ...@@ -213,13 +209,13 @@ public class SSADecoder extends SimpleSubtitleDecoder {
} }
public static String formatTimeCode(long tc_us) { public static String formatTimeCode(long tc_us) {
long seconds = tc_us / 1000000; long seconds = tc_us / _1e6;
long us = tc_us - 1000000*seconds; long us = tc_us - _1e6*seconds;
long minutes = seconds / 60; long minutes = seconds / 60;
seconds -= 60 * minutes; seconds -= 60 * minutes;
long hours = minutes / 60; long hours = minutes / 60;
minutes -= 60*hours; 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); return String.format(Locale.US, "%01d:%02d:%06.3f", hours, minutes, sec);
} }
...@@ -228,8 +224,8 @@ public class SSADecoder extends SimpleSubtitleDecoder { ...@@ -228,8 +224,8 @@ public class SSADecoder extends SimpleSubtitleDecoder {
long hours = Long.parseLong(p[0]); long hours = Long.parseLong(p[0]);
long minutes = Long.parseLong(p[1]); long minutes = Long.parseLong(p[1]);
float seconds = Float.parseFloat(p[2]); float seconds = Float.parseFloat(p[2]);
float us = 1000000*seconds; float us = _1e6*seconds;
long lus = ((long)us); long lus = ((long)us);
return lus + 1000000 * (60 * (minutes + 60 * hours)); return lus + _1e6 * (60 * (minutes + 60 * hours));
} }
} }
...@@ -12,6 +12,7 @@ import java.util.List; ...@@ -12,6 +12,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import static android.R.attr.start; import static android.R.attr.start;
import static android.os.Build.VERSION_CODES.N;
/** /**
* Created by cablej01 on 26/12/2016. * Created by cablej01 on 26/12/2016.
...@@ -92,6 +93,7 @@ public class SSASubtitle implements Subtitle { ...@@ -92,6 +93,7 @@ public class SSASubtitle implements Subtitle {
int layer = Integer.parseInt(ev.get("layer")); int layer = Integer.parseInt(ev.get("layer"));
String effect = ev.get("effect"); String effect = ev.get("effect");
String text = ev.get("text").replaceAll("\\\\N", "\n"); String text = ev.get("text").replaceAll("\\\\N", "\n");
text = text.replaceAll("\\\\n", "\n");
String simpleText = text.replaceAll("\\{[^{]*\\}", ""); String simpleText = text.replaceAll("\\{[^{]*\\}", "");
//Cue cue = new SSACue(text, style, layer, effect); //Cue cue = new SSACue(text, style, layer, effect);
Cue cue = new Cue(simpleText); Cue cue = new Cue(simpleText);
...@@ -99,7 +101,7 @@ public class SSASubtitle implements Subtitle { ...@@ -99,7 +101,7 @@ public class SSASubtitle implements Subtitle {
cueTimesUs.add(start); cueTimesUs.add(start);
cues.add(cue); cues.add(cue);
// add null cue to remove this cue after it's duration // 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); cueTimesUs.add(end);
cues.add(null); cues.add(null);
} }
......
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