Solved

Stream video or Jpeg across internet

Posted on 2001-07-03
13
849 Views
Last Modified: 2008-03-17
I want to be able to stream video (PVIDEOHDR) or jpeg  across the internet.

I have some code working (using socket components), but the full jpeg is not getting delivered. across the internet maybe only 10% of the picture is "decoded" correctly, over a local lan (10 speed), if i make the compression of the jpeg 50% or less, it displays correctly, anything above that gives jpeg error #52 on the client end.

Dropping the frame rate seems to have no effect on the display, can anyone give me working code ?.

PS : I am using the TVideoCap Version 2.3 component to capture the video at the server end.
0
Comment
Question by:justcomputers
  • 6
  • 6
13 Comments
 
LVL 13

Expert Comment

by:Epsylon
ID: 6247951
I have 2 examples of sending a stream over TCP/IP. One is non-blocking the other is blocking (faster but more difficult). They both transfer files but it won't be difficult to have it loading a jpeg (or something else) from memory into a stream and transfer that.
0
 

Author Comment

by:justcomputers
ID: 6249065
Can you post the code here or email it as an attatchment so i can see if it works ?.

Thanks.

Alternativley i can post my code here, then you can see where my code is faulty.


0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6249766
Post to where..?

If it's not too big the show me your code.
0
 

Author Comment

by:justcomputers
ID: 6250046
Post to experts-exchange if possible.

OK here is my code.

******************** client socket read **************
procedure TForm1.ClientSocketRead(Sender: TObject;
  Socket: TCustomWinSocket);
var
 Memorystream: TMemoryStream;
 JPEG : TJPEGImage;
 Buffer: Array[0..10000] of byte;
 Received: Integer;
begin

     try

             MemoryStream := TMemoryStream.Create;
             Received := socket.ReceiveBuf(Buffer, sizeof(Buffer));
             Memorystream.Write(Buffer,Received);
             Memorystream.Seek(0,0);
             cledit2.Text := inttostr(Received);
             JPEG := TJpegImage.Create;

              try
                        JPeg.LoadFromStream(MemoryStream);
              except;
                        exit;
                {Ive placed this exception here just to get rid of those annoying messgaes}
              end;

             Image1.Width:= JPEG.Width;
             CLEditImageHeight.Text := inttostr(JPEG.Height);
             CLEditImageWidth.Text := inttostr(JPEG.Width);
             Image1.Height:= JPEG.Height;
             image1.Picture.Assign(Jpeg);


     finally

             Memorystream.free;
             Jpeg.free;
     end;

     end;

*****************  end of client socket read ************




******  start of onvideostream event of videocap *********


procedure TForm1.VideoCap1VideoStream(sender: TObject; lpVhdr: PVIDEOHDR);
var Bitmap:TBitmap;
    info:TBitmapInfo;
    j : TJPegImage;
    MemoryStream:  TMemoryStream;
begin

try


       
        inc(Frames);
        Editframes.text := inttostr(Frames);


        j:=TJPegImage.create;
        info:= videocap1.BitMapInfo;

        Bitmap:=TBitmap.Create;

       
        frameToBitmap(Bitmap,lpvhdr^.lpData,Info);


        j.assign(Bitmap);
        J.CompressionQuality :=CompressionValue;// Anything above 50 causes corruption

        J.Compress;
        Image1.Picture.Assign(J);
        MemoryStream := TMemoryStream.Create;
        Memorystream.Seek(0,0);
        J.SaveToStream(MemoryStream);
        Memorystream.Seek(0,0);
        ServerSocket.Socket.Connections[0].sendstream(MemoryStream);
finally;

        J.free;
        Bitmap.free;
end;
end;

0
 

Expert Comment

by:bloodline
ID: 6250423
//Bloodline Listening
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6250707
Hi, the way you receive the packets is not right. It seems that everyone makes the same mistakes  ;o)

The best thing you should do is sending the number of bytes to send first. This is because the receiving part can get multiple OnRead events. This means that the first packet contains the size (let's say 4 or 8 bytes) and some data. The second packet has more data and so on until the number of received bytes equals the size received at the beginning of the first packet.
If you are sending a continuous stream of data (e.g. multiple image), you must take into account that the size of the n-th image can be in the middle of a packet. So if image n-1 has been received, don't throw away the date after the last byte of image n-1.
Use some FIFO queue or something like that during the life of the connection.

I hope this clears things up a little.
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:justcomputers
ID: 6251612
Yes, it's more or less what i had guessed at, but do you have any example code, i cant find any examples to work from, and this is my first time working with sockets.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6251853
0
 
LVL 13

Accepted Solution

by:
Epsylon earned 200 total points
ID: 6261782
Hello?
0
 

Author Comment

by:justcomputers
ID: 6262154
Thanks for the examples, i only got an email telling me of your post on Sunday morning @ 08:00, i am looking at the code now, and will get back within a day or 2, but it certainly looks like you will be getting the points.

Thanks very much for your help.
0
 

Author Comment

by:justcomputers
ID: 6262869
Thanks Epsylon, your code did the trick so here are the points, thanks very much once again, you are a star.

PS :- Do you know where i can find decent documentation explaining sockets, and how your code works.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6262916
So far I haven't found any good documentation for Delphi's components. Most of it I found out myself using the knowlegde I have since 1990.

delphi.about.com has a search engine which is the best option I can think of right now.
0
 

Author Comment

by:justcomputers
ID: 6263290
OK Thanks
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now