2012-07-06 170 views
2

我的目标是进行微调以找到正确的线程优先级。未定义的property_get引用

线程我关注的是位于下/硬件/ my_company /编解码器/ openmax_il/

我修改了2个文件

  1. Android.mk

    添加“$(TOP)/在LOCAL_C_INCLUDES列表系统/核心/包括”,如下

    LOCAL_C_INCLUDES:= \ 
    
        blur blur blur 
        $(TOP)/hardware/my_company/camera/v4l2_camerahal \ 
        $(TOP)/system/core/include 
    
  2. 在我的源文件中。

    #include <cutils/properties.h> 
    
    int componentInit(blur blur blur) 
    { 
        int ret = 0; 
    
        blur blur blur 
    
        // To find proper thread priority 
        char value[92]; 
        property_get("omx.video_enc.priority", value, "0"); 
        setVideoEncoderPriority(atoi(value)); 
    
        return ret; 
    } 
    

但是,我遇到的

error: undefined reference to 'property_get' 
collect2: ld returned 1 exit status 

链接错误如果有人可以帮助这一点,那将是对我好。 :)

感谢

回答

7

这听起来像你想使用__system_property_get(),这是在<sys/system_properties.h>定义。从该标题开始:

/* Look up a system property by name, copying its value and a 
** \0 terminator to the provided pointer. The total bytes 
** copied will be no greater than PROP_VALUE_MAX. Returns 
** the string length of the value. A property that is not 
** defined is identical to a property with a length 0 value. 
*/ 
int __system_property_get(const char *name, char *value); 

此签名不完全是您要使用的,因为您在未定义属性的情况下具有默认值。由于__system_property_get()在未定义属性的情况下返回0,因此您可以轻松地自行对此进行补充。

这里是我是如何解决这个问题在我自己的本机代码,它很适合我(虽然缺乏缓冲区溢出检查,这将是一个更好的解决方案的话):

#include <sys/system_properties.h> 
int android_property_get(const char *key, char *value, const char *default_value) 
{ 
    int iReturn = __system_property_get(key, value); 
    if (!iReturn) strcpy(value, default_value); 
    return iReturn; 
} 
6

你必须在源文件中

#include <cutils/properties.h> 

和链接添加到您的android.mk libcutils:

LOCAL_STATIC_LIBRARIES := libcutils libc