Bug 1065957 - [B2G] Correct photo orientation. r=roc

This commit is contained in:
Alfredo Yang 2014-09-17 02:26:00 -04:00
Родитель 6a79dce6d7
Коммит b822ee259b
2 изменённых файлов: 50 добавлений и 1 удалений

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

@ -101,6 +101,7 @@ public:
, mCallbackMonitor("WebRTCCamera.CallbackMonitor")
, mRotation(0)
, mBackCamera(false)
, mOrientationChanged(true) // Correct the orientation at first time takePhoto.
, mCaptureIndex(aIndex)
, mMediaSource(aMediaSource)
, mMonitor("WebRTCCamera.Monitor")
@ -202,6 +203,10 @@ public:
nsresult TakePhoto(PhotoCallback* aCallback) MOZ_OVERRIDE;
// It sets the correct photo orientation via camera parameter according to
// current screen orientation.
nsresult UpdatePhotoOrientation();
#endif
// This runnable is for creating a temporary file on the main thread.
@ -245,6 +250,7 @@ private:
int mRotation;
int mCameraAngle; // See dom/base/ScreenOrientation.h
bool mBackCamera;
bool mOrientationChanged; // True when screen rotates.
#else
webrtc::VideoEngine* mVideoEngine; // Weak reference, don't free.
webrtc::ViEBase* mViEBase;

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

@ -799,6 +799,8 @@ MediaEngineWebRTCVideoSource::Notify(const hal::ScreenConfiguration& aConfigurat
mRotation, mCaptureIndex, mBackCamera, mCameraAngle));
}
#endif
mOrientationChanged = true;
}
void
@ -1080,7 +1082,11 @@ MediaEngineWebRTCVideoSource::TakePhoto(PhotoCallback* aCallback)
// If other callback exists, that means there is a captured picture on the way,
// it doesn't need to TakePicture() again.
if (!mPhotoCallbacks.Length()) {
nsresult rv = mCameraControl->TakePicture();
nsresult rv;
if (mOrientationChanged) {
UpdatePhotoOrientation();
}
rv = mCameraControl->TakePicture();
if (NS_FAILED(rv)) {
return rv;
}
@ -1091,6 +1097,43 @@ MediaEngineWebRTCVideoSource::TakePhoto(PhotoCallback* aCallback)
return NS_OK;
}
nsresult
MediaEngineWebRTCVideoSource::UpdatePhotoOrientation()
{
MOZ_ASSERT(NS_IsMainThread());
hal::ScreenConfiguration config;
hal::GetCurrentScreenConfiguration(&config);
// The rotation angle is clockwise.
int orientation = 0;
switch (config.orientation()) {
case eScreenOrientation_PortraitPrimary:
orientation = 0;
break;
case eScreenOrientation_PortraitSecondary:
orientation = 180;
break;
case eScreenOrientation_LandscapePrimary:
orientation = 270;
break;
case eScreenOrientation_LandscapeSecondary:
orientation = 90;
break;
}
// Front camera is inverse angle comparing to back camera.
orientation = (mBackCamera ? orientation : (-orientation));
ICameraControlParameterSetAutoEnter batch(mCameraControl);
// It changes the orientation value in EXIF information only.
mCameraControl->Set(CAMERA_PARAM_PICTURE_ROTATION, orientation);
mOrientationChanged = false;
return NS_OK;
}
#endif
}