1.preview方向
Call setDisplayOrientation(int) to ensure
correct orientation of preview.---->设preview
目前追踪到preview设置地方在这里:
frameworks/av/services/camera/libcameraservice/api1/Camera2Client.cpp
status_t Camera2Client::commandSetDisplayOrientationL(int degrees) {
int transform = Parameters::degToTransform(degrees,
mCameraFacing == CAMERA_FACING_FRONT);
if (transform == -1) {
ALOGE("%s: Camera %d: Error setting %d as display orientation value",
__FUNCTION__, mCameraId, degrees);
return BAD_VALUE;
}
SharedParameters::Lock l(mParameters);
if (transform != l.mParameters.previewTransform &&
getPreviewStreamId() != NO_STREAM) {
mDevice->setStreamTransform(getPreviewStreamId(), transform);
}
l.mParameters.previewTransform = transform;
return OK;
}
frameworks/av/services/camera/libcameraservice/api1/client2/Parameters.cpp
int Parameters::degToTransform(int degrees, bool mirror) {
if (!mirror) {
if (degrees == 0) return 0;
else if (degrees == 90) return HAL_TRANSFORM_ROT_90;
else if (degrees == 180) return HAL_TRANSFORM_ROT_180;
else if (degrees == 270) return HAL_TRANSFORM_ROT_270;
} else { // Do mirror (horizontal flip)
if (degrees == 0) { // FLIP_H and ROT_0
return HAL_TRANSFORM_FLIP_H;
} else if (degrees == 90) { // FLIP_H and ROT_90
return HAL_TRANSFORM_FLIP_H | HAL_TRANSFORM_ROT_90;
} else if (degrees == 180) { // FLIP_H and ROT_180
return HAL_TRANSFORM_FLIP_V;
} else if (degrees == 270) { // FLIP_H and ROT_270
return HAL_TRANSFORM_FLIP_V | HAL_TRANSFORM_ROT_90;
}
}
ALOGE("%s: Bad input: %d", __FUNCTION__, degrees);
return -1;
}
可以在degToTransform这里加log看下qq或者微信二维码时候传来的degrees和mirror是什么,和正常preview是不是不一样,然后对应修改
2.系统Camera 预览方向
frameworks/av/camera/CameraUtils.cpp
if (!mirror) {
switch (orientation) {
case 0:
flags = 0;
break;
case 90:
flags = NATIVE_WINDOW_TRANSFORM_ROT_90;
break;
case 180:
flags = NATIVE_WINDOW_TRANSFORM_ROT_180;
break;
case 270:
flags = NATIVE_WINDOW_TRANSFORM_ROT_270;
break;
default:
ALOGE("%s: Invalid HAL android.sensor.orientation value: %d",
__FUNCTION__, orientation);
return INVALID_OPERATION;
}
} else {
// Front camera needs to be horizontally flipped for mirror-like behavior.
// Note: Flips are applied before rotates; using XOR here as some of these flags are
// composed in terms of other flip/rotation flags, and are not bitwise-ORable.
switch (orientation) {
case 0:
flags = NATIVE_WINDOW_TRANSFORM_FLIP_H;
break;
case 90:
flags = NATIVE_WINDOW_TRANSFORM_FLIP_H ^
NATIVE_WINDOW_TRANSFORM_ROT_270;
break;
case 180:
flags = NATIVE_WINDOW_TRANSFORM_FLIP_H ^
NATIVE_WINDOW_TRANSFORM_ROT_180;
break;
case 270:
flags = NATIVE_WINDOW_TRANSFORM_FLIP_H ^
NATIVE_WINDOW_TRANSFORM_ROT_90;
break;
3.修改整体的Camera方向
vendor/mediatek/proprietary/custom/tb8788p1_64_bsp/hal/imgsensor_src/cfg_setting_imgsensor.cpp
static CUSTOM_CFG gCustomCfg[] = {
{
.sensorIdx = IMGSENSOR_SENSOR_IDX_MAIN,
.mclk = CUSTOM_CFG_MCLK_1,
.port = CUSTOM_CFG_CSI_PORT_0,
.dir = CUSTOM_CFG_DIR_REAR,
.bitOrder = CUSTOM_CFG_BITORDER_9_2,
.orientation = 0,
.horizontalFov = 67,
.verticalFov = 49
},
{
.sensorIdx = IMGSENSOR_SENSOR_IDX_SUB,
.mclk = CUSTOM_CFG_MCLK_2,
.port = CUSTOM_CFG_CSI_PORT_1,
.dir = CUSTOM_CFG_DIR_FRONT,
.bitOrder = CUSTOM_CFG_BITORDER_9_2,
.orientation = 0,
.horizontalFov = 63,
.verticalFov = 40
},