Exemple #1
0
static int process_packet(void *user_data, const uint8_t *pkt, int len)
{
    static udptl_state_t *state = NULL;

    if (state == NULL)
        state = udptl_init(NULL, UDPTL_ERROR_CORRECTION_REDUNDANCY, 3, 3, ifp_handler, NULL);

    udptl_rx_packet(state, pkt, len);
    return 0;
}
Exemple #2
0
int fax_rxUDPTL(const session_t *session, const uint8_t *buf, int len)
{
    int ret_val = 0;
    int res = 0;

    if(!session || !buf)
    {
        ret_val = -1; goto _exit;
    }

    res = udptl_rx_packet(session->fax_params.pvt.udptl_state,
                          buf, len);
    if(res)
    {
        app_trace(TRACE_ERR, "Fax %04x. UDPTL RX failed (%d)",
                  session->ses_id, res);
        ret_val = -2;
    }

_exit:
    return ret_val;
}
Exemple #3
0
/*
 *  Thread for fax receiving
 *  We need to receive UDP (with UDPTL) packet and feed it to spandsp and also
 *  get UDPTL from spandsp and send them to remote IAF
 */
void *fax_worker_thread(void *data)
{
    fax_session_t *fax_session = (fax_session_t *)data;
    struct sockaddr_in local_addr;
    int ret_val = 0;
    int bytes_received = 0;
    const int poll_timeout = 20;
    struct pollfd fds;

    struct in_addr addr;
    addr.s_addr = htonl(fax_session->remote_ip);


    printf("fax: Starting T.38 FAX handling: local_port: %d remote_addr:%s:%d\n",
           fax_session->local_port, inet_ntoa(addr), fax_session->remote_port);

    fax_params_init(fax_session);

    ret_val = socket_init(&local_addr, fax_session);
    if (ret_val < 0) {
        printf("fax: Fax socket init failed\n");
        goto thread_finish;
    }

    fds.fd = ret_val;
    fds.events = POLLIN;

    fax_params_set_default(fax_session);
    if (spanfax_init(fax_session, FAX_TRANSPORT_T38_MOD) != 0) {
        printf("fax: spanfax_init() ERROR\n");
        goto thread_finish;
    }

    configure_t38(fax_session);

    if(!fax_session->pvt.caller)
    {
        printf("fax %s receiver: wait first frame\n", fax_session->call_id);
        bytes_received = receive_frame(fax_session, msg_buffer, MAX_MSG_SIZE);
        printf("fax %s receiver: first frame received\n", fax_session->call_id);
    }

    fcntl(fax_session->socket_fd, F_SETFL, O_NONBLOCK);

    while (!fax_session->pvt.done) {

        /*
         * All we need to do here is:
         *      1) Receive new UDPTL packet without blocking
         *      2) Feed it to spandsp (udptl_rx_packet)
         *      3) Invoke t38_terminal_send_timeout() function
         */
        ret_val = poll(&fds, 1, poll_timeout);
        if (ret_val == -1) {
            perror("poll");
            break;
        }

        if (fds.revents & POLLIN) {

            bytes_received = receive_frame(fax_session, msg_buffer, MAX_MSG_SIZE);
//            printf("fax: Packet RECEIVED (size: %d)\n", bytes_received);
            if (bytes_received == 0) continue;
            if (bytes_received == -1) {
                printf("fax: receive_frame() ERRROR: returned -1\n");
                break;
            }

            ret_val = udptl_rx_packet(fax_session->pvt.udptl_state,
                                      msg_buffer, bytes_received);
            if (ret_val) printf("fax %s: udptl_rx_packet() ERROR\n", fax_session->call_id);
        }

        t38_terminal_send_timeout(fax_session->pvt.t38_state, FRAMES_PER_CHUNK);
    }

thread_finish:
    spanfax_destroy(fax_session);
    fax_params_destroy(fax_session);

    close(fds.fd);

    pthread_exit(NULL);
}