static int out_standby_stream_locked(struct astream_out *out) { int ret = 0; int attempts = MAX_WRITE_COMPLETION_ATTEMPTS; if (out->standby || !out->data) return 0; out->standby = true; /* wait for write completion if needed */ while (out->write_busy && attempts--) { ret = pthread_cond_timeout_np(&out->write_cond, &out->lock, BUF_WRITE_COMPLETION_TIMEOUT_MS); LOGE_IF(ret != 0, "out_standby_stream_locked() wait cond error %d", ret); } LOGE_IF(attempts == 0, "out_standby_stream_locked() a2dp_write() would not stop!!!"); LOGV_IF(!out->bt_enabled, "Standby skip stop: enabled %d", out->bt_enabled); if (out->bt_enabled) { ret = a2dp_stop(out->data); } release_wake_lock(A2DP_WAKE_LOCK_NAME); return ret; }
bool OverlayImpl<P0, P1, P2>::reconfigure(const utils::ReconfArgs& args) { OVASSERT(mPipe0 && mPipe1 && mPipe2, "%s: Pipes are null p0=%p p1=%p p2=%p", __FUNCTION__, mPipe0, mPipe1, mPipe2); switch(args.reconf) { case utils::RECONFIG_ON: { LOGE_IF(DEBUG_OVERLAY, "%s reconfig is on", __FUNCTION__); // reconfig the buffers here utils::PlayInfo play; if(!mReconf.setupBuf(args, play)) { LOGE("%s failed to reconf setupargs", __FUNCTION__); return false; } // regular setXXX interface calls here utils::ReconfArgs reargs(args); reargs.play = play; utils::PipeArgs parg0(mPipe0->getArgs()); parg0 = reargs; utils::PipeArgs parg1(mPipe1->getArgs()); parg1 = reargs; utils::PipeArgs parg2(mPipe2->getArgs()); parg2 = reargs; utils::PipeArgs pargs[utils::MAX_PIPES] = {parg0, parg1, parg2}; if(!this->setSource(pargs)) { LOGE("%s failed to setCrop", __FUNCTION__); return false; } if(!this->setCrop(reargs.crop)) { LOGE("%s failed to setCrop", __FUNCTION__); return false; } if(!this->setPosition(reargs.pos)) { LOGE("%s failed to setPosition", __FUNCTION__); return false; } utils::Params param(utils::OVERLAY_TRANSFORM, reargs.orientation); if(!this->setParameter(param)) { LOGE("%s failed to setParameter", __FUNCTION__); return false; } if(!this->commit()){ LOGE("%s failed to commit", __FUNCTION__); return false; } break; } case utils::RECONFIG_OFF: LOGE_IF(DEBUG_OVERLAY, "%s reconfig is off", __FUNCTION__); mReconf.reset(); break; default: OVASSERT(false, "%s unknown reconfig state %d", __FUNCTION__, args.reconf); return false; } return true; }
FramebufferNativeWindow::FramebufferNativeWindow() : BASE(), fbDev(0), grDev(0), mUpdateOnDemand(false) { hw_module_t const* module; if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module) == 0) { int stride; int err; err = framebuffer_open(module, &fbDev); LOGE_IF(err, "couldn't open framebuffer HAL (%s)", strerror(-err)); err = gralloc_open(module, &grDev); LOGE_IF(err, "couldn't open gralloc HAL (%s)", strerror(-err)); // bail out if we can't initialize the modules if (!fbDev || !grDev) return; mUpdateOnDemand = (fbDev->setUpdateRect != 0); // initialize the buffer FIFO mNumBuffers = 2; mNumFreeBuffers = 2; mBufferHead = mNumBuffers-1; buffers[0] = new NativeBuffer( fbDev->width, fbDev->height, fbDev->format, GRALLOC_USAGE_HW_FB); buffers[1] = new NativeBuffer( fbDev->width, fbDev->height, fbDev->format, GRALLOC_USAGE_HW_FB); err = grDev->alloc(grDev, fbDev->width, fbDev->height, fbDev->format, GRALLOC_USAGE_HW_FB, &buffers[0]->handle, &buffers[0]->stride); LOGE_IF(err, "fb buffer 0 allocation failed w=%d, h=%d, err=%s", fbDev->width, fbDev->height, strerror(-err)); err = grDev->alloc(grDev, fbDev->width, fbDev->height, fbDev->format, GRALLOC_USAGE_HW_FB, &buffers[1]->handle, &buffers[1]->stride); LOGE_IF(err, "fb buffer 1 allocation failed w=%d, h=%d, err=%s", fbDev->width, fbDev->height, strerror(-err)); const_cast<uint32_t&>(android_native_window_t::flags) = fbDev->flags; const_cast<float&>(android_native_window_t::xdpi) = fbDev->xdpi; const_cast<float&>(android_native_window_t::ydpi) = fbDev->ydpi; const_cast<int&>(android_native_window_t::minSwapInterval) = fbDev->minSwapInterval; const_cast<int&>(android_native_window_t::maxSwapInterval) = fbDev->maxSwapInterval; } else { LOGE("Couldn't get gralloc module"); } android_native_window_t::setSwapInterval = setSwapInterval; android_native_window_t::dequeueBuffer = dequeueBuffer; android_native_window_t::lockBuffer = lockBuffer; android_native_window_t::queueBuffer = queueBuffer; android_native_window_t::query = query; android_native_window_t::perform = perform; }
void SensorService::cleanupConnection(SensorEventConnection* c) { Mutex::Autolock _l(mLock); const wp<SensorEventConnection> connection(c); size_t size = mActiveSensors.size(); LOGD_IF(DEBUG_CONNECTIONS, "%d active sensors", size); for (size_t i=0 ; i<size ; ) { int handle = mActiveSensors.keyAt(i); if (c->hasSensor(handle)) { LOGD_IF(DEBUG_CONNECTIONS, "%i: disabling handle=0x%08x", i, handle); SensorInterface* sensor = mSensorMap.valueFor( handle ); LOGE_IF(!sensor, "mSensorMap[handle=0x%08x] is null!", handle); if (sensor) { sensor->activate(c, false); } } SensorRecord* rec = mActiveSensors.valueAt(i); LOGE_IF(!rec, "mActiveSensors[%d] is null (handle=0x%08x)!", i, handle); LOGD_IF(DEBUG_CONNECTIONS, "removing connection %p for sensor[%d].handle=0x%08x", c, i, handle); if (rec && rec->removeConnection(connection)) { LOGD_IF(DEBUG_CONNECTIONS, "... and it was the last connection"); mActiveSensors.removeItemsAt(i, 1); mActiveVirtualSensors.removeItem(handle); delete rec; size--; } else { i++; } } mActiveConnections.remove(connection); }
void V4L2Camera::Uninit () { int ret; memset(&videoIn->buf,0,sizeof(videoIn->buf)); videoIn->buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; videoIn->buf.memory = V4L2_MEMORY_MMAP; /* Dequeue everything */ int DQcount = nQueued - nDequeued; for (int i = 0; i < DQcount-1; i++) { ret = ioctl(fd, VIDIOC_DQBUF, &videoIn->buf); LOGE_IF(ret < 0, "Uninit: VIDIOC_DQBUF Failed"); } nQueued = 0; nDequeued = 0; /* Unmap buffers */ for (int i = 0; i < NB_BUFFER; i++) if (videoIn->mem[i] != NULL) { ret = munmap(videoIn->mem[i], videoIn->buf.length); LOGE_IF(ret < 0, "Uninit: Unmap failed"); videoIn->mem[i] = NULL; } if (videoIn->tmpBuffer) free(videoIn->tmpBuffer); videoIn->tmpBuffer = NULL; }
int sensors_poll_context_t::pollEvents(sensors_event_t* data, int count) { D("Entered : count = %d", count); int nbEvents = 0; int n = 0; do { // see if we have some leftover from the last poll() for (int i=0 ; count && i<numSensorDrivers ; i++) { SensorBase* const sensor(mSensors[i]); if ((mPollFds[i].revents & POLLIN) || (sensor->hasPendingEvents())) { int nb = sensor->readEvents(data, count); // num of evens received. D("nb = %d.", nb); #if defined(CALIBRATION_SUPPORT) if(i == mma) { data->acceleration.x -= gAccelCaliData[0] * ACCELERATION_RATIO_ANDROID_TO_HW; data->acceleration.y -= gAccelCaliData[1] * ACCELERATION_RATIO_ANDROID_TO_HW; data->acceleration.z -= gAccelCaliData[2] * ACCELERATION_RATIO_ANDROID_TO_HW; } #endif if (nb < count) { // no more data for this sensor mPollFds[i].revents = 0; } count -= nb; nbEvents += nb; data += nb; D("count = %d, nbEvents = %d, data = 0x%p.", count, nbEvents, data); } } if (count) { // we still have some room, so try to see if we can get // some events immediately or just wait if we don't have // anything to return n = poll(mPollFds, numFds, nbEvents ? 0 : -1); if (n<0) { LOGE("poll() failed (%s)", strerror(errno)); return -errno; } if (mPollFds[wake].revents & POLLIN) { char msg; int result = read(mPollFds[wake].fd, &msg, 1); LOGE_IF(result<0, "error reading from wake pipe (%s)", strerror(errno)); LOGE_IF(msg != WAKE_MESSAGE, "unknown message on wake queue (0x%02x)", int(msg)); mPollFds[wake].revents = 0; } } // if we have events and space, go read them D("n =0x%x, count = 0x%x.", n, count); } while (n && count); D("to return : nbEvents = %d", nbEvents); return nbEvents; }
static volatile surface_flinger_cblk_t const * get_cblk() { if (gServerCblk == 0) { sp<ISurfaceComposer> sm(getComposerService()); Mutex::Autolock _l(gLock); if (gServerCblk == 0) { gServerCblkMemory = sm->getCblk(); LOGE_IF(gServerCblkMemory==0, "Can't get server control block"); gServerCblk = (surface_flinger_cblk_t *)gServerCblkMemory->getBase(); LOGE_IF(gServerCblk==0, "Can't get server control block address"); } } return gServerCblk; }
void BpMemoryHeap::assertReallyMapped() const { if (mHeapId == -1) { // remote call without mLock held, worse case scenario, we end up // calling transact() from multiple threads, but that's not a problem, // only mmap below must be in the critical section. Parcel data, reply; data.writeInterfaceToken(IMemoryHeap::getInterfaceDescriptor()); status_t err = remote()->transact(HEAP_ID, data, &reply); int parcel_fd = reply.readFileDescriptor(); ssize_t size = reply.readInt32(); uint32_t flags = reply.readInt32(); LOGE_IF(err, "binder=%p transaction failed fd=%d, size=%ld, err=%d (%s)", asBinder().get(), parcel_fd, size, err, strerror(-err)); int fd = dup( parcel_fd ); LOGE_IF(fd==-1, "cannot dup fd=%d, size=%ld, err=%d (%s)", parcel_fd, size, err, strerror(errno)); int access = PROT_READ; if (!(flags & READ_ONLY)) { access |= PROT_WRITE; } Mutex::Autolock _l(mLock); if (mHeapId == -1) { mRealHeap = true; mBase = mmap(0, size, access, MAP_SHARED, fd, 0); if (mBase == MAP_FAILED) { LOGE("cannot map BpMemoryHeap (binder=%p), size=%ld, fd=%d (%s)", asBinder().get(), size, fd, strerror(errno)); close(fd); } else { if (flags & MAP_ONCE) { //LOGD("pinning heap (binder=%p, size=%d, fd=%d", // asBinder().get(), size, fd); pin_heap(); } mSize = size; mFlags = flags; android_atomic_write(fd, &mHeapId); } } } }
bool OverlayImpl<P0, P1, P2>::openPipe(RotatorBase* rot, utils::eDest dest) { OVASSERT(rot, "%s: OverlayImpl rot is null", __FUNCTION__); OVASSERT(utils::isValidDest(dest), "%s: OverlayImpl invalid dest=%d", __FUNCTION__, dest); // Need to down case rotator to mdp one. // we assume p0/p1/p2/px all use the _same_ underlying mdp structure. // FIXME STATIC_ASSERT here bool ret = true; if (utils::OV_PIPE0 & dest) { OVASSERT(mPipe0, "%s: OverlayImpl pipe0 is null", __FUNCTION__); LOGE_IF(DEBUG_OVERLAY, "Open pipe0"); ret = mPipe0->open(rot); mRotP0 = rot; if(!ret) { LOGE("%s: OverlayImpl pipe0 failed to open", __FUNCTION__); } return ret; } if (utils::OV_PIPE1 & dest) { OVASSERT(mPipe1, "%s: OverlayImpl pipe1 is null", __FUNCTION__); LOGE_IF(DEBUG_OVERLAY, "Open pipe1"); ret = mPipe1->open(rot); mRotP1 = rot; if(!ret) { LOGE("%s: OverlayImpl pipe1 failed to open", __FUNCTION__); } return ret; } if (utils::OV_PIPE2 & dest) { OVASSERT(mPipe2, "%s: OverlayImpl pipe2 is null", __FUNCTION__); LOGE_IF(DEBUG_OVERLAY, "Open pipe2"); ret = mPipe2->open(rot); mRotP2 = rot; if(!ret) { LOGE("%s: OverlayImpl pipe2 failed to open", __FUNCTION__); } return ret; } // Should have returned by here return false; }
int CABL::Notify(uint32_t notification_type) { int32_t ret = 0; LOGD_IF(mDebug, "Starting %s ", __func__); pthread_mutex_lock(&mCABLLock); if (mHistStatus == 0 && (notification_type == NOTIFY_TYPE_BL_UPDATE || notification_type == NOTIFY_TYPE_UPDATE)) { uint32_t level = get_backlight_level(); if (level <= mOEMParams.bl_min_level) { LOGE_IF(mDebug, "New BL level %d lower than min level %u," " Skip this update for calc", level, mOEMParams.bl_min_level); if (mPrevNotify == NOTIFY_TYPE_SUSPEND) ret = -1; goto exit_early; } if (eStatus == CABL_OFF) { pthread_mutex_unlock(&mCABLLock); return ret; } LOGD_IF(mDebug, "Start notification received, start histogram"); ret = startHistogram(); if (0 == ret) { mHistStatus = 1; pthread_cond_signal(&mCABLCond); } } else if (mHistStatus == 1 && (notification_type == NOTIFY_TYPE_SUSPEND || notification_type == NOTIFY_TYPE_NO_UPDATE)) { LOGD_IF(mDebug, "Stop notification received, stop histogram"); if(!stopHistogram(mHistStatus)) mHistStatus = 0; if (notification_type == NOTIFY_TYPE_SUSPEND) abl_reset_history(); } if (notification_type == NOTIFY_TYPE_BL_UPDATE) { if (mRefresher) { mRefresher->Control(1); LOGE_IF(mDebug, "Calling refresh()"); mRefresher->Refresh(1, 16); mRefresher->Control(0); } } exit_early: mPrevNotify = notification_type; pthread_mutex_unlock(&mCABLLock); return ret; }
int SecCamera::setFlashMode(const char* strFlashMode) { _v4l2Params.flash_mode = _v4l2Cam->enumFlashMode(strFlashMode); LOGV("setting flash-mode set to %s...", strFlashMode); switch (_v4l2Params.flash_mode) { case FLASH_MODE_TORCH: return 0; case FLASH_MODE_ON: case FLASH_MODE_AUTO: break; case FLASH_MODE_OFF: default: break; } if (!_isPreviewOn) return 0; int ret = _v4l2Cam->setCtrl(V4L2_CID_CAMERA_FLASH_MODE, _v4l2Params.flash_mode); LOGE_IF(0 > ret, "%s:Failed to set flash-mode, %s!! ret=%d", __func__, strFlashMode, ret); return 0 > ret ? -1 : 0; }
void BootAnimation::onFirstRef() { status_t err = mSession->linkToComposerDeath(this); LOGE_IF(err, "linkToComposerDeath failed (%s) ", strerror(-err)); if (err == NO_ERROR) { run("BootAnimation", PRIORITY_DISPLAY); } }
int SensorBase::open_device() { if (dev_fd<0 && dev_name) { dev_fd = open(dev_name, O_RDONLY); LOGE_IF(dev_fd<0, "Couldn't open %s (%s)", dev_name, strerror(errno)); } return 0; }
status_t QemuClient::doQuery(QemuQuery* query) { /* Make sure that query has been successfuly constructed. */ if (query->mQueryDeliveryStatus != NO_ERROR) { LOGE("%s: Query is invalid", __FUNCTION__); return query->mQueryDeliveryStatus; } LOGQ("Send query '%s'", query->mQuery); /* Send the query. */ status_t res = sendMessage(query->mQuery, strlen(query->mQuery) + 1); if (res == NO_ERROR) { /* Read the response. */ res = receiveMessage(reinterpret_cast<void**>(&query->mReplyBuffer), &query->mReplySize); if (res == NO_ERROR) { LOGQ("Response to query '%s': Status = '%.2s', %d bytes in response", query->mQuery, query->mReplyBuffer, query->mReplySize); } else { LOGE("%s Response to query '%s' has failed: %s", __FUNCTION__, query->mQuery, strerror(res)); } } else { LOGE("%s: Send query '%s' failed: %s", __FUNCTION__, query->mQuery, strerror(res)); } /* Complete the query, and return its completion handling status. */ const status_t res1 = query->completeQuery(res); LOGE_IF(res1 != NO_ERROR && res1 != res, "%s: Error %d in query '%s' completion", __FUNCTION__, res1, query->mQuery); return res1; }
// only for debugging / logging int FramebufferNativeWindow::getCurrentBufferIndex() const { Mutex::Autolock _l(mutex); LOGE_IF(!grDev, "[RACE] FramebufferNativeWindow::getCurrentBufferIndex"); const int index = mCurrentBufferIndex; return index; }
sensors_poll_context_t::sensors_poll_context_t() { mSensors[light] = new LightSensor(); mPollFds[light].fd = mSensors[light]->getFd(); mPollFds[light].events = POLLIN; mPollFds[light].revents = 0; mSensors[proximity] = new ProximitySensor(); mPollFds[proximity].fd = mSensors[proximity]->getFd(); mPollFds[proximity].events = POLLIN; mPollFds[proximity].revents = 0; mSensors[akm] = new AkmSensor(); mPollFds[akm].fd = mSensors[akm]->getFd(); mPollFds[akm].events = POLLIN; mPollFds[akm].revents = 0; int wakeFds[2]; int result = pipe(wakeFds); LOGE_IF(result<0, "error creating wake pipe (%s)", strerror(errno)); fcntl(wakeFds[0], F_SETFL, O_NONBLOCK); fcntl(wakeFds[1], F_SETFL, O_NONBLOCK); mWritePipeFd = wakeFds[1]; mPollFds[wake].fd = wakeFds[0]; mPollFds[wake].events = POLLIN; mPollFds[wake].revents = 0; }
int gralloc_unregister_buffer(gralloc_module_t const* module, buffer_handle_t handle) { DEBUG_ENTER(); if (private_handle_t::validate(handle) < 0) return -EINVAL; /* * If the buffer has been mapped during a lock operation, it's time * to un-map it. It's an error to be here with a locked buffer. * NOTE: the framebuffer is handled differently and is never unmapped. */ private_handle_t* hnd = (private_handle_t*)handle; LOGE_IF(hnd->lockState & private_handle_t::LOCK_STATE_READ_MASK, "[unregister] handle %p still locked (state=%08x)", hnd, hnd->lockState); // never unmap buffers that were created in this process if (hnd->pid != getpid()) { if (hnd->lockState & private_handle_t::LOCK_STATE_MAPPED) { gralloc_unmap(module, handle); } hnd->base = 0; hnd->lockState = 0; hnd->writeOwner = 0; } DEBUG_LEAVE(); return 0; }
// establish binder interface to service const sp<IMediaPlayerService>& MPlayer::getMediaPlayerService() { MPLAYER_DBG(); // Mutex::Autolock _l(sServiceLock); if (sMediaPlayerService.get() == 0) { sp<IServiceManager> sm = defaultServiceManager(); sp<IBinder> binder; do { binder = sm->getService(String16("media.player")); if (binder != 0) break; LOGW("MediaPlayerService not published, waiting..."); usleep(500000); // 0.5 s } while(true); /* if (sDeathNotifier == NULL) { sDeathNotifier = new DeathNotifier(); } MPLAYER_DBG(); binder->linkToDeath(sDeathNotifier); */ MPLAYER_DBG(); sMediaPlayerService = interface_cast<IMediaPlayerService>(binder); } MPLAYER_DBG(); LOGE_IF(sMediaPlayerService==0, "no MediaPlayerService!?"); MPLAYER_DBG(); return sMediaPlayerService; }
// establish binder interface to MediaPlayerService /*static*/const sp<IMediaPlayerService>& IMediaDeathNotifier::getMediaPlayerService() { ALOGV("getMediaPlayerService"); Mutex::Autolock _l(sServiceLock); if (sMediaPlayerService.get() == 0) { sp<IServiceManager> sm = defaultServiceManager(); sp<IBinder> binder; do { binder = sm->getService(String16("media.player")); if (binder != 0) { break; } ALOGW("Media player service not published, waiting..."); usleep(500000); // 0.5 s } while(true); if (sDeathNotifier == NULL) { sDeathNotifier = new DeathNotifier(); } binder->linkToDeath(sDeathNotifier); sMediaPlayerService = interface_cast<IMediaPlayerService>(binder); } LOGE_IF(sMediaPlayerService == 0, "no media player service!?"); return sMediaPlayerService; }
// establish binder interface to AudioFlinger service const sp<IAudioFlinger>& AudioSystem::get_audio_flinger() { Mutex::Autolock _l(gLock); if (gAudioFlinger.get() == 0) { sp<IServiceManager> sm = defaultServiceManager(); sp<IBinder> binder; do { binder = sm->getService(String16("media.audio_flinger")); if (binder != 0) break; LOGW("AudioFlinger not published, waiting..."); usleep(500000); // 0.5 s } while(true); if (gAudioFlingerClient == NULL) { gAudioFlingerClient = new AudioFlingerClient(); } else { if (gAudioErrorCallback) { gAudioErrorCallback(NO_ERROR); } } binder->linkToDeath(gAudioFlingerClient); gAudioFlinger = interface_cast<IAudioFlinger>(binder); gAudioFlinger->registerClient(gAudioFlingerClient); } LOGE_IF(gAudioFlinger==0, "no AudioFlinger!?"); return gAudioFlinger; }
EGLBoolean eglDestroyImageKHR(EGLDisplay display, EGLImageKHR image) { EGLBoolean ret = EGL_FALSE; LOGV("eglDestroyImageKHR - 1" ); if( EGL_NO_IMAGE_KHR != image ) { EGL_IMAGE_T *img = (EGL_IMAGE_T *)image; LOGV("eglDestroyImageKHR - 2" ); //force a flush glFinish(); //delete the KHR image ret = eglDestroyImageKHR_Int( display, img->v3d_egl_imagekhr ); LOGE_IF( ret == EGL_FALSE, "eglSwapBuffers: eglDestroyImageKHR FAILED" ); //dec the ref // ((native_buffer *)img->abuffer->handle)->decRef(); img->abuffer->common.decRef(&img->abuffer->common); free( img ); } return ret; }
int FramebufferNativeWindow::query(ANativeWindow* window, int what, int* value) { FramebufferNativeWindow* self = getSelf(window); Mutex::Autolock _l(self->mutex); LOGE_IF(!self->grDev, "[RACE] FramebufferNativeWindow::query"); framebuffer_device_t* fb = self->fbDev; if (fb) { switch (what) { case NATIVE_WINDOW_WIDTH: *value = fb->width; return NO_ERROR; case NATIVE_WINDOW_HEIGHT: *value = fb->height; return NO_ERROR; case NATIVE_WINDOW_FORMAT: *value = fb->format; return NO_ERROR; case NATIVE_WINDOW_NUM_BUFFERS: *value = fb->numFramebuffers; return NO_ERROR; } } *value = 0; return BAD_VALUE; }
int FramebufferNativeWindow::queueBuffer(ANativeWindow* window, android_native_buffer_t* buffer) { FramebufferNativeWindow* self = getSelf(window); Mutex::Autolock _l(self->mutex); LOGE_IF(!self->grDev, "[RACE] FramebufferNativeWindow::queueBuffer"); framebuffer_device_t* fb = self->fbDev; if (!fb) return NO_INIT; buffer_handle_t handle = static_cast<NativeBuffer*>(buffer)->handle; const int index = self->mCurrentBufferIndex; GraphicLog& logger(GraphicLog::getInstance()); logger.log(GraphicLog::SF_FB_POST_BEFORE, index); int res = fb->post(fb, handle); logger.log(GraphicLog::SF_FB_POST_AFTER, index); self->front = static_cast<NativeBuffer*>(buffer); self->mNumFreeBuffers++; self->mCondition.broadcast(); return res; }
int AccelSensor::enable(int32_t handle, int en) { int what = -1; switch (handle) { case ID_A: what = Accelerometer; break; } if (uint32_t(what) >= numSensors) return -EINVAL; int newState = en ? 1 : 0; int err = 0; if ((uint32_t(newState)<<what) != (mEnabled & (1<<what))) { uint32_t sensor_type; switch (what) { case Accelerometer: sensor_type = SENSOR_TYPE_ACCELEROMETER; break; } short flags = newState; if (en) err = accel_enable_sensor(sensor_type); else err = accel_disable_sensor(sensor_type); LOGE_IF(err, "Could not change sensor state (%s)", strerror(-err)); if (!err) { mEnabled &= ~(1<<what); mEnabled |= (uint32_t(flags)<<what); } } return err; }
void Layer::reloadTexture(const Region& dirty) { sp<GraphicBuffer> buffer(mBufferManager.getActiveBuffer()); if (buffer == NULL) { // this situation can happen if we ran out of memory for instance. // not much we can do. continue to use whatever texture was bound // to this context. return; } if (mGLExtensions.haveDirectTexture()) { EGLDisplay dpy(mFlinger->graphicPlane(0).getEGLDisplay()); if (mBufferManager.initEglImage(dpy, buffer) != NO_ERROR) { // not sure what we can do here... goto slowpath; } } else { slowpath: GGLSurface t; if (buffer->usage & GRALLOC_USAGE_SW_READ_MASK) { status_t res = buffer->lock(&t, GRALLOC_USAGE_SW_READ_OFTEN); LOGE_IF(res, "error %d (%s) locking buffer %p", res, strerror(res), buffer.get()); if (res == NO_ERROR) { mBufferManager.loadTexture(dirty, t); buffer->unlock(); } } else { // we can't do anything } } }
CompassSensor::CompassSensor(const sensor_platform_config_t *config) : SensorBase(config), mEnabled(0), mInputReader(32), inputDataOverrun(0) { if (mConfig->handle != SENSORS_HANDLE_MAGNETIC_FIELD) E("CompassSensor: Incorrect sensor config"); data_fd = SensorBase::openInputDev(mConfig->name); LOGE_IF(data_fd < 0, "can't open compass input dev"); if (!config->priv_data) mFilterEn = 0; else mFilterEn = ((union sensor_data_t *)config->priv_data)->compass_filter_en; mMagneticEvent.version = sizeof(sensors_event_t); mMagneticEvent.sensor = SENSORS_HANDLE_MAGNETIC_FIELD; mMagneticEvent.type = SENSOR_TYPE_MAGNETIC_FIELD; mMagneticEvent.magnetic.status = SENSOR_STATUS_ACCURACY_LOW; mMagneticEvent.magnetic.x = 0; mMagneticEvent.magnetic.y = 0; mMagneticEvent.magnetic.x = 0; mCalDataFile = -1; }
int terminateBuffer(gralloc_module_t const* module, private_handle_t* hnd) { DEBUG_ENTER(); /* * If the buffer has been mapped during a lock operation, it's time * to un-map it. It's an error to be here with a locked buffer. */ LOGE_IF(hnd->lockState & private_handle_t::LOCK_STATE_READ_MASK, "[terminate] handle %p still locked (state=%08x)", hnd, hnd->lockState); if (hnd->lockState & private_handle_t::LOCK_STATE_MAPPED) { // this buffer was mapped, unmap it now if (hnd->flags & private_handle_t::PRIV_FLAGS_USES_PMEM) { if (hnd->pid != getpid()) { // ... unless it's a "master" pmem buffer, that is a buffer // mapped in the process it's been allocated. // (see gralloc_alloc_buffer()) gralloc_unmap(module, hnd); } } else { gralloc_unmap(module, hnd); } } DEBUG_LEAVE(); return 0; }
int KionixSensor::enable(int32_t handle, int en) { int cmd = en ? KIONIX_IOCTL_ENABLE_OUTPUT : KIONIX_IOCTL_DISABLE_OUTPUT; int newState = en ? 1 : 0; int err = 0; if (newState != mEnabled) { if (!mEnabled) { open_device(); } int flags = newState; err = ioctl(dev_fd, cmd); err = err<0 ? -errno : 0; LOGE_IF(err, "CAPELLA_CM3602_IOCTL_ENABLE failed (%s)", strerror(-err)); if (!err) { mEnabled = newState; if (en) { setInitialState(); } } if (!mEnabled) { close_device(); } } return err; }
int SensorKXTF9::enable(int32_t handle, int en) { int err = 0; int newState = en ? 1 : 0; if(mEnabled == (unsigned)newState) return err; if (!mEnabled) open_device(); err = ioctl(dev_fd, KXTF9_IOCTL_SET_ENABLE, &newState); err = err < 0 ? -errno : 0; LOGE_IF(err, "SensorKXTF9: KXTF9_IOCTL_SET_ENABLE failed (%s)", strerror(-err)); if (!err) { mEnabled = newState; err = setDelay(handle, KXTF9_DEFAULT_DELAY); } if (!mEnabled) close_device(); return err; }
// establish binder interface to AudioFlinger service const sp<IAudioFlinger>& AudioSystem::get_audio_flinger() { Mutex::Autolock _l(gLock); if (gAudioFlinger.get() == 0) { sp<IServiceManager> sm = defaultServiceManager(); sp<IBinder> binder; do { binder = sm->getService(String16("media.audio_flinger")); if (binder != 0) break; LOGW("AudioFlinger not published, waiting..."); usleep(500000); // 0.5 s } while(true); if (gDeathNotifier == NULL) { gDeathNotifier = new DeathNotifier(); } else { if (gAudioErrorCallback) { gAudioErrorCallback(NO_ERROR); } } binder->linkToDeath(gDeathNotifier); gAudioFlinger = interface_cast<IAudioFlinger>(binder); // Cache frequently accessed parameters gOutFrameCount = (int)gAudioFlinger->frameCount(); gOutSamplingRate = (int)gAudioFlinger->sampleRate(); gOutLatency = gAudioFlinger->latency(); } LOGE_IF(gAudioFlinger==0, "no AudioFlinger!?"); return gAudioFlinger; }