MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / worker

Function worker

libavcodec/frame_thread_encoder.c:78–118  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

76#undef OFF
77
78static void * attribute_align_arg worker(void *v){
79 AVCodecContext *avctx = v;
80 ThreadContext *c = avctx->internal->frame_thread_encoder;
81
82 while (!atomic_load(&c->exit)) {
83 int ret;
84 AVPacket *pkt;
85 AVFrame *frame;
86 Task *task;
87 unsigned task_index;
88
89 pthread_mutex_lock(&c->task_fifo_mutex);
90 while (c->next_task_index == c->task_index || atomic_load(&c->exit)) {
91 if (atomic_load(&c->exit)) {
92 pthread_mutex_unlock(&c->task_fifo_mutex);
93 goto end;
94 }
95 pthread_cond_wait(&c->task_fifo_cond, &c->task_fifo_mutex);
96 }
97 task_index = c->next_task_index;
98 c->next_task_index = (c->next_task_index + 1) % c->max_tasks;
99 pthread_mutex_unlock(&c->task_fifo_mutex);
100 /* The main thread ensures that any two outstanding tasks have
101 * different indices, ergo each worker thread owns its element
102 * of c->tasks with the exception of finished, which is shared
103 * with the main thread and guarded by finished_task_mutex. */
104 task = &c->tasks[task_index];
105 frame = task->indata;
106 pkt = task->outdata;
107
108 ret = ff_encode_encode_cb(avctx, pkt, frame, &task->got_packet);
109 pthread_mutex_lock(&c->finished_task_mutex);
110 task->return_code = ret;
111 task->finished = 1;
112 pthread_cond_signal(&c->finished_task_cond);
113 pthread_mutex_unlock(&c->finished_task_mutex);
114 }
115end:
116 avcodec_free_context(&avctx);
117 return NULL;
118}
119
120av_cold int ff_frame_thread_encoder_init(AVCodecContext *avctx)
121{

Callers

nothing calls this directly

Calls 6

ff_encode_encode_cbFunction · 0.85
avcodec_free_contextFunction · 0.85
pthread_mutex_lockFunction · 0.50
pthread_mutex_unlockFunction · 0.50
pthread_cond_waitFunction · 0.50
pthread_cond_signalFunction · 0.50

Tested by

no test coverage detected