Esempio n. 1
0
SPAN_DECLARE(int) fax_modems_free(fax_modems_state_t *s)
{
    if (s)
        span_free(s);
    /*endif*/
    return 0;
}
Esempio n. 2
0
SPAN_DECLARE(int) span_schedule_free(span_sched_state_t *s)
{
    span_schedule_release(s);
    if (s)
        span_free(s);
    return 0;
}
Esempio n. 3
0
SPAN_DECLARE(int) t4_rx_free(t4_rx_state_t *s)
{
    int ret;

    ret = t4_rx_release(s);
    span_free(s);
    return ret;
}
Esempio n. 4
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;
}
Esempio n. 5
0
SPAN_DECLARE(int) span_schedule_release(span_sched_state_t *s)
{
    if (s->sched)
    {
        span_free(s->sched);
        s->sched = NULL;
    }
    return 0;
}
Esempio n. 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;
}
Esempio n. 7
0
static int free_buffers(t4_t6_decode_state_t *s)
{
    if (s->cur_runs)
    {
        span_free(s->cur_runs);
        s->cur_runs = NULL;
    }
    if (s->ref_runs)
    {
        span_free(s->ref_runs);
        s->ref_runs = NULL;
    }
    if (s->row_buf)
    {
        span_free(s->row_buf);
        s->row_buf = NULL;
    }
    s->bytes_per_row = 0;
    return 0;
}
Esempio n. 8
0
static void tiff_rx_release(t4_rx_state_t *s)
{
    if (s->tiff.tiff_file)
        close_tiff_output_file(s);
    if (s->tiff.image_buffer)
    {
        span_free(s->tiff.image_buffer);
        s->tiff.image_buffer = NULL;
        s->tiff.image_size = 0;
        s->tiff.image_buffer_size = 0;
    }
}
Esempio n. 9
0
SPAN_DECLARE(int) super_tone_rx_free_descriptor(super_tone_rx_descriptor_t *desc)
{
    int i;

    if (desc)
    {
        for (i = 0; i < desc->tones; i++)
        {
            if (desc->tone_list[i])
                span_free(desc->tone_list[i]);
        }
        if (desc->tone_list)
            span_free(desc->tone_list);
        if (desc->tone_segs)
            span_free(desc->tone_segs);
        if (desc->desc)
            span_free(desc->desc);
        span_free(desc);
    }
    return 0;
}
Esempio n. 10
0
SPAN_DECLARE(int) t30_set_tx_csa(t30_state_t *s, int type, const char *address, int len)
{
    if (s->tx_info.csa)
        span_free(s->tx_info.csa);
    if (address == NULL)
    {
        s->tx_info.csa = NULL;
        return 0;
    }
    s->tx_info.csa = strdup(address);
    return 0;
}
Esempio n. 11
0
static int write_tiff_t43_image(t4_rx_state_t *s)
{
    uint8_t *buf;
    uint8_t *buf2;
    int buf_len;
    int len;
    int image_len;
    t43_encode_state_t t43;
    packer_t packer;

    packer.buf = s->tiff.image_buffer;
    packer.ptr = 0;
    if (t43_encode_init(&t43, s->metadata.image_width, s->metadata.image_length, row_read_handler, &packer) == NULL)
        return -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 = t43_encode_get(&t43, &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);
    t43_encode_release(&t43);
    span_free(buf);
    return 0;
}
Esempio n. 12
0
int main(int argc, char *argv[])
{
    void *a;
    void *b;
    void *c;
    
    if (span_mem_allocators(memalign,
                            malloc,
                            realloc,
                            free))
    {
        printf("Failed\n");
        exit(2);
    }
    a = span_aligned_alloc(8, 42);
    b = span_alloc(42);
    c = span_realloc(NULL, 42);
    printf("%p %p %p\n", a, b, c);
    span_free(a);
    span_free(b);
    span_free(c);
}
Esempio n. 13
0
SPAN_DECLARE(int) t30_set_tx_nsc(t30_state_t *s, const uint8_t *nsc, int len)
{
    if (s->tx_info.nsc)
        span_free(s->tx_info.nsc);
    if (nsc  &&  len > 0  &&  (s->tx_info.nsc = span_alloc(len + 3)))
    {
        memcpy(s->tx_info.nsc + 3, nsc, len);
        s->tx_info.nsc_len = len;
    }
    else
    {
        s->tx_info.nsc = NULL;
        s->tx_info.nsc_len = 0;
    }
    return 0;
}
Esempio n. 14
0
SPAN_DECLARE(int) t30_set_tx_nss(t30_state_t *s, const uint8_t *nss, int len)
{
    if (s->tx_info.nss)
        span_free(s->tx_info.nss);
    if (nss  &&  len > 0  &&  (s->tx_info.nss = span_alloc(len + 3)))
    {
        memcpy(&s->tx_info.nss[3], nss, len);
        s->tx_info.nss_len = len;
    }
    else
    {
        s->tx_info.nss = NULL;
        s->tx_info.nss_len = 0;
    }
    return 0;
}
Esempio n. 15
0
SPAN_DECLARE(int) t30_set_tx_tsa(t30_state_t *s, int type, const char *address, int len)
{
    if (s->tx_info.tsa)
        span_free(s->tx_info.tsa);
    if (address == NULL  ||  len == 0)
    {
        s->tx_info.tsa = NULL;
        s->tx_info.tsa_len = 0;
        return 0;
    }
    s->tx_info.tsa_type = type;
    if (len < 0)
        len = strlen(address);
    if ((s->tx_info.tsa = span_alloc(len)))
    {
        memcpy(s->tx_info.tsa, address, len);
        s->tx_info.tsa_len = len;
    }
    return 0;
}
Esempio n. 16
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)
        {
            if (remove(s->tiff.file) < 0)
                span_log(&s->logging, SPAN_LOG_WARNING, "%s: Failed to remove file.\n", s->tiff.file);
        }
        span_free((char *) s->tiff.file);
    }
    s->tiff.file = NULL;
    return 0;
}
Esempio n. 17
0
static int pre_encoded_put(no_decoder_state_t *s, const uint8_t data[], size_t len)
{
    uint8_t *buf;

    if (s->buf_len < s->buf_ptr + len)
    {
        s->buf_len += 65536;
        if ((buf = span_realloc(s->buf, s->buf_len)) == NULL)
        {
            if (s->buf)
            {
                span_free(s->buf);
                s->buf = NULL;
                s->buf_len = 0;
            }
            return -1;
        }
        s->buf = buf;
    }
    memcpy(&s->buf[s->buf_ptr], data, len);
    s->buf_ptr += len;
    return T4_DECODE_MORE_DATA;
}
Esempio n. 18
0
SPAN_DECLARE(int) silence_gen_free(silence_gen_state_t *s)
{
    if (s)
        span_free(s);
    return 0;
}
Esempio n. 19
0
SPAN_DECLARE(void) tone_gen_descriptor_free(tone_gen_descriptor_t *s)
{
    span_free(s);
}
Esempio n. 20
0
SPAN_DECLARE(int) queue_free(queue_state_t *s)
{
    span_free(s);
    return 0;
}
Esempio n. 21
0
SPAN_DECLARE(int) fax_free(fax_state_t *s)
{
    t30_release(&s->t30);
    span_free(s);
    return 0;
}
Esempio n. 22
0
SPAN_DECLARE(int) sig_tone_tx_free(sig_tone_tx_state_t *s)
{
    if (s)
        span_free(s);
    return 0;
}
Esempio n. 23
0
SPAN_DECLARE(int) super_tone_rx_free(super_tone_rx_state_t *s)
{
    if (s)
        span_free(s);
    return 0;
}
Esempio n. 24
0
SPAN_DECLARE(int) ademco_contactid_receiver_free(ademco_contactid_receiver_state_t *s)
{
    span_free(s);
    return 0;
}
Esempio n. 25
0
static int pre_encoded_release(no_decoder_state_t *s)
{
    if (s->buf)
        span_free(s->buf);
    return 0;
}