169 lines
4 KiB
C++
169 lines
4 KiB
C++
|
|
#include "SCENE.h"
|
|
#include "MEDIA.h"
|
|
#include "CODEC.h"
|
|
|
|
#ifndef SKIMMED_NET
|
|
|
|
class StreamIn:public INPUT_IO
|
|
{
|
|
public:
|
|
WORLD *pScene;
|
|
u32 ulConnectedIP;
|
|
u32 ulConnectedPort;
|
|
u32 ulConnectedIPIsLocked;
|
|
|
|
void *Codec;
|
|
u32 CurrentDecodedImage;
|
|
u32 CurrentDecodedSegments;
|
|
char CurrentDecodedBlock[DATA_MAX + DATA_MAX_SOUND];
|
|
|
|
int INIT (class WORLD*pscn);
|
|
int FRAME ();
|
|
int END (void);
|
|
IOTYPE GetType() {return IOtype_STRI;};
|
|
|
|
};
|
|
|
|
int StreamIn::END()
|
|
{
|
|
if (Codec) Decode_CLOSE(Codec);
|
|
Codec = NULL;
|
|
Image.Delete();
|
|
return 0;
|
|
}
|
|
|
|
int StreamIn::INIT(class WORLD*pscn)
|
|
{
|
|
pScene = pscn;
|
|
ulConnectedIP = ulConnectedPort = CurrentDecodedImage = CurrentDecodedSegments = ulConnectedIPIsLocked = 0;
|
|
CurrentDecodedImage = -1;
|
|
Codec = NULL;
|
|
return 0;
|
|
};
|
|
|
|
int StreamIn::FRAME()
|
|
{
|
|
#ifdef VIDEO_OPENLIB
|
|
u32 Ret;
|
|
u32 Index;
|
|
this->IsValidForMosaique = 1;
|
|
START_RASTER(Stri);
|
|
pScene->ConnectedMask &= pScene->NetObj->ValidMask;
|
|
ulConnectedPort = pScene->NetObj->MyPort;
|
|
Index = pScene->NetObj->GetIndexFromIP(ulConnectedIP,ulConnectedPort);
|
|
if (Index != -1)
|
|
{
|
|
u32 TileNumb,X,Y,*Ptr;
|
|
if (Codec == NULL)
|
|
{
|
|
CurrentDecodedImage = -1;
|
|
pScene->MustEncodeFromScratch = 5;
|
|
}
|
|
OneBuf Input;
|
|
TileNumb = 0;
|
|
while (pScene->NetObj->LinkedIP[Index].GetNextPacket(&Input, pScene->NetObj))
|
|
{
|
|
ImageHeader *IH;
|
|
IH = (ImageHeader *)Input.BufDATA;
|
|
if (IH->Flag == 'PICT')
|
|
{
|
|
if (Image.SetSize(IH->SX, IH->SY))
|
|
{
|
|
if (Codec) Decode_CLOSE(Codec);
|
|
Codec = NULL;
|
|
if (ulAssociatedTextureIndex != -1)
|
|
pScene->DI->DestroyTexture(ulAssociatedTextureIndex);
|
|
ulAssociatedTextureIndex = -1;
|
|
ulAssociatedTextureIndex = pScene->DI->CreateTexture(&Image,ulColorMode);
|
|
}
|
|
|
|
if (IH->ImageNum != CurrentDecodedImage)
|
|
{
|
|
CurrentDecodedImage = IH->ImageNum;
|
|
CurrentDecodedSegments = 0;
|
|
}
|
|
if (IH->Image_SEGMENT * IMAGE_SEGMENT_SIZE + IMAGE_SEGMENT_SIZE < sizeof(CurrentDecodedBlock))
|
|
{
|
|
memcpy( CurrentDecodedBlock + IH->Image_SEGMENT * IMAGE_SEGMENT_SIZE , Input.BufDATA + sizeof(ImageHeader), IMAGE_SEGMENT_SIZE);
|
|
if (CurrentDecodedSegments == IH->Image_SEGMENT_MAX)
|
|
{
|
|
if (Codec == NULL) Codec = Decode_INIT(&Image);
|
|
if (Codec) Decode_FRAME_AND_SOUND(Codec,&Image,CurrentDecodedBlock,IH->Image_SEGMENT_MAX * IMAGE_SEGMENT_SIZE + Input.Size - sizeof(ImageHeader));
|
|
}
|
|
CurrentDecodedSegments ++;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/* char TEXT[200];
|
|
sprintf(TEXT,"%s:%d",pScene->NetObj->LinkedIP[Index].ComputerName,CurrentDecodedImage);
|
|
DRawTEXT_Soft_B((u8*)TEXT,(u32*)Image.BASE,0,Image.SY - 16,Image.SX, Image.SY, 0xff0000);
|
|
//*/
|
|
IsValidForMosaique = 1;
|
|
STOP_RASTER(Stri);
|
|
return 1;
|
|
} else
|
|
{
|
|
u32 Index,Mask;
|
|
/* Connect */
|
|
if (Codec) Decode_CLOSE(Codec);
|
|
Codec = NULL;
|
|
if (!ulConnectedIPIsLocked)
|
|
{
|
|
Mask = pScene->ConnectedMask ^ pScene->NetObj->ValidMask;
|
|
if (Mask)
|
|
{
|
|
Index = GetFirstBit(pScene->ConnectedMask ^ pScene->NetObj->ValidMask);
|
|
if (pScene->NetObj->LinkedIP[Index].ulIP != 0)
|
|
{
|
|
ulConnectedIP = pScene->NetObj->LinkedIP[Index].ulIP;
|
|
ulConnectedPort = pScene->NetObj->LinkedIP[Index].Port;
|
|
pScene->ConnectedMask |= 1 << Index;
|
|
}
|
|
}
|
|
DRawTEXT_Soft_B_Centered((u8*)"connect..",(u32*)Image.GetBase(),Image.SX, Image.SY, 0xff0000);
|
|
STOP_RASTER(Stri);
|
|
} else
|
|
{
|
|
memset(Image.GetBase(),0,Image.SX * Image.SY * 4);
|
|
DRawTEXT_Soft_B_Centered((u8*)"connect..",(u32*)Image.GetBase(),Image.SX, Image.SY, 0xff0000);
|
|
STOP_RASTER(Stri);
|
|
return 1;
|
|
}
|
|
}
|
|
STOP_RASTER(Stri);
|
|
#endif
|
|
return 1;
|
|
}
|
|
void STRI_SETPARAMS(INPUT_IO *pSTRI,u32 ulIP)
|
|
{
|
|
if (ulIP == 0)
|
|
((StreamIn *)pSTRI)->ulConnectedIPIsLocked = 0;
|
|
else
|
|
{
|
|
((StreamIn *)pSTRI)->ulConnectedIPIsLocked = 1;
|
|
((StreamIn *)pSTRI)->ulConnectedIP = ulIP;
|
|
}
|
|
}
|
|
|
|
INPUT_IO *StreamIn_CREATE(WORLD *pScene,char *Name)
|
|
{
|
|
u32 SX,SY;
|
|
StreamIn *Ret;
|
|
Ret = new(StreamIn);
|
|
|
|
Ret->INIT(pScene);
|
|
SX = 256;
|
|
SY = 256;
|
|
strcpy((char*)Ret->MediaName,Name);
|
|
|
|
Ret->dTotalTime = 0;
|
|
Ret->dAvgFramePerSecond = 30.0;
|
|
Ret->Image.SetSize(SX, SY, 1);
|
|
|
|
return (INPUT_IO *)Ret;
|
|
};
|
|
|
|
#endif
|