239 lines
6.6 KiB
C++
239 lines
6.6 KiB
C++
|
|
#include "SCENE.h"
|
|
#include "MEDIA.h"
|
|
#include "CODEC.h"
|
|
#include <process.h>
|
|
|
|
/*
|
|
MEDIA TYPE "DRVO"
|
|
Used to connect to cammcam virtual device
|
|
*/
|
|
//#pragma optimize("",off)
|
|
#define IsInUseHW 1
|
|
#define IsInUseCV 2
|
|
#define IsInUseDLL 4
|
|
#define IsReadyForDLL 8
|
|
#define IsReadyForHW 16
|
|
|
|
typedef struct
|
|
{
|
|
int SX,SY,BPP,Size,FLAGS;
|
|
} VideoInfoHeaderCamCam;
|
|
|
|
|
|
|
|
|
|
class DRVO:public INPUT_IO
|
|
{
|
|
public:
|
|
DRVO *DRVOTHREAD_CurrentDRVO;
|
|
u32 LastFraming;
|
|
volatile u32 MustBeKilled;
|
|
volatile u32 Semaphore;
|
|
volatile u32 LoadingTime;
|
|
volatile u32 DrvoCounter;
|
|
WORLD *pScene;
|
|
u32 IsConnectedToDriver;
|
|
|
|
int INIT (class WORLD*pscn);
|
|
int FRAME (u32 CalledFrom);
|
|
int FRAME () {return FRAME(0);};
|
|
int END (void);
|
|
IOTYPE GetType() {return IOtype_DRVO;};
|
|
|
|
};
|
|
|
|
|
|
int DRVO::END()
|
|
{
|
|
MustBeKilled = 1;
|
|
while (MustBeKilled == 1)
|
|
{
|
|
Sleep(2);
|
|
}
|
|
Image.Delete();
|
|
return 0;
|
|
}
|
|
|
|
int DRVO::INIT(class WORLD*pscn)
|
|
{
|
|
IsValidForMosaique = 0;
|
|
pScene = pscn;
|
|
LastFraming = timeGetTime();
|
|
Semaphore = 0;
|
|
MustBeKilled = 0;
|
|
LoadingTime = 2000;
|
|
DrvoCounter = 0;
|
|
return 0;
|
|
};
|
|
int DRVO::FRAME(u32 CalledFromThread)
|
|
{
|
|
HANDLE hFile;
|
|
if ((Image.SX < 300) || (Image.SY < 200)) return 0;
|
|
while (Semaphore) {};
|
|
Semaphore = 1;
|
|
if (!CalledFromThread) DrvoCounter = 0;
|
|
if (IsConnectedToDriver)
|
|
IsConnectedToDriver--;
|
|
hFile = OpenFileMapping(FILE_MAP_WRITE|FILE_MAP_READ,FALSE,"Global\\YouUpTunnel0");
|
|
if (hFile == NULL)
|
|
hFile = OpenFileMapping(FILE_MAP_WRITE|FILE_MAP_READ,FALSE,"Global\\YouUpTunnel1");
|
|
|
|
if (hFile != NULL)
|
|
{
|
|
u8 *MyM;
|
|
LastFraming = timeGetTime();
|
|
MyM = (u8*)MapViewOfFile(hFile,FILE_MAP_READ|FILE_MAP_WRITE,0,0,sizeof(VideoInfoHeaderCamCam));
|
|
if (MyM != NULL)
|
|
{
|
|
VideoInfoHeaderCamCam VIHCC;
|
|
VIHCC = *((VideoInfoHeaderCamCam*)MyM);
|
|
UnmapViewOfFile(MyM);
|
|
|
|
if ((VIHCC.SX != Image.SX) || (VIHCC.SY != Image.SY))
|
|
{
|
|
if (CalledFromThread)
|
|
{
|
|
VIHCC.FLAGS &= ~IsReadyForDLL;
|
|
MyM = (u8*)MapViewOfFile(hFile,FILE_MAP_READ|FILE_MAP_WRITE,0,0,VIHCC.Size);
|
|
if (MyM != NULL)
|
|
{
|
|
((VideoInfoHeaderCamCam*)MyM)->FLAGS |= IsReadyForHW;
|
|
|
|
u8 *pDST;
|
|
//Counter = VIHCC.SX * VIHCC.SY;
|
|
pDST = MyM + sizeof(VideoInfoHeaderCamCam);
|
|
memset(pDST,0xff, 4096);
|
|
|
|
UnmapViewOfFile(MyM);
|
|
}
|
|
} else
|
|
{
|
|
if (ulAssociatedTextureIndex != -1) pScene->DI->DestroyTexture(ulAssociatedTextureIndex);
|
|
ulAssociatedTextureIndex = -1;
|
|
Image.SetSize(VIHCC.SX, VIHCC.SY, 1);
|
|
ulAssociatedTextureIndex = pScene->DI->CreateTexture(&Image,ulColorMode);
|
|
}
|
|
}
|
|
if ((VIHCC.FLAGS & IsReadyForDLL) && (VIHCC.SX <= Image.SX) && (VIHCC.SY <= Image.SY))
|
|
{
|
|
MyM = (u8*)MapViewOfFile(hFile,FILE_MAP_READ|FILE_MAP_WRITE,0,0,VIHCC.Size);
|
|
if (MyM != NULL)
|
|
{
|
|
if (CalledFromThread)
|
|
{
|
|
u32 Color;
|
|
u8 *PtrB,*PtrLast;
|
|
PtrB = (u8 *)Image.GetBase();
|
|
PtrLast = PtrB + Image.SY * Image.PITCH * 4;
|
|
while (PtrB < PtrLast)
|
|
{
|
|
if (*PtrB)
|
|
{
|
|
if(*PtrB > 4) *PtrB -= 4;
|
|
else *PtrB = 0;
|
|
}
|
|
PtrB++;
|
|
}
|
|
Color = (DrvoCounter>>3);
|
|
Color = ( (Color & 1) ? 0xff : 0x80 ) + ( (Color & 2) ? 0xff00 : 0x8000 ) + ( (Color & 4) ? 0xff0000 : 0x800000 );
|
|
for (int i = 0 ; i < 32 ; i ++)
|
|
{
|
|
|
|
float LongL = 24.0f;
|
|
float LongS = 16.0f;
|
|
DrawLine(&Image,(Image.SX>>1) + LongS * sin(((float)(DrvoCounter & ~7)*8.0f + (float)i) * 0.01f),(Image.SY>>1) + LongS * cos(((float)(DrvoCounter & ~7)*8.0f + (float)i) * 0.01f),(Image.SX>>1) + LongL * sin(((float)(DrvoCounter & ~7)*8.0f + (float)i) * 0.01f),(Image.SY>>1) + LongL * cos(((float)(DrvoCounter & ~7)*8.0f + (float)i) * 0.01f),Color);
|
|
DrawLine(&Image,1+(Image.SX>>1) + LongS * sin(((float)(DrvoCounter & ~7)*8.0f + (float)i) * 0.01f),(Image.SY>>1) + LongS * cos(((float)(DrvoCounter & ~7)*8.0f + (float)i) * 0.01f),1+(Image.SX>>1) + LongL * sin(((float)(DrvoCounter & ~7)*8.0f + (float)i) * 0.01f),(Image.SY>>1) + LongL * cos(((float)(DrvoCounter & ~7)*8.0f + (float)i) * 0.01f),Color);
|
|
DrawLine(&Image,(Image.SX>>1) + LongS * sin(((float)(DrvoCounter & ~7)*8.0f + (float)i) * 0.01f),1+(Image.SY>>1) + LongS * cos(((float)(DrvoCounter & ~7)*8.0f + (float)i) * 0.01f),(Image.SX>>1) + LongL * sin(((float)(DrvoCounter & ~7)*8.0f + (float)i) * 0.01f),1+(Image.SY>>1) + LongL * cos(((float)(DrvoCounter & ~7)*8.0f + (float)i) * 0.01f),Color);
|
|
DrawLine(&Image,1+(Image.SX>>1) + LongS * sin(((float)(DrvoCounter & ~7)*8.0f + (float)i) * 0.01f),1+(Image.SY>>1) + LongS * cos(((float)(DrvoCounter & ~7)*8.0f + (float)i) * 0.01f),1+(Image.SX>>1) + LongL * sin(((float)(DrvoCounter & ~7)*8.0f + (float)i) * 0.01f),1+(Image.SY>>1) + LongL * cos(((float)(DrvoCounter & ~7)*8.0f + (float)i) * 0.01f),Color);
|
|
}
|
|
}
|
|
if (VIHCC.BPP == 4)
|
|
{
|
|
memcpy(MyM + sizeof(VideoInfoHeaderCamCam),Image.GetBase(),VIHCC.Size);
|
|
}
|
|
else
|
|
if ((VIHCC.BPP == 3) && (Image.GetBase()))
|
|
{
|
|
u32 Counter;
|
|
u8 *pDST;
|
|
u32 *pSRC;
|
|
Counter = VIHCC.SX * VIHCC.SY;
|
|
pSRC = (u32 *)Image.GetBase();
|
|
pDST = MyM + sizeof(VideoInfoHeaderCamCam);
|
|
while (Counter--)
|
|
{
|
|
*(pDST++) = (u8)(*pSRC & 0xff);
|
|
*(pDST++) = (u8)((*pSRC>>8) & 0xff);
|
|
*(pDST++) = (u8)((*pSRC>>16) & 0xff);
|
|
pSRC++;
|
|
}
|
|
//glReadPixels(0,0,VIHCC.SX,VIHCC.SY,GL_RGB,GL_UNSIGNED_BYTE,MyM + sizeof(VideoInfoHeaderCamCam));
|
|
}
|
|
((VideoInfoHeaderCamCam*)MyM)->FLAGS |= IsReadyForHW;
|
|
IsConnectedToDriver = 50;
|
|
UnmapViewOfFile(MyM);
|
|
}
|
|
}
|
|
}
|
|
CloseHandle(hFile);
|
|
}
|
|
Semaphore = 0;
|
|
return 0;
|
|
}
|
|
u32 DRVO_ISLINKED(INPUT_IO *pDRO)
|
|
{
|
|
if (pDRO && (pDRO->GetType() == IOtype_DRVO)) return ((DRVO *)pDRO)->IsConnectedToDriver;
|
|
else return 0;
|
|
}
|
|
|
|
|
|
//_beginthreadex( NULL , THREAD_STACK_SIZE , INPUT_THREAD , this , 0 , &InputthreadID );
|
|
unsigned __stdcall DRVOTHREAD_Thread(void *params)
|
|
{
|
|
DRVO *Drv0;
|
|
Drv0 = (DRVO*)params;
|
|
while (1)
|
|
{
|
|
if (Drv0->MustBeKilled)
|
|
{
|
|
Drv0->MustBeKilled = 2;
|
|
_endthread();
|
|
}
|
|
if (Drv0->DrvoCounter == 0)
|
|
Drv0->LoadingTime = 1000;
|
|
if (Drv0->Semaphore == 0)
|
|
{
|
|
if (timeGetTime() - Drv0->LastFraming > Drv0->LoadingTime)
|
|
{
|
|
Drv0->FRAME(1);
|
|
Drv0->LoadingTime = 50;
|
|
Drv0->DrvoCounter ++;
|
|
}
|
|
}
|
|
Sleep(30) ;
|
|
}//*/
|
|
}
|
|
|
|
INPUT_IO *MainDriver = NULL;
|
|
|
|
INPUT_IO *DRVO_CREATE(WORLD *pScene,char *Name)
|
|
{
|
|
DRVO *Ret;
|
|
Ret = new(DRVO);
|
|
|
|
Ret->INIT(pScene);
|
|
Ret->IsConnectedToDriver = 0;
|
|
Ret->Image.SetSize(320, 200, 1);
|
|
Ret->dTotalTime = 0;
|
|
Ret->dAvgFramePerSecond = 30.0;
|
|
{
|
|
_beginthreadex( NULL , 8192 , DRVOTHREAD_Thread , Ret , 0 , NULL );
|
|
}
|
|
|
|
MainDriver = Ret;
|
|
|
|
return (INPUT_IO *)Ret;
|
|
};
|
|
|
|
|