diff options
Diffstat (limited to 'src/hdsync_cli.cpp')
| -rw-r--r-- | src/hdsync_cli.cpp | 201 |
1 files changed, 72 insertions, 129 deletions
diff --git a/src/hdsync_cli.cpp b/src/hdsync_cli.cpp index 915ced3..88163bc 100644 --- a/src/hdsync_cli.cpp +++ b/src/hdsync_cli.cpp @@ -91,7 +91,7 @@ int shout(const char *message, int flags) { // zmq_connect(sock_out, pgmaddr); zmq_msg_init_size (&request, strlen(message)); memcpy (zmq_msg_data (&request), message, strlen(message)); - printf ("Shouting \"%s\"\n", message); + // printf ("Shouting \"%s\"\n", message); res = zmq_send (sock_shout, &request, flags); zmq_msg_close (&request); // zmq_close(sock_out); @@ -107,7 +107,7 @@ int expect(const char *prefix, char *message, int flags) { char *p, *pp; int pfxlen = strlen(prefix); - printf("Expecting prefix %s\n",prefix); + // printf("Expecting prefix %s\n",prefix); // listen for answers zmq_msg_init (&reply); @@ -124,7 +124,7 @@ int expect(const char *prefix, char *message, int flags) { // *p has the ip string snprintf(message,511,"%s",p); - printf("Expected prefix %s found: %s\n",prefix,message); + // printf("Expected prefix %s found %s\n",prefix,message); return(0); } @@ -161,7 +161,7 @@ int handshake() { shout(message, 0); if( expect("ACK",res, 0) == 0) { - printf("Got ACK from %s\n",res); + // printf("Got ACK from %s\n",res); // parse the response and if ACK insert it in uniq list for(c=0; c<listindex; c++) if(strncmp(listeners[c], res, 16) == 0) @@ -214,6 +214,7 @@ int handshake() { int main(int argc, char **argv) { upnp_t *upnp; int found; + char tmp[512]; ////////// ///// INIT @@ -221,7 +222,7 @@ int main(int argc, char **argv) { cmdline(argc, argv); if(!filename[0]) { - fprintf(stderr,"not enough args specified on commandline, see help."); + fprintf(stderr,"not enough args specified on commandline, see help.\n"); exit(ERR); } @@ -293,19 +294,18 @@ int main(int argc, char **argv) { zmq_sleep(3); - shout("SYNC;GOGO;", 0); + shout("SYNC;;", 0); } else { // listener should prepare to receive sync - printf("Prepare to receive sync\n"); - // TODO - zmq_sleep(6); + while( expect("SYNC", tmp, 0) !=0); // blocking + } ////////////////////// - } else { // RUN FOR REAL + } else { // RUN FOR REAL, FUN FOR REAL ////////////////////// @@ -313,139 +313,87 @@ int main(int argc, char **argv) { // break and reopen connection in between - if(chanID==1) { // offer should send sync - zmq_sleep(1); - // create output socket - // sock_out = zmq_socket (zcontext, ZMQ_PUB); - // zmq_connect(sock_out, pgmaddr); - // prepare signal - zmq_msg_init_size (&request, 4); - memcpy (zmq_msg_data (&request), "SYNC", 4); - - // stop player - connect_upnp(upnp); - render_upnp(upnp,"Stop",""); - send_upnp(upnp); - recv_upnp(upnp, 1000); - close(upnp->sockfd); - upnp->sockfd = 0; - + // stop player + connect_upnp(upnp); + render_upnp(upnp,"Stop",""); + send_upnp(upnp); + recv_upnp(upnp, 1000); + close(upnp->sockfd); + upnp->sockfd = 0; - zmq_sleep(1); + zmq_sleep(1); + // load video into player + connect_upnp(upnp); + render_uri_meta(upnp,filename); + render_upnp(upnp,"SetAVTransportURI", upnp->meta); + send_upnp(upnp); + recv_upnp(upnp, 1000); + close(upnp->sockfd); + upnp->sockfd = 0; + + zmq_sleep(1); - // prepare player in position - render_uri_meta(upnp,filename); - render_upnp(upnp,"SetAVTransportURI", upnp->meta); - send_upnp(upnp); - recv_upnp(upnp, 1000); - close(upnp->sockfd); - upnp->sockfd = 0; + // play + connect_upnp(upnp); + render_upnp(upnp,"Play","<Speed>1</Speed>"); + send_upnp(upnp); + recv_upnp(upnp, 1000); + close(upnp->sockfd); + upnp->sockfd = 0; + + zmq_sleep(5); + + connect_upnp(upnp); + snprintf(tmp,511,"<Unit>REL_TIME</Unit><Target>%s</Target>",filename); + render_upnp(upnp,"Seek","<Unit>REL_TIME</Unit><Target>00:00:00</Target>"); + send_upnp(upnp); + recv_upnp(upnp, 1000); + close(upnp->sockfd); + upnp->sockfd = 0; + + // pause + connect_upnp(upnp); + render_upnp(upnp,"Pause",""); + send_upnp(upnp); + recv_upnp(upnp, 1000); + close(upnp->sockfd); + upnp->sockfd = 0; + + // prepare upnp play message + connect_upnp(upnp); + render_upnp(upnp,"Play","<Speed>1</Speed>"); + + if(chanID==1) { // offer should send sync - zmq_sleep(1); + zmq_sleep(2); - // play - connect_upnp(upnp); - render_upnp(upnp,"Play","<Speed>1</Speed>"); - send_upnp(upnp); - recv_upnp(upnp, 1000); - close(upnp->sockfd); - upnp->sockfd = 0; - // pause - connect_upnp(upnp); - render_upnp(upnp,"Pause",""); - send_upnp(upnp); - recv_upnp(upnp, 1000); - close(upnp->sockfd); - upnp->sockfd = 0; + shout("SYNC", 0); // send sync signal - zmq_sleep(1); + } else { - // prepare upnp play message - connect_upnp(upnp); - render_upnp(upnp,"Play","<Speed>1</Speed>"); - - // send sync signal - // zmq_send (sock_out, &request, 0); - - // start player - send_upnp(upnp); - recv_upnp(upnp, 1000); - - } else { // this is a listener - - // create input socket - sock_in = zmq_socket (zcontext, ZMQ_SUB); - zmq_bind (sock_in, pgmaddr); + // wait for sync + while( expect("SYNC", tmp, 0) !=0); // blocking + } - // stop player - connect_upnp(upnp); - render_upnp(upnp,"Stop",""); - send_upnp(upnp); - recv_upnp(upnp, 1000); - close(upnp->sockfd); - upnp->sockfd = 0; - - - zmq_sleep(1); - - - // prepare player in position - render_uri_meta(upnp,filename); - render_upnp(upnp,"SetAVTransportURI", upnp->meta); - send_upnp(upnp); - recv_upnp(upnp, 1000); - close(upnp->sockfd); - upnp->sockfd = 0; - - zmq_sleep(1); - - // play - connect_upnp(upnp); - render_upnp(upnp,"Play","<Speed>1</Speed>"); - send_upnp(upnp); - recv_upnp(upnp, 1000); - close(upnp->sockfd); - upnp->sockfd = 0; - // pause - connect_upnp(upnp); - render_upnp(upnp,"Pause",""); - send_upnp(upnp); - recv_upnp(upnp, 1000); - close(upnp->sockfd); - upnp->sockfd = 0; - - zmq_sleep(1); - - // prepare upnp play message - connect_upnp(upnp); - render_upnp(upnp,"Play","<Speed>1</Speed>"); - - // Wait for next request from client - zmq_msg_init (&request); - zmq_recv (sock_in, &request, 0); - if(strncmp((char*)zmq_msg_data(&request),"SYNC",4)==0) { - // start player - send_upnp(upnp); - recv_upnp(upnp, 1000); - } - - } // if(offer|listen) + // start player + send_upnp(upnp); + recv_upnp(upnp, 1000); - zmq_msg_close (&request); + zmq_sleep(1); + free_upnp(upnp); - } // if(test|real) fprintf(stderr,"Software shutdown\n"); // if(sock_out) { - // zmq_close (sock_out); + zmq_close (sock_shout); // sock_out = NULL; // } // if(sock_in) { - // zmq_close (sock_in); + zmq_close (sock_in); // sock_in = NULL; // } @@ -481,11 +429,6 @@ void cmdline(int argc, char **argv) { "\n" "Syntax: hdsync [options] channel_id channel_total filename\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" |

