VideoNet: Peer to Peer Video Conference Application

This application allows any two persons on the LAN/Intranet (possibly the Internet) to have a video conference. There are several video conference applications that exist today. Each has its own performance enhancement techniques. The major problem in video conferencing is that the size of the video frame is too big for transmission. Hence, the performance is based on the codec used for encoding and decoding the frame. I am using the Fast h263 Encoder library that gives a better compression rate at high speed. This application can also be used on the Internet with little modification.

Recording and Playing Audio

I have used the same RecordSound and PlaySound classes that I have used in my previous voice conference application. Here, I will provide a brief overview of how to use the RecordSound and PlaySound classes.

// Create and Start Recorder Thread
   record=new RecordSound(this);
   record->CreateThread();


// Create and Start Player Thread
   play=new PlaySound1(this);
   play->CreateThread();


// Start Recording
   record->PostThreadMessage(WM_RECORDSOUND_STARTRECORDING,0,0);


// Start Playing
   play->PostThreadMessage(WM_PLAYSOUND_STARTPLAYING,0,0);


// During audio recording, data will be available in the OnSoundData
// callback function of the RecordSound class. Here, you can place
// your code to send the data to remote host...


// To play the data received from the remote host
   play->PostThreadMessage(WM_PLAYSOUND_PLAYBLOCK,size,(LPARAM)data);


// Stop Recording
   record->PostThreadMessage(WM_RECORDSOUND_STOPRECORDING,0,0);


// Stop Playing
   play->PostThreadMessage(WM_PLAYSOUND_STOPPLAYING,0,0);


// At last, to Stop the Recording Thread
   record->PostThreadMessage(WM_RECORDSOUND_ENDTHREAD,0,0);


// To stop playing thread...
   play->PostThreadMessage(WM_PLAYSOUND_ENDTHREAD,0,0);

Video Capture

VideoCapture is done using the VFW (Video For Windows) API. It provides support for capturing the video from a webcam. VideoCapture.h and VideoCapture.cpp are the files that contain the code for the complete video capture process.

Here are the brief details of how to use this class:

// Create instance of Class
   vidcap=new VideoCapture();


// This is later used to call display function of the main
// dialog class when the frame is captured...
   vidcap->SetDialog(this);


// This does lot of work, including connecting to the driver
// and setting the desired video format. Returns TRUE if
// successfully connected to videocapture device.
   vidcap->Initialize();


// If successfully connected, you can get the BITMAPINFO
// structure associated with the video format. This is later
// used to display the captured frame...
   this->m_bmpinfo=&vidcap->m_bmpinfo;


// Now you can start the capture....
   vidcap->StartCapture();


// Once capture is started, frames will arrive in the "OnCaptureVideo"
// callback function of the VideoCapture class. Here you call the
// display function to display the frame.


// To stop the capture
   vidcap->StopCapture();


// If your job is over....just destroy it..
   vidcap->Destroy();

If you do this much work, your code will compile well, but the linker will trouble you. You must link the suitable libraries.

#pragma comment(lib,"vfw32")
#pragma comment(lib,"winmm")

Displaying the Captured Video Frame

There are various methods and APIs for displaying the captured frame. You can use the SetDIBitsToDevice() method to directly display the frame. But, this is quite slow because it is based on the Graphics Device Interface (GDI) functions. The better method is to use DrawDib API to draw the frame. The DrawDib functions provide high performance image-drawing capabilities for device-independent bitmaps (DIBs). DrawDib functions write directly to video memory, hence providing better performance.

Here is the brief view of how to use DrawDib API to display a frame.

// Initialize DIB for drawing...
   HDRAWDIB hdib=::DrawDibOpen();


// Then call this function with suitable parameters....
   ::DrawDibBegin(hdib,...);


// Now, if you are ready with the frame data, just invoke this
// function to display the frame
   ::DrawDibDraw(hdib,...);


// Finally, termination...
   ::DrawDibEnd(hdib);
   ::DrawDibClose(hdib);

Encoder and Decoder Library

Encoder

I have used the fast h.263 encoder library for the encoding. This library was a modified version of Tmndecoder to make it faster for real-time encoding. I have converted this library from C to C++ so that it can be integrated easily into any Windows application. I have removed some of unnecessary codes/files from the fast h263 library and moved definitions and declarations in their proper .h and .cpp files.

Brief view of usage of H263 Encoder library:

// Initialize the compressor
   CParam cparams;
   cparams.format = CPARAM_QCIF;
   InitH263Encoder(&cparams);



//If you need conversion from RGB24 to YUV420, call this
   InitLookupTable();



// Set up the callback function
// OwnWriteFunction is the global function called during
// encoding to return the encoded data...
   WriteByteFunction = OwnWriteFunction;



// For compression, data must be in the YUV420 format...
// Hence, before compression, invoke this method
   ConvertRGB2YUV(IMAGE_WIDTH,IMAGE_HEIGHT,data,yuv);


// Compress the frame.....
   cparams.format  = CPARAM_QCIF;
   cparams.inter   = CPARAM_INTRA;
   cparams.Q_intra = 8;
   cparams.data=yuv;    //  Data in YUV format...
   CompressFrame(&cparams, &bits);


// You can get the compressed data from the callback function
// that you have registerd at the begining...


// Finally, terminate the encoder
// ExitH263Encoder();

Decoder

This is the modified version of tmndecoder (H.263 decoder). It was in ANSI C. I have converted it to C++ so that it can be integrated into any windows application. I have removed some of the files that had display and file storing functions. I have removed the unnecessary code and also added some new files.

The original library dealt with files. It was not suitable to use for real-time decoding. I have made some major changes so that it can be easily integrated into the application for a real-time decoding process. Now, one can use this library to decode H263 frames. This library is quite fast and gives better performance.

Usage of the Decoder .....

//Initialize the decoder
   InitH263Decoder();


// Decompress the frame....
// > rgbdata must be large enough to hold the output data...
// > decoder produces the image data in YUV420 format. After
//   decoding, it is converted into RGB24 format...
   DecompressFrame(data,size,rgbdata,buffersize);


// Finaly, terminate the decoder
   ExitH263Decoder();

How to Run the Application

Copy the executable file onto two different machines, A & B, thath are on LAN. Run both the applications. From machine A (or B), select the connect menu item and in the popup dialog box enter the name or IP Address of the other host(B) and press the connect button. On the other machine (B), an accept/reject dialog box will appear. Press the accept button. On machine A, a notification dialog box will be displayed. Press OK to begin the conference.

That's it....Enjoy......!!!

Acknowledgements

I would like to thank Paul Cheffers for his audio recording and playing sound classes. You are seeing this videonet application here because of Opensource libraries contributed by Openminded persons. I am grateful to developer Karl Lillevold of Tmndecoder and Roalt Aalmoes of the h.263 fast encoder library for making it free.

If you have any queries or suggestions, plese feel free to mail me at nsry2002@yahoo.co.in.



Downloads

Comments

  • help me converting this code

    Posted by judjo on 01/27/2012 02:10am

    how to translate into C #?
    how to get the id name not the IP?
    how to add the date, day and hour in the chat box panel?
    how to give a variable name in the local and remote screen secreen?

    Reply
  • HOW CAN I CONVERT THE CODE TO C#? .... HELP PLZ

    Posted by SCANIA8 on 05/23/2006 06:49am

    HEY GUYS I HAVE A PROBLEM CONVERTING THIS CODE TO C# SO IF ANYONE CAN HELP PLZ AS SOON AS POSSIBLE

    Reply
  • change video resolution and audio compression level

    Posted by wilgrass1 on 02/10/2006 08:17am

    Hi,
    I try to change video resolution (ex: 320x240) and audio compression, but i have many problemes.
    Could you explain me how can i do it, and what are all possible format in Audio compression and video resolution?
    You can email me at wgrassi@free.fr
    
    Thanks a lot ...

    Reply
  • Need help in Converting this code into Group Video Conferencing

    Posted by zalmaygul on 07/26/2005 02:27am

    Please help me convert this code into group Video Conferencing without the use of multicasting.
    I m quite new to VC++ and I don't know where to start from.
    Please a guide me a bit to start my work
    Zalmay Gul

    • eed help in Converting this code into Group Video Conferencing

      Posted by alirio on 01/23/2008 11:31am

      Please help me convert this code into group Video Conferencing without the use of multicasting. I m quite new to VC++ and I don't know where to start from. Please a guide me a bit to start my work

      Reply
    Reply
  • Need help in Converting this code into Group Video Conferencing

    Posted by zalmaygul on 07/26/2005 02:17am

    Please help me convert this code into group Video Conferencing without the use of multicasting.
    I m quite new to VC++ and I don't know where to start from.
    Please a guide me a bit to start my work
    Zalmay Gul

    Reply
  • VCM vs. h263

    Posted by SohailB on 06/18/2005 04:51am

    I was using your code to develope a video conferencing dll, when I noticed problems in decompressing the received frames. I guess the problem is with the global functions and the static data. Searching more I could not find any neat implementaion of h263 (with classes). The question is why should bother to use h263, and what does it do more than normal VCM codecs?

    Reply
  • Video Conference Measurement Software ?

    Posted by jizdan on 05/11/2005 12:56am

    dear mr sorry,my english is poor. Dear Mr, I want to know about performance this application, for example fps, bit rate, bit commpression, video format, etc. What is the software can me used ? Thank's

    Reply
  • Memory Leak

    Posted by danuvius on 03/15/2005 11:36am

    Found a memory leak in your code. Add in the file libr263.cpp in the function ExitH263Encoder the line: FreeHuff();

    • Thanks

      Posted by nsry on 03/17/2005 09:19am

      I will fix it and update soon... Thanks

      Reply
    Reply
  • The application will not close if it is not disconnected

    Posted by sklim on 12/06/2004 04:31am

    Hi, your project really help me a lot. During the code modification, I found that the application still running though the UI is closing when user close the application without disconnect it. Can you help me to figure it out? Thanks. I am running using VC++ .NET but I think this is not the reason because the provided demo also have this problem.

    Reply
  • Compilation error indicated by \Debug\VideoNet.pch

    Posted by Locutus01 on 12/01/2004 04:34am

    Hi,
    I have a problem compiling the project under VS.NET 2003.
    
    The error is 
    fatal error C1852: '.\Debug/VideoNet.pch' is not a valid precompiled header file
    
    Now if i change the setting in the Precompiled Headers section of the project properties, 9 other errors surfaced,
    
    error C2440: 'static_cast' : cannot convert from 'LRESULT (__thiscall RecordSound::* )(WPARAM,LPARAM)' to 'void (__thiscall CWinThread::* )(WPARAM,LPARAM)'
    
    The errors only happen for the RecordSound.cpp and PlaySound.cpp
    
    
    Is this a problem with me using VS.NET? or am I missing something? Sorry for asking such a question :) as I am quite a newbie in this.
    
    If someone has a solution for this i would be very greatful Thanks.

    • How i can try?

      Posted by robby72 on 07/10/2005 11:54am

      sklim,please, could explain me how you have modified the code??

      Reply
    • Can try

      Posted by sklim on 12/06/2004 02:41am

      I faced this problem also and solved it by changed the LRESULT to void for the function and also the declaration of the function.

      Reply
    • You can try this.......

      Posted by nsry on 12/01/2004 05:00am

      Since it has designed with VS6.0 ...some changes are required in case of .net version.. But this is common error..."not valid header file" Do the rebuild once again....it will resolve... For the problem with record sound and playsound.cpp you may have to do some other changes...i am not aware of...

      Reply
    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • As all sorts of data becomes available for storage, analysis and retrieval - so called 'Big Data' - there are potentially huge benefits, but equally huge challenges...
  • The agile organization needs knowledge to act on, quickly and effectively. Though many organizations are clamouring for "Big Data", not nearly as many know what to do with it...
  • Cloud-based integration solutions can be confusing. Adding to the confusion are the multiple ways IT departments can deliver such integration...

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date