Dolda2000 GitWeb
/
kaka
/
cakelight.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Updated the 'under the sea' ambient mode
[kaka/cakelight.git]
/
src
/
kaka
/
cakelight
/
FrameGrabber.java
diff --git
a/src/kaka/cakelight/FrameGrabber.java
b/src/kaka/cakelight/FrameGrabber.java
index
d228b7b
..
92fd50a
100644
(file)
--- a/
src/kaka/cakelight/FrameGrabber.java
+++ b/
src/kaka/cakelight/FrameGrabber.java
@@
-1,8
+1,11
@@
package kaka.cakelight;
import java.io.*;
package kaka.cakelight;
import java.io.*;
+import java.util.Optional;
-public class FrameGrabber {
+import static kaka.cakelight.Main.log;
+
+public class FrameGrabber implements Closeable {
private Configuration config;
private File file;
private int bytesPerFrame;
private Configuration config;
private File file;
private int bytesPerFrame;
@@
-11,15
+14,16
@@
public class FrameGrabber {
private FrameGrabber() {
}
private FrameGrabber() {
}
- public static FrameGrabber from(Configuration config) {
+ public static FrameGrabber from(
File videoDevice,
Configuration config) {
FrameGrabber fg = new FrameGrabber();
fg.config = config;
FrameGrabber fg = new FrameGrabber();
fg.config = config;
- fg.file =
new File(config.video.device)
;
+ fg.file =
videoDevice
;
fg.bytesPerFrame = config.video.width * config.video.height * config.video.bpp;
fg.bytesPerFrame = config.video.width * config.video.height * config.video.bpp;
+ fg.prepare();
return fg;
}
return fg;
}
- p
ublic
boolean prepare() {
+ p
rivate
boolean prepare() {
try {
fileStream = new FileInputStream(file);
return true;
try {
fileStream = new FileInputStream(file);
return true;
@@
-29,24
+33,24
@@
public class FrameGrabber {
}
}
}
}
- public Frame grabFrame() {
+ /**
+ * Must be run in the same thread as {@link #prepare}.
+ */
+ public Optional<Frame> grabFrame() {
try {
byte[] data = new byte[bytesPerFrame];
int count = fileStream.read(data);
try {
byte[] data = new byte[bytesPerFrame];
int count = fileStream.read(data);
-
System.out.println("count
= " + count);
- return
Frame.of(data, config
);
+
log("# of bytes read
= " + count);
+ return
Optional.of(Frame.of(data, config)
);
} catch (IOException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
- return
null
;
+ return
Optional.empty()
;
}
}
- public void close() {
- try {
- fileStream.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
+ @Override
+ public void close() throws IOException {
+ fileStream.close();
}
}
}
}