2024年2月8日发(作者:)
import yout;import nfo;import ;import gle;import ;import t;import Event;import Listener;import pter;import nt;import dapter;import vent;import istener;import edImage;import rayInputStream;import rayOutputStream;import ble;import ;import ption;import AccessFile;import ffer;import ByteBuffer;import annel;import e;import ist;import ;import ;import ngQueue;import orService;import ors;import BlockingQueue;import ledExecutorService;import it;import ry;
private String currentFilePath;public MainFrame() {setUndecorated(true);setSize(WIDTH, HEIGHT);Toolkit tk = aultToolkit();screenSize = eenSize();setLocation((int) th() - WIDTH, (int) (ght() -eenInsets(getGraphicsConfiguration()).bottom - HEIGHT));MouseListener buttonMouseListener = new MouseAdapter() {public void mouseEntered(MouseEvent e) {JButton btn = (JButton) rce();if(led()) {kground(BUTTON_FOCUS_COLOR);}}public void mouseExited(MouseEvent e) {JButton btn = (JButton) rce();if(led()) {kground(BUTTON_COLOR);}}};seListener(buttonMouseListener);seListener(buttonMouseListener);seListener(buttonMouseListener);seListener(buttonMouseListener);seListener(buttonMouseListener);seListener(buttonMouseListener);ChangeListener changeListener = new ChangeListener() {public void stateChanged(ChangeEvent e) {JButton btn = (JButton) rce();if(led()) {kground(BUTTON_COLOR);} else {
kground(BUTTON_DISABLE_COLOR);}}};ngeListener(changeListener);ngeListener(changeListener);ngeListener(changeListener);ngeListener(changeListener);ngeListener(changeListener);t(BUTTON_FONT);t(BUTTON_FONT);t(BUTTON_FONT);t(BUTTON_FONT);t(BUTTON_FONT);t(BUTTON_FONT);kground(BUTTON_COLOR);kground(BUTTON_DISABLE_COLOR);kground(BUTTON_DISABLE_COLOR);kground(BUTTON_DISABLE_COLOR);kground(BUTTON_DISABLE_COLOR);kground(BUTTON_COLOR);bled(false);bled(false);bled(false);bled(false);ionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {bled(false);bled(true);bled(true);bled(false);currentFilePath = DEFAULT_FILE_PATH tTimeMillis();(currentFilePath);}
});ionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {bled(false);bled(true);bled(false);();}});ionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {bled(true);bled(false);bled(true);t();}});ionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {bled(true);bled(false);bled(false);bled(true);();}});ionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {setVisible(false);new PlayerFrame();}});ionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {
(0);}});setLayout(new GridLayout(2, 3));add(start);add(pause);add(restart);add(stop);add(play);add(close);setVisible(true);}class PlayerFrame extends JFrame {private MyVideo mv;private final ExecutorService player;private volatile BufferedImage lastImage;public PlayerFrame() {player = gleThreadExecutor();e(new Runnable() {public void run() {mv = new MyVideo(new File(currentFilePath), false, (byte) 0);on(0);}});e(new Runnable() {public void run() {for(;;) {Object[] data = ame();if(0 == ) {wn();();dispose();ible(true);bled(true);
return;}lastImage = (BufferedImage) data[0];repaint();byte[] audioData = (byte[]) data[1];ata(audioData);}}});setUndecorated(true);setBounds((int) (th() / 8), (int) (ght() / 8), (int) (th() / 4 * 3), (int)(ght() / 4 * 3));final JPanel canvas = new JPanel() {protected void paintComponent(Graphics g) {omponent(g);if(null != lastImage) {int w = th();int h = ght();if(w * getHeight() > h * getWidth()) {age(lastImage, 0, (int) (getHeight() - getWidth() * 1.0 / w * h) / 2, getWidth(), (int) (getWidth() * 1.0 / w * h), null);} else {age(lastImage, (int) (getWidth() - getHeight() * 1.0 / h * w) / 2, 0, (int) (getHeight() * 1.0 / h * w), getHeight(), null);}}Point mouseLocation = nterInfo().getLocation();if(new Rectangle(ation().x, ation().y getHeight() - 70, getWidth(),50).contains(mouseLocation)) {Color c = or();or(new Color(0, 0, 100, 60));3DRect(0, getHeight() - 70, getWidth(), 50, true);or(new Color(97, 211, 225, 120));3DRect(mouseLocation.x - () - 1, getHeight() - 70, 3, 50, true);3DRect(0, getHeight() - 70, on() * getWidth() / (), 50, true);or(c);}
}};seMotionListener(new MouseAdapter() {public void mouseMoved(MouseEvent e) {repaint();}});seListener(new MouseAdapter() {public void mouseClicked(MouseEvent e) {if(new Rectangle(ation().x, ation().y getHeight() - 70, getWidth(),50).contains(ationOnScreen()) && null != mv) {on((ationOnScreen().x - ation().x) * () / getWidth());}}});kground();add(canvas);addKeyListener(new KeyAdapter() {public void keyReleased(KeyEvent e) {if(Code() == _ENTER) {ation(0, 0);e(screenSize);} else if(Code() == _ESCAPE) {nds((int) (th() / 8), (int) (ght() / 8), (int) (th() /4 * 3), (int) (ght() / 4 * 3));}}});setVisible(true);}}public static void main(String[] args) throws Exception {new MainFrame();}}
}}} catch (Exception e) {throw new RuntimeException(e);}}public synchronized void position(int newFrameIndex) {try {frameIndex = newFrameIndex;int lastFullFrameIndex;for(lastFullFrameIndex = frameIndex; lastFullFrameIndex >= 0; lastFullFrameIndex--) {if((lastFullFrameIndex).isFull) {break;}}Frame frame = getFrame(lastFullFrameIndex);last = (new ByteArrayInputStream((Data()).toByteArray()));oldRgbData = (last);for(int i = lastFullFrameIndex 1; i <= frameIndex; i ) {frame = getFrame(i);int[] rgb = ray2RgbArray((Data()).toByteArray());ArrayChange(last, oldRgbData, rgb);}} catch (Exception e) {tackTrace();}}public int position() {return frameIndex;}public int length() {return ();}public synchronized Object[] nextFrame() {
try {Frame frame = getFrame( frameIndex);if(null == frame) {return new Object[]{};}byte[] audioData = (ioData()).toByteArray();int[] rgb = null;if(g() == ) {last = (new ByteArrayInputStream((Data()).toByteArray()));} else {rgb = ray2RgbArray((Data()).toByteArray());}audioData = (ioData()).toByteArray();if(-1 != lastFrameTime) {long period = tTimeMillis() - lastFrameTime;if(period < 1000 / rate) {(1000 / rate - period);}}if(null != rgb) {ArrayChange(last, oldRgbData, rgb);}lastFrameTime = tTimeMillis();return new Object[] {last, audioData};} catch (Exception e) {throw new RuntimeException(e);}}public void addFrame(Frame frame) {try {FrameIndex fi = new FrameIndex(g() == , ioData().length, Data().length,(int) on());(fi);write(Data());
write(ioData());} catch (IOException e) {tackTrace();}}public Frame getFrame(int index) {if(index == ()) {return null;}FrameIndex frameIndex = (index);byte[] picData = new byte[aSize];byte[] audioData = new byte[ataSize];on();(picData);(audioData);return new Frame( ? : ENTAL, picData, audioData);}public void close() {try {if(isCreate) {int indexListIndex = (int) on();for(FrameIndex fi : indexList) {write(Array());}write(te(4).putInt(indexListIndex).array());write(new byte[] {rate});}(false);();();} catch (IOException e) {tackTrace();}}
private void write(byte[] data) throws IOException {ByteBuffer bb = (data);while(aining()) {(bb);}}static class FrameIndex {private final boolean isFull;private final int audioDataSize;private final int picDataSize;private final int index;public FrameIndex(boolean isFull, int audioDataSize, int picDataSize, int index) { = isFull;ataSize = audioDataSize;aSize = picDataSize; = index;}public boolean isFull() {return isFull;}public int getAudioDataSize() {return audioDataSize;}public int getPicDataSize() {return picDataSize;}public int getIndex() {return index;}public byte[] toByteArray() {byte[] result = new byte[10];result[0] = (isFull ? : ENTAL);te(4).putInt(audioDataSize).array();opy(te(4).putInt(audioDataSize).array(), 2, result, 1, 2);
opy(te(4).putInt(picDataSize).array(), 1, result, 3, 3);opy(te(4).putInt(index).array(), 0, result, 6, 4);return result;}public static FrameIndex fromByteArray(byte[] bs) {boolean isFull = ( == bs[0]);byte[] temp = new byte[8];opy(bs, 1, temp, 6, 2);int audioDataSize = (int) (temp).getLong();opy(bs, 3, temp, 5, 3);int picDataSize = (int) (temp).getLong();opy(bs, 6, temp, 4, 4);int index = (int) (temp).getLong();return new FrameIndex(isFull, audioDataSize, picDataSize, index);}}static class Frame {public static final Frame TERMINATE_FRAME = new Frame((byte) 0, null, null);public static final byte FULL = 0;public static final byte INCREMENTAL = 1;private final byte flag;private final byte[] picData;private final byte[] audioData;public Frame(byte flag, byte[] picData, byte[] audioData) { = flag;a = picData;ata = audioData;}public byte getFlag() {return flag;}public byte[] getPicData() {return picData;}
public byte[] getAudioData() {return audioData;}}}class RecordHelper {private static final byte RECORD_RATE = 5;private static final int DEFAULT_FULL_PIC_RATE = 80;private static final int FULL_PIC_PERIOD = 60;private static final Rectangle rectangle = new Rectangle(aultToolkit().getScreenSize());private static ScheduledExecutorService screenCapture;private static ScheduledExecutorService audioProcesser;private static final ExecutorService ioProcesser = gleThreadExecutor();private static final ExecutorService dataProcesser = gleThreadExecutor();private static final BlockingQueue screenQueue = new LinkedBlockingQueue();private static final BlockingQueue audioQueue = new LinkedBlockingQueue();private static final BlockingQueue frameQueue = new LinkedBlockingQueue();private static volatile boolean generateFull = false;public static void start(final String filePath) {generateFull = true;restart();e(new Runnable() {public void run() {try {double lastFullPicTime = -1;int[] latestRgb = null;for(;;) {byte[] picData;byte flag;Object[] imageData = ();byte[] audioData = ();if(generateFull) {latestRgb = ((BufferedImage) imageData[1]);picData = (2Stream((BufferedImage) imageData[1]).toByteArray()).toByteArray();
flag = ;lastFullPicTime = (Long) imageData[0];(new (flag, picData, (audioData).toByteArray()));generateFull = false;continue;}int[] temp = ();double rate = DEFAULT_FULL_PIC_RATE - ((((Long) imageData[0]) - lastFullPicTime) * DEFAULT_FULL_PIC_RATE / 1000 /FULL_PIC_PERIOD);byte[] changeData = eArrayChange(temp, (BufferedImage) imageData[1], rate);if(null != changeData) {latestRgb = temp;picData = (changeData).toByteArray();flag = ENTAL;} else {latestRgb = ((BufferedImage) imageData[1]);picData = (2Stream((BufferedImage) imageData[1]).toByteArray()).toByteArray();flag = ;lastFullPicTime = (Long) imageData[0];}(new (flag, picData, (audioData).toByteArray()));}} catch (InterruptedException e) {tThread().interrupt();}}});e(new Runnable() {public void run() {MyVideo video = new MyVideo(new File(filePath), true, RECORD_RATE);try {for(;;) { frame = ();if(frame == ATE_FRAME) {
return;}me(frame);}} catch (InterruptedException e) {tThread().interrupt();} finally {();}}});}public static void pause() {wnNow();wnNow();}public static void restart() {screenCapture = gleThreadScheduledExecutor();audioProcesser = gleThreadScheduledExecutor();leAtFixedRate(new Runnable() {public void run() {try {(new Object[] {tTimeMillis(), een(rectangle)});} catch (InterruptedException e) {tThread().interrupt();}}}, 0, 1000 / RECORD_RATE, ECONDS);final int bufferSize = ferSize();byte[] data = new byte[bufferSize];ta(data);leAtFixedRate(new Runnable() {public void run() {try {
}oldRgbData[index] = newRgb;rgb = (DEFAULT_RGB == newRgb ? oldRgb : newRgb);} else {rgb = DEFAULT_RGB;}if(DEFAULT_RGB == rgb) {if(samePointCount >= 0) {samePointCount ;} else {(samePointCount);samePointCount = 1;}} else {if(samePointCount <= 0) {samePointCount--;} else {(samePointCount);samePointCount = -1;}();((rgb).array());}}}(samePointCount);byte[] rgbData = Array();byte[] result = new byte[(() 1) * 4 ];();int index = 0;opy((()).array(), 0, result, index, 4);for(int chunkSize : chunkCountList) {();opy((chunkSize).array(), 0, result, index = 4, 4);
}public static void setRgbArray(BufferedImage image, int[] rgbChangeData) {int h = ght();int w = th();for(int i = 0; i < h; i ) {for(int j = 0; j < w; j ) {int newRgb = rgbChangeData[i * w j];if(DEFAULT_RGB != newRgb) {(j, i, newRgb);}}}}public static ByteArrayOutputStream image2Stream(BufferedImage image) {try {ByteArrayOutputStream baos = new ByteArrayOutputStream();(image, DEFAULT_FORMAT_NAME, baos);return baos;} catch (IOException e) {throw new RuntimeException(e);}}/*** 压缩后的byte数组还原为rgb数组* @param data* @return*/public static int[] byteArray2RgbArray(byte[] data) {ByteBuffer buffer = te(4);();(new byte[] {data[0], data[1], data[2], data[3]});();int chunkCount = ();List chunkCountList = new ArrayList(chunkCount);
int index = 4;int rgbCount = 0;for(int i = 0; i < chunkCount; i ) {();((new byte[] {data[index 0], data[index 1], data[index 2], data[index 3]}));();int chunkSize = ();(chunkSize);rgbCount = (chunkSize);index = 4;}int[] rgbData = new int[rgbCount];int rgbDataIndex = 0;for(int chunkSize : chunkCountList) {if(chunkSize > 0) {for(int j = 0; j < chunkSize; j ) {rgbData[rgbDataIndex ] = DEFAULT_RGB;}} else {for(int j = 0; j > chunkSize; j--) {();(new byte[] {data[index 0], data[index 1], data[index 2], data[index 3]});();rgbData[rgbDataIndex ] = ();index = 4;}}}return rgbData;}}final class AudioHelper {private static final float RATE = 8000;private static final int SAMPLE_SIZE_IN_BITS = 8;
private static final int CHANNELS = 1;private static final AudioFormat DEFAULT_AUDIO_FORMAT = new AudioFormat(_SIGNED,RATE, SAMPLE_SIZE_IN_BITS, CHANNELS, SAMPLE_SIZE_IN_BITS / 8 * CHANNELS, RATE, false);private static SourceDataLine sourceDataLine;private static TargetDataLine targetDataLine;static {try { targetInfo = new (, DEFAULT_AUDIO_FORMAT);targetDataLine = (TargetDataLine) e(targetInfo);(DEFAULT_AUDIO_FORMAT);(); sourceInfo = new (, DEFAULT_AUDIO_FORMAT);sourceDataLine = (SourceDataLine) e(sourceInfo);(DEFAULT_AUDIO_FORMAT);();} catch (Exception e) {throw new RuntimeException(e);}}public static int getBufferSize() {return ferSize();}public static int readData(byte[] bs) {return (bs, 0, ble());}public static void writeData(byte[] bs) {(bs, 0, );}public static void flush() {();}}final class ZipHelper {public static ByteArrayOutputStream zip(byte[] data) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();try {ZipOutputStream zip = new ZipOutputStream(baos);ZipEntry entry = new ZipEntry("zip");e();tEntry(entry);(data);ntry();();} catch (Exception e) {tackTrace();}return baos;}public static ByteArrayOutputStream unZip(byte[] data) {ByteArrayOutputStream baos = null;try {ByteArrayInputStream bis = new ByteArrayInputStream(data);ZipInputStream zip = new ZipInputStream(bis);if (tEntry() != null) {byte[] buf = new byte[1024];int num;baos = new ByteArrayOutputStream();while ((num = (buf, 0, )) != -1) {(buf, 0, num);}();();}();();} catch (Exception e) {tackTrace();}
return baos;}}
本文发布于:2024-02-08 16:13:18,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170737999867953.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |