本文整理汇总了C++中sp::get方法的典型用法代码示例。如果您正苦于以下问题:C++ sp::get方法的具体用法?C++ sp::get怎么用?C++ sp::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sp
的用法示例。
在下文中一共展示了sp::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addFd
int Looper::addFd(int fd, int ident, int events, const sp<LooperCallback>& callback, void* data) {
#if DEBUG_CALLBACKS
ALOGD("%p ~ addFd - fd=%d, ident=%d, events=0x%x, callback=%p, data=%p", this, fd, ident,
events, callback.get(), data);
#endif
if (!callback.get()) {
if (! mAllowNonCallbacks) {
ALOGE("Invalid attempt to set NULL callback but not allowed for this looper.");
return -1;
}
if (ident < 0) {
ALOGE("Invalid attempt to set NULL callback with ident < 0.");
return -1;
}
} else {
ident = POLL_CALLBACK;
}
{ // acquire lock
AutoMutex _l(mLock);
Request request;
request.fd = fd;
request.ident = ident;
request.events = events;
request.seq = mNextRequestSeq++;
request.callback = callback;
request.data = data;
if (mNextRequestSeq == -1) mNextRequestSeq = 0; // reserve sequence number -1
struct epoll_event eventItem;
request.initEventItem(&eventItem);
ssize_t requestIndex = mRequests.indexOfKey(fd);
if (requestIndex < 0) {
int epollResult = epoll_ctl(mEpollFd, EPOLL_CTL_ADD, fd, & eventItem);
if (epollResult < 0) {
ALOGE("Error adding epoll events for fd %d: %s", fd, strerror(errno));
return -1;
}
mRequests.add(fd, request);
} else {
int epollResult = epoll_ctl(mEpollFd, EPOLL_CTL_MOD, fd, & eventItem);
if (epollResult < 0) {
if (errno == ENOENT) {
// Tolerate ENOENT because it means that an older file descriptor was
// closed before its callback was unregistered and meanwhile a new
// file descriptor with the same number has been created and is now
// being registered for the first time. This error may occur naturally
// when a callback has the side-effect of closing the file descriptor
// before returning and unregistering itself. Callback sequence number
// checks further ensure that the race is benign.
//
// Unfortunately due to kernel limitations we need to rebuild the epoll
// set from scratch because it may contain an old file handle that we are
// now unable to remove since its file descriptor is no longer valid.
// No such problem would have occurred if we were using the poll system
// call instead, but that approach carries others disadvantages.
#if DEBUG_CALLBACKS
ALOGD("%p ~ addFd - EPOLL_CTL_MOD failed due to file descriptor "
"being recycled, falling back on EPOLL_CTL_ADD: %s",
this, strerror(errno));
#endif
epollResult = epoll_ctl(mEpollFd, EPOLL_CTL_ADD, fd, & eventItem);
if (epollResult < 0) {
ALOGE("Error modifying or adding epoll events for fd %d: %s",
fd, strerror(errno));
return -1;
}
scheduleEpollRebuildLocked();
} else {
ALOGE("Error modifying epoll events for fd %d: %s", fd, strerror(errno));
return -1;
}
}
mRequests.replaceValueAt(requestIndex, request);
}
} // release lock
return 1;
}
示例2: ReadVideo
bool OmxDecoder::ReadVideo(VideoFrame *aFrame, int64_t aSeekTimeUs)
{
MOZ_ASSERT(aSeekTimeUs >= -1);
if (!mVideoSource.get())
return false;
ReleaseVideoBuffer();
status_t err;
if (aSeekTimeUs != -1) {
MediaSource::ReadOptions options;
options.setSeekTo(aSeekTimeUs);
err = mVideoSource->read(&mVideoBuffer, &options);
} else {
err = mVideoSource->read(&mVideoBuffer);
}
if (err == OK && mVideoBuffer->range_length() > 0) {
int64_t timeUs;
int32_t keyFrame;
if (!mVideoBuffer->meta_data()->findInt64(kKeyTime, &timeUs) ) {
LOG("no frame time");
return false;
}
if (timeUs < 0) {
LOG("frame time %lld must be nonnegative", timeUs);
return false;
}
if (!mVideoBuffer->meta_data()->findInt32(kKeyIsSyncFrame, &keyFrame)) {
keyFrame = 0;
}
char *data = reinterpret_cast<char *>(mVideoBuffer->data()) + mVideoBuffer->range_offset();
size_t length = mVideoBuffer->range_length();
if (!ToVideoFrame(aFrame, timeUs, data, length, keyFrame)) {
return false;
}
}
else if (err == INFO_FORMAT_CHANGED) {
// If the format changed, update our cached info.
LOG("mVideoSource INFO_FORMAT_CHANGED");
if (!SetVideoFormat())
return false;
else
return ReadVideo(aFrame, aSeekTimeUs);
}
else if (err == ERROR_END_OF_STREAM) {
LOG("mVideoSource END_OF_STREAM");
}
else if (err != OK) {
LOG("mVideoSource ERROR %#x", err);
}
return err == OK;
}
示例3: lock
// set the ISurface that the preview will use
status_t CameraService::Client::setPreviewDisplay(const sp<ISurface>& surface) {
LOG1("setPreviewDisplay(%p) (pid %d)", surface.get(), getCallingPid());
Mutex::Autolock lock(mLock);
status_t result = checkPidAndHardware();
if (result != NO_ERROR) return result;
result = NO_ERROR;
// return if no change in surface.
// asBinder() is safe on NULL (returns NULL)
if (surface->asBinder() == mSurface->asBinder()) {
return result;
}
if (mSurface != 0) {
LOG1("clearing old preview surface %p", mSurface.get());
if (mUseOverlay) {
// Force the destruction of any previous overlay
sp<Overlay> dummy;
mHardware->setOverlay(dummy);
mOverlayRef = 0;
} else {
mSurface->unregisterBuffers();
}
}
mSurface = surface;
mOverlayRef = 0;
// If preview has been already started, set overlay or register preview
// buffers now.
#ifdef USE_OVERLAY_FORMAT_YCbCr_420_SP
if (mHardware->previewEnabled() || mUseOverlay) {
#else
if (mHardware->previewEnabled()) {
#endif
if (mUseOverlay) {
#ifdef USE_OVERLAY_FORMAT_YCbCr_420_SP
if (mSurface != NULL) {
#endif
result = setOverlay();
#ifdef USE_OVERLAY_FORMAT_YCbCr_420_SP
}
#endif
} else if (mSurface != 0) {
result = registerPreviewBuffers();
}
}
return result;
}
status_t CameraService::Client::registerPreviewBuffers() {
int w, h;
CameraParameters params(mHardware->getParameters());
params.getPreviewSize(&w, &h);
//for 720p recording , preview can be 800X448
if(w == preview_sizes[0].width && h== preview_sizes[0].height){
LOGD("registerpreviewbufs :changing dimensions to 768X432 for 720p recording.");
w = preview_sizes[1].width;
h = preview_sizes[1].height;
}
// FIXME: don't use a hardcoded format here.
ISurface::BufferHeap buffers(w, h, w, h,
HAL_PIXEL_FORMAT_YCrCb_420_SP,
mOrientation,
0,
mHardware->getPreviewHeap());
status_t result = mSurface->registerBuffers(buffers);
if (result != NO_ERROR) {
LOGE("registerBuffers failed with status %d", result);
}
return result;
}
status_t CameraService::Client::setOverlay() {
int w, h;
CameraParameters params(mHardware->getParameters());
params.getPreviewSize(&w, &h);
//for 720p recording , preview can be 800X448
if(w == preview_sizes[0].width && h==preview_sizes[0].height){
LOGD("Changing overlay dimensions to 768X432 for 720p recording.");
w = preview_sizes[1].width;
h = preview_sizes[1].height;
}
if (w != mOverlayW || h != mOverlayH || mOrientationChanged) {
// Force the destruction of any previous overlay
sp<Overlay> dummy;
mHardware->setOverlay(dummy);
mOverlayRef = 0;
#ifdef USE_OVERLAY_FORMAT_YCbCr_420_SP
if (mOverlay != NULL) {
mOverlay->destroy();
}
#endif
mOrientationChanged = false;
//.........这里部分代码省略.........
示例4: registerStream
int Merge::registerStream(const sp<OutStream>& stream)
{
if (stream == NULL) {
ALOGE("Merge: stream is invalid, cannot register");
return -EINVAL;
}
const PcmParams ¶ms = stream->getParams();
const SlotMap &map = stream->getSlotMap();
ALOGV("Merge: register stream %p src 0x%04x dst 0x%04x",
stream.get(), map.getSrcMask(), map.getDstMask());
if (params.sampleBits != mParams.sampleBits) {
ALOGE("Merge: stream has incompatible sample size");
return -EINVAL;
}
if (!stream->canResample() && (params.sampleRate != mParams.sampleRate)) {
ALOGE("Merge: stream has incompatible sample rate");
return -EINVAL;
}
if (!stream->canResample() && (params.frameCount != mParams.frameCount)) {
ALOGE("Merge: stream has incompatible frame count");
return -EINVAL;
}
/*
* sanity check that defined dest channels fall within the defined number
* of channels for the output
*/
if (map.getDstMask() >= (1U << mParams.channels)) {
ALOGE("Merge: stream's dest mask 0x%x requests channels not present in"
" the output (%u channel output)",
map.getDstMask(), mParams.channels);
return -EINVAL;
}
AutoMutex lock(mLock);
/* check if dst channels overlap with already registered dst channels */
if (map.getDstMask() & mDstMask) {
ALOGE("Merge: stream's dst mask overlaps already registered streams");
return -EINVAL;
}
if (mStreams.find(stream) != mStreams.end()) {
ALOGE("Merge: stream is already registered");
return -EINVAL;
}
if (mStreams.size() == mParams.channels) {
ALOGE("Merge: max number of streams registered");
return -ENOMEM;
}
mStreams.insert(stream);
mDstMask |= map.getDstMask();
return 0;
}
示例5: GetOMX
static sp<IOMX> GetOMX() {
if(sOMX.get() == NULL) {
sOMX = reinterpret_cast<IOMX*>(new OMX);
}
return sOMX;
}
示例6: LOGD
JNIEXPORT void JNICALL Java_com_mediatek_ut_SurfaceFlingerTest_disconnect(JNIEnv /**_env*/, jobject /*_this*/, jint id) {
LOGD("disconnect");
utProc->disconnect(id);
LOGI("disconnect, id=%d, utProc=%p", id, utProc.get());
}
示例7: add
void DeathRecipientList::add(const sp<JavaDeathRecipient>& recipient) {
AutoMutex _l(mLock);
LOGDEATH("DRL @ %p : add JDR %p", this, recipient.get());
mList.push_back(recipient);
}
示例8: initialize
void RenderProxy::initialize(const sp<Surface>& surface) {
SETUP_TASK(initialize);
args->context = mContext;
args->surface = surface.get();
post(task);
}
示例9: updateSurface
void RenderProxy::updateSurface(const sp<Surface>& surface) {
SETUP_TASK(updateSurface);
args->context = mContext;
args->surface = surface.get();
postAndWait(task);
}
示例10: ReadVideo
bool OmxDecoder::ReadVideo(VideoFrame *aFrame, int64_t aSeekTimeUs)
{
if (!mVideoSource.get())
return false;
for (;;) {
ReleaseVideoBuffer();
status_t err;
if (aSeekTimeUs != -1) {
MediaSource::ReadOptions options;
options.setSeekTo(aSeekTimeUs);
err = mVideoSource->read(&mVideoBuffer, &options);
} else {
err = mVideoSource->read(&mVideoBuffer);
}
aSeekTimeUs = -1;
if (err == OK) {
if (mVideoBuffer->range_length() == 0) // If we get a spurious empty buffer, keep going
continue;
int64_t timeUs;
int32_t unreadable;
int32_t keyFrame;
if (!mVideoBuffer->meta_data()->findInt64(kKeyTime, &timeUs) ) {
LOG("no key time");
return false;
}
if (!mVideoBuffer->meta_data()->findInt32(kKeyIsSyncFrame, &keyFrame)) {
keyFrame = 0;
}
if (!mVideoBuffer->meta_data()->findInt32(kKeyIsUnreadable, &unreadable)) {
unreadable = 0;
}
LOG("data: %p size: %u offset: %u length: %u unreadable: %d",
mVideoBuffer->data(),
mVideoBuffer->size(),
mVideoBuffer->range_offset(),
mVideoBuffer->range_length(),
unreadable);
char *data = reinterpret_cast<char *>(mVideoBuffer->data()) + mVideoBuffer->range_offset();
size_t length = mVideoBuffer->range_length();
if (unreadable) {
LOG("video frame is unreadable");
}
if (!ToVideoFrame(aFrame, timeUs, data, length, keyFrame)) {
return false;
}
return true;
}
if (err == INFO_FORMAT_CHANGED) {
// If the format changed, update our cached info.
if (!SetVideoFormat()) {
return false;
}
// Ok, try to read a buffer again.
continue;
}
/* err == ERROR_END_OF_STREAM */
break;
}
return false;
}
示例11: listener
status_t Camera3StreamSplitter::addOutputLocked(const sp<Surface>& outputQueue) {
ATRACE_CALL();
if (outputQueue == nullptr) {
SP_LOGE("addOutput: outputQueue must not be NULL");
return BAD_VALUE;
}
sp<IGraphicBufferProducer> gbp = outputQueue->getIGraphicBufferProducer();
// Connect to the buffer producer
sp<OutputListener> listener(new OutputListener(this, gbp));
IInterface::asBinder(gbp)->linkToDeath(listener);
status_t res = outputQueue->connect(NATIVE_WINDOW_API_CAMERA, listener);
if (res != NO_ERROR) {
SP_LOGE("addOutput: failed to connect (%d)", res);
return res;
}
// Query consumer side buffer count, and update overall buffer count
int maxConsumerBuffers = 0;
res = static_cast<ANativeWindow*>(outputQueue.get())->query(
outputQueue.get(),
NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS, &maxConsumerBuffers);
if (res != OK) {
SP_LOGE("%s: Unable to query consumer undequeued buffer count"
" for surface", __FUNCTION__);
return res;
}
SP_LOGV("%s: Consumer wants %d buffers, Producer wants %zu", __FUNCTION__,
maxConsumerBuffers, mMaxHalBuffers);
size_t totalBufferCount = maxConsumerBuffers + mMaxHalBuffers;
res = native_window_set_buffer_count(outputQueue.get(),
totalBufferCount);
if (res != OK) {
SP_LOGE("%s: Unable to set buffer count for surface %p",
__FUNCTION__, outputQueue.get());
return res;
}
// Set dequeueBuffer/attachBuffer timeout if the consumer is not hw composer or hw texture.
// We need skip these cases as timeout will disable the non-blocking (async) mode.
uint64_t usage = 0;
res = native_window_get_consumer_usage(static_cast<ANativeWindow*>(outputQueue.get()), &usage);
if (!(usage & (GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_TEXTURE))) {
outputQueue->setDequeueTimeout(kDequeueBufferTimeout);
}
res = gbp->allowAllocation(false);
if (res != OK) {
SP_LOGE("%s: Failed to turn off allocation for outputQueue", __FUNCTION__);
return res;
}
// Add new entry into mOutputs
mOutputs.push_back(gbp);
mNotifiers[gbp] = listener;
mOutputSlots[gbp] = std::make_unique<OutputSlots>(totalBufferCount);
mMaxConsumerBuffers += maxConsumerBuffers;
return NO_ERROR;
}
示例12: Init
bool OmxDecoder::Init() {
//register sniffers, if they are not registered in this process.
DataSource::RegisterDefaultSniffers();
sp<DataSource> dataSource = new MediaStreamSource(mPluginHost, mDecoder);
if (dataSource->initCheck()) {
return false;
}
mPluginHost->SetMetaDataReadMode(mDecoder);
sp<MediaExtractor> extractor = MediaExtractor::Create(dataSource);
if (extractor == NULL) {
return false;
}
sp<MediaSource> videoTrack;
sp<MediaSource> audioTrack;
const char *audioMime = NULL;
bool audioMetaFound = false;
for (size_t i = 0; i < extractor->countTracks(); ++i) {
sp<MetaData> meta = extractor->getTrackMetaData(i);
int32_t bitRate;
if (!meta->findInt32(kKeyBitRate, &bitRate))
bitRate = 0;
const char *mime;
if (!meta->findCString(kKeyMIMEType, &mime)) {
continue;
}
if (videoTrack == NULL && !strncasecmp(mime, "video/", 6)) {
videoTrack = extractor->getTrack(i);
} else if (audioTrack == NULL && !strncasecmp(mime, "audio/", 6)) {
audioTrack = extractor->getTrack(i);
audioMime = mime;
if (!meta->findInt32(kKeyChannelCount, &mAudioChannels) ||
!meta->findInt32(kKeySampleRate, &mAudioSampleRate)) {
return false;
}
audioMetaFound = true;
LOG("channelCount: %d sampleRate: %d",
mAudioChannels, mAudioSampleRate);
}
}
if (videoTrack == NULL && audioTrack == NULL) {
return false;
}
mPluginHost->SetPlaybackReadMode(mDecoder);
int64_t totalDurationUs = 0;
sp<MediaSource> videoSource;
if (videoTrack != NULL) {
videoSource = OMXCodec::Create(GetOMX(),
videoTrack->getFormat(),
false, // decoder
videoTrack,
NULL,
0); // flags (prefer hw codecs)
if (videoSource == NULL) {
return false;
}
if (videoSource->start() != OK) {
return false;
}
int64_t durationUs;
if (videoTrack->getFormat()->findInt64(kKeyDuration, &durationUs)) {
if (durationUs > totalDurationUs)
totalDurationUs = durationUs;
}
}
sp<MediaSource> audioSource;
if (audioTrack != NULL) {
if (!strcasecmp(audioMime, "audio/raw")) {
audioSource = audioTrack;
} else {
audioSource = OMXCodec::Create(GetOMX(),
audioTrack->getFormat(),
false, // decoder
audioTrack);
}
if (audioSource == NULL) {
return false;
}
if (audioSource->start() != OK) {
return false;
}
int64_t durationUs;
if (audioTrack->getFormat()->findInt64(kKeyDuration, &durationUs)) {
if (durationUs > totalDurationUs)
totalDurationUs = durationUs;
//.........这里部分代码省略.........
示例13: GetOMX
static sp<IOMX> GetOMX() {
if(sOMX.get() == NULL) {
sOMX = new OMX;
}
return sOMX;
}
示例14: setVideoSurface
status_t PVPlayer::setVideoSurface(const sp<ISurface>& surface)
{
LOGV("setVideoSurface(%p)", surface.get());
mSurface = surface;
return OK;
}
示例15: equals
bool BaseObj::equals(sp<const BaseObj> obj) {
// Early-out check to see if both BaseObjs are actually the same
if (this == obj.get())
return true;
return mID == obj->mID;
}