| 671 | } |
| 672 | |
| 673 | void ff_thread_finish_setup(AVCodecContext *avctx) { |
| 674 | PerThreadContext *p; |
| 675 | |
| 676 | if (!(avctx->active_thread_type&FF_THREAD_FRAME)) return; |
| 677 | |
| 678 | p = avctx->internal->thread_ctx; |
| 679 | |
| 680 | p->hwaccel_threadsafe = avctx->hwaccel && |
| 681 | (ffhwaccel(avctx->hwaccel)->caps_internal & HWACCEL_CAP_THREAD_SAFE); |
| 682 | |
| 683 | if (hwaccel_serial(avctx) && !p->hwaccel_serializing) { |
| 684 | pthread_mutex_lock(&p->parent->hwaccel_mutex); |
| 685 | p->hwaccel_serializing = 1; |
| 686 | } |
| 687 | |
| 688 | /* this assumes that no hwaccel calls happen before ff_thread_finish_setup() */ |
| 689 | if (avctx->hwaccel && |
| 690 | !(ffhwaccel(avctx->hwaccel)->caps_internal & HWACCEL_CAP_ASYNC_SAFE)) { |
| 691 | p->async_serializing = 1; |
| 692 | |
| 693 | async_lock(p->parent); |
| 694 | } |
| 695 | |
| 696 | /* thread-unsafe hwaccels share a single private data instance, so we |
| 697 | * save hwaccel state for passing to the next thread; |
| 698 | * this is done here so that this worker thread can wipe its own hwaccel |
| 699 | * state after decoding, without requiring synchronization */ |
| 700 | av_assert0(!p->parent->stash_hwaccel); |
| 701 | if (hwaccel_serial(avctx)) { |
| 702 | p->parent->stash_hwaccel = avctx->hwaccel; |
| 703 | p->parent->stash_hwaccel_context = avctx->hwaccel_context; |
| 704 | p->parent->stash_hwaccel_priv = avctx->internal->hwaccel_priv_data; |
| 705 | } |
| 706 | |
| 707 | pthread_mutex_lock(&p->progress_mutex); |
| 708 | if(atomic_load(&p->state) == STATE_SETUP_FINISHED){ |
| 709 | av_log(avctx, AV_LOG_WARNING, "Multiple ff_thread_finish_setup() calls\n"); |
| 710 | } |
| 711 | |
| 712 | atomic_store(&p->state, STATE_SETUP_FINISHED); |
| 713 | |
| 714 | pthread_cond_broadcast(&p->progress_cond); |
| 715 | pthread_mutex_unlock(&p->progress_mutex); |
| 716 | } |
| 717 | |
| 718 | /// Waits for all threads to finish. |
| 719 | static av_cold void park_frame_worker_threads(FrameThreadContext *fctx, int thread_count) |
no test coverage detected