14 Replies - 4067 Views - Last Post: 13 May 2011 - 01:44 PM Rate Topic: -----

#1 theotherguy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 05-April 11

Sending & receiving bitmap from networkstream

Posted 11 May 2011 - 10:35 PM

Hello,

I was trying to develop a video chat p2p system by sending bitmap of the picturebox where the webcam performs. I want to send and make the client just prompted without having the client to save the file by opening savefiledialog of the bitmap i was sending.

The sending part was like first I copy the frame of the picturebox which showing the video cam, and saved it into memorystream as .bmp file like this:
ms = New MemoryStream()
        Dim a As Image
        a = Server1.copyFrame(Me.PictureBox1, New RectangleF(0, 0, _
                            Me.PictureBox1.Width, Me.PictureBox1.Height))

        a.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp)
        Dim arrImage As Byte() = ms.ToArray()

        Server1.SendCam(arrImage)

In different class file
Public Sub SendCam(ByVal arrImage As Byte())
        Server.BroadcastSendCam(arrImage, Contact.Cam)
    End Sub

Public Sub SendCam(ByVal msgTag As Byte, ByVal arrImage As Byte()) ', ByVal flag As Boolean)

        SyncLock client.GetStream
            'Dim arrImage As Byte() = ms.GetBuffer()

            Dim w As New BinaryWriter(client.GetStream)
            
            w.Write(RequestTags.Cam)
            
            w.Write(msgTag)
            'Send the file data
           
            w.Write(arrImage)
            
            w.Flush()
        End SyncLock
    End Sub

On the receiver side which is the following code, this is to retrieve the bytes and store it again to memorystream.
Case RequestTags.Cam
                SyncLock client.GetStream
                    r = New BinaryReader(client.GetStream)

                    client.GetStream.Read(readByte, 0, 1)
                    passThroughByte = readByte(0)
                    'next expect length of data (Int32)
                    nData = r.ReadInt32
                    lenData = nData
                    'now comes the data, save it in a memory stream
                    mStream = New MemoryStream

                    lData = client.GetStream.Read(readBuffer, 0, PACKET_SIZE)
                    mStream.Write(readBuffer, 0, lData)

                    'Continue the asynchronous read from the NetworkStream
                    Me.client.GetStream.BeginRead(readByte, 0, 1, AddressOf ReceiveOneByte, Nothing)
                End SyncLock
                'once all data has arrived, pass it on to the end user as a stream
                RaiseEvent VideoReceived(Me, passThroughByte, mStream)
                mStream.Dispose()

Private Sub Cam(ByVal ms As MemoryStream)
        PictureBox2.Image = Image.FromStream(ms)
    End Sub


I got error showing on the following:
Public Sub HandleCam(ByVal ms As MemoryStream)
        'Here, you handle adding the text to a text box.
        Me.Invoke(New NewFileDelegate(AddressOf Cam), ms) 'This line was highlighted when I get the error.
    End Sub


Any help will be much appreciated.

Thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: Sending & receiving bitmap from networkstream

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9570
  • View blog
  • Posts: 36,240
  • Joined: 12-June 08

Re: Sending & receiving bitmap from networkstream

Posted 12 May 2011 - 06:56 AM

What error are you getting?
Was This Post Helpful? 0
  • +
  • -

#3 theotherguy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 05-April 11

Re: Sending & receiving bitmap from networkstream

Posted 12 May 2011 - 07:34 AM

View Postmodi123_1, on 12 May 2011 - 06:56 AM, said:

What error are you getting?


Thanks for your reply, but now I got no error already. But I still can't trasnfer the bitmap to the client though, when I click the send button, It was like the program is going to not responding. No error and no result.

The scenario is something like this, from the server application, I start the webcam, and copy a piece of frame from the picturebox which I save it as bitmap. Then, the bitmap I pass it through two classes before I can send the bitmap to the socket.

The sending part for the moment is like this:
Public Sub SendCam(ByVal msgTag As Byte, ByVal bmp As Bitmap)
        Dim arrImage() As Byte
        Dim ms As New MemoryStream
        bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp)
        Dim r As New BinaryReader(ms)

        SyncLock client.GetStream
            Dim w As New BinaryWriter(client.GetStream)

            w.Write(RequestTags.Cam)

            w.Write(msgTag)

            arrImage = ms.GetBuffer()

            w.Write(arrImage, 0, ms.Length)
			
            w.Flush()
        End SyncLock
End Sub


And the receiving part for the current moment:
Case RequestTags.Cam
                SyncLock client.GetStream
                    r = New BinaryReader(client.GetStream)

                    client.GetStream.Read(readByte, 0, 1)
                    passThroughByte = readByte(0)
                    'next expect length of data (Int32)
                    nData = r.ReadInt32
                    lenData = nData
                    'now comes the data, save it in a memory stream
                    mStream = New MemoryStream

                    While nData > 0
                        lData = client.GetStream.Read(readBuffer, 0, PACKET_SIZE)
                        mStream.Write(readBuffer, 0, lData)
                        nData -= lData
                    End While
                    'Continue the asynchronous read from the NetworkStream
                    Me.client.GetStream.BeginRead(readByte, 0, 1, AddressOf ReceiveOneByte, Nothing)
                End SyncLock
                'once all data has arrived, pass it on to the end user as a stream

                RaiseEvent VideoReceived(Me, passThroughByte, mStream)
                mStream.Dispose()


I want to make the bitmap sending and receiving like normal video call, but running out of idea on how to get it works.

Any help, thanks.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9570
  • View blog
  • Posts: 36,240
  • Joined: 12-June 08

Re: Sending & receiving bitmap from networkstream

Posted 12 May 2011 - 07:46 AM

Quote

I want to make the bitmap sending and receiving like normal video call, but running out of idea on how to get it works.


Now I am confused. In your OP you said you were getting an error, but now you are not? If that's not the issue then can you elaborate what do you mean by "like normal video call"? How is your error free application *not* operating like a normal video call? Is no signal being received? Choppy? Out of focus? out of sync? There's a myriad of ways it could be malfunctioning.
Was This Post Helpful? 0
  • +
  • -

#5 theotherguy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 05-April 11

Re: Sending & receiving bitmap from networkstream

Posted 12 May 2011 - 07:59 AM

View Postmodi123_1, on 12 May 2011 - 07:46 AM, said:

Now I am confused. In your OP you said you were getting an error, but now you are not? If that's not the issue then can you elaborate what do you mean by "like normal video call"? How is your error free application *not* operating like a normal video call? Is no signal being received? Choppy? Out of focus? out of sync? There's a myriad of ways it could be malfunctioning.

My bad, let me explain, in OP, I was getting error and now already fixed that part.
Normal video call in my view is I can send and view the bitmap to client application almost realtime, just like having a video call, only thing is the video call I'm trying to make is running within a LAN.

It's not error free, i can't send the bitmap through yet.

Thanks.
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9570
  • View blog
  • Posts: 36,240
  • Joined: 12-June 08

Re: Sending & receiving bitmap from networkstream

Posted 12 May 2011 - 08:09 AM

Again - so what is the problem? It's not working? It's choppy? You can't find the recipient on the LAN? Explain to me what it is doing versus what it should be doing.

This post has been edited by modi123_1: 12 May 2011 - 08:09 AM

Was This Post Helpful? 0
  • +
  • -

#7 theotherguy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 05-April 11

Re: Sending & receiving bitmap from networkstream

Posted 12 May 2011 - 08:17 AM

View Postmodi123_1, on 12 May 2011 - 08:09 AM, said:

Again - so what is the problem? It's not working? It's choppy? You can't find the recipient on the LAN? Explain to me what it is doing versus what it should be doing.

It's not working. I can connect to the client and do normal text and other file transfer but not the cam capture transfer. I suspect the problem is between the sending and receiving parts, but I don't understand what went wrong in there.
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9570
  • View blog
  • Posts: 36,240
  • Joined: 12-June 08

Re: Sending & receiving bitmap from networkstream

Posted 12 May 2011 - 08:21 AM

Ah.. gotcha. Let me think about it for a bit.
Was This Post Helpful? 0
  • +
  • -

#9 theotherguy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 05-April 11

Re: Sending & receiving bitmap from networkstream

Posted 13 May 2011 - 12:46 PM

I have succesfully send and receive bitmap, but only 1 on 1, can't do simultaneous bitmap sending yet, and I was expecting something like pop-up a preview window for webcam, whenever somebody runs a video call and still can't do that too. :(
Was This Post Helpful? 0
  • +
  • -

#10 _HAWK_  Icon User is online

  • Master(Of Foo)
  • member icon

Reputation: 1065
  • View blog
  • Posts: 4,170
  • Joined: 02-July 08

Re: Sending & receiving bitmap from networkstream

Posted 13 May 2011 - 12:54 PM

Here's something to think about. Your sending each capture via TCP and I think you would get better speed with UDP. We don't care if every transmission makes it and most will anyway. It's known to be faster and that's why gamer use it.
Was This Post Helpful? 1
  • +
  • -

#11 theotherguy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 05-April 11

Re: Sending & receiving bitmap from networkstream

Posted 13 May 2011 - 01:10 PM

View Posthawkvalley1, on 13 May 2011 - 12:54 PM, said:

Here's something to think about. Your sending each capture via TCP and I think you would get better speed with UDP. We don't care if every transmission makes it and most will anyway. It's known to be faster and that's why gamer use it.

Thanks for reply. But I have already established a TCP connection, and need to be maintained until the application close. Is it possible to have both TCP and UDP connection at once?
Was This Post Helpful? 0
  • +
  • -

#12 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1820
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: Sending & receiving bitmap from networkstream

Posted 13 May 2011 - 01:12 PM

You have to establish UDP for speed and performance since it is a video chat like it needs speed to perform its work>
Was This Post Helpful? 1
  • +
  • -

#13 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9570
  • View blog
  • Posts: 36,240
  • Joined: 12-June 08

Re: Sending & receiving bitmap from networkstream

Posted 13 May 2011 - 01:32 PM

Random question - why are you working on a bit map by bitmap process? Things like DirectShow and what not would seem to make this bit more simpler and more polished off the bat.
Was This Post Helpful? 0
  • +
  • -

#14 theotherguy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 05-April 11

Re: Sending & receiving bitmap from networkstream

Posted 13 May 2011 - 01:40 PM

Hmm, yeah, for audio and video will be better by UDP. But, the current problem is not that. I can broadcast my server's cam capture to the clients, but clients won't be able to send their cam capture. Because that will cause me to create a lot of picturebox controls and my interface will be a mess. :(

Even the code, I don't know how a server which send cam to both client1 and client2, will be able to receive both client1 and client2 cam capture and differentiate them, like knowing that the picturebox2 will output only client1 cam capture, and picturebox3 will output only client2 cam capture. Picturebox1, 2, and 3 I meant here is on the server application.

Any thought? :(

View Postmodi123_1, on 13 May 2011 - 01:32 PM, said:

Random question - why are you working on a bit map by bitmap process? Things like DirectShow and what not would seem to make this bit more simpler and more polished off the bat.


Hmm, I thought bitmap will be much simpler. Am I wrong?
Was This Post Helpful? 0
  • +
  • -

#15 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9570
  • View blog
  • Posts: 36,240
  • Joined: 12-June 08

Re: Sending & receiving bitmap from networkstream

Posted 13 May 2011 - 01:44 PM

Well there's simple and then there's optimized simple.

Example:
http://www.codeproje...ectShowNET.aspx
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1