freenect_internal.h
Go to the documentation of this file.
1 /*
2  * This file is part of the OpenKinect Project. http://www.openkinect.org
3  *
4  * Copyright (c) 2010-2011 individual OpenKinect contributors. See the CONTRIB
5  * file for details.
6  *
7  * This code is licensed to you under the terms of the Apache License, version
8  * 2.0, or, at your option, the terms of the GNU General Public License,
9  * version 2.0. See the APACHE20 and GPL2 files for the text of the licenses,
10  * or the following URLs:
11  * http://www.apache.org/licenses/LICENSE-2.0
12  * http://www.gnu.org/licenses/gpl-2.0.txt
13  *
14  * If you redistribute this file in source form, modified or unmodified, you
15  * may:
16  * 1) Leave this header intact and distribute it under the same terms,
17  * accompanying it with the APACHE20 and GPL20 files, or
18  * 2) Delete the Apache 2.0 clause and accompany it with the GPL2 file, or
19  * 3) Delete the GPL v2 clause and accompany it with the APACHE20 file
20  * In all cases you must keep the copyright notice intact and include a copy
21  * of the CONTRIB file.
22  *
23  * Binary distributions must follow the binary distribution requirements of
24  * either License.
25  */
26 #pragma once
27 
28 #include <stdint.h>
29 
30 #include "libfreenect.h"
32 #include "libfreenect_audio.h"
33 
34 #ifdef __ELF__
35  #define FN_INTERNAL __attribute__ ((visibility ("hidden")))
36 #else
37  #define FN_INTERNAL
38 #endif
39 
40 
41 typedef void (*fnusb_iso_cb)(freenect_device *dev, uint8_t *buf, int len);
42 
43 #include "usb_libusb10.h"
44 
45 // needed to set the led state for non 1414 devices
47 
55 
56  // if you want to load firmware from memory rather than disk
57  unsigned char * fn_fw_nui_ptr;
58  unsigned int fn_fw_nui_size;
59 
60  unsigned char * fn_fw_k4w_ptr;
61  unsigned int fn_fw_k4w_size;
62 };
63 
64 #define LL_FATAL FREENECT_LOG_FATAL
65 #define LL_ERROR FREENECT_LOG_ERROR
66 #define LL_WARNING FREENECT_LOG_WARNING
67 #define LL_NOTICE FREENECT_LOG_NOTICE
68 #define LL_INFO FREENECT_LOG_INFO
69 #define LL_DEBUG FREENECT_LOG_DEBUG
70 #define LL_SPEW FREENECT_LOG_SPEW
71 #define LL_FLOOD FREENECT_LOG_FLOOD
72 
73 
74 #ifdef _WIN32
75 #include <stdarg.h>
76 #include <stdio.h>
77 void fn_log(freenect_context *ctx, freenect_loglevel level, const char *fmt, ...);
78 #else
79 void fn_log(freenect_context *ctx, freenect_loglevel level, const char *fmt, ...) __attribute__ ((format (printf, 3, 4)));
80 #endif
81 
82 #define FN_LOG(level, ...) fn_log(ctx, level, __VA_ARGS__)
83 
84 #define FN_FATAL(...) FN_LOG(LL_FATAL, __VA_ARGS__)
85 #define FN_ERROR(...) FN_LOG(LL_ERROR, __VA_ARGS__)
86 #define FN_WARNING(...) FN_LOG(LL_WARNING, __VA_ARGS__)
87 #define FN_NOTICE(...) FN_LOG(LL_NOTICE, __VA_ARGS__)
88 #define FN_INFO(...) FN_LOG(LL_INFO, __VA_ARGS__)
89 #define FN_DEBUG(...) FN_LOG(LL_DEBUG, __VA_ARGS__)
90 #define FN_SPEW(...) FN_LOG(LL_SPEW, __VA_ARGS__)
91 #define FN_FLOOD(...) FN_LOG(LL_FLOOD, __VA_ARGS__)
92 
93 #ifdef FN_BIGENDIAN
94 static inline uint16_t fn_le16(uint16_t d)
95 {
96  return (d<<8) | (d>>8);
97 }
98 static inline uint32_t fn_le32(uint32_t d)
99 {
100  return (d<<24) | ((d<<8)&0xFF0000) | ((d>>8)&0xFF00) | (d>>24);
101 }
102 static inline int16_t fn_le16s(int16_t s)
103 {
104  // reinterpret cast to unsigned, use the normal fn_le16, and then reinterpret cast back
105  union {
106  int16_t s;
107  uint16_t u;
108  } conversion_union;
109  conversion_union.s = s;
110  conversion_union.u = fn_le16(conversion_union.u);
111  return conversion_union.s;
112 }
113 static inline int32_t fn_le32s(int32_t s)
114 {
115  // reinterpret cast to unsigned, use the normal fn_le32, and then reinterpret cast back
116  union {
117  int32_t s;
118  uint32_t u;
119  } conversion_union;
120  conversion_union.s = s;
121  conversion_union.u = fn_le32(conversion_union.u);
122  return conversion_union.s;
123 }
124 #else
125 #define fn_le16(x) (x)
126 #define fn_le32(x) (x)
127 #define fn_le16s(x) (x)
128 #define fn_le32s(x) (x)
129 #endif
130 
131 #define DEPTH_PKTSIZE 1760
132 #define VIDEO_PKTSIZE 1920
133 
134 #define DEPTH_PKTDSIZE (DEPTH_PKTSIZE-12)
135 #define VIDEO_PKTDSIZE (VIDEO_PKTSIZE-12)
136 
137 #define VID_MICROSOFT 0x45e
138 #define PID_NUI_AUDIO 0x02ad
139 #define PID_NUI_CAMERA 0x02ae
140 #define PID_NUI_MOTOR 0x02b0
141 #define PID_K4W_CAMERA 0x02bf
142 
143 // For K4W: first pid is what it starts out as,
144 // second is how it appears with lastest firmware from SDK,
145 // third is from beta SDK firmware ( which is what is unpacked by the fw script and doesn't support motor control )
146 #define PID_K4W_AUDIO 0x02be
147 #define PID_K4W_AUDIO_ALT_1 0x02c3
148 #define PID_K4W_AUDIO_ALT_2 0x02bb
149 
150 typedef struct {
151  int running;
153  int synced;
155  int got_pkts;
156  int pkt_num;
158  int pkt_size;
162  unsigned int lost_pkts;
168  void *lib_buf;
169  void *usr_buf;
171  void *proc_buf;
172 } packet_stream;
173 
174 typedef struct {
175  int running;
176 
177  freenect_sample_51* audio_out_ring; // TODO: implement sending user-provided data in callbacks
178  int ring_reader_idx; // Index in audio_out_ring of the last sent sample
179  int ring_writer_idx; // Index in audio_out_ring of the next sample we haven't received from the client yet
180 
186 
188  uint16_t last_seen_window[10];
190  int32_t* mic_buffer[4];
192  void* in_unknown;
193 
194  // TODO: timestamps
195 } audio_stream;
196 
197 typedef struct {
198  uint32_t magic; // 0x80000080
199  uint16_t channel; // Values between 0x1 and 0xa indicate audio channel
200  uint16_t len; // packet length
201  uint16_t window; // timestamp
203  int32_t samples[]; // Size depends on len
205 
206 typedef struct {
207  uint16_t window; // Kinda like a timestamp.
208  uint8_t seq; // Values from 0x00 to 0x7f
209  uint8_t weird; // Has an odd cyclic behavior.
210  freenect_sample_51 samples[6]; // Audio samples - 6 samples per transfer
212 
216  void *user_data;
217 
218  // Cameras
222 
231 
234 
237 
238  // Registration
240 
241  // Audio
245 
248 
251 
252  // Motor
255 
258 };
void(* freenect_audio_in_cb)(freenect_device *dev, int num_samples, int32_t *mic1, int32_t *mic2, int32_t *mic3, int32_t *mic4, int16_t *cancelled, void *unknown)
freenect_chunk_cb depth_chunk_cb
freenect_device_flags enabled_subdevices
void(* freenect_audio_out_cb)(freenect_device *dev, freenect_sample_51 *samples, int *sample_count)
freenect_video_format video_format
freenect_context * parent
unsigned char * fn_fw_k4w_ptr
uint8_t out_window_parity
packet_stream video
short int16_t
int device_does_motor_control_with_audio
freenect_registration registration
freenect_video_format
Definition: libfreenect.h:86
uint32_t last_timestamp
unsigned short uint16_t
unsigned int fn_fw_k4w_size
freenect_device * first
freenect_depth_format depth_format
#define fn_le32s(x)
void fn_log(freenect_context *ctx, freenect_loglevel level, const char *fmt,...) __attribute__((format(printf
fnusb_isoc_stream video_isoc
#define fn_le16(x)
unsigned char uint8_t
freenect_device * next
freenect_resolution depth_resolution
packet_stream depth
void(* freenect_depth_cb)(freenect_device *dev, void *depth, uint32_t timestamp)
Typedef for depth image received event callbacks.
Definition: libfreenect.h:385
freenect_depth_cb depth_cb
uint8_t out_counter_within_window
fnusb_isoc_stream audio_in_isoc
freenect_depth_format
Definition: libfreenect.h:99
#define fn_le16s(x)
Structure to represent a single 16-bit signed little-endian PCM sample.
FN_INTERNAL int fnusb_set_led_alt(libusb_device_handle *dev, freenect_context *ctx, freenect_led_options state)
Definition: tilt.c:239
freenect_loglevel
Enumeration of message logging levels.
Definition: libfreenect.h:200
freenect_log_cb log_cb
freenect_sample_51 * audio_out_ring
uint16_t out_weird_timestamp
int int32_t
void(* fnusb_iso_cb)(freenect_device *dev, uint8_t *buf, int len)
unsigned char * fn_fw_nui_ptr
freenect_raw_tilt_state raw_state
freenect_led_options
Definition: libfreenect.h:148
all data needed for depth->RGB mapping
void(* freenect_log_cb)(freenect_context *dev, freenect_loglevel level, const char *msg)
Typedef for logging callback functions.
Definition: libfreenect.h:232
unsigned int lost_pkts
freenect_resolution
Definition: libfreenect.h:77
typedef void(ONI_CALLBACK_TYPE *DeviceConnectedCallback)(const OniDeviceInfo *
static freenect_context * ctx
Data from the tilt motor and accelerometer.
Definition: libfreenect.h:167
#define FN_INTERNAL
unsigned int fn_fw_nui_size
unsigned int uint32_t
freenect_loglevel log_level
freenect_resolution video_resolution
capture state
Definition: micview.c:53
freenect_device_flags
Definition: libfreenect.h:58
fnusb_isoc_stream depth_isoc
fnusb_isoc_stream audio_out_isoc
freenect_audio_out_cb audio_out_cb
#define fn_le32(x)
void(* freenect_chunk_cb)(void *buffer, void *pkt_data, int pkt_num, int datalen, void *user_data)
Typedef for stream chunk processing callbacks.
Definition: libfreenect.h:389
freenect_chunk_cb video_chunk_cb
void(* freenect_video_cb)(freenect_device *dev, void *video, uint32_t timestamp)
Typedef for video image received event callbacks.
Definition: libfreenect.h:387
int16_t * cancelled_buffer
freenect_video_cb video_cb
freenect_audio_in_cb audio_in_cb


libfreenect
Author(s): Hector Martin, Josh Blake, Kyle Machulis, OpenKinect community
autogenerated on Mon Jun 10 2019 13:46:42