Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Stream video or Jpeg across internet

Posted on 2001-07-03
13
Medium Priority
?
888 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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
 

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

Accepted Solution

by:
Epsylon earned 800 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

721 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