//server线程函数
unsigned int __stdcall ServerFun(PVOID pM)
{
SetEvent(g_hEventBufferLeft);
sockte(IP, address);
return 0;
}
//生产者线程函数
unsigned int __stdcall ProducerThreadFun(PVOID pM)
{
unsigned char ch;
int j = 0;
int size;
int Number = 1;
FILE *fpCopy;
point = (unsigned char*)malloc(sizeof(unsigned char)*804928);
fp = fopen("6.avi", "rb");
//首先保证文件中有流可以用来进行处理
while(TRUE)
{
if((ch = fgetc(fp)) != EOF)
{
Sleep(100);
/*for(j = 0; j < 100; j++)
{
fseek(fp, j, 0);
ch = fgetc(fp);
printf("\n%d\n", ch);
}*/
fseek(fp, 0, 0);
size = filelength(fileno(fp));
printf("%d", size);
if(size > 82000)
{
break;
}
/*flag = TRUE;
fclose(fp);
break;*/
//fread(s)
}
}
while(TRUE)
{
//等待缓冲区为空
WaitForSingleObject(g_hEventBufferLeft, INFINITE);
//互斥的访问缓冲区
EnterCriticalSection(&g_cs);
/*for(j = 0; j < CAPACITY; j++)
{
pFrame = cvQueryFrame(capture);
if(!pFrame) break;
pFramesOne[j] = pFrame;
}*/
TEST = fopen(name1File, "r");
if(!TEST)
remove(name1File);
//设置子文件
if(size > 82000*Number)
{
fread(point , sizeof(ch), 82000, fp);
fpCopy = fopen(nameFile, "ab"); //将其另保存为一个文件
fseek(fpCopy, 0, SEEK_SET);
fwrite(point, sizeof(ch), 82000, fpCopy); //保存完成直接给压缩
fclose(fpCopy);
fseek(fp, 82000, 1);
}
_ldecod(argcCopy, argvCopy, nameFile, nameFileOut, referFile_1);
Number++;
LeaveCriticalSection(&g_cs);
Sleep(50);
SetEvent(g_hEventBufferLeftFull);
/*
unsigned int __stdcall ProducerThreadFun1(PVOID pM)
{
int size;
int Number = 2;
fp = fopen("6.avi", "rb");
while(TRUE)
{
WaitForSingleObject(g_hEventBufferRight, INFINITE);
EnterCriticalSection(&g_cs);*/
/*while(TRUE)
{
size = filelength(fileno(fp));
if(size > 82000*Number)
break;
}*/
/*
Number++;
SetEvent(g_hEventBufferLeftFull);
}*/
WaitForSingleObject(g_hEventBufferRight, INFINITE);
//互斥的访问缓冲区
EnterCriticalSection(&g_cs1);
TEST = fopen(nameFile, "r"); //将前一个文件清除
if(TEST)
remove("copy1.txt");
//设置子文件
if(size > 82000*Number)
{
fread(point , sizeof(ch), 82000, fp);
fpCopy = fopen(name1File, "ab"); //将其另保存为一个文件
fseek(fpCopy, 0, SEEK_SET);
fwrite(point, sizeof(ch),82000, fpCopy); //保存完成直接给压缩
fclose(fpCopy);
fseek(fp, 82000, 1);
}
_ldecod(argcCopy, argvCopy, nameFile, name1FileOut, referFile_2);
Number++;
LeaveCriticalSection(&g_cs1);
Sleep(50);
SetEvent(g_hEventBufferRightFull);
}
return 0;
}
//消费者线程函数
unsigned int __stdcall ConsumerThreadFun(PVOID pM)
{
//volatile bool flag = TRUE;
int i = 0;
//cvNamedWindow("perFrame",1);
//while(!flag);
while(TRUE)
{
WaitForSingleObject(g_hEventBufferLeftFull, INFINITE);
//等待缓冲区中有数据
SetEvent(g_hEventBufferRight);
//互斥的访问缓冲区
EnterCriticalSection(&g_cs);
//SetConsoleColor(FOREGROUND_GREEN); //设置颜色
//cout << "消费者取出数据" << g_Buffer;
//SetConsoleColor(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
//for(i = 0; i < CAPACITY; i++)
//{
// /*cvShowImage("perFrame", pFramesOne[i]);
// cvWaitKey(30);*/
//}
LeaveCriticalSection(&g_cs);
Sleep(10);
WaitForSingleObject(g_hEventBufferRightFull, INFINITE);
//等待缓冲区中有数据
SetEvent(g_hEventBufferLeft);
//互斥的访问缓冲区
EnterCriticalSection(&g_cs1);
//SetConsoleColor(FOREGROUND_GREEN); //设置颜色
//cout << "消费者取出数据" << g_Buffer;
//SetConsoleColor(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
LeaveCriticalSection(&g_cs1);
Sleep(10);
}
return 0;
}
多线程的两个视频文件行不通的错误
最新推荐文章于 2024-03-11 15:57:44 发布