diff options
-rw-r--r-- | README.markdown | 14 | ||||
-rwxr-xr-x | prepare-videochat.sh | 76 |
2 files changed, 68 insertions, 22 deletions
diff --git a/README.markdown b/README.markdown index b6ebfc7..14c9c14 100644 --- a/README.markdown +++ b/README.markdown @@ -1,16 +1,20 @@ ipwebcam-gst ============ -This is a very simple shell script which allows Android users to use their phones as a webcam/microphone in Linux. The setup is slightly contrived, though: +This is a shell script which allows Android users to use their phones as a webcam/microphone in Linux. The setup is as follows: * [IP Webcam](https://market.android.com/details?id=com.pas.webcam) (on the phone) serves up a MJPEG live video stream and a WAV live audio stream through HTTP (port 8080 by default). -* Port 8080 in the phone is bridged to port 8080 in the computer that the phone is plugged to, using ADB port forwarding. You can use IP Webcam through Wi-Fi, but it's rather choppy, so I wouldn't recommend it. -* From local port 8080, a GStreamer graph takes the MJPEG live video stream and dumps it to a loopback V4L2 device, using [v4l2loopback](https://github.com/umlaeute/v4l2loopback). The audio stream is dumped to a PulseAudio null sink. -* Most videochat software in Linux is compatible with `v4l2loopback`: Skype 2.1 (*not* 2.2, it seems), Cheese, Empathy and the Google Talk video chat plugin should work. +* If the phone is plugged to USB and ADB is available, the HTTP port in the phone is bridged to the same port in the computer, using ADB port forwarding. This is much faster than using Wi-Fi, and the shell will be able to start the IP Webcam application on the phone directly. The script supports Wi-Fi as well, but it can be rather choppy with bad reception, so I wouldn't recommend it. +* From the local port in the computer, a GStreamer graph takes the MJPEG live video stream and dumps it to a loopback V4L2 device, using [v4l2loopback](https://github.com/umlaeute/v4l2loopback). The audio stream is dumped to a PulseAudio null sink. +* Most videochat software in Linux is compatible with `v4l2loopback`: Skype 2.1 (*not* the latest 2.2, it seems), Cheese, Empathy and the Google Talk video chat plugin should work. * The sound recording device for your videochat application should be changed to the 'Monitor of Null Sink' using `pavucontrol`. -This project includes `prepare-videochat.sh`, which does all these things, except for switching the recording device for your videochat application. It does open `pavucontrol` if needed, though. The script installs the GStreamer tools and `pavucontrol` if required, but you will have to install the [Android SDK](http://developer.android.com/sdk) and v4l2loopback by yourself. +This project includes `prepare-videochat.sh`, which does all these things, except for switching the recording device for your videochat application. It does open `pavucontrol` if needed, though. The script installs `v4l2loopback`, the GStreamer tools and `pavucontrol` if required, but you will have to install the [Android SDK](http://developer.android.com/sdk) by yourself. To use this script, simply run it with `./prepare-videochat.sh` and follow instructions. You may have to customize a few variables in the CUSTOMIZATION section before using it, though. Disclaimer: the script has only been tested in my local installation of Ubuntu 11.04. I can't really support other distributions, sorry! + +-- +Antonio +Twitter: @antoniogado diff --git a/prepare-videochat.sh b/prepare-videochat.sh index d1729fa..056e1d1 100755 --- a/prepare-videochat.sh +++ b/prepare-videochat.sh @@ -4,12 +4,19 @@ # Copyright (C) 2011 Antonio García Domínguez # Licensed under GPLv3 +# Exit on first error set -e ### CONFIGURATION -# Path to "adb" in the Android SDK -ADB=~/bin/android-sdk-linux_x86/platform-tools/adb +# If your "adb" is not in your $PATH, set the full path to it here. +# If "adb" is in your $PATH, you don't have to change this option. +ADB_PATH=~/bin/android-sdk-linux_x86/platform-tools/adb +if which adb; then + ADB=$(which adb) +else + ADB=$ADB_PATH +fi # IP used by the phone in your wireless network WIFI_IP=192.168.2.122 @@ -17,46 +24,76 @@ WIFI_IP=192.168.2.122 # Port on which IP Webcam is listening PORT=8080 +# URL on which the latest v4l2loopback DKMS .deb can be found +V4L2LOOPBACK_DEB_URL=http://ftp.us.debian.org/debian/pool/main/v/v4l2loopback/v4l2loopback-dkms_0.4.0-1_all.deb + +# Path to which the v4l2loopback DKMS .deb should be saved +V4L2LOOPBACK_DEB_PATH=/tmp/v4l2loopback-dkms.deb + ### FUNCTIONS has_kernel_module() { - modprobe -q "$1" + sudo modprobe -q "$1" } error() { - zenity --error --text $@ + zenity --error --text "$@" exit 1 } warning() { - zenity --warning --text "$1" + zenity --warning --text "$@" } info() { - zenity --info --text "$1" + zenity --info --text "$@" } confirm() { - zenity --question --text "$1" + zenity --question --text "$@" } -can_run() { - type -P "$1" >/dev/null +can_run() { + # It's either the path to a file, or the name of an executable in $PATH + (test -x "$1" || which "$1") >/dev/null +} + +start_adb() { + can_run "$ADB" && "$ADB" start-server } phone_plugged() { - test "$("$ADB" get-state)" == "device" + start_adb && test "$("$ADB" get-state)" == "device" } url_reachable() { curl -sI "$1" >/dev/null } +send_intent() { + start_adb && "$ADB" shell am start -a android.intent.action.MAIN -n $@ +} + +iw_server_is_started() { + url_reachable "$VIDEO_URL" +} + +start_iw_server() { + send_intent com.pas.webcam/.Rolling + sleep 2s +} + ### MAIN BODY # Check if the user has v4l2loopback if ! has_kernel_module v4l2loopback; then - error "The v4l2loopback kernel module is not installed or could not be loaded. Please install v4l2loopback from github.com/umlaeute/v4l2loopback." + info "The v4l2loopback kernel module is not installed or could not be loaded. I will try to install the kernel module using DKMS. If that doesn't work, please install v4l2loopback manually from github.com/umlaeute/v4l2loopback." + sudo apt-get install dkms + wget "$V4L2LOOPBACK_DEB_URL" -O "$V4L2LOOPBACK_DEB_PATH" + sudo dpkg -i "$V4L2LOOPBACK_DEB_PATH" + if has_kernel_module v4l2loopback; then + info "The v4l2loopback kernel module was installed successfully." + fi fi # Decide whether to connect through USB or through wi-fi @@ -65,7 +102,7 @@ if ! can_run "$ADB"; then warning "adb is not available: you'll have to use Wi-Fi, which will be slower. Next time, please install the Android SDK from developer.android.com/sdk." else while ! phone_plugged && ! confirm "adb is available, but the phone is not plugged in. Are you sure you want to use Wi-Fi (slower)? If you don't, please connect your phone to USB."; do - true; + true done if phone_plugged; then "$ADB" forward tcp:$PORT tcp:$PORT @@ -77,7 +114,11 @@ fi BASE_URL=http://$IP:$PORT VIDEO_URL=$BASE_URL/videofeed AUDIO_URL=$BASE_URL/audio.wav -while ! url_reachable "$VIDEO_URL"; do +if phone_plugged && ! iw_server_is_started; then + # If the phone is plugged to USB and we have ADB, we can start the server by sending an intent + start_iw_server +fi +while ! iw_server_is_started; do info "The IP Webcam video feed is not reachable at $VIDEO_URL. Please open IP Webcam in your phone and start the server." done @@ -88,7 +129,7 @@ fi # Install and open pavucontrol as needed if ! can_run pavucontrol; then - info "You don't have pavucontrol. I'll try to install its Ubuntu package." + info "You don't have pavucontrol. I'll try to install its Debian/Ubuntu package." sudo apt-get install pavucontrol fi if ! pgrep pavucontrol; then @@ -96,12 +137,13 @@ if ! pgrep pavucontrol; then pavucontrol & fi -# Start up the required GStreamer graph +# Check for gst-launch if ! can_run gst-launch; then - info "You don't have gst-launch. I'll try to install its Ubuntu package." - sudo apt-get install gstreamer0.10-tools + info "You don't have gst-launch. I'll try to install its Debian/Ubuntu package." + sudo apt-get install gstreamer-tools fi +# Start the GStreamer graph needed to grab the video and audio set +e info "Using IP Webcam as webcam/microphone. You can now open your videochat app." gst-launch -v \ |