Ok, it still doesn't work really good.
I pasted the essential parts of the code into a small demo, added a
frame to it for display and it runs just as bad as the complete thing.
The delay between movement and drawing ia about five seconds, getting
worse with the time. If you have the time to check it out for a sec and
find something problematic, please let me know. Otherwise I will have to
port the whole thing to C. Thanks in any case.
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.InputStream;
import java.net.*;
import java.awt.*;
import java.awt.image.*;
import javax.imageio.ImageIO;
public class Test
{
private static HttpURLConnection hurlconnection = null;
private static DataInputStream datainstream = null;
private static String serialNumber = null;
private static boolean connected = false;
private static BufferedImage image = null;
public static void main(String[] args) throws Exception
{
URL streamurl = new
URL("
http://192.168.1.51/axis-cgi/mjpg/video.cgi?resolution=352x288&compression=100&showlength=1&fps=10");
hurlconnection = (HttpURLConnection)streamurl.openConnection();
hurlconnection.setReadTimeout(10000);
InputStream instream = hurlconnection.getInputStream();
connected = true;
BufferedInputStream bis = new BufferedInputStream(instream);
datainstream = new DataInputStream(bis);
Frame frm = new Frame();
frm.setSize(200,200);
frm.setVisible(true);
//decodiere stream
if(connected)
{
Image i;
while(!Thread.currentThread().isInterrupted())
{
image = null;
i = null;
String header;
int k = 0;
while(image == null)
{
k = 0;
do
{
header = datainstream.readLine();
}
while(++k < 3);
datainstream.readByte();
int j = (new Integer(header.substring("Content-Length:
".length()))).intValue();
datainstream.readByte();
byte abyte1[] = new byte[j + 2];
datainstream.readFully(abyte1, 0, j + 2);
datainstream.readLine();
ByteArrayInputStream bin = new ByteArrayInputStream (abyte1);
image = ImageIO.read ( bin );
} //end while image==null
long before = System.currentTimeMillis();
Graphics2D g2 = (Graphics2D)frm.getGraphics();
frm.getGraphics().drawImage(image,0,0,null);
long after = System.currentTimeMillis();
System.out.println("Duration: " +(after-before));
//Thread.currentThread().sleep(100);
}
}
}
}