[rk3288][android-5.1]通过prop属性设定camera orientation
2020-02-17 04:26
801 查看
通过prop属性设定camera orientation
需求:
增加prop属性改变camera预览角度
思路:
添加属性很简单,重点是如何将其与camera预览角度处理过程进行绑定,camera的注册初始化以及orientation设定是在HAL层进行
Prop属性 ——> 找到HAL层关于camera orientation处理位置 ——> 解析prop属性值 ——> 对原有设定进行对应修改
准备:
property_get/property_set
该函数专门用于获取prop属性值,java和c域中均可使用,下面是源码中的解释:
/* property_get: returns the length of the value which will never be ** greater than PROPERTY_VALUE_MAX - 1 and will always be zero terminated. ** (the length does not include the terminating zero). ** ** If the property read fails or returns an empty value, the default ** value is used (if nonnull). */ int property_get(const char *key, char *value, const char *default_value); //key为prop中具体属性名;value获取到的属性值,存储在字符数组中;default_value为默认值:如果未获取到属性值,则使用改默认值,一般将其设为NULL //函数返回值:成功获取到属性值时返回该属性值的字符长度;未能成功获取属性值时返回值小于0 /* property_set: returns 0 on success, < 0 on failure*/ int property_set(const char *key, const char *value);
示例用法:
char buf[20]="ssssssssssss"; char tempbuf[PROPERTY_VALUE_MAX]; property_set("phone.imei",buf); property_get("phone.imei",tempbuf,NULL);
方案实现:
device/rockchip/rk3288/system.prop
中新增属性:
ro.cam.orientation=90 # 0\90\180\270
hardware/rockchip/camera/CameraHAL/CameraHal_Module.cpp
中角度设定是在camera_get_number_of_cameras
函数中,实际修改如下:
diff --git a/CameraHal/CameraHal_Module.cpp b/CameraHal/CameraHal_Module.cpp index a41e69a..53f6059 100755 --- a/CameraHal/CameraHal_Module.cpp +++ b/CameraHal/CameraHal_Module.cpp @@ -27,6 +27,7 @@ #include "CameraHal.h" #include "CameraHal_Module.h" #include "CameraHal_MediaProfile.cpp" +#include <cutils/properties.h> #include <time.h> #include "cam_api/cam_engine_interface.h" @@ -626,6 +627,8 @@ int find_DV_resolution_index(int w, int h) int camera_get_number_of_cameras(void) { + char CamOriVal[PROPERTY_VALUE_MAX]; //存储获取到的属性值,char类型 + int cam_ori_val = 0; char cam_path[20]; char cam_num[3],i; int cam_cnt=0,fd=-1,rk29_cam[CAMERAS_SUPPORT_MAX]; @@ -777,7 +780,26 @@ int camera_get_number_of_cameras(void) ptr++; camInfoTmp[cam_cnt&0x01].facing_info.orientation = atoi(ptr); } else { - camInfoTmp[cam_cnt&0x01].facing_info.orientation = 90; + LOGD("[edward] try to get property of cma orentation.\n"); + if(property_get("ro.cam.orientation", CamOriVal, NULL)) { //尝试获取ro.cam.orientation属性值 + cam_ori_val = atoi(CamOriVal); //将获取到的属性值转换为整型值 + LOGD("now get the val of ro.cam.orientation : %d\n",cam_ori_val); + if(cam_ori_val == 0) + camInfoTmp[cam_cnt&0x01].facing_info.orientation = 0; //根据获取到的属性值设定camera角度 + else if (cam_ori_val == 90) + camInfoTmp[cam_cnt&0x01].facing_info.orientation = 90; + else if (cam_ori_val == 180) + camInfoTmp[cam_cnt&0x01].facing_info.orientation = 180; + else if (cam_ori_val == 270) + camInfoTmp[cam_cnt&0x01].facing_info.orientation = 270; + else { + LOGD("sorry! it is not a legal val.\n"); + camInfoTmp[cam_cnt&0x01].facing_info.orientation = 90; + } + } else { + LOGD("sorry! can not get the property value.\n"); + camInfoTmp[cam_cnt&0x01].facing_info.orientation = 90; + } }
- 点赞 1
- 收藏
- 分享
- 文章举报
相关文章推荐
- [rk3288][android-5.1]打印机支持 (dev/usb/lp*)
- android 读取excel POI JXL
- Android百度地图开发(三)范围搜索
- Android百度地图开发(三)范围搜索
- android开发--推箱子小游戏(一)
- android开发--推箱子小游戏(二)
- Android删除Alarm的方法
- Android多线程编程 之 Handler机制的简单理解
- Android调用JNI本地方法跟踪目标代码
- Android gdb so
- Android添加系统级顶层窗口 和 WindowManager添加view的动画问题
- AndroidX86模拟器Genymotion的一些使用和另一款Andy模拟器
- android socket file server
- 关于Android读取不同位置(drawable,asset,SDCard)的图片资源的总结
- ffmpeg 硬解码 android mediacodec
- Android开发遇到的问题:不给include设置width、height,导致ListView GridView内容无法显示...
- android的ListAdapter简单用法
- 编译android4.0错误总结
- android 启动服务播放音乐
- cordova build android 报错