ff_thread_init判断对slice并行或者frame并行进行初始化
int ff_thread_init(AVCodecContext *avctx)
71 {
72 validate_thread_parameters(avctx);
73
74 if (avctx->active_thread_type&FF_THREAD_SLICE)
75 return ff_slice_thread_init(avctx);
76 else if (avctx->active_thread_type&FF_THREAD_FRAME)
77 return ff_frame_thread_init(avctx);
78
79 return 0;
80 }
ff_slice_thread_init是帧级并行初始化
int ff_slice_thread_init(AVCodecContext *avctx)
130 {
131 SliceThreadContext *c;
132 int thread_count = avctx->thread_count;
133 static void (*mainfunc)(void *);
134
135 // We cannot do this in the encoder init as the threads are created before
136 if (av_codec_is_encoder(avctx->codec) &&
137 avctx->codec_id == AV_CODEC_ID_MPEG1VIDEO &&
138 avctx->height > 2800)
139 thread_count = avctx->thread_count = 1;
140
141 if (!thread_count) {
142 int nb_cpus = av_cpu_count();
143 if (avctx->height)
144 nb_cpus = FFMIN(nb_cpus, (avctx->height+15)/16);
145 // use number of cores + 1 as thread count if there is more than one
146 if (nb_cpus > 1)
147 thread_count = avctx->thread_count = FFMIN(nb_cpus + 1, MAX_AUTO_THREADS);
148 else
149 thread_count = avctx->thread_count = 1;
150 }
151
152 if (thread_count <= 1) {
153 avctx->active_thread_type = 0;
154 re