From b24eaf88f62bd4ef913a9b51692d754de9a1f535 Mon Sep 17 00:00:00 2001 From: Martin Lucina Date: Wed, 3 Feb 2010 16:13:35 +0100 Subject: Fix multicast transports --- zmq-camera.c | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/zmq-camera.c b/zmq-camera.c index ce8e3da..5469808 100644 --- a/zmq-camera.c +++ b/zmq-camera.c @@ -78,6 +78,10 @@ const char local_camera[] = "inproc://local-camera"; /* inproc endpoint used for signalling the main thread */ const char local_signal[] = "inproc://local-signal"; +/* multicast transport options */ +const uint64_t mcast_rate = 100000; /* Rate limit for multicast, kbps */ +const uint64_t recovery_ivl = 5; /* Recovery interval for multicast, seconds */ + /* * Sender thread */ @@ -104,15 +108,24 @@ void *sender_thread (void *arg) unicap_data_buffer_t *returned_buffer; int conversion_found = 0; int index = 0; - uint64_t zmq_rate = 100000; /* Rate limit for PGM, kbps */ sender_args = (struct sender_args_t *)arg; - /* Create a ZMQ_PUB socket for sending video data and connect it to both - an inproc endpoint for the local loopback view and bind to the remote - endpoint specified by the user. */ + /* Create a ZMQ_PUB socket for sending video data */ s = zmq_socket (sender_args->ctx, ZMQ_PUB); assert (s); + + /* Set a suitable rate limit and recovery window for multicast transports. + This must be done before attempting to connect or bind the socket + to the multicast transport. */ + rc = zmq_setsockopt (s, ZMQ_RATE, &mcast_rate, sizeof mcast_rate); + assert (rc == 0); + rc = zmq_setsockopt (s, ZMQ_RECOVERY_IVL, &recovery_ivl, + sizeof recovery_ivl); + assert (rc == 0); + + /* Connect it to both an inproc endpoint for the local loopback view and + bind to the remote endpoint specified by the user. */ rc = zmq_connect (s, local_camera); assert (rc == 0); rc = zmq_bind (s, sender_args->endpoint); @@ -121,11 +134,6 @@ void *sender_thread (void *arg) zmq_strerror (errno)); exit (1); } - /* PGM transports need to have their default rate limit (100 kbps) raised - to something usable for our purposes. Use 100 Mbps as a default - for now. */ - rc = zmq_setsockopt (s, ZMQ_RATE, &zmq_rate, sizeof zmq_rate); - assert (rc == 0); /* Open first available video capture device. */ if (!SUCCESS (unicap_enumerate_devices (NULL, &device, 0))) { @@ -410,11 +418,22 @@ int main (int argc, char *argv []) (void *)&signal_args); assert (rc == 0); - /* Create a ZMQ_SUB socket to receive video data. If we're sending video, - bind to an inproc: endpoint that the sender thread will connect to, - otherwise connect to the remote endpoint the user specified. */ + /* Create a ZMQ_SUB socket to receive video data. */ s_video = zmq_socket (ctx, ZMQ_SUB); assert (s_video); + + /* Set a suitable rate limit and recovery window for multicast transports. + This must be done before attempting to connect or bind the socket + to the multicast transport. */ + rc = zmq_setsockopt (s_video, ZMQ_RATE, &mcast_rate, sizeof mcast_rate); + assert (rc == 0); + rc = zmq_setsockopt (s_video, ZMQ_RECOVERY_IVL, &recovery_ivl, + sizeof recovery_ivl); + assert (rc == 0); + + /* If we're sending video, bind to an inproc: endpoint that the sender + thread will connect to, otherwise connect to the remote endpoint the + user specified. */ if (opt_sender) { rc = zmq_bind (s_video, local_camera); assert (rc == 0); -- cgit v1.2.3