📄 ts.java
字号:
return firstID;
}
//DM09082004 081.7 int08 changed
public void setfirstID()
{
firstID = 0xE0;
pmtPCR[2] = (byte)firstID;
updateHeader(23, firstID);
}
// PAT with section 0 and SID = 0x102, PMT = 0x100 , CRC32
private static byte[] pat1 = {
0x47,0x40,0,0x10,
0, 0, (byte)0xB0, 0xd, 0, 1, 1, 0, 0, 1, 2, (byte)0xE1, 0,
(byte)0x8f, (byte)0xa5, 0x26, (byte)0xcf,
};
// counter shall not be updated in PCR only paket (but do it), 42bits for PCR
private static byte pcr1[] = {
0x47,0,(byte)0xe0,0x20,
(byte)0xB7,0x10,0,0,0,0,0,0
};
private static byte ttx[] = {
0x47,0x40,(byte)0x9F,0x10,
0,0,1,(byte)0xBD,0,(byte)0xB2,(byte)0x84,(byte)0x80,0x24,
(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,
(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,
(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,
(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,
(byte)0xFF,
0x10,
// 022C E7E4 40A8 A8CE A80B A80B 7A40
2,44,-25,-28,64,-88,-88,-50,-88,11,-88,11,122,64,
38,-50,117,87,-122,79,4,42,-53,-75,-110,118,103,-9,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
// 022C E8E4 40D9
2,44,-24,-28,64,-39,
// l i n e 2 2 :
4,55,-105,118,-89,4,76,76, 4,107,67,-110,4,-116,-12,28,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
// 022C E9E4 E3D9
2,44,-23,-28,-29,-39,
// line 23 PTS
4,55,-105,118,-89,4,76,-51, 4,107,67,-110,4,-116,-12,-99,4,11,42,-53,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4
};
//DM26052004 081.7 int03 changed
public byte[] getTTX(byte[] data, String pts)
{
byte[] tPTS = pts.getBytes();
for (int a=0; a < tPTS.length; a++)
tPTS[a] = Teletext.bytereverse(Teletext.parity(tPTS[a]));
System.arraycopy(tPTS, 0, ttx, 169, tPTS.length);
System.arraycopy(data, 9, ttx, 13, 5);
ttx[13] &= ~0x10;
ttx[3] = (byte)(0x10 | (0xF & (count3++)));
return ttx;
}
public byte[] getPmt()
{
pmt[3] = (byte)(0x10 | (0xf & (count1++)));
return pmt;
}
public byte[] getPat()
{
pat[3] = (byte)(0x10 | (0xf & (count2++)));
return pat;
}
public byte[] getPCR(long pts, int count, int PCRPid)
{
/* Construct the PCR, PTS-55000 (2ms) 1Bit ~ 3Ticks (counter) */
pcr[2] = (byte)(PCRPid);
pcr[3] = (byte)(0x20 | (0xF & count));
pcr[6] = (byte)(0xFF & pts>>>25);
pcr[7] = (byte)(0xFF & pts>>>17);
pcr[8] = (byte)(0xFF & pts>>>9);
pcr[9] = (byte)(0xFF & pts>>>1);
pcr[10] = (byte)((1 & pts) << 7 );
/* PCR ext is 0, byte10+byte11 */
return pcr;
}
//DM09082004 081.7 int08 changed
public byte[] init(String name, boolean ac3, boolean myTTX, int mode)
{
count1 = count2 = count3 = 0;
TS.myTTX = myTTX;
java.util.Arrays.fill(pat, (byte)0xff);
java.util.Arrays.fill(pmt, (byte)0xff);
java.util.Arrays.fill(pcr, (byte)0xff);
System.arraycopy(pmt1, 0, pmt, 0, pmt1.length);
System.arraycopy(pat1, 0, pat, 0, pat1.length);
System.arraycopy(pcr1, 0, pcr, 0, pcr1.length);
switch (mode)
{
case 1:
return initTF4000header(name, ac3);
case 2:
return initTF5000header(name, ac3);
}
return (new byte[0]);
}
//DM09082004 081.7 int08 outsourced from X ++
private void updateHeader(int pos, int val)
{
//only last 8 bits used
TF4000header[pos] = (byte)val;
TF5000header[pos] = (byte)val;
}
public static String updateAdditionalHeader(String old_name, long time[], int mode) throws IOException
{
String new_name = "";
switch (mode)
{
case 0:
return old_name;
case 1:
new_name = old_name.substring(0, old_name.length() - 3) + ".raw";
if (new File(new_name).exists())
new File(new_name).delete();
Common.renameTo(old_name, new_name); //DM13042004 081.7 int01 changed
finishTF4000header(new_name, time);
break;
case 2:
new_name = old_name.substring(0, old_name.length() - 3) + ".rec";
if (new File(new_name).exists())
new File(new_name).delete();
Common.renameTo(old_name, new_name);
finishTF5000header(new_name, time);
break;
}
return new_name;
}
private static void finishTF4000header(String name, long time[]) throws IOException
{
long event[] = new long[4];
long millis = (time[1] - time[0]) / 90L;
short minutes = (short)(0xFFFF & (Math.round(millis / 60000f)));
event[0] = System.currentTimeMillis();
event[1] = event[0] - millis;
event[2] = (event[0] / 86400000L) + 40587;
event[3] = (event[1] / 86400000L) + 40587;
java.util.Calendar datum = java.util.Calendar.getInstance();
datum.setTime(new java.util.Date(event[0]));
RandomAccessFile ts = new RandomAccessFile(name, "rw");
ts.seek(0);
ts.writeShort((short)event[2]);
ts.writeByte((byte)datum.get(11));
ts.writeByte((byte)datum.get(12));
ts.writeShort((short)event[2]);
ts.writeByte((byte)datum.get(11));
ts.writeByte((byte)datum.get(12));
ts.writeShort(minutes);
ts.seek(0x44);
ts.writeShort((short)event[2]);
ts.writeByte((byte)datum.get(11));
ts.writeByte((byte)datum.get(12));
ts.writeShort(minutes);
datum.setTime(new java.util.Date(event[1]));
ts.seek(0x40);
ts.writeShort((short)event[3]);
ts.writeByte((byte)datum.get(11));
ts.writeByte((byte)datum.get(12));
ts.close();
}
//introduced by 'catapult' 09082004
private static void finishTF5000header(String name, long time[]) throws IOException
{
long event[] = new long[4];
long millis = (time[1] - time[0]) / 90L;
short minutes = (short)(0xFFFF & (Math.round(millis / 60000f)));
event[0] = System.currentTimeMillis();
event[1] = event[0] - millis;
event[2] = (event[0] / 86400000L) + 40587;
event[3] = (event[1] / 86400000L) + 40587;
java.util.Calendar datum = java.util.Calendar.getInstance();
datum.setTime(new java.util.Date(event[0]));
RandomAccessFile ts = new RandomAccessFile(name, "rw");
ts.seek(0x08);
ts.writeShort(minutes);
ts.seek(0x46);
ts.writeShort(minutes);
ts.seek(0x50);
ts.writeShort((short)event[2]);
ts.writeByte((byte)datum.get(11));
ts.writeByte((byte)datum.get(12));
datum.setTime(new java.util.Date(event[1]));
ts.seek(0x4c);
ts.writeShort((short)event[3]);
ts.writeByte((byte)datum.get(11));
ts.writeByte((byte)datum.get(12));
ts.close();
}
private byte[] initTF4000header(String name, boolean ac3)
{
byte header[] = new byte[564]; //TF4000
System.arraycopy(TF4000header, 0, header, 0, TF4000header.length);
byte file_name[] = new File(name).getName().getBytes();
header[75] = (byte)(file_name.length - 3);
System.arraycopy(file_name, 0, header, 76, file_name.length - 3);
if (ac3)
{
header[26] = 0;
header[27] = (byte)0x80; // set 1. AC3 PID as main TFaudio
}
else
{
header[26] = 0; //DM14062004 081.7 int04 changed
header[27] = (byte)0xC0;
}
return header;
}
private byte[] initTF5000header(String name, boolean ac3)
{
byte header[] = new byte[1316]; //TF5000
System.arraycopy(TF5000header, 0, header, 0, TF5000header.length);
byte file_name[] = new File(name).getName().getBytes();
header[75] = (byte)(file_name.length - 3);
System.arraycopy(file_name, 0, header, 76, file_name.length - 3);
if (ac3)
{
header[26] = 0;
header[27] = (byte)0x80; // set 1. AC3 PID as main TFaudio
}
else
{
header[26] = 0; //DM14062004 081.7 int04 changed
header[27] = (byte)0xC0; //MPA
}
return header;
}
//DM09082004 081.7 int08 outsourced from X --
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -