I have the bytes of a image i’m trying to broadcast to my clients from a server, i did some test and the biggest message i could send was one that has a byte size of 32759. the way im thinking about going about this would send 38 parts for 1 image then i would have to re assemble them together on the client. i would like to be able to send less parts or the whole image in 1 message.
[java]
/*
To change this template, choose Tools | Templates
and open the template in the editor.
*/
package com.benkyou.webcam;
import com.benkyou.common.WebcamMessage;
import com.benkyou.server.WebcamServer;
import com.jme3.network.serializing.Serializer;
import com.jme3.texture.Image.Format;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.ByteBuffer;
import javax.imageio.ImageIO;
import jme3tools.converters.ImageToAwt;
/**
*
@author Student
/
public class JPGStreamReader implements Runnable{
private String imgLocation;
private URL imgURL;
private BufferedImage awtImage;
private ByteBuffer byteBuffer;
final public Format jmeformat = Format.RGBA8;
public static byte[] imageBytes;
private ByteBuffer copiedBuffer;
private WebcamServer webcamServer;
public JPGStreamReader(String imgLocation, WebcamServer webcamServer){
Because of the way the serializer is architected, we can’t really increase the buffer size as that would impact even small messages. It’s a deficiency of the ByteBuffer design.
You will be happier splitting it up in the long run anyway, I think. Otherwise, your channel is tied up with no other messages being able to go through. At least this way, other messages can still squeeze in.
Also, you could compress the image which would save a lot of messages.
I planned on having this webcam stream reading server running on its own server separate from the game server and having the game client connect to both servers, will this bog down the game server channels on the client?
But on the other hand, there is only so much bandwidth to go around. Trying to shove uncompressed 1.2 meg images over TCP is going to really saturate your pipe, I think. How often are you trying to send them?
i’m hopping to get a good frame rate of 25 fps, but since each frame is 37 messages that’s about 925 messages a second. The image is from a webcam so i think it is decently pre-compressed for me… pulling a single image of the webcam is only 24kb… I think my bottleneck is how i’m reading the byte array from the byte buffer, i would suspect that it should be various sizes with a stream, but its not.
I was hoping to do the image conversion server side so that the image i send out to the clients is pre converted, tho it is starting to look like it would be more efficient to just foward the compressed image from the webcam to the clients and converting it over there.
That’s a huge amount of data to be sending in one chunk… and is definitely uncompressed in that form. It’s especially bad when you get 24kb per frame originally… which will easily fit in one SM message. Are you streaming from the camera or capturing single frames?
In fact, depending on what you are doing with them, if you are just capturing and sending single frames then you might be able to get away with sending each frame “unreliable” which will be faster but you might miss frames. Especially if they are large (UDP reliability goes down if packets are bigger than the MTU of the pipe.)
If you still want to get the raw 640x480 frames then you could do some basic compression on them before sending. Something would be better than nothing.
Its a single frame generated from the webcam server that i grab and do all my conversions on.
i found a tid bit on how to read a motion jpg stream and i “think” im able to pull off a full image tho i haven’t been very succesfull in converting the data back to a image…
[java]
package com.benkyou.webcam;
import com.jme3.texture.Image;
import com.jme3.texture.Image.Format;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.ByteBuffer;
import java.util.Iterator;
public class Test {
private ByteBuffer convertByteArrayBuff;
ByteArrayOutputStream buffer = new ByteArrayOutputStream();