/** * Re-detects all camera devices connected to the system. Returns without performing any action if * a media stream is currently being served. */ public synchronized void updateDeviceList() { if (currentStream != null) { log.error("Attempted to update capture list while serving a stream."); return; } // Store the old list of cameras, and generate a new list to store // cameras detected during this update List<CameraController> oldCameras = cameras; CameraController oldActiveCam = getActiveCamera(); cameras = new ArrayList<CameraController>(); // Detect all connected cameras, and generate a new CameraController // for those which were not present during the last update of the device // list NativeCaptureSystemFactory captureFactory = new NativeCaptureSystemFactory(); try { CaptureSystem captureSystem = captureFactory.createCaptureSystem(); captureSystem.init(); List<com.lti.civil.CaptureDeviceInfo> devices = captureSystem.getCaptureDeviceInfoList(); for (com.lti.civil.CaptureDeviceInfo device : devices) { log.info( "LTI-Civil found device: " + device.getDescription() + " - " + device.getDeviceID()); // Add the previously existing camera controller for the detected // device, or create a new one of no controller is available boolean foundExisting = false; for (CameraController c : oldCameras) { if (c.getDeviceId().equals(device.getDeviceID())) { cameras.add(c); foundExisting = true; break; } } if (!foundExisting) { CameraController newCam = new CameraController(device); cameras.add(newCam); } } if (cameras.isEmpty()) { selectedCamera = null; } else { if (cameras.contains(oldActiveCam)) { setActiveCamera(oldActiveCam); } else { // Note: Defaults to first detected camera if no active // camera was previously selected setActiveCamera(cameras.get(0)); } } } catch (CaptureException e) { e.printStackTrace(); } }
@Override public List<WebcamDevice> getDevices() { initialize(); int i = 0; while (!ready) { try { Thread.sleep(100); } catch (InterruptedException e) { return null; } // wait max 10 seconds for driver to be ready if (i++ > 100) { throw new RuntimeException( "Cannot get devices because capture driver has not become ready for 10 seconds"); } } List<WebcamDevice> devices = new ArrayList<WebcamDevice>(); try { for (Object cdi : system.getCaptureDeviceInfoList()) { devices.add(new LtiCivilDevice((CaptureDeviceInfo) cdi)); } } catch (CaptureException e) { throw new WebcamException(e); } return devices; }
private static void initialize() { if (!INIT.compareAndSet(false, true)) { return; } LtiCivilLoader.load("civil"); factory = DefaultCaptureSystemFactorySingleton.instance(); try { system = factory.createCaptureSystem(); system.init(); ready = true; } catch (UnsatisfiedLinkError e) { // ignore - it is already loaded LOG.debug("Library already loaded"); } catch (CaptureException e) { throw new WebcamException(e); } }