videostreaming application i wrote a whole code ,it run fine on my
machine but when same code i try
to run on client machine the computer get hang means all i/o
operations get stuck n even task manager is also not open
plz help me if u have any solution
1) i wrote a application in visual c++ 6.0
2)i rad a data from cypress USB and disply it
3) i read a data in from of 512 packets
4)i use avi apli for windw
5) i used two thread one is for display and another tthread read a data from usb
please help me as early as possiable
/************************
code**************************
// Video_Streaming_Soft1.cpp : implementation file
//
#include "stdafx.h"
#include "high_frame_rate_board.h"
#include "Video_Streaming_Soft.h"
#include
#include
#include
#include "CyApi.h"
#include "Wingdi.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//////////////////////////////
// Video_Streaming_Soft dialog
//CCyUSBDevice *USBDevice = new CCyUSBDevice(NULL);
extern class CCyUSBDevice *USBDevice;// Create an instance of CCyUSBDevice
unsigned long Exit_Thread_Code,Exit_Thread_
unsigned short* Input_Buff=new unsigned short[76801];
PUCHAR Bmp_Buff=new UCHAR[230401];
PUCHAR Bmp_Buff2=new UCHAR[230401];
PUCHAR Out_Buff1=new UCHAR[513];
bool Play_Stop=false;
unsigned int Store_Video1 = 0;
unsigned int Store_Video2 = 0;
unsigned int Display_Video = 0;
unsigned int Exit_All_Loops = 0;
time_t rawtime;
struct tm * timeinfo;
LONG inlen=153600,outlen=512;
IAVIFile *pfile = NULL; // created by CreateAvi
IAVIStream *ps = NULL;
IAVIStream *psCompressed = NULL; // video stream, when first created
Video_Streaming_Soft::Video_
: CDialog(Video_Streaming_Soft::
{
//{{AFX_DATA_INIT(Video_
m_Save_Option = FALSE;
//}}AFX_DATA_INIT
}
void Video_Streaming_Soft::
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(Video_
DDX_Control(pDX, IDC_SHOW_FRAME, m_Show_Frame);
DDX_Check(pDX, IDC_SAVE_OPTION, m_Save_Option);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(Video_
//{{AFX_MSG_MAP(Video_
ON_BN_CLICKED(IDC_PLAY_STOP, OnPlayStop)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//////////////////////////////
// Video_Streaming_Soft message handlers
BOOL Video_Streaming_Soft::
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_
pSysMenu->AppendMenu(MF_
strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
SetPriorityClass(
// Process
Priority
//BITMAP bmpInfo;
ZeroMemory(&bmpInfo,sizeof(
bmpInfo.bmiHeader.biPlanes = 1;
bmpInfo.bmiHeader.biWidth = 320;
bmpInfo.bmiHeader.biHeight = 240;
bmpInfo.bmiHeader.
bmpInfo.bmiHeader.biBitCount = 24;
bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmpInfo.bmiHeader.biSizeImage = (320*240*3);
return TRUE; // return TRUE unless you set the focus to a control
}
void Video_Streaming_Soft::
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
// CAboutDlg dlgAbout;
//dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void Video_Streaming_Soft::OnPaint(
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR Video_Streaming_Soft::
{
return (HCURSOR) m_hIcon;
}
struct ThreadParam_Cypress
{
HWND mDlg; // Note: A handle.
CWnd* pParent;
Video_Streaming_Soft* mDlg_Handle;
};
struct ThreadParam_Display
{
HWND mDlg; // Note: A handle.
CWnd* pParent;
Video_Streaming_Soft* mDlg_Handle;
};
UINT Video_Stream(LPVOID param) //<----for multithreaded Mouse
{
ThreadParam_Cypress* thread_param =
static_cast
HWND hWnd =
::GetDlgItem(thread_param->
bool Success_In = false;
register unsigned int min_val=0xFFFF,max_val=0;
register unsigned int loop=0;
register unsigned int step_factor=0,diff_val=0;
register unsigned int bmp_ptr = 0;
SetThreadPriority(
// SetThreadPriority(
Out_Buff1[0]=0xcd;
Out_Buff1[1]=0xab;
bool Success_Out=USBDevice->
if(!Success_Out)
{
Play_Stop = false;
::SetWindowText(hWnd,"Play");
AfxMessageBox("Failed to Write to USB ???",MB_ICONERROR);
return 0;
}
HDC bDC_frame = ::GetDC(thread_param->mDlg_
while(1)
{
inlen=153600;
Success_In = USBDevice->BulkInEndPt->
char*)Input_Buff,inlen);
if(!Success_In)
{
Play_Stop = false;
AVIStreamRelease(ps);
AVIStreamRelease(
AVIFileRelease(pfile);
AVIFileExit();
::SetWindowText(hWnd,"Play");
AfxMessageBox("Failed to Read From USB
???",MB_ICONERROR);
return 0;
}
/* min_val = Input_Buff[76799];
max_val = Input_Buff[76798];
step_factor = max_val - min_val;
step_factor >>= 8;*/
Display_Video = 1;
Store_Video1 = 0;
for(loop=0,bmp_ptr=0;loop<
{
diff_val = (Input_Buff[loop]);
// Bmp_Buff[bmp_ptr] = diff_val;
// diff_val = (Input_Buff[loop]-min_val)/
Bmp_Buff[bmp_ptr] = (diff_val & 0x001F)<<3;
Bmp_Buff[++bmp_ptr] =(diff_val & 0x03E0)>>2;
Bmp_Buff[++bmp_ptr] =(diff_val & 0x7C00)>>7;
}
Store_Video1 = 1;
Display_Video = 1;
Sleep(8);
///////////// Read 2nd Time
///////////
inlen=153600;
Success_In = USBDevice->BulkInEndPt->
char*)Input_Buff,inlen);
if(!Success_In)
{
Play_Stop = false;
AVIStreamRelease(ps);
AVIStreamRelease(
AVIFileRelease(pfile);
AVIFileExit();
::SetWindowText(hWnd,"Play");
AfxMessageBox("Failed to Read From USB
???",MB_ICONERROR);
return 0;
}
/* min_val=Input_Buff[76799];
max_val=Input_Buff[76798];
step_factor = max_val - min_val;
step_factor >>= 8;*/
Store_Video2 = 0;
for(loop=0,bmp_ptr=0;loop<
{
// diff_val = (Input_Buff[loop]-min_val)/
diff_val = (Input_Buff[loop]);
// Bmp_Buff2[bmp_ptr] = diff_val;
Bmp_Buff[bmp_ptr] = (diff_val & 0x001F)<<3;
Bmp_Buff[++bmp_ptr] = (diff_val & 0x03E0)>>2;
Bmp_Buff[++bmp_ptr] =(diff_val & 0x7C00)>>7;
}
Store_Video2 = 1;
Sleep(8);
}
return 0;
}
UINT Display_Save_Stream(LPVOID param) //<----for multithreaded Mouse
{
ThreadParam_Cypress* thread_param =
static_cast
HWND hWnd =
::GetDlgItem(thread_param->
HWND hWnd_Save_Option =
::GetDlgItem(thread_param->
SetThreadPriority(
HDC bDC_frame = ::GetDC(thread_param->mDlg_
::EnableWindow(hWnd_Save_
Store_Video1=0;
Store_Video2=0;
Display_Video=1;
if(thread_param->mDlg_Handle-
{
unsigned long m_lSample = 0;
// Keeps track of the current Frame Index
while(1)
{
if(Store_Video1)
{
psCompressed->Write(m_lSample+
Store_Video1 = 0;
}
if(Store_Video2)
{
psCompressed->Write(m_lSample+
Store_Video2 = 0;
}
if(Display_Video)
{
Display_Video = 0;
SetDIBitsToDevice(bDC_frame,0,
}
if(Exit_All_Loops)
break;
}
}
else
{
while(1)
{
if(Display_Video)
{
Display_Video = 1;
SetDIBitsToDevice(bDC_frame,0,
}
if(Exit_All_Loops)
break;
}
}
return 0;
}
void Video_Streaming_Soft::
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if(!Play_Stop)
{
if(m_Save_Option) // AVI
Store Function
{
char ptr_file_name[40]="";
time ( &rawtime );
timeinfo = localtime ( &rawtime );
sprintf(ptr_file_name,"Out_
FILE* fp = fopen(ptr_file_name,"wb+");
fclose(fp);
AVIFileInit();
// Initialise AVI Function
HRESULT hr =
AVIFileOpen(&pfile,ptr_file_
if (hr != AVIERR_OK)
{
Play_Stop = false;
AVIFileExit();
AfxMessageBox("Failed to Open AVI File
Function ???",MB_ICONERROR);
return;
}
else
{
Play_Stop = true;
AVISTREAMINFO strhdr;
// create the stream, if it wasn't there before
ZeroMemory(&strhdr,sizeof(
strhdr.fccType = streamtypeVIDEO;// stream type
strhdr.fccHandler = mmioFOURCC('D','I','V','X');
strhdr.dwScale = 1;
strhdr.wPriority=1;
strhdr.dwRate = 50;
strhdr.dwSuggestedBufferSize = 320*240*3;
SetRect(&strhdr.rcFrame, 0, 0, 320, 240);
_tcscpy(strhdr.szName, _T("Video Stream"));
hr=AVIFileCreateStream(pfile,
if (hr!=AVIERR_OK)
{
Play_Stop = false;
AVIFileExit();
AfxMessageBox("Failed in
AVIFileCreateStream Function ???",MB_ICONERROR);
return;
}
else
{
Play_Stop = true;
AVICOMPRESSOPTIONS opts;
ZeroMemory(&opts,sizeof(opts)
opts.fccHandler =
mmioFOURCC('D','I','V','X');
opts.dwFlags=AVICOMPRESSF_
opts.dwKeyFrameEvery=1;
hr =
AVIMakeCompressedStream(&
if (hr != AVIERR_OK)
{
Play_Stop = false;
AVIFileExit();
AfxMessageBox("Failed
in AVIMakeCompressedStream
Function ???",MB_ICONERROR);
return;
}
else
{
Play_Stop = true;
hr =
AVIStreamSetFormat(
if (hr!=AVIERR_OK)
{
Play_Stop = false;
AVIFileExit();
AfxMessageBox("Failed in AVIStreamSetFormat Function
???",MB_ICONERROR);
return;
}
else
{
Play_Stop = true;
}
}
}
}
}
else
{
Exit_All_Loops=0;
Play_Stop = true;
ThreadParam_Cypress* param = new ThreadParam_Cypress;
param->mDlg = GetSafeHwnd();
param->mDlg_Handle = this;
ThreadParam_Display* param2 = new ThreadParam_Display;
param2->mDlg = GetSafeHwnd();
param2->mDlg_Handle=this;
hDevice = USBDevice->DeviceHandle();
if(hDevice==INVALID_HANDLE_
{
Play_Stop = false;
AfxMessageBox("Error in Opening Handle
",MB_ICONERROR);
return;
}
else
{
Play_Stop = true;
ThreadID=AfxBeginThread(Video_
ThreadID->m_bAutoDelete=TRUE;
if(!GetExitCodeThread(
{
MessageBox("GetExitCodeThread
Failed !!!","Thread ID",MB_ICONERROR);
return;
}
else
{
ThreadID_Display=
ThreadID_Display->m_
if(!GetExitCodeThread(
{
MessageBox("GetExitCodeThread Failed !!!","Thread ID",MB_ICONERROR);
return;
}
else
{
GetDlgItem(IDC_PLAY_STOP)->
param=0;
param2=0;
}
}
}
}
}
else
{
GetDlgItem(IDC_SAVE_OPTION)->
outlen=512;
bool
Success_Out=USBDevice->
if(!Success_Out)
{
AfxMessageBox("Failed to Write to USB
???",MB_ICONERROR);
return;
}
else
{
Exit_All_Loops=1;
Play_Stop = false;
GetDlgItem(IDC_PLAY_STOP)->
Sleep(100);
if(!(::TerminateThread(
{
MessageBox("Failed to Kill Video Stream
Thread ????","Thread
ID",MB_ICONERROR);
}
else
{
USBDevice->BulkOutEndPt->
USBDevice->BulkInEndPt->
if(m_Save_Option)
{
AVIStreamRelease(ps);
AVIStreamRelease(
AVIFileRelease(pfile);
AVIFileExit();
}
else
{
}
}
}
}
}
Replies
Know the answer? Post it — somebody with the same question will find it here.