思特奇智慧酒店云平台 v0.0.5版本的 MD5 值为:dedb172bb322639d79d7e0e26262fb5c
以下内容为反编译后的 SMPTETTTrackImpl.java 源代码,内容仅作参考
package com.googlecode.mp4parser.authoring.tracks;
import com.googlecode.mp4parser.authoring.AbstractTrack;
import com.googlecode.mp4parser.authoring.Sample;
import com.googlecode.mp4parser.authoring.TrackMetaData;
import com.googlecode.mp4parser.util.Iso639;
import com.taobao.weex.ui.view.gesture.WXGesture;
import defpackage.x00;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.WritableByteChannel;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.xml.namespace.NamespaceContext;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
public class SMPTETTTrackImpl extends AbstractTrack {
public static final String SMPTE_TT_NAMESPACE = "http://www.smpte-ra.org/schemas/2052-1/2010/smpte-tt";
public nf0 XMLSubtitleSampleEntry;
public boolean containsImages;
public p00 sampleDescriptionBox;
public long[] sampleDurations;
public List<Sample> samples;
public x00 subSampleInformationBox;
public TrackMetaData trackMetaData;
public static class TextTrackNamespaceContext implements NamespaceContext {
public TextTrackNamespaceContext() {
}
@Override
public String getNamespaceURI(String str) {
if (str.equals("ttml")) {
return "http://www.w3.org/ns/ttml";
}
if (str.equals("smpte")) {
return SMPTETTTrackImpl.SMPTE_TT_NAMESPACE;
}
return null;
}
@Override
public String getPrefix(String str) {
if (str.equals("http://www.w3.org/ns/ttml")) {
return "ttml";
}
if (str.equals(SMPTETTTrackImpl.SMPTE_TT_NAMESPACE)) {
return "smpte";
}
return null;
}
@Override
public Iterator getPrefixes(String str) {
return Arrays.asList("ttml", "smpte").iterator();
}
public TextTrackNamespaceContext(TextTrackNamespaceContext textTrackNamespaceContext) {
this();
}
}
public SMPTETTTrackImpl(File... fileArr) throws IOException, ParserConfigurationException, SAXException, XPathExpressionException {
super(fileArr[0].getName());
this.trackMetaData = new TrackMetaData();
this.sampleDescriptionBox = new p00();
this.XMLSubtitleSampleEntry = new nf0();
this.samples = new ArrayList();
this.subSampleInformationBox = new x00();
this.sampleDurations = new long[fileArr.length];
DocumentBuilderFactory newInstance = DocumentBuilderFactory.newInstance();
newInstance.setNamespaceAware(true);
DocumentBuilder newDocumentBuilder = newInstance.newDocumentBuilder();
TextTrackNamespaceContext textTrackNamespaceContext = null;
long j = 0;
int i = 0;
String str = null;
while (i < fileArr.length) {
final File file = fileArr[i];
x00.a aVar = new x00.a();
this.subSampleInformationBox.getEntries().add(aVar);
aVar.a(1L);
Document parse = newDocumentBuilder.parse(file);
String language = getLanguage(parse);
if (str == null) {
str = language;
} else if (!str.equals(language)) {
throw new RuntimeException("Within one Track all sample documents need to have the same language");
}
XPathFactory newInstance2 = XPathFactory.newInstance();
TextTrackNamespaceContext textTrackNamespaceContext2 = new TextTrackNamespaceContext(textTrackNamespaceContext);
XPath newXPath = newInstance2.newXPath();
newXPath.setNamespaceContext(textTrackNamespaceContext2);
long latestTimestamp = latestTimestamp(parse);
this.sampleDurations[i] = latestTimestamp - j;
NodeList nodeList = (NodeList) newXPath.compile("/ttml:tt/ttml:body/ttml:div/@smpte:backgroundImage").evaluate(parse, XPathConstants.NODESET);
HashMap hashMap = new HashMap();
HashSet hashSet = new HashSet();
for (int i2 = 0; i2 < nodeList.getLength(); i2++) {
hashSet.add(nodeList.item(i2).getNodeValue());
}
ArrayList<String> arrayList = new ArrayList(hashSet);
Collections.sort(arrayList);
int i3 = 1;
for (String str2 : arrayList) {
hashMap.put(str2, "urn:dece:container:subtitleimageindex:" + i3 + str2.substring(str2.lastIndexOf(".")));
i3++;
}
if (!arrayList.isEmpty()) {
final String str3 = new String(streamToByteArray(new FileInputStream(file)));
for (Map.Entry entry : hashMap.entrySet()) {
str3 = str3.replace((CharSequence) entry.getKey(), (CharSequence) entry.getValue());
}
final ArrayList arrayList2 = new ArrayList();
this.samples.add(new Sample() {
@Override
public ByteBuffer asByteBuffer() {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
try {
writeTo(Channels.newChannel(byteArrayOutputStream));
return ByteBuffer.wrap(byteArrayOutputStream.toByteArray());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public long getSize() {
long length = wy.a(str3).length;
for (File file2 : arrayList2) {
length += file2.length();
}
return length;
}
@Override
public void writeTo(WritableByteChannel writableByteChannel) throws IOException {
writableByteChannel.write(ByteBuffer.wrap(wy.a(str3)));
for (File file2 : arrayList2) {
FileInputStream fileInputStream = new FileInputStream(file2);
byte[] bArr = new byte[8096];
while (true) {
int read = fileInputStream.read(bArr);
if (-1 == read) {
break;
}
writableByteChannel.write(ByteBuffer.wrap(bArr, 0, read));
}
}
}
});
x00.a.C0296a c0296a = new x00.a.C0296a();
c0296a.b(wy.b(str3));
aVar.c().add(c0296a);
for (String str4 : arrayList) {
File file2 = new File(file.getParentFile(), str4);
arrayList2.add(file2);
x00.a.C0296a c0296a2 = new x00.a.C0296a();
c0296a2.b(file2.length());
aVar.c().add(c0296a2);
}
} else {
this.samples.add(new Sample() {
@Override
public ByteBuffer asByteBuffer() {
try {
return ByteBuffer.wrap(SMPTETTTrackImpl.this.streamToByteArray(new FileInputStream(file)));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public long getSize() {
return file.length();
}
@Override
public void writeTo(WritableByteChannel writableByteChannel) throws IOException {
Channels.newOutputStream(writableByteChannel).write(SMPTETTTrackImpl.this.streamToByteArray(new FileInputStream(file)));
}
});
}
i++;
j = latestTimestamp;
textTrackNamespaceContext = null;
}
this.trackMetaData.setLanguage(Iso639.convert2to3(str));
this.XMLSubtitleSampleEntry.c(SMPTE_TT_NAMESPACE);
this.XMLSubtitleSampleEntry.d(SMPTE_TT_NAMESPACE);
if (this.containsImages) {
this.XMLSubtitleSampleEntry.a("image/png");
} else {
this.XMLSubtitleSampleEntry.a("");
}
this.sampleDescriptionBox.addBox(this.XMLSubtitleSampleEntry);
this.trackMetaData.setTimescale(30000L);
this.trackMetaData.setLayer(65535);
}
public static long earliestTimestamp(Document document) {
XPathFactory newInstance = XPathFactory.newInstance();
TextTrackNamespaceContext textTrackNamespaceContext = new TextTrackNamespaceContext(null);
XPath newXPath = newInstance.newXPath();
newXPath.setNamespaceContext(textTrackNamespaceContext);
try {
NodeList nodeList = (NodeList) newXPath.compile("//*[@begin]").evaluate(document, XPathConstants.NODESET);
long j = 0;
for (int i = 0; i < nodeList.getLength(); i++) {
j = Math.min(toTime(nodeList.item(i).getAttributes().getNamedItem("begin").getNodeValue()), j);
}
return j;
} catch (XPathExpressionException e) {
throw new RuntimeException(e);
}
}
public static String getLanguage(Document document) {
return document.getDocumentElement().getAttribute("xml:lang");
}
public static long latestTimestamp(Document document) {
long time;
XPathFactory newInstance = XPathFactory.newInstance();
TextTrackNamespaceContext textTrackNamespaceContext = new TextTrackNamespaceContext(null);
XPath newXPath = newInstance.newXPath();
newXPath.setNamespaceContext(textTrackNamespaceContext);
try {
NodeList nodeList = (NodeList) newXPath.compile("//*[@begin]").evaluate(document, XPathConstants.NODESET);
long j = 0;
for (int i = 0; i < nodeList.getLength(); i++) {
Node item = nodeList.item(i);
String nodeValue = item.getAttributes().getNamedItem("begin").getNodeValue();
if (item.getAttributes().getNamedItem("dur") != null) {
time = toTime(nodeValue) + toTime(item.getAttributes().getNamedItem("dur").getNodeValue());
} else if (item.getAttributes().getNamedItem(WXGesture.END) != null) {
time = toTime(item.getAttributes().getNamedItem(WXGesture.END).getNodeValue());
} else {
throw new RuntimeException("neither end nor dur attribute is present");
}
j = Math.max(time, j);
}
return j;
} catch (XPathExpressionException e) {
throw new RuntimeException(e);
}
}
public byte[] streamToByteArray(InputStream inputStream) throws IOException {
byte[] bArr = new byte[8096];
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
while (true) {
int read = inputStream.read(bArr);
if (-1 == read) {
return byteArrayOutputStream.toByteArray();
}
byteArrayOutputStream.write(bArr, 0, read);
}
}
public static long toTime(String str) {
Matcher matcher = Pattern.compile("([0-9][0-9]):([0-9][0-9]):([0-9][0-9])([\\.:][0-9][0-9]?[0-9]?)?").matcher(str);
if (matcher.matches()) {
String group = matcher.group(1);
String group2 = matcher.group(2);
String group3 = matcher.group(3);
String group4 = matcher.group(4);
if (group4 == null) {
group4 = ".000";
}
String replace = group4.replace(":", ".");
return (long) ((Long.parseLong(group) * 60 * 60 * 1000) + (Long.parseLong(group2) * 60 * 1000) + (Long.parseLong(group3) * 1000) + (Double.parseDouble("0" + replace) * 1000.0d));
}
throw new RuntimeException("Cannot match " + str + " to time expression");
}
@Override
public void close() throws IOException {
}
@Override
public String getHandler() {
return "subt";
}
@Override
public p00 getSampleDescriptionBox() {
return this.sampleDescriptionBox;
}
@Override
public long[] getSampleDurations() {
long[] jArr = new long[this.sampleDurations.length];
for (int i = 0; i < jArr.length; i++) {
jArr[i] = (this.sampleDurations[i] * this.trackMetaData.getTimescale()) / 1000;
}
return jArr;
}
@Override
public List<Sample> getSamples() {
return this.samples;
}
@Override
public x00 getSubsampleInformationBox() {
return this.subSampleInformationBox;
}
@Override
public TrackMetaData getTrackMetaData() {
return this.trackMetaData;
}
}