FFmpeg
Data Structures | Functions
threadmessage.c File Reference
#include <limits.h>
#include <stddef.h>
#include "error.h"
#include "fifo.h"
#include "mem.h"
#include "threadmessage.h"
#include "thread.h"

Go to the source code of this file.

Data Structures

struct  AVThreadMessageQueue
 

Functions

int av_thread_message_queue_alloc (AVThreadMessageQueue **mq, unsigned nelem, unsigned elsize)
 Allocate a new message queue. More...
 
void av_thread_message_queue_set_free_func (AVThreadMessageQueue *mq, void(*free_func)(void *msg))
 Set the optional free message callback function which will be called if an operation is removing messages from the queue. More...
 
void av_thread_message_queue_free (AVThreadMessageQueue **mq)
 Free a message queue. More...
 
int av_thread_message_queue_nb_elems (AVThreadMessageQueue *mq)
 Return the current number of messages in the queue. More...
 
int av_thread_message_queue_send (AVThreadMessageQueue *mq, void *msg, unsigned flags)
 Send a message on the queue. More...
 
int av_thread_message_queue_recv (AVThreadMessageQueue *mq, void *msg, unsigned flags)
 Receive a message from the queue. More...
 
void av_thread_message_queue_set_err_send (AVThreadMessageQueue *mq, int err)
 Set the sending error code. More...
 
void av_thread_message_queue_set_err_recv (AVThreadMessageQueue *mq, int err)
 Set the receiving error code. More...
 
void av_thread_message_flush (AVThreadMessageQueue *mq)
 Flush the message queue. More...
 

Function Documentation

◆ av_thread_message_queue_alloc()

int av_thread_message_queue_alloc ( AVThreadMessageQueue **  mq,
unsigned  nelem,
unsigned  elsize 
)

Allocate a new message queue.

Parameters
mqpointer to the message queue
nelemmaximum number of elements in the queue
elsizesize of each element in the queue
Returns
>=0 for success; <0 for error, in particular AVERROR(ENOSYS) if lavu was built without thread support

Definition at line 45 of file threadmessage.c.

Referenced by android_camera_read_header(), fifo_init(), main(), and sch_add_dec().

◆ av_thread_message_queue_set_free_func()

void av_thread_message_queue_set_free_func ( AVThreadMessageQueue mq,
void(*)(void *msg)  free_func 
)

Set the optional free message callback function which will be called if an operation is removing messages from the queue.

Definition at line 88 of file threadmessage.c.

Referenced by fifo_init(), and main().

◆ av_thread_message_queue_free()

void av_thread_message_queue_free ( AVThreadMessageQueue **  mq)

Free a message queue.

The message queue must no longer be in use by another thread.

Definition at line 96 of file threadmessage.c.

Referenced by android_camera_read_close(), fifo_deinit(), main(), and sch_free().

◆ av_thread_message_queue_nb_elems()

int av_thread_message_queue_nb_elems ( AVThreadMessageQueue mq)

Return the current number of messages in the queue.

Returns
the current number of messages or AVERROR(ENOSYS) if lavu was built without thread support

Definition at line 110 of file threadmessage.c.

Referenced by receiver_thread().

◆ av_thread_message_queue_send()

int av_thread_message_queue_send ( AVThreadMessageQueue mq,
void *  msg,
unsigned  flags 
)

Send a message on the queue.

Definition at line 161 of file threadmessage.c.

Referenced by fifo_write_packet(), fifo_write_trailer(), image_available(), sch_dec_receive(), and sender_thread().

◆ av_thread_message_queue_recv()

int av_thread_message_queue_recv ( AVThreadMessageQueue mq,
void *  msg,
unsigned  flags 
)

Receive a message from the queue.

Definition at line 177 of file threadmessage.c.

Referenced by android_camera_read_close(), android_camera_read_packet(), demux_flush(), fifo_consumer_thread(), and receiver_thread().

◆ av_thread_message_queue_set_err_send()

void av_thread_message_queue_set_err_send ( AVThreadMessageQueue mq,
int  err 
)

Set the sending error code.

If the error code is set to non-zero, av_thread_message_queue_send() will return it immediately. Conventional values, such as AVERROR_EOF or AVERROR(EAGAIN), can be used to cause the sending thread to stop or suspend its operation.

Definition at line 193 of file threadmessage.c.

Referenced by android_camera_read_close(), fifo_consumer_thread(), and receiver_thread().

◆ av_thread_message_queue_set_err_recv()

void av_thread_message_queue_set_err_recv ( AVThreadMessageQueue mq,
int  err 
)

Set the receiving error code.

If the error code is set to non-zero, av_thread_message_queue_recv() will return it immediately when there are no longer available messages. Conventional values, such as AVERROR_EOF or AVERROR(EAGAIN), can be used to cause the receiving thread to stop or suspend its operation.

Definition at line 204 of file threadmessage.c.

Referenced by dec_done(), fifo_write_trailer(), image_available(), and sender_thread().

◆ av_thread_message_flush()

void av_thread_message_flush ( AVThreadMessageQueue mq)

Flush the message queue.

This function is mostly equivalent to reading and free-ing every message except that it will be done in a single operation (no lock/unlock between reads).

Definition at line 226 of file threadmessage.c.

Referenced by av_thread_message_queue_free(), fifo_consumer_thread(), receiver_thread(), and sender_thread().