001package com.github.sarxos.webcam.ds.vlcj; 002 003import java.util.ArrayList; 004import java.util.List; 005 006import uk.co.caprica.vlcj.binding.LibVlc; 007import uk.co.caprica.vlcj.medialist.MediaList; 008import uk.co.caprica.vlcj.medialist.MediaListItem; 009import uk.co.caprica.vlcj.player.MediaPlayerFactory; 010import uk.co.caprica.vlcj.player.discoverer.MediaDiscoverer; 011import uk.co.caprica.vlcj.runtime.RuntimeUtil; 012 013import com.github.sarxos.webcam.WebcamDevice; 014import com.github.sarxos.webcam.WebcamDriver; 015import com.sun.jna.Native; 016 017 018/** 019 * NOT STABLE, EXPERIMENTAL STUFF!!! 020 * 021 * Vlcj service discovery works only on Linux, so there is no way (at least for 022 * now) to list capture devices on Windows. 023 * 024 * For Windows dsj library could be used (http://www.humatic.de/htools/dsj.htm) 025 * listing DirectShow filters for all capture devices in system. 026 * 027 * There is service discovery for Linux, but in any case this one could be used 028 * (http://code.google.com/p/v4l4j/) to access the Video4Linux devices. 029 * 030 * MAC OS X can reuse Rococoa (http://code.google.com/p/rococoa/), a Java 031 * binding to the Mac Objective-C object system, could read device details via 032 * the Mac's QTKit library. 033 * 034 * @author Bartosz Firyn (SarXos) 035 */ 036public class VlcjDriver implements WebcamDriver { 037 038 static { 039 Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class); 040 } 041 042 public VlcjDriver() { 043 if (OS.getOS() == OS.WIN) { 044 System.err.println(String.format("WARNING: %s does not support Windows platform", getClass().getSimpleName())); 045 } 046 } 047 048 @Override 049 public List<WebcamDevice> getDevices() { 050 051 MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory(); 052 MediaDiscoverer videoMediaDiscoverer = mediaPlayerFactory.newVideoMediaDiscoverer(); 053 MediaList videoDeviceList = videoMediaDiscoverer.getMediaList(); 054 055 List<WebcamDevice> devices = new ArrayList<WebcamDevice>(); 056 057 List<MediaListItem> videoDevices = videoDeviceList.items(); 058 for (MediaListItem item : videoDevices) { 059 devices.add(new VlcjDevice(item)); 060 } 061 062 videoDeviceList.release(); 063 videoMediaDiscoverer.release(); 064 mediaPlayerFactory.release(); 065 066 return devices; 067 } 068 069 @Override 070 public boolean isThreadSafe() { 071 return false; 072 } 073 074 @Override 075 public String toString() { 076 return getClass().getSimpleName(); 077 } 078}