diff --git a/src/main/java/de/mas/wiiu/streaming/ImageStreamer.java b/src/main/java/de/mas/wiiu/streaming/ImageStreamer.java index 616f062..2b77075 100644 --- a/src/main/java/de/mas/wiiu/streaming/ImageStreamer.java +++ b/src/main/java/de/mas/wiiu/streaming/ImageStreamer.java @@ -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; diff --git a/src/main/java/de/mas/wiiu/streaming/Main.java b/src/main/java/de/mas/wiiu/streaming/Main.java index 075e19e..fb8eebf 100644 --- a/src/main/java/de/mas/wiiu/streaming/Main.java +++ b/src/main/java/de/mas/wiiu/streaming/Main.java @@ -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()); } }); } diff --git a/src/main/java/de/mas/wiiu/streaming/gui/StreamWindow.java b/src/main/java/de/mas/wiiu/streaming/gui/StreamWindow.java index 9978f36..44e70ef 100644 --- a/src/main/java/de/mas/wiiu/streaming/gui/StreamWindow.java +++ b/src/main/java/de/mas/wiiu/streaming/gui/StreamWindow.java @@ -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); + } } diff --git a/src/main/java/de/mas/wiiu/streaming/network/TCPClient.java b/src/main/java/de/mas/wiiu/streaming/network/TCPClient.java index e7a517a..5db0cde 100644 --- a/src/main/java/de/mas/wiiu/streaming/network/TCPClient.java +++ b/src/main/java/de/mas/wiiu/streaming/network/TCPClient.java @@ -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;