正在查看: Hyouka private v5.8.9 应用的 SMPTETTTrackImpl.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Hyouka private v5.8.9 应用的 SMPTETTTrackImpl.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.googlecode.mp4parser.authoring.tracks;
import com.beint.project.core.utils.Constants;
import com.coremedia.iso.Utf8;
import com.coremedia.iso.boxes.SampleDescriptionBox;
import com.coremedia.iso.boxes.SubSampleInformationBox;
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 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 k9.a;
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";
a XMLSubtitleSampleEntry;
boolean containsImages;
SampleDescriptionBox sampleDescriptionBox;
private long[] sampleDurations;
List<Sample> samples;
SubSampleInformationBox subSampleInformationBox;
TrackMetaData trackMetaData;
private static class TextTrackNamespaceContext implements NamespaceContext {
private TextTrackNamespaceContext() {
}
TextTrackNamespaceContext(TextTrackNamespaceContext textTrackNamespaceContext) {
this();
}
@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 SMPTETTTrackImpl(File... fileArr) throws IOException, ParserConfigurationException, SAXException, XPathExpressionException {
super(fileArr[0].getName());
int i2;
this.trackMetaData = new TrackMetaData();
this.sampleDescriptionBox = new SampleDescriptionBox();
this.XMLSubtitleSampleEntry = new a();
this.samples = new ArrayList();
this.subSampleInformationBox = new SubSampleInformationBox();
this.sampleDurations = new long[fileArr.length];
DocumentBuilderFactory newInstance = DocumentBuilderFactory.newInstance();
newInstance.setNamespaceAware(true);
DocumentBuilder newDocumentBuilder = newInstance.newDocumentBuilder();
long j2 = 0;
TextTrackNamespaceContext textTrackNamespaceContext = null;
String str = null;
int i3 = 0;
while (i3 < fileArr.length) {
final File file = fileArr[i3];
SubSampleInformationBox.SubSampleEntry subSampleEntry = new SubSampleInformationBox.SubSampleEntry();
this.subSampleInformationBox.getEntries().add(subSampleEntry);
subSampleEntry.setSampleDelta(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[i3] = latestTimestamp - j2;
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 i4 = 0; i4 < nodeList.getLength(); i4++) {
hashSet.add(nodeList.item(i4).getNodeValue());
}
ArrayList<String> arrayList = new ArrayList(hashSet);
Collections.sort(arrayList);
int i5 = 1;
for (String str2 : arrayList) {
hashMap.put(str2, "urn:dece:container:subtitleimageindex:" + i5 + str2.substring(str2.lastIndexOf(".")));
i5++;
i3 = i3;
}
if (arrayList.isEmpty()) {
i2 = i3;
this.samples.add(new Sample() {
@Override
public ByteBuffer asByteBuffer() {
try {
return ByteBuffer.wrap(SMPTETTTrackImpl.this.streamToByteArray(new FileInputStream(file)));
} catch (IOException e2) {
throw new RuntimeException(e2);
}
}
@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)));
}
});
} else {
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 e2) {
throw new RuntimeException(e2);
}
}
@Override
public long getSize() {
long length = Utf8.convert(str3).length;
Iterator it = arrayList2.iterator();
while (it.hasNext()) {
length += ((File) it.next()).length();
}
return length;
}
@Override
public void writeTo(WritableByteChannel writableByteChannel) throws IOException {
writableByteChannel.write(ByteBuffer.wrap(Utf8.convert(str3)));
Iterator it = arrayList2.iterator();
while (it.hasNext()) {
FileInputStream fileInputStream = new FileInputStream((File) it.next());
byte[] bArr = new byte[8096];
while (true) {
int read = fileInputStream.read(bArr);
if (-1 == read) {
break;
} else {
writableByteChannel.write(ByteBuffer.wrap(bArr, 0, read));
}
}
}
}
});
SubSampleInformationBox.SubSampleEntry.SubsampleEntry subsampleEntry = new SubSampleInformationBox.SubSampleEntry.SubsampleEntry();
i2 = i3;
subsampleEntry.setSubsampleSize(Utf8.utf8StringLengthInBytes(str3));
subSampleEntry.getSubsampleEntries().add(subsampleEntry);
Iterator it = arrayList.iterator();
while (it.hasNext()) {
File file2 = new File(file.getParentFile(), (String) it.next());
arrayList2.add(file2);
SubSampleInformationBox.SubSampleEntry.SubsampleEntry subsampleEntry2 = new SubSampleInformationBox.SubSampleEntry.SubsampleEntry();
subsampleEntry2.setSubsampleSize(file2.length());
subSampleEntry.getSubsampleEntries().add(subsampleEntry2);
}
}
i3 = i2 + 1;
j2 = latestTimestamp;
textTrackNamespaceContext = null;
}
this.trackMetaData.setLanguage(Iso639.convert2to3(str));
this.XMLSubtitleSampleEntry.b(SMPTE_TT_NAMESPACE);
this.XMLSubtitleSampleEntry.c(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 j2 = 0;
for (int i2 = 0; i2 < nodeList.getLength(); i2++) {
j2 = Math.min(toTime(nodeList.item(i2).getAttributes().getNamedItem("begin").getNodeValue()), j2);
}
return j2;
} catch (XPathExpressionException e2) {
throw new RuntimeException(e2);
}
}
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 j2 = 0;
for (int i2 = 0; i2 < nodeList.getLength(); i2++) {
Node item = nodeList.item(i2);
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("end") == null) {
throw new RuntimeException("neither end nor dur attribute is present");
}
time = toTime(item.getAttributes().getNamedItem("end").getNodeValue());
}
j2 = Math.max(time, j2);
}
return j2;
} catch (XPathExpressionException e2) {
throw new RuntimeException(e2);
}
}
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);
}
}
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()) {
throw new RuntimeException("Cannot match " + str + " to time expression");
}
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(Constants.P2P_ABORT_STRING + replace) * 1000.0d));
}
@Override
public void close() throws IOException {
}
@Override
public String getHandler() {
return "subt";
}
@Override
public SampleDescriptionBox getSampleDescriptionBox() {
return this.sampleDescriptionBox;
}
@Override
public long[] getSampleDurations() {
int length = this.sampleDurations.length;
long[] jArr = new long[length];
for (int i2 = 0; i2 < length; i2++) {
jArr[i2] = (this.sampleDurations[i2] * this.trackMetaData.getTimescale()) / 1000;
}
return jArr;
}
@Override
public List<Sample> getSamples() {
return this.samples;
}
@Override
public SubSampleInformationBox getSubsampleInformationBox() {
return this.subSampleInformationBox;
}
@Override
public TrackMetaData getTrackMetaData() {
return this.trackMetaData;
}
}