Release the video frame buffer to fix the memory leak issue on emulator

The camera video recording crashes randomly on emulator.
It's caused by the memory leak issue, the emulator camera HAL does not release
recording frames properly in its releaseRecordingFrame method.

Change-Id: Ib6ad4647856cb6b69695a6172692fcff1819672b
Signed-off-by: Jun Tian <jun.j.tian@intel.com>
Signed-off-by: Chang Panfeng <pangfengx.chang@intel.com>
Signed-off-by: Igor Murashkin <iam@google.com>
diff --git a/camera/CallbackNotifier.cpp b/camera/CallbackNotifier.cpp
index 140c872..b288f52 100755
--- a/camera/CallbackNotifier.cpp
+++ b/camera/CallbackNotifier.cpp
@@ -170,8 +170,14 @@
 
 void CallbackNotifier::releaseRecordingFrame(const void* opaque)
 {
-    /* We don't really have anything to release here, since we report video
-     * frames by copying them directly to the camera memory. */
+    List<camera_memory_t*>::iterator it = mCameraMemoryTs.begin();
+    for( ; it != mCameraMemoryTs.end(); ++it ) {
+        if ( (*it)->data == opaque ) {
+            (*it)->release( *it );
+            mCameraMemoryTs.erase(it);
+            break;
+        }
+    }
 }
 
 status_t CallbackNotifier::storeMetaDataInBuffers(bool enable)
@@ -214,6 +220,8 @@
             memcpy(cam_buff->data, frame, camera_dev->getFrameBufferSize());
             mDataCBTimestamp(timestamp, CAMERA_MSG_VIDEO_FRAME,
                                cam_buff, 0, mCBOpaque);
+
+            mCameraMemoryTs.push_back( cam_buff );
         } else {
             ALOGE("%s: Memory failure in CAMERA_MSG_VIDEO_FRAME", __FUNCTION__);
         }
diff --git a/camera/CallbackNotifier.h b/camera/CallbackNotifier.h
index 63301d2..24784b5 100755
--- a/camera/CallbackNotifier.h
+++ b/camera/CallbackNotifier.h
@@ -22,6 +22,8 @@
  * via set_callbacks, enable_msg_type, and disable_msg_type camera HAL API.
  */
 
+#include <utils/List.h>
+
 namespace android {
 
 class EmulatedCameraDevice;
@@ -209,6 +211,9 @@
     camera_request_memory           mGetMemoryCB;
     void*                           mCBOpaque;
 
+    /* video frame queue for the CameraHeapMemory destruction */
+    List<camera_memory_t*>          mCameraMemoryTs;
+
     /* Timestamp when last frame has been delivered to the framework. */
     nsecs_t                         mLastFrameTimestamp;