diff options
-rwxr-xr-x | prepare-videochat.sh | 97 |
1 files changed, 76 insertions, 21 deletions
diff --git a/prepare-videochat.sh b/prepare-videochat.sh index 96bfda2..d1729fa 100755 --- a/prepare-videochat.sh +++ b/prepare-videochat.sh @@ -1,12 +1,12 @@ -#!/bin/sh +#!/bin/bash # Script for using IP Webcam as a microphone/webcam in Ubuntu 11.04 -# Copyright (C) 2010 Antonio García Domínguez +# Copyright (C) 2011 Antonio García Domínguez # Licensed under GPLv3 set -e -### CONFIGURATION START +### CONFIGURATION # Path to "adb" in the Android SDK ADB=~/bin/android-sdk-linux_x86/platform-tools/adb @@ -17,42 +17,97 @@ WIFI_IP=192.168.2.122 # Port on which IP Webcam is listening PORT=8080 -### CONFIGURATION END +### FUNCTIONS + +has_kernel_module() { + modprobe -q "$1" +} + +error() { + zenity --error --text $@ + exit 1 +} + +warning() { + zenity --warning --text "$1" +} + +info() { + zenity --info --text "$1" +} + +confirm() { + zenity --question --text "$1" +} + +can_run() { + type -P "$1" >/dev/null +} + +phone_plugged() { + test "$("$ADB" get-state)" == "device" +} + +url_reachable() { + curl -sI "$1" >/dev/null +} + +### 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." +fi # Decide whether to connect through USB or through wi-fi -if zenity --question --text "Is the phone plugged to a USB port?"; then - "$ADB" forward tcp:$PORT tcp:$PORT - IP=127.0.0.1 +IP=$WIFI_IP +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 - IP=$WIFI_IP + 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; + done + if phone_plugged; then + "$ADB" forward tcp:$PORT tcp:$PORT + IP=127.0.0.1 + fi fi # Remind the user to open up IP Webcam and start the server -zenity --info --text "Now open IP Webcam in your phone and start the server." +BASE_URL=http://$IP:$PORT +VIDEO_URL=$BASE_URL/videofeed +AUDIO_URL=$BASE_URL/audio.wav +while ! url_reachable "$VIDEO_URL"; 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 + +# Load null-sink if needed +if !(pactl list | grep -q module-null-sink); then + pactl load-module module-null-sink +fi # Install and open pavucontrol as needed -if ! type pavucontrol; then - zenity --info --text "You don't have pavucontrol. I'll try to install its Ubuntu package." +if ! can_run pavucontrol; then + info "You don't have pavucontrol. I'll try to install its Ubuntu package." sudo apt-get install pavucontrol fi if ! pgrep pavucontrol; then - zenity --info --text "We will open now pavucontrol. You should leave it open to change the recording device of your video chat program to 'Monitor Null Output'. NOTE: make sure that in 'Output Devices' *all* devices are listed." + info "We will open now pavucontrol. You should leave it open to change the recording device of your video chat program to 'Monitor Null Output'. NOTE: make sure that in 'Output Devices' *all* devices are listed." pavucontrol & fi -# Load null-sink if needed -if !(pactl list | grep -q module-null-sink); then - pactl load-module module-null-sink -fi - # Start up the required GStreamer graph -if ! type gst-launch; then - zenity --info --text "You don't have gst-launch. I'll try to install its Ubuntu package." +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 fi + +set +e +info "Using IP Webcam as webcam/microphone. You can now open your videochat app." gst-launch -v \ souphttpsrc location="http://$IP:$PORT/videofeed" do-timestamp=true is_live=true \ - ! jpegdec ! ffmpegcolorspace ! v4l2sink device=/dev/video0 \ + ! multipartdemux ! jpegdec ! ffmpegcolorspace ! v4l2sink device=/dev/video0 \ souphttpsrc location="http://$IP:$PORT/audio.wav" do-timestamp=true is_live=true \ - ! wavparse ! pulsesink device=null sync=false \ + ! wavparse ! audioconvert ! volume volume=3 ! rglimiter ! pulsesink device=null sync=false \ 2>&1 | tee feed.log +info "Disconnected from IP Webcam. Have a nice day!" |