Finally, the android-driven USB camera is ready!

Source: Internet
Author: User

Finally, the android-driven USB camera is ready!

Thanks to a post posted by stackoverflow, there are several key words in the post, and then the problem is solved.

Post description:
The premise is that your USB camera is UVC compatible (most cameras are compatible today)
By default, Android does not provide APIs to access external cameras. Therefore, you must consider writing a middleware for Kernel-to-android application-layer communication.
When you connect a USB camera to your device, check the following points:
1) Does your device support USB-OTG?
2) have you created a device in the/dev directory? If it is created, everything is simple. Run ls-L/dev/V * in shell and you will see video0 or video1.
3) If/dev does not create a device, you need to write a firmware (UVC) to communicate with the hardware!
(Post address: http://stackoverflow.com/questio... Android-Application)
Read this, connect the USB camera to mk802 again, open ADB shell, execute LS-L/dev/V *, and you will see the/dev/video0 device!
Unplug the camera and run it again. video0 disappears and then connects. video0 appears. This indicates that mk802 supports my camera!

At this point, it has been clear that I need to write a middleware from the Android Application layer to the kernel communication. I do not know about this, so I am searching for "android USB camera" on Google"
Finally, I found an android USB camera application example.
Http://brain.cc.kogakuin.ac.jp/research/usb-e.html
Find a simplewebcamra.apk from it, download it, and install it quickly. If it cannot run, logcat reports an error, prompting you to have no permission to access the video0 device.
Why? My system is already root! Do I need root permission for my APK? I checked the information online and tried it for half a day.
Later, I suddenly got an idea. Android is also Linux. Can I set video0 to no permission? Asked a friend, and executed a command:
Chmod 777/dev/video0
Run the APK again! (After testing, you can set it to chmod 0666/dev/vidoe0, but I do not understand the meaning of 0666 ..)
But the problem comes again. When the program goes in, an error is reported.
Vidioc_dqbuf error 22, invalid argument

So I thought that we had to live the simplewebcamea source code! After searching, I am lucky to find a simplewebcam source code:
Https://bitbucket.org/neuralassembly/simplewebcam/src
Download the C source code and Android source code of ndk, and install cygwin according to the ndk tutorial.
The error message "vidioc_dqbuf" indicates that the call parameter is incorrect, but the error message cannot be obtained.
After reading n tutorials, I accidentally found some parameters for the open method of the camera device. Then I tried to remove some parameters in the C code:
FD = open (dev_name, o_rdwr | o_nonblock, 0 );
Change
FD = open (dev_name, o_rdwr );

Build again and run it. Oh, my God, I am so happy!


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.