1 /*
2 * Copyright (c) 2014 Nicolas George
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License
8 * as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg 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 FFmpeg; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
26
28 #if HAVE_THREADS
33 int err_send;
34 int err_recv;
35 unsigned elsize;
36 void (*free_func)(void *msg);
37 #else
39 #endif
40 };
41
43 unsigned nelem,
44 unsigned elsize)
45 {
46 #if HAVE_THREADS
49
50 if (nelem > INT_MAX / elsize)
57 }
62 }
68 }
75 }
76 rmq->elsize = elsize;
77 *mq = rmq;
78 return 0;
79 #else
82 #endif /* HAVE_THREADS */
83 }
84
86 void (*free_func)(void *msg))
87 {
88 #if HAVE_THREADS
89 mq->free_func = free_func;
90 #endif
91 }
92
94 {
95 #if HAVE_THREADS
96 if (*mq) {
103 }
104 #endif
105 }
106
108 {
109 #if HAVE_THREADS
115 #else
117 #endif
118 }
119
120 #if HAVE_THREADS
121
123 void *msg,
125 {
130 }
131 if (mq->err_send)
132 return mq->err_send;
134 /* one message is sent, signal one receiver */
136 return 0;
137 }
138
140 void *msg,
142 {
147 }
149 return mq->err_recv;
151 /* one message space appeared, signal one sender */
153 return 0;
154 }
155
156 #endif /* HAVE_THREADS */
157
159 void *msg,
161 {
162 #if HAVE_THREADS
164
166 ret = av_thread_message_queue_send_locked(mq, msg,
flags);
169 #else
171 #endif /* HAVE_THREADS */
172 }
173
175 void *msg,
177 {
178 #if HAVE_THREADS
180
182 ret = av_thread_message_queue_recv_locked(mq, msg,
flags);
185 #else
187 #endif /* HAVE_THREADS */
188 }
189
191 int err)
192 {
193 #if HAVE_THREADS
195 mq->err_send = err;
198 #endif /* HAVE_THREADS */
199 }
200
202 int err)
203 {
204 #if HAVE_THREADS
206 mq->err_recv = err;
209 #endif /* HAVE_THREADS */
210 }
211
212 #if HAVE_THREADS
213 static int free_func_wrap(
void *
arg,
void *buf,
size_t *nb_elems)
214 {
216 uint8_t *msg = buf;
217 for (
size_t i = 0;
i < *nb_elems;
i++)
218 mq->free_func(msg +
i * mq->elsize);
219 return 0;
220 }
221 #endif
222
224 {
225 #if HAVE_THREADS
226 size_t used;
227
230 if (mq->free_func)
232 /* only the senders need to be notified since the queue is empty and there
233 * is nothing to read */
236 #endif /* HAVE_THREADS */
237 }