Add FPS to toolbar

This commit is contained in:
ErdbeerbaerLP 2019-05-25 21:57:26 +02:00
parent a6c3332af4
commit ec8248a49b
4 changed files with 28 additions and 9 deletions

View File

@ -84,8 +84,9 @@ public class ImageStreamer {
while (true) {
if (tcpClient.isConnected()) {
System.out.println("FPS:" + framesThisSecond);
if(Main.win != null) Main.win.setFps(framesThisSecond);
framesThisSecond = 0;
}
}else if(Main.win != null) Main.win.setFps(-1);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
@ -102,7 +103,15 @@ public class ImageStreamer {
tcpClient.send(rawCommand);
result = true;
} catch (Exception e) {
e.printStackTrace();
result = false;
tcpClient.abort();
try {
tcpClient.connect();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
return result;
@ -141,18 +150,18 @@ public class ImageStreamer {
@Synchronized("lock")
private void udpDataHandler(byte[] data) {
if (state == DataState.UNKNOWN) {
// System.out.println("GET CRC");
// System.out.println("GET CRC");
// System.out.println("data.length = "+data.length);
if (data.length == 4) {
ByteBuffer wrapped = ByteBuffer.wrap(data); // big-endian by default
curcrc32 = wrapped.getInt(); // 1
state = DataState.CRC32_RECEIVED;
} else {
state = DataState.UNKNOWN;
return;
}
} else if (state == DataState.CRC32_RECEIVED) {
// System.out.println("GET Size");
// System.out.println("GET Size");
if (data.length == 8) {
ByteBuffer wrapped = ByteBuffer.wrap(data); // big-endian by default
curJPEGSize = (int) wrapped.getLong();
@ -165,7 +174,7 @@ public class ImageStreamer {
return;
}
} else if (state == DataState.RECEIVING_IMAGE) {
// System.out.println("GET IMAGE");
// System.out.println("GET IMAGE");
System.arraycopy(data, 0, jpegBuffer, curLenPos, data.length > curJPEGSize ? curJPEGSize : data.length);
curJPEGSize -= data.length;

View File

@ -39,7 +39,7 @@ import org.apache.commons.cli.Options;
import de.mas.wiiu.streaming.gui.StreamWindow;
public class Main {
public static StreamWindow win;
public static void main(String[] args) throws Exception {
if(GraphicsEnvironment.isHeadless()) {
System.out.println("This program does not support running in a headless environment!");
@ -112,7 +112,7 @@ public class Main {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new StreamWindow(imageStreamer.getImageProvider());
win = new StreamWindow(imageStreamer.getImageProvider());
}
});
}

View File

@ -23,11 +23,13 @@
package de.mas.wiiu.streaming.gui;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
@ -36,7 +38,7 @@ import javax.swing.WindowConstants;
public class StreamWindow {
private final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
private final ImagePanel image = new ImagePanel(screenSize.width-15, screenSize.height-100);
private final JLabel lblFps = new JLabel(" FPS: Not Connected!");
public StreamWindow(IImageProvider imageProvider) {
JFrame editorFrame = new JFrame("Wii U Streaming Client");
@ -70,10 +72,17 @@ public class StreamWindow {
mntmNewMenuItem.setEnabled(false);
mnSettings.add(mntmNewMenuItem);
mnSettings.add(mntmExit);
lblFps.setFont(new Font("Tahoma", Font.PLAIN, 11));
menuBar.add(lblFps);
editorFrame.pack();
editorFrame.setLocationRelativeTo(null);
editorFrame.setVisible(true);
}
public void setFps(int fps){
if(fps == -1) this.lblFps.setText(" FPS: Not Connected!");
else this.lblFps.setText(" FPS: "+fps);
}
}

View File

@ -62,6 +62,7 @@ final public class TCPClient {
public boolean abort() {
try {
sock.close();
log.info("TCP client closed");
} catch (IOException e) {
log.info(e.getMessage()); // TODO: handle
return false;