void computeDescriptorsLane(void *pixels, int depth, int width, int height, VertexBufferObject &points, DescriptorData &descriptors) { unsigned char *srcBuffer; unsigned char *dstBuffer; cudaMalloc( (void**) &srcBuffer, sizeof(unsigned char)*depth*width*height); cudaMemcpy( srcBuffer, pixels, sizeof(unsigned char)*depth*width*height, cudaMemcpyHostToDevice ); cudaMalloc((void**) &dstBuffer, sizeof(unsigned char)*depth*width*height*2); // convert to RGB cudaYCbYCrToY( (uchar4*)dstBuffer, (uchar4*)srcBuffer, width*2, height); std::cout << "Passed cudaYCbYCrToY" << std::endl; // convert to 1 plane float cuda //float *yBuffer; //cudaMalloc((void**)&yBuffer, sizeof(float)*width*2*height); UInt2 imgSize(1920,1080); CudaImageBuffer<float> m_satImage; allocBuffer(m_satImage, imgSize); cudaRGBAtoCuda((float*)m_satImage, (uchar4*)dstBuffer, width*2, height, width*2); std::cout << "Passed cudaRGBAtoCuda" << std::endl; convertToIntegral(m_satImage); std::cout << "Passed convertToIntegral" << std::endl; CudaImageBuffer<float> m_hesImage; allocBuffer(m_hesImage, imgSize); HessianData m_hessianData; m_hessianData.allocImages(imgSize); computeHessianDet( m_satImage, m_hesImage, m_hessianData ); std::cout << "Passed computeHessianDet" << std::endl; computeNonMaxSuppression( m_hesImage, m_hessianData ); std::cout << "Passed computeNonMaxSuppression" << std::endl; collectHessianPoints( m_hessianData, descriptors); std::cout << "Passed collectHessianPoint" << std::endl; computeDescriptors( m_satImage, descriptors); std::cout << "Passed computeDescriptors" << std::endl; //collectPoints( descriptors, points, imgSize ); // free memory m_hessianData.freeImages(); releaseBuffer(m_hesImage); releaseBuffer(m_satImage); cudaFree(srcBuffer); cudaFree(dstBuffer); }
void GraphicBufferSource::setLatestBuffer_l( const BufferItem &item, bool dropped) { ALOGV("setLatestBuffer_l"); if (mLatestBufferId >= 0) { if (mLatestBufferUseCount == 0) { releaseBuffer(mLatestBufferId, mLatestBufferFrameNum, mBufferSlot[mLatestBufferId], mLatestBufferFence); // mLatestBufferFence will be set to new fence just below } } mLatestBufferId = item.mBuf; mLatestBufferFrameNum = item.mFrameNumber; mRepeatLastFrameTimestamp = item.mTimestamp + mRepeatAfterUs * 1000; mLatestBufferUseCount = dropped ? 0 : 1; mRepeatBufferDeferred = false; mRepeatLastFrameCount = kRepeatLastFrameCount; mLatestBufferFence = item.mFence; if (mReflector != NULL) { sp<AMessage> msg = new AMessage(kWhatRepeatLastFrame, mReflector); msg->setInt32("generation", ++mRepeatLastFrameGeneration); msg->post(mRepeatAfterUs); } }
void GraphicsInterface::releaseStagingResource(MapContext& ctx) { if (ctx.keep_staging_resource && ctx.staging_resource) { releaseBuffer(ctx.staging_resource); ctx.staging_resource = nullptr; } }
void NotePlayHandle::done() { lock(); noteOff( 0 ); if( hasParent() == false ) { delete m_baseDetuning; m_instrumentTrack->m_processHandles.removeAll( this ); } else { m_parent->m_subNotes.removeOne( this ); } if( m_pluginData != NULL ) { m_instrumentTrack->deleteNotePluginData( this ); } if( m_instrumentTrack->m_notes[key()] == this ) { m_instrumentTrack->m_notes[key()] = NULL; } m_subNotes.clear(); delete m_filter; if( buffer() ) releaseBuffer(); unlock(); }
void nuVertexBuffer::update(void) { if(!isInitialized()) { CHECK_GL_ERROR(glGenBuffers(1, &mVertexBufferID)); NU_ASSERT(mVertexBufferID != 0, "Cannot generate vertex buffer object.\n"); CHECK_GL_ERROR(glBindBuffer(GL_ARRAY_BUFFER, mVertexBufferID)); CHECK_GL_ERROR(glBufferData(GL_ARRAY_BUFFER, mSize, mpBuffer, getResourceUsage())); if(getUsage() == nuGResource::STATIC_RESOURCE) releaseBuffer(); mCommitSize = 0; setInitialized(true); } else { CHECK_GL_ERROR(glBindBuffer(GL_ARRAY_BUFFER, mVertexBufferID)); if(mCommitSize > VERTEX_BUFFER_MAP_THRESHOLD) { void* p_buffer; CHECK_GL_ERROR(p_buffer = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY)); memcpy(p_buffer, mpBuffer, mCommitSize); CHECK_GL_ERROR(glUnmapBuffer(GL_ARRAY_BUFFER)); } else { CHECK_GL_ERROR(glBufferSubData(GL_ARRAY_BUFFER, 0, mCommitSize, mpBuffer)); } mCommitSize = 0; } }
void ompi_java_releaseWritePtr( void *ptr, ompi_java_buffer_t *item, JNIEnv *env, jobject buf, jboolean db, int offset, int count, MPI_Datatype type, int baseType) { if(db || !buf || !ptr) return; if(opal_datatype_is_contiguous_memory_layout(&type->super, count)) { int length = count * getTypeExtent(env, type); setArrayRegion(env, buf, baseType, offset, length, ptr); } else { void *inBuf, *inBase; inBuf = ompi_java_getArrayCritical(&inBase, env, buf, offset); int rc = opal_datatype_copy_content_same_ddt( &type->super, count, inBuf, ptr); ompi_java_exceptionCheck(env, rc==OPAL_SUCCESS ? OMPI_SUCCESS : OMPI_ERROR); (*env)->ReleasePrimitiveArrayCritical(env, buf, inBase, 0); } releaseBuffer(ptr, item); }
void LLVertexBuffer::destroyGLBuffer() { LLMemType mt(LLMemType::MTYPE_VERTEX_DATA); if (mGLBuffer) { if (useVBOs()) { freeClientBuffer() ; if (mMappedData || mMappedIndexData) { llerrs << "Vertex buffer destroyed while mapped!" << llendl; } releaseBuffer(); } else { delete [] mMappedData; mMappedData = NULL; mEmpty = TRUE; } sAllocatedBytes -= getSize(); } mGLBuffer = 0; unbind(); }
//-------------------------------------------------------------- void testApp::keyPressed (int key) { // in fullscreen mode, on a pc at least, the // first time video settings the come up // they come up *under* the fullscreen window // use alt-tab to navigate to the settings // window. we are working on a fix for this... if (key == 's' || key == 'S') { vidGrabber.videoSettings(); } if (key == 'h' || key == 'H') { if(holdingBuffer == 1) { releaseBuffer(); } else { holdBuffer(); } } if (key == ']' || key == '}') { differentThreshold++; } if (key == '[' || key == '{') { differentThreshold--; } if (key == 'p' || key == 'P') { alpha = alpha + .1 > 1 ? 1 : alpha + .1; } if (key == 'o' || key == 'P') { alpha = alpha - .1 < 0 ? 0 : alpha - .1; } }
ssize_t AudioTrack::write(const void* buffer, size_t userSize) { if (mSharedBuffer != 0) return INVALID_OPERATION; if (ssize_t(userSize) < 0) { // sanity-check. user is most-likely passing an error code. LOGE("AudioTrack::write(buffer=%p, size=%u (%d)", buffer, userSize, userSize); return BAD_VALUE; } LOGV("write %p: %d bytes, mActive=%d", this, userSize, mActive); // acquire a strong reference on the IMemory and IAudioTrack so that they cannot be destroyed // while we are accessing the cblk mLock.lock(); sp <IAudioTrack> audioTrack = mAudioTrack; sp <IMemory> iMem = mCblkMemory; mLock.unlock(); ssize_t written = 0; const int8_t *src = (const int8_t *)buffer; Buffer audioBuffer; size_t frameSz = (size_t)frameSize(); do { audioBuffer.frameCount = userSize/frameSz; // Calling obtainBuffer() with a negative wait count causes // an (almost) infinite wait time. status_t err = obtainBuffer(&audioBuffer, -1); if (err < 0) { // out of buffers, return #bytes written if (err == status_t(NO_MORE_BUFFERS)) break; return ssize_t(err); } size_t toWrite; if (mFormat == AUDIO_FORMAT_PCM_8_BIT && !(mFlags & AUDIO_POLICY_OUTPUT_FLAG_DIRECT)) { // Divide capacity by 2 to take expansion into account toWrite = audioBuffer.size>>1; // 8 to 16 bit conversion int count = toWrite; int16_t *dst = (int16_t *)(audioBuffer.i8); while(count--) { *dst++ = (int16_t)(*src++^0x80) << 8; } } else { toWrite = audioBuffer.size; memcpy(audioBuffer.i8, src, toWrite); src += toWrite; } userSize -= toWrite; written += toWrite; releaseBuffer(&audioBuffer); } while (userSize >= frameSz);
void CD3D9Texture::OnLostDevice() { if (!m_bPoolManaged) { releaseBuffer(); } }
Buffer<RS>::~Buffer() { if(locked) unlock(); if(finalized) releaseBuffer(); delete buffer; }
void ofxBaseShaderNode::scaleResolution(float ws, float hs){ settings.width*=ws; settings.height*=hs; if(output){ releaseBuffer(); requestBuffer(); } }
/** * Caller does not provide a buffer -- * Nupic will either provide a buffer via setBuffer or * ask the ArrayBase to allocate a buffer via allocateBuffer. */ ArrayBase::ArrayBase(NTA_BasicType type) { if (!BasicType::isValid(type)) { NTA_THROW << "Invalid NTA_BasicType " << type << " used in array constructor"; } type_ = type; own_ = true; releaseBuffer(); }
/* -----------------------------------------------------------------------------*/ TTFileBuffer::~TTFileBuffer() { releaseBuffer(); if ( file_handle <= -1) return; closeFile(true); }
void VideoStream::decode(uint8_t* buffer, unsigned int index) { int new_frame = m_decoder.decode(buffer, index); if (new_frame) { unsigned char* buf = acquireBuffer(); m_decoder.fillFrameBuffer(buf); releaseBuffer(); } }
//--------------------------------------------------------------------- bool CD3D9HardwareIndexBuffer::releaseIfDefaultPool() { if (mD3DPool == D3DPOOL_DEFAULT) { releaseBuffer(); return true; } return false; }
/// <summary> /// Frees the memory occupied by all allocated buffers. /// </summary> void CodeAllocator::releaseAllBuffers() { while (!buffers.empty()) { releaseBuffer(buffers.top()); buffers.pop(); } ptr = NULL; sizeRemaining = 0; }
ssize_t AudioTrack::write(const void* buffer, size_t userSize) { if (mSharedBuffer != 0) return INVALID_OPERATION; if (ssize_t(userSize) < 0) { // sanity-check. user is most-likely passing an error code. LOGE("AudioTrack::write(buffer=%p, size=%u (%d)", buffer, userSize, userSize); return BAD_VALUE; } LOGV("write %p: %d bytes, mActive=%d", this, userSize, mActive); ssize_t written = 0; const int8_t *src = (const int8_t *)buffer; Buffer audioBuffer; do { audioBuffer.frameCount = userSize/frameSize(); // Calling obtainBuffer() with a negative wait count causes // an (almost) infinite wait time. status_t err = obtainBuffer(&audioBuffer, -1); if (err < 0) { // out of buffers, return #bytes written if (err == status_t(NO_MORE_BUFFERS)) break; return ssize_t(err); } size_t toWrite; if (mFormat == AudioSystem::PCM_8_BIT && !(mFlags & AudioSystem::OUTPUT_FLAG_DIRECT)) { // Divide capacity by 2 to take expansion into account toWrite = audioBuffer.size>>1; // 8 to 16 bit conversion int count = toWrite; int16_t *dst = (int16_t *)(audioBuffer.i8); while(count--) { *dst++ = (int16_t)(*src++^0x80) << 8; } } else { toWrite = audioBuffer.size; memcpy(audioBuffer.i8, src, toWrite); src += toWrite; } userSize -= toWrite; written += toWrite; releaseBuffer(&audioBuffer); } while (userSize);
void Buffer<RS>::addSize(uint32 s) { if(finalized) { if(locked) unlock(); releaseBuffer(); finalized = false; } dynamIndex.push_back(byteSize); byteSize += s; indexSize++; }
//override to copy fbo content void ofxConstantShaderNode::scaleResolution(float ws, float hs){ settings.width*=ws; settings.height*=hs; if(output){ ofFbo *output_old = output; releaseBuffer(); requestBuffer(); if(output!=output_old){ output->begin(); output_old->draw(0,0,output->getWidth(), output->getHeight()); output->end(); } } }
ssize_t AudioRecord::read(void* buffer, size_t userSize) { ssize_t read = 0; Buffer audioBuffer; int8_t *dst = static_cast<int8_t*>(buffer); if (ssize_t(userSize) < 0) { // sanity-check. user is most-likely passing an error code. LOGE("AudioRecord::read(buffer=%p, size=%u (%d)", buffer, userSize, userSize); return BAD_VALUE; } mLock.lock(); // acquire a strong reference on the IAudioRecord and IMemory so that they cannot be destroyed // while we are accessing the cblk sp <IAudioRecord> audioRecord = mAudioRecord; sp <IMemory> iMem = mCblkMemory; mLock.unlock(); do { audioBuffer.frameCount = userSize/frameSize(); // By using a wait count corresponding to twice the timeout period in // obtainBuffer() we give a chance to recover once for a read timeout // (if media_server crashed for instance) before returning a length of // 0 bytes read to the client status_t err = obtainBuffer(&audioBuffer, ((2 * MAX_RUN_TIMEOUT_MS) / WAIT_PERIOD_MS)); if (err < 0) { // out of buffers, return #bytes written if (err == status_t(NO_MORE_BUFFERS)) break; if (err == status_t(TIMED_OUT)) err = 0; return ssize_t(err); } size_t bytesRead = audioBuffer.size; memcpy(dst, audioBuffer.i8, bytesRead); dst += bytesRead; userSize -= bytesRead; read += bytesRead; releaseBuffer(&audioBuffer); } while (userSize); return read; }
/* -----------------------------------------------------------------------------*/ void TTFileBuffer::setBufferSize( int size ) { if ( buffer_size != size ) { releaseBuffer(); if ( size > MAX_BUFFER_SIZE ) buffer_size = MAX_BUFFER_SIZE; else buffer_size = size; initBuffer(); } }
std::vector<int64> Filesystem::readBlocks(int64 pStartBlock, unsigned int n, const std::vector<char*>& buffers, unsigned int buffer_offset) { _u32 blocksize=(_u32)getBlocksize(); std::vector<int64> ret; size_t currbuf = 0; for(int64 i=pStartBlock;i<pStartBlock+n;++i) { if (read_ahead_mode == IFSImageFactory::EReadaheadMode_Overlapped) { if (hasBlock(i)) { SNextBlock* next_block = completionGetBlock(i); if (next_block != NULL) { memcpy(buffers[currbuf] + buffer_offset, next_block->buffer, blocksize); ++currbuf; ret.push_back(i); free_next_blocks.push(next_block); } else if (has_error) { break; } } } else { char* buf = readBlock(i); if (buf != NULL) { memcpy(buffers[currbuf] + buffer_offset, buf, blocksize); ++currbuf; ret.push_back(i); releaseBuffer(buf); } else if (has_error) { break; } } } return ret; }
GraphicBufferSource::~GraphicBufferSource() { if (mLatestBufferId >= 0) { releaseBuffer( mLatestBufferId, mLatestBufferFrameNum, mBufferSlot[mLatestBufferId], mLatestBufferFence); } if (mNumBufferAcquired != 0) { ALOGW("potential buffer leak (acquired %d)", mNumBufferAcquired); } if (mConsumer != NULL && !mIsPersistent) { status_t err = mConsumer->consumerDisconnect(); if (err != NO_ERROR) { ALOGW("consumerDisconnect failed: %d", err); } } }
// WARNING: do not call this while device is in use! buffer is not locked! void AmBufferedAudio::setBufferSize(size_t _output_buffer_size, size_t _low_buffer_thresh, size_t _full_buffer_thresh) { DBG("set output buffer size to %zd low thresh %zd, fill thresh %zd\n", _output_buffer_size, _low_buffer_thresh, _full_buffer_thresh); bool reset_buffer = output_buffer_size != _output_buffer_size; output_buffer_size = _output_buffer_size; low_buffer_thresh = _low_buffer_thresh; full_buffer_thresh = _full_buffer_thresh; if (reset_buffer) { releaseBuffer(); allocateBuffer(); } }
ssize_t AudioRecord::read(void* buffer, size_t userSize, bool blocking) { if (mTransfer != TRANSFER_SYNC) { return INVALID_OPERATION; } if (ssize_t(userSize) < 0 || (buffer == NULL && userSize != 0)) { // sanity-check. user is most-likely passing an error code, and it would // make the return value ambiguous (actualSize vs error). ALOGE("AudioRecord::read(buffer=%p, size=%zu (%zu)", buffer, userSize, userSize); return BAD_VALUE; } ssize_t read = 0; Buffer audioBuffer; while (userSize >= mFrameSize) { audioBuffer.frameCount = userSize / mFrameSize; status_t err = obtainBuffer(&audioBuffer, blocking ? &ClientProxy::kForever : &ClientProxy::kNonBlocking); if (err < 0) { if (read > 0) { break; } if (err == TIMED_OUT || err == -EINTR) { err = WOULD_BLOCK; } return ssize_t(err); } size_t bytesRead = audioBuffer.size; memcpy(buffer, audioBuffer.i8, bytesRead); buffer = ((char *) buffer) + bytesRead; userSize -= bytesRead; read += bytesRead; releaseBuffer(&audioBuffer); } if (read > 0) { mFramesRead += read / mFrameSize; // mFramesReadTime = systemTime(SYSTEM_TIME_MONOTONIC); // not provided at this time. } return read; }
void ompi_java_releaseWritePtrv( void *ptr, ompi_java_buffer_t *item, JNIEnv *env, jobject buf, jboolean db, int offset, int *counts, int *displs, int size, MPI_Datatype type, int baseType) { if(db || !buf || !ptr) return; int i; int extent = getTypeExtent(env, type); if(opal_datatype_is_contiguous_memory_layout(&type->super, 2)) { for(i = 0; i < size; i++) { int iOff = offset + extent * displs[i], iLen = extent * counts[i]; void *iPtr = (char*)ptr + extent * displs[i]; setArrayRegion(env, buf, baseType, iOff, iLen, iPtr); } } else { void *bufPtr, *bufBase; bufPtr = ompi_java_getArrayCritical(&bufBase, env, buf, offset); for(i = 0; i < size; i++) { int iOff = extent * displs[i]; char *iBuf = iOff + (char*)bufPtr, *iPtr = iOff + (char*)ptr; int rc = opal_datatype_copy_content_same_ddt( &type->super, counts[i], iBuf, iPtr); ompi_java_exceptionCheck(env, rc==OPAL_SUCCESS ? OMPI_SUCCESS : OMPI_ERROR); } (*env)->ReleasePrimitiveArrayCritical(env, buf, bufBase, 0); } releaseBuffer(ptr, item); }
// BufferQueue::ConsumerListener callback void GraphicBufferSource::onFrameAvailable(const BufferItem& /*item*/) { Mutex::Autolock autoLock(mMutex); ALOGV("onFrameAvailable exec=%d avail=%zu", mExecuting, mNumFramesAvailable); if (mEndOfStream || mSuspended) { if (mEndOfStream) { // This should only be possible if a new buffer was queued after // EOS was signaled, i.e. the app is misbehaving. ALOGW("onFrameAvailable: EOS is set, ignoring frame"); } else { ALOGV("onFrameAvailable: suspended, ignoring frame"); } BufferItem item; status_t err = mConsumer->acquireBuffer(&item, 0); if (err == OK) { mNumBufferAcquired++; // If this is the first time we're seeing this buffer, add it to our // slot table. if (item.mGraphicBuffer != NULL) { ALOGV("onFrameAvailable: setting mBufferSlot %d", item.mBuf); mBufferSlot[item.mBuf] = item.mGraphicBuffer; } releaseBuffer(item.mBuf, item.mFrameNumber, item.mGraphicBuffer, item.mFence); } return; } mNumFramesAvailable++; mRepeatBufferDeferred = false; ++mRepeatLastFrameGeneration; if (mExecuting) { fillCodecBuffer_l(); } }
ssize_t AudioRecord::read(void* buffer, size_t userSize) { ssize_t read = 0; Buffer audioBuffer; int8_t *dst = static_cast<int8_t*>(buffer); if (ssize_t(userSize) < 0) { // sanity-check. user is most-likely passing an error code. LOGE("AudioRecord::read(buffer=%p, size=%u (%d)", buffer, userSize, userSize); return BAD_VALUE; } LOGV("read size: %d", userSize); do { audioBuffer.frameCount = userSize/mChannelCount/sizeof(int16_t); // Calling obtainBuffer() with a negative wait count causes // an (almost) infinite wait time. status_t err = obtainBuffer(&audioBuffer, -1); if (err < 0) { // out of buffers, return #bytes written if (err == status_t(NO_MORE_BUFFERS)) break; return ssize_t(err); } size_t bytesRead = audioBuffer.size; memcpy(dst, audioBuffer.i8, bytesRead); dst += bytesRead; userSize -= bytesRead; read += bytesRead; releaseBuffer(&audioBuffer); } while (userSize); return read; }
void GraphicBufferSource::suspend(bool suspend) { Mutex::Autolock autoLock(mMutex); if (suspend) { mSuspended = true; while (mNumFramesAvailable > 0) { BufferItem item; status_t err = mConsumer->acquireBuffer(&item, 0); if (err == BufferQueue::NO_BUFFER_AVAILABLE) { // shouldn't happen. ALOGW("suspend: frame was not available"); break; } else if (err != OK) { ALOGW("suspend: acquireBuffer returned err=%d", err); break; } ++mNumBufferAcquired; --mNumFramesAvailable; releaseBuffer(item.mBuf, item.mFrameNumber, item.mGraphicBuffer, item.mFence); } return; } mSuspended = false; if (mExecuting && mNumFramesAvailable == 0 && mRepeatBufferDeferred) { if (repeatLatestBuffer_l()) { ALOGV("suspend/deferred repeatLatestBuffer_l SUCCESS"); mRepeatBufferDeferred = false; } else { ALOGV("suspend/deferred repeatLatestBuffer_l FAILURE"); } } }