Release a recording frame only if mCamera exists and is not cleared.
and also call mCamera->stopRecording() only after CameraSource releases all the
outstanding video frames sent from CameraSource to its clients (such as video encoder).

Change-Id: I7eeed4e2f388e77c28668d52c24b5330d3d9ebde
diff --git a/media/libstagefright/CameraSource.cpp b/media/libstagefright/CameraSource.cpp
index 371c21f..8c686b9 100644
--- a/media/libstagefright/CameraSource.cpp
+++ b/media/libstagefright/CameraSource.cpp
@@ -576,13 +576,13 @@
     mFrameAvailableCondition.signal();
 
     int64_t token = IPCThreadState::self()->clearCallingIdentity();
-    stopCameraRecording();
     releaseQueuedFrames();
     while (!mFramesBeingEncoded.empty()) {
         LOGI("Waiting for outstanding frames being encoded: %d",
                 mFramesBeingEncoded.size());
         mFrameCompleteCondition.wait(mLock);
     }
+    stopCameraRecording();
     releaseCamera();
     IPCThreadState::self()->restoreCallingIdentity(token);
 
@@ -602,7 +602,9 @@
 }
 
 void CameraSource::releaseRecordingFrame(const sp<IMemory>& frame) {
-    mCamera->releaseRecordingFrame(frame);
+    if (mCamera != NULL) {
+        mCamera->releaseRecordingFrame(frame);
+    }
 }
 
 void CameraSource::releaseQueuedFrames() {