D3DTexture::~D3DTexture() { traceIn(D3DTexture::~D3DTexture); FreeBuffer(); if(bDynamic || (dwTexType == D3DTEXTURE_FRAME_BUFFER)) { d3d->DynamicTextureList.RemoveItem(this); Free(textureData); } traceOut; }
void wxStreamBuffer::SetBufferIO(size_t bufsize) { if ( bufsize ) { // this will free the old buffer and allocate the new one SetBufferIO(malloc(bufsize), bufsize, true /* take ownership */); } else // no buffer size => no buffer { // still free the old one FreeBuffer(); InitBuffer(); } }
OMX_ERRORTYPE ISource::FreeUsedBuffers( BufferInfo **pBuffers, OMX_U32 nBufferCount, OMX_U32 ePortIndex) { OMX_ERRORTYPE result = OMX_ErrorNone; VTEST_MSG_MEDIUM("%s, freeing used buffer on %s port", Name(), OMX_PORT_NAME(ePortIndex)); for (OMX_U32 i = 0; i < nBufferCount; i++) { BufferInfo *pBuffer = &((*pBuffers)[i]); VTEST_MSG_LOW("%s, free-use 0x%lx (%p %p)",Name(), pBuffer->pHandle, pBuffer->pHeaderIn, pBuffer->pHeaderOut); result = FreeBuffer(pBuffer, ePortIndex); } return result; }
Buffer_t * CreateBuffer(int width, int height, int sample_sz) { Buffer_t* out = (Buffer_t*)malloc(sizeof(Buffer_t)); out->m.height = height; out->m.width = width; out->m.sample_sz = sample_sz; out->m.pitch = out->m.sample_sz * out->m.width; out->m.size = out->m.pitch * out->m.height; out->payload = (BYTE*)malloc(out->m.size); if (!out->payload) { DBGERROR("out of memory"); FreeBuffer(out); return NULL; } return out; }
void wxStreamBuffer::SetBufferIO(void *start, size_t len, bool takeOwnership) { // start by freeing the old buffer FreeBuffer(); m_buffer_start = (char *)start; m_buffer_end = m_buffer_start + len; // if we own it, we free it m_destroybuf = takeOwnership; ResetBuffer(); }
// initialize the content (attachment) by reading from a file bool CMimeBody::ReadFromFile(const char* pszFilename) { int hFile = ::open(pszFilename, O_RDONLY | O_BINARY); if (hFile < 0) return false; try { int nFileSize = (int)::lseek(hFile, 0L, SEEK_END); // get file length ::lseek(hFile, 0L, SEEK_SET); FreeBuffer(); if (nFileSize > 0) { AllocateBuffer(nFileSize+4); unsigned char* pszData = m_pbText; for (;;) { int nRead = ::read(hFile, pszData, 512); if (nRead < 0) { ::close(hFile); return false; } pszData += nRead; if (nRead < 512) break; } *pszData = 0; m_nTextSize = nFileSize; } } catch (...) { ::close(hFile); throw; } ::close(hFile); const char* pszName = ::strrchr(pszFilename, '\\'); if (!pszName) pszName = pszFilename; else pszName++; SetName(pszName); // set 'name' parameter: return true; }
/* ======================== idSoundSample_XAudio2::FreeData Called before deleting the object and at the start of LoadResource() ======================== */ void idSoundSample_XAudio2::FreeData() { if ( buffers.Num() > 0 ) { soundSystemLocal.StopVoicesWithSample( (idSoundSample *)this ); for ( int i = 0; i < buffers.Num(); i++ ) { FreeBuffer( buffers[i].buffer ); } buffers.Clear(); } amplitude.Clear(); timestamp = FILE_NOT_FOUND_TIMESTAMP; memset( &format, 0, sizeof( format ) ); loaded = false; totalBufferSize = 0; playBegin = 0; playLength = 0; }
//停止录音 BOOL CAudioRec::Stop() { BOOL bRet=FALSE; if(!m_hIn) goto RET; m_mmr=waveInReset(m_hIn); if(m_mmr) goto RET; if(!FreeBuffer()) goto RET; bRet=TRUE; RET: return TRUE; }
//终止录音 BOOL CWaveIn::StopRec() { //停止录音 CloseRecord(); //休眠1500毫秒 Sleep(800); //释放缓存 FreeBuffer(); //关闭录音设备 if (CloseDev()) { //停止线程 StopThread(); } //返回 return TRUE; }
DWORD PCOBuffer::Free() { DWORD err = PCO_NOERROR; if ((buf != NULL) && (bufnr > -1)) { err = FreeBuffer(cameraHandle, bufnr); errmsg.ShowPCOError("FreeBuffer",err); if (err == PCO_NOERROR) { bufwidth = bufheight = 0; buf = NULL; bufnr = -1; picev=NULL; } } return err; }
// save Jpeg file BOOL CJpeg::Save(LPCSTR lpstrFileName, CDib* pDib, BOOL bColor, int nQuality) { if (pDib == NULL) pDib = m_pDib; if (pDib == NULL) return FALSE; HDIB hDib = CopyHandle(pDib->GetHandle()); if (hDib == NULL) return FALSE; CDib* pDibTmp = new CDib; pDibTmp->Attach(hDib); if (pDibTmp->GetBitCount() != 24) pDibTmp->ConvertFormat(24); UINT uWidth = pDibTmp->GetWidth(); UINT uHeight = pDibTmp->GetHeight(); // convert from DIB format (DWORD aligned, vertically flipped, red and blue swapped) BYTE* tmp = ClearDwordAlign(pDibTmp->GetBitsPtr(), uWidth, WIDTHBYTES(uWidth * 24), uHeight); if (tmp == NULL) return FALSE; // convert from DIB VertFlipBuf(tmp, uWidth*3, uHeight); BGRFromRGB(tmp, uWidth, uHeight); BOOL bSuccess = WriteJPEGFile(lpstrFileName, tmp, uWidth, uHeight, bColor, nQuality); delete pDibTmp; FreeBuffer(tmp); return bSuccess; }
gralloc1_error_t BufferManager::ReleaseBuffer(private_handle_t const *hnd) { if (hnd->flags & private_handle_t::PRIV_FLAGS_CLIENT_ALLOCATED) { return GRALLOC1_ERROR_NONE; } ALOGD_IF(DEBUG, "Release buffer handle:%p id: %" PRIu64, hnd, hnd->id); std::lock_guard<std::mutex> lock(buffer_lock_); auto buf = GetBufferFromHandleLocked(hnd); if (buf == nullptr) { ALOGE("Could not find handle: %p id: %" PRIu64, hnd, hnd->id); return GRALLOC1_ERROR_BAD_HANDLE; } else { if (buf->DecRef()) { handles_map_.erase(hnd); // Unmap, close ion handle and close fd FreeBuffer(buf); } } return GRALLOC1_ERROR_NONE; }
void wxStreamBuffer::Truncate() { size_t new_size = m_buffer_pos - m_buffer_start; if ( m_buffer_pos == m_buffer_end ) return; if ( !new_size ) { FreeBuffer(); InitBuffer(); return; } char *new_start = (char *)realloc(m_buffer_start, new_size); wxCHECK_RET( new_size, wxT("shrinking buffer shouldn't fail") ); m_buffer_start = new_start; m_buffer_end = m_buffer_start + new_size; m_buffer_pos = m_buffer_end; }
//------------------------------------------------------------------------- MH_STATUS WINAPI MH_RemoveHook(LPVOID pTarget) { MH_STATUS status = MH_OK; EnterSpinLock(); if (g_hHeap != NULL) { UINT pos = FindHookEntry(pTarget); if (pos != INVALID_HOOK_POS) { if (g_hooks.pItems[pos].isEnabled) { FROZEN_THREADS threads; Freeze(&threads, pos, ACTION_DISABLE); status = EnableHookLL(pos, FALSE); Unfreeze(&threads); } if (status == MH_OK) { FreeBuffer(g_hooks.pItems[pos].pTrampoline); DeleteHookEntry(pos); } } else { status = MH_ERROR_NOT_CREATED; } } else { status = MH_ERROR_NOT_INITIALIZED; } LeaveSpinLock(); return status; }
void _M_RUCH_INFO(astr A_S) { aint KONIEC=0; rysuj(); MouseClick(); // INFO: OKNO(90,100,158,22); // OKNO[90,100,158,22] GADGET(OKX+4,OKY+4,150,15,"",31,2,30,1,0);// GADGET[OKX+4,OKY+4,150,15,"",31,2,30,1,0] gad_text(1.0); Text(OKX+8,OKY+15,A_S); // Ink 1,30 : Text OKX+8,OKY+15,A$ void *sb=StoreBuffer(OKX-1,OKY-1,158+2,22+2); do { // Repeat rysuj(); RestoreBuffer(sb); WaitVbl(); if( MouseClick() ) { // If Mouse Click=1 KONIEC=-1; // KONIEC=True } // End If } while( KONIEC==0 ); // Until KONIEC ZOKNO(); // ZOKNO FreeBuffer(sb); rysuj(); WaitVbl(); }
// 加载订阅数据 void MsgClient::LoadSubscribe( User &user ) { if ( _dmddir.IsEmpty() ) return ; char szbuf[1024] = {0}; sprintf( szbuf, "%s/%d", _dmddir.GetBuffer(), user._access_code ) ; int len = 0 ; char *ptr = ReadFile( szbuf, len ) ; if ( ptr == NULL ){ OUT_ERROR( NULL, 0, NULL, "load subscribe file %s failed", szbuf ) ; return ; } // 移除掉换行回车空格等字符 while( len > 0 ) { if ( ptr[len-1] == '\r' || ptr[len-1] == '\n' || ptr[len-1] == ' ' || ptr[len-1] == '\t' ){ ptr[len-1] = 0 ; -- len ; continue ; } break ; } // DMD 0 {E005_13571198041} \r\n CQString sz ; sz.AppendBuffer( "DMD 0 {" ) ; sz.AppendBuffer( ptr , len ) ; sz.AppendBuffer( "} \r\n" ) ; FreeBuffer( ptr ) ; if ( ! SendData( user._fd, sz.GetBuffer(), sz.GetLength() ) ) { OUT_ERROR( NULL, 0, NULL, "Send Data : %s Failed", sz.GetBuffer() ) ; } else { OUT_PRINT( NULL, 0, NULL, "Send Sub: %s", sz.GetBuffer() ) ; } }
void ReadNewUser() { userFirstLine = 1; inputCount = 0; ClearUserVariables(); ResetTopicSystem(); // set his random seed bool hasUpperCharacters; unsigned int rand = (unsigned int) Hashit((unsigned char *) loginID,strlen(loginID),hasUpperCharacters); char word[MAX_WORD_SIZE]; randIndex = rand & 4095; sprintf(word,"%d",randIndex); SetUserVariable("$randindex",word ); strcpy(word,computerID); word[0] = toUppercaseData[(unsigned char)word[0]]; SetUserVariable("$bot",word ); SetUserVariable("$login",loginName); sprintf(readBuffer,"^%s",computerID); WORDP D = FindWord(readBuffer,0,LOWERCASE_LOOKUP); if (!D) { ReportBug("Cannot find bot %s\r\n",computerID); return; } int oldjump = jumpIndex; char* macroArgumentList = AllocateBuffer(); *macroArgumentList = 0; globalDepth = 2; unsigned int result; currentOutputBase = macroArgumentList; DoFunction(D->word,macroArgumentList,macroArgumentList,result); globalDepth = 0; jumpIndex = oldjump; // return to old error handler FreeBuffer(); }
NTSTATUS FdoPortClose(IN PC0C_FDOPORT_EXTENSION pDevExt, IN PIRP pIrp) { NTSTATUS status; LIST_ENTRY queueToComplete; KIRQL oldIrql; PC0C_IO_PORT pIoPort; pIoPort = pDevExt->pIoPortLocal; pIoPort->isOpen = FALSE; if (pIoPort->pIoPortRemote->plugInMode) IoInvalidateDeviceRelations(pIoPort->pIoPortRemote->pPhDevObj, BusRelations); InitializeListHead(&queueToComplete); KeAcquireSpinLock(pIoPort->pIoLock, &oldIrql); pIoPort->escapeChar = 0; pIoPort->writeHoldingRemote = 0; pIoPort->sendXonXoff = 0; SetModemControl(pIoPort, C0C_MCR_OUT2, C0C_MCR_MASK | C0C_MCR_OPEN, &queueToComplete); FreeBuffer(&pIoPort->readBuf); SetBreakHolding(pIoPort, FALSE, &queueToComplete); KeReleaseSpinLock(pIoPort->pIoLock, oldIrql); FdoPortCompleteQueue(&queueToComplete); status = FdoPortStartIrp(pIoPort, pIrp, C0C_QUEUE_CLOSE, StartIrpClose); if (status != STATUS_PENDING) { pIrp->IoStatus.Status = status; IoCompleteRequest(pIrp, IO_NO_INCREMENT); } return status; }
bool FileScanner::Close() { bool result; if (file==NULL) { log.Error() << "File '" << filename << "' already closed, cannot close it again!"; filename.clear(); return false; } filename.clear(); FreeBuffer(); result=fclose(file)==0; if (result) { file=NULL; } return result; }
//------------------------------------------------------------------------------ //! Summary: Called to set the data buffer //! //! Parameters: \li pBuffer - the buffer containing the data stream //! //! Returns: None //------------------------------------------------------------------------------ void CMLDataStream::SetStream(char* pBuffer, unsigned long ulSize) { FreeBuffer(); // deallocate the existing buffer // If the size is not specified assume this is a null-terminated character buffer if((ulSize == 0) && (pBuffer != NULL) && (lstrlen(pBuffer) > 0)) { ulSize = lstrlen(pBuffer) + 1; } if((pBuffer != NULL) && (ulSize > 0)) { m_ulSize = ulSize; m_pBuffer = new char[m_ulSize]; memcpy(m_pBuffer, pBuffer, m_ulSize); } else { m_pBuffer = NULL; m_ulSize = 0; } }
int MimeBody::LoadFromFile(const AnsiString &pszFilename) { File oFile; if (!oFile.Open(pszFilename, File::OTReadOnly)) return false; // Read the file as a text file. This will cause a null // to be added by File, which is required by Load() below. shared_ptr<ByteBuffer> pFileContents = oFile.ReadTextFile(); FreeBuffer(); if (pFileContents->GetSize() > 0) { try { // Minus one, since the last character is the null... int index = 0; Load(pFileContents->GetCharBuffer(), pFileContents->GetSize() - 1, index); } catch (...) { String sFilename = pszFilename; String sFileNameExclPath = FileUtilities::GetFileNameFromFullPath(sFilename); String sMessageBackupPath = IniFileSettings::Instance()->GetLogDirectory() + "\\Problematic messages\\" + sFileNameExclPath; FileUtilities::Copy(sFilename, sMessageBackupPath, true); String sErrorMessage = Formatter::Format("An unknown error occurred while loading message. File: {0}. Backuped to: {1}", pszFilename, sMessageBackupPath); ErrorManager::Instance()->ReportError(ErrorManager::Medium, 4228, "MimeBody::LoadFromFile", sErrorMessage); } } return true; }
static bool_t AllocBuffer(GE2DBitmapType* p,int w,int h,int* Allocated) { int size; w = (w+1) & ~1; h = (h+1) & ~1; size = w*h; p->format = sonyGE2DFormatYCbCr420Planar; p->zero = 0; p->pitch = (UInt16)w; p->chromaPitch = (UInt16)(w >> 1); p->width = (UInt16)w; p->height = (UInt16)h; p->unused = 0; if (*Allocated < size) { free(p->plane1P); free(p->plane2P); free(p->plane3P); p->plane1P = malloc(size); p->plane2P = malloc(size/4); p->plane3P = malloc(size/4); if (!p->plane1P || !p->plane2P || !p->plane3P) { FreeBuffer(p,Allocated); return 0; } *Allocated = size; } memset(p->plane1P,0,size); memset(p->plane2P,128,size/4); memset(p->plane2P,128,size/4); return 1; }
STDMETHODIMP_(NTSTATUS) CDmaChannel::AllocateBuffer(ULONG newBufferSize, PPHYSICAL_ADDRESS constraint OPTIONAL) { // free current buffer FreeBuffer(); // re-allocate buffer = MmAllocateContiguousMemory(newBufferSize,*constraint); if(buffer) { allocatedSize=newBufferSize; bufferSize=newBufferSize; physicalBufstart=MmGetPhysicalAddress(buffer); return STATUS_SUCCESS; } else { debug(DWDM,"!! CDmaChannel::AllocateBuffer: could not re-allocate buffer (%d->%d)\n",allocatedSize,bufferSize); allocatedSize=0; bufferSize=0; return STATUS_INSUFFICIENT_RESOURCES; } }
CGUISound::~CGUISound() { #ifndef HAS_SDL_AUDIO FreeBuffer(); #endif }
void DoExecute (GPtr globals) { size_t total = 0; size_t done = 0; Boolean doThis = true; BufferID sBuffer = 0; Ptr sData = NULL; BufferID dBuffer = 0; Ptr dData = NULL; BufferID mBuffer = 0; Ptr mData = NULL; BufferID rBuffer = 0; Ptr rData = NULL; PixelMemoryDesc sDesc, dDesc, mDesc, rDesc; ReadImageDocumentDesc *doc = gStuff->documentInfo; WriteChannelDesc *selection = gStuff->newSelection; ChannelReadPort selectionRead; ReadChannelDesc *composite; ReadChannelDesc *transparency; ReadChannelDesc *curChannel; /* Access the port procs. */ if (!WarnChannelPortAvailable ()) { gResult = errPlugInHostInsufficient; goto CleanUp; } gQueryForParameters = ReadScriptParams (globals); if ( gQueryForParameters ) doThis = DoUI (globals); if ( !doThis ) goto CleanUp; // user cancelled, etc. /* look in gStuff->supportedTreatments for support for this next thang */ if (gCreate == iCreateMaskpath) { // can't do that! Handle h = PIGetResource (StringResource, errCantCreatePath, &total); if (h != NULL) { Str255 errString = ""; // The handle, since it's a string, is automagically fetched as a // pascal string. If we use PIHandle2PString, we'll get two // length bytes. This way, the length byte (which is already byte // 0 of the handle) is preserved as the very first byte of the // string: PIHandle2CString(h, (char*)errString, 255); // handle, string, maxlength PIDisposeHandle(h); h = NULL; // reset gResult = PIReportError(errString); } else gStuff->treatment = KeyToEnum(EnumToKey(gCreate,typeMyCreate),typeMyPISel); // otherwise Pshop will catch it automatically goto CleanUp; // don't do any of this gunk } else gStuff->treatment = KeyToEnum(EnumToKey(gCreate,typeMyCreate),typeMyPISel); // Set the treatment then move on /* We will need a read port for the selection. */ gResult = ReadFromWritePort(&selectionRead, selection->port); if (gResult != noErr) goto CleanUp; /* Figure out which composite data to use. */ if (DoTarget) { composite = doc->targetCompositeChannels; transparency = doc->targetTransparency; if (composite == NULL) { composite = doc->mergedCompositeChannels; transparency = doc->mergedTransparency; } } else { composite = doc->mergedCompositeChannels; transparency = doc->mergedTransparency; } /* Allocate the buffers. */ if (!WarnBufferProcsAvailable ()) { gResult = +1; goto CleanUp; } #define kBufferSize kBlockRows * (long) kBlockCols gResult = AllocateBuffer (kBufferSize, &sBuffer); if (gResult != noErr) goto CleanUp; gResult = AllocateBuffer (kBufferSize, &dBuffer); if (gResult != noErr) goto CleanUp; gResult = AllocateBuffer (kBufferSize, &rBuffer); if (gResult != noErr) goto CleanUp; if (transparency != NULL) { gResult = AllocateBuffer (kBufferSize, &mBuffer); if (gResult != noErr) goto CleanUp; } /* Lock the buffers down. */ sData = LockBuffer (sBuffer, false); dData = LockBuffer (dBuffer, false); rData = LockBuffer (rBuffer, false); if (mBuffer != 0) mData = LockBuffer (mBuffer, false); /* Set up the pixel memory descriptors. */ sDesc.data = sData; sDesc.rowBits = kBlockCols * 8; sDesc.colBits = 8; sDesc.bitOffset = 0; sDesc.depth = 8; dDesc = sDesc; dDesc.data = dData; rDesc = sDesc; rDesc.data = rData; mDesc = sDesc; mDesc.data = mData; rData[0] = kInitRandom; // flag for uninitialized random buffer /* Count the channels to process. */ if (doc->selection != NULL) total += AccountChannel (doc->selection, NULL, selection); curChannel = composite; while (curChannel != NULL) { if (DoTarget ? curChannel->target : curChannel->shown) total += AccountChannel (curChannel, transparency, selection); curChannel = curChannel->next; } if (doc->targetLayerMask != NULL && (DoTarget ? doc->targetLayerMask->target : doc->targetLayerMask->shown)) total += AccountChannel (doc->targetLayerMask, NULL, selection); curChannel = doc->alphaChannels; while (curChannel != NULL) { if (DoTarget ? curChannel->target : curChannel->shown) total += AccountChannel (curChannel, NULL, selection); curChannel = curChannel->next; } /* Apply any existing selection. */ if (doc->selection != NULL) { ApplyChannel (globals, doc->selection, &sDesc, NULL, &mDesc, selection, selectionRead, &dDesc, &rDesc, &done, total); if (gResult != noErr) goto CleanUp; } /* Apply each of the channels. This isn't the most efficient approach since it reads the data back out of the selection repeatedly, but it provides a good work out for the code. */ curChannel = composite; while (curChannel != NULL) { if (DoTarget ? curChannel->target : curChannel->shown) { ApplyChannel (globals, curChannel, &sDesc, transparency, &mDesc, selection, selectionRead, &dDesc, &rDesc, &done, total); if (gResult != noErr) goto CleanUp; } curChannel = curChannel->next; } /* Apply the layer mask. */ if (doc->targetLayerMask != NULL && (DoTarget ? doc->targetLayerMask->target : doc->targetLayerMask->shown)) { ApplyChannel (globals, doc->targetLayerMask, &sDesc, NULL, &mDesc, selection, selectionRead, &dDesc, &rDesc, &done, total); if (gResult != noErr) goto CleanUp; } /* Process the alpha channels. */ curChannel = doc->alphaChannels; while (curChannel != NULL) { if (DoTarget ? curChannel->target : curChannel->shown) { ApplyChannel (globals, curChannel, &sDesc, NULL, &mDesc, selection, selectionRead, &dDesc, &rDesc, &done, total); if (gResult != noErr) goto CleanUp; } curChannel = curChannel->next; } CleanUp: if (sData != NULL) UnlockBuffer (sBuffer); if (dData != NULL) UnlockBuffer (dBuffer); if (mData != NULL) UnlockBuffer (mBuffer); if (rData != NULL) UnlockBuffer (rBuffer); if (sBuffer != 0) FreeBuffer (sBuffer); if (dBuffer != 0) FreeBuffer (dBuffer); if (mBuffer != 0) FreeBuffer (mBuffer); if (rBuffer != 0) FreeBuffer (rBuffer); WriteScriptParams(globals); }
/* ======================== idSoundSample_XAudio2::LoadWav ======================== */ bool idSoundSample_XAudio2::LoadWav( const idStr & filename ) { // load the wave idWaveFile wave; if ( !wave.Open( filename ) ) { return false; } idStrStatic< MAX_OSPATH > sampleName = filename; sampleName.SetFileExtension( "amp" ); LoadAmplitude( sampleName ); const char * formatError = wave.ReadWaveFormat( format ); if ( formatError != NULL ) { idLib::Warning( "LoadWav( %s ) : %s", filename.c_str(), formatError ); MakeDefault(); return false; } timestamp = wave.Timestamp(); totalBufferSize = wave.SeekToChunk( 'data' ); if ( format.basic.formatTag == idWaveFile::FORMAT_PCM || format.basic.formatTag == idWaveFile::FORMAT_EXTENSIBLE ) { if ( format.basic.bitsPerSample != 16 ) { idLib::Warning( "LoadWav( %s ) : %s", filename.c_str(), "Not a 16 bit PCM wav file" ); MakeDefault(); return false; } playBegin = 0; playLength = ( totalBufferSize ) / format.basic.blockSize; buffers.SetNum( 1 ); buffers[0].bufferSize = totalBufferSize; buffers[0].numSamples = playLength; buffers[0].buffer = AllocBuffer( totalBufferSize, GetName() ); wave.Read( buffers[0].buffer, totalBufferSize ); if ( format.basic.bitsPerSample == 16 ) { idSwap::LittleArray( (short *)buffers[0].buffer, totalBufferSize / sizeof( short ) ); } buffers[0].buffer = GPU_CONVERT_CPU_TO_CPU_CACHED_READONLY_ADDRESS( buffers[0].buffer ); } else if ( format.basic.formatTag == idWaveFile::FORMAT_ADPCM ) { playBegin = 0; playLength = ( ( totalBufferSize / format.basic.blockSize ) * format.extra.adpcm.samplesPerBlock ); buffers.SetNum( 1 ); buffers[0].bufferSize = totalBufferSize; buffers[0].numSamples = playLength; buffers[0].buffer = AllocBuffer( totalBufferSize, GetName() ); wave.Read( buffers[0].buffer, totalBufferSize ); buffers[0].buffer = GPU_CONVERT_CPU_TO_CPU_CACHED_READONLY_ADDRESS( buffers[0].buffer ); } else if ( format.basic.formatTag == idWaveFile::FORMAT_XMA2 ) { if ( format.extra.xma2.blockCount == 0 ) { idLib::Warning( "LoadWav( %s ) : %s", filename.c_str(), "No data blocks in file" ); MakeDefault(); return false; } int bytesPerBlock = format.extra.xma2.bytesPerBlock; assert( format.extra.xma2.blockCount == ALIGN( totalBufferSize, bytesPerBlock ) / bytesPerBlock ); assert( format.extra.xma2.blockCount * bytesPerBlock >= totalBufferSize ); assert( format.extra.xma2.blockCount * bytesPerBlock < totalBufferSize + bytesPerBlock ); buffers.SetNum( format.extra.xma2.blockCount ); for ( int i = 0; i < buffers.Num(); i++ ) { if ( i == buffers.Num() - 1 ) { buffers[i].bufferSize = totalBufferSize - ( i * bytesPerBlock ); } else { buffers[i].bufferSize = bytesPerBlock; } buffers[i].buffer = AllocBuffer( buffers[i].bufferSize, GetName() ); wave.Read( buffers[i].buffer, buffers[i].bufferSize ); buffers[i].buffer = GPU_CONVERT_CPU_TO_CPU_CACHED_READONLY_ADDRESS( buffers[i].buffer ); } int seekTableSize = wave.SeekToChunk( 'seek' ); if ( seekTableSize != 4 * buffers.Num() ) { idLib::Warning( "LoadWav( %s ) : %s", filename.c_str(), "Wrong number of entries in seek table" ); MakeDefault(); return false; } for ( int i = 0; i < buffers.Num(); i++ ) { wave.Read( &buffers[i].numSamples, sizeof( buffers[i].numSamples ) ); idSwap::Big( buffers[i].numSamples ); } playBegin = format.extra.xma2.loopBegin; playLength = format.extra.xma2.loopLength; if ( buffers[buffers.Num()-1].numSamples < playBegin + playLength ) { // This shouldn't happen, but it's not fatal if it does playLength = buffers[buffers.Num()-1].numSamples - playBegin; } else { // Discard samples beyond playLength for ( int i = 0; i < buffers.Num(); i++ ) { if ( buffers[i].numSamples > playBegin + playLength ) { buffers[i].numSamples = playBegin + playLength; // Ideally, the following loop should always have 0 iterations because playBegin + playLength ends in the last block already // But there is no guarantee for that, so to be safe, discard all buffers beyond this one for ( int j = i + 1; j < buffers.Num(); j++ ) { FreeBuffer( buffers[j].buffer ); } buffers.SetNum( i + 1 ); break; } } } } else { idLib::Warning( "LoadWav( %s ) : Unsupported wave format %d", filename.c_str(), format.basic.formatTag ); MakeDefault(); return false; } wave.Close(); if ( format.basic.formatTag == idWaveFile::FORMAT_EXTENSIBLE ) { // HACK: XAudio2 doesn't really support FORMAT_EXTENSIBLE so we convert it to a basic format after extracting the channel mask format.basic.formatTag = format.extra.extensible.subFormat.data1; } // sanity check... assert( buffers[buffers.Num()-1].numSamples == playBegin + playLength ); return true; }
// call: interpret(telnetstate, readbytes) // return: boolean: again, string: towritebytes, string: command, [string: arg] static int l_interpret(lua_State *L) { TelnetState* ts = getts(L); size_t inputlen = 0; const char* inputbuffer = 0; if (lua_type(L, 2) == LUA_TSTRING) inputbuffer = luaL_checklstring(L, 2, &inputlen); ReadBuffer* in = &ts->in; if (in->len && inputbuffer) // make the two buffers (old + new data) only one { int len = in->len + inputlen; char* buf = MEM_ALLOC(len); memcpy(buf, in->p, in->len); memcpy(buf+in->len, inputbuffer, inputlen); MEM_FREE(in->buffer); in->p = in->mark = in->buffer = buf; in->len = len; } else if (inputbuffer) // we only have new data { in->buffer = 0; // this buffer is not allocated in->p = in->mark = (char*) inputbuffer; in->len = inputlen; } InterpretCommand cmd; if (ts->editmode == TELNET_EDIT_MODE) cmd = processeditmode(ts); else cmd = processlinemode(ts); if (cmd != IC_EOS) ReadMark(in); else cmd = IC_NOP; // EOS command is equivalent to a NOP for the caller // Again ? if (in->len) // Only need to be called again if we did not exhaust the input buffers lua_pushboolean(L, 1); else lua_pushboolean(L, 0); // Store the unprocessed bytes, if any and if they are not already stored if (in->mark < in->p && !in->buffer) { int len = in->p-in->mark+in->len; in->buffer = MEM_ALLOC(len); memcpy(in->buffer, in->mark, len); in->p = in->mark = in->buffer; in->len = len; } // free the input buffer if it was allocated and is empty else if (in->mark == in->p && !in->len && in->buffer) { MEM_FREE(in->buffer); in->buffer = in->p = in->mark = 0; in->len = 0; } // Byte to send if (ts->out.buffer) { lua_pushlstring(L, ts->out.buffer, ts->out.len); FreeBuffer(&ts->out); } else lua_pushnil(L); // Command assert(cmd < IC_NB_OF_CMD); lua_pushstring(L, ic_names[cmd]); // push command // Optional argument int opt = 0; if (cmd == IC_LINE) { opt++; if (ts->editmode == TELNET_EDIT_MODE) { char* line; int len; teel_getline(ts->teel, &line, &len, 1); lua_pushlstring(L, line, len); MEM_FREE(line); } else // TELNET_LINE_MODE { lua_pushlstring(L, ts->linemodebuffer.buffer, ts->linemodebuffer.len); FreeBuffer(&ts->linemodebuffer); } } return 3 + opt; }
static InterpretCommand processlinemode(TelnetState* ts) { InterpretCommand cmd = IC_EOS; ReadBuffer* input = &ts->in; WriteBuffer* line = &ts->linemodebuffer; int val; while (1) { ReadMark(input); CHECK_BREAK(val = ReadByte(input)); if (val == IAC) { CHECK_BREAK(val = ReadByte(input)); if (val >= WILL && val <= DONT) { int opt; CHECK_BREAK(opt = ReadByte(input)); parseoption(ts, val, opt); } else if (val == SB) { int sopt; CHECK_BREAK(sopt = ReadByte(input)); parsesuboption(ts, sopt, input); } else if (val == IP) { WriteBytes(&ts->out, "\r\n", 2); FreeBuffer(line); cmd = IC_IP; break; } else if (val == SUSP) { WriteBytes(&ts->out, "\r\n", 2); FreeBuffer(line); cmd = IC_SUSP; break; } else if (val == EOF_) { if (!line->len) // only close if there the current line is empty ! { cmd = IC_CLOSE; break; } } else if (val == 255) { WriteByte(line, 255); } else { printf("Telnet interpreter: unknown character code: 255, %d. Skipping it...\n", val); } } else if (val == 10) // New line { WriteBytes(line, "\r\n", 2); // store and echo the newline cmd = IC_LINE; break; } else if (val == 13) // CR, NULL and CR/NL is interpreted as a new line { CHECK_BREAK(val = ReadByte(input)); if (val == 0 || val == 10) { WriteBytes(line, "\r\n", 2); // store and echo the newline cmd = IC_LINE; break; } else // false detection, just store and echo as is. { WriteByte(line, 10); WriteByte(line, val); } } else if (val == 4) // EOF the user requested to close the terminal { if (!line->len) // only close if there the current line is empty ! { cmd = IC_CLOSE; break; } } else if (val == 3) // IP (equivalent to IAC IP) { WriteBytes(&ts->out, "\r\n", 2); FreeBuffer(line); cmd = IC_IP; break; } else if (val == 19) // IP (equivalent to IAC SUSP) { WriteBytes(&ts->out, "\r\n", 2); FreeBuffer(line); cmd = IC_SUSP; break; } else // other char are just stored { WriteByte(line, val); } } return cmd; }
wxStreamBuffer::~wxStreamBuffer() { FreeBuffer(); }
CIpInfo::~CIpInfo() { FreeBuffer(); }