您的位置:首页 > 移动开发 > Android开发

[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
  • 收藏
  • 分享
  • 文章举报
Edward_0107 发布了2 篇原创文章 · 获赞 1 · 访问量 659 私信 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: