Click here to Skip to main content
Click here to Skip to main content

VideoNet

, 29 Jun 2004
Rate this:
Please Sign up or sign in to vote.
Peer to peer video conference application.

Introduction

This application allows any 2 persons on the LAN/Intranet (possibly Internet too) to have video conference. There are several video conference applications existing today. Each has its own performance enhancement techniques. The major problem in video conference is that the size of video frames is too big for transmission. Hence the performance is based on the codec used for encoding and decoding the frame. I am using Fast h263 Encoder library which gives 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 which I have used in my previous voice conference application. Here, I will provide a brief overview of how to use this 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 OnSoundData 
// callback function of 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

Video capture is done using VFW (Video For Windows) API. It provides support for capturing the video from web cam. VideoCapture.h and VideoCapture.cpp are the files which contain the code for 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 
// main dialog class when the frame is captured... 
vidcap->SetDialog(this); 


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


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

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

// Once capture started frames will arrive in callback function 
// "OnCaptureVideo" of VideoCapture class.Here you call 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 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 SetDIBitsToDevice() method to directly display the frame. But this is quite slow as it is based on 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 provide better performance.

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

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

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

// Now if you are ready with 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 fast h.263 encoder library for the encoding. This library was the modified version of Tmndecoder to make it more faster for real time encoding. I have converted this library from C to C++ so that it can be integrated into any Windows application easily. I have removed some of the unnecessary codes/files from the fast h263 library. Also 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 then 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 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 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 into C++ so that it can be integrated into any Windows application. I have removed some of the files which had display and file storing functions. I have removed the unnecessary code and also added some new files.

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

Usage of 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 into 2 different machines A & B which are on LAN. Run both the applications. From machine A (or B), select Connect menu item, and in the popup dialog box, enter the name or IP Address of the other host (B), and press Connect button. In the other machine (B), Accept/Reject dialog box will appear. Press Accept button. In the machine A, notification dialog box will get displayed. Press OK to begin the conference.

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

Acknowledgement

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

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

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Nagareshwar
Web Developer
India India
Nagareshwar is a security enthusiastic person involved in reverse engineering, vulnerability research, coding security tools etc. He spend most of the time in uncovering the secrets of computer world.
 
He holds 'Bachelor of Engineering' degree from National Institute of Technology of Karnataka, India. He had professional experience of 2.5 years in Novell. At Novell he was working on various security products including 'Novell Secure Login' and CASA.
 
For more details visit his website http://securityxploded.com

Comments and Discussions

 
QuestionHELP Pinmembershaima'18-Sep-13 22:01 
QuestionC# Pinmemberzezo14979-Apr-13 14:47 
Questionbug in GetPic.cpp PinmemberPeter Eugene Coleman15-Jan-13 23:19 
GeneralERROR : MFC application stopped working Pinmemberfayyu.5u26-Nov-10 21:20 
Generalcan't work on windows7 Pinmemberhzbinger19-Feb-10 19:35 
GeneralRe: can't work on windows7 PinmemberPhalgun2511-Apr-10 9:09 
QuestionCompile Error Pinmembernew_test_codeproject19-Jun-09 1:40 
AnswerRe: Compile Error Pinmemberfrankcch12349-Sep-09 14:44 
Questionh.263 compressed size of 1 frame?? Pinmemberk-guys28-Apr-09 16:58 
QuestionCan you help me saving the video conferencing Pinmembernadine-bd29-Dec-08 23:14 
QuestionModification for Internet PinmemberAngel Kafazov21-Nov-08 2:16 
AnswerRe: Modification for Internet PinmemberPeter Eugene Coleman15-Jan-13 23:09 
Generalmulti video conferencing Pinmemberssribalamurugan3-Nov-08 1:33 
QuestionProblems resizing video PinmemberNeil Ellerington1-Oct-08 12:07 
AnswerRe: Problems resizing video Pinmemberzhuchang0073-Aug-09 23:57 
QuestionCan I use it in an open source project? Pinmembertriplebit25-Aug-08 11:46 
GeneralI can't donwload the source code! PinmemberMember 317102319-Aug-08 4:03 
QuestionVS 2005 compiler error PinmemberTouchdownsBundy30-Jul-08 1:04 
AnswerRe: VS 2005 compiler error Pinmember52yinjin13-Jul-10 15:45 
Generaldecode H263 frame from 'output.263' file PinmemberDamon__8330-Jun-08 3:32 
GeneralThanks a lot. Pinmemberkevin7892-Jun-08 17:33 
Question[Message Deleted] Pinmembernsh_enp16-Apr-08 23:11 
GeneralRe: May I use VideoNet for commercial purposes ? PinmemberThanks for all the fish25-Apr-08 9:07 
GeneralYUV Display Pinmembershiva shankar8-Apr-08 1:56 
GeneralTo make this work on internet PinmemberThanks for all the fish22-Mar-08 12:33 
GeneralInternet PinmemberThanks for all the fish14-Mar-08 6:57 
GeneralRemote Screen not displayed Pinmembermanish.patel11-Mar-08 2:44 
GeneralImage Size in Decoder PinmemberMember 32241118-Mar-08 22:31 
Generalconversion in C# PinmemberMember 32241114-Mar-08 19:38 
Generalmotion compensation PinmemberMember 32241114-Mar-08 17:48 
GeneralPorting to PocketPC PinmemberAmilan15-Feb-08 7:57 
QuestionPink image when using inter frames? PinmemberSvetoslav Chekanov9-Feb-08 10:35 
AnswerRe: Pink image when using inter frames? PinmemberSvetoslav Chekanov20-Feb-08 4:41 
Generalvideo conference over internet.... Pinmembersudhi.sudarshan6-Feb-08 23:15 
GeneralCPARAM_SQCIF is useless? [modified] Pinmemberpagesen17-Jan-08 14:30 
Questionvideonet using C# ????? PinmemberDHAVAL LKAHANI10-Jan-08 2:21 
GeneralException when recompile in VC++ 6.0 Pinmembernice_fox5-Dec-07 1:27 
GeneralRe: Exception when recompile in VC++ 6.0 Pinmembernice_fox6-Dec-07 6:44 
Questionplz help URGENTLY Pinmemberanoshia18-Nov-07 20:36 
QuestionChange resolution to CPARAM_CIF PinmemberLTHOOI_MY27-Sep-07 23:17 
AnswerRe: Change resolution to CPARAM_CIF [modified] Pinmemberprecozzi17-Oct-07 22:28 
GeneralRe: Change resolution to CPARAM_CIF Pinmembercaptainc/c++25-Nov-07 23:53 
QuestionXP Incompatibily problem Pinmembergeorgestef17-Sep-07 1:09 
AnswerRe: XP Incompatibily problem PinmemberNagareshwar17-Sep-07 2:01 
QuestionThanks a lot [modified] Pinmembergeorgestef20-Sep-07 2:02 
AnswerRe: Thanks a lot PinmemberNagareshwar20-Sep-07 4:45 
Question??? Pinmemberparksi31-Aug-07 2:24 
Questionquestion about Lan Pinmemberaket160224-Jul-07 3:25 
Generalplease send to me the Document Pinmemberlenam32826-May-07 12:22 
QuestionVideo in 4CIF Pinmemberdjin942-Apr-07 5:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 30 Jun 2004
Article Copyright 2004 by Nagareshwar
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid