para_server: New command line option: --autoplay_delay
[paraslash.git] / ortp_recv.c
index d9b2609..287d706 100644 (file)
@@ -32,8 +32,6 @@
 
 #define CHUNK_SIZE 128 * 1024
 
-extern int msg_to_buf(mblk_t *, char *, int);
-
 /**
  * data specific to the ortp receiver
  *
@@ -67,6 +65,37 @@ uint32_t timestamp;
 uint32_t chunk_ts;
 };
 
+
+static int msg_to_buf(mblk_t *mp, char *buffer, int len)
+{
+       int rlen = len;
+       mblk_t *m, *mprev;
+       int mlen;
+
+       m = mp->b_cont;
+       mprev = mp;
+       while (m != NULL) {
+               mlen = (int) (m->b_wptr - m->b_rptr);
+               if (mlen <= rlen) {
+                       mblk_t *consumed = m;
+                       memcpy (buffer, m->b_rptr, mlen);
+                       /* go to next mblk_t */
+                       mprev->b_cont = m->b_cont;
+                       m = m->b_cont;
+                       consumed->b_cont = NULL;
+                       freeb (consumed);
+                       buffer += mlen;
+                       rlen -= mlen;
+               } else {  /*if mlen>rlen */
+                       memcpy (buffer, m->b_rptr, rlen);
+                       m->b_rptr += rlen;
+                       return len;
+               }
+       }
+       return len - rlen;
+}
+
+
 static void ortp_recv_pre_select(struct sched *s, struct task *t)
 {
        struct receiver_node *rn = t->private_data;
@@ -91,9 +120,9 @@ static void compute_next_chunk(unsigned chunk_time,
        tv_add(&chunk_tv, &pord->next_chunk, &tmp);
        pord->next_chunk = tmp;
        pord->timestamp += pord->chunk_ts;
-       PARA_DEBUG_LOG("next chunk (ts = %d) due at %lu:%lu\n",
-               pord->timestamp, pord->next_chunk.tv_sec,
-               pord->next_chunk.tv_usec);
+//     PARA_DEBUG_LOG("next chunk (ts = %d) due at %lu:%lu\n",
+//             pord->timestamp, pord->next_chunk.tv_sec,
+//             pord->next_chunk.tv_usec);
 }
 
 static void ortp_recv_post_select(__a_unused struct sched *s, struct task *t)
@@ -244,20 +273,21 @@ static void *ortp_recv_parse_config(int argc, char **argv)
 static int ortp_recv_open(struct receiver_node *rn)
 {
        struct private_ortp_recv_data *pord;
-       struct ortp_recv_args_info *conf = rn->conf;
+       struct ortp_recv_args_info *c = rn->conf;
 
        rn->buf = para_calloc(CHUNK_SIZE);
 
        rn->private_data = para_calloc(sizeof(struct private_ortp_recv_data));
        pord = rn->private_data;
        pord->session = rtp_session_new(RTP_SESSION_RECVONLY);
-       PARA_NOTICE_LOG("receiving from %s:%d\n", conf->host_arg, conf->port_arg);
-       rtp_session_set_local_addr(pord->session, conf->host_arg, conf->port_arg);
+       PARA_NOTICE_LOG("receiving from %s:%d\n", c->host_arg, c->port_arg);
+       rtp_session_set_local_addr(pord->session, c->host_arg, c->port_arg);
+       rtp_session_set_remote_addr(pord->session, c->host_arg, c->port_arg);
        rtp_session_set_payload_type(pord->session, PAYLOAD_AUDIO_CONTINUOUS);
-       if (conf->jitter_compensation_arg) {
+       if (c->jitter_compensation_arg) {
                rtp_session_enable_adaptive_jitter_compensation(pord->session, TRUE);
                rtp_session_set_jitter_compensation(pord->session,
-                       conf->jitter_compensation_arg);
+                       c->jitter_compensation_arg);
        }
        return 1;
 }