From da2abace4f116ca0431feeb22d0ca41863489426 Mon Sep 17 00:00:00 2001 From: Andreas Eversberg Date: Sun, 5 Mar 2023 12:21:22 +0100 Subject: [PATCH] Send two B-channel frames when first frame is received The size of both frames match the receive size. --- src/pstn/pstn.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/pstn/pstn.c b/src/pstn/pstn.c index e2d16f2..00c5dc3 100644 --- a/src/pstn/pstn.c +++ b/src/pstn/pstn.c @@ -723,18 +723,9 @@ static void bchannel_rx_tx(pstn_t *pstn, uint8_t *data, int len) } } - uint8_t init_data[len * 2]; - int offset = 0; - if (!pstn->b_transmitting) { - PDEBUG(DTEL, DEBUG_DEBUG, "First received b-channel data, filling FIFO with double data of %d bytes.\n", len * 2); - memset(init_data, 0xff, len); - data = init_data; - offset = len; - } - /* load from TX jitter buffer and optionally overload with tones an with caller ID */ - jitter_load(&pstn->tx_dejitter, data + offset, len); - isdn_tone_copy(&pstn->isdn_tone, data + offset, len); + jitter_load(&pstn->tx_dejitter, data, len); + isdn_tone_copy(&pstn->isdn_tone, data, len); switch (pstn->callerid_state) { case PSTN_CID_STATE_OFF: @@ -766,7 +757,7 @@ static void bchannel_rx_tx(pstn_t *pstn, uint8_t *data, int len) g711_encode_alaw_flipped((uint8_t *)spl, rc * 2, &data_cid, &len_cid, NULL); else g711_encode_ulaw_flipped((uint8_t *)spl, rc * 2, &data_cid, &len_cid, NULL); - memcpy(data + offset, data_cid, len_cid); + memcpy(data, data_cid, len_cid); free(data_cid); } if (rc < len) { @@ -798,10 +789,18 @@ static void bchannel_rx_tx(pstn_t *pstn, uint8_t *data, int len) break; } - /* forward to interface */ - ph_socket_tx_msg(&pstn->ph_socket, 1, PH_PRIM_DATA_REQ, data, len + offset); + if (!pstn->b_transmitting) { + uint8_t init_data[len]; + PDEBUG(DTEL, DEBUG_DEBUG, "First received b-channel data, sending two frames, to preload FIFO with %d extra bytes.\n", len); + memset(init_data, 0xff, len); + /* forward to interface */ + ph_socket_tx_msg(&pstn->ph_socket, 1, PH_PRIM_DATA_REQ, init_data, len); + pstn->b_transmitting = 1; + } + + /* forward to interface */ + ph_socket_tx_msg(&pstn->ph_socket, 1, PH_PRIM_DATA_REQ, data, len); - pstn->b_transmitting = 1; } /*