From 8ae8ac79bc59795df5a16b7552c13bc83dbddf86 Mon Sep 17 00:00:00 2001 From: Julian Cable Date: Wed, 11 Jan 2017 08:13:43 +0000 Subject: [PATCH] move Matroska specific things to the MatroskaExtractor --- .../extractor/mkv/MatroskaExtractor.java | 5 +++- .../text/SubtitleDecoderFactory.java | 9 ++++++-- .../exoplayer2/text/ssa/SSADecoder.java | 23 +++++++++---------- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/library/src/main/java/com/google/android/exoplayer2/extractor/mkv/MatroskaExtractor.java b/library/src/main/java/com/google/android/exoplayer2/extractor/mkv/MatroskaExtractor.java index 01e5cd2d1e..a8ff63c776 100644 --- a/library/src/main/java/com/google/android/exoplayer2/extractor/mkv/MatroskaExtractor.java +++ b/library/src/main/java/com/google/android/exoplayer2/extractor/mkv/MatroskaExtractor.java @@ -1498,7 +1498,10 @@ public final class MatroskaExtractor implements Extractor { break; case CODEC_ID_ASS: 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; case CODEC_ID_VOBSUB: mimeType = MimeTypes.APPLICATION_VOBSUB; diff --git a/library/src/main/java/com/google/android/exoplayer2/text/SubtitleDecoderFactory.java b/library/src/main/java/com/google/android/exoplayer2/text/SubtitleDecoderFactory.java index 68045e5f64..e21d4404ad 100644 --- a/library/src/main/java/com/google/android/exoplayer2/text/SubtitleDecoderFactory.java +++ b/library/src/main/java/com/google/android/exoplayer2/text/SubtitleDecoderFactory.java @@ -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.util.MimeTypes; +import java.util.List; + +import static android.R.attr.initialKeyguardLayout; import static android.R.attr.mimeType; /** @@ -79,8 +82,10 @@ public interface SubtitleDecoderFactory { throw new IllegalArgumentException("Attempted to create decoder for unsupported format"); } if(clazz == SSADecoder.class) { - return clazz.asSubclass(SubtitleDecoder.class).getConstructor(byte[].class) - .newInstance(format.initializationData.get(0)); + 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); } if (clazz == Cea608Decoder.class) { return clazz.asSubclass(SubtitleDecoder.class).getConstructor(String.class, Integer.TYPE) diff --git a/library/src/main/java/com/google/android/exoplayer2/text/ssa/SSADecoder.java b/library/src/main/java/com/google/android/exoplayer2/text/ssa/SSADecoder.java index 29f4b0bfee..4b160f8a00 100644 --- a/library/src/main/java/com/google/android/exoplayer2/text/ssa/SSADecoder.java +++ b/library/src/main/java/com/google/android/exoplayer2/text/ssa/SSADecoder.java @@ -8,12 +8,14 @@ import com.google.android.exoplayer2.util.ParsableByteArray; import java.io.UnsupportedEncodingException; import java.util.HashMap; +import java.util.List; import java.util.Locale; import java.util.Map; import static android.R.attr.data; import static android.R.attr.subtitle; import static android.R.attr.x; +import static android.media.CamcorderProfile.get; /** * Created by cablej01 on 26/12/2016. @@ -65,26 +67,23 @@ import static android.R.attr.x; */ public class SSADecoder extends SimpleSubtitleDecoder { private static final String TAG = "SSADecoder"; - private static String defaultDialogueFormat = "Start, End, ReadOrder, Layer, Style, Name, MarginL, MarginR, MarginV, Effect, Text"; - 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[] dialogueFormat; - private String[] styleFormat; + private String[] dialogueFormat = null; + private String[] styleFormat = null; private Map 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() { super("SSADecoder"); - dialogueFormat = parseKeys(defaultDialogueFormat); - styleFormat = parseKeys(defaultStyleFormat); } - public SSADecoder(byte[] header) { + public SSADecoder(byte[] header, byte[] dialogueFormatBytes) { super("SSADecoder"); - styleFormat = parseKeys(defaultStyleFormat); decodeHeader(header, header.length); - // put back the Matroska format - dialogueFormat = parseKeys(defaultDialogueFormat); + try { + dialogueFormat = parseKeys(new String(dialogueFormatBytes, "UTF-8")); + } + catch (UnsupportedEncodingException e) { + // can't happen? + } } /**