Skip to content

Commit 3b22efd

Browse files
committed
Merge pull request OpenKinect#383 from OpenKinect/win32
win32: Core project compiles with VS 2012 and gcc-4.7.3
2 parents ee162e2 + 3f21441 commit 3b22efd

File tree

10 files changed

+95
-69
lines changed

10 files changed

+95
-69
lines changed

CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ if(BUILD_AUDIO)
8787
endif()
8888

8989
if (WIN32)
90-
set(MATH_LIB "")
90+
set(MATH_LIB "")
9191
else(WIN32)
9292
set(MATH_LIB "m")
9393
endif()
@@ -130,7 +130,6 @@ include_directories(${LIBUSB_1_INCLUDE_DIRS})
130130

131131
if(WIN32)
132132
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/platform/windows")
133-
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/platform/windows/libusb10emu/libusb-1.0")
134133
endif()
135134

136135
# Add library project

fakenect/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ install (TARGETS fakenect
1414
DESTINATION "${PROJECT_LIBRARY_INSTALL_DIR}/fakenect")
1515

1616
add_executable(fakenect-record record.c)
17-
target_link_libraries(fakenect-record freenect m)
17+
target_link_libraries(fakenect-record freenect ${MATH_LIB})
1818
install (TARGETS fakenect-record
1919
DESTINATION bin)
2020

fakenect/fakenect.c

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,13 @@
2424
*/
2525

2626
#include "libfreenect.h"
27+
#include "platform.h"
2728
#include <stdio.h>
2829
#include <string.h>
2930
#include <stdlib.h>
3031
#include <math.h>
3132
#include <unistd.h>
32-
#include <time.h>
3333
#include <assert.h>
34-
#ifdef _WIN32
35-
#include <windows.h>
36-
#endif
3734

3835
#define GRAVITY 9.80665
3936

@@ -45,7 +42,7 @@ static freenect_depth_cb cur_depth_cb = NULL;
4542
static freenect_video_cb cur_rgb_cb = NULL;
4643
static char *input_path = NULL;
4744
static FILE *index_fp = NULL;
48-
static freenect_raw_tilt_state state = {};
45+
static freenect_raw_tilt_state state = { 0 };
4946
static int already_warned = 0;
5047
static double playback_prev_time = 0.;
5148
static double record_prev_time = 0.;
@@ -55,45 +52,6 @@ static int depth_running = 0;
5552
static int rgb_running = 0;
5653
static void *user_ptr = NULL;
5754

58-
static void sleep_highres(double tm)
59-
{
60-
#ifdef _WIN32
61-
int msec = floor(tm * 1000);
62-
if (msec > 0) {
63-
Sleep(msec);
64-
}
65-
#else
66-
int sec = floor(tm);
67-
int usec = (tm - sec) * 1000000;
68-
if (tm > 0) {
69-
sleep(sec);
70-
usleep(usec);
71-
}
72-
#endif
73-
}
74-
75-
static double get_time()
76-
{
77-
#ifdef _WIN32
78-
SYSTEMTIME st;
79-
GetSystemTime(&st);
80-
FILETIME ft;
81-
SystemTimeToFileTime(&st, &ft);
82-
ULARGE_INTEGER li;
83-
li.LowPart = ft.dwLowDateTime;
84-
li.HighPart = ft.dwHighDateTime;
85-
// FILETIME is given as a 64-bit value for the number of 100-nanosecond
86-
// intervals that have passed since Jan 1, 1601 (UTC). The difference between that
87-
// epoch and the POSIX epoch (Jan 1, 1970) is 116444736000000000 such ticks.
88-
uint64_t total_usecs = (li.QuadPart - 116444736000000000L) / 10L;
89-
return (total_usecs / 1000000.);
90-
#else
91-
struct timeval cur;
92-
gettimeofday(&cur, NULL);
93-
return cur.tv_sec + cur.tv_usec / 1000000.;
94-
#endif
95-
}
96-
9755
static char *one_line(FILE *fp)
9856
{
9957
int c;

fakenect/platform.h

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* This file is part of the OpenKinect Project. http://www.openkinect.org
3+
*
4+
* Copyright (c) 2010 Brandyn White ([email protected])
5+
*
6+
* This code is licensed to you under the terms of the Apache License, version
7+
* 2.0, or, at your option, the terms of the GNU General Public License,
8+
* version 2.0. See the APACHE20 and GPL2 files for the text of the licenses,
9+
* or the following URLs:
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* http://www.gnu.org/licenses/gpl-2.0.txt
12+
*
13+
* If you redistribute this file in source form, modified or unmodified, you
14+
* may:
15+
* 1) Leave this header intact and distribute it under the same terms,
16+
* accompanying it with the APACHE20 and GPL20 files, or
17+
* 2) Delete the Apache 2.0 clause and accompany it with the GPL2 file, or
18+
* 3) Delete the GPL v2 clause and accompany it with the APACHE20 file
19+
* In all cases you must keep the copyright notice intact and include a copy
20+
* of the CONTRIB file.
21+
*
22+
* Binary distributions must follow the binary distribution requirements of
23+
* either License.
24+
*/
25+
#pragma once
26+
27+
#include <math.h>
28+
#ifdef _WIN32
29+
#include <direct.h>
30+
#include <windows.h>
31+
#define snprintf _snprintf
32+
#define popen _popen
33+
#else
34+
#include <time.h>
35+
#include <unistd.h>
36+
#endif
37+
38+
39+
double get_time()
40+
{
41+
#ifdef _WIN32
42+
SYSTEMTIME st;
43+
GetSystemTime(&st);
44+
FILETIME ft;
45+
SystemTimeToFileTime(&st, &ft);
46+
ULARGE_INTEGER li;
47+
li.LowPart = ft.dwLowDateTime;
48+
li.HighPart = ft.dwHighDateTime;
49+
// FILETIME is given as a 64-bit value for the number of 100-nanosecond
50+
// intervals that have passed since Jan 1, 1601 (UTC). The difference between that
51+
// epoch and the POSIX epoch (Jan 1, 1970) is 116444736000000000 such ticks.
52+
uint64_t total_usecs = (li.QuadPart - 116444736000000000L) / 10L;
53+
return (total_usecs / 1000000.);
54+
#else
55+
struct timeval cur;
56+
gettimeofday(&cur, NULL);
57+
return cur.tv_sec + cur.tv_usec / 1000000.;
58+
#endif
59+
}
60+
61+
void sleep_highres(double tm)
62+
{
63+
#ifdef _WIN32
64+
int msec = floor(tm * 1000);
65+
if (msec > 0) {
66+
Sleep(msec);
67+
}
68+
#else
69+
int sec = floor(tm);
70+
int usec = (tm - sec) * 1000000;
71+
if (tm > 0) {
72+
sleep(sec);
73+
usleep(usec);
74+
}
75+
#endif
76+
}

fakenect/record.c

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424
*/
2525

2626
#include "libfreenect.h"
27+
#include "platform.h"
2728
#include <sys/stat.h>
2829
#include <sys/types.h>
2930
#include <stdio.h>
3031
#include <signal.h>
3132
#include <string.h>
3233
#include <stdlib.h>
33-
#include <sys/time.h>
3434

3535
char *out_dir=0;
3636
volatile sig_atomic_t running = 1;
@@ -48,13 +48,6 @@ char *rgb_name = 0;
4848
FILE *depth_stream=0;
4949
FILE *rgb_stream=0;
5050

51-
double get_time()
52-
{
53-
struct timeval cur;
54-
gettimeofday(&cur, NULL);
55-
return cur.tv_sec + cur.tv_usec / 1000000.;
56-
}
57-
5851
void dump_depth(FILE *fp, void *data, int data_size)
5952
{
6053
fprintf(fp, "P5 %d %d 65535\n", FREENECT_FRAME_W, FREENECT_FRAME_H);
@@ -140,20 +133,21 @@ void dump_ffmpeg_24(FILE *stream, uint32_t timestamp, void *data,
140133
void dump_ffmpeg_pad16(FILE *stream, uint32_t timestamp, void *data,
141134
int data_size)
142135
{
143-
unsigned int z=0;
144-
void *end = data + data_size;
145-
while (data < end) {
146-
z = *(unsigned short*)data;
136+
unsigned int z = 0;
137+
uint16_t* data_ptr = (uint16_t*)data;
138+
uint16_t* end = data_ptr + data_size;
139+
while (data_ptr < end) {
140+
z = *data_ptr;
147141
fwrite(((char*)(&z)), 3, 1, stream);
148-
data += 2;
142+
data_ptr += 2;
149143
}
150144
}
151145

152146
void snapshot_accel(freenect_device *dev)
153147
{
148+
freenect_raw_tilt_state* state;
154149
if (!last_timestamp)
155150
return;
156-
freenect_raw_tilt_state* state;
157151
freenect_update_tilt_state(dev);
158152
state = freenect_get_tilt_state(dev);
159153
dump('a', last_timestamp, state, sizeof *state);

platform/windows/unistd.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828

2929
#include <stdint.h>
3030

31-
// MinGW defines _SSIZE_T_ in sys/types.h when it defines ssize_t to be a long.
31+
// MinGW defines _SSIZE_T_DEFINED in sys/types.h when it defines ssize_t to be a long.
3232
// Redefining it causes an error.
3333
// MSVC does not define this.
34-
#ifndef _SSIZE_T_
35-
#define _SSIZE_T_
34+
#ifndef _SSIZE_T_DEFINED
35+
#define _SSIZE_T_DEFINED
3636
typedef long ssize_t;
37-
#endif // _SSIZE_T_
37+
#endif // _SSIZE_T_DEFINED

src/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ include_directories (${CMAKE_CURRENT_SOURCE_DIR})
77
include_directories(${LIBUSB_1_INCLUDE_DIRS})
88
LIST(APPEND SRC core.c tilt.c cameras.c flags.c usb_libusb10.c registration.c keep_alive.c)
99
IF(WIN32)
10-
LIST(APPEND SRC ../platform/windows/libusb10emu/libusb-1.0/libusbemu.cpp ../platform/windows/libusb10emu/libusb-1.0/failguard.cpp)
1110
set_source_files_properties(${SRC} PROPERTIES LANGUAGE CXX)
1211
ENDIF(WIN32)
1312

src/cameras.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ static int freenect_fetch_zero_plane_info(freenect_device *dev)
833833
FN_SPEW("reference_pixel_size: %f\n", dev->registration.zero_plane_info.reference_pixel_size);
834834

835835
// FIXME: OpenNI seems to use a hardcoded value of 2.4 instead of 2.3 as reported by Kinect
836-
dev->registration.zero_plane_info.dcmos_rcmos_dist = 2.4;
836+
dev->registration.zero_plane_info.dcmos_rcmos_dist = 2.4f;
837837

838838
return 0;
839839
}

src/freenect_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ typedef struct {
162162
int frame_size;
163163
int last_pkt_size;
164164
int valid_pkts;
165-
uint lost_pkts;
165+
unsigned int lost_pkts;
166166
int valid_frames;
167167
int variable_length;
168168
uint32_t last_timestamp;

src/usb_libusb10.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ FN_INTERNAL int fnusb_close_subdevices(freenect_device *dev)
585585
return 0;
586586
}
587587

588-
static void iso_callback(struct libusb_transfer *xfer)
588+
static void LIBUSB_CALL iso_callback(struct libusb_transfer *xfer)
589589
{
590590
int i;
591591
fnusb_isoc_stream *strm = (fnusb_isoc_stream*)xfer->user_data;

0 commit comments

Comments
 (0)