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) { while (true) {
if (tcpClient.isConnected()) { if (tcpClient.isConnected()) {
System.out.println("FPS:" + framesThisSecond); System.out.println("FPS:" + framesThisSecond);
if(Main.win != null) Main.win.setFps(framesThisSecond);
framesThisSecond = 0; framesThisSecond = 0;
} }else if(Main.win != null) Main.win.setFps(-1);
try { try {
Thread.sleep(1000); Thread.sleep(1000);
} catch (InterruptedException e) { } catch (InterruptedException e) {
@ -102,7 +103,15 @@ public class ImageStreamer {
tcpClient.send(rawCommand); tcpClient.send(rawCommand);
result = true; result = true;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();
result = false; result = false;
tcpClient.abort();
try {
tcpClient.connect();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
} }
return result; return result;
@ -141,18 +150,18 @@ public class ImageStreamer {
@Synchronized("lock") @Synchronized("lock")
private void udpDataHandler(byte[] data) { private void udpDataHandler(byte[] data) {
if (state == DataState.UNKNOWN) { 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) { if (data.length == 4) {
ByteBuffer wrapped = ByteBuffer.wrap(data); // big-endian by default ByteBuffer wrapped = ByteBuffer.wrap(data); // big-endian by default
curcrc32 = wrapped.getInt(); // 1 curcrc32 = wrapped.getInt(); // 1
state = DataState.CRC32_RECEIVED; state = DataState.CRC32_RECEIVED;
} else { } else {
state = DataState.UNKNOWN; state = DataState.UNKNOWN;
return; return;
} }
} else if (state == DataState.CRC32_RECEIVED) { } else if (state == DataState.CRC32_RECEIVED) {
// System.out.println("GET Size"); // System.out.println("GET Size");
if (data.length == 8) { if (data.length == 8) {
ByteBuffer wrapped = ByteBuffer.wrap(data); // big-endian by default ByteBuffer wrapped = ByteBuffer.wrap(data); // big-endian by default
curJPEGSize = (int) wrapped.getLong(); curJPEGSize = (int) wrapped.getLong();
@ -165,7 +174,7 @@ public class ImageStreamer {
return; return;
} }
} else if (state == DataState.RECEIVING_IMAGE) { } 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); System.arraycopy(data, 0, jpegBuffer, curLenPos, data.length > curJPEGSize ? curJPEGSize : data.length);
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; import de.mas.wiiu.streaming.gui.StreamWindow;
public class Main { public class Main {
public static StreamWindow win;
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
if(GraphicsEnvironment.isHeadless()) { if(GraphicsEnvironment.isHeadless()) {
System.out.println("This program does not support running in a headless environment!"); System.out.println("This program does not support running in a headless environment!");
@ -112,7 +112,7 @@ public class Main {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
public void run() { public void run() {
new StreamWindow(imageStreamer.getImageProvider()); win = new StreamWindow(imageStreamer.getImageProvider());
} }
}); });
} }

View File

@ -23,11 +23,13 @@
package de.mas.wiiu.streaming.gui; package de.mas.wiiu.streaming.gui;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit; import java.awt.Toolkit;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu; import javax.swing.JMenu;
import javax.swing.JMenuBar; import javax.swing.JMenuBar;
import javax.swing.JMenuItem; import javax.swing.JMenuItem;
@ -36,7 +38,7 @@ import javax.swing.WindowConstants;
public class StreamWindow { public class StreamWindow {
private final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); private final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
private final ImagePanel image = new ImagePanel(screenSize.width-15, screenSize.height-100); 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) { public StreamWindow(IImageProvider imageProvider) {
JFrame editorFrame = new JFrame("Wii U Streaming Client"); JFrame editorFrame = new JFrame("Wii U Streaming Client");
@ -70,10 +72,17 @@ public class StreamWindow {
mntmNewMenuItem.setEnabled(false); mntmNewMenuItem.setEnabled(false);
mnSettings.add(mntmNewMenuItem); mnSettings.add(mntmNewMenuItem);
mnSettings.add(mntmExit); mnSettings.add(mntmExit);
lblFps.setFont(new Font("Tahoma", Font.PLAIN, 11));
menuBar.add(lblFps);
editorFrame.pack(); editorFrame.pack();
editorFrame.setLocationRelativeTo(null); editorFrame.setLocationRelativeTo(null);
editorFrame.setVisible(true); 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() { public boolean abort() {
try { try {
sock.close(); sock.close();
log.info("TCP client closed");
} catch (IOException e) { } catch (IOException e) {
log.info(e.getMessage()); // TODO: handle log.info(e.getMessage()); // TODO: handle
return false; return false;