Implemented frequent read returns for quick stop in time lapse.

If the frame capture interval is large, read will block for a long time.
Due to the way the mediaRecorder framework works, a stop() call from
mediaRecorder waits until the read returns, causing a long wait for
stop() to return. To avoid this, we return a copy of the last read
frame with the same time stamp if a frame is not available quickly.
This keeps the read() call from blocking too long. This method is
triggered when startQuickReadReturns() is called on
CameraSourceTimeLapse.

In the still camera case, also using waitRelative on Condition
instaed of sleeping, so that we can wake it up.
Also for the idle check instead of sleeping, we now wait on a
condition variable, which is woken up when the last takePicture
callback gets called.

Change-Id: Ia74386e175536aee0f44ae2f8b114c353d3d72f5
diff --git a/media/libstagefright/CameraSource.cpp b/media/libstagefright/CameraSource.cpp
index 12ac168..0c9eef4 100644
--- a/media/libstagefright/CameraSource.cpp
+++ b/media/libstagefright/CameraSource.cpp
@@ -210,6 +210,7 @@
 }
 
 void CameraSource::stopCameraRecording() {
+    mCamera->setListener(NULL);
     mCamera->stopRecording();
 }
 
@@ -220,7 +221,6 @@
     mFrameAvailableCondition.signal();
 
     int64_t token = IPCThreadState::self()->clearCallingIdentity();
-    mCamera->setListener(NULL);
     stopCameraRecording();
     releaseQueuedFrames();
     while (!mFramesBeingEncoded.empty()) {