summaryrefslogtreecommitdiffstats
path: root/debian/transcode/transcode-1.1.7/testsuite/test-framealloc.c
blob: 2383803cb3b460f14c52338a69c6f6cac3f1fdcb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*
 * test-framealloc.c -- testsuite for frame allocation functions.
 *                      everyone feel free to add more tests and improve
 *                      existing ones.
 * (C) 2006-2010 - Francesco Romani <fromani -at- gmail -dot- com>
 *
 * This file is part of transcode, a video stream processing tool.
 *
 * transcode is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * transcode is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */


#include <stdio.h>
#include <stdlib.h>

#include "config.h"
#include "libtc/libtc.h"
#include "libtc/tcframes.h"
#include "src/tc_defaults.h"
#include "src/framebuffer.h"

#ifndef PACKAGE
#define PACKAGE __FILE__
#endif

static int format[] = { CODEC_RGB, CODEC_YUV422, CODEC_YUV }; /* old breed */
static const char *strfmt[] = { "rgb24", "yuv422p", "yuv420p" };

static int test_alloc_vid(int w, int h, int fmtid, int part)
{
    int ret = 0;
    int fmt = format[fmtid];
    vframe_list_t *vptr = tc_new_video_frame(w, h, fmt, part);

    if (vptr != NULL && vptr->video_size >= (w * h * 3 / 2)) {
        ret = 1;
    }
    tc_del_video_frame(vptr);

    if (ret) {
        tc_info("testing frame (simple): width=%i height=%i format=%s partial=%s -> OK",
                w, h, strfmt[fmtid], (part) ?"yes" :"no");
    } else {
        tc_warn("testing frame (simple): width=%i height=%i format=%s partial=%s -> FAILED",
                w, h, strfmt[fmtid], (part) ?"yes" :"no");
    }
    return ret;
}

static int test_alloc_aud(double rate, double fps, int chans, int bits)
{
    int ret = 0;
    aframe_list_t *aptr = tc_new_audio_frame(rate/fps, chans, bits);

    if (aptr != NULL) {
        int as = ((rate/fps) * chans * bits/8);
        if (aptr->audio_size >=  as - 2) {
            ret = 1;
        }
    }
    tc_del_audio_frame(aptr);

    if (ret) {
        tc_info("testing frame (simple): samples=%.0f/%.3f channels=%i bits=%i -> OK",
                rate, fps, chans, bits);
    } else {
        tc_warn("testing frame (simple): samples=%.0f/%.3f channels=%i bits=%i -> FAILED",
                rate, fps, chans, bits);
    }
    return ret;
}


static int test_alloc_memset_vid(int w, int h, int fmtid, int part)
{
    int ret = 0;
    int fmt = format[fmtid];
    vframe_list_t *vptr = tc_new_video_frame(w, h, fmt, part);

    if (vptr != NULL && vptr->video_size >= (w * h * 3 / 2)) {
        memset(vptr->video_buf, 'A', vptr->video_size);
        if (!part) {
            memset(vptr->video_buf2, 'B', vptr->video_size);
        }
        ret = 1;
    }
    tc_del_video_frame(vptr);

    if (ret) {
        tc_info("testing frame (memset): width=%i height=%i format=%s partial=%s -> OK",
                w, h, strfmt[fmtid], (part) ?"yes" :"no");
    } else {
        tc_warn("testing frame (memset): width=%i height=%i format=%s partial=%s -> FAILED",
                w, h, strfmt[fmtid], (part) ?"yes" :"no");
    }
    return ret;
}

static int test_alloc_memset_aud(double rate, double fps, int chans, int bits)
{
    int ret = 0;
    aframe_list_t *aptr = tc_new_audio_frame(rate/fps, chans, bits);

    if (aptr != NULL) {
        int as = ((rate/fps) * chans * bits/8);
        if (aptr->audio_size >=  as - 2) {
            memset(aptr->audio_buf, 'A', aptr->audio_size);
            ret = 1;
        }
    }
    tc_del_audio_frame(aptr);

    if (ret) {
        tc_info("testing frame (memset): samples=%.0f/%.3f channels=%i bits=%i -> OK",
                rate, fps, chans, bits);
    } else {
        tc_warn("testing frame (memset): samples=%.0f/%.3f channels=%i bits=%i -> FAILED",
                rate, fps, chans, bits);
    }
    return ret;
}


#define LEN(a)  (sizeof(a)/sizeof((a)[0]))

int main(void)
{
    int width[] = { 128, 320, 576, 640, 960, 1024, 1280, 2048 };
    int height[] = { 96, 240, 240, 480, 560, 768, 800, 1536 };
    int w, h, f;

    double fps[] = { 24000.0/1001.0, 24000.0/1000.0, 25000.0/1000.0,
                     30000.0/1001.0, 30000.0/1000.0, 50000.0/1000.0 };
    double rate[] = { 16000.0, 22500.0, 24000.0, 32000.0, 44100.0, 48000.0 };
    int channels[] = { 1, 2 };
    int bits[] = { 8, 16 };
    int F, r, c, b;

    int runned = 0, succesfull = 0;

    for (f = 0; f < LEN(format); f++) {
        for (w = 0; w < LEN(width); w++) {
            for (h = 0; h < LEN(height); h++) {
                succesfull += test_alloc_vid(width[w], height[h], f, 0);
                succesfull += test_alloc_vid(width[w], height[h], f, 1);
                runned += 2;
            }
        }
    }

    for (F = 0; F < LEN(fps); F++) {
        for (r = 0; r < LEN(rate); r++) {
            for (c = 0; c < LEN(channels); c++) {
                for (b = 0; b < LEN(bits); b++) {
                   succesfull += test_alloc_aud(rate[r], fps[F], channels[c], bits[b]);
                   runned++;
                }
            }
        }
    }

    for (f = 0; f < LEN(format); f++) {
        for (w = 0; w < LEN(width); w++) {
            for (h = 0; h < LEN(height); h++) {
                succesfull += test_alloc_memset_vid(width[w], height[h], f, 0);
                succesfull += test_alloc_memset_vid(width[w], height[h], f, 1);
                runned += 2;
            }
        }
    }

    for (F = 0; F < LEN(fps); F++) {
        for (r = 0; r < LEN(rate); r++) {
            for (c = 0; c < LEN(channels); c++) {
                for (b = 0; b < LEN(bits); b++) {
                    succesfull += test_alloc_memset_aud(rate[r], fps[F], channels[c], bits[b]);
                    runned++;
                }
            }
        }
    }

    tc_info("test summary: %i tests runned, %i succesfully",
            runned, succesfull);
    return 0;
}

/*************************************************************************/

/*
 * Local variables:
 *   c-file-style: "stroustrup"
 *   c-file-offsets: ((case-label . *) (statement-case-intro . *))
 *   indent-tabs-mode: nil
 * End:
 *
 * vim: expandtab shiftwidth=4:
 */