Fix regression for AudioRecord streaming callback mode

The notification period (frequency of client wakeups) was broken in
streaming callback mode.  Fast tracks were OK, but non-fast tracks with
normal latency weren't getting woken up at all.

Bug: 10222943
Change-Id: Ife9a2f57fa73c6eb921f1c5ba62de0bfcc20557b
diff --git a/media/libmedia/AudioRecord.cpp b/media/libmedia/AudioRecord.cpp
index 2718420..616c3d6 100644
--- a/media/libmedia/AudioRecord.cpp
+++ b/media/libmedia/AudioRecord.cpp
@@ -245,9 +245,8 @@
         return BAD_VALUE;
     }
 
-    if (notificationFrames == 0) {
-        notificationFrames = frameCount/2;
-    }
+    mNotificationFramesReq = notificationFrames;
+    mNotificationFramesAct = 0;
 
     // create the IAudioRecord
     status = openRecord_l(sampleRate, format, frameCount, mFlags, input, 0 /*epoch*/);
@@ -267,8 +266,6 @@
 
     mActive = false;
     mCbf = cbf;
-    mNotificationFramesReq = notificationFrames;
-    mNotificationFramesAct = 0;
     mRefreshRemaining = true;
     mUserData = user;
     // TODO: add audio hardware input latency here
@@ -464,6 +461,15 @@
         }
     }
 
+    mNotificationFramesAct = mNotificationFramesReq;
+
+    if (!(flags & AUDIO_INPUT_FLAG_FAST)) {
+        // Make sure that application is notified with sufficient margin before overrun
+        if (mNotificationFramesAct == 0 || mNotificationFramesAct > frameCount/2) {
+            mNotificationFramesAct = frameCount/2;
+        }
+    }
+
     int originalSessionId = mSessionId;
     sp<IAudioRecord> record = audioFlinger->openRecord(input,
                                                        sampleRate, format,
@@ -495,7 +501,6 @@
     mCblk = cblk;
     // FIXME missing fast track frameCount logic
     mAwaitBoost = false;
-    mNotificationFramesAct = mNotificationFramesReq;
     if (flags & AUDIO_INPUT_FLAG_FAST) {
         if (trackFlags & IAudioFlinger::TRACK_FAST) {
             ALOGV("AUDIO_INPUT_FLAG_FAST successful; frameCount %u", frameCount);