Skip to content

Commit

Permalink
Add resolution and pixel format fields to freenect_frame_mode.
Browse files Browse the repository at this point in the history
This should make it possible to create a "try all supported modes" program
- without this support, freenect_get_video_mode(int) is rather useless,
since we won't know how to interpret the data itself.

This patch breaks binary compatibility (change of size of non-opaque
struct), but no one cares yet, since I don't think anyone's built much
on the new API yet anyway, and it's better to make these changes before
release.

Signed-off-by: Drew Fisher <drew.m.fisher@gmail.com>
  • Loading branch information
zarvox committed Mar 27, 2011
1 parent 435ec19 commit 7cc10f8
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 45 deletions.
4 changes: 2 additions & 2 deletions fakenect/fakenect.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ const freenect_frame_mode freenect_find_video_mode(freenect_resolution res, free
assert(FREENECT_VIDEO_RGB == fmt);
// NOTE: This will leave uninitialized values if new fields are added.
// To update this line run the "record" program, look at the top output
freenect_frame_mode out = {256, 1, 921600, 640, 480, 24, 0, 30};
freenect_frame_mode out = {256, 1, {0}, 1, 921600, 640, 480, 24, 0, 30};
return out;
}

Expand All @@ -278,7 +278,7 @@ const freenect_frame_mode freenect_find_depth_mode(freenect_resolution res, free
assert(FREENECT_DEPTH_11BIT == fmt);
// NOTE: This will leave uninitialized values if new fields are added.
// To update this line run the "record" program, look at the top output
freenect_frame_mode out = {256, 1, 614400, 640, 480, 11, 5, 30};
freenect_frame_mode out = {256, 1, {0}, 1, 614400, 640, 480, 11, 5, 30};
return out;
}

Expand Down
4 changes: 2 additions & 2 deletions fakenect/record.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ void print_mode(const char *name, freenect_frame_mode mode) {
if it becomes a bother for maintainability just comment out the
code in its body. It will only break if struct entries go missing.
*/
printf("%s Mode: {%d, %d, %d, %d, %d, %d, %d, %d}\n", name,
mode.reserved, mode.is_valid, mode.bytes, mode.width,
printf("%s Mode: {%d, %d, %d, %d, %d, %d, %d, %d, %d, %d}\n", name,
mode.reserved, (int)mode.resolution, (int)mode.video_format, mode.is_valid, mode.bytes, mode.width,
mode.height, mode.data_bits_per_pixel, mode.padding_bits_per_pixel,
mode.framerate);
}
Expand Down
51 changes: 28 additions & 23 deletions include/libfreenect.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,6 @@ extern "C" {

#define FREENECT_COUNTS_PER_G 819 /**< Ticks per G for accelerometer as set per http://www.kionix.com/Product%20Sheets/KXSD9%20Product%20Brief.pdf */

/// Structure to give information about the width, height, bitrate,
/// framerate, and buffer size of a frame in a particular mode, as
/// well as the total number of bytes needed to hold a single frame.
typedef struct {
uint32_t reserved; /**< unique ID used internally. The meaning of values may change without notice. Don't touch or depend on the contents of this field. We mean it. */
int is_valid; /**< If 0, this freenect_frame_mode is invalid and does not describe a supported mode. Otherwise, the frame_mode is valid. */
int bytes; /**< Total buffer size in bytes to hold a single frame of data. Should be equivalent to width * height * (data_bits_per_pixel+padding_bits_per_pixel) / 8 */
int width; /**< Width of the frame, in pixels */
int height; /**< Height of the frame, in pixels */
int data_bits_per_pixel; /**< Number of bits of information needed for each pixel */
int padding_bits_per_pixel; /**< Number of bits of padding for alignment used for each pixel */
int framerate; /**< Approximate expected frame rate, in Hz */
} freenect_frame_mode ;

/// Enumeration of available resolutions.
/// Not all available resolutions are actually supported for all video formats.
/// Frame modes may not perfectly match resolutions. For instance,
Expand All @@ -71,6 +57,34 @@ typedef enum {
FREENECT_VIDEO_YUV_RAW = 6, /**< YUV Raw mode */
} freenect_video_format;

/// Enumeration of depth frame states
/// See http://openkinect.org/wiki/Protocol_Documentation#RGB_Camera for more information.
typedef enum {
FREENECT_DEPTH_11BIT = 0, /**< 11 bit depth information in one uint16_t/pixel */
FREENECT_DEPTH_10BIT = 1, /**< 10 bit depth information in one uint16_t/pixel */
FREENECT_DEPTH_11BIT_PACKED = 2, /**< 11 bit packed depth information */
FREENECT_DEPTH_10BIT_PACKED = 3, /**< 10 bit packed depth information */
} freenect_depth_format;

/// Structure to give information about the width, height, bitrate,
/// framerate, and buffer size of a frame in a particular mode, as
/// well as the total number of bytes needed to hold a single frame.
typedef struct {
uint32_t reserved; /**< unique ID used internally. The meaning of values may change without notice. Don't touch or depend on the contents of this field. We mean it. */
freenect_resolution resolution; /**< Resolution this freenect_frame_mode describes, should you want to find it again with freenect_find_*_frame_mode(). */
union {
freenect_video_format video_format;
freenect_depth_format depth_format;
}; /**< The video or depth format that this freenect_frame_mode describes. The caller should know which of video_format or depth_format to use, since they called freenect_get_*_frame_mode() */
int is_valid; /**< If 0, this freenect_frame_mode is invalid and does not describe a supported mode. Otherwise, the frame_mode is valid. */
int bytes; /**< Total buffer size in bytes to hold a single frame of data. Should be equivalent to width * height * (data_bits_per_pixel+padding_bits_per_pixel) / 8 */
int width; /**< Width of the frame, in pixels */
int height; /**< Height of the frame, in pixels */
int data_bits_per_pixel; /**< Number of bits of information needed for each pixel */
int padding_bits_per_pixel; /**< Number of bits of padding for alignment used for each pixel */
int framerate; /**< Approximate expected frame rate, in Hz */
} freenect_frame_mode;

/// Enumeration of LED states
/// See http://openkinect.org/wiki/Protocol_Documentation#Setting_LED for more information.
typedef enum {
Expand All @@ -83,15 +97,6 @@ typedef enum {
LED_BLINK_RED_YELLOW = 6, /**< Make LED blink Red/Yellow */
} freenect_led_options;

/// Enumeration of depth frame states
/// See http://openkinect.org/wiki/Protocol_Documentation#RGB_Camera for more information.
typedef enum {
FREENECT_DEPTH_11BIT = 0, /**< 11 bit depth information in one uint16_t/pixel */
FREENECT_DEPTH_10BIT = 1, /**< 10 bit depth information in one uint16_t/pixel */
FREENECT_DEPTH_11BIT_PACKED = 2, /**< 11 bit packed depth information */
FREENECT_DEPTH_10BIT_PACKED = 3, /**< 10 bit packed depth information */
} freenect_depth_format;


/// Enumeration of tilt motor status
typedef enum {
Expand Down
37 changes: 19 additions & 18 deletions src/cameras.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,35 +37,36 @@

#define video_mode_count 12
freenect_frame_mode supported_video_modes[video_mode_count] = {
// reserved, is_valid, bytes,width, height, data_bits_per_pixel, padding_bits_per_pixel, framerate
{MAKE_RESERVED(FREENECT_RESOLUTION_HIGH, FREENECT_VIDEO_RGB), 1, 1280*1024*3, 1280, 1024, 24, 0, 10 },
{MAKE_RESERVED(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_RGB), 1, 640*480*3, 640, 480, 24, 0, 30 },
// reserved, resolution, format, is_valid, bytes, width, height, data_bits_per_pixel, padding_bits_per_pixel, framerate
{MAKE_RESERVED(FREENECT_RESOLUTION_HIGH, FREENECT_VIDEO_RGB), FREENECT_RESOLUTION_HIGH, {FREENECT_VIDEO_RGB}, 1, 1280*1024*3, 1280, 1024, 24, 0, 10 },
{MAKE_RESERVED(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_RGB), FREENECT_RESOLUTION_MEDIUM, {FREENECT_VIDEO_RGB}, 1, 640*480*3, 640, 480, 24, 0, 30 },

{MAKE_RESERVED(FREENECT_RESOLUTION_HIGH, FREENECT_VIDEO_BAYER), 1, 1280*1024, 1280, 1024, 8, 0, 10 },
{MAKE_RESERVED(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_BAYER), 1, 640*480, 640, 480, 8, 0, 30 },
{MAKE_RESERVED(FREENECT_RESOLUTION_HIGH, FREENECT_VIDEO_BAYER), FREENECT_RESOLUTION_HIGH, {FREENECT_VIDEO_BAYER}, 1, 1280*1024, 1280, 1024, 8, 0, 10 },
{MAKE_RESERVED(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_BAYER), FREENECT_RESOLUTION_MEDIUM, {FREENECT_VIDEO_BAYER}, 1, 640*480, 640, 480, 8, 0, 30 },

{MAKE_RESERVED(FREENECT_RESOLUTION_HIGH, FREENECT_VIDEO_IR_8BIT), 1, 1280*1024, 1280, 1024, 8, 0, 10 },
{MAKE_RESERVED(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_IR_8BIT), 1, 640*488, 640, 488, 8, 0, 30 },
{MAKE_RESERVED(FREENECT_RESOLUTION_HIGH, FREENECT_VIDEO_IR_8BIT), FREENECT_RESOLUTION_HIGH, {FREENECT_VIDEO_IR_8BIT}, 1, 1280*1024, 1280, 1024, 8, 0, 10 },
{MAKE_RESERVED(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_IR_8BIT), FREENECT_RESOLUTION_MEDIUM, {FREENECT_VIDEO_IR_8BIT}, 1, 640*488, 640, 488, 8, 0, 30 },

{MAKE_RESERVED(FREENECT_RESOLUTION_HIGH, FREENECT_VIDEO_IR_10BIT), 1, 1280*1024*2, 1280, 1024, 10, 6, 10 },
{MAKE_RESERVED(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_IR_10BIT), 1, 640*488*2, 640, 488, 10, 6, 30 },
{MAKE_RESERVED(FREENECT_RESOLUTION_HIGH, FREENECT_VIDEO_IR_10BIT), FREENECT_RESOLUTION_HIGH, {FREENECT_VIDEO_IR_10BIT}, 1, 1280*1024*2, 1280, 1024, 10, 6, 10 },
{MAKE_RESERVED(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_IR_10BIT), FREENECT_RESOLUTION_MEDIUM, {FREENECT_VIDEO_IR_10BIT}, 1, 640*488*2, 640, 488, 10, 6, 30 },

{MAKE_RESERVED(FREENECT_RESOLUTION_HIGH, FREENECT_VIDEO_IR_10BIT_PACKED), 1, 1280*1024*10/8, 1280, 1024, 10, 0, 10 },
{MAKE_RESERVED(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_IR_10BIT_PACKED), 1, 640*488*10/8, 640, 488, 10, 0, 30 },
{MAKE_RESERVED(FREENECT_RESOLUTION_HIGH, FREENECT_VIDEO_IR_10BIT_PACKED), FREENECT_RESOLUTION_HIGH, {FREENECT_VIDEO_IR_10BIT_PACKED}, 1, 1280*1024*10/8, 1280, 1024, 10, 0, 10 },
{MAKE_RESERVED(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_IR_10BIT_PACKED), FREENECT_RESOLUTION_MEDIUM, {FREENECT_VIDEO_IR_10BIT_PACKED}, 1, 640*488*10/8, 640, 488, 10, 0, 30 },

{MAKE_RESERVED(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_YUV_RGB), 1, 640*480*3, 640, 480, 24, 0, 15 },
{MAKE_RESERVED(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_YUV_RGB), FREENECT_RESOLUTION_MEDIUM, {FREENECT_VIDEO_YUV_RGB}, 1, 640*480*3, 640, 480, 24, 0, 15 },

{MAKE_RESERVED(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_YUV_RAW), 1, 640*480*2, 640, 480, 16, 0, 15 },
{MAKE_RESERVED(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_YUV_RAW), FREENECT_RESOLUTION_MEDIUM, {FREENECT_VIDEO_YUV_RAW}, 1, 640*480*2, 640, 480, 16, 0, 15 },
};

#define depth_mode_count 4
freenect_frame_mode supported_depth_modes[depth_mode_count] = {
{MAKE_RESERVED(FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_11BIT), 1, 640*480*2, 640, 480, 11, 5, 30},
{MAKE_RESERVED(FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_10BIT), 1, 640*480*2, 640, 480, 11, 5, 30},
{MAKE_RESERVED(FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_11BIT_PACKED), 1, 640*480*11/8, 640, 480, 11, 0, 30},
{MAKE_RESERVED(FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_10BIT_PACKED), 1, 640*480*10/8, 640, 480, 10, 0, 30},
// reserved, resolution, format, is_valid, bytes, width, height, data_bits_per_pixel, padding_bits_per_pixel, framerate
{MAKE_RESERVED(FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_11BIT), FREENECT_RESOLUTION_MEDIUM, {FREENECT_DEPTH_11BIT}, 1, 640*480*2, 640, 480, 11, 5, 30},
{MAKE_RESERVED(FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_10BIT), FREENECT_RESOLUTION_MEDIUM, {FREENECT_DEPTH_10BIT}, 1, 640*480*2, 640, 480, 11, 5, 30},
{MAKE_RESERVED(FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_11BIT_PACKED), FREENECT_RESOLUTION_MEDIUM, {FREENECT_DEPTH_11BIT_PACKED}, 1, 640*480*11/8, 640, 480, 11, 0, 30},
{MAKE_RESERVED(FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_10BIT_PACKED), FREENECT_RESOLUTION_MEDIUM, {FREENECT_DEPTH_10BIT_PACKED}, 1, 640*480*10/8, 640, 480, 10, 0, 30},
};
static const freenect_frame_mode invalid_mode = {0, 0, 0, 0, 0, 0, 0, 0};
static const freenect_frame_mode invalid_mode = {0, 0, {0}, 0, 0, 0, 0, 0, 0, 0};

struct pkt_hdr {
uint8_t magic[2];
Expand Down

0 comments on commit 7cc10f8

Please sign in to comment.