#define CYCTIME 2000
#define RESTORE_BUFFSIZE  4096 
ULONG inbuffersize = RESTORE_BUFFSIZE;
BYTE1 *inbufferptr[CYCTIME];
BYTE1 *outbufferptr[CYCTIME/5];
void GetThread(void *param)
{
    CFlyDemoDlg *pVideo = (CFlyDemoDlg *)param;

  UINT GetNum = 0;
UINT tempres = 0;
UINT i = 0; for(i = 0; i < CYCTIME;i++)
{
inbufferptr[i] = (BYTE *)malloc(RESTORE_BUFFSIZE);
memset(inbufferptr[i],0,RESTORE_BUFFSIZE);
}

while (pVideo->m_RunMode==RUNMODE_PLAY)
{
        tempres = GetNum % CYCTIME;
    pVideo->m_pCFlyUSB->bGetUSBData(inbufferptr[tempres],inbuffersize); // CString ss;
// ss.Format("%d",inbufferptr[1][11]);
// AfxMessageBox(ss);
GetNum++;
}
    SetEvent(pVideo->m_hGetUSBThreadEventDead);
    _endthread();
//clear the state flag

}void DecThread(void *param)
{
CFlyDemoDlg *pVideo = (CFlyDemoDlg *)param;
UINT GetNum = 0;
UINT tempres = 0;
UINT i = 0;
  int outbuffersize = (pVideo->CurrentSensor.width) * (pVideo->CurrentSensor.height) *(pVideo->CurrentSensor.type);

for(i = 0; i < CYCTIME/2;i++)
{
outbufferptr[i] = (BYTE *)malloc(outbuffersize);
memset(outbufferptr[i],0,outbuffersize);
}

while (pVideo->m_RunMode==RUNMODE_PLAY)
{
tempres = GetNum % CYCTIME;
       if(inbufferptr[tempres] == NULL)
   {
     WaitForSingleObject(pVideo->m_hGetUSBThreadEventDead, INFINITE);
         CloseHandle(pVideo->m_hGetUSBThreadEventDead);
   }
     
//    CString ss;
//    ss.Format("%d",inbufferptr[0][10]);
//    AfxMessageBox(ss);
       
 pVideo->m_pCFlyUSB->bH264decoder(inbufferptr[tempres],inbuffersize,outbufferptr[tempres],outbuffersize);

      if(!(outbufferptr[tempres] == NULL))
  {;
  }
     GetNum ++ ;
} SetEvent(pVideo->m_hDecodeThreadEventDead);
    _endthread();
}void DispThread(void *param)
{
    CFlyDemoDlg  *pVideo = (CFlyDemoDlg *)param;
UINT timeStart=0;
UINT timeStop = 0;
UINT FrameNum = 0;
float Framefps = 0.00;
UINT GetNum = 0;
UINT tempres = 0;
int ret = 0;
int outbuffersize = (pVideo->CurrentSensor.width) * (pVideo->CurrentSensor.height) *(pVideo->CurrentSensor.type);

    while (pVideo->m_RunMode!=RUNMODE_STOP)
    {
if(outbufferptr[tempres] == NULL) 
{
WaitForSingleObject(pVideo->m_hDisplayThreadEventDead, INFINITE);
CloseHandle(pVideo->m_hDisplayThreadEventDead);
}     pVideo->m_USBKey = pVideo->m_pCFlyUSB->GetKey(RUNMODE_STOP);
pVideo->m_pDD->bDisplayVideo(outbufferptr[tempres]);      
}

    SetEvent(pVideo->m_hDisplayThreadEventDead);
    _endthread();

}为什么显示都是绿屏?前提:我顺序执行解码显示正确
是不是同步有问题?
另问:
多线程怎么调试,不小心就死机,找不到问题出在哪里?

解决方案 »

  1.   

    多线程调试
    输出调用信息至输出窗口:trace atltrace OutPutDebugString .... 
      

  2.   

    这个不需要多线程吧,没看出哪里能提高速度。
    另外下面应该是m_hDecodeThreadEventDead?
    void DispThread(void *param) 

        CFlyDemoDlg  *pVideo = (CFlyDemoDlg *)param; 
    UINT timeStart=0; 
    UINT timeStop = 0; 
    UINT FrameNum = 0; 
    float Framefps = 0.00; 
    UINT GetNum = 0; 
    UINT tempres = 0; 
    int ret = 0; 
    int outbuffersize = (pVideo->CurrentSensor.width) * (pVideo->CurrentSensor.height) *(pVideo->CurrentSensor.type);     while (pVideo->m_RunMode!=RUNMODE_STOP) 
        { 
    if(outbufferptr[tempres] == NULL) 

    WaitForSingleObject(pVideo->m_hDisplayThreadEventDead, INFINITE); 《------
    CloseHandle(pVideo->m_hDisplayThreadEventDead); 《------------------------
    }     pVideo->m_USBKey = pVideo->m_pCFlyUSB->GetKey(RUNMODE_STOP); 
    pVideo->m_pDD->bDisplayVideo(outbufferptr[tempres]);      
    }     SetEvent(pVideo->m_hDisplayThreadEventDead); 
        _endthread(); } 
      

  3.   

    多线程,断点调试,顺序是不确定的,因为每次到达断点,所有线程都会被挂起。
    建议写LOG,或者TRACE吧。