framewroks/av:Fix ANR at the end of video recording

- While doing video recording, when the recording
  ends ANR observed while doing stress test for
  many hours
- When the recording is stopped, audio HAL receives error
  from driver and  audio HAL propagates this error to
  AudioFlinger.  But AudioFlinger  is not sending error
  status to audio source to stop recording.  Because of
  this audiorecord thread keeps on waiting for buffers
  which is resulting in ANR.
- To avoid indefinite wait, a timeout of 1 sec is set for buffer
  in audioSource and after timeout, -ETIMEDOUT is returned
  to recorder thread.

Change-Id: Ic191c63d2a0f0144eb6d5b53e5c6d7c8602f44ba
CRs-Fixed: 479968
diff --git a/media/libstagefright/AudioSource.cpp b/media/libstagefright/AudioSource.cpp
index bdd842f..abbafd5 100644
--- a/media/libstagefright/AudioSource.cpp
+++ b/media/libstagefright/AudioSource.cpp
@@ -29,7 +29,9 @@
 #include <stdlib.h>
 
 namespace android {
-
+// Treat time out as an error if we have not received any output
+// buffers after 1 seconds
+const static int64_t WaitLockEventTimeOutNs = 1000000000LL;
 static void AudioRecordCallbackFunction(int event, void *user, void *info) {
     AudioSource *source = (AudioSource *) user;
     switch (event) {
@@ -217,7 +219,9 @@
     }
 
     while (mStarted && mBuffersReceived.empty()) {
-        mFrameAvailableCondition.wait(mLock);
+       status_t err = mFrameAvailableCondition.waitRelative(mLock,WaitLockEventTimeOutNs);
+       if(err == -ETIMEDOUT)
+           return (status_t)err;
     }
     if (!mStarted) {
         return OK;