summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/CameraSource.cpp
diff options
context:
space:
mode:
authorNipun Kwatra <nkwatra@google.com>2010-06-30 18:51:31 -0700
committerNipun Kwatra <nkwatra@google.com>2010-07-01 14:54:36 -0700
commitd26920ada05843e736d78709812e03797eedee55 (patch)
tree236a3b2ee4fbe0fcc564895206f1143faa1551fd /media/libstagefright/CameraSource.cpp
parent3bf8430e05de4d80eec39019f67614dfe3a449ef (diff)
downloadframeworks_base-d26920ada05843e736d78709812e03797eedee55.zip
frameworks_base-d26920ada05843e736d78709812e03797eedee55.tar.gz
frameworks_base-d26920ada05843e736d78709812e03797eedee55.tar.bz2
Adding timelapse capture from videocamera.
Current implementation looks at the timestamps of all incoming frames in CameraSource::dataCallbackTimestamp(). It drops all frames until enough time has elapsed to get the next time lapse frame. When enough time has passed to capture the next time lapse frame, the frame is no longer dropped and the timestamp of this frame is modified to be one frame time (1/framerate) ahead of the last encoded frame's time stamp. Change-Id: I82b9d5e96113dffa6901aac3b8a8ef999ffc1d0b
Diffstat (limited to 'media/libstagefright/CameraSource.cpp')
-rw-r--r--media/libstagefright/CameraSource.cpp47
1 files changed, 46 insertions, 1 deletions
diff --git a/media/libstagefright/CameraSource.cpp b/media/libstagefright/CameraSource.cpp
index 6f4c980..bb53d97 100644
--- a/media/libstagefright/CameraSource.cpp
+++ b/media/libstagefright/CameraSource.cpp
@@ -116,6 +116,19 @@ CameraSource *CameraSource::CreateFromCamera(const sp<Camera> &camera) {
return new CameraSource(camera);
}
+void CameraSource::enableTimeLapseMode(
+ int64_t timeBetweenTimeLapseFrameCaptureUs, int32_t videoFrameRate) {
+ LOGV("starting time lapse mode");
+ mTimeBetweenTimeLapseFrameCaptureUs = timeBetweenTimeLapseFrameCaptureUs;
+ mTimeBetweenTimeLapseVideoFramesUs = (1E6/videoFrameRate);
+}
+
+void CameraSource::disableTimeLapseMode() {
+ LOGV("stopping time lapse mode");
+ mTimeBetweenTimeLapseFrameCaptureUs = -1;
+ mTimeBetweenTimeLapseVideoFramesUs = 0;
+}
+
CameraSource::CameraSource(const sp<Camera> &camera)
: mCamera(camera),
mFirstFrameTimeUs(0),
@@ -126,7 +139,10 @@ CameraSource::CameraSource(const sp<Camera> &camera)
mNumGlitches(0),
mGlitchDurationThresholdUs(200000),
mCollectStats(false),
- mStarted(false) {
+ mStarted(false),
+ mTimeBetweenTimeLapseFrameCaptureUs(-1),
+ mTimeBetweenTimeLapseVideoFramesUs(0),
+ mLastTimeLapseFrameRealTimestampUs(0) {
int64_t token = IPCThreadState::self()->clearCallingIdentity();
String8 s = mCamera->getParameters();
@@ -316,6 +332,35 @@ void CameraSource::dataCallbackTimestamp(int64_t timestampUs,
++mNumGlitches;
}
+ // time lapse
+ if(mTimeBetweenTimeLapseFrameCaptureUs >= 0) {
+ if(mLastTimeLapseFrameRealTimestampUs == 0) {
+ // First time lapse frame. Initialize mLastTimeLapseFrameRealTimestampUs
+ // to current time (timestampUs) and save frame data.
+ LOGV("dataCallbackTimestamp timelapse: initial frame");
+
+ mLastTimeLapseFrameRealTimestampUs = timestampUs;
+ } else if (timestampUs <
+ (mLastTimeLapseFrameRealTimestampUs + mTimeBetweenTimeLapseFrameCaptureUs)) {
+ // Skip all frames from last encoded frame until
+ // sufficient time (mTimeBetweenTimeLapseFrameCaptureUs) has passed.
+ // Tell the camera to release its recording frame and return.
+ LOGV("dataCallbackTimestamp timelapse: skipping intermediate frame");
+
+ releaseOneRecordingFrame(data);
+ return;
+ } else {
+ // Desired frame has arrived after mTimeBetweenTimeLapseFrameCaptureUs 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.
+ LOGV("dataCallbackTimestamp timelapse: got timelapse frame");
+
+ mLastTimeLapseFrameRealTimestampUs = timestampUs;
+ timestampUs = mLastFrameTimestampUs + mTimeBetweenTimeLapseVideoFramesUs;
+ }
+ }
+
mLastFrameTimestampUs = timestampUs;
if (mNumFramesReceived == 0) {
mFirstFrameTimeUs = timestampUs;