summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/CameraSourceTimeLapse.cpp
diff options
context:
space:
mode:
authorNipun Kwatra <nkwatra@google.com>2010-09-02 11:43:15 -0700
committerNipun Kwatra <nkwatra@google.com>2010-09-03 17:09:36 -0700
commit155e833a7a5fc3e193691324cf9326da1bc3289a (patch)
treebf8997c55b22617004836014389664dcb56ebf05 /media/libstagefright/CameraSourceTimeLapse.cpp
parentcfe88a20345dad981842b2c8092e4c704d3f98b4 (diff)
downloadframeworks_av-155e833a7a5fc3e193691324cf9326da1bc3289a.zip
frameworks_av-155e833a7a5fc3e193691324cf9326da1bc3289a.tar.gz
frameworks_av-155e833a7a5fc3e193691324cf9326da1bc3289a.tar.bz2
Moving decision to use still camera to CameraSourceTimeLapse
CameraSourceTimeLapse now decides whether to use still or video camera automatically. It checks if the passed in size is a valid preview size and if it is, then uses the video camera else uses the still camera. Removed from StagefrightRecorder the support to set parameter useStillCameraForTimeLapse. Change-Id: I71f5b0fc7080ca524792381efe918d22e41a7f36
Diffstat (limited to 'media/libstagefright/CameraSourceTimeLapse.cpp')
-rw-r--r--media/libstagefright/CameraSourceTimeLapse.cpp50
1 files changed, 41 insertions, 9 deletions
diff --git a/media/libstagefright/CameraSourceTimeLapse.cpp b/media/libstagefright/CameraSourceTimeLapse.cpp
index ba99501..7595a28 100644
--- a/media/libstagefright/CameraSourceTimeLapse.cpp
+++ b/media/libstagefright/CameraSourceTimeLapse.cpp
@@ -37,7 +37,7 @@
namespace android {
// static
-CameraSourceTimeLapse *CameraSourceTimeLapse::Create(bool useStillCameraForTimeLapse,
+CameraSourceTimeLapse *CameraSourceTimeLapse::Create(
int64_t timeBetweenTimeLapseFrameCaptureUs,
int32_t width, int32_t height,
int32_t videoFrameRate) {
@@ -47,13 +47,12 @@ CameraSourceTimeLapse *CameraSourceTimeLapse::Create(bool useStillCameraForTimeL
return NULL;
}
- return new CameraSourceTimeLapse(camera, useStillCameraForTimeLapse,
- timeBetweenTimeLapseFrameCaptureUs, width, height, videoFrameRate);
+ return new CameraSourceTimeLapse(camera, timeBetweenTimeLapseFrameCaptureUs,
+ width, height, videoFrameRate);
}
// static
CameraSourceTimeLapse *CameraSourceTimeLapse::CreateFromCamera(const sp<Camera> &camera,
- bool useStillCameraForTimeLapse,
int64_t timeBetweenTimeLapseFrameCaptureUs,
int32_t width, int32_t height,
int32_t videoFrameRate) {
@@ -61,17 +60,15 @@ CameraSourceTimeLapse *CameraSourceTimeLapse::CreateFromCamera(const sp<Camera>
return NULL;
}
- return new CameraSourceTimeLapse(camera, useStillCameraForTimeLapse,
- timeBetweenTimeLapseFrameCaptureUs, width, height, videoFrameRate);
+ return new CameraSourceTimeLapse(camera, timeBetweenTimeLapseFrameCaptureUs,
+ width, height, videoFrameRate);
}
CameraSourceTimeLapse::CameraSourceTimeLapse(const sp<Camera> &camera,
- bool useStillCameraForTimeLapse,
int64_t timeBetweenTimeLapseFrameCaptureUs,
int32_t width, int32_t height,
int32_t videoFrameRate)
: CameraSource(camera),
- mUseStillCameraForTimeLapse(useStillCameraForTimeLapse),
mTimeBetweenTimeLapseFrameCaptureUs(timeBetweenTimeLapseFrameCaptureUs),
mTimeBetweenTimeLapseVideoFramesUs(1E6/videoFrameRate),
mLastTimeLapseFrameRealTimestampUs(0),
@@ -80,7 +77,13 @@ CameraSourceTimeLapse::CameraSourceTimeLapse(const sp<Camera> &camera,
LOGV("starting time lapse mode");
mVideoWidth = width;
mVideoHeight = height;
- if (mUseStillCameraForTimeLapse) {
+
+ if (trySettingPreviewSize(width, height)) {
+ mUseStillCameraForTimeLapse = false;
+ } else {
+ // TODO: Add a check to see that mTimeBetweenTimeLapseFrameCaptureUs is greater
+ // than the fastest rate at which the still camera can take pictures.
+ mUseStillCameraForTimeLapse = true;
CHECK(setPictureSizeToClosestSupported(width, height));
mNeedCropping = computeCropRectangleOffset();
mMeta->setInt32(kKeyWidth, width);
@@ -91,6 +94,35 @@ CameraSourceTimeLapse::CameraSourceTimeLapse(const sp<Camera> &camera,
CameraSourceTimeLapse::~CameraSourceTimeLapse() {
}
+bool CameraSourceTimeLapse::trySettingPreviewSize(int32_t width, int32_t height) {
+ int64_t token = IPCThreadState::self()->clearCallingIdentity();
+ String8 s = mCamera->getParameters();
+ IPCThreadState::self()->restoreCallingIdentity(token);
+
+ CameraParameters params(s);
+ Vector<Size> supportedSizes;
+ params.getSupportedPreviewSizes(supportedSizes);
+
+ bool previewSizeSupported = false;
+ for (uint32_t i = 0; i < supportedSizes.size(); ++i) {
+ int32_t pictureWidth = supportedSizes[i].width;
+ int32_t pictureHeight = supportedSizes[i].height;
+
+ if ((pictureWidth == width) && (pictureHeight == height)) {
+ previewSizeSupported = true;
+ }
+ }
+
+ if (previewSizeSupported) {
+ LOGV("Video size (%d, %d) is a supported preview size", width, height);
+ params.setPreviewSize(width, height);
+ CHECK(mCamera->setParameters(params.flatten()));
+ return true;
+ }
+
+ return false;
+}
+
bool CameraSourceTimeLapse::setPictureSizeToClosestSupported(int32_t width, int32_t height) {
int64_t token = IPCThreadState::self()->clearCallingIdentity();
String8 s = mCamera->getParameters();