PDA

View Full Version : Streaming Web cam Video In Both Party



Peter_APIIT
5th December 2009, 06:43
Hello to all, i need to develop an application that does VOIP call. In the same time, i need to send video capture from web cam to the callee.

I using pjlib for VOIP and QT for GUI.

http://nashruddin.com/Streaming_Open...k#introduction

I have this resources.

Do we need another thread for web cam frame grabber and one thread for voip calling ?

My task is to discover the callee IP using SIP URI register to public server. Then, i send the web cam to the calless' address.
How to discover IP after VOIP call of caller and callee ?

This is my final year project.

Please suggest the tool to use or idea to start.
I wonder does anyone do this before.
I plan to do this in Qt using QThread and QTcpSocket. Is this possible ? If yes, how to code ?



class InteractiveMultiTouchCommunicationSystem : public QMainWindow
{
private:
Q_OBJECT

public:
InteractiveMultiTouchCommunicationSystem(QWidget *parent = 0, Qt::WFlags flags = 0);
~InteractiveMultiTouchCommunicationSystem();

protected:

// Show Context Menu created by createStandardContextMenu();
// Event paramenet used to identify where mouse position event generated
// Implement KeyBoard shortcut Event
void contextMenuEvent(QContextMenuEvent* );

//private SIGNAL:

//

// SLOT
private slots:

// Main Slot
void VOIPLogSlot();
void VOIPCallRedialSlot();
void VOIPCallRecordSlot();
void VOIPCallRecordValidateSlot();
void VOIPCallHoldSlot();
void VOIPCallReInvite();
void VOIPCallTransferSlot();

void VOIPConfigSlot();

void AddContactSlot();
void DeleteContactSlot();
void ManageContactSlot();

void VOIPHistorySlot();

void AboutSlot();
void AboutQTSlot();


// Slot for Child Widget


// VOIP Widget Slot
void VOIPCallSlot();
void VOIPHUSlot();
void DialPadSlot();


// VOIP Config Dialog Slot
// First Tab
void SIPSaveSlot();
void SIPAddSlot();
void SIPEditSlot();
void SIPRemoveSlot();

// Second Tab
void NetworkSettingsSaveSlot();
void NetworkSettingsDefaultSlot();

// Third Tab


// Add Contact Dialog Slot
void AddContactDlgSlot();

// Delete Contact Dialog Slot
void DeleteContactDlgSlot();

private:

Ui::InteractiveMultiTouchCommunicationSystemClass ui;

// ToolBar
QToolBar* myTB;

// Menu
QMenu* VOIPMenu;
QMenu* ConfigurationMenu;
QMenu* HistoryMenu, *NestedVOIPMenu;
QMenu *ContactsMenu, *HelpMenu, *ExitMenu;

// Action
QAction* VOIPInfoAct, *VOIPRedialAct,
*VOIPRecordAct, *VOIPHoldAct,
*VOIPReinviteAct, *VOIPTransferAct;

QAction* VOIPConfigAct;
QAction* IncomingVOIPHistoryAct,
*OutgoingVOIPHistoryAct, *MissedVOIPHistoryAct,
*ReceivedVOIPHistoryAct;

QAction* AddContactAct, *DeleteContactAct,
*ManageContactAct;

QAction* AboutAct, *AboutQTAct;
QAction* ExitAct;


// Child Widget Component
// Selection Widget/Dialog/GO
QWidget* VOIPWgt, *IMWgt, *SMSWgt;
QDialog* VOIPConfigDlg, *AddContactDlg,
*DeleteContactDlg, *ManageContactDlg;

// VOIP Widget Component
QLineEdit* display;
QPushButton* call, *hangup, *One, *Two, *Three,
*Four, *Five, *Six, *Seven, *Eight, *Nine,
*DotSign, *Zero, *Hash;
QErrorMessage* errorMsg;

// VOIP Log Dialog Component
QDialog* VOIPDebugDlg;
QTextEdit* logText;

// VOIP Call Record Widget Componenet
QDialog* CallRecordFileNameDlg;
QLabel* fileName;
QLineEdit* fileNameLE;
QPushButton* confirm;
QMessageBox* msgBox;

// VOIP Configuration Dialog Component
QLabel* UserInfo, *Username, *SIPAdd,
*SIPAccount, *Ports, *SIPPort, *audioVideoPort,
*NAT, *StunServer;
QLineEdit* usernameLE, *SIPAddLE, *StunServerLE;
QPushButton* Save, *AddSIPAcc, *EditSIPAcc,
*RemoveSIPAcc, *SaveBtn, *DefaultBtn;
QSpinBox* PortSB, *audioVideoSB ;
QRadioButton* DirectConn, *RouterConn;

// Third Tab
QLabel* SIPContacts, *SIPAddress, *SIPContactList;
QLineEdit* SIPURIAddLE;
QPushButton* saveContact, *EditSIPAdd,
*RemoveSIPAdd;


// Add Contact Dialog Component
QLabel* contactInfo, *Instruction,
*myEmail;
QLineEdit* myEmailLE;
QPushButton* OK, *Cancel;

// Delete Contact Dialog Component
QLabel* theContactInfo, *theInstruction,
*theEmail;
QComboBox* myEmailCB;
QPushButton* Delete, *Reset;



// Private Function
void Init();

void createAction();
void createMenu();
void createToolBar();

void createVOIPWidget();

void createVOIPConfigDlg();

void createAddContactDlg();
void createDeleteContactDlg();
void createManageContactDlg();


// Utility Function
bool ValidateSIP(const std::string&, bool&, int&) const;




// =================== VOIP ====================
public:

typedef boost::shared_ptr<VOIP> VOIPPtr;

private:

VOIPPtr obj;

};




And this is my openCV Video streaming code.



class OpenCVQT : public QWidget
{
Q_OBJECT

public:
typedef unsigned char uchar;

public:
OpenCVQT(QWidget *parent = 0, Qt::WFlags flags = 0);
~OpenCVQT();

void operator()();

void StreamCamera();

void InitCam();
void ConvertImage();
void CreateQImage();
void SetDisplayImage();

private:
Ui::OpenCVQTClass ui;
QLabel* myLabel;
QVBoxLayout* mainLayout;

private:
CvCapture* myCaptureHandler;
IplImage* myOriginalIplImage, *myRGBIplImage;
QImage myQImage;
uchar* ImageData;

void CreateImage();
};

OpenCVQT::OpenCVQT(QWidget *parent, Qt::WFlags flags)
: QWidget(parent, flags),
myCaptureHandler(),
myOriginalIplImage(&IplImage() ),
myRGBIplImage(&IplImage() ),
myQImage(QImage()),
ImageData()
{
ui.setupUi(this);
myLabel = new QLabel;
mainLayout = new QVBoxLayout;

mainLayout->addWidget(myLabel);
this->setLayout(mainLayout);

myCaptureHandler = cvCreateCameraCapture(0);
myOriginalIplImage = cvCreateImage(cvSize(320, 480),
IPL_DEPTH_8U, 3);
myRGBIplImage = cvCloneImage(myOriginalIplImage);

}
// =============================================
OpenCVQT::~OpenCVQT()
{
}
// =============================================
void OpenCVQT::StreamCamera()
{
//InitCam();

//while (1)
{
myRGBIplImage = cvQueryFrame(myCaptureHandler);
//cvNamedWindow("OpenCV");
//cvShowImage("OpenCV", myRGBIplImage);
ConvertImage();
CreateQImage();
//SetDisplayImage();
myLabel->setPixmap(QPixmap::fromImage(myQImage) );

}
}
// =============================================
void OpenCVQT::InitCam()
{
myCaptureHandler = cvCreateCameraCapture(0);

if (!myCaptureHandler)
{
QErrorMessage* errMsg = new QErrorMessage;
errMsg->showMessage("No Web Cam Plugin");
}

}
// =============================================
void OpenCVQT::ConvertImage()
{
cvCvtColor(myRGBIplImage,
myRGBIplImage, CV_BGR2RGB);

if (!myRGBIplImage)
{
QErrorMessage* errMsg = new QErrorMessage;
errMsg->showMessage("Error Convert Image");
}
else
{
ImageData = (uchar*) myRGBIplImage->imageData;
}
}
// =============================================
void OpenCVQT::CreateQImage()
{
myQImage = QImage(ImageData,
myRGBIplImage->width, myRGBIplImage->height,
myRGBIplImage->widthStep,
QImage::Format_RGB888);
}
// =============================================
void OpenCVQT::SetDisplayImage()
{
QPainter* myPainter = new QPainter(this);
myPainter->drawImage(myQImage.rect(), myQImage);
resize(myRGBIplImage->width, myRGBIplImage->height);
}
// =============================================
void OpenCVQT::CreateImage()
{
myOriginalIplImage = cvCreateImage(
cvSize(myOriginalIplImage->width,
myOriginalIplImage->height), IPL_DEPTH_8U, 3);

ImageData = (uchar*)myOriginalIplImage->imageData;

myQImage = QImage(ImageData,
myOriginalIplImage->width,
myOriginalIplImage->height, myOriginalIplImage->widthStep,
QImage::Format_RGB888);

}

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
OpenCVQT w;

w.show();
w.StreamCamera();

return a.exec();
}




It just display a single image rather than sequence of live frame.
Please comment my code.

Please provide some guide to start.

Please help.

Thanks.

Peter_APIIT
8th December 2009, 06:12
AFAIK, there is no video streaming support in pjlib.

Do you know any VOIP library that does support video streaming ?


I plan to use QThread and Qt datagram.

The thing bothering me now is

1. discover ip of caller and caller.
2. Port of server and client.

I want them to send/received video at different port.