aboutsummaryrefslogtreecommitdiffstats
path: root/android/camera/camera-common.h
diff options
context:
space:
mode:
Diffstat (limited to 'android/camera/camera-common.h')
-rwxr-xr-xandroid/camera/camera-common.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/android/camera/camera-common.h b/android/camera/camera-common.h
index 126b3ed..37bdef4 100755
--- a/android/camera/camera-common.h
+++ b/android/camera/camera-common.h
@@ -176,5 +176,31 @@ typedef struct CameraDevice {
/* Opaque pointer used by the camera capturing API. */
void* opaque;
} CameraDevice;
+
+/* Returns current time in microseconds. */
+static __inline__ uint64_t
+_get_timestamp(void)
+{
+ struct timeval t;
+ t.tv_sec = t.tv_usec = 0;
+ gettimeofday(&t, NULL);
+ return (uint64_t)t.tv_sec * 1000000LL + t.tv_usec;
+}
+
+/* Sleeps for the given amount of milliseconds */
+static __inline__ void
+_sleep(int millisec)
+{
+ struct timeval t;
+ const uint64_t wake_at = _get_timestamp() + (uint64_t)millisec * 1000;
+ do {
+ const uint64_t stamp = _get_timestamp();
+ if ((stamp / 1000) >= (wake_at / 1000)) {
+ break;
+ }
+ t.tv_sec = (wake_at - stamp) / 1000000;
+ t.tv_usec = (wake_at - stamp) - (uint64_t)t.tv_sec * 1000000;
+ } while (select(0, NULL, NULL, NULL, &t) < 0 && errno == EINTR);
+}
#endif /* ANDROID_CAMERA_CAMERA_COMMON_H_ */