OSDN Git Service

Fix log spamming during time lapse video recording
authorJames Dong <jdong@google.com>
Sun, 20 Nov 2011 17:45:44 +0000 (09:45 -0800)
committerJames Dong <jdong@google.com>
Mon, 21 Nov 2011 20:09:51 +0000 (12:09 -0800)
Change-Id: I4fc0809203684ebb02eaf217d7abad00aefc898f

related-to-bug: 5626569

include/media/stagefright/CameraSource.h
include/media/stagefright/CameraSourceTimeLapse.h
media/libstagefright/CameraSource.cpp
media/libstagefright/CameraSourceTimeLapse.cpp

index 8c1c593..446720b 100644 (file)
@@ -153,6 +153,9 @@ protected:
     bool mStarted;
     int32_t mNumFramesEncoded;
 
+    // Time between capture of two frames.
+    int64_t mTimeBetweenFrameCaptureUs;
+
     CameraSource(const sp<ICamera>& camera, const sp<ICameraRecordingProxy>& proxy,
                  int32_t cameraId,
                  Size videoSize, int32_t frameRate,
index 0e264c7..b060691 100644 (file)
@@ -57,10 +57,6 @@ private:
     int32_t mVideoWidth;
     int32_t mVideoHeight;
 
-    // Time between capture of two frames during time lapse recording
-    // Negative value indicates that timelapse is disabled.
-    int64_t mTimeBetweenTimeLapseFrameCaptureUs;
-
     // Time between two frames in final video (1/frameRate)
     int64_t mTimeBetweenTimeLapseVideoFramesUs;
 
index 256f3ba..57989c5 100755 (executable)
@@ -33,6 +33,8 @@
 
 namespace android {
 
+static const int64_t CAMERA_SOURCE_TIMEOUT_NS = 3000000000LL;
+
 struct CameraSourceListener : public CameraListener {
     CameraSourceListener(const sp<CameraSource> &source);
 
@@ -156,6 +158,7 @@ CameraSource::CameraSource(
       mLastFrameTimestampUs(0),
       mStarted(false),
       mNumFramesEncoded(0),
+      mTimeBetweenFrameCaptureUs(0),
       mFirstFrameTimeUs(0),
       mNumFramesDropped(0),
       mNumGlitches(0),
@@ -644,7 +647,8 @@ status_t CameraSource::stop() {
     releaseQueuedFrames();
     while (!mFramesBeingEncoded.empty()) {
         if (NO_ERROR !=
-            mFrameCompleteCondition.waitRelative(mLock, 3000000000LL)) {
+            mFrameCompleteCondition.waitRelative(mLock,
+                    mTimeBetweenFrameCaptureUs * 1000LL + CAMERA_SOURCE_TIMEOUT_NS)) {
             LOGW("Timed out waiting for outstanding frames being encoded: %d",
                 mFramesBeingEncoded.size());
         }
@@ -736,7 +740,8 @@ status_t CameraSource::read(
         Mutex::Autolock autoLock(mLock);
         while (mStarted && mFramesReceived.empty()) {
             if (NO_ERROR !=
-                mFrameAvailableCondition.waitRelative(mLock, 1000000000LL)) {
+                mFrameAvailableCondition.waitRelative(mLock,
+                    mTimeBetweenFrameCaptureUs * 1000LL + CAMERA_SOURCE_TIMEOUT_NS)) {
                 if (mCameraRecordingProxy != 0 &&
                     !mCameraRecordingProxy->asBinder()->isBinderAlive()) {
                     LOGW("camera recording proxy is gone");
index e4de20a..eb456f4 100644 (file)
@@ -39,12 +39,12 @@ CameraSourceTimeLapse *CameraSourceTimeLapse::CreateFromCamera(
         Size videoSize,
         int32_t videoFrameRate,
         const sp<Surface>& surface,
-        int64_t timeBetweenTimeLapseFrameCaptureUs) {
+        int64_t timeBetweenFrameCaptureUs) {
 
     CameraSourceTimeLapse *source = new
             CameraSourceTimeLapse(camera, proxy, cameraId,
                 videoSize, videoFrameRate, surface,
-                timeBetweenTimeLapseFrameCaptureUs);
+                timeBetweenFrameCaptureUs);
 
     if (source != NULL) {
         if (source->initCheck() != OK) {
@@ -62,15 +62,15 @@ CameraSourceTimeLapse::CameraSourceTimeLapse(
         Size videoSize,
         int32_t videoFrameRate,
         const sp<Surface>& surface,
-        int64_t timeBetweenTimeLapseFrameCaptureUs)
+        int64_t timeBetweenFrameCaptureUs)
     : CameraSource(camera, proxy, cameraId, videoSize, videoFrameRate, surface, true),
-      mTimeBetweenTimeLapseFrameCaptureUs(timeBetweenTimeLapseFrameCaptureUs),
       mTimeBetweenTimeLapseVideoFramesUs(1E6/videoFrameRate),
       mLastTimeLapseFrameRealTimestampUs(0),
       mSkipCurrentFrame(false) {
 
+    mTimeBetweenFrameCaptureUs = timeBetweenFrameCaptureUs;
     LOGD("starting time lapse mode: %lld us",
-        mTimeBetweenTimeLapseFrameCaptureUs);
+        mTimeBetweenFrameCaptureUs);
 
     mVideoWidth = videoSize.width;
     mVideoHeight = videoSize.height;
@@ -271,14 +271,14 @@ bool CameraSourceTimeLapse::skipFrameAndModifyTimeStamp(int64_t *timestampUs) {
     // The first 2 output frames from the encoder are: decoder specific info and
     // the compressed video frame data for the first input video frame.
     if (mNumFramesEncoded >= 1 && *timestampUs <
-        (mLastTimeLapseFrameRealTimestampUs + mTimeBetweenTimeLapseFrameCaptureUs)) {
+        (mLastTimeLapseFrameRealTimestampUs + mTimeBetweenFrameCaptureUs)) {
         // Skip all frames from last encoded frame until
-        // sufficient time (mTimeBetweenTimeLapseFrameCaptureUs) has passed.
+        // sufficient time (mTimeBetweenFrameCaptureUs) has passed.
         // Tell the camera to release its recording frame and return.
         LOGV("dataCallbackTimestamp timelapse: skipping intermediate frame");
         return true;
     } else {
-        // Desired frame has arrived after mTimeBetweenTimeLapseFrameCaptureUs time:
+        // Desired frame has arrived after mTimeBetweenFrameCaptureUs time:
         // - Reset mLastTimeLapseFrameRealTimestampUs to current time.
         // - Artificially modify timestampUs to be one frame time (1/framerate) ahead
         // of the last encoded frame's time stamp.