summaryrefslogtreecommitdiff
path: root/src/freenect-server.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/freenect-server.c')
-rw-r--r--src/freenect-server.c44
1 files changed, 17 insertions, 27 deletions
diff --git a/src/freenect-server.c b/src/freenect-server.c
index 94f307c..f6c2016 100644
--- a/src/freenect-server.c
+++ b/src/freenect-server.c
@@ -39,6 +39,8 @@
#include "util.h"
void stop(int sig);
+int exitcode = 0;
+bool running = true;
#define threaderror(stat, errnum, ...) do { \
error(0, errnum, __VA_ARGS__); \
exitcode = stat; \
@@ -66,16 +68,11 @@ struct mpjpg_encoder {
unsigned long jpeg_len;
};
-int exitcode = 0;
-bool running = true;
-FILE *depth_stream = NULL;
-FILE *video_stream = NULL;
-FILE *accel_stream = NULL;
-freenect_context *ctx = NULL;
-freenect_device *dev = NULL;
+/* MPJPEG encoding */
+
struct mpjpg_encoder depth_encoder;
struct mpjpg_encoder video_encoder;
-
+
void mpjpg_init(struct mpjpg_encoder *e) {
e->jpeg_encoder.err = jpeg_std_error(&e->jpeg_encoder_err);
jpeg_create_compress(&e->jpeg_encoder);
@@ -119,6 +116,12 @@ void write_imageframe(const char *name, FILE *stream, struct mpjpg_encoder *e, J
stdioerror(stream, name);
}
+/* Stream handlers */
+
+FILE *depth_stream = NULL;
+FILE *video_stream = NULL;
+FILE *accel_stream = NULL;
+
void handle_accel(freenect_device *dev UNUSED, freenect_raw_tilt_state* data) {
double x, y, z, angle;
freenect_get_mks_accel(data, &x, &y, &z);
@@ -183,6 +186,12 @@ void handle_video(freenect_device *dev, void *rgb, uint32_t timestamp UNUSED) {
write_imageframe("video.mjpg", video_stream, &video_encoder, rgb);
}
+/* Main program lifecycle */
+
+freenect_context *ctx = NULL;
+freenect_device *dev = NULL;
+void cleanup(void);
+
void stop(int sig) {
if (sig != 0)
log("Caught %d", sig);
@@ -190,29 +199,10 @@ void stop(int sig) {
running = false;
}
-FILE *xfopen(const char *path, const char *mode) {
- FILE *stream = fopen(path, mode);
- if (stream == NULL)
- error(EXIT_FAILURE, errno, "fopen: %s", path);
- return stream;
-}
-
-FILE *xfdopen(const char *path, const char *mode) {
- int fd = get_fd(path);
- if (fd < 0)
- error(EXIT_FAILURE, -fd, "get_fd: %s", path);
- FILE *stream = fdopen(fd, mode);
- if (stream == NULL)
- error(EXIT_FAILURE, errno, "fdopen: %s (%d)", path, fd);
- return stream;
-}
-
void usage() {
printf("Usage: %s [-h] [-v video.mjpg|-V video_fd] [-d depth.mjpg|-D depth_fd] [-a accel.mjson|-A accel_fd]\n", program_invocation_name);
}
-void cleanup(void);
-
int main(int argc, char *argv[]) {
int res = 0;