trunk contents moved to root

This commit is contained in:
Jindra Petřík
2014-05-10 20:50:57 +02:00
parent 1b851e66a8
commit 199a4d0c2b
2296 changed files with 0 additions and 0 deletions
@@ -0,0 +1,73 @@
/*
* Copyright (C) 2010-2014 JPEXS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.flv;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
/**
*
* @author JPEXS
*/
public class AUDIODATA extends DATA {
public static final int SOUNDFORMAT_UNCOMPRESSED_NE = 0;
public static final int SOUNDFORMAT_ADPCM = 1;
public static final int SOUNDFORMAT_MP3 = 2;
public static final int SOUNDFORMAT_UNCOMPRESSED_LE = 3;
public static final int SOUNDFORMAT_NELLYMOSER_16 = 4;
public static final int SOUNDFORMAT_NELLYMOSER_8 = 5;
public static final int SOUNDFORMAT_NELLYMOSER = 6;
public static final int SOUNDFORMAT_SPEEX = 11;
public static final int SOUNDRATE_5K5 = 0;
public static final int SOUNDRATE_11K = 1;
public static final int SOUNDRATE_22K = 2;
public static final int SOUNDRATE_44K = 3;
public static final int SOUNDSIZE_8BIT = 0;
public static final int SOUNDSIZE_16BIT = 1;
public static final int SOUNDTYPE_MONO = 0;
public static final int SOUNDTYPE_STEREO = 1;
public int soundFormat;
public int soundRate;
public boolean soundSize;
public boolean soundType;
public byte[] soundData;
public AUDIODATA(int soundFormat, int soundRate, boolean soundSize, boolean soundType, byte[] soundData) {
this.soundFormat = soundFormat;
this.soundRate = soundRate;
this.soundSize = soundSize;
this.soundType = soundType;
this.soundData = soundData;
}
@Override
public byte[] getBytes() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
FLVOutputStream flv = new FLVOutputStream(baos);
flv.writeUB(4, soundFormat);
flv.writeUB(2, soundRate);
flv.writeUB(1, soundSize ? 1 : 0);
flv.writeUB(1, soundType ? 1 : 0);
flv.write(soundData);
} catch (IOException ex) {
//ignore
}
return baos.toByteArray();
}
}
@@ -0,0 +1,26 @@
/*
* Copyright (C) 2010-2014 JPEXS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.flv;
/**
*
* @author JPEXS
*/
public abstract class DATA {
public abstract byte[] getBytes();
}
@@ -0,0 +1,262 @@
/*
* Copyright (C) 2010-2014 JPEXS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.flv;
import com.jpexs.helpers.utf8.Utf8Helper;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
/**
*
* @author JPEXS
*/
public class FLVOutputStream extends OutputStream {
private final OutputStream os;
private int bitPos = 0;
private int tempByte = 0;
private long pos = 0;
public FLVOutputStream(OutputStream os) {
this.os = os;
}
public long getPos() {
return pos;
}
/**
* Writes byte to the stream
*
* @param b byte to write
* @throws IOException
*/
@Override
public void write(int b) throws IOException {
alignByte();
os.write(b);
pos++;
}
private void alignByte() throws IOException {
if (bitPos > 0) {
bitPos = 0;
write(tempByte);
tempByte = 0;
}
}
/**
* Writes UI8 (Unsigned 8bit integer) value to the stream
*
* @param val UI8 value to write
* @throws IOException
*/
public void writeUI8(int val) throws IOException {
write(val);
}
/**
* Writes UI24 (Unsigned 24bit integer) value to the stream
*
* @param value UI32 value
* @throws IOException
*/
public void writeUI24(long value) throws IOException {
write((int) ((value >> 16) & 0xff));
write((int) ((value >> 8) & 0xff));
write((int) (value & 0xff));
}
/**
* Writes UI32 (Unsigned 32bit integer) value to the stream
*
* @param value UI32 value
* @throws IOException
*/
public void writeUI32(long value) throws IOException {
write((int) ((value >> 24) & 0xff));
write((int) ((value >> 16) & 0xff));
write((int) ((value >> 8) & 0xff));
write((int) (value & 0xff));
}
/**
* Writes UI16 (Unsigned 16bit integer) value to the stream
*
* @param value UI16 value
* @throws IOException
*/
public void writeUI16(int value) throws IOException {
write((int) ((value >> 8) & 0xff));
write((int) (value & 0xff));
}
/**
* Writes UB[nBits] (Unsigned-bit value) value to the stream
*
* @param nBits Number of bits which represent value
* @param value Unsigned value to write
* @throws IOException
*/
public void writeUB(int nBits, long value) throws IOException {
for (int bit = 0; bit < nBits; bit++) {
int nb = (int) ((value >> (nBits - 1 - bit)) & 1);
tempByte += nb * (1 << (7 - bitPos));
bitPos++;
if (bitPos == 8) {
bitPos = 0;
write(tempByte);
tempByte = 0;
}
}
}
public void writeHeader(boolean audio, boolean video) throws IOException {
write("FLV".getBytes());
write(1); //version
writeUB(5, 0); //must be 0
writeUB(1, audio ? 1 : 0); //audio present
writeUB(1, 0); //reserved
writeUB(1, video ? 1 : 0); //video present
writeUI32(9); //header size
writeUI32(0);
}
public void writeTag(FLVTAG tag) throws IOException {
long posBefore = getPos();
writeUI8(tag.tagType);
byte[] data = tag.data.getBytes();
writeUI24(data.length);
writeUI24(tag.timeStamp & 0xffffff);
writeUI8((int) ((tag.timeStamp >> 24) & 0xff));
writeUI24(0);
write(data); //codecId 4, frameType 1
long posAfter = getPos();
long size = posAfter - posBefore;
writeUI32(size);
}
public void writeSCRIPTDATASTRING(String s) throws IOException {
byte[] bytes = Utf8Helper.getBytes(s);
writeUI16(bytes.length);
write(bytes);
}
public void writeSCRIPTDATALONGSTRING(String s) throws IOException {
byte[] bytes = Utf8Helper.getBytes(s);
writeUI32(bytes.length);
write(bytes);
}
private void writeLong(long value) throws IOException {
byte[] writeBuffer = new byte[8];
writeBuffer[3] = (byte) (value >>> 56);
writeBuffer[2] = (byte) (value >>> 48);
writeBuffer[1] = (byte) (value >>> 40);
writeBuffer[0] = (byte) (value >>> 32);
writeBuffer[7] = (byte) (value >>> 24);
writeBuffer[6] = (byte) (value >>> 16);
writeBuffer[5] = (byte) (value >>> 8);
writeBuffer[4] = (byte) (value);
write(writeBuffer);
}
public void writeDOUBLE(double value) throws IOException {
writeLong(Double.doubleToLongBits(value));
}
public void writeSCRIPTDATAOBJECT(SCRIPTDATAOBJECT o) throws IOException {
writeSCRIPTDATASTRING(o.objectName);
writeSCRIPTDATAVALUE(o.objectData);
}
public void writeSCRIPTDATAVARIABLE(SCRIPTDATAVARIABLE v) throws IOException {
writeSCRIPTDATASTRING(v.variableName);
writeSCRIPTDATAVALUE(v.variableData);
}
public void writeSCRIPTDATAVALUE(SCRIPTDATAVALUE v) throws IOException {
writeUI8(v.type);
switch (v.type) {
case 0:
writeDOUBLE((double) (Double) v.value);
break;
case 1:
writeUI8((boolean) (Boolean) v.value ? 1 : 0);
break;
case 2:
writeSCRIPTDATASTRING((String) v.value);
break;
case 3:
@SuppressWarnings("unchecked") List<SCRIPTDATAOBJECT> objects = (List<SCRIPTDATAOBJECT>) v.value;
for (SCRIPTDATAOBJECT o : objects) {
writeSCRIPTDATAOBJECT(o);
}
writeUI24(9);//SCRIPTDATAOBJECTEND
break;
case 4:
writeSCRIPTDATASTRING((String) v.value);
break;
case 5:
//null
break;
case 6:
//undefined
break;
case 7:
writeUI16((int) (Integer) v.value);
break;
case 8:
@SuppressWarnings("unchecked") List<SCRIPTDATAVARIABLE> variables = (List<SCRIPTDATAVARIABLE>) v.value;
writeUI32(variables.size());
for (SCRIPTDATAVARIABLE var : variables) {
writeSCRIPTDATAVARIABLE(var);
}
writeUI24(9);//SCRIPTDATAVARIABLEEND
break;
case 9:
//reserved
break;
case 10:
@SuppressWarnings("unchecked") List<SCRIPTDATAVARIABLE> stvariables = (List<SCRIPTDATAVARIABLE>) v.value;
writeUI32(stvariables.size());
for (SCRIPTDATAVARIABLE var : stvariables) {
writeSCRIPTDATAVARIABLE(var);
}
break;
case 11:
writeSCRIPTDATADATE((SCRIPTDATADATE) v.value);
break;
case 12:
writeSCRIPTDATALONGSTRING((String) v.value);
break;
}
}
public void writeSI16(int value) throws IOException {
writeUI16(value);
}
public void writeSCRIPTDATADATE(SCRIPTDATADATE d) throws IOException {
writeDOUBLE(d.dateTime);
writeSI16(d.localDateTimeOffset);
}
}
@@ -0,0 +1,48 @@
/*
* Copyright (C) 2010-2014 JPEXS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.flv;
/**
*
* @author JPEXS
*/
public class FLVTAG {
public int tagType;
public long timeStamp;
public DATA data;
public static final int DATATYPE_VIDEO = 9;
public static final int DATATYPE_AUDIO = 8;
public static final int DATATYPE_SCRIPT_DATA = 18;
public FLVTAG(long timeStamp, SCRIPTDATA data) {
tagType = DATATYPE_SCRIPT_DATA;
this.data = data;
}
public FLVTAG(long timeStamp, VIDEODATA data) {
this.tagType = DATATYPE_VIDEO;
this.timeStamp = timeStamp;
this.data = data;
}
public FLVTAG(long timeStamp, AUDIODATA data) {
this.tagType = DATATYPE_AUDIO;
this.timeStamp = timeStamp;
this.data = data;
}
}
@@ -0,0 +1,72 @@
/*
* Copyright (C) 2010-2014 JPEXS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.flv;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author JPEXS
*/
public class SCRIPTDATA extends DATA {
public List<SCRIPTDATAOBJECT> data;
public SCRIPTDATA(List<SCRIPTDATAOBJECT> data) {
this.data = data;
}
@Override
public byte[] getBytes() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (FLVOutputStream fos = new FLVOutputStream(baos)) {
for (SCRIPTDATAOBJECT d : data) {
fos.writeSCRIPTDATAOBJECT(d);
}
fos.writeUI24(9); //SCRIPTDATAOBJECTEND
} catch (IOException ex) {
Logger.getLogger(SCRIPTDATA.class.getName()).log(Level.SEVERE, "i/o error", ex);
}
return baos.toByteArray();
}
public static SCRIPTDATA onMetaData(double duration, double width, double height, double videodatarate, double framerate, double videocodecid, double audiosamplerate, double audiosamplesize, boolean stereo, double audiocodecid, double filesize) {
List<SCRIPTDATAOBJECT> list = new ArrayList<>();
List<SCRIPTDATAVARIABLE> values = new ArrayList<>();
values.add(new SCRIPTDATAVARIABLE("duration", new SCRIPTDATAVALUE(duration)));
values.add(new SCRIPTDATAVARIABLE("width", new SCRIPTDATAVALUE(width)));
values.add(new SCRIPTDATAVARIABLE("height", new SCRIPTDATAVALUE(height)));
values.add(new SCRIPTDATAVARIABLE("videodatarate", new SCRIPTDATAVALUE(videodatarate)));
values.add(new SCRIPTDATAVARIABLE("framerate", new SCRIPTDATAVALUE(framerate)));
values.add(new SCRIPTDATAVARIABLE("videocodecid", new SCRIPTDATAVALUE(videocodecid)));
values.add(new SCRIPTDATAVARIABLE("audiosamplerate", new SCRIPTDATAVALUE(audiosamplerate)));
values.add(new SCRIPTDATAVARIABLE("audiosamplesize", new SCRIPTDATAVALUE(audiosamplesize)));
values.add(new SCRIPTDATAVARIABLE("stereo", new SCRIPTDATAVALUE(stereo)));
values.add(new SCRIPTDATAVARIABLE("audiocodecid", new SCRIPTDATAVALUE(audiocodecid)));
values.add(new SCRIPTDATAVARIABLE("filesize", new SCRIPTDATAVALUE(filesize)));
SCRIPTDATAVALUE valuesList = new SCRIPTDATAVALUE(8, values);
SCRIPTDATAOBJECT metaData = new SCRIPTDATAOBJECT("onMetaData", valuesList);
list.add(metaData);
SCRIPTDATA ret = new SCRIPTDATA(list);
return ret;
}
}
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2010-2014 JPEXS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.flv;
/**
*
* @author JPEXS
*/
public class SCRIPTDATADATE {
public double dateTime;
public int localDateTimeOffset;
public SCRIPTDATADATE(double dateTime, int localDateTimeOffset) {
this.dateTime = dateTime;
this.localDateTimeOffset = localDateTimeOffset;
}
}
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2010-2014 JPEXS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.flv;
/**
*
* @author JPEXS
*/
public class SCRIPTDATAOBJECT {
public String objectName;
public SCRIPTDATAVALUE objectData;
public SCRIPTDATAOBJECT(String objectName, SCRIPTDATAVALUE objectData) {
this.objectName = objectName;
this.objectData = objectData;
}
}
@@ -0,0 +1,42 @@
/*
* Copyright (C) 2010-2014 JPEXS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.flv;
/**
*
* @author JPEXS
*/
public class SCRIPTDATAVALUE {
public int type;
public Object value;
public SCRIPTDATAVALUE(int type, Object value) {
this.type = type;
this.value = value;
}
public SCRIPTDATAVALUE(boolean b) {
this.value = (Boolean) b;
type = 1;
}
public SCRIPTDATAVALUE(double d) {
this.value = (Double) d;
type = 0;
}
}
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2010-2014 JPEXS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.flv;
/**
*
* @author JPEXS
*/
public class SCRIPTDATAVARIABLE {
public String variableName;
public SCRIPTDATAVALUE variableData;
public SCRIPTDATAVARIABLE(String variableName, SCRIPTDATAVALUE variableData) {
this.variableName = variableName;
this.variableData = variableData;
}
}
@@ -0,0 +1,51 @@
/*
* Copyright (C) 2010-2014 JPEXS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.flv;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
/**
*
* @author JPEXS
*/
public class VIDEODATA extends DATA {
public int frameType;
public int codecId;
public byte[] videoData;
public VIDEODATA(int frameType, int codecId, byte[] videoData) {
this.frameType = frameType;
this.codecId = codecId;
this.videoData = videoData;
}
@Override
public byte[] getBytes() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
FLVOutputStream flv = new FLVOutputStream(baos);
flv.writeUB(4, frameType);
flv.writeUB(4, codecId);
flv.write(videoData);
} catch (IOException ex) {
//ignore
}
return baos.toByteArray();
}
}