/** {@inheritDoc} */ @Override public void close(final CameraSession session) { final Session s = (Session) session; try { lock.acquire(); if (s.captureSession != null) { closeLatch = new CountDownLatch(1); s.captureSession.close(); closeLatch.await(2, TimeUnit.SECONDS); s.captureSession = null; } if (s.cameraDevice != null) { s.cameraDevice.close(); s.cameraDevice = null; } if (s.reader != null) { s.reader.close(); } Descriptor camera = (Descriptor) session.getDescriptor(); camera.setDevice(null); getBus().post(new ClosedEvent()); } catch (Exception e) { getBus().post(new ClosedEvent(e)); } finally { lock.release(); } }
@Override public void onOpened(CameraDevice cameraDevice) { lock.release(); s.cameraDevice = cameraDevice; s.reader = s.buildImageReader(); Descriptor camera = (Descriptor) s.getDescriptor(); camera.setDevice(cameraDevice); try { cameraDevice.createCaptureSession( Arrays.asList(surface, s.reader.getSurface()), new StartPreviewTransaction(s, surface), handler); } catch (CameraAccessException e) { getBus().post(new OpenedEvent(e)); } }