⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 script.cpp

📁 一个GNU的开源软件,基于linux下X-Window的flash播放器,工作稳定,方便移植和修改
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	}	if (outOfMemory) {		delete text;		return;	}	if (m_filePos >= m_tagEnd) break;    } while (textRecord);    addCharacter(text);}void CInputScript::ParseDefineSound(){    Sound		*sound;    U32 tagid = (U32) GetWord();    long		 nbSamples,skipSize;    long		 flags;    char		*buffer;    sound = new Sound(tagid);    flags = GetByte();    sound->setSoundFlags(flags);    switch (sound->getFormat()) {    	// Raw    	case 0:	case 3:		nbSamples = GetDWord();		buffer = sound->setNbSamples(nbSamples);		if (buffer == NULL) {			outOfMemory = 1;			delete sound;			return;		}		memcpy(buffer, &m_fileBuf[m_filePos], m_tagLen-5);		break;	// ADPCM	case 1:		nbSamples = GetDWord();		buffer = sound->setNbSamples(nbSamples);		if (buffer == NULL) {			outOfMemory = 1;			delete sound;			return;		}		Adpcm		*adpcm;		adpcm = new Adpcm( &m_fileBuf[m_filePos] , flags & soundIsStereo );		adpcm->Decompress((short *)buffer, nbSamples);		delete adpcm;		break;	// MP3	case 2:		nbSamples = GetDWord();		buffer = sound->setBuffer(m_tagLen-4);		if (buffer == NULL) {			outOfMemory = 1;			delete sound;			return;		}		skipSize = GetWord();		fprintf(stderr, "New block\n");		sound->setSoundSize(m_tagLen-4);		memcpy(buffer, &m_fileBuf[m_filePos], m_tagLen-4);		break;		// Nellymoser ASAO	case 6:		fprintf(stderr, "Unsupported sound compression: Nellymoser\n");		break;    }    addCharacter(sound);}void CInputScript::ParseDefineButtonSound(){    U32 tagid = (U32) GetWord();    Button	*button;    tagid = tagid;    printf("tagDefineButtonSound \ttagid %-5u\n", tagid);    button = (Button *)getCharacter(tagid);    if (button == 0) {	printf("	Couldn't find Button id %d\n", tagid);	return;    }    // step through for button states    for (int i = 0; i < 4; i++)    {	Sound	*sound;	U32 soundTag = GetWord();	sound = (Sound *)getCharacter(soundTag);	if (sound) {	    button->setButtonSound(sound,i);	} else if (soundTag) {	    printf("	Couldn't find Sound id %d\n", soundTag);	}	switch (i)	{	case 0:         	    printf("upState \ttagid %-5u\n", soundTag);	    break;	case 1:            	    printf("overState \ttagid %-5u\n", soundTag);	    break;	case 2:            	    printf("downState \ttagid %-5u\n", soundTag);	    break;	}	if (soundTag)	{	    U32 code = GetByte();	    printf("sound code %u", code);	    if ( code & soundHasInPoint )		printf(" inpoint %u", GetDWord());	    if ( code & soundHasOutPoint )		printf(" outpoint %u", GetDWord());	    if ( code & soundHasLoops )		printf(" loops %u", GetWord());	    printf("\n");	    if ( code & soundHasEnvelope ) 	    {		int points = GetByte();		for ( int p = 0; p < points; p++ ) 		{		    printf("\n");		    printf("mark44 %u", GetDWord());		    printf(" left chanel %u", GetWord());		    printf(" right chanel %u", GetWord());		    printf("\n");		}	    }	}	if (m_filePos == m_tagEnd) break;    }}void CInputScript::ParseSoundStreamHead(){    int tmp = GetByte();    tmp = GetByte();    if (tmp != 0) {    	streamFlags = tmp;	streamNew = 1;	streamID++;	fprintf(stderr, "new stream 1, id: %d\n", streamID);    }}void CInputScript::ParseSoundStreamHead2(){    int tmp = GetByte();    tmp = GetByte();    if (tmp != 0) {    	streamFlags = tmp;	streamNew = 1;	streamID++;	fprintf(stderr, "new stream 2, id: %d\n", streamID);    }}void CInputScript::ParseSoundStreamBlock(){    Sound		*sound;    long		 skipSize, oldsize, this_frame, next_frame;    char		*buffer;        if (m_tagLen < 5) return;        skipSize = GetWord();    skipSize = GetWord();        if (streamNew) {    	fprintf(stderr, "samples: %d\n", skipSize); 	sound = new Sound(streamID);	sound->setSoundFlags(streamFlags);	buffer = sound->setBuffer(m_tagLen-4);	if (buffer == NULL) {	  	outOfMemory = 1;		delete sound;		return;	}	sound->setSoundSize(m_tagLen-4);    	memcpy(buffer, &m_fileBuf[m_filePos], m_tagLen-4);	addCharacter(sound);	Control *ctrl;	streamNew=0;	ctrl = new Control;    	if (ctrl == NULL) {		outOfMemory = 1;    		return;    	}    	ctrl->character = getCharacter(streamID);    	ctrl->type = ctrlStartSound;    	program->addControlInCurrentFrame(ctrl);    } else {    	sound = (Sound*) getCharacter(streamID);	oldsize = sound->getSoundSize();	buffer = sound->resetBuffer(m_tagLen-4);    	memcpy(buffer+oldsize, &m_fileBuf[m_filePos], m_tagLen-4);	// If playback already has started, we must update 	// the SoundList as well...	if (sound->getPlaybackStarted()) {		SoundList* sl = sound->getSound();		this_frame =  (char*) sl->mp3Stream.this_frame - sl->originalMp3;		next_frame =  (char*) sl->mp3Stream.next_frame - sl->originalMp3;				sl->currentMp3 = sound->getSamples();		sl->originalMp3 = sl->currentMp3;		sl->remainingMp3 += m_tagLen-4;		mad_stream_buffer (&sl->mp3Stream, (unsigned char*)sl->currentMp3, sl->remainingMp3);		sl->mp3Stream.this_frame = sl->mp3Stream.this_frame + this_frame;		sl->mp3Stream.next_frame = sl->mp3Stream.next_frame + next_frame;			}    }}void CInputScript::ParseDefineButtonCxform(){    ButtonRecord *br;    Button	*button;    U32 tagid = (U32) GetWord();    button = (Button *)getCharacter(tagid);    for (br = button->getButtonRecords(); br; br = br->next)    {	br->cxform = new Cxform;	GetCxform(br->cxform, false);    }}void CInputScript::ParseNameCharacter(){    U32 tagid = (U32) GetWord();    char *label = strdup(GetString());    nameCharacter(tagid, label);}void CInputScript::ParseFrameLabel(){    char *label = strdup(GetString());    program->setCurrentFrameLabel(label);}void CInputScript::ParseDefineMouseTarget(){    printf("tagDefineMouseTarget\n");}void CInputScript::ParseDefineSprite(){    Sprite  *sprite;    Program *prg;    int status;    U32 tagid = (U32) GetWord();    U32 frameCount = (U32) GetWord();    if (frameCount == 0) return;    printf("tagDefineSprite \ttagid %-5u \tframe count %-5u\n", tagid, frameCount);    sprite = new Sprite(program->movie, tagid, frameCount);    if (sprite == NULL) {    	outOfMemory = 1;	return;    }    if (sprite->getProgram() == NULL) {    	delete sprite;    	outOfMemory = 1;	return;    }    prg = sprite->getProgram();    // Set current program    program = prg;    ParseTags(&status);    if (outOfMemory) {    	delete sprite;	return;    }    addCharacter(sprite);}void CInputScript::ParseUnknown(long code, long len){    printf("Unknown Tag : %d  - Length = %d\n", code, len);}voidCInputScript::ParseTags(int *status)	// Parses the tags within the file.{    // Initialize the end of frame flag.    BOOL atEnd = false;    // Loop through each tag.    while (!atEnd)    {	U32 here;	// Get the current tag.	U16 code = GetTag();	if (code == notEnoughData) {		m_filePos = m_tagStart;		*status |= FLASH_PARSE_NEED_DATA;		return;	}	//printf("Code %d, tagLen %8u \n", code, m_tagLen);	here = m_filePos;	// Get the tag ending position.	U32 tagEnd = m_tagEnd;	if (m_tagEnd > m_actualSize) {		m_filePos = m_tagStart;		*status |= FLASH_PARSE_NEED_DATA;	    	return;	}	switch (code)	{	case stagProtect:	    break;	case stagEnd:	    // We reached the end of the file.	    atEnd = true;	    printf("End of Movie\n");	    break;	case stagShowFrame:	    // Validate frame	    program->validateLoadingFrame();	    *status |= FLASH_PARSE_WAKEUP;	    break;	case stagFreeCharacter:	    ParseFreeCharacter();	    break;	case stagPlaceObject:	    ParsePlaceObject();	    break;	case stagPlaceObject2:	    ParsePlaceObject2();	    break;	case stagRemoveObject:	    ParseRemoveObject();	    break;	case stagRemoveObject2:	    ParseRemoveObject2();	    break;	case stagSetBackgroundColor:	    ParseSetBackgroundColor();	    break;	case stagDoAction:	    ParseDoAction();	    break;	case stagStartSound:	    ParseStartSound();	    break;	case stagStopSound:	    ParseStopSound();	    break;	case stagDefineShape: 	    ParseDefineShape(1);	    break;	case stagDefineShape2:	    ParseDefineShape(2);	    break;	case stagDefineShape3:	    ParseDefineShape(3);	    break;	case stagDefineBits:	    ParseDefineBits();	    break;	case stagDefineBitsJPEG2:	    ParseDefineBitsJPEG2();	    break;	case stagDefineBitsJPEG3:	    ParseDefineBitsJPEG3();	    break;	case stagDefineBitsLossless:	    ParseDefineBitsLossless(1);	    break;	case stagDefineBitsLossless2:	    ParseDefineBitsLossless(2);	    break;	case stagJPEGTables:	    ParseJPEGTables();	    break;	case stagDefineButton:	    ParseDefineButton();	    break;	case stagDefineButton2:	    ParseDefineButton2();	    break;	case stagDefineFont:	    ParseDefineFont();	    break;	case stagDefineMorphShape:	    ParseDefineMorphShape();	    break;	case stagDefineFontInfo:	    ParseDefineFontInfo();	    break;	case stagDefineText:	    ParseDefineText(0);	    break;	case stagDefineText2:	    ParseDefineText(1);	    break;	case stagDefineSound:	    ParseDefineSound();	    break;	case stagDefineButtonSound:	    ParseDefineButtonSound();	    break;	case stagSoundStreamHead:	    ParseSoundStreamHead();	    break;	case stagSoundStreamHead2:	    ParseSoundStreamHead2();	    break;	case stagSoundStreamBlock:	    ParseSoundStreamBlock();	    break;	case stagDefineButtonCxform:	    ParseDefineButtonCxform();	    break;	case stagDefineSprite:	    Program *save;	    save = program;	    ParseDefineSprite();	    program->rewindMovie();	    program = save;	    break;	case stagNameCharacter:	    ParseNameCharacter();	    break;	case stagFrameLabel:	    ParseFrameLabel();	    break;	case stagDefineFont2:	    ParseDefineFont2();	    break;	default:	    ParseUnknown(code, m_tagLen);	    break;	}	//printf("Bytes read = %d\n", m_filePos-here);	// Increment the past the tag.	m_filePos = tagEnd;	if (outOfMemory) {		fprintf(stderr,"Flash: Out of memory\n");		*status |= FLASH_PARSE_OOM;		return;	}    }    program->validateLoadingFrame();    *status |= FLASH_PARSE_EOM;}intCInputScript::ParseData(FlashMovie *movie, char * data, long size){    static long lLastSize = 0;    int status = FLASH_PARSE_ERROR;    int zstatus;    m_fileBuf = (unsigned char *)data;    m_actualSize = size;    if (needHeader) {	    // Do we have sufficient data to read the header ?	    if (size < 21) {		return FLASH_PARSE_NEED_DATA;	// No, need more data	    }	    U8 fileHdr[8];	    // recognize TRUE pure SWF files	    if( data[1] == 'W' && data[2] == 'S' && 0 == lLastSize )	    {		if(data[0] == 'C' || data[0] == 'F')		{		    needFileID = FALSE;		    memcpy(fileHdr,data,8);		    m_filePos = 8;		}	    }	    if( needFileID )//haven't found swf file,so find it in the data	    {		char * pos = data + lLastSize;		char * end = data + size - 21;//the size of swf file is at least 21 bytes		// try to see if we have an embeded SWF file (exe)		for(  ; pos < end && (pos[0]!='F' || pos[1]!='W' || pos[2]!='S'); pos++ );		if( pos < end )		{		    // if we are here then we've found a flash header		    memcpy(fileHdr, pos, 8);		    m_filePos = 8+(pos-data);		    m_bExe = TRUE; // Add file format field info]		    needFileID = FALSE;		    lLastSize = pos-data; // remember beginning of SWF data in the file		}		else		{		    lLastSize = size; // remember where we were		    return FLASH_PARSE_NEED_DATA;		}	    }	    m_bCompressed = (fileHdr[0] == 'C')?TRUE:FALSE;	    // Get the file version.	    m_fileVersion = (U16) fileHdr[3];        	    // Get the file size.	    m_fileSize = (U32) fileHdr[4]	              | ((U32) fileHdr[5] << 8)		      | ((U32) fileHdr[6] << 16)		      | ((U32) fileHdr[7] << 24);	    // Verify the minimum length of a Flash file.	    if (m_fileSize < 21)	    {		return FLASH_PARSE_ERROR;	// Error	    }	    if( m_bCompressed )	    {		fprintf(stdout, "decoding...\n");		// The file is compressed. Create a buffer to hold the		// uncompressed data.		m_zBuffer = new U8 [m_fileSize];		if(m_zBuffer == NULL)		{    		    return FLASH_PARSE_OOM;		}		// Initialize the ZLib decompressor. We skip the first eight		// bytes, since we've already processed them.		m_zstream.next_out = (Bytef *)&m_zBuffer[8];		m_zstream.avail_out = (uInt)m_fileSize;		m_zstream.next_in = (Bytef *)&data[8];		m_zstream.avail_in = 0;		m_zstream.zalloc = Z_NULL;		m_zstream.zfree = Z_NULL;		m_zstream.opaque = Z_NULL;		zstatus = inflateInit(&m_zstream);		if(zstatus != Z_OK)		{		    return FLASH_PARSE_OOM;		}		m_zInitialized = true;		// We'll be decoding from our own decompressed data buffer.		m_fileBuf = m_zBuffer;		m_lastSize = 8;	    }	    else	    {		// The file is uncompressed, so we'll be decoding it from the		// caller's buffer.		m_fileBuf = (U8 *)data;	    }	}	// If we're reading a compressed file, we need to decompress as much of	// it as we have available into the decompressed data buffer.	if( m_zBuffer )	{	    // Figure out how much new compressed data is available.	    m_zstream.avail_in = (uInt)(size - m_lastSize);	    m_lastSize = size;	    // Decompress it.	    zstatus = inflate(&m_zstream, Z_SYNC_FLUSH);	    if(   (zstatus != Z_OK) && (zstatus != Z_STREAM_END) &&					(zstatus != Z_BUF_ERROR))	    {		// There was an error in decompression.		return FLASH_PARSE_ERROR;	    }	    // Figure out how much decompressed data is available.	    m_actualSize = m_zstream.total_out + 8;	}	else	{	    // The file is uncompressed, so the amount of it available for	    // processing is just what the caller thinks it is.	    // except if we are embeded in another file	    m_actualSize = size;// - lLastSize;	}	if( needHeader )	{	    // Do we have sufficient data to read the header ?	    if( m_actualSize < 21 )	    {		return FLASH_PARSE_NEED_DATA; // No, need more data	    }	    // Get the frame information.	    GetRect(&frameRect);	    frameRate = GetWord() >> 8;	    frameCount = GetWord();	    program = new Program(movie, frameCount);	    if (program == NULL || program->totalFrames == 0)	    {		return FLASH_PARSE_ERROR;	    }	    status |= FLASH_PARSE_START;	    needHeader = FALSE;	}	ParseTags(&status);	// If we've reached the end of a compressed movie, we need to shut down	// the decompressor and dispose of the decompressed data.	if( m_zBuffer && (status & FLASH_PARSE_EOM) )	{	    inflateEnd(&m_zstream);	    m_zInitialized = false;	    delete m_zBuffer;	    m_zBuffer = NULL;	}	return status;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -