void CameraControlImpl::OnHardwareStateChange(CameraControlListener::HardwareState aNewState, nsresult aReason) { // This callback can run on threads other than the Main Thread and // the Camera Thread. On Gonk, it may be called from the camera's // local binder thread, should the mediaserver process die. MutexAutoLock lock(mListenerLock); if (aNewState == mHardwareState) { DOM_CAMERA_LOGI("OnHardwareStateChange: state did not change from %d\n", mHardwareState); return; } const char* state[] = { "uninitialized", "closed", "open", "failed" }; MOZ_ASSERT(aNewState >= 0); if (static_cast<unsigned int>(aNewState) < sizeof(state) / sizeof(state[0])) { DOM_CAMERA_LOGI("New hardware state is '%s' (reason=0x%x)\n", state[aNewState], aReason); } else { DOM_CAMERA_LOGE("OnHardwareStateChange: got invalid HardwareState value %d\n", aNewState); } mHardwareState = aNewState; mHardwareStateChangeReason = aReason; for (uint32_t i = 0; i < mListeners.Length(); ++i) { CameraControlListener* l = mListeners[i]; l->OnHardwareStateChange(mHardwareState, mHardwareStateChangeReason); } }
void CameraControlImpl::OnClosed() { // This callback can run on threads other than the Main Thread and // the Camera Thread. RwLockAutoEnterRead lock(mListenerLock); for (uint32_t i = 0; i < mListeners.Length(); ++i) { CameraControlListener* l = mListeners[i]; l->OnHardwareStateChange(CameraControlListener::kHardwareClosed); } }
void CameraControlImpl::AddListenerImpl(already_AddRefed<CameraControlListener> aListener) { MutexAutoLock lock(mListenerLock); CameraControlListener* l = *mListeners.AppendElement() = aListener; DOM_CAMERA_LOGI("Added camera control listener %p\n", l); // Update the newly-added listener's state l->OnConfigurationChange(mCurrentConfiguration); l->OnHardwareStateChange(mHardwareState, mHardwareStateChangeReason); l->OnPreviewStateChange(mPreviewState); }