Bug 803733 - Normalize camera sensor orientation. r=cjones

This commit is contained in:
Michael Vines 2012-10-24 17:23:01 -07:00
parent d6cc9a88c2
commit 47d6f6b628
3 changed files with 45 additions and 0 deletions

View File

@ -657,6 +657,7 @@ nsGonkCameraControl::TakePictureImpl(TakePictureTask* aTakePicture)
// Convert 'rotation' to a positive value from 0..270 degrees, in steps of 90.
uint32_t r = static_cast<uint32_t>(aTakePicture->mRotation);
r += GonkCameraHardware::GetSensorOrientation(mHwHandle);
r %= 360;
r += 45;
r /= 90;

View File

@ -19,6 +19,7 @@
#include "GonkCameraHwMgr.h"
#include "GonkNativeWindow.h"
#include "CameraCommon.h"
#include <sys/system_properties.h>
using namespace mozilla;
using namespace mozilla::layers;
@ -187,6 +188,24 @@ GonkCameraHardware::Init()
return;
}
struct camera_info info;
int rv = mModule->get_camera_info(mCamera, &info);
if (rv != 0) {
return;
}
mSensorOrientation = info.orientation;
// Some kernels report the wrong sensor orientation through
// get_camera_info()...
char propname[PROP_NAME_MAX];
char prop[PROP_VALUE_MAX];
snprintf(propname, sizeof(propname), "ro.moz.cam.%d.sensor_offset", mCamera);
if (__system_property_get(propname, prop) > 0) {
int offset = clamped(atoi(prop), 0, 270);
mSensorOrientation += offset;
mSensorOrientation %= 360;
}
if (sHwHandle == 0) {
sHwHandle = 1; // don't use 0
}
@ -251,6 +270,17 @@ GonkCameraHardware::GetHandle(GonkCamera* aTarget, uint32_t aCamera)
return 0;
}
int
GonkCameraHardware::GetSensorOrientation(uint32_t aHwHandle)
{
DOM_CAMERA_LOGI("%s: aHwHandle = %d\n", __func__, aHwHandle);
GonkCameraHardware* hw = GetHardware(aHwHandle);
if (!hw) {
return 0;
}
return hw->mSensorOrientation;
}
int
GonkCameraHardware::AutoFocus(uint32_t aHwHandle)
{

View File

@ -55,6 +55,19 @@ public:
static void ReleaseHandle(uint32_t aHwHandle);
static uint32_t GetHandle(GonkCamera* aTarget, uint32_t aCamera);
/**
* The physical orientation of the camera sensor: 0, 90, 180, or 270.
*
* For example, suppose a device has a naturally tall screen. The
* back-facing camera sensor is mounted in landscape. You are looking at
* the screen. If the top side of the camera sensor is aligned with the
* right edge of the screen in natural orientation, the value should be
* 90. If the top side of a front-facing camera sensor is aligned with the
* right of the screen, the value should be 270.
*/
static int GetSensorOrientation(uint32_t aHwHandle);
static int AutoFocus(uint32_t aHwHandle);
static void CancelAutoFocus(uint32_t aHwHandle);
static int TakePicture(uint32_t aHwHandle);
@ -103,6 +116,7 @@ protected:
#endif
sp<GonkCameraListener> mListener;
bool mInitialized;
int mSensorOrientation;
bool IsInitialized()
{