Пример #1
0
SPAN_DECLARE(span_sched_state_t *) span_schedule_init(span_sched_state_t *s)
{
    memset(s, 0, sizeof(*s));
    span_log_init(&s->logging, SPAN_LOG_NONE, NULL);
    span_log_set_protocol(&s->logging, "SCHEDULE");
    return s;
}
Пример #2
0
SPAN_DECLARE(ademco_contactid_sender_state_t *) ademco_contactid_sender_init(ademco_contactid_sender_state_t *s,
        tone_report_func_t callback,
        void *user_data)
{
    if (s == NULL)
    {
        if ((s = (ademco_contactid_sender_state_t *) span_alloc(sizeof(*s))) == NULL)
            return NULL;
    }
    memset(s, 0, sizeof(*s));
    span_log_init(&s->logging, SPAN_LOG_NONE, NULL);
    span_log_set_protocol(&s->logging, "Ademco");

    if (!tone_rx_init)
    {
        make_goertzel_descriptor(&tone_1400_desc, 1400.0f, GOERTZEL_SAMPLES_PER_BLOCK);
        make_goertzel_descriptor(&tone_2300_desc, 2300.0f, GOERTZEL_SAMPLES_PER_BLOCK);
        tone_rx_init = true;
    }
    goertzel_init(&s->tone_1400, &tone_1400_desc);
    goertzel_init(&s->tone_2300, &tone_2300_desc);
    s->current_sample = 0;

    s->callback = callback;
    s->callback_user_data = user_data;

    s->step = 0;
    s->remaining_samples = ms_to_samples(100);
    dtmf_tx_init(&s->dtmf, NULL, NULL);
    /* The specified timing is 50-60ms on, 50-60ms off */
    dtmf_tx_set_timing(&s->dtmf, 55, 55);
    return s;
}
Пример #3
0
SPAN_DECLARE(fax_state_t *) fax_init(fax_state_t *s, int calling_party)
{
    if (s == NULL)
    {
        if ((s = (fax_state_t *) malloc(sizeof(*s))) == NULL)
            return NULL;
    }
    memset(s, 0, sizeof(*s));
    span_log_init(&s->logging, SPAN_LOG_NONE, NULL);
    span_log_set_protocol(&s->logging, "FAX");
    fax_modems_init(&s->modems,
                    FALSE,
                    t30_hdlc_accept,
                    hdlc_underflow_handler,
                    t30_non_ecm_put_bit,
                    t30_non_ecm_get_bit,
                    tone_detected,
                    &s->t30);
    t30_init(&s->t30,
             calling_party,
             fax_set_rx_type,
             (void *) s,
             fax_set_tx_type,
             (void *) s,
             fax_send_hdlc,
             (void *) s);
    t30_set_supported_modems(&s->t30, T30_SUPPORT_V27TER | T30_SUPPORT_V29 | T30_SUPPORT_V17);
    t30_restart(&s->t30);
#if defined(LOG_FAX_AUDIO)
    {
        char buf[100 + 1];
        struct tm *tm;
        time_t now;

        time(&now);
        tm = localtime(&now);
        sprintf(buf,
                "/tmp/fax-rx-audio-%p-%02d%02d%02d%02d%02d%02d",
                s,
                tm->tm_year%100,
                tm->tm_mon + 1,
                tm->tm_mday,
                tm->tm_hour,
                tm->tm_min,
                tm->tm_sec);
        s->modems.audio_rx_log = open(buf, O_CREAT | O_TRUNC | O_WRONLY, 0666);
        sprintf(buf,
                "/tmp/fax-tx-audio-%p-%02d%02d%02d%02d%02d%02d",
                s,
                tm->tm_year%100,
                tm->tm_mon + 1,
                tm->tm_mday,
                tm->tm_hour,
                tm->tm_min,
                tm->tm_sec);
        s->modems.audio_tx_log = open(buf, O_CREAT | O_TRUNC | O_WRONLY, 0666);
    }
#endif
    return s;
}
Пример #4
0
SPAN_DECLARE(fax_modems_state_t *) fax_modems_init(fax_modems_state_t *s,
                                                   int use_tep,
                                                   hdlc_frame_handler_t hdlc_accept,
                                                   hdlc_underflow_handler_t hdlc_tx_underflow,
                                                   put_bit_func_t non_ecm_put_bit,
                                                   get_bit_func_t non_ecm_get_bit,
                                                   tone_report_func_t tone_callback,
                                                   void *user_data)
{
    if (s == NULL)
    {
        if ((s = (fax_modems_state_t *) span_alloc(sizeof(*s))) == NULL)
            return NULL;
    }
    /*endif*/
    memset(s, 0, sizeof(*s));
    s->use_tep = use_tep;

    modem_connect_tones_tx_init(&s->connect_tx, MODEM_CONNECT_TONES_FAX_CNG);
    span_log_init(&s->logging, SPAN_LOG_NONE, NULL);
    span_log_set_protocol(&s->logging, "FAX modems");

    s->tone_callback = tone_callback;
    s->tone_callback_user_data = user_data;
    if (tone_callback)
    {
        modem_connect_tones_rx_init(&s->connect_rx,
                                    MODEM_CONNECT_TONES_FAX_CNG,
                                    s->tone_callback,
                                    s->tone_callback_user_data);
    }
    /*endif*/
    dc_restore_init(&s->dc_restore);

    s->get_bit = non_ecm_get_bit;
    s->get_bit_user_data = user_data;
    s->put_bit = non_ecm_put_bit;
    s->put_bit_user_data = user_data;

    s->hdlc_accept = hdlc_accept;
    s->hdlc_accept_user_data = user_data;

    hdlc_rx_init(&s->hdlc_rx, false, false, HDLC_FRAMING_OK_THRESHOLD, fax_modems_hdlc_accept, s);
    hdlc_tx_init(&s->hdlc_tx, false, 2, false, hdlc_tx_underflow, user_data);

    fax_modems_start_slow_modem(s, FAX_MODEM_V21_RX);
    fsk_tx_init(&s->v21_tx, &preset_fsk_specs[FSK_V21CH2], (get_bit_func_t) hdlc_tx_get_bit, &s->hdlc_tx);

    silence_gen_init(&s->silence_gen, 0);

    s->rx_signal_present = false;
    s->rx_handler = (span_rx_handler_t) &span_dummy_rx;
    s->rx_fillin_handler = (span_rx_fillin_handler_t) &span_dummy_rx;
    s->rx_user_data = NULL;
    s->rx_fillin_user_data = NULL;
    s->tx_handler = (span_tx_handler_t) &silence_gen;
    s->tx_user_data = &s->silence_gen;
    return s;
}
Пример #5
0
Файл: fax.c Проект: vir/spandsp
SPAN_DECLARE(fax_state_t *) fax_init(fax_state_t *s, int calling_party)
{
#if 0
    v8_parms_t v8_parms;
#endif

    if (s == NULL)
    {
        if ((s = (fax_state_t *) span_alloc(sizeof(*s))) == NULL)
            return NULL;
        /*endif*/
    }
    /*endif*/
    memset(s, 0, sizeof(*s));
    span_log_init(&s->logging, SPAN_LOG_NONE, NULL);
    span_log_set_protocol(&s->logging, "FAX");
    fax_modems_init(&s->modems,
                    false,
                    t30_hdlc_accept,
                    hdlc_underflow_handler,
                    t30_non_ecm_put_bit,
                    t30_non_ecm_get_bit,
                    tone_detected,
                    &s->t30);
    t30_init(&s->t30,
             calling_party,
             fax_set_rx_type,
             (void *) s,
             fax_set_tx_type,
             (void *) s,
             fax_send_hdlc,
             (void *) s);
    t30_set_supported_modems(&s->t30, T30_SUPPORT_V27TER | T30_SUPPORT_V29 | T30_SUPPORT_V17);
#if 0
    v8_parms.modem_connect_tone = MODEM_CONNECT_TONES_ANSAM_PR;
    v8_parms.call_function = V8_CALL_T30_RX;
    v8_parms.modulations = V8_MOD_V21;
    if (s->t30.supported_modems & T30_SUPPORT_V27TER)
        v8_parms.modulations |= V8_MOD_V27TER;
    /*endif*/
    if (s->t30.supported_modems & T30_SUPPORT_V29)
        v8_parms.modulations |= V8_MOD_V29;
    /*endif*/
    if (s->t30.supported_modems & T30_SUPPORT_V17)
        v8_parms.modulations |= V8_MOD_V17;
    /*endif*/
    if (s->t30.supported_modems & T30_SUPPORT_V34HDX)
        v8_parms.modulations |= V8_MOD_V34HDX;
    /*endif*/
    v8_parms.protocol = V8_PROTOCOL_NONE;
    v8_parms.pcm_modem_availability = 0;
    v8_parms.pstn_access = 0;
    v8_parms.nsf = -1;
    v8_parms.t66 = -1;
    v8_init(&s->v8, calling_party, &v8_parms, v8_handler, s);
#endif
    fax_restart(s, calling_party);
    return s;
}
Пример #6
0
SPAN_DECLARE(t4_rx_state_t *) t4_rx_init(t4_rx_state_t *s, const char *file, int supported_output_compressions)
{
    bool alloced;

    alloced = false;
    if (s == NULL)
    {
        if ((s = (t4_rx_state_t *) span_alloc(sizeof(*s))) == NULL)
            return NULL;
        alloced = true;
    }
#if defined(SPANDSP_SUPPORT_TIFF_FX)
    TIFF_FX_init();
#endif
    memset(s, 0, sizeof(*s));
    span_log_init(&s->logging, SPAN_LOG_NONE, NULL);
    span_log_set_protocol(&s->logging, "T.4");

    span_log(&s->logging, SPAN_LOG_FLOW, "Start rx document\n");

    s->supported_tiff_compressions = supported_output_compressions;
#if !defined(SPANDSP_SUPPORT_T88)
    s->supported_tiff_compressions &= ~T4_COMPRESSION_T88;
#endif
#if !defined(SPANDSP_SUPPORT_T43)
    s->supported_tiff_compressions &= ~T4_COMPRESSION_T43;
#endif
#if !defined(SPANDSP_SUPPORT_T45)
    s->supported_tiff_compressions &= ~T4_COMPRESSION_T45;
#endif

    /* Set some default values */
    s->metadata.x_resolution = T4_X_RESOLUTION_R8;
    s->metadata.y_resolution = T4_Y_RESOLUTION_FINE;

    s->current_page = 0;
    s->current_decoder = 0;

    /* Default handler */
    s->row_handler = tiff_row_write_handler;
    s->row_handler_user_data = s;

    if (file)
    {
        s->tiff.pages_in_file = 0;
        if (open_tiff_output_file(s, file) < 0)
        {
            if (alloced)
                span_free(s);
            return NULL;
        }
        /* Save the file name for logging reports. */
        s->tiff.file = strdup(file);
    }
    return s;
}
Пример #7
0
SPAN_DECLARE(dtmf_rx_state_t *) dtmf_rx_init(dtmf_rx_state_t *s,
                                             digits_rx_callback_t callback,
                                             void *user_data)
{
    int i;
    static int initialised = FALSE;

    if (s == NULL)
    {
        if ((s = (dtmf_rx_state_t *) malloc(sizeof (*s))) == NULL)
            return NULL;
    }
    memset(s, 0, sizeof(*s));
    span_log_init(&s->logging, SPAN_LOG_NONE, NULL);
    span_log_set_protocol(&s->logging, "DTMF");
    s->digits_callback = callback;
    s->digits_callback_data = user_data;
    s->realtime_callback = NULL;
    s->realtime_callback_data = NULL;
    s->filter_dialtone = FALSE;
    s->normal_twist = DTMF_NORMAL_TWIST;
    s->reverse_twist = DTMF_REVERSE_TWIST;
    s->threshold = DTMF_THRESHOLD;

    s->in_digit = 0;
    s->last_hit = 0;

    if (!initialised)
    {
        for (i = 0;  i < 4;  i++)
        {
            make_goertzel_descriptor(&dtmf_detect_row[i], dtmf_row[i], DTMF_SAMPLES_PER_BLOCK);
            make_goertzel_descriptor(&dtmf_detect_col[i], dtmf_col[i], DTMF_SAMPLES_PER_BLOCK);
        }
        initialised = TRUE;
    }
    for (i = 0;  i < 4;  i++)
    {
        goertzel_init(&s->row_out[i], &dtmf_detect_row[i]);
        goertzel_init(&s->col_out[i], &dtmf_detect_col[i]);
    }
#if defined(SPANDSP_USE_FIXED_POINT)
    s->energy = 0;
#else
    s->energy = 0.0f;
#endif
    s->current_sample = 0;
    s->lost_digits = 0;
    s->current_digits = 0;
    s->digits[0] = '\0';
    return s;
}
Пример #8
0
SPAN_DECLARE(t4_rx_state_t *) t4_rx_init(t4_rx_state_t *s, const char *file, int output_encoding)
{
    int allocated;

    allocated = FALSE;
    if (s == NULL)
    {
        if ((s = (t4_rx_state_t *) malloc(sizeof(*s))) == NULL)
            return NULL;
        allocated = TRUE;
    }
#if defined(SPANDSP_SUPPORT_TIFF_FX)
    TIFF_FX_init();
#endif
    memset(s, 0, sizeof(*s));
    span_log_init(&s->logging, SPAN_LOG_NONE, NULL);
    span_log_set_protocol(&s->logging, "T.4");

    span_log(&s->logging, SPAN_LOG_FLOW, "Start rx document\n");

    /* Only provide for one form of coding throughout the file, even though the
       coding on the wire could change between pages. */
    s->tiff.output_encoding = output_encoding;

    /* Set some default values */
    s->metadata.x_resolution = T4_X_RESOLUTION_R8;
    s->metadata.y_resolution = T4_Y_RESOLUTION_FINE;

    s->current_page = 0;

    /* Default handler */
    s->row_handler = tiff_row_write_handler;
    s->row_handler_user_data = s;

    if (file)
    {
        s->tiff.pages_in_file = 0;
        if (open_tiff_output_file(s, file) < 0)
        {
            if (allocated)
                free(s);
            return NULL;
        }
        /* Save the file name for logging reports. */
        s->tiff.file = strdup(file);
    }
    return s;
}
Пример #9
0
t38_terminal_state_t *t38_terminal_init(t38_terminal_state_t *s,
                                        int calling_party,
                                        t38_tx_packet_handler_t *tx_packet_handler,
                                        void *tx_packet_user_data)
{
    if (tx_packet_handler == NULL)
        return NULL;

    memset(s, 0, sizeof(*s));
    span_log_init(&s->logging, SPAN_LOG_NONE, NULL);
    span_log_set_protocol(&s->logging, "T.38T");
    s->rx_signal_present = FALSE;

    s->timed_step = T38_TIMED_STEP_NONE;
    s->tx_ptr = 0;

    t38_core_init(&s->t38,
                  process_rx_indicator,
                  process_rx_data,
                  process_rx_missing,
                  (void *) s,
                  tx_packet_handler,
                  tx_packet_user_data);
    s->t38.fastest_image_data_rate = 14400;
    t38_terminal_set_config(s, FALSE);

    s->timed_step = T38_TIMED_STEP_NONE;
    s->current_tx_data_type = T38_DATA_NONE;
    s->next_tx_samples = 0;

    t30_init(&(s->t30_state),
             calling_party,
             set_rx_type,
             (void *) s,
             set_tx_type,
             (void *) s,
             send_hdlc,
             (void *) s);
    t30_set_supported_modems(&(s->t30_state),
                             T30_SUPPORT_V27TER | T30_SUPPORT_V29 | T30_SUPPORT_V17 | T30_SUPPORT_IAF);
    t30_set_iaf_mode(&(s->t30_state), T30_IAF_MODE_T37 | T30_IAF_MODE_T38);
    t30_restart(&s->t30_state);
    return s;
}
Пример #10
0
SPAN_DECLARE(ademco_contactid_receiver_state_t *) ademco_contactid_receiver_init(ademco_contactid_receiver_state_t *s,
        ademco_contactid_report_func_t callback,
        void *user_data)
{
    if (s == NULL)
    {
        if ((s = (ademco_contactid_receiver_state_t *) span_alloc(sizeof(*s))) == NULL)
            return NULL;
    }
    memset(s, 0, sizeof(*s));
    span_log_init(&s->logging, SPAN_LOG_NONE, NULL);
    span_log_set_protocol(&s->logging, "Ademco");

    dtmf_rx_init(&s->dtmf, dtmf_digit_delivery, (void *) s);
    s->rx_digits_len = 0;

    s->callback = callback;
    s->callback_user_data = user_data;

    s->step = 0;
    s->remaining_samples = ms_to_samples(500);
    return s;
}
Пример #11
0
int psuedo_terminal_create(modem_t *modem)
{
#if defined(WIN32)
    COMMTIMEOUTS timeouts = {0};
#endif

    memset(modem, 0, sizeof(*modem));

    span_log_init(&modem->logging, SPAN_LOG_NONE, NULL);
    span_log_set_protocol(&modem->logging, "PTY");

    span_log_set_level(&modem->logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW);
    span_log_set_tag(&modem->logging, "PTY");

    modem->master = -1;
    modem->slave = -1;

#if USE_OPENPTY
    if (openpty(&modem->master, &modem->slave, NULL, NULL, NULL))
    {
        span_log(&modem->logging, SPAN_LOG_ERROR, "Fatal error: failed to initialize pty\n");
        return -1;
    }
    modem->stty = ttyname(modem->slave);
#else
#if defined(WIN32)
    modem->slot = 4 + next_id++; /* need work here we start at COM4 for now*/
    snprintf(modem->devlink, sizeof(modem->devlink), "COM%d", modem->slot);

    modem->master = CreateFile(modem->devlink,
                               GENERIC_READ | GENERIC_WRITE,
                               0,
                               0,
                               OPEN_EXISTING,
                               FILE_FLAG_OVERLAPPED,
                               0);
    if (modem->master == INVALID_HANDLE_VALUE)
    {
        if (GetLastError() == ERROR_FILE_NOT_FOUND)
            span_log(&modem->logging, SPAN_LOG_ERROR, "Fatal error: Serial port does not exist\n");
        else
            span_log(&modem->logging, SPAN_LOG_ERROR, "Fatal error: Serial port open error\n");
        return -1;
    }
#elif !defined(HAVE_POSIX_OPENPT)
    modem->master = open("/dev/ptmx", O_RDWR);
#else
    modem->master = posix_openpt(O_RDWR | O_NOCTTY);
#endif

#if !defined(WIN32)
    if (modem->master < 0)
        span_log(&modem->logging, SPAN_LOG_ERROR, "Fatal error: failed to initialize UNIX98 master pty\n");

    if (grantpt(modem->master) < 0)
        span_log(&modem->logging, SPAN_LOG_ERROR, "Fatal error: failed to grant access to slave pty\n");

    if (unlockpt(modem->master) < 0)
        span_log(&modem->logging, SPAN_LOG_ERROR, "Fatal error: failed to unlock slave pty\n");

    if ((modem->stty = ptsname(modem->master)) == NULL)
        span_log(&modem->logging, SPAN_LOG_ERROR, "Fatal error: failed to obtain slave pty filename\n");

    if ((modem->slave = open(modem->stty, O_RDWR)) < 0)
        span_log(&modem->logging, SPAN_LOG_ERROR, "Fatal error: failed to open slave pty %s\n", modem->stty);
#endif

#if defined(SOLARIS)
    ioctl(modem->slave, I_PUSH, "ptem");
    ioctl(modem->slave, I_PUSH, "ldterm");
#endif
#endif

#if defined(WIN32)
    timeouts.ReadIntervalTimeout = 50;
    timeouts.ReadTotalTimeoutConstant = 50;
    timeouts.ReadTotalTimeoutMultiplier = 10;

    timeouts.WriteTotalTimeoutConstant = 50;
    timeouts.WriteTotalTimeoutMultiplier = 10;

    SetCommMask(modem->master, EV_RXCHAR);

    if (!SetCommTimeouts(modem->master, &timeouts))
    {
        span_log(&modem->logging, SPAN_LOG_ERROR, "Cannot set up non-blocking read on %s\n", modem->devlink);
        psuedo_terminal_close(modem);
        return -1;
    }
    modem->threadAbort = CreateEvent(NULL, true, false, NULL);
#else
    modem->slot = next_id++;
    snprintf(modem->devlink, sizeof(modem->devlink), "%s/%d", device_root_name, modem->slot);

    /* Remove any stale link which might be present */
    unlink(modem->devlink);

    if (symlink(modem->stty, modem->devlink))
    {
        span_log(&modem->logging, SPAN_LOG_ERROR, "Fatal error: failed to create %s symbolic link\n", modem->devlink);
        psuedo_terminal_close(modem);
        return -1;
    }

    if (fcntl(modem->master, F_SETFL, fcntl(modem->master, F_GETFL, 0) | O_NONBLOCK))
    {
        span_log(&modem->logging, SPAN_LOG_ERROR, "Cannot set up non-blocking read on %s\n", ttyname(modem->master));
        psuedo_terminal_close(modem);
        return -1;
    }
#endif
    return 0;
}
Пример #12
0
int main(int argc, char *argv[])
{
    fsk_rx_state_t *fsk;
    v17_rx_state_t *v17;
    v29_rx_state_t *v29;
    v27ter_rx_state_t *v27ter_4800;
    v27ter_rx_state_t *v27ter_2400;
    int16_t amp[SAMPLES_PER_CHUNK];
    SNDFILE *inhandle;
    SF_INFO info;
    int len;
    const char *filename;
    logging_state_t *logging;

    filename = "fax_samp.wav";

    if (argc > 1)
        filename = argv[1];

    memset(&info, 0, sizeof(info));
    if ((inhandle = sf_open(filename, SFM_READ, &info)) == NULL)
    {
        fprintf(stderr, "    Cannot open audio file '%s' for reading\n", filename);
        exit(2);
    }
    if (info.samplerate != SAMPLE_RATE)
    {
        fprintf(stderr, "    Unexpected sample rate in audio file '%s'\n", filename);
        exit(2);
    }
    if (info.channels != 1)
    {
        fprintf(stderr, "    Unexpected number of channels in audio file '%s'\n", filename);
        exit(2);
    }

    memset(&t30_dummy, 0, sizeof(t30_dummy));
    span_log_init(&t30_dummy.logging, SPAN_LOG_FLOW, NULL);
    span_log_set_protocol(&t30_dummy.logging, "T.30");

    hdlc_rx_init(&hdlcrx, FALSE, TRUE, 5, hdlc_accept, NULL);
    fsk = fsk_rx_init(NULL, &preset_fsk_specs[FSK_V21CH2], FSK_FRAME_MODE_SYNC, v21_put_bit, NULL);
    v17 = v17_rx_init(NULL, 14400, v17_put_bit, NULL);
    v29 = v29_rx_init(NULL, 9600, v29_put_bit, NULL);
    //v29 = v29_rx_init(NULL, 7200, v29_put_bit, NULL);
    v27ter_4800 = v27ter_rx_init(NULL, 4800, v27ter_put_bit, NULL);
    v27ter_2400 = v27ter_rx_init(NULL, 2400, v27ter_put_bit, NULL);

    fsk_rx_signal_cutoff(fsk, -45.5);
    v17_rx_signal_cutoff(v17, -45.5);
    v29_rx_signal_cutoff(v29, -45.5);
    v27ter_rx_signal_cutoff(v27ter_4800, -40.0);
    v27ter_rx_signal_cutoff(v27ter_2400, -40.0);

#if 1
    logging = v17_rx_get_logging_state(v17);
    span_log_init(logging, SPAN_LOG_FLOW, NULL);
    span_log_set_protocol(logging, "V.17");
    span_log_set_level(logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_FLOW);

    logging = v29_rx_get_logging_state(v29);
    span_log_init(logging, SPAN_LOG_FLOW, NULL);
    span_log_set_protocol(logging, "V.29");
    span_log_set_level(logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_FLOW);

    logging = v27ter_rx_get_logging_state(v27ter_4800);
    span_log_init(logging, SPAN_LOG_FLOW, NULL);
    span_log_set_protocol(logging, "V.27ter-4800");
    span_log_set_level(logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_FLOW);

    logging = v27ter_rx_get_logging_state(v27ter_2400);
    span_log_init(logging, SPAN_LOG_FLOW, NULL);
    span_log_set_protocol(logging, "V.27ter-2400");
    span_log_set_level(logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_FLOW);
#endif

    if (t4_rx_init(&t4_rx_state, "fax_decode.tif", T4_COMPRESSION_ITU_T4_2D) == NULL)
    {
        fprintf(stderr, "Failed to init\n");
        exit(0);
    }
        
    for (;;)
    {
        len = sf_readf_short(inhandle, amp, SAMPLES_PER_CHUNK);
        if (len < SAMPLES_PER_CHUNK)
            break;
        fsk_rx(fsk, amp, len);
        v17_rx(v17, amp, len);
        v29_rx(v29, amp, len);
        v27ter_rx(v27ter_4800, amp, len);
        v27ter_rx(v27ter_2400, amp, len);
    }
    t4_rx_release(&t4_rx_state);

    if (sf_close(inhandle))
    {
        fprintf(stderr, "    Cannot close audio file '%s'\n", filename);
        exit(2);
    }
    return 0;
}
int main(int argc, char *argv[])
{
    t38_non_ecm_buffer_state_t buffer;
    logging_state_t logging;
    uint8_t buf[1024];
    int bit;
    int n;
    int log_bits;
    int i;

    log_bits = (argc > 1);
    printf("T.38 non-ECM rate adapting buffer tests.\n");
    span_log_init(&logging, SPAN_LOG_FLOW, NULL);
    span_log_set_protocol(&logging, "Buffer");

    printf("1 - Impose no minimum for the bits per row\n");
    t38_non_ecm_buffer_init(&buffer, TRUE, 0);
    n = 0;
    bit_no = 0;
    /* We should get ones until the buffers recognises an EOL */
    printf("    We should get ones here\n");
    for (i = 0;  i < 17;  i++)
        xxx(&buffer, &logging, log_bits, i, 1);
    printf("    We should change to zeros here\n");
    xxx(&buffer, &logging, log_bits, i, 0);
    for (i = 0;  i < 17;  i++)
        xxx(&buffer, &logging, log_bits, i, 0);
    printf("    We should get the first row here\n");
    xxx(&buffer, &logging, log_bits, i, -1);
    for (i = 0;  i < 17;  i++)
        xxx(&buffer, &logging, log_bits, i, 0);
    printf("    We should get the second row here\n");
    xxx(&buffer, &logging, log_bits, i, -1);
    for (i = 0;  i < 17;  i++)
        xxx(&buffer, &logging, log_bits, i, 0);
    printf("    We should get the third row here\n");
    xxx(&buffer, &logging, log_bits, i, -1);
    printf("    Done\n");
    t38_non_ecm_buffer_report_input_status(&buffer, &logging);
    t38_non_ecm_buffer_report_output_status(&buffer, &logging);

    printf("2 - Impose no minimum for the bits per row, different alignment\n");
    t38_non_ecm_buffer_init(&buffer, TRUE, 0);
    n = 0;
    memset(buf, 0, sizeof(buf));
    /* The first one in this should be seen as the first EOL */
    memset(buf + 10, 0x55, 10);
    /* EOL 2 */
    buf[25] = 0x20;
    /* EOL 3 */
    memset(buf + 30, 0x55, 10);
    /* EOL 4 */
    buf[45] = 0x10;
    t38_non_ecm_buffer_inject(&buffer, buf, 50);
    t38_non_ecm_buffer_push(&buffer);
    for (;;)
    {
        bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
        if (log_bits)
            printf("Rx bit %d - %d\n", n, bit);
        n++;
        if (bit == SIG_STATUS_END_OF_DATA)
        {
            if (n != 337)
            {
                printf("Tests failed\n");
                exit(2);
            }
            break;
        }
        if (n >= 18  &&  n <= 96)
        {
            if (bit == (n & 1))
            {
                printf("Tests failed\n");
                exit(2);
            }
        }
        else if (n >= 178  &&  n <= 256)
        {
            if (bit == (n & 1))
            {
                printf("Tests failed\n");
                exit(2);
            }
        }
        else if (n == 139  ||  n == 300)
        {
            if (bit != 1)
            {
                printf("Tests failed\n");
                exit(2);
            }
        }
        else
        {
            if (bit != 0)
            {
                printf("Tests failed\n");
                exit(2);
            }
        }
    }
    t38_non_ecm_buffer_report_input_status(&buffer, &logging);
    t38_non_ecm_buffer_report_output_status(&buffer, &logging);

    printf("3 - Demand a fairly high minimum for the bits per row\n");
    t38_non_ecm_buffer_init(&buffer, TRUE, 400);
    n = 0;
    memset(buf, 0, sizeof(buf));
    /* The first one in this should be seen as the first EOL */
    memset(buf + 10, 0x55, 10);
    /* EOL 2 */
    buf[25] = 0x08;
    /* EOL 3 */
    memset(buf + 30, 0x55, 10);
    /* EOL 4 */
    buf[45] = 0x04;
    t38_non_ecm_buffer_inject(&buffer, buf, 50);
    t38_non_ecm_buffer_push(&buffer);
    for (;;)
    {
        bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
        if (log_bits)
            printf("Rx bit %d - %d\n", n, bit);
        n++;
        if (bit == SIG_STATUS_END_OF_DATA)
        {
            if (n != 1273)
            {
                printf("Tests failed\n");
                exit(2);
            }
            break;
        }
        if (n >= 18  &&  n <= 96)
        {
            if (bit == (n & 1))
            {
                printf("Tests failed\n");
                exit(2);
            }
        }
        else if (n >= 834  &&  n <= 912)
        {
            if (bit == (n & 1))
            {
                printf("Tests failed\n");
                exit(2);
            }
        }
        else if (n == 429  ||  n == 1238)
        {
            if (bit != 1)
            {
                printf("Tests failed\n");
                exit(2);
            }
        }
        else
        {
            if (bit != 0)
            {
                printf("Tests failed\n");
                exit(2);
            }
        }
    }
    t38_non_ecm_buffer_report_input_status(&buffer, &logging);
    t38_non_ecm_buffer_report_output_status(&buffer, &logging);

    printf("4 - Take some time to get to the first row of the image, output ahead\n");
    t38_non_ecm_buffer_init(&buffer, TRUE, 400);
    n = 0;
    /* Get some initial bits from an empty buffer. These should be ones */
    for (i = 0;  i < 1000;  i++)
    {
        bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
        if (log_bits)
            printf("Rx bit %d - %d\n", n++, bit);
        if (bit != 1)
        {
            printf("Tests failed\n");
            exit(2);
        }
    }
    printf("    Initial ones OK\n");
    /* Now put some zeros into the buffer, but no EOL. We should continue
       getting ones out. */
    memset(buf, 0, sizeof(buf));
    t38_non_ecm_buffer_inject(&buffer, buf, 20);
    for (i = 0;  i < 1000;  i++)
    {
        bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
        if (log_bits)
            printf("Rx bit %d - %d\n", n++, bit);
        if (bit != 1)
        {
            printf("Tests failed\n");
            exit(2);
        }
    }
    printf("    Continuing initial ones OK\n");
    /* Now add a one, to make an EOL. We should see the zeros come out. */
    buf[0] = 0x01;
    t38_non_ecm_buffer_inject(&buffer, buf, 1);
    for (i = 0;  i < 1000;  i++)
    {
        bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
        if (log_bits)
            printf("Rx bit %d - %d\n", n++, bit);
        if (bit != 0)
        {
            printf("Tests failed\n");
            exit(2);
        }
    }
    printf("    First EOL caused zeros to output OK\n");
    /* Now add another line. We should see the first line come out. This means just the
       23rd bit from now will be a one. */
    buf[0] = 0x00;
    buf[4] = 0x01;
    t38_non_ecm_buffer_inject(&buffer, buf, 5);
    for (i = 0;  i < 1000;  i++)
    {
        bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
        if (log_bits)
            printf("Rx bit %d - %d\n", n++, bit);
        if ((i == 23  &&  bit == 0)  ||  (i != 23  &&  bit != 0))
        {
            printf("Tests failed (%d)\n", i);
            exit(2);
        }
    }
    printf("    Second EOL caused the first row to output OK\n");
    /* Now inject an RTC - 6 EOLs */
    memset(buf, 0, sizeof(buf));
    /* T.4 1D style */
    for (i = 10;  i < 19;  i += 3)
    {
        buf[i] = 0x00;
        buf[i + 1] = 0x10;
        buf[i + 2] = 0x01;
    }
    /* T.4 2D style */
    buf[25 + 0] = 0x00;
    buf[25 + 1] = 0x18;
    buf[25 + 2] = 0x00;
    buf[25 + 3] = 0xC0;
    buf[25 + 4] = 0x06;
    buf[25 + 5] = 0x00;
    buf[25 + 6] = 0x30;
    buf[25 + 7] = 0x01;
    buf[25 + 8] = 0x80;
    buf[25 + 9] = 0x0C;
    t38_non_ecm_buffer_inject(&buffer, buf, 50);
    t38_non_ecm_buffer_push(&buffer);
    for (i = 0;  i < 1000;  i++)
    {
        bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
        if (log_bits)
            printf("Rx bit %d - %d\n", n++, bit);
        if (i == 7
            ||
            i == 400 + 11 + 0*12
            ||
            i == 400 + 11 + 1*12
            ||
            i == 400 + 11 + 2*12
            ||
            i == 400 + 11 + 3*12
            ||
            i == 400 + 11 + 4*12
            ||
            i == 400 + 11 + 5*12
            ||
            i == 400 + 11 + 60 + 400 + 4 + 0*13
            ||
            i == 400 + 11 + 60 + 400 + 4 + 0*13 + 1
            ||
            i == 400 + 11 + 60 + 400 + 4 + 1*13
            ||
            i == 400 + 11 + 60 + 400 + 4 + 1*13 + 1
            ||
            i == 400 + 11 + 60 + 400 + 4 + 2*13
            ||
            i == 400 + 11 + 60 + 400 + 4 + 2*13 + 1
            ||
            i == 400 + 11 + 60 + 400 + 4 + 3*13
            ||
            i == 400 + 11 + 60 + 400 + 4 + 3*13 + 1
            ||
            i == 400 + 11 + 60 + 400 + 4 + 4*13
            ||
            i == 400 + 11 + 60 + 400 + 4 + 4*13 + 1
            ||
            i == 400 + 11 + 60 + 400 + 4 + 5*13
            ||
            i == 400 + 11 + 60 + 400 + 4 + 5*13 + 1)
        {
            if (bit == 0)
            {
                printf("Tests failed (%d)\n", i);
                exit(2);
            }
        }
        else
        {
            if (bit == 1)
            {
                printf("Tests failed (%d)\n", i);
                exit(2);
            }
        }
    }
    printf("    RTC output OK\n");
    t38_non_ecm_buffer_report_input_status(&buffer, &logging);
    t38_non_ecm_buffer_report_output_status(&buffer, &logging);

    printf("5 - Take some time to get to the first row of the image, output behind\n");
    t38_non_ecm_buffer_init(&buffer, TRUE, 400);
    n = 0;
    /* Inject some ones. */
    memset(buf, 0xFF, 100);
    t38_non_ecm_buffer_inject(&buffer, buf, 100);
    /* Inject some zeros */
    memset(buf, 0, sizeof(buf));
    t38_non_ecm_buffer_inject(&buffer, buf, 100);
    for (i = 0;  i < 1000;  i++)
    {
        bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
        if (log_bits)
            printf("Rx bit %d - %d\n", n++, bit);
        if (bit != 1)
        {
            printf("Tests failed\n");
            exit(2);
        }
    }
    printf("    Initial ones OK\n");
    /* Now add a one, to make an EOL. We should see the zeros come out. */
    buf[0] = 0x01;
    t38_non_ecm_buffer_inject(&buffer, buf, 1);
    for (i = 0;  i < 1000;  i++)
    {
        bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
        if (log_bits)
            printf("Rx bit %d - %d\n", n++, bit);
        if (bit != 0)
        {
            printf("Tests failed\n");
            exit(2);
        }
    }
    printf("    First EOL caused zeros to output OK\n");
    /* Now add another line. We should see the first line come out. This means just the
       23rd bit from now will be a one. */
    buf[0] = 0x00;
    buf[4] = 0x01;
    t38_non_ecm_buffer_inject(&buffer, buf, 5);
    for (i = 0;  i < 1000;  i++)
    {
        bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
        if (log_bits)
            printf("Rx bit %d - %d\n", n++, bit);
        if ((i == 23  &&  bit == 0)  ||  (i != 23  &&  bit != 0))
        {
            printf("Tests failed (%d)\n", i);
            exit(2);
        }
    }
    printf("    Second EOL caused the first row to output OK\n");
    /* Now inject an RTC - 6 EOLs */
    memset(buf, 0, sizeof(buf));
    /* T.4 1D style */
    for (i = 10;  i < 19;  i += 3)
    {
        buf[i] = 0x00;
        buf[i + 1] = 0x10;
        buf[i + 2] = 0x01;
    }
    /* T.4 2D style */
    buf[25 + 0] = 0x00;
    buf[25 + 1] = 0x18;
    buf[25 + 2] = 0x00;
    buf[25 + 3] = 0xC0;
    buf[25 + 4] = 0x06;
    buf[25 + 5] = 0x00;
    buf[25 + 6] = 0x30;
    buf[25 + 7] = 0x01;
    buf[25 + 8] = 0x80;
    buf[25 + 9] = 0x0C;
    t38_non_ecm_buffer_inject(&buffer, buf, 50);
    t38_non_ecm_buffer_push(&buffer);
    for (i = 0;  i < 1000;  i++)
    {
        bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
        if (log_bits)
            printf("Rx bit %d - %d\n", n++, bit);
        if (i == 7
            ||
            i == 400 + 11 + 0*12
            ||
            i == 400 + 11 + 1*12
            ||
            i == 400 + 11 + 2*12
            ||
            i == 400 + 11 + 3*12
            ||
            i == 400 + 11 + 4*12
            ||
            i == 400 + 11 + 5*12
            ||
            i == 400 + 11 + 60 + 400 + 4 + 0*13
            ||
            i == 400 + 11 + 60 + 400 + 4 + 0*13 + 1
            ||
            i == 400 + 11 + 60 + 400 + 4 + 1*13
            ||
            i == 400 + 11 + 60 + 400 + 4 + 1*13 + 1
            ||
            i == 400 + 11 + 60 + 400 + 4 + 2*13
            ||
            i == 400 + 11 + 60 + 400 + 4 + 2*13 + 1
            ||
            i == 400 + 11 + 60 + 400 + 4 + 3*13
            ||
            i == 400 + 11 + 60 + 400 + 4 + 3*13 + 1
            ||
            i == 400 + 11 + 60 + 400 + 4 + 4*13
            ||
            i == 400 + 11 + 60 + 400 + 4 + 4*13 + 1
            ||
            i == 400 + 11 + 60 + 400 + 4 + 5*13
            ||
            i == 400 + 11 + 60 + 400 + 4 + 5*13 + 1)
        {
            if (bit == 0)
            {
                printf("Tests failed (%d)\n", i);
                exit(2);
            }
        }
        else
        {
            if (bit == 1)
            {
                printf("Tests failed (%d)\n", i);
                exit(2);
            }
        }
    }
    printf("    RTC output OK\n");
    t38_non_ecm_buffer_report_input_status(&buffer, &logging);
    t38_non_ecm_buffer_report_output_status(&buffer, &logging);

    printf("6 - TCF without leading ones\n");
    t38_non_ecm_buffer_init(&buffer, FALSE, 400);
    n = 0;
    /* Get some initial bits from an empty buffer. These should be ones */
    for (i = 0;  i < 1000;  i++)
    {
        bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
        if (log_bits)
            printf("Rx bit %d - %d\n", n++, bit);
        if (bit != 1)
        {
            printf("Tests failed\n");
            exit(2);
        }
    }
    printf("    Initial ones from an empty TCF buffer OK\n");
    /* Now send some TCF through, and see that it comes out */
    memset(buf, 0x00, sizeof(buf));
    t38_non_ecm_buffer_inject(&buffer, buf, 500);
    t38_non_ecm_buffer_push(&buffer);
    for (i = 0;  i < 500*8;  i++)
    {
        bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
        if (log_bits)
            printf("Rx bit %d - %d\n", n++, bit);
        if (bit != 0)
        {
            printf("Tests failed\n");
            exit(2);
        }
    }
    printf("    Passthrough of TCF OK\n");
    /* Check the right number of bits was buffered */
    bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
    if (log_bits)
        printf("Rx bit %d - %d\n", n++, bit);
    if (bit != SIG_STATUS_END_OF_DATA)
    {
        printf("Tests failed\n");
        exit(2);
    }
    printf("    End of data seen OK\n");
    t38_non_ecm_buffer_report_input_status(&buffer, &logging);
    t38_non_ecm_buffer_report_output_status(&buffer, &logging);

    printf("7 - TCF with leading ones\n");
    t38_non_ecm_buffer_init(&buffer, FALSE, 400);
    n = 0;
    /* Get some initial bits from an empty buffer. These should be ones */
    for (i = 0;  i < 1000;  i++)
    {
        bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
        if (log_bits)
            printf("Rx bit %d - %d\n", n++, bit);
        if (bit != 1)
        {
            printf("Tests failed\n");
            exit(2);
        }
    }
    printf("    Initial ones from an empty TCF buffer OK\n");
    
    /* Now send some initial ones, and see that we continue to get all ones
       as the stuffing. */
    memset(buf, 0xFF, 500);
    t38_non_ecm_buffer_inject(&buffer, buf, 500);
    for (i = 0;  i < 500*8;  i++)
    {
        bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
        if (log_bits)
            printf("Rx bit %d - %d\n", n++, bit);
        if (bit != 1)
        {
            printf("Tests failed\n");
            exit(2);
        }
    }
    printf("    Sustaining ones OK\n");

    /* Now send some initial ones, and some TCF through, and see that only
       the TCF comes out */
    memset(buf, 0x00, sizeof(buf));
    memset(buf, 0xFF, 100);
    /* End the ones mid byte */
    buf[100] = 0xF0;
    t38_non_ecm_buffer_inject(&buffer, buf, 500);
    t38_non_ecm_buffer_push(&buffer);
    for (i = 0;  i < 400*8;  i++)
    {
        bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
        if (log_bits)
            printf("Rx bit %d - %d\n", n++, bit);
        if ((i < 4  &&  bit == 0)  ||  (i >= 4  &&  bit != 0))
        {
            printf("Tests failed\n");
            exit(2);
        }
    }
    printf("    Passthrough of TCF OK\n");
    /* Check the right number of bits was buffered */
    bit = t38_non_ecm_buffer_get_bit((void *) &buffer);
    if (log_bits)
        printf("Rx bit %d - %d\n", n++, bit);
    if (bit != SIG_STATUS_END_OF_DATA)
    {
        printf("Tests failed\n");
        exit(2);
    }
    printf("    End of data seen OK\n");
    t38_non_ecm_buffer_report_input_status(&buffer, &logging);
    t38_non_ecm_buffer_report_output_status(&buffer, &logging);

    printf("Tests passed\n");
    return  0;
}
Пример #14
0
int main(int argc, char *argv[])
{
    logging_state_t *log;
    int i;
    uint8_t buf[1000];
    struct timespec delay;

    /* Set up a logger */
    if ((log = span_log_init(NULL, 123, "TAG")) == NULL)
    {
        fprintf(stderr, "Failed to initialise log.\n");
        exit(2);
    }
    /* Try it */
    span_log_set_level(log, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_FLOW);
    if (span_log(log, SPAN_LOG_FLOW, "Logging to fprintf, as simple as %d %d %d\n", 1, 2, 3))
        fprintf(stderr, "Logged.\n");
    else
        fprintf(stderr, "Not logged.\n");

    /* Now set a custom log handler */
    span_log_set_message_handler(log, &message_handler, NULL);
    span_log_set_sample_rate(log, 44100);

    /* Try the different logging elements */
    span_log_set_level(log, SPAN_LOG_SHOW_TAG | SPAN_LOG_FLOW);
    if (span_log(log, SPAN_LOG_FLOW, "Log with tag %d %d %d\n", 1, 2, 3))
        fprintf(stderr, "Logged.\n");
    else
        fprintf(stderr, "Not logged.\n");
    span_log_set_level(log, SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW);
    if (span_log(log, SPAN_LOG_FLOW, "Log with protocol %d %d %d\n", 1, 2, 3))
        fprintf(stderr, "Logged.\n");
    else
        fprintf(stderr, "Not logged.\n");
    span_log_set_level(log, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_FLOW);
    if (span_log(log, SPAN_LOG_ERROR, "Log with severity log %d %d %d\n", 1, 2, 3))
        fprintf(stderr, "Logged.\n");
    else
        fprintf(stderr, "Not logged.\n");

    span_log_set_level(log, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_FLOW);
    span_log_set_tag(log, "NewTag");
    if (span_log(log, SPAN_LOG_FLOW, "Log with new tag %d %d %d\n", 1, 2, 3))
        fprintf(stderr, "Logged.\n");
    else
        fprintf(stderr, "Not logged.\n");

    span_log_set_protocol(log, "Protocol");
    if (span_log(log, SPAN_LOG_FLOW, "Log with protocol %d %d %d\n", 1, 2, 3))
        fprintf(stderr, "Logged.\n");
    else
        fprintf(stderr, "Not logged.\n");

    /* Test logging of buffer contents */
    for (i = 0;  i < 1000;  i++)
        buf[i] = i;
    if (span_log_buf(log, SPAN_LOG_FLOW, "Buf", buf, 10))
        fprintf(stderr, "Logged.\n");
    else
        fprintf(stderr, "Not logged.\n");
    if (span_log_buf(log, SPAN_LOG_FLOW, "Buf", buf, 1000))
        fprintf(stderr, "Logged.\n");
    else
        fprintf(stderr, "Not logged.\n");

    /* Test the correct severities will be logged */
    for (i = 0;  i < 10;  i++)
    {
        if (!span_log_test(log, i))
        {
            if (i != 6)
                tests_failed = true;
            break;
        }
    }

    /* Check timestamping by samples */
    span_log_set_level(log, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_FLOW | SPAN_LOG_SHOW_SAMPLE_TIME);
    for (i = 0;  i < 10;  i++)
    {
        span_log(log, SPAN_LOG_FLOW, "Time tagged log %d %d %d\n", 1, 2, 3);
        span_log_bump_samples(log, 441*2);
    }

    /* Check timestamping by current date and time */
    span_log_set_message_handler(log, &message_handler2, NULL);
    span_log_set_level(log, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_FLOW | SPAN_LOG_SHOW_DATE);
    for (i = 0;  i < 10;  i++)
    {
        span_log(log, SPAN_LOG_FLOW, "Date/time tagged log %d %d %d\n", 1, 2, 3);
        delay.tv_sec = 0;
        delay.tv_nsec = 20000000;
        nanosleep(&delay, NULL);
    }
    if (tests_failed  ||  !msg_done)
    {
        printf("Tests failed - %d %d.\n", tests_failed, msg_done);
        return 2;
    }

    span_log_set_message_handler(log, &message_handler, NULL);

    printf("Tests passed.\n");
    return 0;
}
Пример #15
0
int main(int argc, char *argv[])
{
    fsk_rx_state_t *fsk;
    v17_rx_state_t *v17;
    v29_rx_state_t *v29;
    v27ter_rx_state_t *v27ter;
    int16_t amp[SAMPLES_PER_CHUNK];
    AFfilehandle inhandle;
    int len;
    const char *filename;
    float x;
    logging_state_t *logging;

    filename = "fax_samp.wav";

    if (argc > 1)
        filename = argv[1];

    if ((inhandle = afOpenFile(filename, "r", NULL)) == AF_NULL_FILEHANDLE)
    {
        fprintf(stderr, "    Cannot open wave file '%s'\n", filename);
        exit(2);
    }
    if ((x = afGetFrameSize(inhandle, AF_DEFAULT_TRACK, 1)) != 2.0)
    {
        printf("    Unexpected frame size in speech file '%s' (%f)\n", filename, x);
        exit(2);
    }
    if ((x = afGetRate(inhandle, AF_DEFAULT_TRACK)) != (float) SAMPLE_RATE)
    {
        printf("    Unexpected sample rate in speech file '%s' (%f)\n", filename, x);
        exit(2);
    }
    if ((x = afGetChannels(inhandle, AF_DEFAULT_TRACK)) != 1.0)
    {
        printf("    Unexpected number of channels in speech file '%s' (%f)\n", filename, x);
        exit(2);
    }
    memset(&t30_dummy, 0, sizeof(t30_dummy));
    span_log_init(&t30_dummy.logging, SPAN_LOG_FLOW, NULL);
    span_log_set_protocol(&t30_dummy.logging, "T.30");

    hdlc_rx_init(&hdlcrx, FALSE, TRUE, 5, hdlc_accept, NULL);
    fsk = fsk_rx_init(NULL, &preset_fsk_specs[FSK_V21CH2], TRUE, v21_put_bit, NULL);
    v17 = v17_rx_init(NULL, 14400, v17_put_bit, NULL);
    v29 = v29_rx_init(NULL, 9600, v29_put_bit, NULL);
    //v29 = v29_rx_init(NULL, 7200, v29_put_bit, NULL);
    v27ter = v27ter_rx_init(NULL, 4800, v27ter_put_bit, NULL);
    fsk_rx_signal_cutoff(fsk, -45.5);
    v17_rx_signal_cutoff(v17, -45.5);
    v29_rx_signal_cutoff(v29, -45.5);
    v27ter_rx_signal_cutoff(v27ter, -40.0);

#if 1
    logging = v17_rx_get_logging_state(v17);
    span_log_init(logging, SPAN_LOG_FLOW, NULL);
    span_log_set_protocol(logging, "V.17");
    span_log_set_level(logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_FLOW);

    logging = v29_rx_get_logging_state(v29);
    span_log_init(logging, SPAN_LOG_FLOW, NULL);
    span_log_set_protocol(logging, "V.29");
    span_log_set_level(logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_FLOW);

    logging = v27ter_rx_get_logging_state(v27ter);
    span_log_init(logging, SPAN_LOG_FLOW, NULL);
    span_log_set_protocol(logging, "V.27ter");
    span_log_set_level(logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_FLOW);
#endif

    if (t4_rx_init(&t4_state, "fax_decode.tif", T4_COMPRESSION_ITU_T4_2D) == NULL)
    {
        fprintf(stderr, "Failed to init\n");
        exit(0);
    }
        
    for (;;)
    {
        len = afReadFrames(inhandle, AF_DEFAULT_TRACK, amp, SAMPLES_PER_CHUNK);
        if (len < SAMPLES_PER_CHUNK)
            break;
        fsk_rx(fsk, amp, len);
        v17_rx(v17, amp, len);
        v29_rx(v29, amp, len);
        //v27ter_rx(v27ter, amp, len);
    }
    t4_rx_release(&t4_state);

    if (afCloseFile(inhandle) != 0)
    {
        fprintf(stderr, "    Cannot close wave file '%s'\n", filename);
        exit(2);
    }
    return  0;
}
Пример #16
0
fax_state_t *fax_init(fax_state_t *s, int calling_party)
{
    if (s == NULL)
    {
        if ((s = (fax_state_t *) malloc(sizeof(*s))) == NULL)
            return NULL;
    }

    memset(s, 0, sizeof(*s));
    span_log_init(&s->logging, SPAN_LOG_NONE, NULL);
    span_log_set_protocol(&s->logging, "FAX");
    t30_init(&(s->t30_state),
             calling_party,
             fax_set_rx_type,
             (void *) s,
             fax_set_tx_type,
             (void *) s,
             fax_send_hdlc,
             (void *) s);
    t30_set_supported_modems(&(s->t30_state),
                             T30_SUPPORT_V27TER | T30_SUPPORT_V29);
    hdlc_rx_init(&(s->hdlcrx), FALSE, FALSE, 5, t30_hdlc_accept, &(s->t30_state));
    fsk_rx_init(&(s->v21rx), &preset_fsk_specs[FSK_V21CH2], TRUE, (put_bit_func_t) hdlc_rx_put_bit, &(s->hdlcrx));
    fsk_rx_signal_cutoff(&(s->v21rx), -45.5);
    hdlc_tx_init(&(s->hdlctx), FALSE, 2, FALSE, hdlc_underflow_handler, &(s->t30_state));
    s->first_tx_hdlc_frame = TRUE;
    fsk_tx_init(&(s->v21tx), &preset_fsk_specs[FSK_V21CH2], (get_bit_func_t) hdlc_tx_get_bit, &(s->hdlctx));
    v17_rx_init(&(s->v17rx), 14400, t30_non_ecm_put_bit, &(s->t30_state));
    v17_tx_init(&(s->v17tx), 14400, s->use_tep, t30_non_ecm_get_bit, &(s->t30_state));
    v29_rx_init(&(s->v29rx), 9600, t30_non_ecm_put_bit, &(s->t30_state));
    v29_rx_signal_cutoff(&(s->v29rx), -45.5);
    v29_tx_init(&(s->v29tx), 9600, s->use_tep, t30_non_ecm_get_bit, &(s->t30_state));
    v27ter_rx_init(&(s->v27ter_rx), 4800, t30_non_ecm_put_bit, &(s->t30_state));
    v27ter_tx_init(&(s->v27ter_tx), 4800, s->use_tep, t30_non_ecm_get_bit, &(s->t30_state));
    silence_gen_init(&(s->silence_gen), 0);
    dc_restore_init(&(s->dc_restore));
    t30_restart(&(s->t30_state));
#if defined(LOG_FAX_AUDIO)
    {
        char buf[100 + 1];
        struct tm *tm;
        time_t now;

        time(&now);
        tm = localtime(&now);
        sprintf(buf,
                "/tmp/fax-rx-audio-%x-%02d%02d%02d%02d%02d%02d",
                s,
                tm->tm_year%100,
                tm->tm_mon + 1,
                tm->tm_mday,
                tm->tm_hour,
                tm->tm_min,
                tm->tm_sec);
        s->fax_audio_rx_log = open(buf, O_CREAT | O_TRUNC | O_WRONLY, 0666);
        sprintf(buf,
                "/tmp/fax-tx-audio-%x-%02d%02d%02d%02d%02d%02d",
                s,
                tm->tm_year%100,
                tm->tm_mon + 1,
                tm->tm_mday,
                tm->tm_hour,
                tm->tm_min,
                tm->tm_sec);
        s->fax_audio_tx_log = open(buf, O_CREAT | O_TRUNC | O_WRONLY, 0666);
    }
#endif
    return s;
}