summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJaromil <jaromil@dyne.org>2011-04-01 19:39:30 (GMT)
committer Jaromil <jaromil@dyne.org>2011-04-01 19:39:30 (GMT)
commit773495d4ee0a61308302447e939a22487b1d96d6 (patch)
tree47ffd0fdfc5f9353cacc0f4916411ff8cdd284b3
parent701c9b906c8647b23889117645fdf8842a365f97 (diff)
debunking upnp commands
experimental shell-only upnp client for now only "load" works somehow other commands are accepted but not executed on screen anyway use of wget is more effective than netcat
-rw-r--r--scripts/S88hdsync18
-rwxr-xr-xscripts/listen-sync.sh13
-rwxr-xr-xscripts/offer-sync.sh25
-rwxr-xr-xscripts/upnp.sh62
-rw-r--r--scripts/utils-sync.sh36
5 files changed, 113 insertions, 41 deletions
diff --git a/scripts/S88hdsync b/scripts/S88hdsync
index ee35ad2..eb6b2cb 100644
--- a/scripts/S88hdsync
+++ b/scripts/S88hdsync
@@ -16,14 +16,24 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# wait the boot to complete
+
+if [ "$1" = "stop" ]; then
+ upnp.sh stop
+ rm -f /tmp/hdsync.reply
+ umount /apps/hdsync
+ exit 0
+fi
+
sleep 15
APPROOT=/apps/hdsync
+touch /tmp/hdsync.log
# USBROOT=`mount | awk '/.tmp.mnt/ { print $3}'`
USBROOT=`cat /tmp/appsRoot | grep hdsync | sed 's/hdsync//`
-echo "HDSync app running on USB $USBROOT" > /tmp/hdsync.log
+echo "HDSync app running on USB $USBROOT" >> /tmp/hdsync.log
date >> /tmp/hdsync.log
+echo "args: $@" >> /tmp/hdsync.log
# if there is a custom osd, we have to wait longer
ls $USBROOT/ | grep 'osd.bin$'
@@ -56,11 +66,15 @@ get_ip
# retrieve application details
get_bins $APPROOT
+# retrieve upnp port
+$UP detect
+# this exports UPNPPORT if a UPNP daemon is found listening
+
# wait that the usb is mounted
sleep 10
# will get ready for play button
-prepare_play
+prepare_play >> /tmp/hdsync.log
if [ "$HDSYNC_CHANNEL" = "1" ]; then
$APPROOT/bin/offer-sync.sh >> /tmp/hdsync.log
diff --git a/scripts/listen-sync.sh b/scripts/listen-sync.sh
index 7147d85..34b6745 100755
--- a/scripts/listen-sync.sh
+++ b/scripts/listen-sync.sh
@@ -21,11 +21,11 @@ PATH=/usr/bin:/bin:/usr/sbin:/sbin
# launch background listener for acks
-rm -f /tmp/offer.replies
-touch /tmp/offer.replies
-(while [ true ]; do
+rm -f /tmp/hdsync.reply
+touch /tmp/hdsync.reply
+(while [ -r /tmp/hdsync.reply ]; do
answer=`echo | $NC -c -u -l -p 3333`;
- echo $answer >> /tmp/offer.replies
+ echo $answer >> /tmp/hdsync.reply
done) &
echo "listening for offers on $IP"
@@ -42,7 +42,7 @@ while [ "$ack" = "" ]; do
sleep 1
echo "$IP" | $NC -c -u $offer 3331
echo -n "."
- ack=`cat /tmp/offer.replies`
+ ack=`cat /tmp/hdsync.reply`
done
echo "ack received, we are channel $ack"
@@ -55,9 +55,10 @@ echo "ready: awaiting syncstarter signal"
# exit after connection (-e true)
$NC -c -u -l -p 3336 -e true
+
# "press play on tape"
$UP play
-echo "sync playback started"
+echo "sync playback started on `date +%T`"
diff --git a/scripts/offer-sync.sh b/scripts/offer-sync.sh
index a0e545d..c0f6b2d 100755
--- a/scripts/offer-sync.sh
+++ b/scripts/offer-sync.sh
@@ -20,11 +20,11 @@ PATH=/usr/bin:/bin:/usr/sbin:/sbin
. $APPROOT/bin/utils-sync.sh
# launch background listener
-rm -f /tmp/offer.replies
-touch /tmp/offer.replies
+rm -f /tmp/hdsync.reply
+touch /tmp/hdsync.reply
(while [ true ]; do
answer=`echo | $NC -c -u -l -p 3331`;
- echo $answer >> /tmp/listener.replies
+ echo $answer >> /tmp/hdsync.reply
done) &
echo "broadcasting offer signals from $IP"
@@ -40,36 +40,29 @@ while [ "$listeners" != "$expected" ]; do
echo -n "$b: `date +%X` "
$BC $bcast 3332 $IP
sleep 2
- listeners=`cat /tmp/listener.replies | sort | uniq | wc -w`
+ listeners=`cat /tmp/hdsync.reply | sort | uniq | wc -w`
done
echo "harvesting replies"
-cat /tmp/listener.replies | sort | uniq > /tmp/listeners
+cat /tmp/hdsync.reply | sort | uniq > /tmp/hdsync.listeners
echo "sending acks"
c=1
-for l in `cat /tmp/listeners`; do
+for l in `cat /tmp/hdsync.listeners`; do
echo "$c: $l"
echo "$c" | $NC -c -u $l 3333
done
echo "waiting for other players to get ready..."
-sleep 15
+sleep 10
sync
# sync start!
$BC $bcast 3336 s
- # configurable wait step
-# sleep $OFFER_SLEEP
-
- # "press play on tape"
+# "press play on tape"
$UP play
-echo "sync playback started"
-
-
-
-
+echo "sync playback started on `date +%T`"
diff --git a/scripts/upnp.sh b/scripts/upnp.sh
index 1875958..08ea15c 100755
--- a/scripts/upnp.sh
+++ b/scripts/upnp.sh
@@ -12,6 +12,34 @@ if [ -z $1 ]; then
exit 0
fi
+HOST=127.0.0.1
+
+# detect UPNP port
+UPNPPORT="`lsof -a -i4 -sTCP:LISTEN -c DMARender -F n | awk -v FS=':' '/^n/ {print $2}'`"
+if ! [ $UPNPPORT ]; then
+ echo "error: no UPNP daemon found."
+ exit 1
+else
+ echo "UPNP daemon found listening on port $UPNPPORT"
+fi
+PORT=$UPNPPORT
+
+
+send_message() {
+ if [ -z $1 ]; then
+ echo "error: send_message"
+ return
+ fi
+ action="$1"
+ message="$2"
+ smsg="<?xml version=\"1.0\" encoding=\"utf-8\"?><s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><u:$action xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID>$message</s:Body></s:Envelope>"
+ wget -O - -q --post-data="$smsg" \
+ $HOST:$PORT/MediaRenderer_AVTransport/control \
+ --header="SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#$action\"" \
+ --bind-address=127.0.0.1
+ echo
+}
+
# make cmd case insensitive
cmd="`echo $1 | tr '[:upper:]' '[:lower:]'`"
@@ -19,17 +47,36 @@ case $cmd in
load)
file="$2"
- if ! [ -r "$file" ]; then
- echo "file not found: $file"
- echo "operation aborted."; exit 1
- fi
+ # if ! [ -r "$file" ]; then
+ # echo "file not found: $file"
+ # echo "operation aborted."; exit 1
+ # fi
uri="file://$file"
- upnp-cmd SetAVTransportURI "$uri"
+ dirName="`dirname "$file"`"
+ fileName="`basename "$file"`"
+ fileSize="`stat -c%s "$file"`"
+
+ meta="<DIDL-Lite xmlns=\"urn:schemas-upnp-org:metadata-1-0/DIDL-Lite\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:upnp=\"urn:schemas-upnp-org:metadata-1-0/upnp/\"><item id=\"2$file\" parentID=\"2$parentDir\" restricted=\"0\"><dc:title>$fileName</dc:title><dc:date></dc:date><upnp:class>object.item.imageItem</upnp:class><dc:creator></dc:creator><upnp:genre></upnp:genre><upnp:artist></upnp:artist><upnp:album></upnp:album><res protocolInfo=\"file-get:*:*:*:DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=00000000001000000000000000000000\" protection=\"\" tokenType=\"0\" bitrate=\"0\" duration=\"\" size=\"$fileSize\" colorDepth=\"0\" ifoFileURI=\"\" resolution=\"\">$uri</res></item></DIDL-Lite>"
+
+ msg="<CurrentURI>$uri</CurrentURI><CurrentURIMetaData>$meta</CurrentURIMetaData>"
+
+# send_message SetAVTransportURI "$msg"
+
+ upnp-cmd SetAVTransportURI "$uri" "$meta"
# allowed NewPlayMode = "NORMAL", "REPEAT_ONE", "REPEAT_ALL", "RANDOM"
upnp-cmd SetPlayMode REPEAT_ONE
;;
+ mode)
+ mode="$2"
+ msg="<NewPlayMode>$mode</NewPlayMode>"
+ send_message SetPlayMode "$msg"
+ ;;
+
play)
+# msg="<Speed>1</Speed>"
+# send_message Play "$msg"
+
upnp-cmd Play
;;
@@ -38,6 +85,7 @@ case $cmd in
;;
pause)
+# send_message Pause ""
upnp-cmd Pause
;;
@@ -48,5 +96,5 @@ case $cmd in
esac
-echo "command $cmd executed succesfully"
-exit 0
+#echo "command $cmd executed succesfully"
+
diff --git a/scripts/utils-sync.sh b/scripts/utils-sync.sh
index 69c1269..1cf6424 100644
--- a/scripts/utils-sync.sh
+++ b/scripts/utils-sync.sh
@@ -38,6 +38,7 @@ get_ip() {
export IP
}
+
get_bins() {
# wrapper to test in development on local paths
if [ -z $1 ]; then
@@ -49,7 +50,7 @@ get_bins() {
BC="$APPROOT/bin/broadcaster"
UP="$APPROOT/bin/upnp.sh"
fi
- echo "netcat binaries found:"
+ echo "hdsync binaries found:"
echo "$BC"
echo "$NC"
echo "$UP"
@@ -61,15 +62,30 @@ prepare_play() {
config_tool -c DMA_ENABLE_SCREENSAVER='0'
config_tool -c DMA_SCREENSAVER='0'
- # go to the video from the initial menu position
- echo "r" > /tmp/ir_injection; sleep 1
- echo "r" > /tmp/ir_injection; sleep 1
- echo "r" > /tmp/ir_injection; sleep 2
- echo "p" > /tmp/ir_injection; sleep 10
-# file=`ls $USBROOT/sync`
-# $UP load "$USBROOT/sync/$file"
- echo "T" > /tmp/ir_injection; sleep 5
+ file=`ls $USBROOT/sync`
+ state=`upnp-cmd GetTransportInfo | awk '/^.CurrentTransportState/ { print $3 }'`
+ $UP load "$USBROOT/sync/$file"
+ while [ "$state" = "NO_MEDIA_PRESENT" ]; do
+ state=`upnp-cmd GetTransportInfo | awk '/^.CurrentTransportState/ { print $3 }'`
+ done
+
+ sync
+
$UP play
+ state=`upnp-cmd GetTransportInfo | awk '/^.CurrentTransportState/ { print $3 }'`
+ while [ "$state" = "TRANSITIONING" ]; do
+ state=`upnp-cmd GetTransportInfo | awk '/^.CurrentTransportState/ { print $3 }'`
+ done
+
+ sync
+
$UP pause
-}
+ state=`upnp-cmd GetTransportInfo | awk '/^.CurrentTransportStatus/ { print $3 }'`
+ while [ "$state" = "PREBUFFING" ]; do
+ state=`upnp-cmd GetTransportInfo | awk '/^.CurrentTransportStatus/ { print $3 }'`
+ done
+ sync
+
+ echo "ready to play on `date +%T`"
+}