1 #ifndef ANDROID_DVR_POSE_CLIENT_H_
2 #define ANDROID_DVR_POSE_CLIENT_H_
3 
4 #ifdef __ARM_NEON
5 #include <arm_neon.h>
6 #else
7 #ifndef __FLOAT32X4T_86
8 #define __FLOAT32X4T_86
9 typedef float float32x4_t __attribute__ ((__vector_size__ (16)));
10 typedef struct float32x4x4_t { float32x4_t val[4]; } float32x4x4_t;
11 #endif
12 #endif
13 
14 #include <stdbool.h>
15 #include <stdint.h>
16 
17 #include <dvr/dvr_pose.h>
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 typedef struct DvrPoseClient DvrPoseClient;
24 
25 // Returned by the async pose ring buffer access API.
26 typedef struct DvrPoseRingBufferInfo {
27   // Read-only pointer to the pose ring buffer. The current pose is in this
28   // buffer at element buffer[current_frame & (buffer_size - 1)]. The next
29   // frame's forecasted pose is at element
30   // ((current_frame + 1) & (buffer_size - 1)). And so on. The poses are
31   // predicted for when 50% of the corresponding frame's pixel data is visible
32   // to the user.
33   // The last value returned by dvrPresent is the count for the next frame,
34   // which is the earliest that the application could display something if they
35   // were to render promptly. (TODO(jbates) move this comment to dvrPresent).
36   volatile const DvrPoseAsync* buffer;
37   // Minimum number of accurate forecasted poses including the current frame's
38   // pose. This is the number of poses that are udpated by the pose service.
39   // If the application reads past this count, they will get a stale prediction
40   // from a previous frame. Guaranteed to be at least 2.
41   uint32_t min_future_count;
42   // Number of elements in buffer. At least 8 and greater than min_future_count.
43   // Guaranteed to be a power of two. The total size of the buffer in bytes is:
44   //   total_count * sizeof(DvrPoseAsync)
45   uint32_t total_count;
46 } DvrPoseRingBufferInfo;
47 
48 typedef enum DvrPoseMode {
49   DVR_POSE_MODE_6DOF = 0,
50   DVR_POSE_MODE_3DOF,
51   DVR_POSE_MODE_MOCK_FROZEN,
52   DVR_POSE_MODE_MOCK_HEAD_TURN_SLOW,
53   DVR_POSE_MODE_MOCK_HEAD_TURN_FAST,
54   DVR_POSE_MODE_MOCK_ROTATE_SLOW,
55   DVR_POSE_MODE_MOCK_ROTATE_MEDIUM,
56   DVR_POSE_MODE_MOCK_ROTATE_FAST,
57   DVR_POSE_MODE_MOCK_CIRCLE_STRAFE,
58   DVR_POSE_MODE_FLOAT,
59   DVR_POSE_MODE_MOCK_MOTION_SICKNESS,
60 
61   // Always last.
62   DVR_POSE_MODE_COUNT,
63 } DvrPoseMode;
64 
65 typedef enum DvrControllerId {
66   DVR_CONTROLLER_0 = 0,
67   DVR_CONTROLLER_1 = 1,
68 } DvrControllerId;
69 
70 // Creates a new pose client.
71 //
72 // @return Pointer to the created pose client, nullptr on failure.
73 DvrPoseClient* dvrPoseClientCreate();
74 
75 // Destroys a pose client.
76 //
77 // @param client Pointer to the pose client to be destroyed.
78 void dvrPoseClientDestroy(DvrPoseClient* client);
79 
80 // Gets the pose for the given vsync count.
81 //
82 // @param client Pointer to the pose client.
83 // @param vsync_count Vsync that this pose should be forward-predicted to.
84 //     Typically this is the count returned by dvrGetNextVsyncCount.
85 // @param out_pose Struct to store pose state.
86 // @return Zero on success, negative error code on failure.
87 int dvrPoseClientGet(DvrPoseClient* client, uint32_t vsync_count,
88                      DvrPoseAsync* out_pose);
89 
90 // Gets the current vsync count.
91 uint32_t dvrPoseClientGetVsyncCount(DvrPoseClient* client);
92 
93 // Gets the pose for the given controller at the given vsync count.
94 //
95 // @param client Pointer to the pose client.
96 // @param controller_id The controller id.
97 // @param vsync_count Vsync that this pose should be forward-predicted to.
98 //     Typically this is the count returned by dvrGetNextVsyncCount.
99 // @param out_pose Struct to store pose state.
100 // @return Zero on success, negative error code on failure.
101 int dvrPoseClientGetController(DvrPoseClient* client, int32_t controller_id,
102                                uint32_t vsync_count, DvrPoseAsync* out_pose);
103 
104 // Enables/disables logging for the controller fusion.
105 //
106 // @param client Pointer to the pose client.
107 // @param enable True starts logging, False stops.
108 // @return Zero on success, negative error code on failure.
109 int dvrPoseClientLogController(DvrPoseClient* client, bool enable);
110 
111 // DEPRECATED
112 // Polls current pose state.
113 //
114 // @param client Pointer to the pose client.
115 // @param state Struct to store polled state.
116 // @return Zero on success, negative error code on failure.
117 int dvrPoseClientPoll(DvrPoseClient* client, DvrPose* state);
118 
119 // Freezes the pose to the provided state.
120 //
121 // Future poll operations will return this state until a different state is
122 // frozen or dvrPoseClientModeSet() is called with a different mode. The timestamp is
123 // not frozen.
124 //
125 // @param client Pointer to the pose client.
126 // @param frozen_state State pose to be frozen to.
127 // @return Zero on success, negative error code on failure.
128 int dvrPoseClientFreeze(DvrPoseClient* client, const DvrPose* frozen_state);
129 
130 // Sets the pose service mode.
131 //
132 // @param mode The requested pose mode.
133 // @return Zero on success, negative error code on failure.
134 int dvrPoseClientModeSet(DvrPoseClient* client, DvrPoseMode mode);
135 
136 // Gets the pose service mode.
137 //
138 // @param mode Return value for the current pose mode.
139 // @return Zero on success, negative error code on failure.
140 int dvrPoseClientModeGet(DvrPoseClient* client, DvrPoseMode* mode);
141 
142 // Get access to the shared memory pose ring buffer.
143 // A future pose at vsync <current> + <offset> is accessed at index:
144 //   index = (<current> + <offset>) % out_buffer_size
145 // Where <current> was the last value returned by dvrPresent and
146 // <offset> is less than or equal to |out_min_future_count|.
147 // |out_buffer| will be set to a pointer to the buffer.
148 // |out_fd| will be set to the gralloc buffer file descriptor, which is
149 //   required for binding this buffer for GPU use.
150 // Returns 0 on success.
151 int dvrPoseClientGetRingBuffer(DvrPoseClient* client,
152                                DvrPoseRingBufferInfo* out_info);
153 
154 // Sets enabled state for sensors pose processing.
155 //
156 // @param enabled Whether sensors are enabled or disabled.
157 // @return Zero on success
158 int dvrPoseClientSensorsEnable(DvrPoseClient* client, bool enabled);
159 
160 // Requests a burst of data samples from pose service. The data samples are
161 // passed through a shared memory buffer obtained by calling
162 // dvrPoseClientGetDataReader().
163 //
164 // @param DvrPoseDataCaptureRequest Parameters on how to capture data.
165 // @return Zero on success.
166 int dvrPoseClientDataCapture(DvrPoseClient* client,
167                              const DvrPoseDataCaptureRequest* request);
168 
169 // Destroys the write buffer queue for the given |data_type|.
170 int dvrPoseClientDataReaderDestroy(DvrPoseClient* client, uint64_t data_type);
171 
172 #ifdef __cplusplus
173 }  // extern "C"
174 #endif
175 
176 #endif  // ANDROID_DVR_POSE_CLIENT_H_
177