diff options
Diffstat (limited to 'prepare-videochat.sh')
-rwxr-xr-x | prepare-videochat.sh | 76 |
1 files changed, 59 insertions, 17 deletions
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 \ |