1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
import com.robotraconteur.*;
import java.util.*;
import experimental.simplewebcam3.*;
public class WebcamHost_impl extends WebcamHost_default_impl implements WebcamHost
{
public static class Webcam_name
{
public int index;
public String name;
public Webcam_name(int index, String name)
{
this.index = index;
this.name = name;
}
}
HashMap<Integer, Webcam_impl> webcams = new HashMap<Integer, Webcam_impl>();
public WebcamHost_impl(Webcam_name[] names)
{
int camcount = 0;
for (Webcam_name c : names)
{
Webcam_impl w = new Webcam_impl(c.index, c.name);
webcams.put(camcount, w);
camcount++;
try
{
// Throw out first frame to ignore a possible bad frame
w.capture_frame();
}
catch (Exception e)
{}
}
}
public synchronized void shutdown()
{
for (Webcam_impl w : webcams.values())
{
w.shutdown();
}
}
@Override public synchronized Map<Integer, String> get_webcam_names()
{
HashMap<Integer, String> o = new HashMap<Integer, String>();
for (int i : o.keySet())
{
o.put(i, webcams.get(i).get_name());
}
return o;
}
@Override public synchronized Webcam get_webcams(int ind)
{
return webcams.get(ind);
}
}
|