Solved

Stream video or Jpeg across internet

Posted on 2001-07-03
13
874 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses
Course of the Month4 days, 13 hours left to enroll

635 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