Clear the message queue
Hi,
I create a dialog-based application. I capture video frame from webcam with
VFW and create a UI thread, CEncThread, to encode the frame. The
OnCaptureVideo is invoked when the video frame is captured by the driver,
copy the frame data into global frame memory, and send a message to tell the
CEncThread to encode:
========================================
if (g_bFrameCopied == false) {
memcpy(g_szFrame, captureframe, size);
g_nFrameLength = size;
g_bFrameCopied = true;
::PostThreadMessage(m_pEncThread->m_nThreadID, WM_ENCODE_FRAME, 0, 0);
========================================
The CEncThread will copy the video frame from global memory into local
memory and encode it with jpeg2000 codec:
========================================
if (g_bFrameCopied == true) {
memcpy(s_szFrame, g_szFrame, g_nFrameLength);
g_bFrameCopied = false;
}
m_Encode.CreateFromArray((unsigned char *)g_szFrame, FRAME_WIDTH,
FRAME_HEIGHT, 8, FRAME_WIDTH, false);
m_Encode.SetJpegQuality(10);
m_Encode.Encode(buffer,len,CXIMAGE_FORMAT_JP2);
========================================
After closing the program, I get an error at this statement:
========================================
::PostThreadMessage(m_pEncThread->m_nThreadID, WM_ENCODE_FRAME, 0, 0);
========================================
I think that there maybe a few messages that invoke video callback function
in message queue after stopping the capturing process and disable the
callback function. So, It still calls PostThreadMessage to tell CEncThread to
work after CEncThread is closed. I want to know how to clear the message
queue???