-
-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathcamera.h
More file actions
252 lines (225 loc) · 6.25 KB
/
Copy pathcamera.h
File metadata and controls
252 lines (225 loc) · 6.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#pragma once
#include <wut.h>
#include <coreinit/thread.h>
/**
* \defgroup cam Camera
* \ingroup cam
* @{
*/
#ifdef __cplusplus
extern "C" {
#endif
#define CAMERA_WIDTH 640
#define CAMERA_PITCH 768
#define CAMERA_HEIGHT 480
#define CAMERA_Y_BUFFER_SIZE (CAMERA_PITCH * CAMERA_HEIGHT)
#define CAMERA_UV_BUFFER_SIZE (CAMERA_PITCH * CAMERA_HEIGHT / 2)
#define CAMERA_YUV_BUFFER_SIZE (CAMERA_Y_BUFFER_SIZE + CAMERA_UV_BUFFER_SIZE)
#define CAMERA_YUV_BUFFER_ALIGNMENT 256
typedef int CAMHandle;
typedef int CAMError;
typedef struct CAMEventData CAMEventData;
typedef struct CAMMode CAMMode;
typedef struct CAMWorkMem CAMWorkMem;
typedef struct CAMStreamInfo CAMStreamInfo;
typedef struct CAMSetupInfo CAMSetupInfo;
typedef struct CAMSurface CAMSurface;
typedef enum CamError
{
CAMERA_ERROR_OK = 0,
CAMERA_ERROR_INVALID_ARG = -1,
CAMERA_ERROR_INVALID_HANDLE = -2,
CAMERA_ERROR_TOO_MANY_SURFACES = -4,
CAMERA_ERROR_INSUFFICIENT_MEMORY = -5,
CAMERA_ERROR_NOT_READY = -6,
CAMERA_ERROR_UNINITIALIZED = -8,
CAMERA_ERROR_UVC = -9,
CAMERA_ERROR_UVD_CONTEXT = -10,
CAMERA_ERROR_DEVICE_IN_USE = -12,
CAMERA_ERROR_UVD_SESSION = -13,
CAMERA_ERROR_SEGMENT_VIOLATION = -15
} CamError;
typedef enum CamFps
{
CAMERA_FPS_15 = 0,
CAMERA_FPS_30 = 1
} CamFps;
//! Stream type. There is only one valid stream type
typedef enum CamStreamType
{
CAMERA_STREAM_TYPE_1 = 0
} CamStreamType;
//! Type of event received by the event handler
typedef enum CamEventType
{
//! Frame was captured, decoded and copied to a submitted surface
CAMERA_DECODE_DONE = 0,
//! Wii U Gamepad disconnected
CAMERA_DRC_DETACH = 1
} CamEventType;
typedef enum CamForceDRC
{
CAMERA_FORCE_DRC_OFF = 0,
CAMERA_FORCE_DRC_ON = 1
} CamForceDRC;
struct CAMEventData
{
//! Event type
CamEventType eventType;
union
{
struct
{
//! Pointer to the buffer of the decoded image
void *surfaceBuffer;
//! Handle of instance
CAMHandle handle;
//! TRUE if decode failed
BOOL failed;
} decode;
struct
{
//! Will be FALSE
BOOL connected;
//! Handle of instance
CAMHandle handle;
} detach;
//! Event args
uint32_t args[3];
};
};
WUT_CHECK_OFFSET(CAMEventData, 0x00, eventType);
WUT_CHECK_OFFSET(CAMEventData, 0x04, decode.surfaceBuffer);
WUT_CHECK_OFFSET(CAMEventData, 0x08, decode.handle);
WUT_CHECK_OFFSET(CAMEventData, 0x0c, decode.failed);
WUT_CHECK_OFFSET(CAMEventData, 0x04, detach.connected);
WUT_CHECK_OFFSET(CAMEventData, 0x08, detach.handle);
WUT_CHECK_OFFSET(CAMEventData, 0x04, args);
WUT_CHECK_SIZE(CAMEventData, 0x10);
typedef void (*CAMEventHandler)(CAMEventData *camEventData);
struct CAMMode
{
//! Controls whether GamePad will display the camera output (regardless of rendered content)
CamForceDRC forceDrc;
//! Framerate setting
CamFps fps;
};
WUT_CHECK_OFFSET(CAMMode, 0x00, forceDrc);
WUT_CHECK_OFFSET(CAMMode, 0x04, fps);
WUT_CHECK_SIZE(CAMMode, 0x08);
struct CAMWorkMem
{
//! Size of the work memory
uint32_t size;
//! Pointer to the work memory
void *pMem;
};
WUT_CHECK_OFFSET(CAMWorkMem, 0x00, size);
WUT_CHECK_OFFSET(CAMWorkMem, 0x04, pMem);
WUT_CHECK_SIZE(CAMWorkMem, 0x08);
struct CAMStreamInfo
{
//! Stream type, only CAMERA_STREAM_TYPE_1 is valid
CamStreamType type;
//! Stream height
uint32_t height;
//! Stream width
uint32_t width;
};
WUT_CHECK_OFFSET(CAMStreamInfo, 0x00, type);
WUT_CHECK_OFFSET(CAMStreamInfo, 0x04, height);
WUT_CHECK_OFFSET(CAMStreamInfo, 0x08, width);
WUT_CHECK_SIZE(CAMStreamInfo, 0x0C);
struct CAMSetupInfo
{
//! Stream info
CAMStreamInfo streamInfo;
//! Memory used by library to record and decode frames
CAMWorkMem workMem;
//! Event handler
CAMEventHandler eventHandler;
//! Camera mode
CAMMode mode;
//! See \link OS_THREAD_ATTRIB \endlink
uint32_t threadAffinity;
WUT_PADDING_BYTES(0x10);
};
WUT_CHECK_OFFSET(CAMSetupInfo, 0x00, streamInfo);
WUT_CHECK_OFFSET(CAMSetupInfo, 0x0C, workMem);
WUT_CHECK_OFFSET(CAMSetupInfo, 0x14, eventHandler);
WUT_CHECK_OFFSET(CAMSetupInfo, 0x18, mode);
WUT_CHECK_OFFSET(CAMSetupInfo, 0x20, threadAffinity);
WUT_CHECK_SIZE(CAMSetupInfo, 0x34);
struct CAMSurface
{
//! Number of bytes allocated to surface buffer
int32_t surfaceSize;
//! Surface buffer data
void *surfaceBuffer;
//! Surface height
int32_t height;
//! Surface width
int32_t width;
//! Surface pitch
int32_t pitch;
//! Surface alignment
int32_t alignment;
//! Tile mode, should be zero
int32_t tileMode;
//! Pixel format, Should be zero
int32_t pixelFormat;
};
WUT_CHECK_OFFSET(CAMSurface, 0x00, surfaceSize);
WUT_CHECK_OFFSET(CAMSurface, 0x04, surfaceBuffer);
WUT_CHECK_OFFSET(CAMSurface, 0x08, height);
WUT_CHECK_OFFSET(CAMSurface, 0x0C, width);
WUT_CHECK_OFFSET(CAMSurface, 0x10, pitch);
WUT_CHECK_OFFSET(CAMSurface, 0x14, alignment);
WUT_CHECK_OFFSET(CAMSurface, 0x18, tileMode);
WUT_CHECK_OFFSET(CAMSurface, 0x1C, pixelFormat);
WUT_CHECK_SIZE(CAMSurface, 0x20);
/**
* Initialize the camera
* \returns camera handle on success, and -1 on failure
*/
CAMHandle
CAMInit(int instance, CAMSetupInfo *setupInfo, CAMError *err);
/**
* Deinitialize and clean up
*/
void
CAMExit(CAMHandle handle);
/**
* Start recording and decoding frames
*/
CAMError
CAMOpen(CAMHandle handle);
/**
* Stops recording and decoding.
* Automatically called when the process is moved to background
*/
CAMError
CAMClose(CAMHandle handle);
/**
* Get the number of bytes requied by the work memory
* \returns number of bytes
* \returns CAM_ERROR_INVALID_ARG if streamInfo is NULL
*/
int32_t
CAMGetMemReq(CAMStreamInfo *streamInfo);
/**
* Submit 1 surface to the working queue.
* Once the frame is captured and decoded, the event handler set in CAMInit will fire, and the frame will be dequeued.
* Up to 20 surfaces may be queued.
* Surface data is returned in the NV12 format
*/
CAMError
CAMSubmitTargetSurface(CAMHandle handle, CAMSurface *surface);
/**
* Checks whether memory is segmented correctly to be used with the camera library
*/
CAMError
CAMCheckMemSegmentation(void *pMem, uint32_t size);
#ifdef __cplusplus
}
#endif