Nipun Kwatra | 65e7e6f | 2010-07-12 09:17:14 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | //#define LOG_NDEBUG 0 |
| 18 | #define LOG_TAG "CameraSourceTimeLapse" |
| 19 | |
| 20 | #include <binder/IPCThreadState.h> |
| 21 | #include <binder/MemoryBase.h> |
| 22 | #include <binder/MemoryHeapBase.h> |
James Dong | f1d5aa1 | 2012-02-06 23:46:37 -0800 | [diff] [blame] | 23 | #include <media/stagefright/foundation/ADebug.h> |
Nipun Kwatra | 65e7e6f | 2010-07-12 09:17:14 -0700 | [diff] [blame] | 24 | #include <media/stagefright/CameraSource.h> |
| 25 | #include <media/stagefright/CameraSourceTimeLapse.h> |
Nipun Kwatra | 65e7e6f | 2010-07-12 09:17:14 -0700 | [diff] [blame] | 26 | #include <media/stagefright/MetaData.h> |
| 27 | #include <camera/Camera.h> |
| 28 | #include <camera/CameraParameters.h> |
| 29 | #include <utils/String8.h> |
Nipun Kwatra | 40e2f3f | 2010-07-30 18:30:55 -0700 | [diff] [blame] | 30 | #include <utils/Vector.h> |
Nipun Kwatra | 65e7e6f | 2010-07-12 09:17:14 -0700 | [diff] [blame] | 31 | |
| 32 | namespace android { |
| 33 | |
| 34 | // static |
James Dong | 54ff19a | 2010-10-08 11:59:32 -0700 | [diff] [blame] | 35 | CameraSourceTimeLapse *CameraSourceTimeLapse::CreateFromCamera( |
| 36 | const sp<ICamera> &camera, |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 37 | const sp<ICameraRecordingProxy> &proxy, |
James Dong | 54ff19a | 2010-10-08 11:59:32 -0700 | [diff] [blame] | 38 | int32_t cameraId, |
Eino-Ville Talvala | 48af7e8 | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 39 | const String16& clientName, |
| 40 | uid_t clientUid, |
James Dong | 54ff19a | 2010-10-08 11:59:32 -0700 | [diff] [blame] | 41 | Size videoSize, |
| 42 | int32_t videoFrameRate, |
Mathias Agopian | 33da402 | 2013-03-12 18:42:23 -0700 | [diff] [blame] | 43 | const sp<IGraphicBufferProducer>& surface, |
James Dong | e8e5f86 | 2011-11-20 09:45:44 -0800 | [diff] [blame] | 44 | int64_t timeBetweenFrameCaptureUs) { |
Nipun Kwatra | 65e7e6f | 2010-07-12 09:17:14 -0700 | [diff] [blame] | 45 | |
James Dong | 54ff19a | 2010-10-08 11:59:32 -0700 | [diff] [blame] | 46 | CameraSourceTimeLapse *source = new |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 47 | CameraSourceTimeLapse(camera, proxy, cameraId, |
Eino-Ville Talvala | 48af7e8 | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 48 | clientName, clientUid, |
James Dong | 54ff19a | 2010-10-08 11:59:32 -0700 | [diff] [blame] | 49 | videoSize, videoFrameRate, surface, |
James Dong | e8e5f86 | 2011-11-20 09:45:44 -0800 | [diff] [blame] | 50 | timeBetweenFrameCaptureUs); |
James Dong | 54ff19a | 2010-10-08 11:59:32 -0700 | [diff] [blame] | 51 | |
| 52 | if (source != NULL) { |
| 53 | if (source->initCheck() != OK) { |
| 54 | delete source; |
| 55 | return NULL; |
| 56 | } |
Nipun Kwatra | 65e7e6f | 2010-07-12 09:17:14 -0700 | [diff] [blame] | 57 | } |
James Dong | 54ff19a | 2010-10-08 11:59:32 -0700 | [diff] [blame] | 58 | return source; |
Nipun Kwatra | 65e7e6f | 2010-07-12 09:17:14 -0700 | [diff] [blame] | 59 | } |
| 60 | |
James Dong | 54ff19a | 2010-10-08 11:59:32 -0700 | [diff] [blame] | 61 | CameraSourceTimeLapse::CameraSourceTimeLapse( |
| 62 | const sp<ICamera>& camera, |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 63 | const sp<ICameraRecordingProxy>& proxy, |
James Dong | 54ff19a | 2010-10-08 11:59:32 -0700 | [diff] [blame] | 64 | int32_t cameraId, |
Eino-Ville Talvala | 48af7e8 | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 65 | const String16& clientName, |
| 66 | uid_t clientUid, |
James Dong | 54ff19a | 2010-10-08 11:59:32 -0700 | [diff] [blame] | 67 | Size videoSize, |
| 68 | int32_t videoFrameRate, |
Mathias Agopian | 33da402 | 2013-03-12 18:42:23 -0700 | [diff] [blame] | 69 | const sp<IGraphicBufferProducer>& surface, |
James Dong | e8e5f86 | 2011-11-20 09:45:44 -0800 | [diff] [blame] | 70 | int64_t timeBetweenFrameCaptureUs) |
Eino-Ville Talvala | 48af7e8 | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 71 | : CameraSource(camera, proxy, cameraId, clientName, clientUid, |
| 72 | videoSize, videoFrameRate, surface, true), |
Nipun Kwatra | 65e7e6f | 2010-07-12 09:17:14 -0700 | [diff] [blame] | 73 | mTimeBetweenTimeLapseVideoFramesUs(1E6/videoFrameRate), |
| 74 | mLastTimeLapseFrameRealTimestampUs(0), |
| 75 | mSkipCurrentFrame(false) { |
| 76 | |
James Dong | e8e5f86 | 2011-11-20 09:45:44 -0800 | [diff] [blame] | 77 | mTimeBetweenFrameCaptureUs = timeBetweenFrameCaptureUs; |
Steve Block | b8a8052 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 78 | ALOGD("starting time lapse mode: %lld us", |
James Dong | e8e5f86 | 2011-11-20 09:45:44 -0800 | [diff] [blame] | 79 | mTimeBetweenFrameCaptureUs); |
James Dong | 3cecf64 | 2011-06-29 16:56:52 -0700 | [diff] [blame] | 80 | |
James Dong | 54ff19a | 2010-10-08 11:59:32 -0700 | [diff] [blame] | 81 | mVideoWidth = videoSize.width; |
| 82 | mVideoHeight = videoSize.height; |
Nipun Kwatra | 155e833 | 2010-09-02 11:43:15 -0700 | [diff] [blame] | 83 | |
James Dong | 3cecf64 | 2011-06-29 16:56:52 -0700 | [diff] [blame] | 84 | if (!trySettingVideoSize(videoSize.width, videoSize.height)) { |
| 85 | mInitCheck = NO_INIT; |
Nipun Kwatra | 65e7e6f | 2010-07-12 09:17:14 -0700 | [diff] [blame] | 86 | } |
Nipun Kwatra | 78eff72 | 2010-09-15 15:08:49 -0700 | [diff] [blame] | 87 | |
| 88 | // Initialize quick stop variables. |
| 89 | mQuickStop = false; |
| 90 | mForceRead = false; |
| 91 | mLastReadBufferCopy = NULL; |
| 92 | mStopWaitingForIdleCamera = false; |
Nipun Kwatra | 65e7e6f | 2010-07-12 09:17:14 -0700 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | CameraSourceTimeLapse::~CameraSourceTimeLapse() { |
James Dong | b44c9d2 | 2012-02-02 18:04:02 -0800 | [diff] [blame] | 96 | if (mLastReadBufferCopy) { |
| 97 | mLastReadBufferCopy->release(); |
| 98 | mLastReadBufferCopy = NULL; |
| 99 | } |
Nipun Kwatra | 65e7e6f | 2010-07-12 09:17:14 -0700 | [diff] [blame] | 100 | } |
| 101 | |
Nipun Kwatra | 78eff72 | 2010-09-15 15:08:49 -0700 | [diff] [blame] | 102 | void CameraSourceTimeLapse::startQuickReadReturns() { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 103 | ALOGV("startQuickReadReturns"); |
Nipun Kwatra | 78eff72 | 2010-09-15 15:08:49 -0700 | [diff] [blame] | 104 | Mutex::Autolock autoLock(mQuickStopLock); |
Nipun Kwatra | 78eff72 | 2010-09-15 15:08:49 -0700 | [diff] [blame] | 105 | |
| 106 | // Enable quick stop mode. |
| 107 | mQuickStop = true; |
| 108 | |
James Dong | 3cecf64 | 2011-06-29 16:56:52 -0700 | [diff] [blame] | 109 | // Force dataCallbackTimestamp() coming from the video camera to |
| 110 | // not skip the next frame as we want read() to get a get a frame |
| 111 | // right away. |
| 112 | mForceRead = true; |
Nipun Kwatra | 78eff72 | 2010-09-15 15:08:49 -0700 | [diff] [blame] | 113 | } |
| 114 | |
James Dong | 3cecf64 | 2011-06-29 16:56:52 -0700 | [diff] [blame] | 115 | bool CameraSourceTimeLapse::trySettingVideoSize( |
| 116 | int32_t width, int32_t height) { |
| 117 | |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 118 | ALOGV("trySettingVideoSize"); |
Nipun Kwatra | 155e833 | 2010-09-02 11:43:15 -0700 | [diff] [blame] | 119 | int64_t token = IPCThreadState::self()->clearCallingIdentity(); |
| 120 | String8 s = mCamera->getParameters(); |
Nipun Kwatra | 155e833 | 2010-09-02 11:43:15 -0700 | [diff] [blame] | 121 | |
| 122 | CameraParameters params(s); |
| 123 | Vector<Size> supportedSizes; |
James Dong | 28934a9 | 2011-01-04 16:09:07 -0800 | [diff] [blame] | 124 | params.getSupportedVideoSizes(supportedSizes); |
| 125 | bool videoOutputSupported = false; |
| 126 | if (supportedSizes.size() == 0) { |
| 127 | params.getSupportedPreviewSizes(supportedSizes); |
| 128 | } else { |
| 129 | videoOutputSupported = true; |
| 130 | } |
Nipun Kwatra | 155e833 | 2010-09-02 11:43:15 -0700 | [diff] [blame] | 131 | |
James Dong | 28934a9 | 2011-01-04 16:09:07 -0800 | [diff] [blame] | 132 | bool videoSizeSupported = false; |
Nipun Kwatra | 155e833 | 2010-09-02 11:43:15 -0700 | [diff] [blame] | 133 | for (uint32_t i = 0; i < supportedSizes.size(); ++i) { |
| 134 | int32_t pictureWidth = supportedSizes[i].width; |
| 135 | int32_t pictureHeight = supportedSizes[i].height; |
| 136 | |
| 137 | if ((pictureWidth == width) && (pictureHeight == height)) { |
James Dong | 28934a9 | 2011-01-04 16:09:07 -0800 | [diff] [blame] | 138 | videoSizeSupported = true; |
Nipun Kwatra | 155e833 | 2010-09-02 11:43:15 -0700 | [diff] [blame] | 139 | } |
| 140 | } |
| 141 | |
James Dong | ba29002 | 2010-12-09 15:04:33 -0800 | [diff] [blame] | 142 | bool isSuccessful = false; |
James Dong | 28934a9 | 2011-01-04 16:09:07 -0800 | [diff] [blame] | 143 | if (videoSizeSupported) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 144 | ALOGV("Video size (%d, %d) is supported", width, height); |
James Dong | 28934a9 | 2011-01-04 16:09:07 -0800 | [diff] [blame] | 145 | if (videoOutputSupported) { |
| 146 | params.setVideoSize(width, height); |
| 147 | } else { |
| 148 | params.setPreviewSize(width, height); |
| 149 | } |
James Dong | ba29002 | 2010-12-09 15:04:33 -0800 | [diff] [blame] | 150 | if (mCamera->setParameters(params.flatten()) == OK) { |
| 151 | isSuccessful = true; |
| 152 | } else { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 153 | ALOGE("Failed to set preview size to %dx%d", width, height); |
James Dong | ba29002 | 2010-12-09 15:04:33 -0800 | [diff] [blame] | 154 | isSuccessful = false; |
| 155 | } |
Nipun Kwatra | 155e833 | 2010-09-02 11:43:15 -0700 | [diff] [blame] | 156 | } |
| 157 | |
James Dong | ba29002 | 2010-12-09 15:04:33 -0800 | [diff] [blame] | 158 | IPCThreadState::self()->restoreCallingIdentity(token); |
| 159 | return isSuccessful; |
Nipun Kwatra | 155e833 | 2010-09-02 11:43:15 -0700 | [diff] [blame] | 160 | } |
| 161 | |
Nipun Kwatra | 78eff72 | 2010-09-15 15:08:49 -0700 | [diff] [blame] | 162 | void CameraSourceTimeLapse::signalBufferReturned(MediaBuffer* buffer) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 163 | ALOGV("signalBufferReturned"); |
Nipun Kwatra | 78eff72 | 2010-09-15 15:08:49 -0700 | [diff] [blame] | 164 | Mutex::Autolock autoLock(mQuickStopLock); |
| 165 | if (mQuickStop && (buffer == mLastReadBufferCopy)) { |
| 166 | buffer->setObserver(NULL); |
| 167 | buffer->release(); |
| 168 | } else { |
| 169 | return CameraSource::signalBufferReturned(buffer); |
| 170 | } |
| 171 | } |
| 172 | |
James Dong | 3cecf64 | 2011-06-29 16:56:52 -0700 | [diff] [blame] | 173 | void createMediaBufferCopy( |
| 174 | const MediaBuffer& sourceBuffer, |
| 175 | int64_t frameTime, |
| 176 | MediaBuffer **newBuffer) { |
| 177 | |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 178 | ALOGV("createMediaBufferCopy"); |
Nipun Kwatra | 78eff72 | 2010-09-15 15:08:49 -0700 | [diff] [blame] | 179 | size_t sourceSize = sourceBuffer.size(); |
| 180 | void* sourcePointer = sourceBuffer.data(); |
| 181 | |
| 182 | (*newBuffer) = new MediaBuffer(sourceSize); |
| 183 | memcpy((*newBuffer)->data(), sourcePointer, sourceSize); |
| 184 | |
| 185 | (*newBuffer)->meta_data()->setInt64(kKeyTime, frameTime); |
| 186 | } |
| 187 | |
| 188 | void CameraSourceTimeLapse::fillLastReadBufferCopy(MediaBuffer& sourceBuffer) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 189 | ALOGV("fillLastReadBufferCopy"); |
Nipun Kwatra | 78eff72 | 2010-09-15 15:08:49 -0700 | [diff] [blame] | 190 | int64_t frameTime; |
| 191 | CHECK(sourceBuffer.meta_data()->findInt64(kKeyTime, &frameTime)); |
| 192 | createMediaBufferCopy(sourceBuffer, frameTime, &mLastReadBufferCopy); |
| 193 | mLastReadBufferCopy->add_ref(); |
| 194 | mLastReadBufferCopy->setObserver(this); |
| 195 | } |
| 196 | |
| 197 | status_t CameraSourceTimeLapse::read( |
| 198 | MediaBuffer **buffer, const ReadOptions *options) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 199 | ALOGV("read"); |
Nipun Kwatra | 78eff72 | 2010-09-15 15:08:49 -0700 | [diff] [blame] | 200 | if (mLastReadBufferCopy == NULL) { |
| 201 | mLastReadStatus = CameraSource::read(buffer, options); |
| 202 | |
James Dong | 3cecf64 | 2011-06-29 16:56:52 -0700 | [diff] [blame] | 203 | // mQuickStop may have turned to true while read was blocked. |
| 204 | // Make a copy of the buffer in that case. |
Nipun Kwatra | 78eff72 | 2010-09-15 15:08:49 -0700 | [diff] [blame] | 205 | Mutex::Autolock autoLock(mQuickStopLock); |
| 206 | if (mQuickStop && *buffer) { |
| 207 | fillLastReadBufferCopy(**buffer); |
| 208 | } |
| 209 | return mLastReadStatus; |
| 210 | } else { |
| 211 | (*buffer) = mLastReadBufferCopy; |
| 212 | (*buffer)->add_ref(); |
| 213 | return mLastReadStatus; |
| 214 | } |
| 215 | } |
| 216 | |
James Dong | 3cecf64 | 2011-06-29 16:56:52 -0700 | [diff] [blame] | 217 | sp<IMemory> CameraSourceTimeLapse::createIMemoryCopy( |
| 218 | const sp<IMemory> &source_data) { |
Nipun Kwatra | 65e7e6f | 2010-07-12 09:17:14 -0700 | [diff] [blame] | 219 | |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 220 | ALOGV("createIMemoryCopy"); |
Nipun Kwatra | 65e7e6f | 2010-07-12 09:17:14 -0700 | [diff] [blame] | 221 | size_t source_size = source_data->size(); |
| 222 | void* source_pointer = source_data->pointer(); |
| 223 | |
| 224 | sp<MemoryHeapBase> newMemoryHeap = new MemoryHeapBase(source_size); |
| 225 | sp<MemoryBase> newMemory = new MemoryBase(newMemoryHeap, 0, source_size); |
| 226 | memcpy(newMemory->pointer(), source_pointer, source_size); |
| 227 | return newMemory; |
| 228 | } |
| 229 | |
Nipun Kwatra | 65e7e6f | 2010-07-12 09:17:14 -0700 | [diff] [blame] | 230 | bool CameraSourceTimeLapse::skipCurrentFrame(int64_t timestampUs) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 231 | ALOGV("skipCurrentFrame"); |
Nipun Kwatra | c4e47d1 | 2010-07-27 22:21:44 -0700 | [diff] [blame] | 232 | if (mSkipCurrentFrame) { |
Nipun Kwatra | 65e7e6f | 2010-07-12 09:17:14 -0700 | [diff] [blame] | 233 | mSkipCurrentFrame = false; |
| 234 | return true; |
| 235 | } else { |
| 236 | return false; |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | bool CameraSourceTimeLapse::skipFrameAndModifyTimeStamp(int64_t *timestampUs) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 241 | ALOGV("skipFrameAndModifyTimeStamp"); |
James Dong | 3cecf64 | 2011-06-29 16:56:52 -0700 | [diff] [blame] | 242 | if (mLastTimeLapseFrameRealTimestampUs == 0) { |
| 243 | // First time lapse frame. Initialize mLastTimeLapseFrameRealTimestampUs |
| 244 | // to current time (timestampUs) and save frame data. |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 245 | ALOGV("dataCallbackTimestamp timelapse: initial frame"); |
Nipun Kwatra | 65e7e6f | 2010-07-12 09:17:14 -0700 | [diff] [blame] | 246 | |
James Dong | 3cecf64 | 2011-06-29 16:56:52 -0700 | [diff] [blame] | 247 | mLastTimeLapseFrameRealTimestampUs = *timestampUs; |
| 248 | return false; |
| 249 | } |
| 250 | |
| 251 | { |
| 252 | Mutex::Autolock autoLock(mQuickStopLock); |
| 253 | |
| 254 | // mForceRead may be set to true by startQuickReadReturns(). In that |
| 255 | // case don't skip this frame. |
| 256 | if (mForceRead) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 257 | ALOGV("dataCallbackTimestamp timelapse: forced read"); |
James Dong | 3cecf64 | 2011-06-29 16:56:52 -0700 | [diff] [blame] | 258 | mForceRead = false; |
| 259 | *timestampUs = |
| 260 | mLastFrameTimestampUs + mTimeBetweenTimeLapseVideoFramesUs; |
James Dong | 93594b5 | 2011-10-26 23:47:55 -0700 | [diff] [blame] | 261 | |
| 262 | // Really make sure that this video recording frame will not be dropped. |
| 263 | if (*timestampUs < mStartTimeUs) { |
Steve Block | df64d15 | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 264 | ALOGI("set timestampUs to start time stamp %lld us", mStartTimeUs); |
James Dong | 93594b5 | 2011-10-26 23:47:55 -0700 | [diff] [blame] | 265 | *timestampUs = mStartTimeUs; |
| 266 | } |
Nipun Kwatra | 78eff72 | 2010-09-15 15:08:49 -0700 | [diff] [blame] | 267 | return false; |
| 268 | } |
James Dong | 3cecf64 | 2011-06-29 16:56:52 -0700 | [diff] [blame] | 269 | } |
Nipun Kwatra | 78eff72 | 2010-09-15 15:08:49 -0700 | [diff] [blame] | 270 | |
James Dong | 3cecf64 | 2011-06-29 16:56:52 -0700 | [diff] [blame] | 271 | // Workaround to bypass the first 2 input frames for skipping. |
| 272 | // The first 2 output frames from the encoder are: decoder specific info and |
| 273 | // the compressed video frame data for the first input video frame. |
| 274 | if (mNumFramesEncoded >= 1 && *timestampUs < |
James Dong | e8e5f86 | 2011-11-20 09:45:44 -0800 | [diff] [blame] | 275 | (mLastTimeLapseFrameRealTimestampUs + mTimeBetweenFrameCaptureUs)) { |
James Dong | 3cecf64 | 2011-06-29 16:56:52 -0700 | [diff] [blame] | 276 | // Skip all frames from last encoded frame until |
James Dong | e8e5f86 | 2011-11-20 09:45:44 -0800 | [diff] [blame] | 277 | // sufficient time (mTimeBetweenFrameCaptureUs) has passed. |
James Dong | 3cecf64 | 2011-06-29 16:56:52 -0700 | [diff] [blame] | 278 | // Tell the camera to release its recording frame and return. |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 279 | ALOGV("dataCallbackTimestamp timelapse: skipping intermediate frame"); |
James Dong | 3cecf64 | 2011-06-29 16:56:52 -0700 | [diff] [blame] | 280 | return true; |
| 281 | } else { |
James Dong | e8e5f86 | 2011-11-20 09:45:44 -0800 | [diff] [blame] | 282 | // Desired frame has arrived after mTimeBetweenFrameCaptureUs time: |
James Dong | 3cecf64 | 2011-06-29 16:56:52 -0700 | [diff] [blame] | 283 | // - Reset mLastTimeLapseFrameRealTimestampUs to current time. |
| 284 | // - Artificially modify timestampUs to be one frame time (1/framerate) ahead |
| 285 | // of the last encoded frame's time stamp. |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 286 | ALOGV("dataCallbackTimestamp timelapse: got timelapse frame"); |
Nipun Kwatra | 78eff72 | 2010-09-15 15:08:49 -0700 | [diff] [blame] | 287 | |
James Dong | 3cecf64 | 2011-06-29 16:56:52 -0700 | [diff] [blame] | 288 | mLastTimeLapseFrameRealTimestampUs = *timestampUs; |
| 289 | *timestampUs = mLastFrameTimestampUs + mTimeBetweenTimeLapseVideoFramesUs; |
| 290 | return false; |
Nipun Kwatra | 65e7e6f | 2010-07-12 09:17:14 -0700 | [diff] [blame] | 291 | } |
| 292 | return false; |
| 293 | } |
| 294 | |
| 295 | void CameraSourceTimeLapse::dataCallbackTimestamp(int64_t timestampUs, int32_t msgType, |
| 296 | const sp<IMemory> &data) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 297 | ALOGV("dataCallbackTimestamp"); |
James Dong | 3cecf64 | 2011-06-29 16:56:52 -0700 | [diff] [blame] | 298 | mSkipCurrentFrame = skipFrameAndModifyTimeStamp(×tampUs); |
Nipun Kwatra | 65e7e6f | 2010-07-12 09:17:14 -0700 | [diff] [blame] | 299 | CameraSource::dataCallbackTimestamp(timestampUs, msgType, data); |
| 300 | } |
| 301 | |
| 302 | } // namespace android |