From b1fb6079ef7f005c4be8de76bef57ce10c1efe76 Mon Sep 17 00:00:00 2001 From: Nipun Kwatra Date: Fri, 30 Jul 2010 18:30:55 -0700 Subject: [PATCH] Implementing getSupportedPictureSizes Go through all the supported picture sizes and choose the smallest one with both dimensions higher than the passed in video width and height. Change-Id: I4e9fe7a6384a0feeb9e069239ec68c70fb5f3033 --- .../media/stagefright/CameraSourceTimeLapse.h | 8 +++-- .../libstagefright/CameraSourceTimeLapse.cpp | 33 +++++++++++++++---- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/include/media/stagefright/CameraSourceTimeLapse.h b/include/media/stagefright/CameraSourceTimeLapse.h index 8ea532c75a093..7135a33f637e6 100644 --- a/include/media/stagefright/CameraSourceTimeLapse.h +++ b/include/media/stagefright/CameraSourceTimeLapse.h @@ -126,9 +126,11 @@ private: // The still camera may not support the demanded video width and height. // We look for the supported picture sizes from the still camera and - // choose the size with either dimensions higher than the corresponding video - // dimensions. The still picture will be cropped to get the video frame. - void setPictureSizeToClosestSupported(int32_t width, int32_t height); + // choose the smallest one with either dimensions higher than the corresponding + // video dimensions. The still picture will be cropped to get the video frame. + // The function returns true if the camera supports picture sizes greater than + // or equal to the passed in width and height, and false otherwise. + bool setPictureSizeToClosestSupported(int32_t width, int32_t height); // Computes the offset of the rectangle from where to start cropping the // still image into the video frame. We choose the center of the image to be diff --git a/media/libstagefright/CameraSourceTimeLapse.cpp b/media/libstagefright/CameraSourceTimeLapse.cpp index a01450bc160f8..854afddc72bf8 100644 --- a/media/libstagefright/CameraSourceTimeLapse.cpp +++ b/media/libstagefright/CameraSourceTimeLapse.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include "OMX_Video.h" namespace android { @@ -79,7 +80,7 @@ CameraSourceTimeLapse::CameraSourceTimeLapse(const sp &camera, mVideoWidth = width; mVideoHeight = height; if (mUseStillCameraForTimeLapse) { - setPictureSizeToClosestSupported(width, height); + CHECK(setPictureSizeToClosestSupported(width, height)); mNeedCropping = computeCropRectangleOffset(); mMeta->setInt32(kKeyWidth, width); mMeta->setInt32(kKeyHeight, height); @@ -89,11 +90,31 @@ CameraSourceTimeLapse::CameraSourceTimeLapse(const sp &camera, CameraSourceTimeLapse::~CameraSourceTimeLapse() { } -void CameraSourceTimeLapse::setPictureSizeToClosestSupported(int32_t width, int32_t height) { - // TODO: Currently fixed to the highest resolution. - // Need to poll the camera and set accordingly. - mPictureWidth = 2048; - mPictureHeight = 1536; +bool CameraSourceTimeLapse::setPictureSizeToClosestSupported(int32_t width, int32_t height) { + int64_t token = IPCThreadState::self()->clearCallingIdentity(); + String8 s = mCamera->getParameters(); + IPCThreadState::self()->restoreCallingIdentity(token); + + CameraParameters params(s); + Vector supportedSizes; + params.getSupportedPictureSizes(supportedSizes); + + int32_t minPictureSize = INT_MAX; + 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)) { + int32_t pictureSize = pictureWidth*pictureHeight; + if (pictureSize < minPictureSize) { + minPictureSize = pictureSize; + mPictureWidth = pictureWidth; + mPictureHeight = pictureHeight; + } + } + } + LOGV("Picture size = (%d, %d)", mPictureWidth, mPictureHeight); + return (minPictureSize != INT_MAX); } bool CameraSourceTimeLapse::computeCropRectangleOffset() {