FFmpeg
sync_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_SYNC_QUEUE_H
20 #define FFTOOLS_SYNC_QUEUE_H
21 
22 #include <stdint.h>
23 
24 #include "libavcodec/packet.h"
25 
26 #include "libavutil/frame.h"
27 
31 };
32 
33 typedef union SyncQueueFrame {
37 
38 #define SQFRAME(frame) ((SyncQueueFrame){ .f = (frame) })
39 #define SQPKT(pkt) ((SyncQueueFrame){ .p = (pkt) })
40 
41 typedef struct SyncQueue SyncQueue;
42 
43 /**
44  * Allocate a sync queue of the given type.
45  *
46  * @param buf_size_us maximum duration that will be buffered in microseconds
47  */
49 void sq_free(SyncQueue **sq);
50 
51 /**
52  * Add a new stream to the sync queue.
53  *
54  * @param limiting whether the stream is limiting, i.e. no other stream can be
55  * longer than this one
56  * @return
57  * - a non-negative stream index on success
58  * - a negative error code on error
59  */
60 int sq_add_stream(SyncQueue *sq, int limiting);
61 
62 /**
63  * Set the timebase for the stream with index stream_idx. Should be called
64  * before sending any frames for this stream.
65  */
66 void sq_set_tb(SyncQueue *sq, unsigned int stream_idx, AVRational tb);
67 
68 /**
69  * Limit the number of output frames for stream with index stream_idx
70  * to max_frames.
71  */
72 void sq_limit_frames(SyncQueue *sq, unsigned int stream_idx,
73  uint64_t max_frames);
74 
75 /**
76  * Submit a frame for the stream with index stream_idx.
77  *
78  * On success, the sync queue takes ownership of the frame and will reset the
79  * contents of the supplied frame. On failure, the frame remains owned by the
80  * caller.
81  *
82  * Sending a frame with NULL contents marks the stream as finished.
83  *
84  * @return
85  * - 0 on success
86  * - AVERROR_EOF when no more frames should be submitted for this stream
87  * - another a negative error code on failure
88  */
89 int sq_send(SyncQueue *sq, unsigned int stream_idx, SyncQueueFrame frame);
90 
91 /**
92  * Read a frame from the queue.
93  *
94  * @param stream_idx index of the stream to read a frame for. May be -1, then
95  * try to read a frame from any stream that is ready for
96  * output.
97  * @param frame output frame will be written here on success. The frame is owned
98  * by the caller.
99  *
100  * @return
101  * - a non-negative index of the stream to which the returned frame belongs
102  * - AVERROR(EAGAIN) when more frames need to be submitted to the queue
103  * - AVERROR_EOF when no more frames will be available for this stream (for any
104  * stream if stream_idx is -1)
105  * - another negative error code on failure
106  */
107 int sq_receive(SyncQueue *sq, int stream_idx, SyncQueueFrame frame);
108 
109 #endif // FFTOOLS_SYNC_QUEUE_H
SYNC_QUEUE_PACKETS
@ SYNC_QUEUE_PACKETS
Definition: sync_queue.h:29
SyncQueueFrame::f
AVFrame * f
Definition: sync_queue.h:34
SyncQueueType
SyncQueueType
Definition: sync_queue.h:28
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:325
SyncQueueFrame::p
AVPacket * p
Definition: sync_queue.h:35
sq_add_stream
int sq_add_stream(SyncQueue *sq, int limiting)
Add a new stream to the sync queue.
Definition: sync_queue.c:351
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
Definition: writing_filters.txt:86
SyncQueueFrame
Definition: sync_queue.h:33
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
sq_limit_frames
void sq_limit_frames(SyncQueue *sq, unsigned int stream_idx, uint64_t max_frames)
Limit the number of output frames for stream with index stream_idx to max_frames.
Definition: sync_queue.c:393
frame.h
sq_receive
int sq_receive(SyncQueue *sq, int stream_idx, SyncQueueFrame frame)
Read a frame from the queue.
Definition: sync_queue.c:339
packet.h
SyncQueue::buf_size_us
int64_t buf_size_us
Definition: sync_queue.c:57
tb
#define tb
Definition: regdef.h:68
sq_alloc
SyncQueue * sq_alloc(enum SyncQueueType type, int64_t buf_size_us)
Allocate a sync queue of the given type.
Definition: sync_queue.c:405
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
sq_set_tb
void sq_set_tb(SyncQueue *sq, unsigned int stream_idx, AVRational tb)
Set the timebase for the stream with index stream_idx.
Definition: sync_queue.c:378
SyncQueue
Definition: sync_queue.c:45
AVPacket
This structure stores compressed data.
Definition: packet.h:351
sq_free
void sq_free(SyncQueue **sq)
Definition: sync_queue.c:428
SYNC_QUEUE_FRAMES
@ SYNC_QUEUE_FRAMES
Definition: sync_queue.h:30
sq_send
int sq_send(SyncQueue *sq, unsigned int stream_idx, SyncQueueFrame frame)
Submit a frame for the stream with index stream_idx.
Definition: sync_queue.c:234