mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2026-06-11 08:13:06 +00:00
fftools/thread_queue: add THREAD_QUEUE_FLAG_NO_BLOCK
Exactly what it says on the tin. There is some ambiguity as to whether this should also prevent reading from *choked*, as opposed to empty queue, but I think it makes sense to consider them equivalent, as I struggle to think of a use case where it would be beneficial to allow draining a queue that was explicitly choked by the upstream (to e.g. prevent further reads). Sponsored-by: nxtedition AB Signed-off-by: Niklas Haas <git@haasn.dev>
This commit is contained in:
committed by
Niklas Haas
co-authored by
Niklas Haas
parent
321b0e36a3
commit
95391352b5
@@ -211,7 +211,7 @@ int tq_receive(ThreadQueue *tq, int *stream_idx, void *data, int flags)
|
||||
if (can_read != av_container_fifo_can_read(tq->fifo))
|
||||
pthread_cond_broadcast(&tq->cond);
|
||||
|
||||
if (ret == AVERROR(EAGAIN)) {
|
||||
if (ret == AVERROR(EAGAIN) && !(flags & THREAD_QUEUE_FLAG_NO_BLOCK)) {
|
||||
pthread_cond_wait(&tq->cond, &tq->lock);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,12 @@ enum ThreadQueueType {
|
||||
THREAD_QUEUE_PACKETS,
|
||||
};
|
||||
|
||||
enum ThreadQueueFlags {
|
||||
/* When set, tq_receive() will return AVERROR(EAGAIN) instead of blocking
|
||||
* when the queue is empty or choked. */
|
||||
THREAD_QUEUE_FLAG_NO_BLOCK = (1 << 0),
|
||||
};
|
||||
|
||||
typedef struct ThreadQueue ThreadQueue;
|
||||
|
||||
/**
|
||||
@@ -74,7 +80,7 @@ void tq_choke(ThreadQueue *tq, int choked);
|
||||
* written here
|
||||
* @param data the data item will be written here on success using the
|
||||
* callback provided to tq_alloc()
|
||||
* @param flags currently unused
|
||||
* @param flags combination of THREAD_QUEUE_FLAG_*
|
||||
*
|
||||
* @return
|
||||
* - 0 a data item was successfully read; *stream_idx contains a non-negative
|
||||
|
||||
Reference in New Issue
Block a user