am 2ca7b0f4: fix issue when capturing with pre processing

* commit '2ca7b0f4515b844a8bcc42b0c45a60e1173ef570':
  fix issue when capturing with pre processing
diff --git a/libaudio/AudioPostProcessor.cpp b/libaudio/AudioPostProcessor.cpp
index a94204d..2db86e5 100644
--- a/libaudio/AudioPostProcessor.cpp
+++ b/libaudio/AudioPostProcessor.cpp
@@ -141,6 +141,7 @@
 {
     if (mEcnsEnabled!=value) {
         LOGD("enableEcns() new %08x old %08x)", value, mEcnsEnabled);
+        mEcnsThread->broadcastReadCond();
         mEcnsThread->requestExitAndWait();
         stopEcns();
         cleanupEcns();
@@ -666,6 +667,7 @@
         run("AudioPostProcessor::EcnsThread", ANDROID_PRIORITY_HIGHEST);
         mIsRunning = true;
     }
+    mEcnsReadCond.signal();
     if (mEcnsReadCond.waitRelative(mEcnsReadLock, seconds(1)) != NO_ERROR) {
         LOGE("%s: ECNS thread is stalled.", __FUNCTION__);
         mClientBuf = 0;
@@ -712,6 +714,17 @@
         GETTIMEOFDAY(&mtv3, NULL);
         mEcnsReadLock.lock();
         ecnsStatus = mProcessor->applyUplinkEcns(mReadBuf, mReadSize, mRate);
+
+        // wait for client buffer if not ready
+        if (!mClientBuf) {
+            if(exitPending()) {
+                mEcnsReadLock.unlock();
+                goto error;
+            }
+            if (mEcnsReadCond.waitRelative(mEcnsReadLock, seconds(1)) != NO_ERROR) {
+                LOGE("%s: client stalled.", __FUNCTION__);
+            }
+        }
         if (mClientBuf && mReadSize) {
             // Give the buffer to the client.
             memcpy(mClientBuf, mReadBuf, mReadSize);
@@ -719,8 +732,8 @@
             ret1 = ::read(mFd, mReadBuf, mReadSize/2);
             half_done = true;
             GETTIMEOFDAY(&mtv7, NULL);
-            mEcnsReadCond.signal();
             mClientBuf = 0;
+            mEcnsReadCond.signal();
         } else {
             half_done = false;
             LOGV("%s: Read overflow (ECNS sanity preserved)", __FUNCTION__);
diff --git a/libaudio/AudioPostProcessor.h b/libaudio/AudioPostProcessor.h
index 5ecf898..3a9ea29 100644
--- a/libaudio/AudioPostProcessor.h
+++ b/libaudio/AudioPostProcessor.h
@@ -117,6 +117,8 @@
                         ~EcnsThread();
             int         readData(int fd, void * buffer, int bytes, int rate,
                                  AudioPostProcessor * pp);
+            void        broadcastReadCond() { mEcnsReadCond.broadcast(); }
+
 private:
             bool        threadLoop();
             Mutex       mEcnsReadLock;