FFmpeg
Data Structures | Macros | Functions
sync_queue.c File Reference
#include <stdint.h>
#include <string.h>
#include "libavutil/avassert.h"
#include "libavutil/container_fifo.h"
#include "libavutil/channel_layout.h"
#include "libavutil/cpu.h"
#include "libavutil/error.h"
#include "libavutil/mathematics.h"
#include "libavutil/mem.h"
#include "libavutil/samplefmt.h"
#include "libavutil/timestamp.h"
#include "sync_queue.h"

Go to the source code of this file.

Data Structures

struct  SyncQueueStream
 
struct  SyncQueue
 A sync queue provides timestamp synchronization between multiple streams. More...
 

Macros

#define SQPTR(sq, frame)
 

Functions

static int64_t frame_end (const SyncQueue *sq, SyncQueueFrame frame, int nb_samples)
 Compute the end timestamp of a frame. More...
 
static int frame_samples (const SyncQueue *sq, SyncQueueFrame frame)
 
static int frame_null (const SyncQueue *sq, SyncQueueFrame frame)
 
static void tb_update (const SyncQueue *sq, SyncQueueStream *st, const SyncQueueFrame frame)
 
static void finish_stream (SyncQueue *sq, unsigned int stream_idx)
 
static void queue_head_update (SyncQueue *sq)
 
static void stream_update_ts (SyncQueue *sq, unsigned int stream_idx, int64_t ts)
 
static int overflow_heartbeat (SyncQueue *sq, int stream_idx)
 
int sq_send (SyncQueue *sq, unsigned int stream_idx, SyncQueueFrame frame)
 Submit a frame for the stream with index stream_idx. More...
 
static void offset_audio (AVFrame *f, int nb_samples)
 
static int frame_is_aligned (const SyncQueue *sq, const AVFrame *frame)
 
static int receive_samples (SyncQueue *sq, SyncQueueStream *st, AVFrame *dst, int nb_samples)
 
static int receive_for_stream (SyncQueue *sq, unsigned int stream_idx, SyncQueueFrame frame)
 
static int receive_internal (SyncQueue *sq, int stream_idx, SyncQueueFrame frame)
 
int sq_receive (SyncQueue *sq, int stream_idx, SyncQueueFrame frame)
 Read a frame from the queue. More...
 
int sq_add_stream (SyncQueue *sq, int limiting)
 Add a new stream to the sync queue. More...
 
void sq_limit_frames (SyncQueue *sq, unsigned int stream_idx, uint64_t frames)
 Limit the number of output frames for stream with index stream_idx to max_frames. More...
 
void sq_frame_samples (SyncQueue *sq, unsigned int stream_idx, int frame_samples)
 Set a constant output audio frame size, in samples. More...
 
SyncQueuesq_alloc (enum SyncQueueType type, int64_t buf_size_us, void *logctx)
 Allocate a sync queue of the given type. More...
 
void sq_free (SyncQueue **psq)
 

Macro Definition Documentation

◆ SQPTR

#define SQPTR (   sq,
  frame 
)
Value:
((sq->type == SYNC_QUEUE_FRAMES) ? \
(void*)frame.f : (void*)frame.p)

Definition at line 69 of file sync_queue.c.

Function Documentation

◆ frame_end()

static int64_t frame_end ( const SyncQueue sq,
SyncQueueFrame  frame,
int  nb_samples 
)
static

Compute the end timestamp of a frame.

If nb_samples is provided, consider the frame to have this number of audio samples, otherwise use frame duration.

Definition at line 118 of file sync_queue.c.

Referenced by bethsoftvid_decode_frame(), bfi_decode_frame(), decode_bmv_frame(), decode_dds1(), decode_dsw1(), decode_tdlt(), decode_tsw1(), decode_wdlt(), ff_h263_decode_frame(), get_duration(), overflow_heartbeat(), receive_for_stream(), sq_send(), and write_subframes().

◆ frame_samples()

static int frame_samples ( const SyncQueue sq,
SyncQueueFrame  frame 
)
static

◆ frame_null()

static int frame_null ( const SyncQueue sq,
SyncQueueFrame  frame 
)
static

Definition at line 136 of file sync_queue.c.

Referenced by sq_send().

◆ tb_update()

static void tb_update ( const SyncQueue sq,
SyncQueueStream st,
const SyncQueueFrame  frame 
)
static

Definition at line 141 of file sync_queue.c.

Referenced by sq_send().

◆ finish_stream()

static void finish_stream ( SyncQueue sq,
unsigned int  stream_idx 
)
static

Definition at line 161 of file sync_queue.c.

Referenced by sq_limit_frames(), sq_send(), and stream_update_ts().

◆ queue_head_update()

static void queue_head_update ( SyncQueue sq)
static

Definition at line 208 of file sync_queue.c.

Referenced by stream_update_ts().

◆ stream_update_ts()

static void stream_update_ts ( SyncQueue sq,
unsigned int  stream_idx,
int64_t  ts 
)
static

Definition at line 243 of file sync_queue.c.

Referenced by overflow_heartbeat(), and sq_send().

◆ overflow_heartbeat()

static int overflow_heartbeat ( SyncQueue sq,
int  stream_idx 
)
static

Definition at line 272 of file sync_queue.c.

Referenced by sq_receive().

◆ sq_send()

int sq_send ( SyncQueue sq,
unsigned int  stream_idx,
SyncQueueFrame  frame 
)

Submit a frame for the stream with index stream_idx.

On success, the sync queue takes ownership of the frame and will reset the contents of the supplied frame. On failure, the frame remains owned by the caller.

Sending a frame with NULL contents marks the stream as finished.

Returns
  • 0 on success
  • AVERROR_EOF when no more frames should be submitted for this stream
  • another a negative error code on failure

Definition at line 333 of file sync_queue.c.

Referenced by send_to_enc_sq(), and sync_queue_process().

◆ offset_audio()

static void offset_audio ( AVFrame f,
int  nb_samples 
)
static

Definition at line 389 of file sync_queue.c.

Referenced by receive_samples().

◆ frame_is_aligned()

static int frame_is_aligned ( const SyncQueue sq,
const AVFrame frame 
)
static

Definition at line 412 of file sync_queue.c.

Referenced by receive_for_stream(), and receive_samples().

◆ receive_samples()

static int receive_samples ( SyncQueue sq,
SyncQueueStream st,
AVFrame dst,
int  nb_samples 
)
static

Definition at line 428 of file sync_queue.c.

Referenced by receive_for_stream().

◆ receive_for_stream()

static int receive_for_stream ( SyncQueue sq,
unsigned int  stream_idx,
SyncQueueFrame  frame 
)
static

Definition at line 502 of file sync_queue.c.

Referenced by receive_internal().

◆ receive_internal()

static int receive_internal ( SyncQueue sq,
int  stream_idx,
SyncQueueFrame  frame 
)
static

Definition at line 562 of file sync_queue.c.

Referenced by sq_receive().

◆ sq_receive()

int sq_receive ( SyncQueue sq,
int  stream_idx,
SyncQueueFrame  frame 
)

Read a frame from the queue.

Parameters
stream_idxindex of the stream to read a frame for. May be -1, then try to read a frame from any stream that is ready for output.
frameoutput frame will be written here on success. The frame is owned by the caller.
Returns
  • a non-negative index of the stream to which the returned frame belongs
  • AVERROR(EAGAIN) when more frames need to be submitted to the queue
  • AVERROR_EOF when no more frames will be available for this stream (for any stream if stream_idx is -1)
  • another negative error code on failure

Definition at line 586 of file sync_queue.c.

Referenced by send_to_enc_sq(), and sync_queue_process().

◆ sq_add_stream()

int sq_add_stream ( SyncQueue sq,
int  limiting 
)

Add a new stream to the sync queue.

Parameters
limitingwhether the stream is limiting, i.e. no other stream can be longer than this one
Returns
  • a non-negative stream index on success
  • a negative error code on error

Definition at line 598 of file sync_queue.c.

Referenced by sch_sq_add_enc(), and setup_sync_queues().

◆ sq_limit_frames()

void sq_limit_frames ( SyncQueue sq,
unsigned int  stream_idx,
uint64_t  frames 
)

Limit the number of output frames for stream with index stream_idx to max_frames.

Definition at line 628 of file sync_queue.c.

Referenced by sch_sq_add_enc(), and setup_sync_queues().

◆ sq_frame_samples()

void sq_frame_samples ( SyncQueue sq,
unsigned int  stream_idx,
int  frame_samples 
)

Set a constant output audio frame size, in samples.

Can only be used with SYNC_QUEUE_FRAMES queues and audio streams.

All output frames will have exactly frame_samples audio samples, except possibly for the last one, which may have fewer.

Definition at line 640 of file sync_queue.c.

Referenced by enc_open().

◆ sq_alloc()

SyncQueue* sq_alloc ( enum SyncQueueType  type,
int64_t  buf_size_us,
void *  logctx 
)

Allocate a sync queue of the given type.

Parameters
buf_size_usmaximum duration that will be buffered in microseconds

Definition at line 654 of file sync_queue.c.

Referenced by sch_add_sq_enc(), and setup_sync_queues().

◆ sq_free()

void sq_free ( SyncQueue **  psq)

Definition at line 671 of file sync_queue.c.

Referenced by of_free(), and sch_free().

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
SYNC_QUEUE_FRAMES
@ SYNC_QUEUE_FRAMES
Definition: sync_queue.h:30