test_decode.c 2.02 KB
Newer Older
1 2 3 4
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <inttypes.h>
5
#include "libae.h"
6 7 8 9 10 11

#define CHUNK_OUT 1
#define CHUNK_IN 1

int main(int argc, char *argv[])
{
12 13
    ae_stream strm;
    uint8_t *in;
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
14
    uint8_t *out;
15 16
    int chunk_in, chunk_out, i, c, total_out, status;
    int input_avail, output_avail;
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
17

18 19 20 21 22
    if (argc == 3)
    {
        chunk_in = atoi(argv[1]);
        chunk_out = atoi(argv[2]);
    }
23 24 25 26 27
    else
    {
        chunk_in = CHUNK_IN;
        chunk_out = CHUNK_OUT;
    }
28

29
    in = (uint8_t *)malloc(chunk_in);
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
30
    out = (uint8_t *)malloc(chunk_out * sizeof(uint8_t));
31 32
    if (in == NULL || out == NULL)
        return 1;
33

Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
34
    strm.bit_per_sample = 8;
35 36
    strm.block_size = 8;
    strm.segment_size = 2;
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
37
    strm.flags = AE_DATA_UNSIGNED | AE_DATA_PREPROCESS;
38

39 40
    if (ae_decode_init(&strm) != AE_OK)
        return 1;
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
41

42
    total_out = 0;
43 44
    strm.avail_in = 0;
    strm.avail_out = chunk_out;
45
    strm.next_out = (uint8_t *)out;
46 47 48

    input_avail = 1;
    output_avail = 1;
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
49

50
    while(input_avail || output_avail)
51
    {
52
        if (strm.avail_in == 0)
53
        {
54 55 56 57 58 59 60 61
            i = 0;
            while(i < chunk_in && (c = getc(stdin)) != EOF)
                in[i++] = c;
            strm.avail_in = i;

            strm.next_in = in;
            if (c == EOF)
                input_avail = 0;
62
        }
63

64
        if ((status = ae_decode(&strm, AE_NO_FLUSH)) != AE_OK)
65
        {
66 67
            fprintf(stderr, "error is %i\n", status);
            return 1;
68
        }
69

70 71 72 73 74
        if (strm.total_out - total_out > 0)
        {
            for (i=0; i < strm.total_out - total_out; i++)
            {
                putc(out[i], stdout);
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
75 76 77
                /* putc(out[i] >> 8, stdout); */
                /* putc(out[i] >> 16, stdout); */
                /* putc(out[i] >> 24, stdout); */
78 79
            }
            total_out = strm.total_out;
80
            output_avail = 1;
81
            strm.next_out = (uint8_t *)out;
82 83
            strm.avail_out = chunk_out;
        }
84 85 86 87 88
        else
        {
            output_avail = 0;
        }

89 90 91
    }

    return 0;
92
}