]> git.sesse.net Git - vlc/blob - src/test/picture_pool.c
mux: avi: don't try to delete failed stream
[vlc] / src / test / picture_pool.c
1 /*****************************************************************************
2  * picture_pool.c: test cases for picture_poo_t
3  *****************************************************************************
4  * Copyright (C) 2014 RĂ©mi Denis-Courmont
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation; either version 2.1 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19  *****************************************************************************/
20
21 #ifdef HAVE_CONFIG_H
22 # include "config.h"
23 #endif
24
25 #include <stdbool.h>
26 #undef NDEBUG
27 #include <assert.h>
28
29 #include <vlc_common.h>
30 #include <vlc_es.h>
31 #include <vlc_picture_pool.h>
32
33 #define PICTURES 10
34
35 static video_format_t fmt;
36 static picture_pool_t *pool, *reserve;
37
38 static void test(bool zombie)
39 {
40     picture_t *pics[PICTURES];
41
42     pool = picture_pool_NewFromFormat(&fmt, PICTURES);
43     assert(pool != NULL);
44
45     for (unsigned i = 0; i < PICTURES; i++) {
46         pics[i] = picture_pool_Get(pool);
47         assert(pics[i] != NULL);
48     }
49
50     for (unsigned i = 0; i < PICTURES; i++)
51         assert(picture_pool_Get(pool) == NULL);
52
53     // Reserve currently assumes that all pictures are free (or reserved).
54     //assert(picture_pool_Reserve(pool, 1) == NULL);
55
56     for (unsigned i = 0; i < PICTURES / 2; i++)
57         picture_Hold(pics[i]);
58
59     for (unsigned i = 0; i < PICTURES / 2; i++)
60         picture_Release(pics[i]);
61
62     for (unsigned i = 0; i < PICTURES; i++) {
63         picture_Release(pics[i]);
64         assert(picture_pool_Get(pool) == pics[i]);
65     }
66
67     for (unsigned i = 0; i < PICTURES; i++)
68         picture_Release(pics[i]);
69
70     reserve = picture_pool_Reserve(pool, PICTURES / 2);
71     assert(reserve != NULL);
72
73     for (unsigned i = 0; i < PICTURES / 2; i++) {
74         pics[i] = picture_pool_Get(pool);
75         assert(pics[i] != NULL);
76     }
77
78     for (unsigned i = PICTURES / 2; i < PICTURES; i++) {
79         assert(picture_pool_Get(pool) == NULL);
80         pics[i] = picture_pool_Get(reserve);
81         assert(pics[i] != NULL);
82     }
83
84     if (!zombie)
85         for (unsigned i = 0; i < PICTURES; i++)
86             picture_Release(pics[i]);
87
88     picture_pool_Release(reserve);
89     picture_pool_Release(pool);
90
91     if (zombie)
92         for (unsigned i = 0; i < PICTURES; i++)
93             picture_Release(pics[i]);
94 }
95
96 int main(void)
97 {
98     video_format_Setup(&fmt, VLC_CODEC_I420, 320, 200, 320, 200, 1, 1);
99
100     pool = picture_pool_NewFromFormat(&fmt, PICTURES);
101     assert(pool != NULL);
102     assert(picture_pool_GetSize(pool) == PICTURES);
103
104     reserve = picture_pool_Reserve(pool, PICTURES / 2);
105     assert(reserve != NULL);
106
107     picture_pool_Release(reserve);
108     picture_pool_Release(pool);
109
110     test(false);
111     test(true);
112
113     return 0;
114 }