Bug 808099 - Write the correct rotational meta-data to the video stream. r=cjones

This commit is contained in:
Mike Habicher 2012-11-06 22:32:01 -05:00
Родитель 3a0845deea
Коммит 39bf4c9296
4 изменённых файлов: 39 добавлений и 12 удалений

Просмотреть файл

@ -191,7 +191,6 @@ nsGonkCameraControl::nsGonkCameraControl(uint32_t aCameraId, nsIThread* aCameraT
, mDiscardedFrameCount(0) , mDiscardedFrameCount(0)
, mMediaProfiles(nullptr) , mMediaProfiles(nullptr)
, mRecorder(nullptr) , mRecorder(nullptr)
, mVideoRotation(0)
, mVideoFile() , mVideoFile()
, mProfileManager(nullptr) , mProfileManager(nullptr)
, mRecorderProfile(nullptr) , mRecorderProfile(nullptr)
@ -1172,7 +1171,7 @@ nsGonkCameraControl::HandleRecorderEvent(int msg, int ext1, int ext2)
} }
nsresult nsresult
nsGonkCameraControl::SetupRecording(int aFd, int64_t aMaxFileSizeBytes, int64_t aMaxVideoLengthMs) nsGonkCameraControl::SetupRecording(int aFd, int aRotation, int64_t aMaxFileSizeBytes, int64_t aMaxVideoLengthMs)
{ {
// choosing a size big enough to hold the params // choosing a size big enough to hold the params
const size_t SIZE = 256; const size_t SIZE = 256;
@ -1200,7 +1199,15 @@ nsGonkCameraControl::SetupRecording(int aFd, int64_t aMaxFileSizeBytes, int64_t
snprintf(buffer, SIZE, "max-filesize=%lld", aMaxFileSizeBytes); snprintf(buffer, SIZE, "max-filesize=%lld", aMaxFileSizeBytes);
CHECK_SETARG(mRecorder->setParameters(String8(buffer))); CHECK_SETARG(mRecorder->setParameters(String8(buffer)));
snprintf(buffer, SIZE, "video-param-rotation-angle-degrees=%d", mVideoRotation); // adjust rotation by camera sensor offset
int r = aRotation;
r += GonkCameraHardware::GetSensorOrientation(mHwHandle, GonkCameraHardware::RAW_SENSOR_ORIENTATION);
r %= 360;
r += 45;
r /= 90;
r *= 90;
DOM_CAMERA_LOGI("setting video rotation to %d degrees (mapped from %d)\n", r, aRotation);
snprintf(buffer, SIZE, "video-param-rotation-angle-degrees=%d", r);
CHECK_SETARG(mRecorder->setParameters(String8(buffer))); CHECK_SETARG(mRecorder->setParameters(String8(buffer)));
CHECK_SETARG(mRecorder->setListener(new GonkRecorderListener(this))); CHECK_SETARG(mRecorder->setListener(new GonkRecorderListener(this)));
@ -1218,7 +1225,6 @@ nsGonkCameraControl::GetPreviewStreamVideoModeImpl(GetPreviewStreamVideoModeTask
StopPreviewInternal(true /* forced */); StopPreviewInternal(true /* forced */);
// setup the video mode // setup the video mode
mVideoRotation = aGetPreviewStreamVideoMode->mOptions.rotation;
nsresult rv = SetupVideoMode(aGetPreviewStreamVideoMode->mOptions.profile); nsresult rv = SetupVideoMode(aGetPreviewStreamVideoMode->mOptions.profile);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
@ -1226,7 +1232,7 @@ nsGonkCameraControl::GetPreviewStreamVideoModeImpl(GetPreviewStreamVideoModeTask
int width = video->GetWidth(); int width = video->GetWidth();
int height = video->GetHeight(); int height = video->GetHeight();
int fps = video->GetFramerate(); int fps = video->GetFramerate();
DOM_CAMERA_LOGI("recording preview format: %d x %d (rotated %d degrees)\n", width, height, fps); DOM_CAMERA_LOGI("recording preview format: %d x %d (%d fps)\n", width, height, fps);
// create and return new preview stream object // create and return new preview stream object
nsCOMPtr<GetPreviewStreamResult> getPreviewStreamResult = new GetPreviewStreamResult(this, width, height, fps, aGetPreviewStreamVideoMode->mOnSuccessCb, mWindowId); nsCOMPtr<GetPreviewStreamResult> getPreviewStreamResult = new GetPreviewStreamResult(this, width, height, fps, aGetPreviewStreamVideoMode->mOnSuccessCb, mWindowId);

Просмотреть файл

@ -56,7 +56,7 @@ public:
nsresult GetVideoSizes(nsTArray<CameraSize>& aVideoSizes); nsresult GetVideoSizes(nsTArray<CameraSize>& aVideoSizes);
nsresult PushParameters(); nsresult PushParameters();
nsresult SetupRecording(int aFd, int64_t aMaxFileSizeBytes = -1, int64_t aMaxVideoLengthMs = -1); nsresult SetupRecording(int aFd, int aRotation = 0, int64_t aMaxFileSizeBytes = -1, int64_t aMaxVideoLengthMs = -1);
nsresult SetupVideoMode(const nsAString& aProfile); nsresult SetupVideoMode(const nsAString& aProfile);
void AutoFocusComplete(bool aSuccess); void AutoFocusComplete(bool aSuccess);
@ -107,7 +107,6 @@ protected:
android::MediaProfiles* mMediaProfiles; android::MediaProfiles* mMediaProfiles;
android::GonkRecorder* mRecorder; android::GonkRecorder* mRecorder;
uint32_t mVideoRotation;
nsString mVideoFile; nsString mVideoFile;
// camcorder profile settings for the desired quality level // camcorder profile settings for the desired quality level

Просмотреть файл

@ -193,18 +193,21 @@ GonkCameraHardware::Init()
if (rv != 0) { if (rv != 0) {
return; return;
} }
mSensorOrientation = info.orientation; mRawSensorOrientation = info.orientation;
mSensorOrientation = mRawSensorOrientation;
// Some kernels report the wrong sensor orientation through // Some kernels report the wrong sensor orientation through
// get_camera_info()... // get_camera_info()...
char propname[PROP_NAME_MAX]; char propname[PROP_NAME_MAX];
char prop[PROP_VALUE_MAX]; char prop[PROP_VALUE_MAX];
int offset = 0;
snprintf(propname, sizeof(propname), "ro.moz.cam.%d.sensor_offset", mCamera); snprintf(propname, sizeof(propname), "ro.moz.cam.%d.sensor_offset", mCamera);
if (__system_property_get(propname, prop) > 0) { if (__system_property_get(propname, prop) > 0) {
int offset = clamped(atoi(prop), 0, 270); offset = clamped(atoi(prop), 0, 270);
mSensorOrientation += offset; mSensorOrientation += offset;
mSensorOrientation %= 360; mSensorOrientation %= 360;
} }
DOM_CAMERA_LOGI("Sensor orientation: base=%d, offset=%d, final=%d\n", info.orientation, offset, mSensorOrientation);
if (sHwHandle == 0) { if (sHwHandle == 0) {
sHwHandle = 1; // don't use 0 sHwHandle = 1; // don't use 0
@ -271,14 +274,24 @@ GonkCameraHardware::GetHandle(GonkCamera* aTarget, uint32_t aCamera)
} }
int int
GonkCameraHardware::GetSensorOrientation(uint32_t aHwHandle) GonkCameraHardware::GetSensorOrientation(uint32_t aHwHandle, uint32_t aType)
{ {
DOM_CAMERA_LOGI("%s: aHwHandle = %d\n", __func__, aHwHandle); DOM_CAMERA_LOGI("%s: aHwHandle = %d\n", __func__, aHwHandle);
GonkCameraHardware* hw = GetHardware(aHwHandle); GonkCameraHardware* hw = GetHardware(aHwHandle);
if (!hw) { if (!hw) {
return 0; return 0;
} }
switch (aType) {
case OFFSET_SENSOR_ORIENTATION:
return hw->mSensorOrientation; return hw->mSensorOrientation;
case RAW_SENSOR_ORIENTATION:
return hw->mRawSensorOrientation;
default:
DOM_CAMERA_LOGE("%s:%d : unknown aType=%d\n", __func__, __LINE__, aType);
return 0;
}
} }
int int

Просмотреть файл

@ -65,8 +65,16 @@ public:
* right edge of the screen in natural orientation, the value should be * 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 * 90. If the top side of a front-facing camera sensor is aligned with the
* right of the screen, the value should be 270. * right of the screen, the value should be 270.
*
* RAW_SENSOR_ORIENTATION is the uncorrected orientation returned directly
* by get_camera_info(); OFFSET_SENSOR_ORIENTATION is the offset adjusted
* orientation.
*/ */
static int GetSensorOrientation(uint32_t aHwHandle); enum {
RAW_SENSOR_ORIENTATION,
OFFSET_SENSOR_ORIENTATION
};
static int GetSensorOrientation(uint32_t aHwHandle, uint32_t aType = OFFSET_SENSOR_ORIENTATION);
static int AutoFocus(uint32_t aHwHandle); static int AutoFocus(uint32_t aHwHandle);
static void CancelAutoFocus(uint32_t aHwHandle); static void CancelAutoFocus(uint32_t aHwHandle);
@ -116,6 +124,7 @@ protected:
#endif #endif
sp<GonkCameraListener> mListener; sp<GonkCameraListener> mListener;
bool mInitialized; bool mInitialized;
int mRawSensorOrientation;
int mSensorOrientation; int mSensorOrientation;
bool IsInitialized() bool IsInitialized()