Skip to content

Commit

Permalink
Rename *rgb* functions to *video* + internals
Browse files Browse the repository at this point in the history
Since we'll be adding IR support, make it consistent.

Signed-off-by: Hector Martin <[email protected]>

More changes to typenames after merge

Signed-off-by: Kyle Machulis <[email protected]>

Fixed function name

Signed-off-by: Kyle Machulis <[email protected]>
  • Loading branch information
marcan authored and qdot committed Dec 1, 2010
1 parent b0e7440 commit 7ad5499
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 92 deletions.
14 changes: 7 additions & 7 deletions examples/glview.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,14 @@ void depth_cb(freenect_device *dev, void *v_depth, uint32_t timestamp)
pthread_mutex_unlock(&gl_backbuf_mutex);
}

void rgb_cb(freenect_device *dev, freenect_pixel *rgb, uint32_t timestamp)
void rgb_cb(freenect_device *dev, void *rgb, uint32_t timestamp)
{
pthread_mutex_lock(&gl_backbuf_mutex);

// swap buffers
assert (rgb_back == rgb);
rgb_back = rgb_mid;
freenect_set_rgb_buffer(dev, rgb_back);
freenect_set_video_buffer(dev, rgb_back);
rgb_mid = rgb;

got_rgb++;
Expand All @@ -307,13 +307,13 @@ void *freenect_threadfunc(void *arg)
freenect_set_tilt_degs(f_dev,freenect_angle);
freenect_set_led(f_dev,LED_RED);
freenect_set_depth_callback(f_dev, depth_cb);
freenect_set_rgb_callback(f_dev, rgb_cb);
freenect_set_rgb_format(f_dev, FREENECT_VIDEO_RGB);
freenect_set_video_callback(f_dev, rgb_cb);
freenect_set_video_format(f_dev, FREENECT_VIDEO_RGB);
freenect_set_depth_format(f_dev, FREENECT_DEPTH_11BIT);
freenect_set_rgb_buffer(f_dev, rgb_back);
freenect_set_video_buffer(f_dev, rgb_back);

freenect_start_depth(f_dev);
freenect_start_rgb(f_dev);
freenect_start_video(f_dev);

printf("'w'-tilt up, 's'-level, 'x'-tilt down, '0'-'6'-select LED mode\n");

Expand All @@ -330,7 +330,7 @@ void *freenect_threadfunc(void *arg)
printf("\nshutting down streams...\n");

freenect_stop_depth(f_dev);
freenect_stop_rgb(f_dev);
freenect_stop_video(f_dev);

freenect_close_device(f_dev);
freenect_shutdown(f_ctx);
Expand Down
22 changes: 11 additions & 11 deletions fakenect/fakenect.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@
static freenect_device *fake_dev = (freenect_device *)1234;
static freenect_context *fake_ctx = (freenect_context *)5678;
static freenect_depth_cb cur_depth_cb = NULL;
static freenect_rgb_cb cur_rgb_cb = NULL;
static freenect_video_cb cur_rgb_cb = NULL;
static char *input_path = NULL;
static FILE *index_fp = NULL;
static freenect_raw_tilt_state state = {};
static int already_warned = 0;
static double playback_prev_time = 0.;
static double record_prev_time = 0.;
static void *depth_buffer = NULL;
static freenect_pixel *rgb_buffer = NULL;
static void *rgb_buffer = NULL;

static void sleep_highres(double tm) {
int sec = floor(tm);
Expand Down Expand Up @@ -179,17 +179,17 @@ int freenect_process_events(freenect_context *ctx) {
if (cur_depth_cb) {
void *cur_depth = skip_line(data);
if (depth_buffer) {
memcpy(depth_buffer, cur_depth, FREENECT_DEPTH_SIZE);
memcpy(depth_buffer, cur_depth, FREENECT_DEPTH_11BIT_SIZE);
cur_depth = depth_buffer;
}
cur_depth_cb(fake_dev, cur_depth, timestamp);
}
break;
case 'r':
if (cur_rgb_cb) {
freenect_pixel *cur_rgb = (freenect_pixel *)skip_line(data);
void *cur_rgb = skip_line(data);
if (rgb_buffer) {
memcpy(rgb_buffer, cur_rgb, FREENECT_RGB_SIZE);
memcpy(rgb_buffer, cur_rgb, FREENECT_VIDEO_RGB_SIZE);
cur_rgb = rgb_buffer;
}
cur_rgb_cb(fake_dev, cur_rgb, timestamp);
Expand All @@ -200,7 +200,7 @@ int freenect_process_events(freenect_context *ctx) {
memcpy(&state, data, sizeof(state));
} else if (!already_warned) {
already_warned = 1;
printf("\n\nWarning: Accelerometer data has an unexpected size [%d] instead of [%d]. The acceleration and tilt data will be substituted for dummy values. This data was probably made with an older version of record (the upstream interface changes and we have to follow).\n\n", data_size, sizeof state);
printf("\n\nWarning: Accelerometer data has an unexpected size [%d] instead of [%ld]. The acceleration and tilt data will be substituted for dummy values. This data was probably made with an older version of record (the upstream interface changes and we have to follow).\n\n", data_size, sizeof state);
}
break;
}
Expand Down Expand Up @@ -231,7 +231,7 @@ void freenect_set_depth_callback(freenect_device *dev, freenect_depth_cb cb) {
cur_depth_cb = cb;
}

void freenect_set_rgb_callback(freenect_device *dev, freenect_rgb_cb cb) {
void freenect_set_video_callback(freenect_device *dev, freenect_video_cb cb) {
cur_rgb_cb = cb;
}

Expand All @@ -256,7 +256,7 @@ int freenect_set_depth_buffer(freenect_device *dev, void *buf) {
return 0;
}

int freenect_set_rgb_buffer(freenect_device *dev, freenect_pixel *buf) {
int freenect_set_video_buffer(freenect_device *dev, void *buf) {
rgb_buffer = buf;
return 0;
}
Expand All @@ -266,12 +266,12 @@ void freenect_set_log_level(freenect_context *ctx, freenect_loglevel level) {}
void freenect_set_user(freenect_device *dev, void *user) {}
int freenect_shutdown(freenect_context *ctx) {return 0;}
int freenect_close_device(freenect_device *dev) {return 0;}
int freenect_set_rgb_format(freenect_device *dev, freenect_video_format fmt) {return 0;}
int freenect_set_video_format(freenect_device *dev, freenect_video_format fmt) {return 0;}
int freenect_set_depth_format(freenect_device *dev, freenect_depth_format fmt) {return 0;}
int freenect_start_depth(freenect_device *dev) {return 0;}
int freenect_start_rgb(freenect_device *dev) {return 0;}
int freenect_start_video(freenect_device *dev) {return 0;}
int freenect_stop_depth(freenect_device *dev) {return 0;}
int freenect_stop_rgb(freenect_device *dev) {return 0;}
int freenect_stop_video(freenect_device *dev) {return 0;}
int freenect_set_tilt_degs(freenect_device *dev, double angle) {return 0;}
int freenect_set_led(freenect_device *dev, freenect_led_options option) {return 0;}
int freenect_update_tilt_state(freenect_device *dev) {return 0;}
Expand Down
10 changes: 5 additions & 5 deletions fakenect/record.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void depth_cb(freenect_device *dev, void *depth, uint32_t timestamp) {
}


void rgb_cb(freenect_device *dev, freenect_pixel *rgb, uint32_t timestamp) {
void rgb_cb(freenect_device *dev, void *rgb, uint32_t timestamp) {
dump('r', timestamp, rgb, FREENECT_VIDEO_RGB_SIZE);
}

Expand All @@ -131,14 +131,14 @@ void init() {
}
freenect_set_depth_format(dev, FREENECT_DEPTH_11BIT);
freenect_start_depth(dev);
freenect_set_rgb_format(dev, FREENECT_VIDEO_RGB);
freenect_start_rgb(dev);
freenect_set_video_format(dev, FREENECT_VIDEO_RGB);
freenect_start_video(dev);
freenect_set_depth_callback(dev, depth_cb);
freenect_set_rgb_callback(dev, rgb_cb);
freenect_set_video_callback(dev, rgb_cb);
while(running && freenect_process_events(ctx) >= 0)
snapshot_accel(dev);
freenect_stop_depth(dev);
freenect_stop_rgb(dev);
freenect_stop_video(dev);
freenect_close_device(dev);
freenect_shutdown(ctx);
}
Expand Down
13 changes: 6 additions & 7 deletions include/libfreenect.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ extern "C" {

typedef uint16_t freenect_depth;
typedef uint8_t freenect_packed_depth;
typedef uint8_t freenect_pixel;

#define FREENECT_FRAME_W 640
#define FREENECT_FRAME_H 480
Expand Down Expand Up @@ -127,21 +126,21 @@ void freenect_set_user(freenect_device *dev, void *user);
void *freenect_get_user(freenect_device *dev);

typedef void (*freenect_depth_cb)(freenect_device *dev, void *depth, uint32_t timestamp);
typedef void (*freenect_rgb_cb)(freenect_device *dev, freenect_pixel *rgb, uint32_t timestamp);
typedef void (*freenect_video_cb)(freenect_device *dev, void *video, uint32_t timestamp);

void freenect_set_depth_callback(freenect_device *dev, freenect_depth_cb cb);
void freenect_set_rgb_callback(freenect_device *dev, freenect_rgb_cb cb);
void freenect_set_video_callback(freenect_device *dev, freenect_video_cb cb);

int freenect_set_depth_format(freenect_device *dev, freenect_depth_format fmt);
int freenect_set_rgb_format(freenect_device *dev, freenect_video_format fmt);
int freenect_set_video_format(freenect_device *dev, freenect_video_format fmt);

int freenect_set_depth_buffer(freenect_device *dev, void *buf);
int freenect_set_rgb_buffer(freenect_device *dev, freenect_pixel *buf);
int freenect_set_video_buffer(freenect_device *dev, void *buf);

int freenect_start_depth(freenect_device *dev);
int freenect_start_rgb(freenect_device *dev);
int freenect_start_video(freenect_device *dev);
int freenect_stop_depth(freenect_device *dev);
int freenect_stop_rgb(freenect_device *dev);
int freenect_stop_video(freenect_device *dev);

int freenect_update_tilt_state(freenect_device *dev);
freenect_raw_tilt_state* freenect_get_tilt_state(freenect_device *dev);
Expand Down
18 changes: 9 additions & 9 deletions include/libfreenect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,19 @@ namespace Freenect {
FreenectDevice(freenect_context *_ctx, int _index) {
if(freenect_open_device(_ctx, &m_dev, _index) != 0) throw std::runtime_error("Cannot open Kinect");
freenect_set_user(m_dev, this);
freenect_set_rgb_format(m_dev, FREENECT_VIDEO_RGB);
freenect_set_video_format(m_dev, FREENECT_VIDEO_RGB);
freenect_set_depth_format(m_dev, FREENECT_DEPTH_11BIT);
freenect_set_depth_callback(m_dev, freenect_depth_callback);
freenect_set_rgb_callback(m_dev, freenect_rgb_callback);
freenect_set_video_callback(m_dev, freenect_video_callback);
}
~FreenectDevice() {
if(freenect_close_device(m_dev) != 0) throw std::runtime_error("Cannot shutdown Kinect");
}
void startRGB() {
if(freenect_start_rgb(m_dev) != 0) throw std::runtime_error("Cannot start RGB callback");
void startVideo() {
if(freenect_start_video(m_dev) != 0) throw std::runtime_error("Cannot start RGB callback");
}
void stopRGB() {
if(freenect_stop_rgb(m_dev) != 0) throw std::runtime_error("Cannot stop RGB callback");
void stopVideo() {
if(freenect_stop_video(m_dev) != 0) throw std::runtime_error("Cannot stop RGB callback");
}
void startDepth() {
if(freenect_start_depth(m_dev) != 0) throw std::runtime_error("Cannot start depth callback");
Expand All @@ -95,7 +95,7 @@ namespace Freenect {
return FreenectDeviceState(freenect_get_tilt_state(m_dev));
}
// Do not call directly even in child
virtual void RGBCallback(freenect_pixel *rgb, uint32_t timestamp) = 0;
virtual void VideoCallback(void *video, uint32_t timestamp) = 0;
// Do not call directly even in child
virtual void DepthCallback(void *depth, uint32_t timestamp) = 0;
private:
Expand All @@ -104,9 +104,9 @@ namespace Freenect {
FreenectDevice* device = static_cast<FreenectDevice*>(freenect_get_user(dev));
device->DepthCallback(depth, timestamp);
}
static void freenect_rgb_callback(freenect_device *dev, freenect_pixel *rgb, uint32_t timestamp) {
static void freenect_video_callback(freenect_device *dev, void *video, uint32_t timestamp) {
FreenectDevice* device = static_cast<FreenectDevice*>(freenect_get_user(dev));
device->RGBCallback(rgb, timestamp);
device->VideoCallback(video, timestamp);
}
};

Expand Down
Loading

0 comments on commit 7ad5499

Please sign in to comment.