Exemplo n.º 1
0
static int close_tiff_output_file(t4_rx_state_t *s)
{
    int i;
    t4_rx_tiff_state_t *t;

    t = &s->tiff;
    /* Perform any operations needed to tidy up a written TIFF file before
       closure. */
    if (s->current_page > 1)
    {
        /* We need to edit the TIFF directories. Until now we did not know
           the total page count, so the TIFF file currently says one. Now we
           need to set the correct total page count associated with each page. */
        for (i = 0;  i < s->current_page;  i++)
        {
            if (!TIFFSetDirectory(t->tiff_file, (tdir_t) i))
                span_log(&s->logging, SPAN_LOG_WARNING, "%s: Failed to set directory to page %d.\n", s->tiff.file, i);
            TIFFSetField(t->tiff_file, TIFFTAG_PAGENUMBER, i, s->current_page);
            if (!TIFFWriteDirectory(t->tiff_file))
                span_log(&s->logging, SPAN_LOG_WARNING, "%s: Failed to write directory for page %d.\n", s->tiff.file, i);
        }
    }
    TIFFClose(t->tiff_file);
    t->tiff_file = NULL;
    if (s->tiff.file)
    {
        /* Try not to leave a file behind, if we didn't receive any pages to
           put in it. */
        if (s->current_page == 0)
            remove(s->tiff.file);
        free((char *) s->tiff.file);
    }
    s->tiff.file = NULL;
    return 0;
}
Exemplo n.º 2
0
static void fax_set_rx_type(void *user_data, int type, int bit_rate, int short_train, int use_hdlc)
{
    fax_state_t *s;
    fax_modems_state_t *t;

    s = (fax_state_t *) user_data;
    t = &s->modems;
    span_log(&s->logging, SPAN_LOG_FLOW, "Set rx type %d\n", type);
    if (t->current_rx_type == type)
        return;
    t->current_rx_type = type;
    t->rx_bit_rate = bit_rate;
    hdlc_rx_init(&t->hdlc_rx, false, true, HDLC_FRAMING_OK_THRESHOLD, fax_modems_hdlc_accept, t);

    switch (type)
    {
    case T30_MODEM_V21:
        fax_modems_start_slow_modem(t, FAX_MODEM_V21_RX);
        break;
    case T30_MODEM_V17:
        fax_modems_start_fast_modem(t, FAX_MODEM_V17_RX, bit_rate, short_train, use_hdlc);
        break;
    case T30_MODEM_V27TER:
        fax_modems_start_fast_modem(t, FAX_MODEM_V27TER_RX, bit_rate, short_train, use_hdlc);
        break;
    case T30_MODEM_V29:
        fax_modems_start_fast_modem(t, FAX_MODEM_V29_RX, bit_rate, short_train, use_hdlc);
        break;
    case T30_MODEM_DONE:
        span_log(&s->logging, SPAN_LOG_FLOW, "FAX exchange complete\n");
    default:
        fax_modems_set_rx_handler(t, (span_rx_handler_t) &span_dummy_rx, s, (span_rx_fillin_handler_t) &span_dummy_rx_fillin, s);
        break;
    }
}
Exemplo n.º 3
0
static int tx_packet_handler(t38_core_state_t *s, void *user_data, const uint8_t *buf, int len, int count)
{
    int i;
    int chan;

    /* This routine queues messages between two instances of T.38 processing */
    chan = (intptr_t) user_data;
    if (t38_simulate_incrementing_repeats)
    {
        for (i = 0;  i < count;  i++)
        {
            span_log(&s->logging, SPAN_LOG_FLOW, "Send seq %d, len %d\n", t38_subst_seq[chan], len);

            if (g1050_put(g1050_path[chan], buf, len, t38_subst_seq[chan], when) < 0)
                printf("Lost packet %d\n", t38_subst_seq[chan]);
            t38_subst_seq[chan] = (t38_subst_seq[chan] + 1) & 0xFFFF;
        }
    }
    else
    {
        span_log(&s->logging, SPAN_LOG_FLOW, "Send seq %d, len %d, count %d\n", s->tx_seq_no, len, count);

        for (i = 0;  i < count;  i++)
        {
            if (g1050_put(g1050_path[chan], buf, len, s->tx_seq_no, when) < 0)
                printf("Lost packet %d\n", s->tx_seq_no);
        }
    }
    return 0;
}
Exemplo n.º 4
0
static int tx_packet_handler_b(t38_core_state_t *s, void *user_data, const uint8_t *buf, int len, int count)
{
    t38_terminal_state_t *t;
    int i;
    static int subst_seq = 0;

    /* This routine queues messages between two instances of T.38 processing */
    t = (t38_terminal_state_t *) user_data;
    if (simulate_incrementing_repeats)
    {
        for (i = 0;  i < count;  i++)
        {
            span_log(&s->logging, SPAN_LOG_FLOW, "Send seq %d, len %d\n", subst_seq, len);

            ip_network_model_send(path_b_to_a, subst_seq, 1, buf, len);
            subst_seq = (subst_seq + 1) & 0xFFFF;
        }
    }
    else
    {
        span_log(&s->logging, SPAN_LOG_FLOW, "Send seq %d, len %d, count %d\n", s->tx_seq_no, len, count);

        ip_network_model_send(path_b_to_a, s->tx_seq_no, count, buf, len);
    }
    return 0;
}
Exemplo n.º 5
0
static int v29_v21_rx(void *user_data, const int16_t amp[], int len)
{
    fax_state_t *t;
    fax_modems_state_t *s;

    t = (fax_state_t *) user_data;
    s = &t->modems;
    v29_rx(&s->v29_rx, amp, len);
    if (t->t30.rx_trained)
    {
        /* The fast modem has trained, so we no longer need to run the slow
           one in parallel. */
        span_log(&t->logging, SPAN_LOG_FLOW, "Switching from V.29 + V.21 to V.29 (%.2fdBm0)\n", v29_rx_signal_power(&s->v29_rx));
        set_rx_handler(t, (span_rx_handler_t *) &v29_rx, (span_rx_fillin_handler_t *) &v29_rx_fillin, &s->v29_rx);
    }
    else
    {
        fsk_rx(&s->v21_rx, amp, len);
        if (t->t30.rx_frame_received)
        {
            /* We have received something, and the fast modem has not trained. We must
               be receiving valid V.21 */
            span_log(&t->logging, SPAN_LOG_FLOW, "Switching from V.29 + V.21 to V.21 (%.2fdBm0)\n", fsk_rx_signal_power(&s->v21_rx));
            set_rx_handler(t, (span_rx_handler_t *) &fsk_rx, (span_rx_fillin_handler_t *) &fsk_rx_fillin, &s->v21_rx);
        }
    }
    return 0;
}
Exemplo n.º 6
0
static int tx_packet_handler_a(t38_core_state_t *s, void *user_data, const uint8_t *buf, int len, int count)
{
    int i;
    static int subst_seq = 0;

    /* This routine queues messages between two instances of T.38 processing */
    if (simulate_incrementing_repeats)
    {
        for (i = 0;  i < count;  i++)
        {
            span_log(&s->logging, SPAN_LOG_FLOW, "Send seq %d, len %d\n", subst_seq, len);

            g1050_put(path_a_to_b, buf, len, subst_seq, when);
            subst_seq = (subst_seq + 1) & 0xFFFF;
        }
    }
    else
    {
        span_log(&s->logging, SPAN_LOG_FLOW, "Send seq %d, len %d, count %d\n", s->tx_seq_no, len, count);

        for (i = 0;  i < count;  i++)
            g1050_put(path_a_to_b, buf, len, s->tx_seq_no, when);
    }
    return 0;
}
Exemplo n.º 7
0
Arquivo: fax.c Projeto: vir/spandsp
static void fax_set_rx_type(void *user_data, int type, int bit_rate, int short_train, int use_hdlc)
{
    fax_state_t *s;
    put_bit_func_t put_bit_func;
    void *put_bit_user_data;
    fax_modems_state_t *t;

    s = (fax_state_t *) user_data;
    t = &s->modems;
    span_log(&s->logging, SPAN_LOG_FLOW, "Set rx type %d\n", type);
    if (t->current_rx_type == type)
        return;
    /*endif*/
    t->current_rx_type = type;
    t->rx_bit_rate = bit_rate;
    if (use_hdlc)
    {
        put_bit_func = (put_bit_func_t) hdlc_rx_put_bit;
        put_bit_user_data = (void *) &t->hdlc_rx;
        hdlc_rx_init(&t->hdlc_rx, false, true, HDLC_FRAMING_OK_THRESHOLD, t30_hdlc_accept, &s->t30);
    }
    else
    {
        put_bit_func = t30_non_ecm_put_bit;
        put_bit_user_data = (void *) &s->t30;
    }
    /*endif*/
    switch (type)
    {
    case T30_MODEM_V21:
        fsk_rx_init(&t->v21_rx, &preset_fsk_specs[FSK_V21CH2], FSK_FRAME_MODE_SYNC, (put_bit_func_t) hdlc_rx_put_bit, put_bit_user_data);
        fsk_rx_signal_cutoff(&t->v21_rx, -45.5f);
        set_rx_handler(s, (span_rx_handler_t *) &fsk_rx, (span_rx_fillin_handler_t *) &fsk_rx_fillin, &t->v21_rx);
        break;
    case T30_MODEM_V17:
        v17_rx_restart(&t->fast_modems.v17_rx, bit_rate, short_train);
        v17_rx_set_put_bit(&t->fast_modems.v17_rx, put_bit_func, put_bit_user_data);
        set_rx_handler(s, &v17_v21_rx, &v17_v21_rx_fillin, s);
        break;
    case T30_MODEM_V27TER:
        v27ter_rx_restart(&t->fast_modems.v27ter_rx, bit_rate, false);
        v27ter_rx_set_put_bit(&t->fast_modems.v27ter_rx, put_bit_func, put_bit_user_data);
        set_rx_handler(s, &v27ter_v21_rx, &v27ter_v21_rx_fillin, s);
        break;
    case T30_MODEM_V29:
        v29_rx_restart(&t->fast_modems.v29_rx, bit_rate, false);
        v29_rx_set_put_bit(&t->fast_modems.v29_rx, put_bit_func, put_bit_user_data);
        set_rx_handler(s, &v29_v21_rx, &v29_v21_rx_fillin, s);
        break;
    case T30_MODEM_DONE:
        span_log(&s->logging, SPAN_LOG_FLOW, "FAX exchange complete\n");
    default:
        set_rx_handler(s, (span_rx_handler_t *) &span_dummy_rx, (span_rx_fillin_handler_t *) &span_dummy_rx_fillin, s);
        break;
    }
    /*endswitch*/
}
Exemplo n.º 8
0
static void tone_detected(void *user_data, int tone, int level, int delay)
{
    t30_state_t *s;

    s = (t30_state_t *) user_data;
    span_log(&s->logging, SPAN_LOG_FLOW, "%s detected (%ddBm0)\n", modem_connect_tone_to_str(tone), level);
}
Exemplo n.º 9
0
static void v8_handler(void *user_data, v8_parms_t *result)
{
    fax_state_t *s;

    s = (fax_state_t *) user_data;
    span_log(&s->logging, SPAN_LOG_FLOW, "V.8 report received\n");
}
Exemplo n.º 10
0
static void tone_detected(void *user_data, int on, int level, int delay)
{
    t30_state_t *s;

    s = (t30_state_t *) user_data;
    span_log(&s->logging, SPAN_LOG_FLOW, "FAX tone declared %s (%ddBm0)\n", (on)  ?  "on"  :  "off", level);
}
Exemplo n.º 11
0
SPAN_DECLARE(int) t4_rx_start_page(t4_rx_state_t *s)
{
    span_log(&s->logging, SPAN_LOG_FLOW, "Start rx page %d - compression %s\n", s->current_page, t4_encoding_to_str(s->line_encoding));

    switch (s->line_encoding)
    {
    case T4_COMPRESSION_ITU_T4_1D:
    case T4_COMPRESSION_ITU_T4_2D:
    case T4_COMPRESSION_ITU_T6:
        t4_t6_decode_restart(&s->decoder.t4_t6, s->image_width);
        break;
    case T4_COMPRESSION_ITU_T42:
        t42_decode_restart(&s->decoder.t42);
        break;
#if defined(SPANDSP_SUPPORT_T43)
    case T4_COMPRESSION_ITU_T43:
        t43_decode_restart(&s->decoder.t43);
        break;
#endif
    case T4_COMPRESSION_ITU_T85:
    case T4_COMPRESSION_ITU_T85_L0:
        t85_decode_restart(&s->decoder.t85);
        break;
    }
    s->line_image_size = 0;
    s->tiff.image_size = 0;

    time (&s->tiff.page_start_time);

    return 0;
}
Exemplo n.º 12
0
SPAN_DECLARE(int) t4_rx_end_page(t4_state_t *s)
{
    int row;
    int i;

    if (s->line_encoding == T4_COMPRESSION_ITU_T6)
    {
        /* Push enough zeros through the decoder to flush out any remaining codes */
        for (i = 0;  i < 13;  i++)
            t4_rx_put_bit(s, 0);
    }
    if (s->t4_t6_rx.curr_bad_row_run)
    {
        if (s->t4_t6_rx.curr_bad_row_run > s->t4_t6_rx.longest_bad_row_run)
            s->t4_t6_rx.longest_bad_row_run = s->t4_t6_rx.curr_bad_row_run;
        s->t4_t6_rx.curr_bad_row_run = 0;
    }

    if (s->image_size == 0)
        return -1;

    if (s->t4_t6_rx.row_write_handler)
    {
        for (row = 0;  row < s->image_length;  row++)
        {
            if (s->t4_t6_rx.row_write_handler(s->t4_t6_rx.row_write_user_data, s->image_buffer + row*s->bytes_per_row, s->bytes_per_row) < 0)
            {
                span_log(&s->logging, SPAN_LOG_WARNING, "Write error at row %d.\n", row);
                break;
            }
        }
        /* Write a blank row to indicate the end of the image. */
        if (s->t4_t6_rx.row_write_handler(s->t4_t6_rx.row_write_user_data, NULL, 0) < 0)
            span_log(&s->logging, SPAN_LOG_WARNING, "Write error at row %d.\n", row);
    }
    else
    {
        write_tiff_image(s);
    }
    s->t4_t6_rx.rx_bits = 0;
    s->t4_t6_rx.rx_skip_bits = 0;
    s->t4_t6_rx.rx_bitstream = 0;
    s->t4_t6_rx.consecutive_eols = EOLS_TO_END_ANY_RX_PAGE;

    s->image_size = 0;
    return 0;
}
Exemplo n.º 13
0
static int write_tiff_image(t4_rx_state_t *s)
{
    t4_rx_tiff_state_t *t;
#if defined(SPANDSP_SUPPORT_TIFF_FX)
    uint64_t offset;
#endif

    t = &s->tiff;
    if (t->image_buffer == NULL  ||  t->image_size <= 0)
        return -1;
    /* Set up the TIFF directory info... */
    set_tiff_directory_info(s);
    /* ...Put the directory in the file before the image data, to get them in the order specified
       for TIFF/F files... */
    if (!TIFFCheckpointDirectory(t->tiff_file))
        span_log(&s->logging, SPAN_LOG_WARNING, "%s: Failed to checkpoint directory for page %d.\n", t->file, s->current_page);
    /* ...and write out the image... */
    if (TIFFWriteEncodedStrip(t->tiff_file, 0, t->image_buffer, t->image_size) < 0)
        span_log(&s->logging, SPAN_LOG_WARNING, "%s: Error writing TIFF strip.\n", t->file);
    /* ...then finalise the directory entry, and libtiff is happy. */
    if (!TIFFWriteDirectory(t->tiff_file))
        span_log(&s->logging, SPAN_LOG_WARNING, "%s: Failed to write directory for page %d.\n", t->file, s->current_page);
#if defined(SPANDSP_SUPPORT_TIFF_FX)
    if (s->current_page == 0)
    {
        if (!TIFFCreateCustomDirectory(t->tiff_file, &tiff_fx_field_array))
        {
            TIFFSetField(t->tiff_file, TIFFTAG_FAXPROFILE, PROFILETYPE_G3_FAX);
            TIFFSetField(t->tiff_file, TIFFTAG_PROFILETYPE, FAXPROFILE_F);
            TIFFSetField(t->tiff_file, TIFFTAG_VERSIONYEAR, "1998");

            offset = 0;
            if (!TIFFWriteCustomDirectory(t->tiff_file, &offset))
                printf("Failed to write custom directory.\n");

            /* Now go back and patch in the pointer to the new IFD */
            if (!TIFFSetDirectory(t->tiff_file, s->current_page))
                printf("Failed to set directory.\n");
            if (!TIFFSetField(t->tiff_file, TIFFTAG_GLOBALPARAMETERSIFD, offset))
                printf("Failed to set field.\n");
            if (!TIFFWriteDirectory(t->tiff_file))
                span_log(&s->logging, SPAN_LOG_WARNING, "%s: Failed to write directory for page %d.\n", t->file, s->current_page);
        }
    }
#endif
    return 0;
}
Exemplo n.º 14
0
static void set_rx_type(void *user_data, int type, int short_train, int use_hdlc)
{
    t38_terminal_state_t *s;

    s = (t38_terminal_state_t *) user_data;
    span_log(&s->logging, SPAN_LOG_FLOW, "Set rx type %d\n", type);
    s->current_rx_type = type;
}
Exemplo n.º 15
0
SPAN_DECLARE(void) v8_log_supported_modulations(v8_state_t *s, int modulation_schemes)
{
    const char *comma;
    int i;
    
    comma = "";
    span_log(&s->logging, SPAN_LOG_FLOW, "");
    for (i = 0;  i < 32;  i++)
    {
        if ((modulation_schemes & (1 << i)))
        {
            span_log(&s->logging, SPAN_LOG_FLOW | SPAN_LOG_SUPPRESS_LABELLING, "%s%s", comma, v8_modulation_to_str(modulation_schemes & (1 << i)));
            comma = ", ";
        }
    }
    span_log(&s->logging, SPAN_LOG_FLOW | SPAN_LOG_SUPPRESS_LABELLING, " supported\n");
}
Exemplo n.º 16
0
SPAN_DECLARE(void) t30_set_status(t30_state_t *s, int status)
{
    if (s->current_status != status)
    {
        span_log(&s->logging, SPAN_LOG_FLOW, "Status changing to '%s'\n", t30_completion_code_to_str(status));
        s->current_status = status;
    }
}
Exemplo n.º 17
0
SPAN_DECLARE(int) ademco_contactid_receiver_log_msg(ademco_contactid_receiver_state_t *s, const ademco_contactid_report_t *report)
{
    const char *t;

    span_log(&s->logging, SPAN_LOG_FLOW, "Ademco Contact ID message:\n");
    span_log(&s->logging, SPAN_LOG_FLOW, "    Account %X\n", report->acct);
    switch (report->mt)
    {
    case ADEMCO_CONTACTID_MESSAGE_TYPE_18:
    case ADEMCO_CONTACTID_MESSAGE_TYPE_98:
        t = "Contact ID";
        break;
    default:
        t = "???";
        break;
    }
    span_log(&s->logging, SPAN_LOG_FLOW, "    Message type %s (%X)\n", t, report->mt);
    t = ademco_contactid_msg_qualifier_to_str(report->q);
    span_log(&s->logging, SPAN_LOG_FLOW, "    Qualifier %s (%X)\n", t, report->q);
    t = ademco_contactid_event_to_str(report->xyz);
    span_log(&s->logging, SPAN_LOG_FLOW, "    Event %s (%X)\n", t, report->xyz);
    span_log(&s->logging, SPAN_LOG_FLOW, "    Group/partition %X\n", report->gg);
    span_log(&s->logging, SPAN_LOG_FLOW, "    User/Zone information %X\n", report->ccc);
    return 0;
}
Exemplo n.º 18
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;
}
Exemplo n.º 19
0
static void write_tiff_image(t4_state_t *s)
{
    /* Set up the TIFF directory info... */
    set_tiff_directory_info(s);
    /* ..and then write the image... */
    if (TIFFWriteEncodedStrip(s->tiff.tiff_file, 0, s->image_buffer, s->image_length*s->bytes_per_row) < 0)
        span_log(&s->logging, SPAN_LOG_WARNING, "%s: Error writing TIFF strip.\n", s->tiff.file);
    /* ...then the directory entry, and libtiff is happy. */
    TIFFWriteDirectory(s->tiff.tiff_file);
}
Exemplo n.º 20
0
static int tx_packet_handler(t38_core_state_t *s, void *user_data, const uint8_t *buf, int len, int count)
{
    t38_core_state_t *t;
    static int seq_no = 0;
    
    t = (t38_core_state_t *) user_data;
    span_log(&s->logging, SPAN_LOG_FLOW, "Send seq %d, len %d, count %d\n", s->tx_seq_no, len, count);
    if (t38_core_rx_ifp_packet(t, buf, len, seq_no) < 0)
        succeeded = FALSE;
    seq_no++;
    return 0;
}
Exemplo n.º 21
0
static int write_tiff_image(t4_rx_state_t *s)
{
    if (s->tiff.image_buffer == NULL  ||  s->tiff.image_size <= 0)
        return -1;
    /* Set up the TIFF directory info... */
    set_tiff_directory_info(s);
    /* ...and then write the image... */
    if (TIFFWriteEncodedStrip(s->tiff.tiff_file, 0, s->tiff.image_buffer, s->tiff.image_size) < 0)
        span_log(&s->logging, SPAN_LOG_WARNING, "%s: Error writing TIFF strip.\n", s->tiff.file);
    /* ...then the directory entry, and libtiff is happy. */
    TIFFWriteDirectory(s->tiff.tiff_file);
    return 0;
}
Exemplo n.º 22
0
SPAN_DECLARE(void) span_schedule_del(span_sched_state_t *s, int i)
{
    if (i >= s->max_to_date
        ||
        i < 0
        ||
        s->sched[i].callback == NULL)
    {
        span_log(&s->logging, SPAN_LOG_WARNING, "Requested to delete invalid scheduled ID %d ?\n", i);
        return;
    }
    /*endif*/
    s->sched[i].callback = NULL;
}
Exemplo n.º 23
0
static void v29_rx_status_handler(void *user_data, int status)
{
    fax_modems_state_t *s;

    s = (fax_modems_state_t *) user_data;
    switch (status)
    {
    case SIG_STATUS_TRAINING_SUCCEEDED:
        span_log(&s->logging, SPAN_LOG_FLOW, "Switching to V.29 (%.2fdBm0)\n", v29_rx_signal_power(&s->v29_rx));
        s->rx_handler = (span_rx_handler_t *) &v29_rx;
        s->rx_user_data = &s->v29_rx;
        break;
    }
}
static int t31_tx_packet_handler(t38_core_state_t *s, void *user_data, const uint8_t *buf, int len, int count)
{
    int i;

    /* This routine queues messages between two instances of T.38 processing, from the T.31 modem side. */
    span_log(t38_core_get_logging_state(s), SPAN_LOG_FLOW, "Send seq %d, len %d, count %d\n", s->tx_seq_no, len, count);

    for (i = 0;  i < count;  i++)
    {
        if (g1050_put(path_b_to_a, buf, len, s->tx_seq_no, when) < 0)
            printf("Lost packet %d\n", s->tx_seq_no);
    }
    return 0;
}
Exemplo n.º 25
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;
}
Exemplo n.º 26
0
static void v29_rx_status_handler(void *user_data, int status)
{
    fax_modems_state_t *s;

    s = (fax_modems_state_t *) user_data;
    switch (status)
    {
    case SIG_STATUS_TRAINING_SUCCEEDED:
        span_log(&s->logging, SPAN_LOG_FLOW, "Switching from V.29 + V.21 to V.29 (%.2fdBm0)\n", v29_rx_signal_power(&s->fast_modems.v29_rx));
        fax_modems_set_rx_handler(s, (span_rx_handler_t) &v29_rx, &s->fast_modems.v29_rx, (span_rx_fillin_handler_t) &v29_rx_fillin, &s->fast_modems.v29_rx);
        v29_rx_set_modem_status_handler(&s->fast_modems.v29_rx, NULL, s);
        break;
    }
    /*endswitch*/
    s->fast_modems.v29_rx.put_bit(s->fast_modems.v29_rx.put_bit_user_data, status);
}
Exemplo n.º 27
0
static int t38_tx_packet_handler(t38_core_state_t *s, void *user_data, const uint8_t *buf, int len, int count)
{
    t31_state_t *t;
    int i;

    /* This routine queues messages between two instances of T.38 processing */
    t = (t31_state_t *) user_data;
    span_log(&s->logging, SPAN_LOG_FLOW, "Send seq %d, len %d, count %d\n", s->tx_seq_no, len, count);

    for (i = 0;  i < count;  i++)
    {
        if (g1050_put(path_a_to_b, buf, len, s->tx_seq_no, when) < 0)
            printf("Lost packet %d\n", s->tx_seq_no);
    }
    return 0;
}
Exemplo n.º 28
0
SPAN_DECLARE_NONSTD(int) fax_modems_v29_v21_rx(void *user_data, const int16_t amp[], int len)
{
    fax_modems_state_t *s;

    s = (fax_modems_state_t *) user_data;
    v29_rx(&s->fast_modems.v29_rx, amp, len);
    fsk_rx(&s->v21_rx, amp, len);
    if (s->rx_frame_received)
    {
        /* We have received something, and the fast modem has not trained. We must be receiving valid V.21 */
        span_log(&s->logging, SPAN_LOG_FLOW, "Switching from V.29 + V.21 to V.21 (%.2fdBm0)\n", fsk_rx_signal_power(&s->v21_rx));
        fax_modems_set_rx_handler(s, (span_rx_handler_t) &fsk_rx, &s->v21_rx, (span_rx_fillin_handler_t) &fsk_rx_fillin, &s->v21_rx);
    }
    /*endif*/
    return 0;
}
Exemplo n.º 29
0
SPAN_DECLARE(int) fax_modems_v17_v21_rx(void *user_data, const int16_t amp[], int len)
{
    fax_modems_state_t *s;

    s = (fax_modems_state_t *) user_data;
    v17_rx(&s->v17_rx, amp, len);
    fsk_rx(&s->v21_rx, amp, len);
    if (s->rx_frame_received)
    {
        /* We have received something, and the fast modem has not trained. We must
           be receiving valid V.21 */
        span_log(&s->logging, SPAN_LOG_FLOW, "Switching from V.17 + V.21 to V.21 (%.2fdBm0)\n", fsk_rx_signal_power(&s->v21_rx));
        s->rx_handler = (span_rx_handler_t *) &fsk_rx;
        s->rx_user_data = &s->v21_rx;
    }
    return 0;
}
Exemplo n.º 30
0
static int write_tiff_t85_image(t4_rx_state_t *s)
{
    uint8_t *buf;
    uint8_t *buf2;
    int buf_len;
    int len;
    int image_len;
    t85_encode_state_t t85;
    packer_t packer;

    /* We need to perform this compression here, as libtiff does not understand it. */
    packer.buf = s->tiff.image_buffer;
    packer.ptr = 0;
    if (t85_encode_init(&t85, s->metadata.image_width, s->metadata.image_length, row_read_handler, &packer) == NULL)
        return -1;
    //if (t->compression == T4_COMPRESSION_T85_L0)
    //    t85_encode_set_options(&t85, 256, -1, -1);
    buf = NULL;
    buf_len = 0;
    image_len = 0;
    do
    {
        if (buf_len < image_len + 65536)
        {
            buf_len += 65536;
            if ((buf2 = span_realloc(buf, buf_len)) == NULL)
            {
                if (buf)
                    span_free(buf);
                return -1;
            }
            buf = buf2;
        }
        len = t85_encode_get(&t85, &buf[image_len], buf_len - image_len);
        image_len += len;
    }
    while (len > 0);
    if (TIFFWriteRawStrip(s->tiff.tiff_file, 0, buf, image_len) < 0)
    {
        span_log(&s->logging, SPAN_LOG_WARNING, "%s: Error writing TIFF strip.\n", s->tiff.file);
        return -1;
    }
    t85_encode_release(&t85);
    span_free(buf);
    return 0;
}