CameraSourceTimeLapse.h revision 54ff19ac69ace7c05ea90d225e26dab3b133f487
165e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra/* 265e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra * Copyright (C) 2010 The Android Open Source Project 365e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra * 465e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra * Licensed under the Apache License, Version 2.0 (the "License"); 565e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra * you may not use this file except in compliance with the License. 665e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra * You may obtain a copy of the License at 765e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra * 865e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra * http://www.apache.org/licenses/LICENSE-2.0 965e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra * 1065e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra * Unless required by applicable law or agreed to in writing, software 1165e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra * distributed under the License is distributed on an "AS IS" BASIS, 1265e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1365e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra * See the License for the specific language governing permissions and 1465e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra * limitations under the License. 1565e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra */ 1665e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra 1765e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra#ifndef CAMERA_SOURCE_TIME_LAPSE_H_ 1865e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra 1965e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra#define CAMERA_SOURCE_TIME_LAPSE_H_ 2065e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra 2165e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra#include <pthread.h> 2265e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra 2365e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra#include <utils/RefBase.h> 2465e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra#include <utils/threads.h> 2565e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra 2665e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatranamespace android { 2765e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra 2865e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatraclass ICamera; 2965e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatraclass IMemory; 3065e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatraclass Camera; 3165e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra 3265e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatraclass CameraSourceTimeLapse : public CameraSource { 3365e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatrapublic: 3454ff19ac69ace7c05ea90d225e26dab3b133f487James Dong static CameraSourceTimeLapse *CreateFromCamera( 3554ff19ac69ace7c05ea90d225e26dab3b133f487James Dong const sp<ICamera> &camera, 3654ff19ac69ace7c05ea90d225e26dab3b133f487James Dong int32_t cameraId, 3754ff19ac69ace7c05ea90d225e26dab3b133f487James Dong Size videoSize, 3854ff19ac69ace7c05ea90d225e26dab3b133f487James Dong int32_t videoFrameRate, 3954ff19ac69ace7c05ea90d225e26dab3b133f487James Dong const sp<Surface>& surface, 4054ff19ac69ace7c05ea90d225e26dab3b133f487James Dong int64_t timeBetweenTimeLapseFrameCaptureUs); 4165e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra 4265e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra virtual ~CameraSourceTimeLapse(); 4365e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra 4478eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra // If the frame capture interval is large, read will block for a long time. 4578eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra // Due to the way the mediaRecorder framework works, a stop() call from 4678eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra // mediaRecorder waits until the read returns, causing a long wait for 4778eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra // stop() to return. To avoid this, we can make read() return a copy of the 4878eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra // last read frame with the same time stamp frequently. This keeps the 4978eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra // read() call from blocking too long. Calling this function quickly 5078eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra // captures another frame, keeps its copy, and enables this mode of read() 5178eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra // returning quickly. 5278eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra void startQuickReadReturns(); 5378eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra 5465e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatraprivate: 5565e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra // If true, will use still camera takePicture() for time lapse frames 5665e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra // If false, will use the videocamera frames instead. 5765e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra bool mUseStillCameraForTimeLapse; 5865e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra 59c4e47d1e81c4e4403663cb911e98dbf3ada9942cNipun Kwatra // Size of picture taken from still camera. This may be larger than the size 60c4e47d1e81c4e4403663cb911e98dbf3ada9942cNipun Kwatra // of the video, as still camera may not support the exact video resolution 61c4e47d1e81c4e4403663cb911e98dbf3ada9942cNipun Kwatra // demanded. See setPictureSizeToClosestSupported(). 62c4e47d1e81c4e4403663cb911e98dbf3ada9942cNipun Kwatra int32_t mPictureWidth; 63c4e47d1e81c4e4403663cb911e98dbf3ada9942cNipun Kwatra int32_t mPictureHeight; 64c4e47d1e81c4e4403663cb911e98dbf3ada9942cNipun Kwatra 65c4e47d1e81c4e4403663cb911e98dbf3ada9942cNipun Kwatra // size of the encoded video. 66c4e47d1e81c4e4403663cb911e98dbf3ada9942cNipun Kwatra int32_t mVideoWidth; 67c4e47d1e81c4e4403663cb911e98dbf3ada9942cNipun Kwatra int32_t mVideoHeight; 68c4e47d1e81c4e4403663cb911e98dbf3ada9942cNipun Kwatra 69c4e47d1e81c4e4403663cb911e98dbf3ada9942cNipun Kwatra // True if we need to crop the still camera image to get the video frame. 70c4e47d1e81c4e4403663cb911e98dbf3ada9942cNipun Kwatra bool mNeedCropping; 71c4e47d1e81c4e4403663cb911e98dbf3ada9942cNipun Kwatra 72c4e47d1e81c4e4403663cb911e98dbf3ada9942cNipun Kwatra // Start location of the cropping rectangle. 73c4e47d1e81c4e4403663cb911e98dbf3ada9942cNipun Kwatra int32_t mCropRectStartX; 74c4e47d1e81c4e4403663cb911e98dbf3ada9942cNipun Kwatra int32_t mCropRectStartY; 75c4e47d1e81c4e4403663cb911e98dbf3ada9942cNipun Kwatra 7665e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra // Time between capture of two frames during time lapse recording 7765e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra // Negative value indicates that timelapse is disabled. 7865e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra int64_t mTimeBetweenTimeLapseFrameCaptureUs; 7965e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra 8065e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra // Time between two frames in final video (1/frameRate) 8165e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra int64_t mTimeBetweenTimeLapseVideoFramesUs; 8265e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra 8365e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra // Real timestamp of the last encoded time lapse frame 8465e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra int64_t mLastTimeLapseFrameRealTimestampUs; 8565e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra 8665e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra // Thread id of thread which takes still picture and sleeps in a loop. 8765e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra pthread_t mThreadTimeLapse; 8865e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra 8965e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra // Variable set in dataCallbackTimestamp() to help skipCurrentFrame() 9065e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra // to know if current frame needs to be skipped. 9165e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra bool mSkipCurrentFrame; 9265e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra 9378eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra // Lock for accessing mCameraIdle 9478eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra Mutex mCameraIdleLock; 9578eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra 9678eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra // Condition variable to wait on if camera is is not yet idle. Once the 9778eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra // camera gets idle, this variable will be signalled. 9878eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra Condition mCameraIdleCondition; 9978eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra 1000aacf105eea098a0b47761a4a9a5c4d820611f2dNipun Kwatra // True if camera is in preview mode and ready for takePicture(). 10178eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra // False after a call to takePicture() but before the final compressed 10278eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra // data callback has been called and preview has been restarted. 10378eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra volatile bool mCameraIdle; 10478eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra 10578eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra // True if stop() is waiting for camera to get idle, i.e. for the last 10678eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra // takePicture() to complete. This is needed so that dataCallbackTimestamp() 10778eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra // can return immediately. 10878eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra volatile bool mStopWaitingForIdleCamera; 10978eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra 11078eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra // Lock for accessing quick stop variables. 11178eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra Mutex mQuickStopLock; 11278eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra 11378eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra // Condition variable to wake up still picture thread. 11478eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra Condition mTakePictureCondition; 11578eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra 11678eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra // mQuickStop is set to true if we use quick read() returns, otherwise it is set 11778eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra // to false. Once in this mode read() return a copy of the last read frame 11878eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra // with the same time stamp. See startQuickReadReturns(). 11978eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra volatile bool mQuickStop; 12078eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra 12178eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra // Forces the next frame passed to dataCallbackTimestamp() to be read 12278eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra // as a time lapse frame. Used by startQuickReadReturns() so that the next 12378eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra // frame wakes up any blocking read. 12478eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra volatile bool mForceRead; 12578eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra 12678eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra // Stores a copy of the MediaBuffer read in the last read() call after 12778eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra // mQuickStop was true. 12878eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra MediaBuffer* mLastReadBufferCopy; 12978eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra 13078eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra // Status code for last read. 13178eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra status_t mLastReadStatus; 1320aacf105eea098a0b47761a4a9a5c4d820611f2dNipun Kwatra 13354ff19ac69ace7c05ea90d225e26dab3b133f487James Dong CameraSourceTimeLapse( 13454ff19ac69ace7c05ea90d225e26dab3b133f487James Dong const sp<ICamera> &camera, 13554ff19ac69ace7c05ea90d225e26dab3b133f487James Dong int32_t cameraId, 13654ff19ac69ace7c05ea90d225e26dab3b133f487James Dong Size videoSize, 13754ff19ac69ace7c05ea90d225e26dab3b133f487James Dong int32_t videoFrameRate, 13854ff19ac69ace7c05ea90d225e26dab3b133f487James Dong const sp<Surface>& surface, 13954ff19ac69ace7c05ea90d225e26dab3b133f487James Dong int64_t timeBetweenTimeLapseFrameCaptureUs); 14065e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra 14178eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra // Wrapper over CameraSource::signalBufferReturned() to implement quick stop. 14278eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra // It only handles the case when mLastReadBufferCopy is signalled. Otherwise 14378eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra // it calls the base class' function. 14478eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra virtual void signalBufferReturned(MediaBuffer* buffer); 14578eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra 14678eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra // Wrapper over CameraSource::read() to implement quick stop. 14778eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra virtual status_t read(MediaBuffer **buffer, const ReadOptions *options = NULL); 14878eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra 14965e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra // For still camera case starts a thread which calls camera's takePicture() 15065e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra // in a loop. For video camera case, just starts the camera's video recording. 15165e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra virtual void startCameraRecording(); 15265e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra 15365e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra // For still camera case joins the thread created in startCameraRecording(). 15465e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra // For video camera case, just stops the camera's video recording. 15565e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra virtual void stopCameraRecording(); 15665e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra 15765e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra // For still camera case don't need to do anything as memory is locally 15865e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra // allocated with refcounting. 15965e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra // For video camera case just tell the camera to release the frame. 16065e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra virtual void releaseRecordingFrame(const sp<IMemory>& frame); 16165e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra 16265e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra // mSkipCurrentFrame is set to true in dataCallbackTimestamp() if the current 16365e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra // frame needs to be skipped and this function just returns the value of mSkipCurrentFrame. 16465e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra virtual bool skipCurrentFrame(int64_t timestampUs); 16565e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra 16665e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra // Handles the callback to handle raw frame data from the still camera. 16765e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra // Creates a copy of the frame data as the camera can reuse the frame memory 16865e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra // once this callback returns. The function also sets a new timstamp corresponding 16965e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra // to one frame time ahead of the last encoded frame's time stamp. It then 17065e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra // calls dataCallbackTimestamp() of the base class with the copied data and the 17165e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra // modified timestamp, which will think that it recieved the frame from a video 17265e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra // camera and proceed as usual. 17365e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra virtual void dataCallback(int32_t msgType, const sp<IMemory> &data); 17465e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra 17565e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra // In the video camera case calls skipFrameAndModifyTimeStamp() to modify 17665e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra // timestamp and set mSkipCurrentFrame. 17765e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra // Then it calls the base CameraSource::dataCallbackTimestamp() 17865e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra virtual void dataCallbackTimestamp(int64_t timestampUs, int32_t msgType, 17965e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra const sp<IMemory> &data); 18065e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra 18178eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra // Convenience function to fill mLastReadBufferCopy from the just read 18278eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra // buffer. 18378eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra void fillLastReadBufferCopy(MediaBuffer& sourceBuffer); 18478eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra 185155e833a7a5fc3e193691324cf9326da1bc3289aNipun Kwatra // If the passed in size (width x height) is a supported preview size, 186155e833a7a5fc3e193691324cf9326da1bc3289aNipun Kwatra // the function sets the camera's preview size to it and returns true. 187155e833a7a5fc3e193691324cf9326da1bc3289aNipun Kwatra // Otherwise returns false. 188155e833a7a5fc3e193691324cf9326da1bc3289aNipun Kwatra bool trySettingPreviewSize(int32_t width, int32_t height); 189155e833a7a5fc3e193691324cf9326da1bc3289aNipun Kwatra 190c4e47d1e81c4e4403663cb911e98dbf3ada9942cNipun Kwatra // The still camera may not support the demanded video width and height. 191c4e47d1e81c4e4403663cb911e98dbf3ada9942cNipun Kwatra // We look for the supported picture sizes from the still camera and 19240e2f3f9b41f44bdb59f7708a421b87f169a6edeNipun Kwatra // choose the smallest one with either dimensions higher than the corresponding 19340e2f3f9b41f44bdb59f7708a421b87f169a6edeNipun Kwatra // video dimensions. The still picture will be cropped to get the video frame. 19440e2f3f9b41f44bdb59f7708a421b87f169a6edeNipun Kwatra // The function returns true if the camera supports picture sizes greater than 19540e2f3f9b41f44bdb59f7708a421b87f169a6edeNipun Kwatra // or equal to the passed in width and height, and false otherwise. 19640e2f3f9b41f44bdb59f7708a421b87f169a6edeNipun Kwatra bool setPictureSizeToClosestSupported(int32_t width, int32_t height); 197c4e47d1e81c4e4403663cb911e98dbf3ada9942cNipun Kwatra 198c4e47d1e81c4e4403663cb911e98dbf3ada9942cNipun Kwatra // Computes the offset of the rectangle from where to start cropping the 199c4e47d1e81c4e4403663cb911e98dbf3ada9942cNipun Kwatra // still image into the video frame. We choose the center of the image to be 200c4e47d1e81c4e4403663cb911e98dbf3ada9942cNipun Kwatra // cropped. The offset is stored in (mCropRectStartX, mCropRectStartY). 201c4e47d1e81c4e4403663cb911e98dbf3ada9942cNipun Kwatra bool computeCropRectangleOffset(); 202c4e47d1e81c4e4403663cb911e98dbf3ada9942cNipun Kwatra 203c4e47d1e81c4e4403663cb911e98dbf3ada9942cNipun Kwatra // Crops the source data into a smaller image starting at 204c4e47d1e81c4e4403663cb911e98dbf3ada9942cNipun Kwatra // (mCropRectStartX, mCropRectStartY) and of the size of the video frame. 205c4e47d1e81c4e4403663cb911e98dbf3ada9942cNipun Kwatra // The data is returned into a newly allocated IMemory. 206c4e47d1e81c4e4403663cb911e98dbf3ada9942cNipun Kwatra sp<IMemory> cropYUVImage(const sp<IMemory> &source_data); 207c4e47d1e81c4e4403663cb911e98dbf3ada9942cNipun Kwatra 20865e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra // When video camera is used for time lapse capture, returns true 20965e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra // until enough time has passed for the next time lapse frame. When 21065e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra // the frame needs to be encoded, it returns false and also modifies 21165e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra // the time stamp to be one frame time ahead of the last encoded 21265e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra // frame's time stamp. 21365e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra bool skipFrameAndModifyTimeStamp(int64_t *timestampUs); 21465e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra 21565e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra // Wrapper to enter threadTimeLapseEntry() 21665e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra static void *ThreadTimeLapseWrapper(void *me); 21765e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra 21865e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra // Runs a loop which sleeps until a still picture is required 21965e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra // and then calls mCamera->takePicture() to take the still picture. 22065e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra // Used only in the case mUseStillCameraForTimeLapse = true. 22165e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra void threadTimeLapseEntry(); 22265e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra 2230aacf105eea098a0b47761a4a9a5c4d820611f2dNipun Kwatra // Wrapper to enter threadStartPreview() 2240aacf105eea098a0b47761a4a9a5c4d820611f2dNipun Kwatra static void *ThreadStartPreviewWrapper(void *me); 2250aacf105eea098a0b47761a4a9a5c4d820611f2dNipun Kwatra 2260aacf105eea098a0b47761a4a9a5c4d820611f2dNipun Kwatra // Starts the camera's preview. 2270aacf105eea098a0b47761a4a9a5c4d820611f2dNipun Kwatra void threadStartPreview(); 2280aacf105eea098a0b47761a4a9a5c4d820611f2dNipun Kwatra 2290aacf105eea098a0b47761a4a9a5c4d820611f2dNipun Kwatra // Starts thread ThreadStartPreviewWrapper() for restarting preview. 2300aacf105eea098a0b47761a4a9a5c4d820611f2dNipun Kwatra // Needs to be done in a thread so that dataCallback() which calls this function 2310aacf105eea098a0b47761a4a9a5c4d820611f2dNipun Kwatra // can return, and the camera can know that takePicture() is done. 2320aacf105eea098a0b47761a4a9a5c4d820611f2dNipun Kwatra void restartPreview(); 2330aacf105eea098a0b47761a4a9a5c4d820611f2dNipun Kwatra 23465e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra // Creates a copy of source_data into a new memory of final type MemoryBase. 23565e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra sp<IMemory> createIMemoryCopy(const sp<IMemory> &source_data); 23665e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra 23765e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra CameraSourceTimeLapse(const CameraSourceTimeLapse &); 23865e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra CameraSourceTimeLapse &operator=(const CameraSourceTimeLapse &); 23965e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra}; 24065e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra 24165e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra} // namespace android 24265e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra 24365e7e6facda89927cb26594b3b65ae81b3235ebcNipun Kwatra#endif // CAMERA_SOURCE_TIME_LAPSE_H_ 244