Camera metadata: Check for inconsistent data count am: 241ff3e1ce
am: 59bc9e30bd
Change-Id: Ie09a5953eb7e44e45838306b2998f70541081499
diff --git a/audio_utils/echo_reference.c b/audio_utils/echo_reference.c
index 90f9a9f..0b82657 100644
--- a/audio_utils/echo_reference.c
+++ b/audio_utils/echo_reference.c
@@ -328,11 +328,24 @@
// allow some time for new frames to arrive if not enough frames are ready for read
if (er->frames_in < buffer->frame_count) {
uint32_t timeoutMs = (uint32_t)((1000 * buffer->frame_count) / er->rd_sampling_rate / 2);
- struct timespec ts;
+ struct timespec ts = {0, 0};
- ts.tv_sec = timeoutMs/1000;
- ts.tv_nsec = timeoutMs%1000;
+#ifndef HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE
+ clock_gettime(CLOCK_REALTIME, &ts);
+#endif
+
+ ts.tv_sec += timeoutMs/1000;
+ ts.tv_nsec += (timeoutMs%1000) * 1000000;
+ if (ts.tv_nsec >= 1000000000) {
+ ts.tv_nsec -= 1000000000;
+ ts.tv_sec += 1;
+ }
+
+#ifdef HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE
pthread_cond_timedwait_relative_np(&er->cond, &er->lock, &ts);
+#else
+ pthread_cond_timedwait(&er->cond, &er->lock, &ts);
+#endif
ALOGV_IF((er->frames_in < buffer->frame_count),
"echo_reference_read() waited %d ms but still not enough frames"\