background:
System code tracking of camera preview direction and picture direction after taking pictures
See blog:
https://blog.csdn.net/liwei16611/article/details/52206894?locationNum=5&fps=1 camera process
https://www.e-learn.cn/topic/58947 camera2 framework
1. android framework/下各目录作用:
https://blog.csdn.net/yui_hatano/article/details/89517165
framework/av下是多媒体框架,camera在这个里面
2.预览角度流程
public native final void setDisplayOrientation(int degrees);
| //Camera.java
|
android_hardware_Camera_setDisplayOrientation(JNIEnv *env, jobject thiz,jint value))
| //android_hardware_Camera.cpp
|
Camera::sendCommand(int32_t cmd, int32_t arg1, int32_t arg2)
| //Camera.cpp
|
Camera2Client::sendCommand(int32_t cmd, int32_t arg1, int32_t arg2)
{ //Camera2Client.cpp
... //省略
case CAMERA_CMD_SET_DISPLAY_ORIENTATION:
return commandSetDisplayOrientationL(arg1);
... //省略
}
|
|
int transform =
Parameters::degToTransform(degrees,mCameraFacing==CAMERA_FACING_FRONT);
|
|
int Parameters::degToTransform(int degrees, bool mirror)
{ //Parameters.cpp
//前摄镜像,后摄不镜像
}
2813 int Parameters::degToTransform(int degrees, bool mirror) {
2814 if (!mirror) {
2815 if (degrees == 0) return 0;
2816 else if (degrees == 90) return HAL_TRANSFORM_ROT_90;
2817 else if (degrees == 180) return HAL_TRANSFORM_ROT_180;
2818 else if (degrees == 270) return HAL_TRANSFORM_ROT_270;
2819 } else { // Do mirror (horizontal flip)
2820 if (degrees == 0) { // FLIP_H and ROT_0
2821 return HAL_TRANSFORM_FLIP_H;
2822 } else if (degrees == 90) { // FLIP_H and ROT_90
2823 return HAL_TRANSFORM_FLIP_H | HAL_TRANSFORM_ROT_90;
2824 } else if (degrees == 180) { // FLIP_H and ROT_180
2825 return HAL_TRANSFORM_FLIP_V;
2826 } else if (degrees == 270) { // FLIP_H and ROT_270
2827 return HAL_TRANSFORM_FLIP_V | HAL_TRANSFORM_ROT_90;
2828 }
2829 }
2830 ALOGE("%s: Bad input: %d", __FUNCTION__, degrees);
2831 return -1;
2832 }
打印的一些log:
打开后摄时,degToTransform会调用两次,默认第一次传入的degToTransform的degree第一次是0,第二次是90,如果app
不修改预览方向,在这里可以根据传入的角度进行调整预览方向。
先写到这里吧...