int CDictionary::Load(LOADINFO* pInfo) { CAutoLock cObjectLock(this); if (!pInfo) { return E_FAIL; } if (IsLoaded(pInfo->pDictionaryName)) { return S_OK; } CSubDictionary* pSD = new CSubDictionary(pInfo->pDictionaryName); AssertValid(pSD); if (pSD->Load(pInfo) != S_OK) { delete pSD; Log("Can't load %s\n", pInfo->pDictionaryName); return E_FAIL; } m_vecDicts.push_back(pSD); Log("Load %s successful!\n", pInfo->pDictionaryName); return S_OK; }
BOOL CHMLayer::IsInViewBL(float fScale) { AssertValid(); if ((fScale<m_startViewBL)|(fScale>m_endViewBL)) return FALSE; else return TRUE; }
int CAudioRenderer::SetSampleRate(int nSampleRate) { AssertValid(nSampleRate > 0); m_nSampleRate = nSampleRate; return S_OK; }
/////////////////////////////////////////////////////////////////////////////// // RemoveItem /////////////////////////////////////////////////////////////////////////////// void cBlockRecordFile::RemoveItem( cBlockRecordFile::tAddr dataAddr ) //throw (eArchive) { ASSERT( mbOpen ); ASSERT( IsValidAddr( dataAddr ) ); #ifdef _BLOCKFILE_DEBUG AssertValid(); #endif mvBlocks[ dataAddr.mBlockNum ].DeleteItem( dataAddr.mIndex ); // // remove unneeded blocks at the end... // //TODO -- not implemented yet! /* while( mvBlocks.back().GetNumItems() == 0 ) { // if there are >2 blocks, and the back two blocks are both // empty, remove one. We always want to be sure there is at // least one block in the database, and we don't want to remove // single trailing empty blocks because it would perform poorly if // there were a bunch of additions and removals at the end of the file. if( (mvBlocks.size() > 2) && (mvBlocks[ mvBlocks.size()-2 ].GetNumItems() == 0 ) { // TODO -- uncomment these to implement file shrinking... mvBlocks.pop_back(); mBlockFile.DestroyLastBlock(); } } */ }
void NodeList::InsertAfter(Node* after, Node* node) { RAD_ASSERT(node); #if defined(RAD_OPT_DEBUG) AssertValid(); node->AssertValid(); if (after) { after->AssertValid(); RAD_ASSERT_MSG(after->m_list == this, "Attempting to insert after a node that is not in this list"); } #endif RAD_ASSERT_MSG(node->m_list == 0, "Node is already in a list!"); RAD_ASSERT(node->m_next == 0 && node->m_prev == 0); node->m_prev = after; if (after) { node->m_next = after->m_next; if (after->m_next) after->m_next->m_prev = node; after->m_next = node; } else // insert at head. { node->m_next = m_head; if (m_head) { RAD_ASSERT(m_head->m_prev == 0); m_head->m_prev = node; m_head = node; } } if (m_head == 0) { RAD_ASSERT(m_tail == 0); m_head = m_tail = node; } if (after == m_tail) { m_tail = node; } #if defined(RAD_OPT_DEBUG) node->m_list = this; #endif m_size++; }
void NodeList::InsertBefore(Node* before, Node* node) { RAD_ASSERT(node); #if defined(RAD_OPT_DEBUG) AssertValid(); node->AssertValid(); if (before) { before->AssertValid(); RAD_ASSERT_MSG(before->m_list == this, "Attempting to insert before a node that is not in this list"); } #endif RAD_ASSERT_MSG(node->m_list == 0, "Node is already in a list!"); RAD_ASSERT(node->m_next == 0 && node->m_prev == 0); node->m_next = before; if (before) { node->m_prev = before->m_prev; if (before->m_prev) before->m_prev->m_next = node; before->m_prev = node; } else // insert at head. { node->m_next = m_head; if (m_head) { RAD_ASSERT(m_head->m_prev == 0); m_head->m_prev = node; m_head = node; } } if (m_head == 0) { RAD_ASSERT(m_tail == 0); m_head = m_tail = node; } if (before == m_head) { m_head = node; } #if defined(RAD_OPT_DEBUG) node->m_list = this; #endif m_size++; }
/////////////////////////////////////////////////////////////////////////////// // GetDataForWriting /////////////////////////////////////////////////////////////////////////////// int8* cBlockRecordFile::GetDataForWriting( cBlockRecordFile::tAddr dataAddr, int32& dataSize ) //throw (eArchive) { ASSERT( mbOpen ); ASSERT( IsValidAddr( dataAddr ) ); #ifdef _BLOCKFILE_DEBUG AssertValid(); #endif return ( mvBlocks[ dataAddr.mBlockNum ].GetDataForWriting( dataAddr.mIndex, dataSize ) ); }
void cHierDatabase::Open ( const TSTRING& fileName, int numPages, bool bTruncate ) //throw (eArchive, eHierDatabase) { inherited::Open(fileName, numPages, bTruncate); #ifdef _BLOCKFILE_DEBUG AssertValid(); #endif OpenImpl( bTruncate ); }
void nsTDependentString_CharT::Rebind( const char_type* data, size_type length ) { // If we currently own a buffer, release it. Finalize(); mData = const_cast<char_type*>(data); mLength = length; SetDataFlags(F_TERMINATED); AssertValid(); }
int CAudioRenderer::GetSamplePool(const GUID& guid, ISamplePool** ppPool) { AssertValid(ppPool); if (!memcmp(&guid, &GUID_AUDIO_DECODER, sizeof(GUID))) { *ppPool = &m_PcmPool; } else { *ppPool = NULL; } return S_OK; }
int StageStats::GetAverageMeter( PlayerNumber pn ) const { AssertValid( pn ); // TODO: This isn't correct for courses. int iTotalMeter = 0; for( unsigned i=0; i<m_vpPlayedSongs.size(); i++ ) { const Steps* pSteps = m_player[pn].m_vpPossibleSteps[i]; iTotalMeter += pSteps->GetMeter(); } return iTotalMeter / m_vpPlayedSongs.size(); // round down }
int CDictionary::LookupWord(const char* pszWord) { CAutoLock cObjectLock(this); for (int i = 0; i < m_vecDicts.size(); ++i) { CSubDictionary* pSubDict = m_vecDicts[i]; AssertValid(pSubDict); if (!strncmp(pSubDict->GetName(), pszWord, 1)) { return pSubDict->LookupWord(pszWord); } } return FALSE; }
CSubDictionary* CDictionary::GetSubDictionary(const char* pszName) { CAutoLock cObjectLock(this); for (int i = 0; i < m_vecDicts.size(); ++i) { CSubDictionary* pSubDict = m_vecDicts[i]; AssertValid(pSubDict); if (!strcmp(pSubDict->GetName(), pszName)) { return pSubDict; } } return NULL; }
/////////////////////////////////////////////////////////////////////////////// // FindRoomForData /////////////////////////////////////////////////////////////////////////////// int cBlockRecordFile::FindRoomForData(int32 dataSize) //throw (eArchive) { ASSERT((dataSize > 0) && (dataSize <= cBlockRecordArray::MAX_DATA_SIZE)); ASSERT(mbOpen); #ifdef _BLOCKFILE_DEBUG AssertValid(); #endif cDebug d("cBlockRecordFile::FindRoomForData"); // first, try the last added to block... // d.TraceDetail("Looking for room for %d bytes; first trying mLastAddedTo (%d)\n", dataSize, mLastAddedTo); if (mLastAddedTo >= 0) { util_InitBlockArray(mvBlocks[mLastAddedTo]); if (mvBlocks[mLastAddedTo].GetAvailableSpace() >= dataSize) { d.TraceDetail("---Found room in block %d\n", mLastAddedTo); return mLastAddedTo; } } // // ok, I guess we will have to iterate through all the blocks... // BlockArray::iterator it; int cnt = 0; for (it = mvBlocks.begin(); it != mvBlocks.end(); ++it, ++cnt) { util_InitBlockArray(*it); if (it->GetAvailableSpace() >= dataSize) { d.TraceDetail("---Found room in block %d\n", cnt); return cnt; } } // // if we got here, then we need to add a new block // d.TraceDetail("---We need to add new block(%d)\n", cnt); mBlockFile.CreateBlock(); ASSERT((mBlockFile.GetNumBlocks() == (mvBlocks.size() + 1)) && (mvBlocks.size() == cnt)); mvBlocks.push_back(cBlockRecordArray(&mBlockFile, cnt)); mvBlocks.back().InitNewBlock(); ASSERT(mvBlocks.back().GetAvailableSpace() >= dataSize); return cnt; }
void CHMLayer::ModifyProp(tagHMLayerID *pLayerID) { ASSERT(pLayerID != NULL); m_CName = pLayerID->strLayerName; m_bHide = pLayerID->bHide; if ((pLayerID->fStartScale != m_startViewBL)|(pLayerID->fEndScale != m_endViewBL)|(pLayerID->fScale != m_DefaultBL)) { m_startViewBL = pLayerID->fStartScale; m_endViewBL = pLayerID->fEndScale; m_DefaultBL = pLayerID->fScale; OnHMLayerDataChanged(); } AssertValid(); }
void NodeList::Remove(Node* node) { RAD_ASSERT(m_size > 0); RAD_ASSERT(node); #if defined(RAD_OPT_DEBUG) AssertValid(); node->AssertValid(); if (m_head) { RAD_ASSERT(m_head->m_prev == 0); } if (m_tail) { RAD_ASSERT(m_tail->m_next == 0); } RAD_ASSERT_MSG(node->m_list == this, "Node not owned by this list!"); #endif if (node->m_prev) node->m_prev->m_next = node->m_next; if (node->m_next) node->m_next->m_prev = node->m_prev; if (node == m_head) { RAD_ASSERT(node->m_prev == 0); m_head = node->m_next; } if (node == m_tail) { RAD_ASSERT(node->m_next == 0); m_tail = node->m_prev; } #if defined(RAD_OPT_DEBUG) node->m_prev = node->m_next = 0; node->m_list = 0; #endif --m_size; }
void CHMLayer::Save(CFile *file, BOOL Yn) { int num; POSITION pos; CTyBase * pTy; int bufsize=0; DRAW_TY tystyle; ASSERT(file!=NULL); if (Yn) { AssertValid(); num=m_TyList.GetCount(); file->Write((char *)&num,sizeof(num)); pos=m_TyList.GetHeadPosition(); while (pos!=NULL) { pTy=m_TyList.GetNext(pos); ASSERT(pTy!=NULL); if (!pTy->m_bDelete) { tystyle=pTy->GetTyType(); ASSERT(tystyle!=tyNone); file->Write((char *)&tystyle,sizeof(tystyle)); pTy->Save(file,Yn); } } } else { file->Read((char *)&num,sizeof(num)); for (int i=0;i<num;i++) { file->Read((char *)&tystyle,sizeof(tystyle)); pTy=CTyBase::CreateTy(tystyle); if (pTy==NULL) return; pTy->Save(file,Yn); Add(pTy,TRUE);//FALSE); } } }
/////////////////////////////////////////////////////////////////////////////// // AddItem /////////////////////////////////////////////////////////////////////////////// cBlockRecordFile::tAddr cBlockRecordFile::AddItem( int8* pData, int dataSize ) //throw (eArchive) { ASSERT( mbOpen ); #ifdef _BLOCKFILE_DEBUG AssertValid(); #endif tAddr rtn(0, 0); // // first, let's find room for this data item... // rtn.mBlockNum = FindRoomForData( dataSize ); // // now, insert the data... // rtn.mIndex = mvBlocks[rtn.mBlockNum].AddItem( pData, dataSize, 1 ); // // update the last added to pointer and return the location... // mLastAddedTo = rtn.mBlockNum; return rtn; }
int CAudioRenderer::Execute() { Log("CAudioRenderer::Execute\n"); AssertValid(m_nSampleRate > 0 && m_nChannelCount > 0); if (m_nSampleRate <= 0 || m_nChannelCount <= 0) { m_lfTSScale = 0; } else { SampleFormat format = (SampleFormat)m_nSampleFormat; Log("format = %d\n", format); int nBitCount = 16; switch (format) { case AV_SAMPLE_FMT_U8: nBitCount = 8; break; case AV_SAMPLE_FMT_S16: nBitCount = 16; break; case AV_SAMPLE_FMT_S32: nBitCount = 32; break; case AV_SAMPLE_FMT_FLT: nBitCount = sizeof(float); break; case AV_SAMPLE_FMT_DBL: nBitCount = sizeof(double); break; default: break; } m_lfTSScale = (double)1 / (m_nSampleRate * nBitCount / 8 * m_nChannelCount) / m_lfTimebase; // pts per byte } CMediaObject::Execute(); return S_OK; }
int CAudioMuxer::WriteFileData(BYTE* pbData, int nSize) { BYTE* pSrcCur = pbData; BYTE* pSrcEnd = pbData + nSize; BYTE* pDstEnd = m_pSamples + m_nBufSize; while (nSize > 0) { if (nSize < pDstEnd - m_pDstCur) { memcpy(m_pDstCur, pSrcCur, nSize); m_pDstCur += nSize; pSrcCur += nSize; AssertValid(pSrcCur == pSrcEnd); } else { memcpy(m_pDstCur, pSrcCur, pDstEnd - m_pDstCur); pSrcCur += pDstEnd - m_pDstCur; WriteFileDataImpl(); m_pDstCur = m_pSamples; } nSize = pSrcEnd - pSrcCur; } return S_OK; }
int CAudioRenderer::GetMediaCurrentTime(double* pTime) { AssertValid(pTime); return E_NOIMPL; }
inline void CAudioRenderer::FillBuffer(BYTE* pBuffer, UINT nDataByteSize) { CMediaSample sample; BOOL bFirst = TRUE; LONGLONG llEarly = 0; while (nDataByteSize > 0 && !m_bFlush && !m_bClose) { int nResult = m_PcmPool.GetUnused(sample); if (nResult != S_OK) { if (m_vecInObjs[0]->IsEOS() || m_bInterrupt) break; m_ASync.Wait(3000); continue; } //Log("audio pts: %lld, syncpt: %lld, actual: %d, stream time: %lld\n", // sample.m_llTimestamp, sample.m_llSyncPoint, sample.m_nActual, m_pRefClock->GetTime()); if (bFirst) { bFirst = FALSE; llEarly = (EstimateTimestamp(sample) - sample.m_llSyncPoint) * m_lfTimebase * 1000 - m_pRefClock->GetTime(); //Log("llEarly = %lld\n", llEarly); if (llEarly > AUDIO_SYNC_MIN_TOP) { memset(pBuffer, 0, nDataByteSize); //Log("actual: %d, wait: %lld\n", sample.m_nActual, llEarly); if (llEarly > AUDIO_SYNC_MAX_TOP) { m_PcmPool.Consume(sample.m_nActual); m_PcmPool.Recycle(sample); continue; } break; } else if (llEarly < AUDIO_SYNC_MAX_BOTTOM) { //Log("early = %lld\n", llEarly); if (sample.m_nActual <= nDataByteSize) { m_PcmPool.Consume(sample.m_nActual); m_PcmPool.Recycle(sample); } else { // sample.m_nActual > nDataByteSize sample.m_pCur += nDataByteSize; sample.m_nActual -= nDataByteSize; m_PcmPool.Consume(nDataByteSize); m_PcmPool.Update(sample); } bFirst = TRUE; continue; } } AssertValid(llEarly >= AUDIO_SYNC_MAX_BOTTOM); if (sample.m_nActual > nDataByteSize) { memcpy(pBuffer, sample.m_pCur, nDataByteSize); sample.m_pCur += nDataByteSize; sample.m_nActual -= nDataByteSize; m_PcmPool.Consume(nDataByteSize); m_PcmPool.Update(sample); nDataByteSize = 0; } else if (sample.m_nActual == nDataByteSize) { memcpy(pBuffer, sample.m_pCur, nDataByteSize); m_PcmPool.Consume(nDataByteSize); m_PcmPool.Recycle(sample); nDataByteSize = 0; } else { // sample.m_nActual < nDataByteSize memcpy(pBuffer, sample.m_pCur, sample.m_nActual); pBuffer += sample.m_nActual; nDataByteSize -= sample.m_nActual; m_PcmPool.Consume(sample.m_nActual); m_PcmPool.Recycle(sample); } } }
void CHMLayer::OnHMLayerDataChanged() { UINT i,j; UINT nRow,nCol; AssertValid(); nRow = (UINT)(m_pHuaMian->m_wPicHeight*m_DefaultBL+m_pHuaMian->m_hResolution-1)/m_pHuaMian->m_hResolution; nCol = (UINT)(m_pHuaMian->m_wPicWidth*m_DefaultBL+m_pHuaMian->m_wResolution-1)/m_pHuaMian->m_wResolution; ASSERT(nRow > 0); ASSERT(nCol > 0); if (nRow < 1) nRow = 1; if (nCol < 1) nCol = 1; ASSERT(nRow <= MAX_QGMROW); ASSERT(nCol <= MAX_QGMCOL); if (nRow > MAX_QGMROW) nRow = MAX_QGMROW; if (nCol > MAX_QGMCOL) nCol = MAX_QGMCOL; for (i = 0;i < m_uRow;i++) { for(j = 0;j < m_uCol;j++) { if ((QGMArr[i][j] != NULL)&&((i >= nRow)||(j >= nCol))) { delete QGMArr[i][j]; QGMArr[i][j] = NULL; } } } m_uRow = nRow; m_uCol = nCol; float stepX = (float)m_pHuaMian->m_wPicWidth/(float)m_uCol; float stepY = (float)m_pHuaMian->m_wPicHeight/(float)m_uRow; for(i = 0;i < (int)m_uRow;i++) { for(j = 0;j < (int)m_uCol;j++) { if (QGMArr[i][j] == NULL) { QGMArr[i][j] = new CQGM(j*stepX,i*stepY,(j+1)*stepX,(i+1)*stepY); } else { QGMArr[i][j]->Clear(); QGMArr[i][j]->SetBounds(j*stepX,i*stepY,(j+1)*stepX,(i+1)*stepY); } } } CTyBase* pTy; POSITION pos = m_TyList.GetHeadPosition(); while (pos != NULL) { pTy = m_TyList.GetNext(pos); ASSERT(pTy!=NULL); OnAddTy(pTy); } }