Lines Matching defs:avctx

91     AVCodecContext *avctx;          ///< Context used to decode packets passed to this thread.
159 #define THREAD_SAFE_CALLBACKS(avctx) \
160 ((avctx)->thread_safe_callbacks || (avctx)->get_buffer2 == avcodec_default_get_buffer2)
191 AVCodecContext *avctx = p->avctx;
192 const FFCodec *codec = ffcodec(avctx->codec);
204 && THREAD_SAFE_CALLBACKS(avctx)
207 ff_thread_finish_setup(avctx);
220 if (avctx->hwaccel) {
227 p->result = codec->cb.decode(avctx, p->frame, &p->got_frame, p->avpkt);
230 ff_thread_release_buffer(avctx, p->frame);
233 ff_thread_finish_setup(avctx);
239 avctx->hwaccel = NULL;
240 avctx->hwaccel_context = NULL;
241 avctx->internal->hwaccel_priv_data = NULL;
246 av_assert0(!avctx->hwaccel);
410 av_assert0(p->avctx->codec_type == AVMEDIA_TYPE_VIDEO ||
411 p->avctx->codec_type == AVMEDIA_TYPE_AUDIO);
426 const AVCodec *codec = p->avctx->codec;
434 ret = update_context_from_user(p->avctx, user_avctx);
440 (p->avctx->debug & FF_DEBUG_THREADS) != 0,
456 err = update_context_from_thread(p->avctx, prev_thread->avctx, 0);
464 av_assert0(!p->avctx->hwaccel);
465 FFSWAP(const AVHWAccel*, p->avctx->hwaccel, fctx->stash_hwaccel);
466 FFSWAP(void*, p->avctx->hwaccel_context, fctx->stash_hwaccel_context);
467 FFSWAP(void*, p->avctx->internal->hwaccel_priv_data, fctx->stash_hwaccel_priv);
473 av_log(p->avctx, AV_LOG_ERROR, "av_packet_ref() failed in submit_packet()\n");
489 if (!p->avctx->thread_safe_callbacks && (
490 p->avctx->get_format != avcodec_default_get_format ||
491 p->avctx->get_buffer2 != avcodec_default_get_buffer2)) {
500 p->result = ff_get_buffer(p->avctx, p->requested_frame, p->requested_flags);
503 p->result_format = ff_get_format(p->avctx, p->available_formats);
525 int ff_thread_decode_frame(AVCodecContext *avctx,
529 FrameThreadContext *fctx = avctx->internal->thread_ctx;
543 err = submit_packet(p, avctx, avpkt);
551 if (fctx->next_decoding > (avctx->thread_count-1-(avctx->codec_id == AV_CODEC_ID_FFV1)))
593 if (finished >= avctx->thread_count) finished = 0;
596 update_context_from_thread(avctx, p->avctx, 1);
598 if (fctx->next_decoding >= avctx->thread_count) fctx->next_decoding = 0;
654 void ff_thread_finish_setup(AVCodecContext *avctx) {
655 PerThreadContext *p = avctx->internal->thread_ctx;
657 if (!(avctx->active_thread_type&FF_THREAD_FRAME)) return;
659 if (avctx->hwaccel && !p->hwaccel_serializing) {
665 if (avctx->hwaccel &&
666 !(avctx->hwaccel->caps_internal & HWACCEL_CAP_ASYNC_SAFE)) {
676 p->parent->stash_hwaccel = avctx->hwaccel;
677 p->parent->stash_hwaccel_context = avctx->hwaccel_context;
678 p->parent->stash_hwaccel_priv = avctx->internal->hwaccel_priv_data;
682 av_log(avctx, AV_LOG_WARNING, "Multiple ff_thread_finish_setup() calls\n");
725 void ff_frame_thread_free(AVCodecContext *avctx, int thread_count)
727 FrameThreadContext *fctx = avctx->internal->thread_ctx;
728 const FFCodec *codec = ffcodec(avctx->codec);
735 AVCodecContext *ctx = p->avctx;
773 av_freep(&p->avctx);
781 av_assert0(!avctx->hwaccel);
782 FFSWAP(const AVHWAccel*, avctx->hwaccel, fctx->stash_hwaccel);
783 FFSWAP(void*, avctx->hwaccel_context, fctx->stash_hwaccel_context);
784 FFSWAP(void*, avctx->internal->hwaccel_priv_data, fctx->stash_hwaccel_priv);
786 av_freep(&avctx->internal->thread_ctx);
790 FrameThreadContext *fctx, AVCodecContext *avctx,
798 copy = av_memdup(avctx, sizeof(*avctx));
808 p->avctx = copy;
815 copy->delay = avctx->delay;
824 err = av_opt_copy(copy->priv_data, avctx->priv_data);
853 update_context_from_thread(avctx, copy, 1);
865 int ff_frame_thread_init(AVCodecContext *avctx)
867 int thread_count = avctx->thread_count;
868 const FFCodec *codec = ffcodec(avctx->codec);
876 thread_count = avctx->thread_count = FFMIN(nb_cpus + 1, MAX_AUTO_THREADS);
878 thread_count = avctx->thread_count = 1;
882 avctx->active_thread_type = 0;
886 avctx->internal->thread_ctx = fctx = av_mallocz(sizeof(FrameThreadContext));
893 av_freep(&avctx->internal->thread_ctx);
901 avctx->delay = avctx->thread_count - 1;
913 err = init_thread(p, &i, fctx, avctx, codec, first);
921 ff_frame_thread_free(avctx, i);
925 void ff_thread_flush(AVCodecContext *avctx)
928 FrameThreadContext *fctx = avctx->internal->thread_ctx;
932 park_frame_worker_threads(fctx, avctx->thread_count);
935 update_context_from_thread(fctx->threads[0].avctx, fctx->prev_thread->avctx, 0);
941 for (i = 0; i < avctx->thread_count; i++) {
952 if (ffcodec(avctx->codec)->flush)
953 ffcodec(avctx->codec)->flush(p->avctx);
957 int ff_thread_can_start_frame(AVCodecContext *avctx)
959 PerThreadContext *p = avctx->internal->thread_ctx;
961 if ((avctx->active_thread_type&FF_THREAD_FRAME) && atomic_load(&p->state) != STATE_SETTING_UP &&
962 (ffcodec(avctx->codec)->update_thread_context
964 || !THREAD_SAFE_CALLBACKS(avctx)
973 static int thread_get_buffer_internal(AVCodecContext *avctx, AVFrame *f, int flags)
978 if (!(avctx->active_thread_type & FF_THREAD_FRAME))
979 return ff_get_buffer(avctx, f, flags);
981 p = avctx->internal->thread_ctx;
984 (ffcodec(avctx->codec)->update_thread_context
986 || !THREAD_SAFE_CALLBACKS(avctx)
990 av_log(avctx, AV_LOG_ERROR, "get_buffer() cannot be called after ff_thread_finish_setup()\n");
996 err = ff_get_buffer(avctx, f->f, flags);
999 if (THREAD_SAFE_CALLBACKS(avctx)) {
1000 err = ff_get_buffer(avctx, f, flags);
1016 if (!THREAD_SAFE_CALLBACKS(avctx) && !ffcodec(avctx->codec)->update_thread_context)
1017 ff_thread_finish_setup(avctx);
1028 enum AVPixelFormat ff_thread_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
1032 if (!(avctx->active_thread_type & FF_THREAD_FRAME) || avctx->thread_safe_callbacks ||
1033 avctx->get_format == avcodec_default_get_format)
1034 return ff_get_format(avctx, fmt);
1036 p = avctx->internal->thread_ctx;
1038 av_log(avctx, AV_LOG_ERROR, "get_format() cannot be called after ff_thread_finish_setup()\n");
1058 int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f, int flags)
1060 int ret = thread_get_buffer_internal(avctx, f, flags);
1062 av_log(avctx, AV_LOG_ERROR, "thread_get_buffer() failed\n");
1066 int ff_thread_get_ext_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
1070 f->owner[0] = f->owner[1] = avctx;
1076 if (!(avctx->active_thread_type & FF_THREAD_FRAME))
1077 return ff_get_buffer(avctx, f->f, flags);
1079 if (ffcodec(avctx->codec)->caps_internal & FF_CODEC_CAP_ALLOCATE_PROGRESS) {
1091 ret = ff_thread_get_buffer(avctx, f->f, flags);
1097 void ff_thread_release_buffer(AVCodecContext *avctx, AVFrame *f)
1105 int can_direct_free = !(avctx->active_thread_type & FF_THREAD_FRAME) ||
1106 THREAD_SAFE_CALLBACKS(avctx);
1113 if (avctx->debug & FF_DEBUG_BUFFERS)
1114 av_log(avctx, AV_LOG_DEBUG, "thread_release_buffer called on pic %p\n", f);
1125 p = avctx->internal->thread_ctx;
1155 av_log(avctx, AV_LOG_ERROR, "Could not queue a frame for freeing, this will leak\n");
1164 void ff_thread_release_ext_buffer(AVCodecContext *avctx, ThreadFrame *f)
1168 ff_thread_release_buffer(avctx, f->f);