resolved conflicts for merge of 8a286a32 to master

Change-Id: I9e8d5e4b4af7f04530b1e49c41e39aa92ad9c898
diff --git a/libaudio/AudioPostProcessor.cpp b/libaudio/AudioPostProcessor.cpp
index e757edb..023c529 100644
--- a/libaudio/AudioPostProcessor.cpp
+++ b/libaudio/AudioPostProcessor.cpp
@@ -141,6 +141,7 @@
 {
     if (mEcnsEnabled!=value) {
         ALOGD("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) {
         ALOGE("%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;
             ALOGV("%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;