size_t ClientStatuses::serialize(Buffer& _dst, size_t _offset)
{
	_pm_checkInit();
	if(_offset == 0) _dst.clear();

	_offset = WriteInt8(_dst, _offset, _pf_packetId);
	_offset = WriteInt8(_dst, _offset, _pf_payload);


	return _offset;
}
size_t CloseWIndow::serialize(Buffer& _dst, size_t _offset)
{
	_pm_checkInit();
	if(_offset == 0) _dst.clear();

	_offset = WriteInt8(_dst, _offset, _pf_packetId);
	_offset = WriteInt8(_dst, _offset, _pf_windowId);


	return _offset;
}
size_t DisplayScoreboard::serialize(Buffer& _dst, size_t _offset)
{
	_pm_checkInit();
	if(_offset == 0) _dst.clear();

	_offset = WriteInt8(_dst, _offset, _pf_packetId);
	_offset = WriteInt8(_dst, _offset, _pf_position);
	_offset = WriteString16(_dst, _offset, _pf_scoreName);


	return _offset;
}
size_t EntityStatus::serialize(Buffer& _dst, size_t _offset)
{
	_pm_checkInit();
	if(_offset == 0) _dst.clear();

	_offset = WriteInt8(_dst, _offset, _pf_packetId);
	_offset = WriteInt32(_dst, _offset, _pf_entityId);
	_offset = WriteInt8(_dst, _offset, _pf_entityStatus);


	return _offset;
}
示例#5
0
size_t SetSlot::serialize(Buffer& _dst, size_t _offset)
{
	_pm_checkInit();
	if(_offset == 0) _dst.clear();

	_offset = WriteInt8(_dst, _offset, _pf_packetId);
	_offset = WriteInt8(_dst, _offset, _pf_windowId);
	_offset = WriteInt16(_dst, _offset, _pf_slotNum);


	return _offset;
}
size_t UpdateWindowProperty::serialize(Buffer& _dst, size_t _offset)
{
	_pm_checkInit();
	if(_offset == 0) _dst.clear();

	_offset = WriteInt8(_dst, _offset, _pf_packetId);
	_offset = WriteInt8(_dst, _offset, _pf_windowId);
	_offset = WriteInt16(_dst, _offset, _pf_property);
	_offset = WriteInt16(_dst, _offset, _pf_value);


	return _offset;
}
size_t DestroyEntity::serialize(Buffer& _dst, size_t _offset)
{
	_pm_checkInit();
	if(_offset == 0) _dst.clear();

	_offset = WriteInt8(_dst, _offset, _pf_packetId);
	_offset = WriteInt8(_dst, _offset, _pf_entityCount);

	for(int i = 0; i < _pf_entityCount; ++i)
		_offset = WriteInt32(_dst, _offset, _pf_entityIds[i]);
	
	return _offset;
}
size_t Handshake::serialize(Buffer& _dst, size_t _offset)
{
	_pm_checkInit();
	if(_offset == 0) _dst.clear();

	_offset = WriteInt8(_dst, _offset, _pf_packetId);
	_offset = WriteInt8(_dst, _offset, _pf_protVer);
	_offset = WriteString16(_dst, _offset, _pf_username);
	_offset = WriteString16(_dst, _offset, _pf_host);
	_offset = WriteInt32(_dst, _offset, _pf_port);


	return _offset;
}
size_t SpawnGlobalEntity::serialize(Buffer& _dst, size_t _offset)
{
	_pm_checkInit();
	if(_offset == 0) _dst.clear();

	_offset = WriteInt8(_dst, _offset, _pf_packetId);
	_offset = WriteInt32(_dst, _offset, _pf_entityId);
	_offset = WriteInt8(_dst, _offset, _pf_type);
	_offset = WriteInt32(_dst, _offset, _pf_x);
	_offset = WriteInt32(_dst, _offset, _pf_y);
	_offset = WriteInt32(_dst, _offset, _pf_z);


	return _offset;
}
size_t ClickWindow::serialize(Buffer& _dst, size_t _offset)
{
	_pm_checkInit();
	if(_offset == 0) _dst.clear();

	_offset = WriteInt8(_dst, _offset, _pf_packetId);
	_offset = WriteInt8(_dst, _offset, _pf_windowId);
	_offset = WriteInt16(_dst, _offset, _pf_slot);
	_offset = WriteInt8(_dst, _offset, _pf_button);
	_offset = WriteInt16(_dst, _offset, _pf_actionNumber);
	_offset = WriteInt8(_dst, _offset, _pf_mode);
	//_offset = WriteSlotData(_dst, _offset, _pf_clickedItem);
	_offset = _pf_clickedItem.serialize(_dst, _offset);


	return _offset;
}
size_t SpawnObject::serialize(Buffer& _dst, size_t _offset)
{
	_pm_checkInit();
	if(_offset == 0) _dst.clear();

	_offset = WriteInt8(_dst, _offset, _pf_packetId);
	_offset = WriteInt32(_dst, _offset, _pf_entityId);
	_offset = WriteInt8(_dst, _offset, _pf_type);
	_offset = WriteInt32(_dst, _offset, _pf_x);
	_offset = WriteInt32(_dst, _offset, _pf_y);
	_offset = WriteInt32(_dst, _offset, _pf_z);
	_offset = WriteInt8(_dst, _offset, _pf_pitch);
	_offset = WriteInt8(_dst, _offset, _pf_yaw);
	// —делать запись Object data


	return _offset;
}
示例#12
0
static int AVIMux( hb_mux_object_t * m, hb_mux_data_t * mux_data,
                   hb_buffer_t * buf )
{
    hb_job_t   * job   = m->job;
    hb_title_t * title = job->title;

    hb_audio_t * audio;
    int i;

    /* Update index */
    IndexAddInt32( m->index, mux_data->fourcc );
    IndexAddInt32( m->index, (buf->frametype & HB_FRAME_KEY) ? AVIIF_KEYFRAME : 0 );
    IndexAddInt32( m->index, 4 + m->size );
    IndexAddInt32( m->index, buf->size );

    /* Write the chunk to the file */
    fseek( m->file, 0, SEEK_END );
    WriteInt32( m->file, mux_data->fourcc );
    WriteInt32( m->file, buf->size );
    WriteBuffer( m->file, buf );

    /* Chunks must be 2-bytes aligned */
    if( buf->size & 1 )
    {
        WriteInt8( m->file, 0 );
    }

    /* Update headers */
    m->size += 8 + EVEN( buf->size );
    mux_data->header.Length++;

    /* RIFF size */
    fseek( m->file, 4, SEEK_SET );
    WriteInt32( m->file, 2052 + m->size );

    /* Mmmmh that's not nice */
    fseek( m->file, 140, SEEK_SET );
    WriteInt32( m->file, job->mux_data->header.Length );
    for( i = 0; i < hb_list_count( title->list_audio ); i++ )
    {
        int is_passthru;
        audio = hb_list_item( title->list_audio, i );
        is_passthru = (audio->config.out.codec == HB_ACODEC_AC3) ||
                      (audio->config.out.codec == HB_ACODEC_DCA);
        fseek( m->file, 264 + i *
               ( 102 + ( is_passthru ? 0 :
                 sizeof( hb_wave_mp3_t ) ) ), SEEK_SET );
        WriteInt32( m->file, audio->priv.mux_data->header.Length );
    }

    /* movi size */
    fseek( m->file, 2052, SEEK_SET );
    WriteInt32( m->file, 4 + m->size );
    return 0;
}
示例#13
0
size_t Player::serialize(Buffer& _dst, size_t _offset)
{
	_pm_checkInit();
	if(_offset == 0) _dst.clear();

	_offset = WriteInt8(_dst, _offset, _pf_packetId);
	_offset = WriteBool(_dst, _offset, _pf_onGround);


	return _offset;
}
size_t ChatMessage::serialize(Buffer& _dst, size_t _offset)
{
	_pm_checkInit();
	if(_offset == 0) _dst.clear();

	_offset = WriteInt8(_dst, _offset, _pf_packetId);
	_offset = WriteString16(_dst, _offset, _pf_text);


	return _offset;
}
示例#15
0
文件: moov.cpp 项目: SteveShaw/povray
/*
void ReadAtomHeader(IStream *file, Type& type, POV_LONG& size)
{
    ReadInt4(file, size);

    if(size == 0) // atom goes up to end of file
    {
        ReadType(file, type);

        POV_LONG t = file->tellg();
        file->seekg(0, IOBase::SEEK_END);
        size = file->tellg() - t + 8;
        file->seekg(t, IOBase::SEEK_SET);
    }
    else if(size == 1) // atom sizes is outside 32-bit range
    {
        ReadType(file, type);

        ReadInt8(file, size);
    }
    else
        ReadType(file, type);
}
*/
void WriteAtomHeader(OStream *file, Type type, POV_LONG size)
{
    if(size < 0) // temporary size - always assume 64-bit size
    {
        WriteInt4(file, 1);
        WriteType(file, type);
        WriteInt8(file, 0);
    }
    else if(size > UINT_MAX) // size outside 32-bit range
    {
        WriteInt4(file, 1);
        WriteType(file, type);
        WriteInt8(file, size);
    }
    else // size within 32-bit range
    {
        WriteType(file, type);
        WriteInt4(file, size);
    }
}
size_t CollectItem::serialize(Buffer& _dst, size_t _offset)
{
	_pm_checkInit();
	if(_offset == 0) _dst.clear();

	_offset = WriteInt8(_dst, _offset, _pf_packetId);
	_offset = WriteInt32(_dst, _offset, _pf_collectedEID);
	_offset = WriteInt32(_dst, _offset, _pf_collectorEID);


	return _offset;
}
示例#17
0
size_t ItemData::serialize(Buffer& _dst, size_t _offset)
{
	_pm_checkInit();
	if(_offset == 0) _dst.clear();

	_offset = WriteInt8(_dst, _offset, _pf_packetId);
	_offset = WriteInt16(_dst, _offset, _pf_itemType);
	_offset = WriteInt16(_dst, _offset, _pf_itemId);
	_offset = WriteInt16(_dst, _offset, _pf_textLength);
	_offset = WriteByteArray(_dst, _offset, _pf_text);


	return _offset;
}
size_t MapChunkBulk::serialize(Buffer& _dst, size_t _offset)
{
	_pm_checkInit();
	if(_offset == 0) _dst.clear();

	_offset = WriteInt8(_dst, _offset, _pf_packetId);
	_offset = WriteInt16(_dst, _offset, _pf_chunkColumnCount);
	_offset = WriteInt32(_dst, _offset, _pf_dataLength);
	_offset = WriteBool(_dst, _offset, _pf_skyLightSent);
	_offset = WriteByteArray(_dst, _offset, _pf_chunkData);
	_offset = WriteByteArray(_dst, _offset, _pf_metaInfo);


	return _offset;
}
示例#19
0
void Packet::WriteChar(char* value) {
	int len = strlen(value);
	if (len > 127) len = 127;

	WriteInt8(len);

	data.resize(data.size() + len);

	for(int i=0; i!=len; i++) {
		char temp = value[i];
		if (temp != '\0' && (temp < 32 || temp > 128)) temp = 32;

		data[data.size() - len + i] = temp;
		//memcpy(&data[data.size() - strlen(value) + i], &value[i], sizeof(char));
	}
}
size_t PlayerPositionAndLook::serialize(Buffer& _dst, size_t _offset)
{
	_pm_checkInit();
	if(_offset == 0) _dst.clear();

	_offset = WriteInt8(_dst, _offset, _pf_packetId);
	_offset = WriteDouble(_dst, _offset, _pf_x);
	_offset = WriteDouble(_dst, _offset, _pf_y);
	_offset = WriteDouble(_dst, _offset, _pf_stance);
	_offset = WriteDouble(_dst, _offset, _pf_z);
	_offset = WriteFloat(_dst, _offset, _pf_yaw);
	_offset = WriteFloat(_dst, _offset, _pf_pitch);
	_offset = WriteBool(_dst, _offset, _pf_onGround);


	return _offset;
}
示例#21
0
size_t Explosion::serialize(Buffer& _dst, size_t _offset)
{
	_pm_checkInit();
	if(_offset == 0) _dst.clear();

	_offset = WriteInt8(_dst, _offset, _pf_packetId);
	_offset = WriteDouble(_dst, _offset, _pf_x);
	_offset = WriteDouble(_dst, _offset, _pf_y);
	_offset = WriteDouble(_dst, _offset, _pf_z);
	_offset = WriteFloat(_dst, _offset, _pf_radius);
	_offset = WriteInt32(_dst, _offset, _pf_recordCount);
	_offset = WriteByteArray(_dst, _offset, _pf_records);
	_offset = WriteFloat(_dst, _offset, _pf_playerMotionX);
	_offset = WriteFloat(_dst, _offset, _pf_playerMotionY);
	_offset = WriteFloat(_dst, _offset, _pf_playerMotionZ);


	return _offset;
}
示例#22
0
size_t Particle::serialize(Buffer& _dst, size_t _offset)
{
	_pm_checkInit();
	if(_offset == 0) _dst.clear();

	_offset = WriteInt8(_dst, _offset, _pf_packetId);
	_offset = WriteString16(_dst, _offset, _pf_particleName);
	_offset = WriteFloat(_dst, _offset, _pf_x);
	_offset = WriteFloat(_dst, _offset, _pf_y);
	_offset = WriteFloat(_dst, _offset, _pf_z);
	_offset = WriteFloat(_dst, _offset, _pf_offsetX);
	_offset = WriteFloat(_dst, _offset, _pf_offsetY);
	_offset = WriteFloat(_dst, _offset, _pf_offsetZ);
	_offset = WriteFloat(_dst, _offset, _pf_particleSpeed);
	_offset = WriteInt32(_dst, _offset, _pf_numOfParticles);


	return _offset;
}
示例#23
0
文件: moov.cpp 项目: SteveShaw/povray
void PostWriteFrame(OStream *file, POV_LONG bytes, const Animation::WriteOptions&, vector<string>&, void *state)
{
    PrivateData *pd = reinterpret_cast<PrivateData *>(state);

    if(pd == NULL)
        throw POV_EXCEPTION_CODE(kNullPointerErr);

    // update mdat size

    file->seekg(0, SEEK_END);
    pd->mdatsize = file->tellg() + 16;
    file->seekg(8, SEEK_SET);
    WriteInt8(file, pd->mdatsize);
    file->seekg(0, SEEK_END);

    if(bytes > 2147483647) // 2^31 - 1
        throw POV_EXCEPTION(kInvalidDataSizeErr, "Cannot handle frame data larger than 2^31 bytes!");

    pd->imagesizes.push_back(int(bytes));
}
示例#24
0
void CObjectOStream::WriteGi(const TGi& obj)
{
    WriteInt8(obj);
}
示例#25
0
myint WriteConfig()
{
#ifndef EMBEDDED
#ifdef ENABLE_CONTROLS
	myint i;
#endif
	myint fd;
	int32_t cs;
	
	fd = OpenWrite(configname);
	
	if (fd != -1) {
		WriteBytes(fd, (byte *)GAMEHDR, 8);	/* WOLF3D, 0, 0 */
		WriteBytes(fd, (byte *)CFGTYPE, 4);	/* CFG, 0 */
		WriteInt32(fd, 0x00000000);		/* Version (integer) */
		WriteBytes(fd, (byte *)GAMETYPE, 4);	/* XXX, 0 */
		WriteInt32(fd, time(NULL));		/* Time */
		WriteInt32(fd, 0x00000000);		/* Padding */
		WriteInt32(fd, 0x00000000);		/* Checksum (placeholder) */
	
#ifdef ENABLE_HIGHSCORES
		for (i = 0; i < 7; i++) { /* MaxScores = 7 */
			WriteBytes(fd, (byte *)Scores[i].name, 58);
			WriteInt32(fd, Scores[i].score);
			WriteInt32(fd, Scores[i].completed);
			WriteInt32(fd, Scores[i].episode);
		}
#endif
		
		WriteInt32(fd, viewsize);

		/* sound config, etc. (to be done) */
		WriteInt32(fd, 0); /* padding */
		WriteInt32(fd, 0); /* padding */
		WriteInt32(fd, 0); /* padding */
		WriteInt32(fd, 0); /* padding */
		WriteInt32(fd, 0); /* padding */
		WriteInt32(fd, 0); /* padding */
		WriteInt32(fd, 0); /* padding */
		WriteInt32(fd, 0); /* padding */
			
#ifdef ENABLE_CONTROLS
		/* direction keys */	
		for (i = 0; i < 4; i++) {
			WriteInt32(fd, dirscan[i]);
		}
			
		/* other game keys */
		for (i = 0; i < 8; i++) { /* NUMBUTTONS = 8 */
			WriteInt32(fd, buttonscan[i]);
		}
			
		/* mouse enabled */
		WriteInt8(fd, mouseenabled);
			
		/* mouse buttons */
		for (i = 0; i < 4; i++) {
			WriteInt32(fd, buttonmouse[i]);
		}
#endif
			
		/* mouse adjustment */
		WriteInt32(fd, mouseadjustment);
			
		/* joystick (to be done) */
		WriteInt32(fd, -1);

		CloseWrite(fd);
		
		fd = OpenRead(configname);
		ReadSeek(fd, 32, SEEK_SET);
		cs = CalcFileChecksum(fd, ReadLength(fd) - 32);
		CloseRead(fd);
		
		fd = OpenWriteAppend(configname);
		WriteSeek(fd, 28, SEEK_SET);
		WriteInt32(fd, cs);
		
		CloseWrite(fd);
	}
	
#endif
	return 0;
}
示例#26
0
 void InteropOutputStream::WriteBool(const bool val)
 {
     WriteInt8(val ? 1 : 0);
 }
示例#27
0
myint SaveTheGame(const char *fn, const char *tag, myint dx, myint dy)
{
	objtype *ob;
	myint fd, i, x, y;
	int32_t cs;
	
	fd = OpenWrite(fn);
	
	if (fd != -1) {
		WriteBytes(fd, (byte *)GAMEHDR, 8);
		WriteBytes(fd, (byte *)SAVTYPE, 4);
		WriteInt32(fd, 0x00000000); /* write version */
		WriteBytes(fd, (byte *)GAMETYPE, 4);
	
		WriteInt32(fd, time(NULL));
		WriteInt32(fd, 0x00000000);
	
		WriteInt32(fd, 0x00000000); /* write checksum (placeholder) */
	
		WriteBytes(fd, (byte *)tag, 32); /* write savegame name */
	
		DiskFlopAnim(dx, dy);
	
		WriteInt32(fd, gamestate_difficulty);
		WriteInt32(fd, gamestate.mapon);
		WriteInt32(fd, gamestate.oldscore);
		WriteInt32(fd, gamestate.score);
		WriteInt32(fd, gamestate.nextextra);
		WriteInt32(fd, gamestate.lives);
		WriteInt32(fd, gamestate.health);
		WriteInt32(fd, gamestate.ammo);
		WriteInt32(fd, gamestate.keys);
		WriteInt32(fd, gamestate.bestweapon);
		WriteInt32(fd, gamestate.weapon);
		WriteInt32(fd, gamestate.chosenweapon);
		WriteInt32(fd, gamestate.faceframe);
		WriteInt32(fd, gamestate.attackframe);
		WriteInt32(fd, gamestate.attackcount);
		WriteInt32(fd, gamestate.weaponframe);
		WriteInt32(fd, gamestate_episode);
		WriteInt32(fd, gamestate.secretcount);
		WriteInt32(fd, gamestate.treasurecount);
		WriteInt32(fd, gamestate.killcount);
		WriteInt32(fd, gamestate.secrettotal);
		WriteInt32(fd, gamestate.treasuretotal);
		WriteInt32(fd, gamestate.killtotal);
		WriteInt32(fd, gamestate.TimeCount);
		WriteInt32(fd, gamestate.killx);
		WriteInt32(fd, gamestate.killy);
		WriteInt8(fd, gamestate.victoryflag);
	
		DiskFlopAnim(dx, dy);
	
#ifdef SPEAR
		for (i = 0; i < 20; i++) {
#else
		for (i = 0; i < 8; i++) {
#endif
			WriteInt32(fd, LevelRatios[i].kill);
			WriteInt32(fd, LevelRatios[i].secret);
			WriteInt32(fd, LevelRatios[i].treasure);
			WriteInt32(fd, LevelRatios[i].time);
		}
	
		DiskFlopAnim(dx, dy);
	
		WriteBytes(fd, (byte *)tilemap, 64*64); /* MAPSIZE * MAPSIZE */
	
		DiskFlopAnim(dx, dy);
	
		for (x = 0; x < 64; x++)
			for (y = 0; y < 64; y++)
				WriteInt32(fd, actorat[x][y]);
	
		DiskFlopAnim(dx, dy);
			
		WriteBytes(fd, (byte *)&areabyplayer, 8);
	
		for (ob = player; ob; ob = obj_next(ob)) {
			DiskFlopAnim(dx, dy);
			
			WriteInt32(fd, obj_id(ob));
			WriteInt32(fd, ob->active);
			WriteInt32(fd, ob->ticcount);
			WriteInt32(fd, ob->obclass);
			WriteInt32(fd, ob->state);
			WriteInt8(fd,  ob->flags);
			WriteInt32(fd, ob->distance);
			WriteInt32(fd, ob->dir);
			WriteInt32(fd, ob->x);
			WriteInt32(fd, ob->y);
			WriteInt32(fd, ob->tilex);
			WriteInt32(fd, ob->tiley);
			WriteInt8(fd,  ob->areanumber);
			WriteInt32(fd, ob->viewx);
			WriteInt32(fd, ob->viewheight);
			WriteInt32(fd, ob->transx);
			WriteInt32(fd, ob->transy);
			WriteInt32(fd, ob->angle);
			WriteInt32(fd, ob->hitpoints);
			WriteInt32(fd, ob->speed);
			WriteInt32(fd, ob->temp1);
			WriteInt32(fd, ob->temp2);
			//WriteInt32(fd, ob->temp3);
		}	
		
		WriteInt32(fd, 0xFFFFFFFF); /* end of actor list */
		
		DiskFlopAnim(dx, dy);
		
		WriteInt32(fd, laststatobj - statobjlist); /* ptr offset */

		for (i = 0; i < 400; i++) { /* MAXSTATS */
			WriteInt8(fd,  statobjlist[i].tilex);
			WriteInt8(fd,  statobjlist[i].tiley);
			WriteInt32(fd, statobjlist[i].shapenum);
			WriteInt8(fd,  statobjlist[i].is_bonus);
			WriteInt8(fd,  statobjlist[i].itemnumber);
		}
	
		DiskFlopAnim(dx, dy);
	
		for (i = 0; i < 64; i++) { /* MAXDOORS */
			WriteInt32(fd, doorposition[i]);
		}
	
		DiskFlopAnim(dx, dy);
	
		for (i = 0; i < 64; i++) { /* MAXDOORS */
			WriteInt8(fd,  doorobjlist[i].tilex);
			WriteInt8(fd,  doorobjlist[i].tiley);
			WriteInt8(fd,  doorobjlist[i].vertical);
			WriteInt8(fd,  doorobjlist[i].lock);
			WriteInt8(fd,  doorobjlist[i].action);
			WriteInt32(fd, doorobjlist[i].ticcount);
		}
	
		DiskFlopAnim(dx, dy);
	
		WriteInt32(fd, pwallstate);
		WriteInt32(fd, pwallx);
		WriteInt32(fd, pwally);
		WriteInt32(fd, pwalldir);
		WriteInt32(fd, pwallpos);

		DiskFlopAnim(dx, dy);

		CloseWrite(fd);

		fd = OpenRead(fn);
		ReadSeek(fd, 64, SEEK_SET);
		cs = CalcFileChecksum(fd, ReadLength(fd) - 64);
		CloseRead(fd);
		
		fd = OpenWriteAppend(fn);
		WriteSeek(fd, 28, SEEK_SET);
		WriteInt32(fd, cs);
		
		CloseWrite(fd);
	} else {
示例#28
0
/**********************************************************************
 * AVIInit
 **********************************************************************
 * Allocates things, create file, initialize and write headers
 *********************************************************************/
static int AVIInit( hb_mux_object_t * m )
{
    hb_job_t   * job   = m->job;
    hb_title_t * title = job->title;

    hb_audio_t    * audio;
    hb_mux_data_t * mux_data;

    int audio_count = hb_list_count( title->list_audio );
    int is_passthru = 0;
    int is_ac3      = 0;
    int hdrl_bytes;
    int i;

    /* Allocate index */
    m->index       = hb_buffer_init( 1024 * 1024 );
    m->index->size = 0;

    /* Open destination file */
    hb_log( "muxavi: opening %s", job->file );
    m->file = fopen( job->file, "wb" );

#define m m->main_header
    /* AVI main header */
    m.FourCC           = FOURCC( "avih" );
    m.BytesCount       = sizeof( hb_avi_main_header_t ) - 8;
    m.MicroSecPerFrame = (uint64_t) 1000000 * job->vrate_base / job->vrate;
    m.Streams          = 1 + audio_count;
    m.Width            = job->width;
    m.Height           = job->height;
#undef m

    /* Video track */
    mux_data = calloc( sizeof( hb_mux_data_t ), 1 );
    job->mux_data = mux_data;

#define h mux_data->header
    /* Video stream header */
    h.FourCC     = FOURCC( "strh" );
    h.BytesCount = sizeof( hb_avi_stream_header_t ) - 8;
    h.Type       = FOURCC( "vids" );

    if( job->vcodec == HB_VCODEC_FFMPEG )
        h.Handler = FOURCC( "divx" );
    else if( job->vcodec == HB_VCODEC_X264 )
        h.Handler = FOURCC( "h264" );

    h.Scale      = job->vrate_base;
    h.Rate       = job->vrate;
#undef h

#define f mux_data->format.v
    /* Video stream format */
    f.FourCC      = FOURCC( "strf" );
    f.BytesCount  = sizeof( hb_bitmap_info_t ) - 8;
    f.Size        = f.BytesCount;
    f.Width       = job->width;
    f.Height      = job->height;
    f.Planes      = 1;
    f.BitCount    = 24;
    if( job->vcodec == HB_VCODEC_FFMPEG )
        f.Compression = FOURCC( "DX50" );
    else if( job->vcodec == HB_VCODEC_X264 )
        f.Compression = FOURCC( "H264" );
#undef f

#define g mux_data->vprp_header
    /* Vprp video stream header */	
    AVRational sample_aspect_ratio = ( AVRational ){ job->anamorphic.par_width, job->anamorphic.par_height };
    AVRational dar = av_mul_q( sample_aspect_ratio, ( AVRational ){ job->width, job->height } );
    int num, den;
    av_reduce(&num, &den, dar.num, dar.den, 0xFFFF);

    g.FourCC                = FOURCC( "vprp" );
    g.BytesCount            = sizeof( hb_avi_vprp_info_t ) - 8;
    g.VideoFormatToken      = 0;
    g.VideoStandard         = 0;
    g.dwVerticalRefreshRate = job->vrate / job->vrate_base;
    g.dwHTotalInT           = job->width;
    g.dwVTotalInLines       = job->height;
    g.dwFrameAspectRatioDen = den;
    g.dwFrameAspectRatioNum = num;
    g.dwFrameWidthInPixels  = job->width;
    g.dwFrameHeightInLines  = job->height;
    g.nbFieldPerFrame       = 1;
    g.CompressedBMHeight    = job->height;
    g.CompressedBMWidth     = job->width;
    g.ValidBMHeight         = job->height;
    g.ValidBMWidth          = job->width;
    g.ValidBMXOffset        = 0;
    g.ValidBMYOffset        = 0;
    g.VideoXOffsetInT       = 0;
    g.VideoYValidStartLine  = 0;
#undef g

    /* Audio tracks */
    for( i = 0; i < hb_list_count( title->list_audio ); i++ )
    {
        audio = hb_list_item( title->list_audio, i );

        is_ac3 = (audio->config.out.codec == HB_ACODEC_AC3);
        is_passthru = (audio->config.out.codec == HB_ACODEC_AC3) ||
                      (audio->config.out.codec == HB_ACODEC_DCA);

        mux_data = calloc( sizeof( hb_mux_data_t ), 1 );
        audio->priv.mux_data = mux_data;

#define h mux_data->header
#define f mux_data->format.a.f
#define m mux_data->format.a.m
        /* Audio stream header */
        h.FourCC        = FOURCC( "strh" );
        h.BytesCount    = sizeof( hb_avi_stream_header_t ) - 8;
        h.Type          = FOURCC( "auds" );
        h.InitialFrames = 1;
        h.Scale         = 1;
        h.Rate          = is_passthru ? ( audio->config.in.bitrate / 8 ) :
                                   ( audio->config.out.bitrate * 1000 / 8 );
        h.Quality       = 0xFFFFFFFF;
        h.SampleSize    = 1;

        /* Audio stream format */
        f.FourCC         = FOURCC( "strf" );
        if( is_passthru )
        {
            f.BytesCount     = sizeof( hb_wave_formatex_t ) - 8;
            f.FormatTag      = is_ac3 ? 0x2000 : 0x2001;
            f.Channels       = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(audio->config.in.channel_layout);
            f.SamplesPerSec  = audio->config.in.samplerate;
        }
        else
        {
            f.BytesCount     = sizeof( hb_wave_formatex_t ) +
                               sizeof( hb_wave_mp3_t ) - 8;
            f.FormatTag      = 0x55;
            f.Channels       = HB_AMIXDOWN_GET_DISCRETE_CHANNEL_COUNT(audio->config.out.mixdown);
            f.SamplesPerSec  = audio->config.out.samplerate;
        }
        f.AvgBytesPerSec = h.Rate;
        f.BlockAlign     = 1;
        if( is_passthru )
        {
            f.Size       = 0;
        }
        else
        {
            f.Size           = sizeof( hb_wave_mp3_t );
            m.Id             = 1;
            m.Flags          = 2;
            m.BlockSize      = 1152 * f.AvgBytesPerSec / audio->config.out.samplerate;
            m.FramesPerBlock = 1;
            m.CodecDelay     = 1393;
        }
#undef h
#undef f
#undef m
    }

    hdrl_bytes =
        /* Main header */
        4 + sizeof( hb_avi_main_header_t ) +
        /* strh for video + audios */
        ( 1 + audio_count ) * ( 12 + sizeof( hb_avi_stream_header_t ) ) +
        /* video strf */
		sizeof( hb_bitmap_info_t ) +
        /* video vprp */
        ( job->anamorphic.mode ? sizeof( hb_avi_vprp_info_t ) : 0 ) +
        /* audios strf */
        audio_count * ( sizeof( hb_wave_formatex_t ) +
                        ( is_passthru ? 0 : sizeof( hb_wave_mp3_t ) ) );

    /* Here we really start to write into the file */

    /* Main headers */
    WriteInt32( m->file, FOURCC( "RIFF" ) );
    WriteInt32( m->file, 2040 );
    WriteInt32( m->file, FOURCC( "AVI " ) );
    WriteInt32( m->file, FOURCC( "LIST" ) );
    WriteInt32( m->file, hdrl_bytes );
    WriteInt32( m->file, FOURCC( "hdrl" ) );
    WriteMainHeader( m->file, &m->main_header );

    /* Video track */
    mux_data          = job->mux_data;
    mux_data->fourcc = FOURCC( "00dc" );

    WriteInt32( m->file, FOURCC( "LIST" ) );
    WriteInt32( m->file, 4 + sizeof( hb_avi_stream_header_t ) +
                sizeof( hb_bitmap_info_t )  +
                ( job->anamorphic.mode ? sizeof( hb_avi_vprp_info_t ) : 0 ) );
    WriteInt32( m->file, FOURCC( "strl" ) );
    WriteStreamHeader( m->file, &mux_data->header );
    WriteBitmapInfo( m->file, &mux_data->format.v );
    if( job->anamorphic.mode )
    {
        WriteVprpInfo( m->file, &mux_data->vprp_header );
    }

    /* Audio tracks */
    for( i = 0; i < audio_count; i++ )
    {
        char fourcc[4] = "00wb";

        audio    = hb_list_item( title->list_audio, i );
        mux_data = audio->priv.mux_data;

        fourcc[1] = '1' + i; /* This is fine as we don't allow more
                                than 8 tracks */
        mux_data->fourcc = FOURCC( fourcc );

        WriteInt32( m->file, FOURCC( "LIST" ) );
        WriteInt32( m->file, 4 + sizeof( hb_avi_stream_header_t ) +
                             sizeof( hb_wave_formatex_t ) +
                             ( is_passthru ? 0 : sizeof( hb_wave_mp3_t ) ) );
        WriteInt32( m->file, FOURCC( "strl" ) );
        WriteStreamHeader( m->file, &mux_data->header );
        WriteWaveFormatEx( m->file, &mux_data->format.a.f );
        if( !is_passthru )
        {
            WriteWaveMp3( m->file, &mux_data->format.a.m );
        }
    }

    WriteInt32( m->file, FOURCC( "JUNK" ) );
    WriteInt32( m->file, 2020 - hdrl_bytes );
    for( i = 0; i < 2020 - hdrl_bytes; i++ )
    {
        WriteInt8( m->file, 0 );
    }
    WriteInt32( m->file, FOURCC( "LIST" ) );
    WriteInt32( m->file, 4 );
    WriteInt32( m->file, FOURCC( "movi" ) );

    return 0;
}
示例#29
0
int NetManager::ListenThread(void* np) {
	NetManager* net = (NetManager*)np;
	if(listen(net->sListen, SOMAXCONN) == SOCKET_ERROR) {
		closesocket(net->sListen);
		return 0;
	}
	int recvlen, index;
	char* pbuf, *psbuf;
	net->sRemote = accept(net->sListen, 0, 0);
	while(net->sRemote != SOCKET_ERROR) {
		recvlen = recv(net->sRemote, net->recv_buf, 4096, 0);
		if(recvlen == SOCKET_ERROR) {
			closesocket(net->sRemote);
			net->sRemote = accept(net->sListen, 0, 0);
			continue;
		}
		//check deck
		pbuf = net->recv_buf;
		int ver = ReadInt16(pbuf);
		if(ver != PROTO_VERSION) {
			psbuf = net->send_buf;
			WriteInt8(psbuf, 0x1);
			WriteInt16(psbuf, PROTO_VERSION);
			send(net->sRemote, net->send_buf, 3, 0);
			closesocket(net->sRemote);
			net->sRemote = accept(net->sListen, 0, 0);
			continue;
		}
		wchar_t cn = ReadInt16(pbuf);
		int off = 0;
		while(cn != 0 && off < 19) {
			mainGame->dInfo.pass[off++] = cn;
			cn = ReadInt16(pbuf);
		}
		mainGame->dInfo.pass[off] = 0;
		if(wcscmp(mainGame->dInfo.pass, mainGame->ebServerPass->getText())) {
			psbuf = net->send_buf;
			WriteInt8(psbuf, 0x3);
			send(net->sRemote, net->send_buf, 1, 0);
			closesocket(net->sRemote);
			net->sRemote = accept(net->sListen, 0, 0);
			continue;
		}
		cn = ReadInt16(pbuf);
		off = 0;
		while(cn != 0 && off < 19) {
			mainGame->dInfo.clientname[off++] = cn;
			cn = ReadInt16(pbuf);
		}
		mainGame->dInfo.clientname[off] = 0;
		int maincount = ReadInt16(pbuf);
		int sidecount = ReadInt16(pbuf);
		mainGame->deckManager.LoadDeck(mainGame->deckManager.deckclient, (int*)pbuf, maincount, sidecount);
		if(!net->hInfo.no_check_deck && !mainGame->deckManager.CheckLFList(mainGame->deckManager.deckclient, net->hInfo.lfindex)) {
			psbuf = net->send_buf;
			WriteInt8(psbuf, 0x2);
			send(net->sRemote, net->send_buf, 1, 0);
			closesocket(net->sRemote);
			net->sRemote = accept(net->sListen, 0, 0);
			continue;
		}
		psbuf = net->send_buf;
		WriteInt8(psbuf, 0);
		const wchar_t* ln = mainGame->ebUsername->getText();
		int li = 0;
		while(ln[li] && li < 19) {
			mainGame->dInfo.hostname[li] = ln[li];
			WriteInt16(psbuf, ln[li++]);
		}
		mainGame->dInfo.hostname[li] = 0;
		WriteInt16(psbuf, 0);
		send(net->sRemote, net->send_buf, 3 + li * 2, 0);
		mainGame->gMutex.Lock();
		mainGame->imgCard->setImage(mainGame->imageManager.tCover);
		mainGame->wCardImg->setVisible(true);
		mainGame->wInfos->setVisible(true);
		mainGame->stName->setText(L"");
		mainGame->stInfo->setText(L"");
		mainGame->stDataInfo->setText(L"");
		mainGame->stText->setText(L"");
		mainGame->stModeStatus->setText(L"");
		mainGame->dInfo.engLen = 0;
		mainGame->dInfo.msgLen = 0;
		mainGame->dField.Clear();
		mainGame->HideElement(mainGame->wModeSelection);
		mainGame->gMutex.Unlock();
		mainGame->WaitFrameSignal(10);
		closesocket(net->sBHost);
		net->is_creating_host = false;
		Thread::NewThread(Game::EngineThread, &mainGame->dInfo);
		Thread::NewThread(Game::GameThread, &mainGame->dInfo);
		break;
	}
	return 0;
}