Data-Over-Voice
[lcr.git] / remote.cpp
index fc28a59..cb6e528 100644 (file)
@@ -24,6 +24,7 @@ Premote::Premote(int type, char *portname, struct port_settings *settings, struc
        p_r_ref = new_remote++;
        SCPY(p_r_remote_app, interface->remote_app);
        p_r_tones = (interface->is_tones == IS_YES);
+       p_r_earlyb = (interface->is_earlyb == IS_YES);
 
        /* send new ref to remote socket */
        memset(&param, 0, sizeof(union parameter));
@@ -139,9 +140,25 @@ void Premote::message_remote(int message_type, union parameter *param)
 
        switch (message_type) {
        case MESSAGE_TRAFFIC:
+               if (p_dov_rx)
+                       dov_rx(param->traffic.data, param->traffic.len);
+               /* record audio */
+               if (p_record)
+                       record(param->traffic.data, param->traffic.len, 0); // from down
+               if (p_tap)
+                       tap(param->traffic.data, param->traffic.len, 0); // from down
                bridge_tx(param->traffic.data, param->traffic.len);
                if (p_tone_name[0]) {
                        read_audio(param->traffic.data, param->traffic.len);
+                       /* record audio */
+                       if (p_record)
+                               record(param->traffic.data, param->traffic.len, 1); // from up
+                       if (p_tap)
+                               tap(param->traffic.data, param->traffic.len, 1); // from up
+                       admin_message_from_lcr(p_r_remote_id, p_r_ref, MESSAGE_TRAFFIC, param);
+               } else if (p_dov_tx) {
+                       /* use receeived traffic to trigger sending DOV */
+                       dov_tx(param->traffic.data, param->traffic.len);
                        admin_message_from_lcr(p_r_remote_id, p_r_ref, MESSAGE_TRAFFIC, param);
                }
                return;
@@ -222,10 +239,19 @@ int Premote::bridge_rx(unsigned char *data, int len)
 {
        union parameter newparam;
        int l;
-
-       /* don't send tones, if not enabled or not connected */
-       if (!p_r_tones
-        && p_state != PORT_STATE_CONNECT)
+       int ret;
+
+       if ((ret = Port::bridge_rx(data, len)))
+               return ret;
+
+       /* send tones, if connected, or if early audio is enabled in proceeding/alerting state */
+       if (p_state != PORT_STATE_CONNECT
+        && !(p_r_earlyb
+         && (p_state == PORT_STATE_OUT_PROCEEDING
+          || p_state == PORT_STATE_OUT_ALERTING))
+        && !(p_r_tones
+         && (p_state == PORT_STATE_IN_PROCEEDING
+          || p_state == PORT_STATE_IN_ALERTING)))
                return 0;
 
        if (p_tone_name[0])
@@ -239,6 +265,11 @@ int Premote::bridge_rx(unsigned char *data, int len)
                len -= l;
                memcpy(newparam.traffic.data, data, l);
                data += l;
+               /* record audio */
+               if (p_record)
+                       record(data, len, 1); // from up
+               if (p_tap)
+                       tap(data, len, 1); // from up
                admin_message_from_lcr(p_r_remote_id, p_r_ref, MESSAGE_TRAFFIC, &newparam);
        }