程序时实播放没有问题,回放出现马赛克现象,为什么?

匪六哥 2003-05-12 03:28:31
程序时实播放没有问题,回放出现马赛克现象,为什么?

void McSocket::OnRecieve (int errcode)
{
int lenrec;
if (errcode != -1)
{

m_csRecv[m_win].Lock();
lenrec = Recv(bufVideo[m_win], Q_SIZE, 0);
if ((lenrec > 6+5) && (m_win < WINDOWSNUM))
{
unsigned char cc = (unsigned char)(bufVideo[m_win][8]);
if ( (bufVideo[m_win][6] == 0) && (bufVideo[m_win][7] ==0) && ((cc & 0x80) == 0x80) //判断标志位是否到来
{
vv[m_win].len = oldl[m_win];//待保存数据长度
if (oldl[m_win]>0)
{
vv[m_win].m_picHwnd = m_picHwnd;
SaveFile(vv[m_win].data, oldl[m_win]);//保存文件
III(m_win, &vv[m_win]);//实时播放
oldl[m_win] = 0;//清零
}
}

for (int i=0; i<lenrec-6; i++)
{
vv[m_win].data[oldl[m_win]+i] = bufVideo[m_win][i+6];//将缓存数据保存
}
oldl[m_win] += lenrec-6;//标志位未到,一直累加。
}
}
m_csRecv[m_win].Unlock();

}
}



void McSocket::SaveFile(unsigned char* wBuf, int size)
{ CFile m_Save_file;
if(m_Save_file.Open(tempN, CFile::modeWrite| CFile::shareDenyRead, NULL ) {
unsigned char sc[2];
sc[0] = size /256;
sc[1] = size % 256;
m_Save_file.SeekToEnd( );
m_Save_file.Write(sc, 2);//保存长度
m_Save_file.Write(wBuf, size);
m_Save_file.Close();
}
}


unsigned long StartPlayBack(CString fileN, HWND hwnd, unsigned long current_size)
{
FILE *f;
unsigned char s[2];

f = fopen(fileN, "rb" );
if (f==NULL)
{
return 0;
}
fseek(f, current_size, SEEK_SET);

if (fread(s, sizeof( char ), 2, f) > 1)
{
//into video queue
unsigned short size = s[0]*256 +s[1];
if (size>0)
{
m_csRecv[WINDOWSNUM].Lock();
fread(vv[WINDOWSNUM].data, sizeof( char ), size, f);//读出数据
vv[WINDOWSNUM].len = size;
vv[WINDOWSNUM].m_picHwnd = hwnd;
EnterQ(q[WINDOWSNUM], vv[WINDOWSNUM]);//播放
m_csRecv[WINDOWSNUM].Unlock();
}
fclose(f);
return current_size+size+2;
}
else
{
HWND hwndParent = GetParent(hwnd);
if(hwndParent != NULL) ::PostMessage(hwndParent,WM_STOP_PLAYBACK,0,0);
fclose(f);
return 0;
}
}
...全文
12 点赞 收藏 5
写回复
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhuwy 2003-06-24
你试着检查一下你进行存盘前的那些判断条件,因为判断条件有可能使程序退出存盘而使得丢桢!
回复
匪六哥 2003-06-05
可能是我代码没贴全,全部存盘代码如下:
void McSocket::SaveFile(unsigned char* wBuf, int size)
{

if( FALSE == m_bSaving[m_win]) return;
CString tempN = CString(AviFilename[m_win]);

CString lpDirectoryName = tempN.Left(3);
ULARGE_INTEGER lpFreeBytesAvailableToCaller;
ULARGE_INTEGER lpTotalNumberOfBytes;
ULARGE_INTEGER lpTotalNumberOfFreeBytes ;
GetDiskFreeSpaceEx(//判断磁盘空间
lpDirectoryName,
&lpFreeBytesAvailableToCaller,
&lpTotalNumberOfBytes,
&lpTotalNumberOfFreeBytes
);
if(lpFreeBytesAvailableToCaller.QuadPart < 5242880
{
MessageBox (NULL, "ÎļþËùÔÚÓ²ÅÌ¿Õ¼äÒÑÂú£¬Í£Ö¹´æÅÌ!", "ERROR", MB_ICONWARNING);
HWND hwnd = AfxGetMainWnd()->m_hWnd ;
if(hwnd != NULL) ::PostMessage(hwnd,WM_STOP_SAVE,m_win,0);
m_bSaving[m_win] = FALSE;
return ; }

int current_time = timeGetTime();

if( AviFrameRate[m_win] > 0 )
{
int m_interval = (int) ( 1000 / AviFrameRate[m_win]);
if( current_time < m_last_time[m_win] + m_interval ) return ;
}

m_last_time[m_win] = current_time ;

if( AviTimeLength[m_win]>0)
{
if( m_last_time[m_win] > m_start_time[m_win] + AviTimeLength[m_win] )
{
HWND hwnd = AfxGetMainWnd()->m_hWnd ;
if(hwnd != NULL) ::PostMessage//存盘结束发结束指令(hwnd,WM_STOP_SAVE,m_win,0);
m_bSaving[m_win] = FALSE;
return ; }
}
CFile m_Save_file;
CFileException ex;
if(m_Save_file.Open(tempN, CFile::modeWrite| CFile::shareDenyRead , &ex ) {
savesuss = TRUE;
unsigned char sc[2];
sc[0] = size /256;
sc[1] = size % 256;
m_Save_file.SeekToEnd( );
m_Save_file.Write(sc, 2);
m_Save_file.Write(wBuf, size);
m_Save_file.Close();
}
}
回复
huaqingci 2003-05-13
你试试,把文件保存成二进制的
回复
zhshly007 2003-05-13
太转业了
回复
匪六哥 2003-05-13
up
回复
发动态
发帖子
VC/MFC
创建于2007-09-28

1.5w+

社区成员

VC/MFC相关问题讨论
申请成为版主
社区公告
暂无公告