54#define MAGIC 0xdeadc0de
135 "discarding %d message(s)\n", rd->
id,
162 return maxv == minv ? maxv : rand() % (maxv - minv) + minv;
169 int nb_senders, sender_min_load, sender_max_load;
170 int nb_receivers, receiver_min_load, receiver_max_load;
177 "<nb_senders> <sender_min_send> <sender_max_send> "
178 "<nb_receivers> <receiver_min_recv> <receiver_max_recv>\n", av[0]);
182 max_queue_size = atoi(av[1]);
183 nb_senders = atoi(av[2]);
184 sender_min_load = atoi(av[3]);
185 sender_max_load = atoi(av[4]);
186 nb_receivers = atoi(av[5]);
187 receiver_min_load = atoi(av[6]);
188 receiver_max_load = atoi(av[7]);
190 if (max_queue_size <= 0 ||
191 nb_senders <= 0 || sender_min_load <= 0 || sender_max_load <= 0 ||
192 nb_receivers <= 0 || receiver_min_load <= 0 || receiver_max_load <= 0) {
198 "%d receivers receiving [%d-%d]\n", max_queue_size,
199 nb_senders, sender_min_load, sender_max_load,
200 nb_receivers, receiver_min_load, receiver_max_load);
202 senders =
av_calloc(nb_senders,
sizeof(*senders));
203 receivers =
av_calloc(nb_receivers,
sizeof(*receivers));
204 if (!senders || !receivers) {
215#define SPAWN_THREADS(type) do { \
216 for (i = 0; i < nb_##type##s; i++) { \
217 struct type##_data *td = &type##s[i]; \
221 td->workload = get_workload(type##_min_load, type##_max_load); \
223 ret = pthread_create(&td->tid, NULL, type##_thread, td); \
225 const int err = AVERROR(ret); \
226 av_log(NULL, AV_LOG_ERROR, "Unable to start " AV_STRINGIFY(type) \
227 " thread: %s\n", av_err2str(err)); \
233#define WAIT_THREADS(type) do { \
234 for (i = 0; i < nb_##type##s; i++) { \
235 struct type##_data *td = &type##s[i]; \
237 ret = pthread_join(td->tid, NULL); \
239 const int err = AVERROR(ret); \
240 av_log(NULL, AV_LOG_ERROR, "Unable to join " AV_STRINGIFY(type) \
241 " thread: %s\n", av_err2str(err)); \
static double val(void *priv, double ch)
#define SPAWN_THREADS(type)
static void free_frame(void *arg)
static int get_workload(int minv, int maxv)
static void * sender_thread(void *arg)
static void * receiver_thread(void *arg)
#define WAIT_THREADS(type)
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
char * av_asprintf(const char *fmt,...)
#define i(width, name, range_min, range_max)
reference-counted frame API
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that's been allocated with av_malloc() or another memory allocation functio...
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
#define AVERROR_EOF
End of file.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
This structure describes decoded (raw) audio or video data.
AVDictionary * metadata
metadata.
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
AVThreadMessageQueue * queue
AVThreadMessageQueue * queue
void av_thread_message_queue_set_err_send(AVThreadMessageQueue *mq, int err)
Set the sending error code.
int av_thread_message_queue_recv(AVThreadMessageQueue *mq, void *msg, unsigned flags)
Receive a message from the queue.
int av_thread_message_queue_alloc(AVThreadMessageQueue **mq, unsigned nelem, unsigned elsize)
Allocate a new message queue.
void av_thread_message_queue_set_free_func(AVThreadMessageQueue *mq, void(*free_func)(void *msg))
Set the optional free message callback function which will be called if an operation is removing mess...
void av_thread_message_queue_set_err_recv(AVThreadMessageQueue *mq, int err)
Set the receiving error code.
int av_thread_message_queue_nb_elems(AVThreadMessageQueue *mq)
Return the current number of messages in the queue.
int av_thread_message_queue_send(AVThreadMessageQueue *mq, void *msg, unsigned flags)
Send a message on the queue.
void av_thread_message_flush(AVThreadMessageQueue *mq)
Flush the message queue.
void av_thread_message_queue_free(AVThreadMessageQueue **mq)
Free a message queue.
static void free_frame(void *opaque, uint8_t *data)