本文整理汇总了C++中sp::base方法的典型用法代码示例。如果您正苦于以下问题:C++ sp::base方法的具体用法?C++ sp::base怎么用?C++ sp::base使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sp
的用法示例。
在下文中一共展示了sp::base方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: convert
status_t DataConverter::convert(const sp<MediaCodecBuffer> &source, sp<MediaCodecBuffer> &target) {
CHECK(source->base() != target->base());
size_t size = targetSize(source->size());
status_t err = OK;
if (size > target->capacity()) {
ALOGE("data size (%zu) is greater than buffer capacity (%zu)",
size, // this is the data received/to be converted
target->capacity()); // this is out buffer size
err = FAILED_TRANSACTION;
} else {
err = safeConvert(source, target);
}
target->setRange(0, err == OK ? size : 0);
return err;
}
示例2: postPreviewBuffer
/**
* This Callback is used by HAL to return the pointer to a preview frame.
*
* After we have created the Frame struct, we can call the user-defined callback
**/
void CameraAcc::postPreviewBuffer(sp<IMemoryHeap> heap, uint8_t *heapBase, size_t size, ssize_t offset)
{
LOG2("@%s, heapBase=%p, size=%d", __FUNCTION__, heapBase, size);
int frameCounter = mFrameMetadata->frameCounter;
if (mCallback != NULL)
{
// Create Frame struct
Frame f;
f.img_data = heap->base();
f.id = mFrameMetadata->id;
f.frameCounter = mFrameMetadata->frameCounter;
f.width = mFrameMetadata->width;
f.height = mFrameMetadata->height;
f.format = mFrameMetadata->format;
f.stride = mFrameMetadata->stride;
f.size = mFrameMetadata->size;
// Call callback function
mCallback(&f);
}
// Return buffer
status_t status = mCamera->sendCommand(CAMERA_CMD_ACC_RETURN_BUFFER, frameCounter, 0);
if (status != NO_ERROR)
ALOGE("Could not return buffer");
}
示例3: cache
int CodeCache::cache( const AssemblyKeyBase& keyBase,
const sp<Assembly>& assembly)
{
pthread_mutex_lock(&mLock);
const ssize_t assemblySize = assembly->size();
while (mCacheInUse + assemblySize > mCacheSize) {
// evict the LRU
size_t lru = 0;
size_t count = mCacheData.size();
for (size_t i=0 ; i<count ; i++) {
const cache_entry_t& e = mCacheData.valueAt(i);
if (e.when < mCacheData.valueAt(lru).when) {
lru = i;
}
}
const cache_entry_t& e = mCacheData.valueAt(lru);
mCacheInUse -= e.entry->size();
mCacheData.removeItemsAt(lru);
}
ssize_t err = mCacheData.add(key_t(keyBase), cache_entry_t(assembly, mWhen));
if (err >= 0) {
mCacheInUse += assemblySize;
mWhen++;
// synchronize caches...
char* base = reinterpret_cast<char*>(assembly->base());
char* curr = reinterpret_cast<char*>(base + assembly->size());
__builtin___clear_cache(base, curr);
}
pthread_mutex_unlock(&mLock);
return err;
}
示例4: MemoryBase
SimpleMemory::SimpleMemory(const sp<IMemoryHeap>& heap,
ssize_t offset, size_t size)
: MemoryBase(heap, offset, size)
{
#ifndef NDEBUG
void* const start_ptr = (void*)(intptr_t(heap->base()) + offset);
memset(start_ptr, 0xda, size);
#endif
}
示例5: MemoryBase
Allocation::Allocation(
const sp<MemoryDealer>& dealer,
const sp<IMemoryHeap>& heap, ssize_t offset, size_t size)
: MemoryBase(heap, offset, size), mDealer(dealer)
{
#ifndef NDEBUG
void* const start_ptr = (void*)(intptr_t(heap->base()) + offset);
memset(start_ptr, 0xda, size);
#endif
}
示例6: copyFrameAndPostCopiedFrame
void CameraClient::copyFrameAndPostCopiedFrame(
int32_t msgType, const sp<ICameraClient>& client,
const sp<IMemoryHeap>& heap, size_t offset, size_t size,
camera_frame_metadata_t *metadata) {
LOG2("copyFrameAndPostCopiedFrame");
// It is necessary to copy out of pmem before sending this to
// the callback. For efficiency, reuse the same MemoryHeapBase
// provided it's big enough. Don't allocate the memory or
// perform the copy if there's no callback.
// hold the preview lock while we grab a reference to the preview buffer
sp<MemoryHeapBase> previewBuffer;
if (mPreviewBuffer == 0) {
mPreviewBuffer = new MemoryHeapBase(size, 0, NULL);
} else if (size > mPreviewBuffer->virtualSize()) {
mPreviewBuffer.clear();
mPreviewBuffer = new MemoryHeapBase(size, 0, NULL);
}
if (mPreviewBuffer == 0) {
ALOGE("failed to allocate space for preview buffer");
mLock.unlock();
return;
}
previewBuffer = mPreviewBuffer;
void* previewBufferBase = previewBuffer->base();
void* heapBase = heap->base();
if (heapBase == MAP_FAILED) {
ALOGE("%s: Failed to mmap heap for preview frame.", __FUNCTION__);
mLock.unlock();
return;
} else if (previewBufferBase == MAP_FAILED) {
ALOGE("%s: Failed to mmap preview buffer for preview frame.", __FUNCTION__);
mLock.unlock();
return;
}
memcpy(previewBufferBase, (uint8_t *) heapBase + offset, size);
sp<MemoryBase> frame = new MemoryBase(previewBuffer, 0, size);
if (frame == 0) {
ALOGE("failed to allocate space for frame callback");
mLock.unlock();
return;
}
mLock.unlock();
client->dataCallback(msgType, frame, metadata);
}
示例7: renderAudio
void SimplePlayer::renderAudio(
CodecState *state, BufferInfo *info, const sp<ABuffer> &buffer) {
CHECK(state->mAudioTrack != NULL);
if (state->mAudioTrack->stopped()) {
state->mAudioTrack->start();
}
uint32_t numFramesPlayed;
CHECK_EQ(state->mAudioTrack->getPosition(&numFramesPlayed), (status_t)OK);
uint32_t numFramesAvailableToWrite =
state->mAudioTrack->frameCount()
- (state->mNumFramesWritten - numFramesPlayed);
size_t numBytesAvailableToWrite =
numFramesAvailableToWrite * state->mAudioTrack->frameSize();
size_t copy = info->mSize;
if (copy > numBytesAvailableToWrite) {
copy = numBytesAvailableToWrite;
}
if (copy == 0) {
return;
}
int64_t startTimeUs = ALooper::GetNowUs();
ssize_t nbytes = state->mAudioTrack->write(
buffer->base() + info->mOffset, copy);
CHECK_EQ(nbytes, (ssize_t)copy);
int64_t delayUs = ALooper::GetNowUs() - startTimeUs;
uint32_t numFramesWritten = nbytes / state->mAudioTrack->frameSize();
if (delayUs > 2000ll) {
ALOGW("AudioTrack::write took %lld us, numFramesAvailableToWrite=%u, "
"numFramesWritten=%u",
delayUs, numFramesAvailableToWrite, numFramesWritten);
}
info->mOffset += nbytes;
info->mSize -= nbytes;
state->mNumFramesWritten += numFramesWritten;
}
示例8: cache
int CodeCache::cache( const AssemblyKeyBase& keyBase,
const sp<Assembly>& assembly)
{
pthread_mutex_lock(&mLock);
const ssize_t assemblySize = assembly->size();
while (mCacheInUse + assemblySize > mCacheSize) {
// evict the LRU
size_t lru = 0;
size_t count = mCacheData.size();
for (size_t i=0 ; i<count ; i++) {
const cache_entry_t& e = mCacheData.valueAt(i);
if (e.when < mCacheData.valueAt(lru).when) {
lru = i;
}
}
const cache_entry_t& e = mCacheData.valueAt(lru);
mCacheInUse -= e.entry->size();
mCacheData.removeItemsAt(lru);
}
ssize_t err = mCacheData.add(key_t(keyBase), cache_entry_t(assembly, mWhen));
if (err >= 0) {
mCacheInUse += assemblySize;
mWhen++;
// synchronize caches...
#if defined(__arm__)
const long base = long(assembly->base());
const long curr = base + long(assembly->size());
err = cacheflush(base, curr, 0);
LOGE_IF(err, "__ARM_NR_cacheflush error %s\n",
strerror(errno));
#endif
}
pthread_mutex_unlock(&mLock);
return err;
}
示例9: safeConvert
status_t AudioConverter::safeConvert(const sp<MediaCodecBuffer> &src, sp<MediaCodecBuffer> &tgt) {
if (mTo == kAudioEncodingPcm8bit && mFrom == kAudioEncodingPcm16bit) {
memcpy_to_u8_from_i16((uint8_t*)tgt->base(), (const int16_t*)src->data(), src->size() / 2);
} else if (mTo == kAudioEncodingPcm8bit && mFrom == kAudioEncodingPcmFloat) {
memcpy_to_u8_from_float((uint8_t*)tgt->base(), (const float*)src->data(), src->size() / 4);
} else if (mTo == kAudioEncodingPcm16bit && mFrom == kAudioEncodingPcm8bit) {
memcpy_to_i16_from_u8((int16_t*)tgt->base(), (const uint8_t*)src->data(), src->size());
} else if (mTo == kAudioEncodingPcm16bit && mFrom == kAudioEncodingPcmFloat) {
memcpy_to_i16_from_float((int16_t*)tgt->base(), (const float*)src->data(), src->size() / 4);
} else if (mTo == kAudioEncodingPcmFloat && mFrom == kAudioEncodingPcm8bit) {
memcpy_to_float_from_u8((float*)tgt->base(), (const uint8_t*)src->data(), src->size());
} else if (mTo == kAudioEncodingPcmFloat && mFrom == kAudioEncodingPcm16bit) {
memcpy_to_float_from_i16((float*)tgt->base(), (const int16_t*)src->data(), src->size() / 2);
} else {
return INVALID_OPERATION;
}
return OK;
}
示例10: MemoryHeapBase
void CameraService::Client::copyFrameAndPostCopiedFrame(
const sp<ICameraClient>& client, const sp<IMemoryHeap>& heap,
size_t offset, size_t size) {
LOG2("copyFrameAndPostCopiedFrame");
// It is necessary to copy out of pmem before sending this to
// the callback. For efficiency, reuse the same MemoryHeapBase
// provided it's big enough. Don't allocate the memory or
// perform the copy if there's no callback.
// hold the preview lock while we grab a reference to the preview buffer
sp<MemoryHeapBase> previewBuffer;
if (mPreviewBuffer == 0) {
mPreviewBuffer = new MemoryHeapBase(size, 0, NULL);
} else if (size > mPreviewBuffer->virtualSize()) {
mPreviewBuffer.clear();
mPreviewBuffer = new MemoryHeapBase(size, 0, NULL);
}
if (mPreviewBuffer == 0) {
LOGE("failed to allocate space for preview buffer");
mLock.unlock();
return;
}
previewBuffer = mPreviewBuffer;
memcpy(previewBuffer->base(), (uint8_t *)heap->base() + offset, size);
sp<MemoryBase> frame = new MemoryBase(previewBuffer, 0, size);
if (frame == 0) {
LOGE("failed to allocate space for frame callback");
mLock.unlock();
return;
}
mLock.unlock();
client->dataCallback(CAMERA_MSG_PREVIEW_FRAME, frame);
}