Run C code of V4L2 on Android Device

3.9k views Asked by At

I want to execute some c code of v4l2 on my android tablet. One is Nexus 7 and the other is Samsung GT-P5100. Anyway, I meet some difficulties.

I run these C code via NKD. And my function is:

jint Java_edu_tjut_cs_jcai_CameraPreviewActivity_createEngine(JNIEnv* env, jclass clazz)
{
    int res;
    res = v4l_open(DEFAULT_DEVICE, &v4l_dev);   
    LOGV("Open V4L2 Device: %d", res);

    res = v4l_get_capability(&v4l_dev);
    LOGV("Getting device capability: %d", res);

    res = v4l_get_picture(&v4l_dev);
    LOGV("Getting picture property: %d", res);

    res = v4l_init_mbuf(&v4l_dev);
    LOGV("Device init: %d", res);

    res = v4l_get_mbuf(&v4l_dev);
    LOGV("Memory mapping: %d", res);

     }

To run this code, I need to set the Default device. The functions I used in the above are widely used in linux.

For NUXES: I found the Default Device in Nexus dev file, and that is #define DEFAULT_DEVICE "/dev/tegra_camera" *!And the opendevice part is ok, which return 1. But the other parts (get capacity..) don't work. They just return 0.

For Samsung, I can't find the name of Default Device. I have the source code of Samsung, but I really don't know which part should I look.

Could anyone help me?? Thx!

I just add the definition of the function I use below, in case it is needed.

int v4l_open( char *dev, v4l_device *vd )
{
    if( !dev )
    {
        dev=DEFAULT_DEVICE ;
    }
    if( ( vd->fd = open( dev, O_RDWR ) )  < 0 )
    {
        perror( "v4l_open error");
        return -1;
    }
    return 0;
}
/**************************************************************
* 函数名: v4l_get_capability
* 功  能: 获取设备属性
* 输  入: vd
* 输  出: 无
* 返  回:  -1—-失败 0—-成功
**************************************************************/
int v4l_get_capability( v4l_device *vd )
{
//    if( ioctl( vd->fd, VIDIOCGCAP, &( vd->capability ) ) <0 )
      if( ioctl( vd->fd, VIDIOC_QUERYCAP, &( vd->capability ) ) <0 )

    {
        perror( "v4l_get_capability");
        return -1 ;
    }
    return 0;
}
/***************************************************************
* 函数名:v4l_get_picture
* 功  能:获取图片属性
* 输  入: vd
* 输  出: 无
* 返  回:  -1—-失败  0—-成功
***************************************************************/
int v4l_get_picture( v4l_device *vd )
{
//    if( ioctl( vd->fd,VIDIOCGPICT,&( vd->picture ) ) < 0 )
    if( ioctl( vd->fd,VIDIOCGPICT,&( vd->picture ) ) < 0 )

    {
        return -1;
    }
    return 0;
}
/**************************************************************
* 函数名: v4l_set_picture
* 功  能: 设置图片属性
* 输  入: vd
* 输  出: 无
* 返  回: -1—-失败 0—-成功
**************************************************************/
int v4l_set_picture( v4l_device *vd )
{
    if( ioctl( vd->fd, VIDIOCSPICT, &( vd->picture ) ) < 0 )
    {
        return -1;
    }
    return 0;
}
/*************************************************************
* 函数名:v4l_get_channels
* 功  能:获取通道信息
* 输  入: vd
* 输  出: 无
* 返  回:  -1—-失败 0—-成功
*************************************************************/
int v4l_get_channels( v4l_device *vd )
{
    int i;
    for( i=0;i < vd->capability.channels ; i++ )
    {
        vd->channel[i].channel = i;               //确定通道
        if( ioctl( vd->fd , VIDIOCGCHAN, &( vd->channel[i] ) ) <0 )
        {
            perror( "v4l_get_channel");
            return -1;
        }
    }
    return 0;
}
1

There are 1 answers

6
TheCodeArtist On BEST ANSWER

There is NO V4L2 camera device-driver on the Nexus7 running stock Android.

Hence no /dev/video device that will support the V4L2 ioctls.

The Ubuntu port on Nexus7 contains the V4L2 driver to enable support for the front-camera sensor on Nexus7.