2 * This file is part of FFmpeg.
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #ifndef FFTOOLS_THREAD_QUEUE_H
20 #define FFTOOLS_THREAD_QUEUE_H
24 enum ThreadQueueType
{
29 typedef struct ThreadQueue ThreadQueue
;
32 * Allocate a queue for sending data between threads.
34 * @param nb_streams number of streams for which a distinct EOF state is
36 * @param queue_size number of items that can be stored in the queue without
39 ThreadQueue
*tq_alloc(unsigned int nb_streams
, size_t queue_size
,
40 enum ThreadQueueType type
);
41 void tq_free(ThreadQueue
**tq
);
44 * Send an item for the given stream to the queue.
46 * @param data the item to send, its contents will be moved using the callback
47 * provided to tq_alloc(); on failure the item will be left
50 * - 0 the item was successfully sent
51 * - AVERROR(ENOMEM) could not allocate an item for writing to the FIFO
52 * - AVERROR(EINVAL) the sending side has previously been marked as finished
53 * - AVERROR_EOF the receiving side has marked the given stream as finished
55 int tq_send(ThreadQueue
*tq
, unsigned int stream_idx
, void *data
);
57 * Mark the given stream finished from the sending side.
59 void tq_send_finish(ThreadQueue
*tq
, unsigned int stream_idx
);
62 * Prevent further reads from the thread queue until it is unchoked. Threads
63 * attempting to read from the queue will block, similar to when the queue is
66 * @param choked 1 to choke, 0 to unchoke
68 void tq_choke(ThreadQueue
*tq
, int choked
);
71 * Read the next item from the queue.
73 * @param stream_idx the index of the stream that was processed or -1 will be
75 * @param data the data item will be written here on success using the
76 * callback provided to tq_alloc()
78 * - 0 a data item was successfully read; *stream_idx contains a non-negative
80 * - AVERROR_EOF When *stream_idx is non-negative, this signals that the sending
81 * side has marked the given stream as finished. This will happen at most once
82 * for each stream. When *stream_idx is -1, all streams are done.
84 int tq_receive(ThreadQueue
*tq
, int *stream_idx
, void *data
);
86 * Mark the given stream finished from the receiving side.
88 void tq_receive_finish(ThreadQueue
*tq
, unsigned int stream_idx
);
90 #endif // FFTOOLS_THREAD_QUEUE_H