21 #include <stdatomic.h> 34 #define MAX_THREADS 64 35 #define BUFFER_SIZE (2*MAX_THREADS) 96 if (ret >= 0 && ret2 < 0)
130 "Forcing thread count to 1 for MJPEG encoding, use -thread_type slice " 131 "or a constant quantizer if you want to use multiple cpu cores\n");
138 "MJPEG CBR encoding works badly with frame multi-threading, consider " 139 "using -threads 1, -thread_type slice or a constant quantizer.\n");
144 int context_model = 0;
147 if (con && con->
value)
148 context_model = atoi(con->
value);
152 else if(context_model > 0) {
155 warn = !t || !t->
value || !atoi(t->
value) ? 1 : 0;
160 "Forcing thread count to 1 for huffyuv encoding with first pass or context 1\n");
202 *thread_avctx = *avctx;
const struct AVCodec * codec
int ff_thread_video_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet_ptr)
static av_always_inline int pthread_mutex_destroy(pthread_mutex_t *mutex)
unsigned finished_task_index
This structure describes decoded (raw) audio or video data.
#define pthread_mutex_lock(a)
static av_always_inline int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
#define atomic_store(object, desired)
#define AV_LOG_WARNING
Something somehow does not look correct.
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
AVCodecContext * parent_avctx
static av_always_inline int pthread_cond_destroy(pthread_cond_t *cond)
int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int(*func)(void *, void *, int))
Feed data from a user-supplied callback to an AVFifoBuffer.
#define AV_CODEC_CAP_INTRA_ONLY
Codec is intra only.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
static av_cold int end(AVCodecContext *avctx)
Multithreading support functions.
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
Task finished_tasks[BUFFER_SIZE]
void * frame_thread_encoder
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
static av_always_inline int pthread_cond_signal(pthread_cond_t *cond)
pthread_mutex_t buffer_mutex
int avcodec_close(AVCodecContext *avctx)
Close a given AVCodecContext and free all the data associated with it (but not the AVCodecContext its...
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define AV_DICT_MATCH_CASE
Only get an entry with exact-case key match.
#define atomic_load(object)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int active_thread_type
Which multithreading methods are in use by the codec.
int capabilities
Codec capabilities.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int av_fifo_generic_read(AVFifoBuffer *f, void *dest, int buf_size, void(*func)(void *, void *, int))
Feed data from an AVFifoBuffer to a user-supplied callback.
pthread_cond_t finished_task_cond
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
int flags
AV_CODEC_FLAG_*.
simple assert() macros that are a bit more flexible than ISO C assert().
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
int ff_frame_thread_encoder_init(AVCodecContext *avctx, AVDictionary *options)
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
#define AV_CODEC_FLAG_QSCALE
Use fixed qscale.
#define FF_THREAD_FRAME
Decode more than one frame at once.
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
int av_packet_make_refcounted(AVPacket *pkt)
Ensure the data described by a given packet is reference counted.
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
static av_always_inline int pthread_join(pthread_t thread, void **value_ptr)
static av_always_inline int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
pthread_mutex_t task_fifo_mutex
#define pthread_mutex_unlock(a)
int thread_count
thread count is used to decide how many independent tasks should be passed to execute() ...
#define attribute_align_arg
static av_always_inline int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg)
Libavcodec external API header.
int av_fifo_size(const AVFifoBuffer *f)
Return the amount of data in bytes in the AVFifoBuffer, that is the amount of data you can read from ...
main external API structure.
a very simple circular buffer FIFO implementation
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
pthread_t worker[MAX_THREADS]
attribute_deprecated int avcodec_encode_video2(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Encode a frame of video.
int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
AVFifoBuffer * av_fifo_alloc_array(size_t nmemb, size_t size)
Initialize an AVFifoBuffer.
const AVClass * priv_class
AVClass for the private context.
const OptionDef options[]
common internal api header.
int av_opt_copy(void *dst, const void *src)
Copy options from src object into dest object.
static av_always_inline int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
pthread_mutex_t finished_task_mutex
static av_always_inline int pthread_cond_broadcast(pthread_cond_t *cond)
struct AVCodecInternal * internal
Private context used for internal data.
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
#define atomic_init(obj, value)
void ff_frame_thread_encoder_free(AVCodecContext *avctx)
void av_fifo_freep(AVFifoBuffer **f)
Free an AVFifoBuffer and reset pointer to NULL.
static void *attribute_align_arg worker(void *v)
pthread_cond_t task_fifo_cond
This structure stores compressed data.
int thread_type
Which multithreading methods to use.