示例#1
0
void	Scene::Mesh::Primitive::Init( Mesh& _Owner, const U8*& _pData ) {
	int	MaterialID = ReadU16( _pData, true );
	ASSERT( MaterialID < _Owner.m_Owner.m_MaterialsCount, "Material ID out of range!" );
	m_pMaterial = _Owner.m_Owner.m_ppMaterials[MaterialID];

	m_FacesCount = ReadU32( _pData );
	m_VerticesCount = ReadU32( _pData );

	// Read BBox in local space
	m_LocalBBoxMin.x = ReadF32( _pData );
	m_LocalBBoxMin.y = ReadF32( _pData );
	m_LocalBBoxMin.z = ReadF32( _pData );
	m_LocalBBoxMax.x = ReadF32( _pData );
	m_LocalBBoxMax.y = ReadF32( _pData );
	m_LocalBBoxMax.z = ReadF32( _pData );

	// Read indices
	m_pFaces = new U32[3*m_FacesCount];
	if ( m_VerticesCount <= 65536 )
	{
		for ( U32 FaceIndex=0; FaceIndex < m_FacesCount; FaceIndex++ )
		{
			m_pFaces[3*FaceIndex+0] = ReadU16( _pData );
			m_pFaces[3*FaceIndex+1] = ReadU16( _pData );
			m_pFaces[3*FaceIndex+2] = ReadU16( _pData );
		}
	}
	else
	{
		int	IndexBufferSize = 3*m_FacesCount*sizeof(U32);
		memcpy( m_pFaces, _pData, IndexBufferSize );
		_pData += IndexBufferSize;
	}

	// Read vertices
	m_VertexFormat = (VERTEX_FORMAT) *_pData++;
	int	VertexSize = 0;
	switch ( m_VertexFormat )
	{
	case P3N3G3B3T2: VertexSize = (3+3+3+3+2) * sizeof(float); break;
	}

	int		VertexBufferSize = m_VerticesCount * VertexSize;
	m_pVertices = new U8[VertexBufferSize];
	memcpy( m_pVertices, _pData, VertexBufferSize );
	_pData += VertexBufferSize;

	// Compute global bounding box
	m_GlobalBBoxMin = float3::MaxFlt;
	m_GlobalBBoxMax = -float3::MaxFlt;
	for ( U32 VertexIndex=0; VertexIndex < m_VerticesCount; VertexIndex++ )
	{
		float3	LocalPosition = *((float3*) ((U8*) m_pVertices + VertexIndex * VertexSize));
		float3	WorldPosition = float4( LocalPosition, 1 ) * _Owner.m_Local2World;
		m_GlobalBBoxMin = m_GlobalBBoxMin.Min( WorldPosition );
		m_GlobalBBoxMax = m_GlobalBBoxMax.Max( WorldPosition );
	}
}
示例#2
0
int FlcCheckFrame()
{ flc.pFrame=flc.pMembuf+flc.FrameSize-16;
  ReadU32(&flc.FrameSize, flc.pFrame+0);
  ReadU16(&flc.FrameCheck, flc.pFrame+4);
  ReadU16(&flc.FrameChunks, flc.pFrame+6);
  ReadU16(&flc.DelayOverride, flc.pFrame+8); // not actually used in UFOINT.FLI, it turns out

#ifdef DEBUG
  printf("flc.FrameSize: %d\n", flc.FrameSize);
  printf("flc.FrameCheck: %d\n", flc.FrameCheck);
  printf("flc.FrameChunks: %d\n", flc.FrameChunks);
  printf("flc.DelayOverride: %d\n", flc.DelayOverride);
#endif

  flc.pFrame+=16;
  if(flc.FrameCheck==0x0f1fa) { 
    return(0);
  }

  flc.DelayOverride = 0; // not FRAME_TYPE means the value we read wasn't a delay at all

  if(flc.FrameCheck==0x0f100) { 
#ifdef DEBUG
    printf("Ani info!!!\n");
#endif
    return(0);
  }

  return(1);
} /* FlcCheckFrame */
示例#3
0
文件: Link.cpp 项目: dridri/bcflight
uint32_t Packet::ReadFloat( float* f )
{
	union { float f; uint32_t u; } u;
	uint32_t ret = ReadU32( &u.u );
	*f = u.f;
	return ret;
}
示例#4
0
void	Scene::Load( U16 _SceneResourceID ) {
	U32			SceneSize = 0;
	const U8*	pData = LoadResourceBinary( _SceneResourceID, "SCENE", &SceneSize );

	U32		Version = ReadU32( pData );	// Should be "GCX1"
	ASSERT( Version == 0x31584347L, "Unsupported scene version!" );

	// ==== Read Materials ====
	//
	m_MaterialsCount = ReadU16( pData );
	m_ppMaterials = new Material*[m_MaterialsCount];
	for ( int MaterialIndex=0; MaterialIndex < m_MaterialsCount; MaterialIndex++ ) {
		Material*	pMaterial = new Material( *this );
		m_ppMaterials[MaterialIndex] = pMaterial;

		pMaterial->Init( pData );
	}

	// ==== Read Node Hierarchy ====
	//
	m_NodesCount = 0;
	m_MeshesCount = 0;
	m_LightsCount = 0;
	m_CamerasCount = 0;
	m_ProbesCount = 0;

	m_pROOT = CreateNode( NULL, pData );
}
示例#5
0
文件: DataIO.cpp 项目: Jeffxz/nodeas
	float DataInput::ReadFloat()
	{
		union {
			uint32_t u;
			float f;
		} ptr;
		ptr.u = ReadU32();
		return ptr.f;
	}
示例#6
0
void FlcDoOneFrame()
{ int ChunkCount; 
  ChunkCount=flc.FrameChunks;
  flc.pChunk=flc.pMembuf;
  if ( SDL_LockSurface(flc.mainscreen) < 0 )
    return;
  // if (!ChunkCount) printf("Empty frame! %d\n", flc.FrameCount); // this is normal and used for delays
  while(ChunkCount--) {
    ReadU32(&flc.ChunkSize, flc.pChunk+0);
    ReadU16(&flc.ChunkType, flc.pChunk+4);

#ifdef DEBUG
    printf("flc.ChunkSize: %d\n", flc.ChunkSize);
    printf("flc.ChunkType: %d aka %x\n", flc.ChunkType, flc.ChunkType);
	if (flc.DelayOverride) printf("DelayOverride: %d\n", flc.DelayOverride);
#endif

    switch(flc.ChunkType) {
      case 4:
        COLORS256();
      break;
      case 7:
        SS2();
      break;
      case 11:
        DECODE_COLOR();
      break;
      case 12:
        DECODE_LC();
      break;
      case 13:
        BLACK();
      break;
      case 15:
        DECODE_BRUN();
      break;
      case 16:
        DECODE_COPY();
      break;
      case 18:
#ifdef DEBUG
        printf("Chunk 18 not yet done.\n");
#endif
      break;
      default:
        Log(LOG_WARNING) << "Ieek an non implemented chunk type:" << flc.ChunkType;
    }
    flc.pChunk+=flc.ChunkSize;
  }
  SDL_UnlockSurface(flc.mainscreen);
} /* FlcDoOneFrame */
示例#7
0
int FlcCheckHeader(const char *filename)
{ 
if((flc.file=fopen(filename, "rb"))==NULL) {
    Log(LOG_ERROR) << "Could not open flx file: " << filename;
		return -1;
  }

  FlcReadFile(128);

  ReadU32(&flc.HeaderSize, flc.pMembuf);
  ReadU16(&flc.HeaderCheck, flc.pMembuf+4);
  ReadU16(&flc.HeaderFrames, flc.pMembuf+6);
  ReadU16(&flc.HeaderWidth, flc.pMembuf+8);
  ReadU16(&flc.HeaderHeight, flc.pMembuf+10);
  ReadU16(&flc.HeaderDepth, flc.pMembuf+12);
  ReadU16(&flc.HeaderSpeed, flc.pMembuf+16);

#ifdef DEBUG
  printf("flc.HeaderSize: %d\n", flc.HeaderSize);
  printf("flc.HeaderCheck: %d\n", flc.HeaderCheck);
  printf("flc.HeaderFrames: %d\n", flc.HeaderFrames);
  printf("flc.HeaderWidth: %d\n", flc.HeaderWidth);
  printf("flc.HeaderHeight: %d\n", flc.HeaderHeight);
  printf("flc.HeaderDepth: %d\n", flc.HeaderDepth);
  printf("flc.HeaderSpeed: %lf\n", flc.HeaderSpeed);
#endif


  if((flc.HeaderCheck==SDL_SwapLE16(0x0AF12)) || (flc.HeaderCheck==SDL_SwapLE16(0x0AF11))) { 
    flc.screen_w=flc.HeaderWidth;
    flc.screen_h=flc.HeaderHeight;
	Log(LOG_INFO) << "Playing flx, " << flc.screen_w << "x" << flc.screen_h << ", " << flc.HeaderFrames << " frames";
    flc.screen_depth=8;
	if(flc.HeaderCheck == SDL_SwapLE16(0x0AF11)){
      flc.HeaderSpeed*=1000.0/70.0;
    }
    return(0);
  }
  return(1);

} /* FlcCheckHeader */
示例#8
0
文件: Link.cpp 项目: dridri/bcflight
uint32_t Packet::ReadU32()
{
	uint32_t ret = 0;
	ReadU32( &ret );
	return ret;
}
示例#9
0
void bus_put_frame(bus_frame *frame)
{
	u16 current_frame_idx = ReadU16(frame->data);
	for (PacketNode * p = packetList; p != NULL; p = p->next)
	{
		for (FrameNode *fp = p->frameList; fp != NULL; fp = fp->next)
		{
			if (fp->frame.srcId == frame->srcId && fp->frame.sessionId == frame->sessionId)
			{
				u16 pre_frame_idx = ReadU16(p->frameList->frame.data);

				//检查最后插进去的idx 跟这个是不是连续的
				if (current_frame_idx == pre_frame_idx + 1)
				{
					//拼接到后面去
					FrameNode *f_temp = my_malloc(sizeof(FrameNode));
					memmove(&f_temp->frame, frame, sizeof(bus_frame));
					f_temp->next = p->frameList;
					p->frameList = f_temp;

					if (p->packetLen == ( (current_frame_idx - 1) * 6 + frame->data_len - 2) )
					{
						//BUS_LOG("收到最后一帧\r\n");
						switch (frame->functionId)
						{
							case BUS_PACK_FUNC_SEND:   //用于发送方给接收方传送数据
							{
								rxHanleCnt++;
								//给个ACK 说明肯定接收到了
								bus_simple_send(frame->adapterId, frame->srcId, BUS_PACK_FUNC_ACK, frame->sessionId, 0, NULL);
								break;
							}
							case BUS_PACK_FUNC_RETURN:  //用于数据发送出去,每一帧的回复 代表接收方收到
							{
								retHandleCnt++;
								break;
							}
						}
					}
				}
				else
				{
					//如果不是连续的 那么把这一整个packet 全部删除
					for (FrameNode *it = p->frameList; it != NULL;)
					{
						FrameNode *itemp = it;
						it = it->next;
						my_free(itemp);
					}
					p->frameList = NULL;
					if (p == packetList)
					{
						packetList = packetList->next;
						my_free(p);
					}
					else
					{
						for (PacketNode * p1 = packetList; p1 != NULL; p1 = p1->next)
						{
							if (p1->next == p)
							{
								p1->next = p->next;
								my_free(p);
								break;
							}
						}
					}
					goto END;	// 清除了之前的死包之后 应该插入新的包 不应该直接return
				}
				return;
			}
			else
			{
				break;	//第一个 frame 节点的 srcId 和sessionId 不一样 就没有必要再观察了
			}
		}

	}
END:
	//没有找到 看看是不是首帧
	if (current_frame_idx != 0)
	{
		//BUS_LOG("首帧丢失 cur= %d\r\n", current_frame_idx);
	}
	else
	{
		//插入的是首帧
		PacketNode * temp = my_malloc(sizeof(PacketNode));
		FrameNode *f_temp = my_malloc(sizeof(FrameNode));
		memmove(&f_temp->frame, frame, sizeof(bus_frame));
		// 给 packet 长度赋值
		temp->packetLen = ReadU32(frame->data + 2);
		
		f_temp->next = temp->frameList;
		temp->frameList = f_temp;
		temp->createdTime = bus_os_time_get();

		temp->next = packetList;
		packetList = temp;

		if (temp->packetLen == 0 )	//加入这个帧就一个包 那么也要进行分析
		{
			//BUS_LOG("收到最后一帧\r\n");
			switch (frame->functionId)
			{
				case BUS_PACK_FUNC_SEND:   //用于发送方给接收方传送数据
				{
					rxHanleCnt++;
					//给个ACK 说明肯定接收到了
					bus_simple_send(frame->adapterId, frame->srcId, BUS_PACK_FUNC_ACK, frame->sessionId, 0, NULL);
					break;
				}
				case BUS_PACK_FUNC_RETURN:  //用于数据发送出去,每一帧的回复 代表接收方收到
				{
					retHandleCnt++;
					break;
				}
			}
		}

	}
}
示例#10
0
//Publish using RTMP_SendPacket()  
int publish_using_packet(){  
	RTMP *rtmp=NULL;                             
	RTMPPacket *packet=NULL;  
	uint32_t start_time=0;  
	uint32_t now_time=0;  
	//the timestamp of the previous frame  
	long pre_frame_time=0;  
	long lasttime=0;  
	int bNextIsKey=1;  
	uint32_t preTagsize=0;  

	//packet attributes  
	uint32_t type=0;                          
	uint32_t datalength=0;             
	uint32_t timestamp=0;             
	uint32_t streamid=0;                          

	FILE*fp=NULL;  
	fp=fopen("../live.flv","rb");  
	if (!fp){  
		RTMP_LogPrintf("Open File Error.\n");  
	//	CleanupSockets();  
		return -1;  
	}  

	/* set log level */  
	//RTMP_LogLevel loglvl=RTMP_LOGDEBUG;  
	//RTMP_LogSetLevel(loglvl);  

//	if (!InitSockets()){  
//		RTMP_LogPrintf("Init Socket Err\n");  
//		return -1;  
//	}  

	rtmp=RTMP_Alloc();  
	RTMP_Init(rtmp);  
	//set connection timeout,default 30s  
	rtmp->Link.timeout=5;                        
	if(!RTMP_SetupURL(rtmp,"rtmp://101.251.251.93:1935/myapp/mystream"))  
	{  
		RTMP_Log(RTMP_LOGERROR,"SetupURL Err\n");  
		RTMP_Free(rtmp);  
	//	CleanupSockets();  
		return -1;  
	}  

	//if unable,the AMF command would be 'play' instead of 'publish'  
	RTMP_EnableWrite(rtmp);       

	if (!RTMP_Connect(rtmp,NULL)){  
		RTMP_Log(RTMP_LOGERROR,"Connect Err\n");  
		RTMP_Free(rtmp);  
	//	CleanupSockets();  
		return -1;  
	}  

	if (!RTMP_ConnectStream(rtmp,0)){  
		RTMP_Log(RTMP_LOGERROR,"ConnectStream Err\n");  
		RTMP_Close(rtmp);  
		RTMP_Free(rtmp);  
//		CleanupSockets();  
		return -1;  
	}  

	packet=(RTMPPacket*)malloc(sizeof(RTMPPacket));  
	RTMPPacket_Alloc(packet,1024*64);  
	RTMPPacket_Reset(packet);  

	packet->m_hasAbsTimestamp = 0;          
	packet->m_nChannel = 0x04;  
	packet->m_nInfoField2 = rtmp->m_stream_id;  

	RTMP_LogPrintf("Start to send data ...\n");  

	//jump over FLV Header  
	fseek(fp,9,SEEK_SET);       
	//jump over previousTagSizen  
	fseek(fp,4,SEEK_CUR);     
	start_time=RTMP_GetTime();  
	while(1)  
	{  
		if((((now_time=RTMP_GetTime())-start_time)  
					<(pre_frame_time)) && bNextIsKey){          
			//wait for 1 sec if the send process is too fast  
			//this mechanism is not very good,need some improvement  
			if(pre_frame_time>lasttime){  
				RTMP_LogPrintf("TimeStamp:%8lu ms\n",pre_frame_time);  
				lasttime=pre_frame_time;  
			}  
			sleep(1);  
			continue;  
		}  

		//not quite the same as FLV spec  
		if(!ReadU8(&type,fp))       
			break;  
		if(!ReadU24(&datalength,fp))  
			break;  
		if(!ReadTime(&timestamp,fp))  
			break;  
		if(!ReadU24(&streamid,fp))  
			break;  

		if (type!=0x08&&type!=0x09){  
			//jump over non_audio and non_video frame,  
			//jump over next previousTagSizen at the same time  
			fseek(fp,datalength+4,SEEK_CUR);  
			continue;  
		}  

		if(fread(packet->m_body,1,datalength,fp)!=datalength)  
			break;  

		packet->m_headerType = RTMP_PACKET_SIZE_LARGE;  
		packet->m_nTimeStamp = timestamp;  
		packet->m_packetType = type;  
		packet->m_nBodySize  = datalength;  
		pre_frame_time=timestamp;  

		if (!RTMP_IsConnected(rtmp)){  
			RTMP_Log(RTMP_LOGERROR,"rtmp is not connect\n");  
			break;  
		}  
		if (!RTMP_SendPacket(rtmp,packet,0)){  
			RTMP_Log(RTMP_LOGERROR,"Send Error\n");  
			break;  
		}  

		if(!ReadU32(&preTagsize,fp))  
			break;  

		if(!PeekU8(&type,fp))  
			break;  
		if(type==0x09){  
			if(fseek(fp,11,SEEK_CUR)!=0)  
				break;  
			if(!PeekU8(&type,fp)){  
				break;  
			}  
			if(type==0x17)  
				bNextIsKey=1;  
			else  
				bNextIsKey=0;  

			fseek(fp,-11,SEEK_CUR);  
		}  
	}                 

	RTMP_LogPrintf("\nSend Data Over\n");  

	if(fp)  
		fclose(fp);  

	if (rtmp!=NULL){  
		RTMP_Close(rtmp);          
		RTMP_Free(rtmp);   
		rtmp=NULL;  
	}  
	if (packet!=NULL){  
		RTMPPacket_Free(packet);      
		free(packet);  
		packet=NULL;  
	}  

//	CleanupSockets();  
	return 0;  
}  
示例#11
0
bool LoadWavFromFileInMemory(const u8 *fileData, size_t numBytes, std::vector<u8> &dst, bool *isStereo, bool *is16Bit, int *frequency)
{
    if (!fileData || numBytes == 0)
    {
        LogError("Null input data passed in");
        return false;
    }

    if (!isStereo || !is16Bit || !frequency)
    {
        LogError("Outputs not set");
        return false;
    }

    unsigned int index = 0;
    
    u8 riff_text[4];
    ReadBytes(riff_text, fileData, index, 4);
    if (!!memcmp(riff_text, "RIFF", 4))
    {
        LogError("No RIFF chunk in WAV data");
        return false;
    }
    if (index >= numBytes) 
        return false;

    ReadU32(fileData, index);
    u8 wave_text[4];
    ReadBytes(wave_text, fileData, index, 4);
    if (!!memcmp(wave_text, "WAVE", 4))
    {
        LogError("No WAVE chunk in WAV data");
        return false;
    }
    
    // Search for the fmt chunk
    for(;;)
    {
        if (index >= numBytes)
        {
            LogError("No fmt chunk in WAV data");
            return false;
        }
        u8 chunk_text[4]; 
        ReadBytes(chunk_text, fileData, index, 4);
        unsigned int chunk_size = ReadU32(fileData, index);
        if (!memcmp(chunk_text, "fmt ", 4))
            break;
        if (!chunk_size)
            return false;
        index += chunk_size;
    }
    
    if (index >= numBytes) 
        return false;

    u16 format = ReadU16(fileData, index);
    u16 channels = ReadU16(fileData, index);
    unsigned int sampleFrequency = ReadU32(fileData, index);
    /*unsigned int avgbytes =*/ ReadU32(fileData, index);
    /*unsigned int blockalign =*/ ReadU16(fileData, index);
    u16 bits = ReadU16(fileData, index);

    if (format != 1)
    {
        LogError("Sound is not PCM data");
        return false;
    }
    if (channels != 1 && channels != 2)
    {
        LogError("Sound is not either mono or stereo");
        return false;
    }
    if (bits != 8 && bits != 16)
    {
        LogError("Sound is not either 8bit or 16bit");
        return false;
    }
                            
    // Search for the data chunk
    unsigned int data_length = 0;
    for(;;)
    {
        if (index >= numBytes)
        {
            LogError("No data chunk in WAV data");
            return false;
        }
        u8 chunk_text[4]; 
        ReadBytes(chunk_text, fileData, index, 4);
        data_length = ReadU32(fileData, index);
        if (!memcmp(chunk_text, "data", 4))
            break;
        if (!data_length) return false;
        index += data_length;
    }        
    
    if (!data_length)
    {
        LogError("Zero numBytes data chunk in WAV data");
        return false;
    }
    
    std::ostringstream msg;
    msg << "Loaded WAV sound with " << channels << " channels " << bits << " bits, frequency " << sampleFrequency << " datasize " << data_length; 
    LogDebug(msg.str());
 
    dst.clear();
    dst.insert(dst.end(), &fileData[index], &fileData[index + data_length]);
    *isStereo = (channels == 2);
    *is16Bit = (bits == 16);
    *frequency = sampleFrequency;

    return true;
}
示例#12
0
    bool WavLoader::LoadFromBuffer(Sound* sound, u8* data, uint size)
    {        
        uint index = 0;
        
        if (index >= size) return false;
        u8 riff_text[4];
        ReadBytes(riff_text, data, index, 4);
        if (memcmp(riff_text, "RIFF", 4))
        {
            OpenALAudioModule::LogError("No RIFF chunk in WAV data");
            return false;
        }
        if (index >= size) return false;
        uint total_size = ReadU32(data, index);

        u8 wave_text[4];        
        ReadBytes(wave_text, data, index, 4);
        if (memcmp(wave_text, "WAVE", 4))
        {
            OpenALAudioModule::LogError("No WAVE chunk in WAV data");
            return false;
        }
        
        // Search for the fmt chunk
        for (;;)
        {
            if (index >= size)
            {
                OpenALAudioModule::LogError("No fmt chunk in WAV data");
                return false;
            }
            u8 chunk_text[4]; 
            ReadBytes(chunk_text, data, index, 4);
            uint chunk_size = ReadU32(data, index);
            if (!memcmp(chunk_text, "fmt ", 4))
                break;
            if (!chunk_size) return false;
            index += chunk_size;
        }
        
        if (index >= size) return false;
        u16 format = ReadU16(data, index);
        u16 channels = ReadU16(data, index);
        uint frequency = ReadU32(data, index);
        uint avgbytes = ReadU32(data, index);
        uint blockalign = ReadU16(data, index);
        u16 bits = ReadU16(data, index);
        
        if (format != 1)
        {
            OpenALAudioModule::LogError("Sound is not PCM data");
            return false;
        }
        if (channels != 1 && channels != 2)
        {
            OpenALAudioModule::LogError("Sound is not either mono or stereo");
            return false;
        }
        if (bits != 8 && bits != 16)
        {
            OpenALAudioModule::LogError("Sound is not either 8bit or 16bit");
            return false;
        }
                                
        // Search for the data chunk
        uint data_length = 0;
        for (;;)
        {
            if (index >= size)
            {
                OpenALAudioModule::LogError("No data chunk in WAV data");
                return false;
            }
            u8 chunk_text[4]; 
            ReadBytes(chunk_text, data, index, 4);
            data_length = ReadU32(data, index);
            if (!memcmp(chunk_text, "data", 4))
                break;
            if (!data_length) return false;
            index += data_length;
        }        
        
        if (!data_length)
        {
            OpenALAudioModule::LogError("Zero size data chunk in WAV data");
            return false;
        }
        
        std::ostringstream msg;
        msg << "Loaded WAV sound with " << channels << " channels " << bits << " bits, frequency " << frequency << " datasize " << data_length; 
        OpenALAudioModule::LogDebug(msg.str());
        
        Foundation::SoundServiceInterface::SoundBuffer wav_buffer;
        wav_buffer.data_.resize(data_length);
        memcpy(&wav_buffer.data_[0], &data[index], data_length);
        wav_buffer.frequency_ = frequency;
        wav_buffer.sixteenbit_  = (bits == 16);
        wav_buffer.stereo_ = (channels == 2);
        
        return sound->LoadFromBuffer(wav_buffer);
    }