Lines Matching defs:avctx
78 AVCodecContext *avctx = v;
79 ThreadContext *c = avctx->internal->frame_thread_encoder;
107 ret = ffcodec(avctx->codec)->cb.encode(avctx, pkt, frame, &got_packet);
128 avcodec_close(avctx);
130 av_freep(&avctx);
134 av_cold int ff_frame_thread_encoder_init(AVCodecContext *avctx)
141 if( !(avctx->thread_type & FF_THREAD_FRAME)
142 || !(avctx->codec->capabilities & AV_CODEC_CAP_FRAME_THREADS))
145 if( !avctx->thread_count
146 && avctx->codec_id == AV_CODEC_ID_MJPEG
147 && !(avctx->flags & AV_CODEC_FLAG_QSCALE)) {
148 av_log(avctx, AV_LOG_DEBUG,
151 avctx->thread_count = 1;
153 if( avctx->thread_count > 1
154 && avctx->codec_id == AV_CODEC_ID_MJPEG
155 && !(avctx->flags & AV_CODEC_FLAG_QSCALE))
156 av_log(avctx, AV_LOG_WARNING,
160 if (avctx->codec_id == AV_CODEC_ID_HUFFYUV ||
161 avctx->codec_id == AV_CODEC_ID_FFVHUFF) {
165 if (avctx->flags & AV_CODEC_FLAG_PASS1)
167 else if (av_opt_get_int(avctx->priv_data, "context", 0, &tmp) >= 0 &&
169 warn = av_opt_get_int(avctx->priv_data, "non_deterministic", 0, &tmp) < 0
174 av_log(avctx, AV_LOG_WARNING,
176 avctx->thread_count = 1;
180 if(!avctx->thread_count) {
181 avctx->thread_count = av_cpu_count();
182 avctx->thread_count = FFMIN(avctx->thread_count, MAX_THREADS);
185 if(avctx->thread_count <= 1)
188 if(avctx->thread_count > MAX_THREADS)
191 av_assert0(!avctx->internal->frame_thread_encoder);
192 c = avctx->internal->frame_thread_encoder = av_mallocz(sizeof(ThreadContext));
196 c->parent_avctx = avctx;
203 c->max_tasks = avctx->thread_count + 2;
212 for(i=0; i<avctx->thread_count ; i++){
214 thread_avctx = avcodec_alloc_context3(avctx->codec);
220 *thread_avctx = *avctx;
224 ret = av_opt_copy(thread_avctx, avctx);
227 if (avctx->codec->priv_class) {
228 ret = av_opt_copy(thread_avctx->priv_data, avctx->priv_data);
235 if ((ret = avcodec_open2(thread_avctx, avctx->codec, NULL)) < 0)
245 avctx->active_thread_type = FF_THREAD_FRAME;
251 avctx->thread_count = i;
252 av_log(avctx, AV_LOG_ERROR, "ff_frame_thread_encoder_init failed\n");
253 ff_frame_thread_encoder_free(avctx);
257 av_cold void ff_frame_thread_encoder_free(AVCodecContext *avctx)
259 ThreadContext *c= avctx->internal->frame_thread_encoder;
264 if (avctx->thread_count > 0) {
270 for (int i = 0; i < avctx->thread_count; i++)
280 av_freep(&avctx->internal->frame_thread_encoder);
283 int ff_thread_video_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
286 ThreadContext *c = avctx->internal->frame_thread_encoder;
306 (c->task_index - c->finished_task_index + c->max_tasks) % c->max_tasks <= avctx->thread_count)) {