summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJaromil <jaromil@dyne.org>2012-05-09 09:24:25 (GMT)
committer Jaromil <jaromil@dyne.org>2012-05-09 09:24:25 (GMT)
commita8e104dabd0e1ecc479ca1d6abc0f221bda8d559 (patch)
tree1ffd70e3bead9c970c40762a8c4bf71aae327b04
parentec46a4a1ee35d2fe11cb0e7595c1cb31f4fbc736 (diff)
looping works, also running over 4 hours
-rw-r--r--scripts/S88hdsync54
-rwxr-xr-xscripts/assemble-app-bin.sh8
-rw-r--r--scripts/utils-sync.sh27
-rw-r--r--src/Makefile.am5
-rw-r--r--src/hdsync_cli.cpp60
5 files changed, 96 insertions, 58 deletions
diff --git a/scripts/S88hdsync b/scripts/S88hdsync
index 8e4b792..64989bd 100644
--- a/scripts/S88hdsync
+++ b/scripts/S88hdsync
@@ -57,7 +57,6 @@ export USBROOT
export APPROOT
export HDSYNC_NETWORK
export HDSYNC_CHANNEL
-export HDSYNC_SLEEP
export TOTAL_CHANNELS
# load up utils
@@ -69,10 +68,6 @@ get_ip
# retrieve application details
get_bins $APPROOT
-if [ $HDSYNC_SLEEP ]; then
- echo "SLEEP adjust set to $HDSYNC_SLEEP useconds" >> /tmp/hdsync.log
-fi
-
UPNPPORT="`lsof -a -i4 -sTCP:LISTEN -c DMARender -F n | awk -v FS=':' '/^n/ {print $2}'`"
export UPNPPORT
echo "UPNP port detected listening on $UPNPPORT" >> /tmp/hdsync.log
@@ -91,22 +86,37 @@ killall pandora_ep
killall apache2
killall smbtree
-if test $WATCHDOGTIMER -gt 0; then
- #start watchdog timer
- echo "starting watchdog, movielenght is $WATCHDOGTIMER"
- ps | grep watchdog | grep -v grep
- if [ $? -ne 0 ]; then
- rm -f /tmp/hdsync.error
- touch /tmp/hdsync.error
- $APPROOT/bin/watchdog.sh >> /tmp/hdsync.error &
- fi
-fi
+# if test $WATCHDOGTIMER -gt 0; then
+# #start watchdog timer
+# echo "starting watchdog, movielenght is $WATCHDOGTIMER"
+# ps | grep watchdog | grep -v grep
+# if [ $? -ne 0 ]; then
+# rm -f /tmp/hdsync.error
+# touch /tmp/hdsync.error
+# $APPROOT/bin/watchdog.sh >> /tmp/hdsync.error &
+# fi
+# fi
+
+file=`ls $USBROOT/video`
+
+cat <<EOF >> /tmp/hdsync.log
+Launching hdsync for channel $HDSYNC_CHANNEL of $TOTAL_CHANNELS
+
+Command:
+
+$APPROOT/bin/hdsync -p $UPNPPORT -s localhost \
+ $HDSYNC_CHANNEL $TOTAL_CHANNELS \
+ "$USBROOT/video/$file"
+
+EOF
+
+while true; do
+
+ $APPROOT/bin/hdsync -p $UPNPPORT -s localhost \
+ $HDSYNC_CHANNEL $TOTAL_CHANNELS \
+ "$USBROOT/video/$file" >> /tmp/hdsync.log
+
+done
+
-if [ "$HDSYNC_CHANNEL" = "1" ]; then
- echo "Offering sync" >> /tmp/hdsync.log
- $APPROOT/bin/offer-sync.sh >> /tmp/hdsync.log
-else
- echo "Listening for sync offers" >> /tmp/hdsync.log
- $APPROOT/bin/listen-sync.sh >> /tmp/hdsync.log
-fi
diff --git a/scripts/assemble-app-bin.sh b/scripts/assemble-app-bin.sh
index e648ad1..72441fd 100755
--- a/scripts/assemble-app-bin.sh
+++ b/scripts/assemble-app-bin.sh
@@ -38,19 +38,15 @@ if [ -z $1 ]; then
mkdir -p $appdir/bin
mkdir -p $appdir/etc/init.d
- cp -v src/netcat $appdir/bin &&
- cp -v src/broadcaster $appdir/bin &&
- cp -v src/avremote $appdir/bin &&
cp -v src/hdsync $appdir/bin &&
- cp -v scripts/*-sync.sh $appdir/bin &&
- cp -v scripts/watchdog.sh $appdir/bin &&
+ cp -v scripts/utils-sync.sh $appdir/bin &&
cp -v scripts/S88hdsync $appdir/etc/init.d &&
chmod a+x $appdir/etc/init.d/S88hdsync &&
cp -v README $appdir &&
sudo chown -R root:root $appdir
- dd if=/dev/zero of=$imagefile bs=1K count=256 &&
+ dd if=/dev/zero of=$imagefile bs=1K count=5120 &&
/sbin/mkfs.ext3 -F $imagefile &&
/sbin/tune2fs -c 0 -i 0 $imagefile &&
mkdir -p $loopdir &&
diff --git a/scripts/utils-sync.sh b/scripts/utils-sync.sh
index 9b731a2..d2068cd 100644
--- a/scripts/utils-sync.sh
+++ b/scripts/utils-sync.sh
@@ -42,30 +42,3 @@ get_ip() {
}
-get_bins() {
- # wrapper to test in development on local paths
- if [ -z $1 ]; then
- NC="../src/netcat"
- BC="../src/broadcaster"
- AV="../src/avremote"
- SYNC="../src/hdsync"
-
- else
- NC="$APPROOT/bin/netcat"
- BC="$APPROOT/bin/broadcaster"
- AV="$APPROOT/bin/avremote"
- SYNC="$APPROOT/bin/hdsync"
- fi
-
- echo "`date +%T` hdsync binaries found:"
- echo "$BC"
- echo "$NC"
- echo "$AV"
- echo "$SYNC"
- export BC NC AV SYNC
-}
-
-prepare_play() {
- file=`ls $USBROOT/video`
- $SYNC -s localhost -p $UPNPPORT prepare "$USBROOT/video/$file"
-}
diff --git a/src/Makefile.am b/src/Makefile.am
index 6b17d1b..30d6c19 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -4,9 +4,8 @@ SUBDIRS = uuid pgm 0mq
bin_PROGRAMS = hdsync
-noinst_HEADERS = avremote.h discover.h intl.h misc.h netcat.h \
- parsers.h proto.h
+noinst_HEADERS = avremote.h discover.h intl.h misc.h netcat.h proto.h
-hdsync_SOURCES = avremote.cpp avremote.h hdsync_cli.cpp parsers.cpp parsers.h
+hdsync_SOURCES = avremote.cpp avremote.h hdsync_cli.cpp
hdsync_LDADD = uuid/libuuid.la 0mq/libzmq.la pgm/libpgm.la -lpthread
diff --git a/src/hdsync_cli.cpp b/src/hdsync_cli.cpp
index 0f6ec9e..f0f591c 100644
--- a/src/hdsync_cli.cpp
+++ b/src/hdsync_cli.cpp
@@ -85,6 +85,10 @@ void cmdline(int argc, char **argv);
int get_address();
+// return 1 on matched string
+// 0 otherwise
+int get_state(const char *match);
+
int shout(const char *message, int flags) {
int res;
@@ -390,10 +394,17 @@ int main(int argc, char **argv) {
send_upnp(peers[0]);
recv_upnp(peers[0], 1000);
+
zmq_sleep(1);
+
+ close(peers[0]->sockfd);
+ peers[0]->sockfd = 0;
+
} // if(test|real)
+ while( ! get_state("STOPPED") ) zmq_sleep(1);
+
fprintf(stderr,"Software shutdown\n");
zmq_close (sock_shout);
@@ -522,3 +533,52 @@ int get_address() {
}
return(1);
}
+
+
+
+#define MAX 256 // max XML string size
+// returns a pointer to the current position in haystack
+// for subsequent calls
+char *extract_xml(char *dest, char *haystack, const char *needle) {
+ char *p, *pp;
+
+ p = strstr(haystack, needle);
+ if (!p) {
+ fprintf(stderr, "parser cannot find \"%s\" in:\n%s\n",needle, haystack);
+ return NULL;
+ }
+ // as you can see, i had a lot of fun with pointers when i was a kid
+ pp = p; do pp+=1; while (*pp != '>'); pp++;
+ p = pp; do p+=1; while (*p != '<'); *p = 0;
+
+ snprintf(dest,MAX-1,"%s",pp);
+
+ return(p+1);
+
+}
+int get_state(const char *match) {
+ char state[MAX];
+ char status[MAX];
+ char speed[MAX];
+ char *p;
+
+ connect_upnp(peers[0]);
+ render_upnp(peers[0],"GetTransportInfo","");
+ send_upnp(peers[0]);
+ recv_upnp(peers[0], 1000);
+ close(peers[0]->sockfd);
+ peers[0]->sockfd = 0;
+
+ p = extract_xml(state, peers[0]->res, "CurrentTransportState"); if(!p) return(0);
+ p = extract_xml(status, p, "CurrentTransportStatus");
+ p = extract_xml(speed, p, "CurrentSpeed");
+
+ // fprintf(stderr,"#\tstate\tstatus\tspeed\n");
+ // fprintf(stderr,"TInfo:\t%s\t%s\t%s\n", state, status, speed);
+
+ if( strcmp(match, state) == 0) return(1);
+
+ return(0);
+}
+
+