FFmpeg: fftools/thread_queue.c Source File
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 #include <stdint.h>
20 #include <string.h>
21
30
32
34
35 enum {
38 };
39
44
46
49
52 };
53
55 {
57
58 if (!tq)
59 return;
60
63
65
68
70 }
71
74 {
77
79 if (!tq)
81
86 }
87
93 }
94
99
101
106
110
111 return tq;
115 }
116
118 {
119 int *finished;
121
123 finished = &tq->
finished[stream_idx];
124
126
130 }
131
134
138 } else {
142
146
148 }
149
152
154 }
155
158 {
159 unsigned int nb_finished = 0;
160
163
165 unsigned idx;
167
173 continue;
174 }
175
176 *stream_idx = idx;
177 return 0;
178 }
179
182 continue;
183
184 /* return EOF to the consumer at most once for each stream */
189 }
190
191 nb_finished++;
192 }
193
195 }
196
198 {
200
201 *stream_idx = -1;
202
204
205 while (1) {
207
209
210 // signal other threads if the fifo state changed
213
216 continue;
217 }
218
219 break;
220 }
221
223
225 }
226
228 {
230
232
233 /* mark the stream as send-finished;
234 * next time the consumer thread tries to read this stream it will get
235 * an EOF and recv-finished flag will be set */
239
241 }
242
244 {
246
248
249 /* mark the stream as recv-finished;
250 * next time the producer thread tries to send for this stream, it will
251 * get an EOF and send-finished flag will be set */
254
256 }
257
259 {
261
262 int prev_choked = tq->
choked;
264 if (choked != prev_choked)
266
268 }
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
size_t av_fifo_can_write(const AVFifo *f)
int av_container_fifo_write(AVContainerFifo *cf, void *obj, unsigned flags)
Write the contents of obj to the FIFO.
Filter the word "frame" indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
AVContainerFifo * av_container_fifo_alloc_avframe(unsigned flags)
Allocate an AVContainerFifo instance for AVFrames.
#define AVERROR_EOF
End of file.
static av_always_inline int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
static av_always_inline int pthread_mutex_lock(pthread_mutex_t *mutex)
ThreadQueue * tq_alloc(unsigned int nb_streams, size_t queue_size, enum ThreadQueueType type)
Allocate a queue for sending data between threads.
int av_fifo_write(AVFifo *f, const void *buf, size_t nb_elems)
Write data into a FIFO.
enum ThreadQueueType type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
int av_fifo_read(AVFifo *f, void *buf, size_t nb_elems)
Read data from a FIFO.
static av_always_inline int pthread_mutex_unlock(pthread_mutex_t *mutex)
static int receive_locked(ThreadQueue *tq, int *stream_idx, void *data)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int av_container_fifo_read(AVContainerFifo *cf, void *obj, unsigned flags)
Read the next available object from the FIFO into obj.
AVContainerFifo is a FIFO for "containers" - dynamically allocated reusable structs (e....
static av_always_inline int pthread_cond_broadcast(pthread_cond_t *cond)
void tq_free(ThreadQueue **ptq)
void tq_receive_finish(ThreadQueue *tq, unsigned int stream_idx)
Mark the given stream finished from the receiving side.
AVFifo * fifo_stream_index
int tq_send(ThreadQueue *tq, unsigned int stream_idx, void *data)
Send an item for the given stream to the queue.
static av_always_inline int pthread_cond_destroy(pthread_cond_t *cond)
static av_always_inline int pthread_mutex_destroy(pthread_mutex_t *mutex)
#define i(width, name, range_min, range_max)
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
int tq_receive(ThreadQueue *tq, int *stream_idx, void *data)
Read the next item from the queue.
void * av_calloc(size_t nmemb, size_t size)
void av_container_fifo_free(AVContainerFifo **pcf)
Free a AVContainerFifo and everything in it.
AVFifo * av_fifo_alloc2(size_t nb_elems, size_t elem_size, unsigned int flags)
Allocate and initialize an AVFifo with a given element size.
size_t av_container_fifo_can_read(const AVContainerFifo *cf)
static av_always_inline int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
void av_fifo_freep2(AVFifo **f)
Free an AVFifo and reset pointer to NULL.
static av_always_inline int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
void tq_choke(ThreadQueue *tq, int choked)
Prevent further reads from the thread queue until it is unchoked.
AVContainerFifo * av_container_fifo_alloc_avpacket(unsigned flags)
Allocate an AVContainerFifo instance for AVPacket.
void tq_send_finish(ThreadQueue *tq, unsigned int stream_idx)
Mark the given stream finished from the sending side.
Generated on Sat Oct 18 2025 19:21:46 for FFmpeg by
doxygen
1.8.17