FFmpeg
Loading...
Searching...
No Matches
thread_queue.h
Go to the documentation of this file.
1/*
2 * This file is part of FFmpeg.
3 *
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.
8 *
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.
13 *
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
17 */
18
19#ifndef FFTOOLS_THREAD_QUEUE_H
20#define FFTOOLS_THREAD_QUEUE_H
21
22#include <string.h>
23
28
30 /* When set, tq_receive() will return AVERROR(EAGAIN) instead of blocking
31 * when the queue is empty or choked. */
33};
34
35typedef struct ThreadQueue ThreadQueue;
36
37/**
38 * Allocate a queue for sending data between threads.
39 *
40 * @param nb_streams number of streams for which a distinct EOF state is
41 * maintained
42 * @param queue_size number of items that can be stored in the queue without
43 * blocking
44 */
45ThreadQueue *tq_alloc(unsigned int nb_streams, size_t queue_size,
47void tq_free(ThreadQueue **tq);
48
49/**
50 * Send an item for the given stream to the queue.
51 *
52 * @param data the item to send, its contents will be moved using the callback
53 * provided to tq_alloc(); on failure the item will be left
54 * untouched
55 * @return
56 * - 0 the item was successfully sent
57 * - AVERROR(ENOMEM) could not allocate an item for writing to the FIFO
58 * - AVERROR(EINVAL) the sending side has previously been marked as finished
59 * - AVERROR_EOF the receiving side has marked the given stream as finished
60 */
61int tq_send(ThreadQueue *tq, unsigned int stream_idx, void *data);
62/**
63 * Mark the given stream finished from the sending side.
64 */
65void tq_send_finish(ThreadQueue *tq, unsigned int stream_idx);
66
67/**
68 * Prevent further reads from the thread queue until it is unchoked. Threads
69 * attempting to read from the queue will block, similar to when the queue is
70 * empty.
71 *
72 * @param choked 1 to choke, 0 to unchoke
73 */
74void tq_choke(ThreadQueue *tq, int choked);
75
76/**
77 * Read the next item from the queue.
78 *
79 * @param stream_idx the index of the stream that was processed or -1 will be
80 * written here
81 * @param data the data item will be written here on success using the
82 * callback provided to tq_alloc()
83 * @param flags combination of THREAD_QUEUE_FLAG_*
84 *
85 * @return
86 * - 0 a data item was successfully read; *stream_idx contains a non-negative
87 * stream index
88 * - AVERROR_EOF When *stream_idx is non-negative, this signals that the sending
89 * side has marked the given stream as finished. This will happen at most once
90 * for each stream. When *stream_idx is -1, all streams are done.
91 */
92int tq_receive(ThreadQueue *tq, int *stream_idx, void *data, int flags);
93
94/**
95 * Mark the given stream finished from the receiving side.
96 */
97void tq_receive_finish(ThreadQueue *tq, unsigned int stream_idx);
98
99#endif // FFTOOLS_THREAD_QUEUE_H
#define flags(name, subs,...)
Definition cbs_h264.c:74
static unsigned int nb_streams
Definition ffprobe.c:352
cl_device_type type
const char data[16]
Definition mxf.c:149
ThreadQueue * tq_alloc(unsigned int nb_streams, size_t queue_size, enum ThreadQueueType type)
Allocate a queue for sending data between threads.
void tq_send_finish(ThreadQueue *tq, unsigned int stream_idx)
Mark the given stream finished from the sending side.
int tq_send(ThreadQueue *tq, unsigned int stream_idx, void *data)
Send an item for the given stream to the queue.
ThreadQueueType
@ THREAD_QUEUE_FRAMES
@ THREAD_QUEUE_PACKETS
ThreadQueueFlags
@ THREAD_QUEUE_FLAG_NO_BLOCK
void tq_choke(ThreadQueue *tq, int choked)
Prevent further reads from the thread queue until it is unchoked.
int tq_receive(ThreadQueue *tq, int *stream_idx, void *data, int flags)
Read the next item from the queue.
void tq_free(ThreadQueue **tq)
void tq_receive_finish(ThreadQueue *tq, unsigned int stream_idx)
Mark the given stream finished from the receiving side.