Fix: Allow recording of audio for SIP/remote/GSM interfaces too
authorAndreas Eversberg <jolly@eversberg.eu>
Tue, 21 Aug 2012 08:34:15 +0000 (10:34 +0200)
committerAndreas Eversberg <jolly@eversberg.eu>
Sun, 16 Dec 2012 09:11:47 +0000 (10:11 +0100)
gsm.cpp
mISDN.cpp
port.cpp
port.h
remote.cpp
sip.cpp

diff --git a/gsm.cpp b/gsm.cpp
index eeb91e8..3157e10 100644 (file)
--- a/gsm.cpp
+++ b/gsm.cpp
@@ -254,6 +254,12 @@ void Pgsm::frame_receive(void *arg)
                }
        }
 
+       /* record data */
+       if (p_record)
+               record(data, 160, 0); // from down
+       if (p_tap)
+               tap(data, 160, 0); // from down
+
        /* local echo */
        if (p_echotest)
                bridge_rx(data, 160);
@@ -275,6 +281,12 @@ int Pgsm::audio_send(unsigned char *data, int len)
 {
        unsigned char frame[33];
 
+       /* record data */
+       if (p_record)
+               record(data, len, 1); // from up
+       if (p_tap)
+               tap(data, len, 1); // from up
+
        /* encoder init failed */
        if (!p_g_encoder)
                return -EINVAL;
index ab25d3b..c32c43f 100644 (file)
--- a/mISDN.cpp
+++ b/mISDN.cpp
@@ -1113,6 +1113,8 @@ void PmISDN::bchannel_receive(struct mISDNhead *hh, unsigned char *data, int len
 //             printf(".");fflush(stdout);return;
                if (p_record)
                        record(data, len, 1); // from up
+               if (p_tap)
+                       tap(data, len, 1); // from up
                return;
        }
        if (hh->prim != PH_DATA_IND && hh->prim != DL_DATA_IND) {
@@ -1153,6 +1155,8 @@ void PmISDN::bchannel_receive(struct mISDNhead *hh, unsigned char *data, int len
        /* record data */
        if (p_record)
                record(data, len, 0); // from down
+       if (p_tap)
+               tap(data, len, 0); // from down
 
        /* randomize and listen to crypt message if enabled */
        if (p_m_crypt_listen) {
@@ -1449,7 +1453,7 @@ void PmISDN::update_rxoff(void)
        int tx_dejitter = 0;
 
        /* call bridges in user space OR crypto OR recording */
-       if (p_bridge || p_m_crypt_msg_loops || p_m_crypt_listen || p_record || p_m_inband_receive_on) {
+       if (p_bridge || p_m_crypt_msg_loops || p_m_crypt_listen || p_record || p_tap || p_m_inband_receive_on) {
                /* rx IS required */
                if (p_m_rxoff) {
                        /* turn on RX */
@@ -1470,8 +1474,8 @@ void PmISDN::update_rxoff(void)
                                        ph_control(p_m_mISDNport, this, p_m_mISDNport->b_sock[p_m_b_index].fd, DSP_RECEIVE_OFF, 0, "DSP-RXOFF", 1);
                }
        }
-       /* recording */
-       if (p_record) {
+       /* recording / tapping */
+       if (p_record || p_tap) {
                /* txdata IS required */
                if (!p_m_txdata) {
                        /* turn on RX */
index f1f92d1..4ffa822 100644 (file)
--- a/port.cpp
+++ b/port.cpp
@@ -179,6 +179,7 @@ Port::Port(int type, const char *portname, struct port_settings *settings, struc
 
        /* call recording */
        p_record = NULL;
+       p_tap = 0;
        p_record_type = 0;
        p_record_length = 0;
        p_record_skip = 0;
@@ -1164,6 +1165,10 @@ different_again:
 
 }
 
+void Port::tap(unsigned char *data, int length, int dir_fromup)
+{
+}
+
 void Port::update_rxoff(void)
 {
 }
diff --git a/port.h b/port.h
index af9610f..061d94c 100644 (file)
--- a/port.h
+++ b/port.h
@@ -231,11 +231,13 @@ class Port
        struct capa_info p_capainfo;    /* info on l2,l3 capacity */
        int p_echotest;                         /* set to echo audio data FROM port back to port's mixer */
 
-       /* recording */
+       /* recording/tapping */
        int open_record(int type, int mode, int skip, char *terminal, int anon_ignore, const char *vbox_email, int vbox_email_file);
        void close_record(int beep, int mute);
        void record(unsigned char *data, int length, int dir_fromup);
+       void tap(unsigned char *data, int length, int dir_fromup);
        FILE *p_record;                         /* recording fp: if not NULL, recording is enabled */
+       unsigned int p_tap;                     /* enpoint to send tapping audio to */
        int p_record_type;                      /* codec to use: RECORD_MONO, RECORD_STEREO, ... */
        int p_record_skip;                      /* skip bytes before writing the sample */
        unsigned int p_record_length;           /* size of what's written so far */
index fc28a59..4917f3b 100644 (file)
@@ -139,9 +139,19 @@ void Premote::message_remote(int message_type, union parameter *param)
 
        switch (message_type) {
        case MESSAGE_TRAFFIC:
+               /* 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);
                }
                return;
@@ -239,6 +249,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);
        }
 
diff --git a/sip.cpp b/sip.cpp
index 4def0a1..1e8d59d 100644 (file)
--- a/sip.cpp
+++ b/sip.cpp
@@ -257,6 +257,12 @@ we only support alaw and ulaw!
                return 0;
        }
 
+       /* record audio */
+       if (psip->p_record)
+               psip->record(payload, payload_len, 0); // from down
+       if (psip->p_tap)
+               psip->tap(payload, payload_len, 0); // from down
+
        n = payload_len;
        from = payload;
        to = payload;
@@ -487,6 +493,12 @@ int Psip::rtp_send_frame(unsigned char *data, unsigned int len, uint8_t payload_
        int duration; /* in samples */
        unsigned char buffer[256];
 
+       /* record audio */
+       if (p_record)
+               record(data, len, 1); // from up
+       if (p_tap)
+               tap(data, len, 1); // from up
+
        if (!p_s_rtp_is_connected) {
                /* drop silently */
                return 0;