0

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;
}
Brendon Tsai
  • 1,267
  • 1
  • 17
  • 31
  • Are the device nodes standard V4L2 devices? Doesn't appear so. `v4l_open()` is just a wrapper around `open()` and so will work without any problem. – TheCodeArtist Sep 05 '13 at 15:24
  • Thx. I suppose that the android media part is based on v4l2. But I'm not sure for that. Could you give a hint where could I find it? – Brendon Tsai Sep 06 '13 at 06:19
  • One can obtain the official [**Nexus7 Linux kernel sources**](http://source.android.com/source/building-kernels.html) and check within the grouper/tilapia defconfigs and the driver source-code for details. – TheCodeArtist Sep 06 '13 at 07:18
  • Thanks. I run this code on another device and it works. I suppose I may use the wrong dev name of Nexus. Do you know where to find the right name? – Brendon Tsai Sep 10 '13 at 08:19

1 Answers1

3

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.

TheCodeArtist
  • 21,479
  • 4
  • 69
  • 130
  • Thanks a lot. Anyway I still need to use android. Maybe still base on this device. Could you tell me where could I find the right format for the camera(V4L??)? Should I look for the source code? Besides, I also have the simlimar problem on Samsung, do you have any suggestion? – Brendon Tsai Sep 11 '13 at 02:26
  • @BrendonTsai Download and study the device-specific camera-HAL code from the OEM. Most Android devices have hardware accelerated video capture blocks specific to their SoC. OEMs implement the CameraHAL in Android to communcate with the camera-sensor via the video capture block present on the SoC of the device. Samsung releases its Kernel/Android modifications on [opensource.samsung.com](http://opensource.samsung.com). – TheCodeArtist Sep 11 '13 at 08:09
  • @BrendonTsai Also, depending upon what you are trying, you may NOT really need such low-level access to the camera. Have you tried out [**OpenCV for Android**](http://opencv.org/platforms/android.html). If you are looking to try out V4L2 then you will most certainly need to do a few modifications on these devices - starting with rooting them and flashing alternate ROMs with support for UVC V4L2 cameras. – TheCodeArtist Sep 11 '13 at 08:14
  • Thanks. I do need get the low-level access to the camera. I actually need to get data from camera in C-level. It doesn't matter whether using V4L2 or not. – Brendon Tsai Sep 11 '13 at 08:33
  • @BrendonTsai In that case you might want to checkout [Native development using OpenCV on Android](http://docs.opencv.org/doc/tutorials/introduction/android_binary_package/android_dev_intro.html#native-development-in-c). – TheCodeArtist Sep 11 '13 at 09:48
  • Thanks! I know the android NDK stuff but I really have no idea about OpenCV. So the OpenCV code can open the cameras of different devices? – Brendon Tsai Sep 12 '13 at 02:07