How to connect android to a USB webcam using Open XC android-webcam ?

2,307 views
Skip to first unread message

El moutaraji Hassan

unread,
Jul 13, 2013, 7:23:53 AM7/13/13
to ope...@googlegroups.com

Christopher Peplin

unread,
Jul 15, 2013, 11:14:22 AM7/15/13
to openxc@googlegroups com
Hi Hassan,

I'm glad to try and help but I need a little more information - did you try the instructions at https://github.com/openxc/android-webcam#usb-webcam-support ? Were there any specific problems or errors?

Chris


On Sat, Jul 13, 2013 at 7:23 AM, El moutaraji Hassan <hassan.el...@gmail.com> wrote:

--
You received this message because you are subscribed to the Google Groups "OpenXC" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openxc+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

MadMax

unread,
Nov 13, 2013, 1:39:39 PM11/13/13
to ope...@googlegroups.com
Hi,

I have a similar problem.

I am trying to connect a logitech c270 camera on an iconia tab a210. When I connect the camera I can see /dev/video0 appearing. I downloaded the openxc webcam git repository.  I am using Ubuntu 13.10 and eclipse. I have imported the android-webcam-library and the example (CameraActivity) in my eclispe workspace. I have set the jni build path so that android-webcam-library compile without problems. I refere to the webcam-library from the example that is: right clic CameraActivity -> properties -> android -> add library -> select android-webcam-library -> OK.

The problem is when I try to run the CameraActivity, I have this error:

[2013-11-13 18:51:39 - CameraActivity] Dx
trouble writing output: already prepared
[2013-11-13 18:51:40 - Dex Loader] Unable to execute dex: java.nio.BufferOverflowException. Check the Eclipse log for stack trace.
[2013-11-13 18:51:40 - CameraActivity] Conversion to Dalvik format failed: Unable to execute dex: java.nio.BufferOverflowException. Check the Eclipse log for stack trace.

I tried many things but nothing is working.

Is there someone that can help me ?

Note: I can see the video stream of the USB camera using the app "USB camera Trial". So it should be possible.

MadMax

unread,
Nov 15, 2013, 3:15:56 AM11/15/13
to ope...@googlegroups.com
Well...I solve part of my problem by using the android sdk manager and removing the "android SDK Build-tools v19" and installing "android SDK Build-tools v17".

Now, I can run the app on the android device but I have another error. The app start and few seconds afterwardds, I have this log message:


11-15 09:11:35.490: I/Process(2429): Sending signal. PID: 2429 SIG: 9
11-15 09:12:00.230: E/NativeWebcamJNI(2468): VIDIOC_S_FMT error 5, I/O error
11-15 09:12:00.230: I/WebcamManager(2468): Service binding in response to Intent { cmp=com.ford.openxc.webcam/.WebcamManager }
11-15 09:12:00.230: I/Choreographer(2468): Skipped 315 frames!  The application may be doing too much work on its main thread.
11-15 09:12:00.250: I/WebcamPreview(2468): Bound to WebcamManager
11-15 09:12:00.250: E/NativeWebcamJNI(2468): Unable to load frame, buffers not initialized
11-15 09:12:00.310: E/NativeWebcamJNI(2468): Unable to load frame, buffers not initialized
...
11-15 09:12:00.310: E/NativeWebcamJNI(2468): Unable to load frame, buffers not initialized //seems to appear each time a frame should be taken

Note: The camera LED is not blinking at all. I think the camera is not really taking pictures.

MadMax

unread,
Nov 15, 2013, 4:37:25 AM11/15/13
to ope...@googlegroups.com
New info:

I checked the webcam on my linux machine ( v4l2-ctl -d /dev/video1 --list-formats) and I got:


ioctl: VIDIOC_ENUM_FMT
    Index       : 0
    Type        : Video Capture
    Pixel Format: 'YUYV'
    Name        : YUV 4:2:2 (YUYV)

    Index       : 1
    Type        : Video Capture
    Pixel Format: 'MJPG' (compressed)
    Name        : MJPEG

In my opinion, it should be fine. The problem in the jni code occurs at this step:

fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
fmt.fmt.pix.width = width;
fmt.fmt.pix.height = height;
fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;

if(-1 == xioctl(fd, VIDIOC_S_FMT, &fmt)) {
      return errnoexit("VIDIOC_S_FMT");

MadMax

unread,
Nov 15, 2013, 6:47:22 AM11/15/13
to ope...@googlegroups.com
Solved !

I solved my app by integrating USB rights in the opencx example the following manner:


/***********************************************/

import java.util.HashMap;
import java.util.Iterator;

import android.app.Activity;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbManager;
import android.os.Bundle;
import android.util.Log;

public class CameraActivity extends Activity {
   
    private static final String TAG = "openXC::Activity";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);    
        usbConnection();
    }
   
    public void usbConnection() {
        UsbManager mUsbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
  
        PendingIntent mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
        IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
        registerReceiver(mUsbReceiver, filter);
       
        String txt = "default";
        HashMap<String, UsbDevice> deviceList = mUsbManager.getDeviceList();
        Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
        UsbDevice device = deviceIterator.next();
        mUsbManager.requestPermission(device, mPermissionIntent);
    }
   
    private static final String ACTION_USB_PERMISSION ="com.android.example.USB_PERMISSION";
    private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {

        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (ACTION_USB_PERMISSION.equals(action)) {
                synchronized (this) {
                    UsbDevice device = (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
   
                    if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
                        if(device != null){
                           
                            setContentView(R.layout.main);

                       }
                    }
                    else {
                        Log.d(TAG, "permission denied for device " + device);
                    }
                }
            }
        }
    };

Christopher Peplin

unread,
Nov 26, 2013, 7:56:41 PM11/26/13
to openxc@googlegroups com
Great! I'm glad you got it working. Would you consider throwing a pull request our way on GitHub so I can try and merge some of the fixes in, if you think it'll work for other people? I just enabled the wiki on the project, too, so maybe we can start collecting some user experiences there since it's seems really difficult to support video on all Android devices (https://github.com/openxc/android-webcam/wiki).


Eric Echeverri

unread,
Apr 22, 2014, 3:06:52 PM4/22/14
to ope...@googlegroups.com
I need to point out that the The VIDIOC_S_FMT error 22, and the  VIDIOC_S_FMT error 5, are just due to that fact different android devices have different speeds to process frames. so I changed the  tv.tv_sec = 2; to  tv.tv_sec = 20;

void process_camera(int fd, buffer* frame_buffers, int width,

        struct timeval tv;

        tv.tv_sec = 20;

        tv.tv_usec = 0;

This made the error go away. Once I changed that value camera worked on te Android Device

ashwin prabu

unread,
Jun 25, 2014, 8:58:19 AM6/25/14
to ope...@googlegroups.com


Hi,

i run this openxc webcam app in my device.but it make problem like 





06-25 18:20:25.860: D/dalvikvm(17022): Late-enabling CheckJNI
06-25 18:20:26.120: D/SurfaceView(17022): pckname = com.ford.openxc.webcam
06-25 18:20:26.140: D/WebcamPreview(17022): WebcamPreview constructed
06-25 18:20:26.150: D/ViewRootImpl(17022): pckname = com.ford.openxc.webcam
06-25 18:20:26.270: D/SurfaceView(17022): pckname = com.ford.openxc.webcam
06-25 18:20:26.270: D/WebcamPreview(17022): WebcamPreview constructed
06-25 18:20:26.370: D/libEGL(17022): loaded /system/lib/egl/libEGL_mali.so
06-25 18:20:26.390: D/libEGL(17022): loaded /system/lib/egl/libGLESv1_CM_mali.so
06-25 18:20:26.400: I/dalvikvm(17022): threadid=3: reacting to signal 3
06-25 18:20:26.430: I/dalvikvm(17022): Wrote stack traces to '/data/anr/traces.txt'
06-25 18:20:26.440: D/libEGL(17022): loaded /system/lib/egl/libGLESv2_mali.so
06-25 18:20:26.560: D/OpenGLRenderer(17022): Enabling debug mode 0
06-25 18:20:26.620: D/WebcamPreview(17022): Surface created
06-25 18:20:26.650: D/WebCam(17022): surfaceChanged
06-25 18:20:26.660: D/ViewRootImpl(17022): pckname = com.ford.openxc.webcam
06-25 18:20:26.900: I/dalvikvm(17022): threadid=3: reacting to signal 3
06-25 18:20:26.920: I/dalvikvm(17022): Wrote stack traces to '/data/anr/traces.txt'
06-25 18:20:27.150: I/WebcamManager(17022): Service starting
06-25 18:20:27.150: D/dalvikvm(17022): Trying to load lib /data/data/com.ford.openxc.webcam/lib/libwebcam.so 0x410561d0
06-25 18:20:27.170: D/dalvikvm(17022): Added shared lib /data/data/com.ford.openxc.webcam/lib/libwebcam.so 0x410561d0
06-25 18:20:27.310: D/dalvikvm(17022): GC_FOR_ALLOC freed 108K, 4% free 6625K/6855K, paused 141ms
06-25 18:20:27.330: I/dalvikvm-heap(17022): Grow heap (frag case) to 7.695MB for 1228816-byte allocation
06-25 18:20:27.410: D/dalvikvm(17022): GC_CONCURRENT freed 3K, 4% free 7822K/8071K, paused 2ms+11ms
06-25 18:20:27.410: I/NativeWebcam(17022): Preparing camera with device name /dev/video0
06-25 18:20:29.120: E/NativeWebcamJNI(17022): VIDIOC_S_FMT error 70, Communication error on send
06-25 18:20:29.120: I/WebcamManager(17022): Service binding in response to Intent { cmp=com.ford.openxc.webcam/.WebcamManager }
06-25 18:20:29.200: I/WebcamPreview(17022): Bound to WebcamManager
06-25 18:20:29.200: E/NativeWebcamJNI(17022): Unable to load frame, buffers not initialized
06-25 18:20:29.240: E/NativeWebcamJNI(17022): Unable to load frame, buffers not initialized

Shall i get some solution for this error

Zeeshan Akram

unread,
Nov 29, 2016, 7:53:08 AM11/29/16
to OpenXC
Hi Chris,
I need help. I am not a professional user of githud and eclipse. how can i use your library and example. i couldnt understand from your post

On Saturday, July 13, 2013 at 2:23:53 PM UTC+3, Hakkannoid wrote:

Reply all
Reply to author
Forward
0 new messages