audio/msm8660: Fix for improper LPA playback after seek

-LPA playback is not in continuous manner when rapid seek is performed
and effects is turned on/off.
-After seek, mSkipwrite flag is set to skip the current buffer either
in bufferavailable or write. If returned from write there is a
mismatch in buffer maintenance between flinger and hal as flinger
is not aware of buffer skip and has already pushed back the buffer
into mEffectsPool.
-Return error in skip case to handle in flinger and re-arrange buffers
to original state in mEffectsPool to avoid any mismatch.
Also mReachedEOS was getting set after fsync i.e. after write_done of
last buffer is processed and hence EOS was not getting posted to the
above layers. Moved this to ahead of fsync to avoid issues.

CRs-Fixed: 454460, 453872, 453833

(cherry picked from commit 8af44e4b795d289315188a3879a07596454bc923)

Change-Id: I98821fb0c97fdfc4f8d27e4480877ed963e5a61e
diff --git a/msm8660/AudioHardware.cpp b/msm8660/AudioHardware.cpp
index 5bace7d..78f9f6f 100644
--- a/msm8660/AudioHardware.cpp
+++ b/msm8660/AudioHardware.cpp
@@ -4146,12 +4146,9 @@
         if (bytes < LPA_BUFFER_SIZE)
             bytes = 0;
         else
-            return 0;
+            return UNKNOWN_ERROR;
     }
 
-    if (mSkipWrite)
-        mSkipWrite = false;
-
     //2.) Dequeue the buffer from empty buffer queue. Copy the data to be
     //    written into the buffer. Then Enqueue the buffer to the filled
     //    buffer queue
@@ -4216,10 +4213,10 @@
 
     if (bytes < LPA_BUFFER_SIZE) {
         ALOGV("Last buffer case");
+        mReachedEOS = true;
         if (fsync(afd) != 0) {
             ALOGE("fsync failed.");
         }
-        mReachedEOS = true;
     }
 
     return NO_ERROR; //TODO Do we need to send error
@@ -4534,11 +4531,11 @@
         switch ( cur_pcmdec_event.event_type ) {
         case AUDIO_EVENT_WRITE_DONE:
             {
+                Mutex::Autolock autoLock(mLock);
                 ALOGE("WRITE_DONE: addr %p len %d and fd is %d\n",
                      cur_pcmdec_event.event_payload.aio_buf.buf_addr,
                      cur_pcmdec_event.event_payload.aio_buf.data_len,
                      (int32_t) cur_pcmdec_event.event_payload.aio_buf.private_data);
-                Mutex::Autolock autoLock(mLock);
                 mFilledQueueMutex.lock();
                 BuffersAllocated buf = *(mFilledQueue.begin());
                 for (List<BuffersAllocated>::iterator it = mFilledQueue.begin();