258 lines
6.2 KiB
C++
258 lines
6.2 KiB
C++
|
|
#include "SCENE.h"
|
|
#include "MEDIA.h"
|
|
#include "CODEC.h"
|
|
|
|
#ifndef SKIMMED_NET
|
|
|
|
#define COPYO2
|
|
//#define DEBUG_DECODE
|
|
//#define EXPORT_264
|
|
//#define STROBYPASSNET
|
|
|
|
class StreamOut:public INPUT_IO
|
|
{
|
|
public:
|
|
void *Codec;
|
|
WORLD *pScene;
|
|
#ifdef EXPORT_264
|
|
FILE *p264;
|
|
#endif
|
|
|
|
#ifdef DEBUG_DECODE
|
|
void *CodecDEC;
|
|
#endif
|
|
u32 SourceIndex;
|
|
u32 CompQuality;
|
|
u32 CompResp;
|
|
|
|
u32 CurrentDecodedImage;
|
|
u32 CurrentDecodedSegments;
|
|
u32 CurrentDecodedSegments_MAX;
|
|
u32 CurrentSize;
|
|
u32 CurrentBaseSize;
|
|
char CurrentDecodedBlock[DATA_MAX + DATA_MAX_SOUND];
|
|
|
|
|
|
int INIT (class WORLD*pscn);
|
|
int FRAME ();
|
|
int END (void);
|
|
IOTYPE GetType() {return IOtype_STRO;};
|
|
|
|
};
|
|
|
|
int StreamOut::END()
|
|
{
|
|
if (Codec) Encode_CLOSE(Codec);
|
|
#ifdef DEBUG_DECODE
|
|
if (CodecDEC) Decode_CLOSE(Codec);
|
|
CodecDEC = NULL;
|
|
#endif
|
|
Codec = NULL;
|
|
Image.Delete();
|
|
return 0;
|
|
}
|
|
|
|
int StreamOut::INIT(class WORLD*pscn)
|
|
{
|
|
Codec = NULL;
|
|
pScene = NULL;
|
|
|
|
#ifdef DEBUG_DECODE
|
|
CodecDEC = NULL;
|
|
#endif
|
|
|
|
IsValidForMosaique = 0;
|
|
CurrentDecodedImage =
|
|
CurrentDecodedSegments =
|
|
CurrentDecodedSegments_MAX =
|
|
CurrentSize = 0;
|
|
#ifdef EXPORT_264
|
|
p264 = NULL;
|
|
#endif
|
|
|
|
CompQuality = 50;
|
|
CompResp = 100;
|
|
|
|
pScene = pscn;
|
|
return 0;
|
|
};
|
|
int StreamOut::FRAME()
|
|
{
|
|
#ifdef VIDEO_OPENLIB
|
|
OneBuf Output;
|
|
u32 OK_Continue;
|
|
u32 LastTileNumb;
|
|
u32 X,Y,*Ptr;
|
|
|
|
#ifdef DEBUG_DECODE
|
|
IsValidForMosaique = 1;
|
|
if (CodecDEC == NULL) CodecDEC = Decode_INIT(&Image);
|
|
#else
|
|
IsValidForMosaique = 0;
|
|
#endif
|
|
|
|
if (!pScene->ID_MEDIA[SourceIndex]) return 0;
|
|
if (Codec == NULL)
|
|
Image.Delete();
|
|
#ifdef COPYO2
|
|
if (Image.SetSize( pScene->ID_MEDIA[SourceIndex]->Image.SX>>1,
|
|
pScene->ID_MEDIA[SourceIndex]->Image.SY>>1, 1))
|
|
#else
|
|
if (Image.SetSize( pScene->ID_MEDIA[SourceIndex]->Image.SX,
|
|
pScene->ID_MEDIA[SourceIndex]->Image.SY, 1))
|
|
#endif
|
|
{
|
|
if (Codec) Encode_CLOSE(Codec);
|
|
Codec = NULL;
|
|
if (ulAssociatedTextureIndex != -1)
|
|
pScene->DI->DestroyTexture(ulAssociatedTextureIndex);
|
|
ulAssociatedTextureIndex = -1;
|
|
ulAssociatedTextureIndex = pScene->DI->CreateTexture(&Image,ulColorMode);
|
|
#ifdef DEBUG_DECODE
|
|
if (CodecDEC) Decode_CLOSE(CodecDEC);
|
|
CodecDEC = Decode_INIT(&Image);
|
|
#endif
|
|
Codec = Encode_INIT(&Image);
|
|
IsValidForMosaique = 0;
|
|
CurrentDecodedImage =
|
|
CurrentDecodedSegments =
|
|
CurrentDecodedSegments_MAX =
|
|
CurrentSize = 0;
|
|
pScene->MustEncodeFromScratch = 5;
|
|
#ifdef EXPORT_264
|
|
if (p264) CC_fclose(p264);
|
|
p264 = CC_fopen("TESt.264","wb");
|
|
#endif
|
|
|
|
}
|
|
if (!Codec) return 0;
|
|
|
|
|
|
START_RASTER(Stro);
|
|
#ifdef STROBYPASSNET
|
|
#ifdef COPYO2
|
|
COPY_O2_RGBA(&pScene->ID_MEDIA[SourceIndex]->Image,&Image);
|
|
CurrentBaseSize = CurrentSize = Encode_FRAME_AND_SOUND(Codec,&Image,CurrentDecodedBlock,pScene->MustEncodeFromScratch, CompQuality, CompResp);
|
|
memset(Image.BASE,0,Image.SX * Image.SY* 4);
|
|
#else
|
|
CurrentBaseSize = CurrentSize = Encode_FRAME_AND_SOUND(Codec,&pScene->ID_MEDIA[SourceIndex]->Image,CurrentDecodedBlock,pScene->MustEncodeFromScratch, CompQuality, CompResp);
|
|
#endif
|
|
#ifdef EXPORT_264
|
|
if (p264) fwrite(CurrentDecodedBlock,CurrentSize,1,p264);
|
|
#endif
|
|
if (pScene->MustEncodeFromScratch) pScene->MustEncodeFromScratch--;
|
|
#ifdef DEBUG_DECODE
|
|
if (CodecDEC && CurrentSize) Decode_FRAME_AND_SOUND(CodecDEC,&Image,CurrentDecodedBlock,CurrentSize);
|
|
#endif
|
|
STOP_RASTER(Stro);
|
|
return 1;
|
|
#endif
|
|
|
|
if (CurrentSize == 0)
|
|
{
|
|
#ifdef COPYO2
|
|
COPY_O2_RGBA(&pScene->ID_MEDIA[SourceIndex]->Image,&Image);
|
|
CurrentBaseSize = CurrentSize = Encode_FRAME_AND_SOUND(Codec,&Image,CurrentDecodedBlock,pScene->MustEncodeFromScratch, CompQuality, CompResp);
|
|
#else
|
|
CurrentBaseSize = CurrentSize = Encode_FRAME_AND_SOUND(Codec,&pScene->ID_MEDIA[SourceIndex]->Image,CurrentDecodedBlock,pScene->MustEncodeFromScratch, CompQuality, CompResp);
|
|
#endif
|
|
#ifdef EXPORT_264
|
|
if (p264) fwrite(CurrentDecodedBlock,CurrentSize,1,p264);
|
|
#endif
|
|
if (pScene->MustEncodeFromScratch) pScene->MustEncodeFromScratch--;
|
|
|
|
CurrentDecodedSegments_MAX = CurrentSize / IMAGE_SEGMENT_SIZE ;
|
|
CurrentDecodedSegments = 0;
|
|
CurrentDecodedImage++;
|
|
}
|
|
OK_Continue = CurrentSize;
|
|
while (OK_Continue)
|
|
{
|
|
ImageHeader *IH;
|
|
Output.SetIP(NET_IO_IP_WORLD);
|
|
Output.SetBufPort(pScene->NetObj->MyPort);
|
|
|
|
IH = (ImageHeader *)Output.BufDATA;
|
|
IH->Flag = 'PICT';
|
|
IH->SX = Image.SX;
|
|
IH->SY = Image.SY;
|
|
|
|
IH->ImageNum = CurrentDecodedImage;
|
|
IH->Image_SEGMENT = CurrentDecodedSegments;
|
|
IH->Image_SEGMENT_MAX = CurrentDecodedSegments_MAX;
|
|
if (CurrentSize >= IMAGE_SEGMENT_SIZE)
|
|
Output.Size = IMAGE_SEGMENT_SIZE;
|
|
else
|
|
Output.Size = CurrentSize;
|
|
memcpy(Output.BufDATA + sizeof(ImageHeader),CurrentDecodedBlock + CurrentDecodedSegments * IMAGE_SEGMENT_SIZE,Output.Size);
|
|
Output.Size += sizeof(ImageHeader);
|
|
if (pScene->NetObj->NET_DataSend(&Output) == 0)
|
|
{
|
|
CurrentDecodedSegments++;
|
|
if (CurrentSize >= IMAGE_SEGMENT_SIZE)
|
|
CurrentSize -= IMAGE_SEGMENT_SIZE;
|
|
else
|
|
CurrentSize = 0;
|
|
OK_Continue = CurrentSize;
|
|
} else
|
|
OK_Continue = 0;
|
|
}
|
|
#ifdef DEBUG_DECODE
|
|
if (CodecDEC && (CurrentSize == 0))
|
|
{
|
|
//memset(Image.BASE,0,Image.SX * Image.SY* 4);
|
|
Decode_FRAME_AND_SOUND(CodecDEC,&Image,CurrentDecodedBlock,CurrentBaseSize);
|
|
char TEXT[200];
|
|
sprintf(TEXT,"%2i,%03iko",CurrentBaseSize>>10,(CurrentBaseSize&1023) * 1000 / 1023);
|
|
DRawTEXT_Soft_B((u8*)TEXT,(u32*)Image.BASE,0,Image.SY - 16,Image.SX, Image.SY, 0xff0000);
|
|
// pScene->MustEncodeFromScratch = 1;
|
|
}
|
|
#endif
|
|
|
|
STOP_RASTER(Stro);
|
|
#endif //VIDEO_OPENLIB
|
|
|
|
return 0;
|
|
}
|
|
|
|
void StreamOut_SETSOURCE(INPUT_IO *pSTRO,u32 SourceIndex)
|
|
{
|
|
((StreamOut *)pSTRO)->SourceIndex = SourceIndex;
|
|
}
|
|
|
|
void StreamOut_SETCOMPQUALITY(INPUT_IO *pSTRO,u32 Q)
|
|
{
|
|
((StreamOut *)pSTRO)->CompQuality = Q;
|
|
}
|
|
|
|
void StreamOut_SETCOMPRESP(INPUT_IO *pSTRO,u32 R)
|
|
{
|
|
((StreamOut *)pSTRO)->CompResp = R;
|
|
}
|
|
|
|
INPUT_IO *StreamOut_CREATE(WORLD *pScene,char *Name)
|
|
{
|
|
u32 SX,SY;
|
|
StreamOut *Ret;
|
|
Ret = new(StreamOut);
|
|
|
|
Ret->INIT(pScene);
|
|
SX = 256;
|
|
SY = 256;
|
|
strcpy((char*)Ret->MediaName,Name);
|
|
|
|
Ret->SourceIndex = 0;
|
|
while (*Name && (!IsDeci(*Name))) Name++;
|
|
while (*Name && (IsDeci(*Name))) {Ret->SourceIndex *= 10; Ret->SourceIndex += IsDeci(*Name++) - 1;};
|
|
if (Ret->SourceIndex >= MAX_INPMED) Ret->SourceIndex = 0;
|
|
|
|
//Ret->SourceIndex = 0;
|
|
|
|
Ret->dTotalTime = 0;
|
|
Ret->dAvgFramePerSecond = 30.0;
|
|
Ret->Image.SetSize(SX, SY, 1);
|
|
return (INPUT_IO *)Ret;
|
|
};
|
|
|
|
#endif
|