move Matroska specific things to the MatroskaExtractor

This commit is contained in:
Julian Cable 2017-01-11 08:13:43 +00:00
parent ac98874021
commit 8ae8ac79bc
3 changed files with 22 additions and 15 deletions

View file

@ -1498,7 +1498,10 @@ public final class MatroskaExtractor implements Extractor {
break; break;
case CODEC_ID_ASS: case CODEC_ID_ASS:
mimeType = MimeTypes.TEXT_SSA; mimeType = MimeTypes.TEXT_SSA;
initializationData = Collections.singletonList(codecPrivate); initializationData = new ArrayList<>(3);
// this dialogue format is specific to Matroska
initializationData.add("Start, End, ReadOrder, Layer, Style, Name, MarginL, MarginR, MarginV, Effect, Text".getBytes());
initializationData.add(codecPrivate);
break; break;
case CODEC_ID_VOBSUB: case CODEC_ID_VOBSUB:
mimeType = MimeTypes.APPLICATION_VOBSUB; mimeType = MimeTypes.APPLICATION_VOBSUB;

View file

@ -25,6 +25,9 @@ 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.util.List;
import static android.R.attr.initialKeyguardLayout;
import static android.R.attr.mimeType; import static android.R.attr.mimeType;
/** /**
@ -79,8 +82,10 @@ public interface SubtitleDecoderFactory {
throw new IllegalArgumentException("Attempted to create decoder for unsupported format"); throw new IllegalArgumentException("Attempted to create decoder for unsupported format");
} }
if(clazz == SSADecoder.class) { if(clazz == SSADecoder.class) {
return clazz.asSubclass(SubtitleDecoder.class).getConstructor(byte[].class) byte[] header = format.initializationData.get(1);
.newInstance(format.initializationData.get(0)); byte[] dialogueFormat = format.initializationData.get(0);
return clazz.asSubclass(SubtitleDecoder.class).getConstructor(byte[].class, byte[].class)
.newInstance(header, dialogueFormat);
} }
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)

View file

@ -8,12 +8,14 @@ import com.google.android.exoplayer2.util.ParsableByteArray;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import static android.R.attr.data; import static android.R.attr.data;
import static android.R.attr.subtitle; import static android.R.attr.subtitle;
import static android.R.attr.x; import static android.R.attr.x;
import static android.media.CamcorderProfile.get;
/** /**
* Created by cablej01 on 26/12/2016. * Created by cablej01 on 26/12/2016.
@ -65,26 +67,23 @@ import static android.R.attr.x;
*/ */
public class SSADecoder extends SimpleSubtitleDecoder { public class SSADecoder extends SimpleSubtitleDecoder {
private static final String TAG = "SSADecoder"; private static final String TAG = "SSADecoder";
private static String defaultDialogueFormat = "Start, End, ReadOrder, Layer, Style, Name, MarginL, MarginR, MarginV, Effect, Text"; private String[] dialogueFormat = null;
private static String defaultStyleFormat = "Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding"; private String[] styleFormat = null;
private String[] dialogueFormat;
private String[] styleFormat;
private Map<String,Style> styles = new HashMap<>(); private Map<String,Style> styles = new HashMap<>();
// 0,0,Watamote-internal/narrator,Serinuma,0000,0000,0000, ,The prince should be with the princess.
// , ,style ,name ,L ,R, V ,Effect, text
public SSADecoder() { public SSADecoder() {
super("SSADecoder"); super("SSADecoder");
dialogueFormat = parseKeys(defaultDialogueFormat);
styleFormat = parseKeys(defaultStyleFormat);
} }
public SSADecoder(byte[] header) { public SSADecoder(byte[] header, byte[] dialogueFormatBytes) {
super("SSADecoder"); super("SSADecoder");
styleFormat = parseKeys(defaultStyleFormat);
decodeHeader(header, header.length); decodeHeader(header, header.length);
// put back the Matroska format try {
dialogueFormat = parseKeys(defaultDialogueFormat); dialogueFormat = parseKeys(new String(dialogueFormatBytes, "UTF-8"));
}
catch (UnsupportedEncodingException e) {
// can't happen?
}
} }
/** /**