1 /*
2 * Permission is hereby granted, free of charge, to any person obtaining a copy
3 * of this software and associated documentation files (the "Software"), to deal
4 * in the Software without restriction, including without limitation the rights
5 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
6 * copies of the Software, and to permit persons to whom the Software is
7 * furnished to do so, subject to the following conditions:
8 *
9 * The above copyright notice and this permission notice shall be included in
10 * all copies or substantial portions of the Software.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
15 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
18 * THE SOFTWARE.
19 */
20
21 /**
22 * Thread message API test
23 */
24
30
36 };
37
38 /* same as sender_data but shuffled for testing purpose */
44 };
45
48 // we add some junk in the message to make sure the message size is >
49 // sizeof(void*)
51 };
52
53 #define MAGIC 0xdeadc0de
54
56 {
60 }
61
63 {
66
72 } else {
78 };
79
82 break;
83 }
84
85 /* we add some metadata to identify the frames */
91 break;
92 }
96 break;
97 }
99
100 /* allocate a real frame in order to simulate "real" work */
107 break;
108 }
109
110 /* push the frame in the common queue */
116 break;
117 }
118 }
119 }
124 }
125
127 {
130
134 "discarding %d message(s)\n", rd->
id,
137 } else {
141
144 break;
150 }
151 }
152
155
157 }
158
160 {
161 return maxv == minv ? maxv : rand() % (maxv - minv) + minv;
162 }
163
165 {
167 int max_queue_size;
168 int nb_senders, sender_min_load, sender_max_load;
169 int nb_receivers, receiver_min_load, receiver_max_load;
173
174 if (ac != 8) {
176 "<nb_senders> <sender_min_send> <sender_max_send> "
177 "<nb_receivers> <receiver_min_recv> <receiver_max_recv>\n", av[0]);
178 return 1;
179 }
180
181 max_queue_size = atoi(av[1]);
182 nb_senders = atoi(av[2]);
183 sender_min_load = atoi(av[3]);
184 sender_max_load = atoi(av[4]);
185 nb_receivers = atoi(av[5]);
186 receiver_min_load = atoi(av[6]);
187 receiver_max_load = atoi(av[7]);
188
189 if (max_queue_size <= 0 ||
190 nb_senders <= 0 || sender_min_load <= 0 || sender_max_load <= 0 ||
191 nb_receivers <= 0 || receiver_min_load <= 0 || receiver_max_load <= 0) {
193 return 1;
194 }
195
197 "%d receivers receiving [%d-%d]\n", max_queue_size,
198 nb_senders, sender_min_load, sender_max_load,
199 nb_receivers, receiver_min_load, receiver_max_load);
200
201 senders =
av_calloc(nb_senders,
sizeof(*senders));
202 receivers =
av_calloc(nb_receivers,
sizeof(*receivers));
203 if (!senders || !receivers) {
205 goto end;
206 }
207
210 goto end;
211
213
214 #define SPAWN_THREADS(type) do { \
215 for (i = 0; i < nb_##type##s; i++) { \
216 struct type##_data *td = &type##s[i]; \
217 \
218 td->id = i; \
219 td->queue = queue; \
220 td->workload = get_workload(type##_min_load, type##_max_load); \
221 \
222 ret = pthread_create(&td->tid, NULL, type##_thread, td); \
223 if (ret) { \
224 const int err = AVERROR(ret); \
225 av_log(NULL, AV_LOG_ERROR, "Unable to start " AV_STRINGIFY(type) \
226 " thread: %s\n", av_err2str(err)); \
227 goto end; \
228 } \
229 } \
230 } while (0)
231
232 #define WAIT_THREADS(type) do { \
233 for (i = 0; i < nb_##type##s; i++) { \
234 struct type##_data *td = &type##s[i]; \
235 \
236 ret = pthread_join(td->tid, NULL); \
237 if (ret) { \
238 const int err = AVERROR(ret); \
239 av_log(NULL, AV_LOG_ERROR, "Unable to join " AV_STRINGIFY(type) \
240 " thread: %s\n", av_err2str(err)); \
241 goto end; \
242 } \
243 } \
244 } while (0)
245
248
251
252 end:
256
259 return 1;
260 }
261 return 0;
262 }