-
Can you send bitmapData over xmlSocket
I have a question, I hope its possible because it would basically allow me to stream any video I want from a client to other clients but...
I put this in backend section because of the xmlSocket server I made in java.
How would I go about sending Bitmapdata over a server and use the xmlSocket.send() function to get it to all the other clients. I am trying to simply create a BitmapData object and have it draw() then send it over, but it only returns as sending the String "[Object Object]". So how would I really send it over. The image is created dynamically obviously so it isn't sending a file over.
I am using this tut for the screenshot making...
http://www.flash-db.com/Tutorials/snapshot/
I kept it the same except I deleted the flv vid and replaced it with a webcam feed. And I made the shadow button into a movieclip and applied the capture for it to be in a onEnterFrame loop instead of a onPress.
Does anyone know how I would send a dynamically created image over a xmlSocket, please give me a reply. Please let it be possible. AND THANK YOU WHO EVER HELPS!
It does work by the way, I do have the image based vid popping up on my screen. I just need to figure out how to send it.
Last edited by cody112; 04-05-2009 at 10:07 AM.
Reason: I forgot to about putting this in...
-
I have an idea but...
I think that I know how to do it, but it will be a pain in the azz... Apparently if I were to have each vid flowing in be 400x300 or something like that I would have to send 120000 variables over the xmlSocket to other users.
Is there a less pain in the ass way to do it? Is there a way that I don't have find the color of each darned pixel in the image.
I can have this done in 400 or 300 onEnterFrame loops if I were to try and minimize the amount of loops needed. But is there an easier way to just have each pixel be sent in one go and not have to manually declare all 120000 variables by actually typing out each one.
I'm planning on declaring all 300 values on the y axis and have each one basically send out a invisible pixel that finds the color of all the pixels in the x axis for the value of the y axis point its sent out from.
Just image it like sending out a wave of pixels across it.
I think it should work, but I still would want a easier way.
I just want to know this: How much bandwidth would be taken up on my side for each variable that goes through the server?
-
WohOoooooo
I'v never worked with xmlSocket, but maybe something like this would work
loop the image pixels and send them using bytearray. And on client2 you loop the bytes and draw the image. I think it will be alot of data sent though, even if its probably less then sending 120000 variables, maybe convert the bitmapdata to a jpg and send that as a bytearray.
If you cant send a bytearray using xmlSocket you could convert it to base64 and send that.
-
 Originally Posted by zompo
I'v never worked with xmlSocket, but maybe something like this would work
loop the image pixels and send them using bytearray. And on client2 you loop the bytes and draw the image. I think it will be alot of data sent though, even if its probably less then sending 120000 variables, maybe convert the bitmapdata to a jpg and send that as a bytearray.
If you cant send a bytearray using xmlSocket you could convert it to base64 and send that.
Well, decided I will make it 250x250 pixels so it will only be 62500 variables, but I would rather not make it into an image that you would load up because I don't think it would go in fast enough to be like a video feed. So the sending 62500 variables might be the better option against that.
But I can't say much for the base64 thing cause I have no idea what it is, so Im gonna google it.
-
Base64 will work on...
 Originally Posted by cody112
But I can't say much for the base64 thing cause I have no idea what it is, so Im gonna google it.
Well... I found it right away XD, so your telling me that base64 would work on a bitmapData right.
So this would work?
var bmpData = new BitmapData("yada yada yada here");//BitmapData
var encoded:String = Base64.encode(bmpData);
trace(encoded)
var decoded:String = Base64.decode(encoded);
trace(decoded);
It don't take a long time to get it through do it?
-
WohOoooooo
 Originally Posted by cody112
Well... I found it right away XD, so your telling me that base64 would work on a bitmapData right.
So this would work?
var bmpData = new BitmapData("yada yada yada here");//BitmapData
var encoded:String = Base64.encode(bmpData);
trace(encoded)
var decoded:String = Base64.decode(encoded);
trace(decoded);
It don't take a long time to get it through do it?
You have to use the Base64 on a byte array
like,
Code:
client1:
ba:ByteArray
loop (image width) {
loop (image height) {
ba.writeInt(pixelcolor);
}}
var encoded:String = Base64.encodeByteArray(ba);
send(encoded)
client2:
var ba:ByteArray = Base64.decodeToByteArray(loadedData);
loop (image width) {
loop (image height) {
ba.readInt(); // Pixel color
}}
This would be better though if its to much data being sent:
Code:
client 1:
ba:ByteArray = imageToJpgByteArray(image, quality = 0.5); // I think there are some JPG classes you can dl
var encoded:String = Base64.encodeByteArray(ba);
send(encoded)
client 2:
var ba:ByteArray = Base64.decodeToByteArray(loadedData);
//display the image
I would try something like this, dont know if its the best way though
Last edited by zompo; 04-06-2009 at 03:34 PM.
-
 Originally Posted by zompo
You have to use the Base64 on a byte array
like,
client1:
ba:ByteArray
loop (image width) {
loop (image height) {
ba.writeInt(pixelcolor);
}}
var encoded:String = Base64.encodeByteArray(ba);
send(encoded)
client2:
var ba:ByteArray = Base64.decodeToByteArray(loadedData);
loop (image width) {
loop (image height) {
ba.readInt(); // Pixel color
}}
sorry, but one last question I'm using this code on the fist frame of the fla...
import flash.display.BitmapData;
import flash.geom.Matrix;
import com.dynamicflash.util.Base64;
var testImgSocket:XMLSocket = new XMLSocket();
testImgSocket.connect("127.0.0.1",8080);
var activeCamera = Camera.getCamera();
activeCamera.setMode(640,480,30);
var output_vid:Video = new Video(250,250);
output_vid.attachCamera(activeCamera);
addChild(output_vid);
var snapshot:BitmapData = new BitmapData(output_vid.width,output_vid.height);
var source:ByteArray = new ByteArray();
addEventListener(Event.ENTER_FRAME, onEnterFrame);
function onEnterFrame(event:Event):void {
snapshot.draw(output_vid,new Matrix());
var bmp:Bitmap = new Bitmap(snapshot);
bmp.x = 350; bmp.y = 20;
source.writeObject(bmp);
var encoded:String = Base64.encodeByteArray(source);
var decoded:ByteArray = Base64.decodeToByteArray(encoded);
var obj2:Bitmap = decoded.readObject();
addChild(obj2);
}
And I keep getting this error in the output for every loop...
TypeError: Error #1034: Type Coercion failed: cannot convert Object@28b62ee9 to flash.display.Bitmap.
at snapshot_fla::MainTimeline/onEnterFrame()
-
WohOoooooo
This seems to work for me
Code:
package
{
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.events.Event;
import flash.geom.Matrix;
import flash.geom.Rectangle;
import flash.media.Camera;
import flash.media.Video;
import flash.utils.ByteArray;
import com.utils.Base64;
public class Main extends Sprite
{
private var dispshotDisplay:Bitmap;
private var snapshot:BitmapData;
private var dispshot:BitmapData;
private var output_vid:Video;
private var ba:ByteArray;
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
var activeCamera:Camera = Camera.getCamera();
activeCamera.setMode(640,480,30);
output_vid = new Video(250,250);
output_vid.attachCamera(activeCamera);
addChild(output_vid);
snapshot = new BitmapData(output_vid.width, output_vid.height);
var snapshotDisplay:Bitmap = new Bitmap(snapshot);
snapshotDisplay.x = 200;
snapshotDisplay.y = 200;
addChild(snapshotDisplay);
dispshot = new BitmapData(output_vid.width, output_vid.height);
dispshotDisplay = new Bitmap(dispshot);
dispshotDisplay.x = 400;
dispshotDisplay.y = 400;
addChild(dispshotDisplay);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function onEnterFrame(e:Event):void
{
ba = new ByteArray();
snapshot.draw(output_vid, new Matrix());
ba = snapshot.getPixels(new Rectangle(0,0,150,150));
var encoded:String = Base64.encodeByteArray(ba);
var decoded:ByteArray = Base64.decodeToByteArray(encoded);
dispshot.setPixels(new Rectangle(0, 0, 150, 150), decoded);
}
}
}
-
Thanks dude!
THANKS A BUNCH MAN! It was nice working with ya XD!
I would like to apologize for all the questions I asked, but this is just simply the first time I ever tried something like this with flash and I just simply didn't know much about it.
I wanted this in order to make an awesome webcam chat system on the side of a chat with moveable 2d avatars.
Also... I wonder whats up with this, are you getting it too?
ReferenceError: Error #1065: Variable Base64 is not defined.
at vidHelp/onEnterFrame()
It works fine even though this comes up but I keep getting this in the onEnterFrame Loop... Weird...
-
WohOoooooo
No problem,
for your error, make sure the import of the base64 is ok.
Im using:
import com.utils.Base64;
but that maybe not the place where you have the Base64 class, in your post above you hade:
import com.dynamicflash.util.Base64; // this is probably the import you should use
the xmlSocket server your working on, is that something you will make public?
-
 Originally Posted by zompo
No problem,
for your error, make sure the import of the base64 is ok.
Im using:
import com.utils.Base64;
but that maybe not the place where you have the Base64 class, in your post above you hade:
import com.dynamicflash.util.Base64; // this is probably the import you should use
the xmlSocket server your working on, is that something you will make public?
I noticed that right after I said that comment, but now I'm not sure if this will work because I am sending out the data like this
testImgSocket.send(";"+decoded);
And the server isn't seeming to get it working because usually adding the ";" in the message should make it create an outgoing message to everyone.
But now it only gives this
Incoming data:ÿ
onData:1
If it worked, then that "onData:1" would be replaced with "Outgoing data:ÿ"
and that "Incoming data:ÿ" should have been "Incoming data:;ÿ".
But for some reason(I am providing the ";") it doesn't add the ";". And also, is that string for the decoded variable only supposed to be "ÿ"?
This is really confusing.
EDIT:
Oh sorry, how rude of me for forgetting. Yes I am planning on releasing to public. I will credit you if that is why you are asking. But since there can be many other reasons why you asked, why are you asking XD?
Last edited by cody112; 04-06-2009 at 05:40 PM.
Reason: Forgot...
-
WohOoooooo
You should send the base64 encoded string
testImgSocket.send(";"+encoded);
and onData you should decode it (if the ";" is recived on data you need to remove it before decode)
No need for credits, I just thought it would be fun playing around with a socketserver some day
-
 Originally Posted by zompo
you should send the base64 encoded string
omg, im a moron!
How did i not consider that!
Thanks again, gonna test right now!
Edit: The server itself splits the ";" and then the outgoing is automatically sent without it.
Edit2: It didn't work, I was trying to copy and paste the incoming data message that the server had in it to here....
But it was more than 120000 characters over the limit flash kit allows in this reply...
There was no Outgoing data either.
No joke.... I swear to god, when it comes to data, handling of 3d, and file creation... FLASH GETS MOST ANNOYING!
Edit3: But I don't think thats the real encoded message, something tells me sumtins getting screwed up with sending it. Because the incoming data was "/wAAAP8AAAD/AAAA" repeated over and over and over again on the same line.
Last edited by cody112; 04-06-2009 at 08:42 PM.
-
You know what...
If the next thing I try doesn't work(still have no clue what that is going to be yet) I am just gonna give this up. It lags from it anyway and I still don't get it.
You can still post something, but if the next thing I try doesn't work(unless it gets me really close), I will quit this for now.
Edit: Don't worry, I only mean I'm quitting the webcam thing... I guess I'm gonna start the actual chat now, I already set up a login and signup for it. All thats left is the chat,moveable avatars, and if I solve this(webcam chat rooms)
Last edited by cody112; 04-06-2009 at 08:57 PM.
-
Ah... I just realized something as I woke up. I know why it is getting such a long string. Its because it keeps writing to the same object, without clearing it.
So I think that the new bytearray should be made in the onenterframe loop as well before it writes the object.
Edit: Nevermind I get it, it is that long because the amount of pixels... sigh... Is there anyway I can send it over, and not have it be pixel values.
I would rather do it my way if I were to be doing that. Sending 250 at a time 250 times seems like it would work better because it is just sending to many over in one loop.
I say the only way to do it is by somehow sending the object itself over, or sending pixel colors bit by bit.
Last edited by cody112; 04-07-2009 at 09:44 AM.
-
WohOoooooo
and before you send it do a .compress() before you make it base64, and when you recive de data, decode it and do a .uncompress() that will make it much smaller
-
Yo dude... I GOT IT WORKING, PARTIALLY!
I managed to get the message through the server and create a image!
BUT IT TURNED OUT BLACK, NOTHING WAS THERE!
EDIT: O.K. Never mind, turns out it was working, just the first one was black and since I had the webcam feed and another image feed running at the same time it was running very slow. So it would turn out that it was just because of lag that it was black for so long.
Got any ideas for this situation though... How would I get a non-lagging feed of up to 1 webcam and 3 imagecams.
Edit2: I'm gonna upload it to any free download site like deposit files, rapidshare, or any website that you specify on your queue. If you want me to that is, you get to see the person you just helped XD, how do u like that...
Edit3: Nope, not yet sorry. I just noticed that the thing stops compressing the data after about 4 loops for some reason. Odd...
So it stops after the first like 4 images.
Last edited by cody112; 04-07-2009 at 06:16 PM.
-
WohOoooooo
I think its not the best idea to send the webcamimage on every frame, or it depends on what your framerate of the movie is set to. Maybe use a time that sends images whit a fps of 10-15 fps.
But as a first test you could try and lower the movie fps and see if it works better
-
Yo zompo its working... Not well enough though
I got it working by doing what you said, but not 10-15, 3 fps is the best not to messy fps i can get it to.
If I could overcome the size of what its sending I should be able to make it work better.
And by the way, after about 3 minutes, it is about a minute & a half(or more) behind. On the image feed.
Edit: Dam... I rolled my eyes into the back of my head at one point. And the imagecam did it about 4-5 minutes later....
Edit2: I got the server to not lag so much, but only by scaling it down by half, it was 150x150, now 75x75. Too small if you ask me... If I could only maintain even a fair fps and keep it 150x150...
Last edited by cody112; 04-08-2009 at 10:27 AM.
Reason: Its better, but not in the way I want it
-
Well...
Considering its in fairly working order(aside from the size of image) do you want me to upload the swf on to a download site like rapidshare or deposit files.
I am going to add a small chat to it, but I'm not gonna add a webcam that sends stuff from you to me because you may not want that or possibly don't have a cam. And also because fear that lag will be bad.
Best I can do is 75x75 at around 4-5 fps.
My problem is that I can't connect to my own server if I try it from my computer if I don't have it running locally.
I literally can't connect if I don't have it running on 127.0.0.1 or 192.168.0.12 from my computer. Everyone else outside my ip can, but our house can't...
Best I can do to actually allow me and you to both be on it is to go over to a neighbors house and go on there.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|