aboutsummaryrefslogtreecommitdiffstats
path: root/android/camera/camera-common.h
diff options
context:
space:
mode:
authorVladimir Chtchetkine <vchtchetkine@google.com>2011-09-23 07:58:34 -0700
committerVladimir Chtchetkine <vchtchetkine@google.com>2011-09-23 09:08:26 -0700
commitc68dbbef0118eab4256acfc0d9430f0e557a82a1 (patch)
tree2308288c3fae94e758fb5c6a6d770cacebc93483 /android/camera/camera-common.h
parent65769f5966d86278cccab3f43e2b67f499de4314 (diff)
downloadexternal_qemu-c68dbbef0118eab4256acfc0d9430f0e557a82a1.zip
external_qemu-c68dbbef0118eab4256acfc0d9430f0e557a82a1.tar.gz
external_qemu-c68dbbef0118eab4256acfc0d9430f0e557a82a1.tar.bz2
Timeout frame capturing.
It has been observed on some of the MS camera devices, that device may got stuck on something that would alwais return EAGAIN when queried for the next video frame. This requires us to timeout the loop that repeats attempts to acquire first frame from the device. Also added detection and reporting of I/O errors occurred during frame capturing. Also, this CL contains some cosmetick changes to error and warning reporting. Change-Id: I81edaf5ff8bfe147dbe4510e1446e77a87817f37
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_ */