Commit | Line | Data |
---|---|---|
e59e98fc TW |
1 | package kaka.cakelight; |
2 | ||
3 | import java.io.*; | |
4 | ||
5 | public class FrameGrabber { | |
6 | private Configuration config; | |
7 | private File file; | |
8 | private int bytesPerFrame; | |
9 | private InputStream fileStream; | |
10 | ||
11 | private FrameGrabber() { | |
12 | } | |
13 | ||
14 | public static FrameGrabber from(Configuration config) { | |
15 | FrameGrabber fg = new FrameGrabber(); | |
16 | fg.config = config; | |
17 | fg.file = new File(config.video.device); | |
18 | fg.bytesPerFrame = config.video.width * config.video.height * config.video.bpp; | |
19 | return fg; | |
20 | } | |
21 | ||
22 | public boolean prepare() { | |
23 | try { | |
24 | fileStream = new FileInputStream(file); | |
25 | return true; | |
26 | } catch (FileNotFoundException e) { | |
27 | e.printStackTrace(); | |
28 | return false; | |
29 | } | |
30 | } | |
31 | ||
32 | public Frame grabFrame() { | |
33 | try { | |
34 | byte[] data = new byte[bytesPerFrame]; | |
35 | int count = fileStream.read(data); | |
36 | System.out.println("count = " + count); | |
37 | return Frame.of(data, config); | |
38 | } catch (IOException e) { | |
39 | e.printStackTrace(); | |
40 | } | |
41 | ||
42 | return null; | |
43 | } | |
44 | ||
45 | public void close() { | |
46 | try { | |
47 | fileStream.close(); | |
48 | } catch (IOException e) { | |
49 | e.printStackTrace(); | |
50 | } | |
51 | } | |
52 | } |