summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJaromil <jaromil@dyne.org>2011-08-18 15:56:55 (GMT)
committer Jaromil <jaromil@dyne.org>2011-08-18 15:56:55 (GMT)
commitf521699506584b5d55922d92daa5bc7a32314d9c (patch)
treea1e18bd92e69545f6d2467fdca8fa9c67433f857
parentc8661094376d34b89ff72685684b1fb9e16e55f1 (diff)
new hdsync cli interface to avremote
now we have a load, play and pause within the same process this should speed up sync significantly
-rwxr-xr-xscripts/assemble-app-bin.sh3
-rwxr-xr-xscripts/listen-sync.sh2
-rwxr-xr-xscripts/offer-sync.sh6
-rw-r--r--scripts/utils-sync.sh21
-rw-r--r--src/Makefile.am6
-rw-r--r--src/avremote_cli.c (renamed from src/cmdline.c)21
-rw-r--r--src/hdsync_cli.c228
7 files changed, 259 insertions, 28 deletions
diff --git a/scripts/assemble-app-bin.sh b/scripts/assemble-app-bin.sh
index d403304..442261c 100755
--- a/scripts/assemble-app-bin.sh
+++ b/scripts/assemble-app-bin.sh
@@ -40,7 +40,8 @@ if [ -z $1 ]; then
cp -v src/netcat $appdir/bin &&
cp -v src/broadcaster $appdir/bin &&
- cp -v src/avremote $appdir/bin &&
+ cp -v src/avremote $appdir/bin &&
+ cp -v src/hdsync $appdir/bin &&
cp -v scripts/*-sync.sh $appdir/bin &&
cp -v scripts/S88hdsync $appdir/etc/init.d &&
chmod a+x $appdir/etc/init.d/S88hdsync &&
diff --git a/scripts/listen-sync.sh b/scripts/listen-sync.sh
index bc4bbbd..5be33a0 100755
--- a/scripts/listen-sync.sh
+++ b/scripts/listen-sync.sh
@@ -69,7 +69,7 @@ while [ true ]; do
fi
# "press play on tape"
- $AV -p $UPNPPORT play
+ $SYNC -s localhost -p $UPNPPORT start
echo "sync playback started on `date +%T`"
fi
diff --git a/scripts/offer-sync.sh b/scripts/offer-sync.sh
index e16d758..6f1d0ec 100755
--- a/scripts/offer-sync.sh
+++ b/scripts/offer-sync.sh
@@ -75,10 +75,10 @@ while [ true ]; do
if [ $HDSYNC_SLEEP ]; then
sleep $HDSYNC_SLEEP
fi
-
+
# "press play on tape"
- $AV -p $UPNPPORT play
-
+ $SYNC -s localhost -p $UPNPPORT start
+
echo "sync playback started on `date +%T`"
fi
done \ No newline at end of file
diff --git a/scripts/utils-sync.sh b/scripts/utils-sync.sh
index 36d4f9c..b393cb9 100644
--- a/scripts/utils-sync.sh
+++ b/scripts/utils-sync.sh
@@ -45,15 +45,20 @@ get_bins() {
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 "hdsync binaries found:"
echo "$BC"
echo "$NC"
echo "$AV"
+ echo "$SYNC"
export BC NC AV
}
@@ -62,20 +67,14 @@ prepare_play() {
config_tool -c DMA_ENABLE_SCREENSAVER='0'
config_tool -c DMA_SCREENSAVER='0'
- file=`ls $USBROOT/video`
- $AV -p $UPNPPORT load "$USBROOT/video/$file"
-
- sync
+ # kill dmaosd!
+ killall dmaosd
- $AV -p $UPNPPORT play
+ file=`ls $USBROOT/video`
+ $SYNC -s localhost -p $UPNPPORT prepare "$USBROOT/video/$file"
+ # hdsync prepare makes: load, play and pause
sync
- sleep 5
-
- $AV -p $UPNPPORT stop
-
- # kill dmaosd!
- killall dmaosd
# $AV -p $UPNPPORT pause
# sync
diff --git a/src/Makefile.am b/src/Makefile.am
index fea2222..961dcaa 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,4 +1,4 @@
-bin_PROGRAMS = netcat broadcaster hdsync
+bin_PROGRAMS = netcat broadcaster hdsync avremote
netcat_SOURCES = \
core.c \
@@ -11,7 +11,9 @@ netcat_SOURCES = \
broadcaster_SOURCES = broadcaster.cpp
-hdsync_SOURCES = avremote.c avremote.h cmdline.c parsers.c parsers.h
+hdsync_SOURCES = avremote.c avremote.h hdsync_cli.c parsers.c parsers.h
+
+avremote_SOURCES = avremote.c avremote.h avremote_cli.c parsers.c parsers.h
netcat_nc = $(DESTDIR)$(bindir)/nc
diff --git a/src/cmdline.c b/src/avremote_cli.c
index 9104633..401dfb8 100644
--- a/src/cmdline.c
+++ b/src/avremote_cli.c
@@ -40,16 +40,18 @@
// uncomment to debug
#define DEBUG 1
-// uncomment to also use UPNP discovery
-// (depends from miniupnp library)
-// #define UPNP_DISCOVERY 1
+// uncomment to activate discovery
+// (requires miniupnp)
+// #define DISCOVER 1
char filename[512];
char command[64];
char server[512];
int port = 0;
int dry_run = 0;
+#ifdef DISCOVER
int discover = 0;
+#endif
int pipe_stdin = 0;
parser_f *parser = NULL;
@@ -78,7 +80,7 @@ void cmdline(int argc, char **argv) {
"\n"
"Commands:\n"
"\n"
-#ifdef UPNP_DISCOVERY
+#ifdef DISCOVER
" discover scan for upnp devices on the network\n"
#endif
" load load a file and prepare it for playback\n"
@@ -143,7 +145,7 @@ void cmdline(int argc, char **argv) {
} while(res != -1);
-#ifdef UPNP_DISCOVERY
+#ifdef DISCOVER
if(command[0] == 'd') { // discover
discover = 1;
} else
@@ -163,8 +165,8 @@ int main(int argc, char **argv) {
cmdline(argc, argv);
upnp = create_upnp();
-
-#ifdef UPNP_DISCOVERY
+
+#ifdef DISCOVER
// no server specified, force discovery
if(!server[0] || !port) discover = 1;
@@ -237,12 +239,11 @@ int main(int argc, char **argv) {
*/
switch(command[0]) {
+#ifdef DISCOVER
case 'd': // discovery
-#ifndef UPNP_DISCOVER
- fprintf(stderr,"UPNP discovery feature not enabled for this binary\n");
-#endif
// was processed earlier
break;
+#endif
case 'l': // load url
render_uri_meta(upnp,filename);
diff --git a/src/hdsync_cli.c b/src/hdsync_cli.c
new file mode 100644
index 0000000..f57835c
--- /dev/null
+++ b/src/hdsync_cli.c
@@ -0,0 +1,228 @@
+/* HDSync
+
+ (c) 2011 Nederlands Instituut voor Mediakunst (NIMk)
+ 2011 Denis Roio <jaromil@nimk.nl>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>
+
+*/
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netdb.h>
+
+#include <errno.h>
+
+#include <avremote.h>
+#include <parsers.h>
+
+// our exit codes are shell style: 1 is error, 0 is success
+#define ERR 1
+
+// uncomment to debug
+#define DEBUG 1
+
+
+char filename[512];
+char command[64];
+char server[512];
+int port = 0;
+
+parser_f *parser = NULL;
+
+// we use only getopt, no _long
+static const char *short_options = "-hvs:p:";
+
+void cmdline(int argc, char **argv) {
+ command[0] = 0;
+ filename[0] = 0;
+ server[0] = 0;
+
+ int res, optlen;
+ do {
+ res = getopt(argc, argv, short_options);
+ switch(res) {
+ case 'h':
+ fprintf(stderr,
+ "%s %s - prepare and start synced playback of video across devices\n"
+ "\n"
+ " Copyright (C) 2011 Jaromil @ NIMk.nl Artlab , License GNU AGPL v3+\n"
+ " This is free software: you are free to change and redistribute it.\n"
+ " The latest HDSync sourcecode is published on <%s>\n"
+ "\n"
+ "Syntax: hdsync [options] [command] [args...]\n"
+ "\n"
+ "Commands:\n"
+ "\n"
+ " prepare prepare a file ready to sync\n"
+ " start start the video that was prepared\n"
+ "\n"
+ "Options:\n"
+ "\n"
+ " -s network address or hostname of the media server\n"
+ " -p port on which the UPNP AVTransport daemon is listening\n"
+ " -t dry run to test without a server (print out rendered xml)\n"
+ "\n"
+ " -h print this help\n"
+ " -v version information for this tool\n"
+ "\n"
+ "For more informations on HDSync see: http://nimk.nl/syncstarter\n"
+ "Please report bugs on <http://bugs.dyne.org>.\n",
+ PACKAGE, VERSION, PACKAGE_URL);
+ exit(0);
+
+ case 'v':
+ fprintf(stderr,"%s - simple commandline tool to send AVTransport commands over UPNP\n"
+ "version %s by Jaromil - Netherlands Media Art Institute\n"
+ "Copyright (C) 2011 NIMk Artlab, License GNU AGPL v3+\n"
+ "This is free software: you are free to change and redistribute it\n",
+ PACKAGE, VERSION);
+ exit(0);
+
+ case 's':
+ snprintf(server,511,"%s",optarg);
+ break;
+
+ case 'p':
+ sscanf (optarg, "%u", &port);
+ break;
+
+ case '?':
+ fprintf(stderr,"unrecognized option: %s\n",optarg);
+ break;
+
+ case 1:
+ if(!command[0]) {
+ snprintf(command,63,"%s",optarg);
+ } else
+ snprintf(filename,511,"%s",optarg);
+ break;
+ default:
+ break;
+ }
+
+ } while(res != -1);
+}
+
+
+int main(int argc, char **argv) {
+ upnp_t *upnp;
+ int found;
+
+ cmdline(argc, argv);
+
+ upnp = create_upnp();
+
+ // no server specified, force localhost
+ if(!server[0]) sprintf(server,"localhost");
+
+ // commandline or detection found explicit addresses
+ snprintf(upnp->hostname, MAX_HOSTNAME_SIZE-1,"%s",server);
+ upnp->port = port;
+
+ if ( connect_upnp (upnp) < 0 )
+ {
+ fprintf(stderr,"can't connect to %s:%u: operation aborted.\n", server, port);
+ exit(ERR);
+ }
+
+ /* command parsing is a cascade switch on single letters
+ this is supposedly faster than strcmp. mapping:
+
+ P repare
+ S tart
+
+ */
+ switch(command[0]) {
+
+ case 'p': // Prepare
+
+ // load, play and pause in sequence
+ // break and reopen connection in between
+
+ // was connected already
+
+ // load
+ render_uri_meta(upnp,filename);
+ render_upnp(upnp,"SetAVTransportURI", upnp->meta);
+
+ // must re-connect socket between commands
+ send_upnp(upnp);
+ recv_upnp(upnp, 1000);
+ close(upnp->sockfd);
+ upnp->sockfd = 0;
+
+ connect_upnp(upnp);
+ render_upnp(upnp,"Play","<Speed>1</Speed>");
+
+ send_upnp(upnp);
+ recv_upnp(upnp, 1000);
+ close(upnp->sockfd);
+ upnp->sockfd = 0;
+
+ connect_upnp(upnp);
+ render_upnp(upnp,"Pause","");
+ send_upnp(upnp);
+ recv_upnp(upnp, 1000);
+ break;
+
+ case 's': // start sync
+ // was connected already
+ render_upnp(upnp,"Play","<Speed>1</Speed>");
+ send_upnp(upnp);
+ recv_upnp(upnp, 1000);
+ break;
+
+ /*
+ case 'g': // dump a parsable full state of the device
+ render_upnp(upnp,"GetTransportInfo","");
+ parser = GetTransportInfo;
+
+ break;
+
+ case 'm': // set the playmode:
+ // "NORMAL", "REPEAT_ONE", "REPEAT_ALL", "RANDOM"
+ {
+ char tmp[256];
+ snprintf(tmp,255,"<NewPlayMode>%s</NewPlayMode>",filename);
+ render_upnp(upnp,"SetPlayMode",tmp);
+ }
+ break;
+
+ case 'j': // jump aka seek
+ // <SeekMode> and <SeekTarget>
+ {
+ char tmp[512];
+ snprintf(tmp,511,"<Unit>REL_TIME</Unit><Target>%s</Target>",filename);
+ render_upnp(upnp,"Seek",tmp);
+ }
+ break;
+ */
+ default:
+ if(!command[0]) break;
+ fprintf(stderr,"warning: command not recognized\n");
+ exit(1);
+ }
+
+ free_upnp(upnp);
+
+ exit(0);
+}