0

I want to get a constant variable from this static variable.

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

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

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

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

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

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

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

Now I need to write something

const FREENECT_VIDEO_RGB = [ An instance in the type of  freenect_frame_mode ]

How to declare a const var in that format?


The original codes from:

https://github.com/OpenKinect/libfreenect/blob/master/src/cameras.c#L42

And I need to pass a const var freenect_frame_mode into this, and see if it returns -1 or not:

https://github.com/OpenKinect/libfreenect/blob/master/src/cameras.c#L1152

int freenect_set_video_mode(freenect_device* dev, const freenect_frame_mode mode)
{
freenect_context *ctx = dev->parent;
if (dev->video.running) {
    FN_ERROR("Tried to set video mode while stream is active\n");
    return -1;
}
// Verify that the mode passed in is actually in the supported mode list
int found = 0;
int i;
for(i = 0 ; i < video_mode_count; i++) {
    if (supported_video_modes[i].reserved == mode.reserved) {
        found = 1;
        break;
    }
}
if (!found) {
    FN_ERROR("freenect_set_video_mode: freenect_frame_mode provided is invalid\n");
    return -1;
}

freenect_resolution res = RESERVED_TO_RESOLUTION(mode.reserved);
freenect_video_format fmt = (freenect_video_format)RESERVED_TO_FORMAT(mode.reserved);
dev->video_format = fmt;
dev->video_resolution = res;
// Now that we've changed video format and resolution, we need to update
// registration tables.
freenect_fetch_reg_info(dev);
return 0;

}

I am just stuck with using the function now.

Thanks!

1
  • A constant variable is definitelly not variable.... :) What about const static ... ??? Commented Sep 2, 2015 at 10:49

1 Answer 1

3

Well, if you want to get an element of an array, you can use the standard syntax array[index].

const freenect_frame_mode FREENECT_VIDEO_RGB = supported_video_modes[5];

for example.

You need to show more code, i.e. the definitions of these symbols, if you want more info.

Sign up to request clarification or add additional context in comments.

2 Comments

The post was re-edited. I use the codes above it reported: src/input/Freenect.cc:88:27: error: ‘const freenect_frame_mode FREENECT_VIDEO_RGB’ redeclared as different kind of symbol const freenect_frame_mode FREENECT_VIDEO_RGB = supported_video_modes[5];
well. I have fixed this problem. The error I got here is because that the var FREENECT_VIDEO_RGB was declared twice. I renamed the var name, and it works! Thank you, Chris Beck!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.