Camera2: Use more buffers for video encoding.

To avoid starvation, set the number of simultaneously available buffers
to the encoder to 8.

Bug: 6243944
Change-Id: I6d0e9f3c0426d62d374c0ae0d427bf5189141adf
diff --git a/services/camera/libcameraservice/Camera2Client.cpp b/services/camera/libcameraservice/Camera2Client.cpp
index 2e1940a..47d1588 100644
--- a/services/camera/libcameraservice/Camera2Client.cpp
+++ b/services/camera/libcameraservice/Camera2Client.cpp
@@ -769,7 +769,7 @@
     }
     buffer_handle_t imgBuffer = *(buffer_handle_t*)(data + 4);
     ALOGV("%s: Camera %d: Freeing buffer_handle_t %p", __FUNCTION__, mCameraId,
-            imgBuffer, *(uint32_t*)(data + 4));
+            imgBuffer);
     res = mRecordingConsumer->freeBuffer(imgBuffer);
     if (res != OK) {
         ALOGE("%s: Camera %d: Unable to free recording frame (buffer_handle_t: %p):"
@@ -1623,7 +1623,7 @@
         memcpy(data, &type, 4);
         memcpy(data + 4, &imgBuffer, sizeof(buffer_handle_t));
         ALOGV("%s: Camera %d: Sending out buffer_handle_t %p",
-                __FUNCTION__, mCameraId, imgBuffer, *(uint32_t*)(data + 4));
+                __FUNCTION__, mCameraId, imgBuffer);
         currentClient = mCameraClient;
     }
     // Call outside mICameraLock to allow re-entrancy from notification
@@ -2615,7 +2615,7 @@
 
     if (mRecordingConsumer == 0) {
         // Create CPU buffer queue endpoint
-        mRecordingConsumer = new MediaConsumer(4);
+        mRecordingConsumer = new MediaConsumer(kRecordingHeapCount);
         mRecordingConsumer->setFrameAvailableListener(new RecordingWaiter(this));
         mRecordingConsumer->setName(String8("Camera2Client::RecordingConsumer"));
         mRecordingWindow = new SurfaceTextureClient(
diff --git a/services/camera/libcameraservice/Camera2Client.h b/services/camera/libcameraservice/Camera2Client.h
index d7836ca..83fe94e 100644
--- a/services/camera/libcameraservice/Camera2Client.h
+++ b/services/camera/libcameraservice/Camera2Client.h
@@ -238,8 +238,9 @@
     sp<Camera2Heap> mRecordingHeap;
 
     // TODO: This needs to be queried from somewhere, or the BufferQueue needs
-    // to be passed all the way to stagefright
-    static const size_t kRecordingHeapCount = 4;
+    // to be passed all the way to stagefright. Right now, set to a large number
+    // to avoid starvation of the video encoders.
+    static const size_t kRecordingHeapCount = 8;
     size_t mRecordingHeapHead, mRecordingHeapFree;
     // Handle new recording image buffers
     void onRecordingFrameAvailable();