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

📄 rtffplin.cpp

📁 linux下的一款播放器
💻 CPP
📖 第 1 页 / 共 5 页
字号:
				lHighestLessThanCharIndex = (LONG32)indx;				bIsInsideTag = TRUE;				// just before a <BR> or <P> tag is a great				// place to end a packet:				if(indx+2<ulBufSize)				{				    if(('P'==szLoppedPkt[indx+1]  ||					    'p'==szLoppedPkt[indx+1])  &&					    ('>'==szLoppedPkt[indx+2]) )				    {					//keep track of					// the first one of the last group					// of one or more BR|P tags so that					// a packet never ends w/BR or P:					if(lHighestBRorPtagStartIndx<0  ||					    indx -					    lMostRecentBRorPTagStartIndx>4)					{					    lHighestBRorPtagStartIndx=indx;					}					lMostRecentBRorPTagStartIndx=indx;				    }				}				if(indx+3<ulBufSize)				{				    if(('B'==szLoppedPkt[indx+1]  ||					    'b'==szLoppedPkt[indx+1])  &&					    ('R'==szLoppedPkt[indx+2]  ||					    'r'==szLoppedPkt[indx+2])  &&					    ('>'==szLoppedPkt[indx+3]  ||					    //can be "<br>" or "<br/>":					    (indx+4<ulBufSize  &&					    '/'==szLoppedPkt[indx+3]  &&					    '>'==szLoppedPkt[indx+4]) )					    )				    {					//keep track of					// the first one of the last group					// of one or more BR|P tags so that					// a packet never ends w/BR or P:					if(lHighestBRorPtagStartIndx<0  ||					    indx - 					    lMostRecentBRorPTagStartIndx>5)					{					    lHighestBRorPtagStartIndx=indx;					}					lMostRecentBRorPTagStartIndx=indx;				    }				}				continue;			    }			    else if(('\n' == ch  ||  '\r' == ch  ||				    ' '==ch  ||  '\t'==ch)  &&  !bIsInsideTag)			    {				lHighestSpaceTabNewlineCharOutsideTagIndex =					(LONG32)indx;				continue;			    }			    //else is regular single-byte char, so continue.			}			BOOL bMinPktSzProb = FALSE;			if(bIsInsideTag) //data ends inside a tag "<..>":			{			    if(MIN_PACKET_SIZE > lHighestLessThanCharIndex)			    {				///XXXEH- unfinished code: don't send less than				/// MIN_PACKET_SIZE, and, if you have to, 				/// send flag saying the packet is ending				/// inside a tag:				m_ulCurPacketSize = ulBufSize;//send it all.				bMinPktSzProb = TRUE;			    }			}			if(!bMinPktSzProb) //(was "else")			{			    // just before a <BR> or <P> tag is a great place			    // to end a packet:			    if((lHighestBRorPtagStartIndx>MIN_PACKET_SIZE) &&				    (lHighestBRorPtagStartIndx				    +10   //go w/earlier BR				    > 				 lHighestSpaceTabNewlineCharOutsideTagIndex))			    {				//goes to just BEFORE the <BR>:				m_ulCurPacketSize = 					lHighestBRorPtagStartIndx;			    }			    else if(					lHighestSpaceTabNewlineCharOutsideTagIndex >=				    MIN_PACKET_SIZE)			    {				m_ulCurPacketSize = 1 +  //add 1 to include it				  lHighestSpaceTabNewlineCharOutsideTagIndex;			    }			    else if(				    lHighestLessThanCharIndex >=				    MIN_PACKET_SIZE  &&				    lHighestLessThanCharIndex >=				    lHighestGreaterThanCharIndex				    )			    {				m_ulCurPacketSize =//(don't +1 to include it)					lHighestLessThanCharIndex;			    }			    else if(					    lHighestGreaterThanCharIndex >=				    MIN_PACKET_SIZE)			    {				m_ulCurPacketSize = 1 + //add 1 to include it					lHighestGreaterThanCharIndex;			    }			    else //no way to split text except inside word			    {				m_ulCurPacketSize = ulBufSize;//send it all. 				if (bEndsOnALeadByteOfDualByteChar  &&					// /Fixes PR 72843: if a high-128-					// valued byte ends the file, then					// we're done (so don't keep re-reading					// the last character of the file!!):					m_ulNextPacketSeekPoint + ulBufSize <					m_ulTotalFileSizeInBytes)				{   //back up to just before the lead byte:				    m_ulCurPacketSize = ulBufSize-1;				}			    }			}			szLoppedPkt[m_ulCurPacketSize] = '\0';			ULONG32 ulCurPktStartByteInFile =				m_ulNextPacketSeekPoint;			//Next read should be done where the first un-parsed			// data is in the file:			m_ulNextPacketSeekPoint += m_ulCurPacketSize;			//>>//Parse the data to determine			// start and end times of data in packet:			// (NOTE: don't need to add one for the NULL-			// terminating char because ParseText does not expect			// a NULL-terminated string)			ULONG32 ulStartTimeOfPacket = m_ulCurrentTime;			ULONG32 ulEndTimeOfPacket = m_ulCurrentTime;			// /Helps fix PR 82567:			// If this is plain text, we don't want to send			// anything but time-0 packets since the SMIL2 renderer			// will reset our dur to 1 millisec and that will cause			// any packets after that time to be treated as past			// the end of the stream:			if (m_bIsTextPlainStreamMimeType)			{			    ulStartTimeOfPacket = ulEndTimeOfPacket = 0;			}			m_bCurPacketHasREQUIREDContents=FALSE;			//Note: ParseText messes with the text (by placing			// '\0's in it) so we need to restore the szLoppedPkt			// buffer after:			//XXXEH- fix ParseText so it doesn't alter the buffer			//ParseText returns the earliest start time of all			// data it parses into TextLine objects:			HX_RESULT hxrParseTextRetVal = ParseText(szLoppedPkt,				m_ulCurPacketSize,				0,  //XXXEH-this is for renderer only, right?				ulStartTimeOfPacket,				ulEndTimeOfPacket,				//This is passed by ref and, if ANY of the				// text in the szLoppedPkt is between a				// <REQUIRED> and a </REQUIRED> tag, then				// this value gets set to TRUE, else FALSE:				m_bCurPacketHasREQUIREDContents,				TRUE,//TRUE==is called from file format.				//This tells ParseText				// where we are in the file so each TextLine				// can keep track of its seek point:				ulCurPktStartByteInFile,				&m_pCurTextLine				);			// /Helps fix PR 82567: if this is played in a SMIL 2.0			// file then plain text packets were getting dropped in			// larger files if current time was greater than 1ms			// since duration was being reset by SMIL to 1 millisec:			if (m_bIsTextPlainStreamMimeType)			{			    ulStartTimeOfPacket =  ulEndTimeOfPacket = 0;			}			else if (HXR_OK != hxrParseTextRetVal)			{   //XXXEH- should this situation be better handled?			    ulStartTimeOfPacket = m_ulCurrentTime;			    ulEndTimeOfPacket = m_ulCurrentTime;			}			else if(ulStartTimeOfPacket > GetDuration())			{#ifdef _DEBUG#if defined(RT_OUTPUT_LOGFILE)			    if(m_logfile  &&				    m_txtWin.getDebugFlags()&				    RT_FF_DEBUG_FLAGS_MASK)			    {				fprintf(m_logfile,"StreamDone() #2.\n");				fflush(m_logfile);			    }#endif#endif			    m_pFFResponse->StreamDone(0);			    return result;			}			memcpy(szLoppedPkt, /* Flawfinder: ignore */				(char*)(pBuffer->GetBuffer()),				m_ulCurPacketSize);			szLoppedPkt[m_ulCurPacketSize] = '\0';			ULONG32 ulNumTCsDeleted = 				m_pTextWindow->deleteAllTCsUpToLastLine();			ULONG32 ulNumBytesParsedGoingInThisPkt =				m_ulCurPacketSize;			ULONG32 ulNumBytesParsedNotGoingInThisPkt = 0L;#if defined(SAVE_PARTIAL_TEXTLINE_AT_END_OF_READ_DATA)			//Let's not send the final TL parsed because it			// may not be a complete line yet, so it'll have			// to wait until more data is parsed in the next			// GetPacket()-->...-->ReadDone() call:			TextLine* pTL_finalTLParsed = 				m_pTextWindow->m_pTLList->end();			ULONG32 ulStartByteOfLastTL =ulCurPktStartByteInFile;			if(pTL_finalTLParsed)			{			    if(m_pCurTextLine)			    {				//XXXEHFOO - test code if this "if" fails!!:				if(m_pCurTextLine->getStartByteInFile() <				    pTL_finalTLParsed->getStartByteInFile())				{				    //Only set this (to skip last TL) if it's				    // not the only TL in the packet:				    ulStartByteOfLastTL = pTL_finalTLParsed->					    getStartByteInFile();				    ulNumBytesParsedGoingInThisPkt =					    ulStartByteOfLastTL -					    ulCurPktStartByteInFile;				    ulNumBytesParsedNotGoingInThisPkt					    m_ulCurPacketSize -					    ulNumBytesParsedGoingInThisPkt;				    if(!m_pSavedDataFromLastRead)				    {					pCommonClassFactory->CreateInstance(						CLSID_IHXBuffer,						(void**)						&m_pSavedDataFromLastRead);				    }				    m_pSavedDataFromLastRead->Set(					    (const UCHAR*)					    (szLoppedPkt+					    ulNumBytesParsedGoingInThisPkt),					    //add 1 for NULL char:					    ulNumBytesParsedNotGoingInThisPkt					    +1);				}			    }			}			if(ulStartByteOfLastTL == ulCurPktStartByteInFile)			{			    ulNumBytesParsedGoingInThisPkt=m_ulCurPacketSize;			    ulNumBytesParsedNotGoingInThisPkt = 0L;			    //If we didn't have any "leftovers" (i.e., no			    // partial TextLine at the end) then clear the			    // IHXBuffer so we don't use any old data:			    if(m_pSavedDataFromLastRead)			    {				m_pSavedDataFromLastRead->Release();				m_pSavedDataFromLastRead = NULL;			    }			}#endif			char pPacketHeaderBuf[MAX_PKT_HDR_SZ+1]; /* Flawfinder: ignore */			pPacketHeaderBuf[0] = '\0';			//This is the byte index relative to the cur buffer:			ULONG32 ulLocationInPktOfStartByteOfTextLine = 0L;			ULONG32 ulNumPktHdrBytes = 0L;			if (m_pCurTextLine  &&				// /No packet header if this is plain text:				!m_bIsTextPlainStreamMimeType)			{			    ulNumPktHdrBytes = 				    m_pCurTextLine->OutputPacketHeaderString(				    //XXXEH- 0 is invalid data ID. OK as long				    // as live is only user of this value:				    0L,				    &m_txtWin,				    //state != GetPacketSeekBackReadPending:				    FALSE,				    //XXXEH-this must be pre-allocated but it				    //would make more sense to use IRMBuffer:				    pPacketHeaderBuf, MAX_PKT_HDR_SZ,				    m_txtWin.m_pFontUndoTagList,				    m_ulCurPacketSize				    );			    ulLocationInPktOfStartByteOfTextLine =				    m_pCurTextLine->getStartByteInFile() -				    ulCurPktStartByteInFile;			    m_pCurTextLine = NULL;			}			//Now, adjust num bytes because we're not going to			// send all the markup tags that come just before the			// start of the first TextLine:			ulNumBytesParsedGoingInThisPkt -= 				ulLocationInPktOfStartByteOfTextLine;#if defined(SAVE_PARTIAL_TEXTLINE_AT_END_OF_READ_DATA)			ULONG32 ulLenOfSavedDataFromLastRead = 0L;			if(m_pSavedDataFromLastRead)			{			    ulLenOfSavedDataFromLastRead = 				    m_pSavedDataFromLastRead->GetSize();			}#endif			m_ulCurPacketSize =#if defined(SAVE_PARTIAL_TEXTLINE_AT_END_OF_READ_DATA)				ulLenOfSavedDataFromLastRead +#endif				ulNumPktHdrBytes +				ulNumBytesParsedGoingInThisPkt;			/*XXXEH- replaced this with the above line...			m_ulCurPacketSize += ulNumPktHdrBytes;			m_ulCurPacketSize -=				ulCurPktStartByteInFile-ulStartByteOfLastTL;			*/			ULONG32 ulNonHeaderPartSize = m_ulCurPacketSize - 				ulNumPktHdrBytes;						pCommonClassFactory->CreateInstance(CLSID_IHXBuffer,				(void**)&pLoppedPkt);			pLoppedPkt->SetSize(				//add 1 for NULL char:				m_ulCurPacketSize+1);			char* pTmpBuf =				(char*)(pLoppedPkt->GetBuffer());			pTmpBuf[0] = '\0';			//Skip all the markup tags in the packet that			// come before the first raw text, and insert in			// their place the pPacketHeaderBuf:#if defined(SAVE_PARTIAL_TEXTLINE_AT_END_OF_READ_DATA)			HX_ASSERT(ulLenOfSavedDataFromLastRead>0?				m_pSavedDataFromLastRead!=NULL);			HX_ASSERT(strlen(pPacketHeaderBuf) ==				ulNumPktHdrBytes);			if(ulLenOfSavedDataFromLastRead)			{			    memcpy(pTmpBuf,  /* Flawfinder: ignore */				    m_pSavedDataFromLastRead->GetBuffer(),				    ulLenOfSavedDataFromLastRead);			}			memcpy((pTmpBuf + ulLenOfSavedDataFromLastRead),  /* Flawfinder: ignore */				pPacketHeaderBuf,				ulNumPktHdrBytes);			memcpy((pTmpBuf + ulLenOfSavedDataFromLastRead + /* Flawfinder: ignore */				ulNumPktHdrBytes), 				(szLoppedPkt +				ulLocationInPktOfStartByteOfTextLine),				ulNonHeaderPartSize);#else			strcpy(pTmpBuf, pPacketHeaderBuf); /* Flawfinder: ignore */			memcpy((pTmpBuf+ulNumPktHdrBytes),  /* Flawfinder: ignore */				(szLoppedPkt+				ulLocationInPktOfStartByteOfTextLine),				ulNonHeaderPartSize);#endif			//Now, make sure packet data is NULL-terminated:			pTmpBuf[m_ulCurPacketSize] = '\0';			//Added this so seeks backwards			// don't reparse the data; subtract 1 because this is			// the last byte of what's been read, not the next			// byte to be read:			m_ulLastByteParsedInFile =m_ulNextPacketSeekPoint-1L;			ULONG32 ulSendTimeOfCurPacket = ulStartTimeOfPacket;			// /Helps fix PR 78150: if a really rediculously-huge			// .txt file is being handled, cut it off at some a			// lower rediculously-huge number of characters:			if (m_bIsTextPlainStreamMimeType  &&				m_ulLastByteParsedInFile >				MAX_ALLOWED_PLAINTEXT_CHARS_TO_SEND)			{			    HX_ASSERT(m_ulLastByteParsedInFile <=				    MAX_ALLOWED_PLAINTEXT_CHARS_TO_SEND);			    // Tell the FormatResponse that we've sent more			    // than enough of this file already:			    m_pFFResponse->StreamDone(0);			    goto doneWithPacket;			}			//Send this with the start time of the text of the			// prior packet in case it starts with centered text			// because the prior packet's last line won't get			// centered until the renderer knows it has received			// the entire line:			if(m_ulStartTimeOfTextOfPriorPacket <				ulSendTimeOfCurPacket)			{			    ulSendTimeOfCurPacket =				    m_ulStartTimeOfTextOfPriorPacket;			}			m_ulStartTimeOfTextOfPriorPacket =				ulStartTimeOfPacket;			// Fill in the Packet with the relevant data...			pPacket->Set(pLoppedPkt,				ulSendTimeOfCurPacket,				0,				HX_ASM_SWITCH_ON,				//RuleBook#1 (priority=10) for all packets				// that contain any text marked <REQUIRED>;				// RuleBook#0 (pri

⌨️ 快捷键说明

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