marcogulino / AndroidUsbCamera

Android USB Camera Driver/Bridge for GNU/Linux
178 stars 104 forks source link

Simple helper script for AndroidUsbCamera startup #1

Open lsartory opened 14 years ago

lsartory commented 14 years ago

Hello,

First, thank you for making this. I was looking for something like this for a while now. This isn't really an issue, but I couldn't find any other way to contribute.. I wrote a startup script to make it easier for me to launch AndroidUsbCamera, and I thought it would be nice to share it so I cleaned it up a bit.

It launches the application on the Android device, sets up port forwarding, attempts to auto-detect which video device to use, and finally starts AndroidUsbCamera.

You should only need to adjust line 71 to use the right path to launch AndroidUsbCamera, but I didn't test it extensively.

#!/bin/sh

echo "AndroidUsbCamera starter script"
echo "-------------------------------"
echo
if [ `adb devices | grep device | wc -l` -gt 1 ]
then
  echo -n "Setting up Android device.. "
  adb shell am start -n usbwebcam.application/.GWebcam &> /dev/null || (echo -e "\nAn error occured while starting the application"; exit 1)
  adb forward tcp:8080 tcp:8080 &> /dev/null || (echo -e "\nAn error occured while attempting to forward the port"; exit 1)
  echo "OK."

  echo -n "Checking module.. "
  if ! lsmod | grep vloopback &> /dev/null
  then
    echo -e "\nThe vloopback module is not loaded, loading it now.."
    if ! modprobe vloopback &> /dev/null
    then
      if which sudo &> /dev/null
      then
        echo "Loading failed, attempting with sudo.."
        echo "Please enter your password."
        sudo modprobe vloopback
      else
        echo "Loading failed, attempting with su.."
        echo "Please enter root password."
        su -c "modprobe vloopback"
      fi
    fi
    if ! lsmod | grep vloopback &> /dev/null
    then
      echo "The vloopback module is still not available, aborting."
      exit 1
    fi
  fi
  echo "OK."

  if [ -z "$1" ]
  then
    echo -n "Auto-detecting video devices to be used.. "
    DEVICES="`dmesg | grep vloopback | grep registered | tail -1`"
    INPUT=`echo $DEVICES | sed "s@.*input: \(.*\),.*@\1@"`
    OUTPUT=`echo $DEVICES | sed "s@.*output: \(.*\)@\1@"`
    if [ ! -e "/dev/$INPUT" -o ! -e "/dev/$OUTPUT" ]
    then
      echo -e "\nCouldn't find input or output device, aborting."
      echo "You can skip auto-detection by starting this script with the video input device as the first parameter"
      echo "e.g. $0 /dev/video0"
      exit 1
    fi
    echo "OK."
  else
    echo -n "Checking video devices.. "
    INPUT="$1"
    DEVNUM=`echo $INPUT | sed "s@[a-Z/]*@@"`
    OUTPUT=`echo $INPUT | sed "s@$DEVNUM\\$@$(expr $DEVNUM + 1)@"`
    if [ ! -e "$INPUT" -o ! -e "$OUTPUT" ]
    then
      echo -e "\nCouldn't find input or output device, aborting."
      echo "Please try with another device."
      exit 1
    fi
    echo "OK."
  fi

  echo -e "\nUsing $INPUT as loopback input. You should use $OUTPUT as webcam device in your application.\n"

  echo "Waiting for device to settle.."
  sleep 5
  echo -e "Starting AndroidUsbCamera..\n"
  ./AndroidUsbCamera $INPUT    # Edit me to properly start the application

else
  echo "No Android device was found, aborting."
  exit 1
fi
jalcine commented 12 years ago

Very good job! I might integrate this into my fork. I'll credit you.

lsartory commented 12 years ago

Great! I hope it still works fine though, I haven't used this in two years.

2012/1/22 Jacky Alciné < reply@reply.github.com

Very good job! I might integrate this into my fork. I'll credit you.


Reply to this email directly or view it on GitHub:

https://github.com/marcogulino/AndroidUsbCamera/issues/1#issuecomment-3603514

jalcine commented 12 years ago

It's iffy, Linux 3.0 doesn't use vloopback, it looks like it uses v4l2loopback. A bit confusing too, since now I've had to build it (to no avail..).

lsartory commented 12 years ago

Well, good luck with that! Keeping this project alive is a good thing, it's pretty convenient at times to be able to use the phone as a webcam. In fact, it would be even better if it was an out of the box Android feature..

2012/1/22 Jacky Alciné < reply@reply.github.com

It's iffy, Linux 3.0 doesn't use vloopback, it looks like it uses v4l2loopback. A bit confusing too, since now I've had to build it (to no avail..).


Reply to this email directly or view it on GitHub:

https://github.com/marcogulino/AndroidUsbCamera/issues/1#issuecomment-3603804

jalcine commented 12 years ago

It would be, wouldn't it? It'd just take device manufacturers to add the USB Webcam driver to their drivers and have Android expose it as such (only if possible, though).

lsartory commented 12 years ago

I suppose it's possible.. I've already seen Android devices that allowed to switch between USB modes from the ongoing USB notification. I guess adding UVC capabilities wouldn't be too hard for someone who knows the protocol.

2012/1/23 Jacky Alciné < reply@reply.github.com

It would be, wouldn't it? It'd just take device manufacturers to add the USB Webcam driver to their drivers and have Android expose it as such (only if possible, though).


Reply to this email directly or view it on GitHub:

https://github.com/marcogulino/AndroidUsbCamera/issues/1#issuecomment-3611147

jalcine commented 12 years ago

It's not only that at times, you can easily write a ROM for it. It's the computer support. If it doesn't have the right drivers, then there's no hope for the end-users..

lsartory commented 12 years ago

Computer support shouldn't be a problem. The Linux UVC driver is pretty good as well, I've been using it on my laptop for more than 4 years now.. Also, since Windows Vista, UVC devices are supposed to work out of the box as far as I know.

2012/1/23 Jacky Alciné < reply@reply.github.com

It's not only that at times, you can easily write a ROM for it. It's the computer support. If it doesn't have the right drivers, then there's no hope for the end-users..


Reply to this email directly or view it on GitHub:

https://github.com/marcogulino/AndroidUsbCamera/issues/1#issuecomment-3611359

jalcine commented 12 years ago

That's a fun fact. Well, with that in mind, I'd add this to my list of to-dos. I'll keep in touch :)

lsartory commented 12 years ago

Alright then, good luck! :)

2012/1/23 Jacky Alciné < reply@reply.github.com

That's a fun fact. Well, with that in mind, I'd add this to my list of to-dos. I'll keep in touch :)


Reply to this email directly or view it on GitHub:

https://github.com/marcogulino/AndroidUsbCamera/issues/1#issuecomment-3611934