This is useful when the lifetime of the object to be shared is the whole decoding process as it allows to avoid having to sync them every time in update_thread_context.
Showing the changes to libavcodec (3 of 3 files). Show all
Unified · Split
| @@ -1747,6 +1747,13 @@ void ff_progress_frame_await(const ProgressFrame *f, int n) · 1746 unmodified lines | |||
| 1747 | ff_thread_progress_await(&f->progress->progress, n); | 1747 | ff_thread_progress_await(&f->progress->progress, n); |
| 1748 | } | 1748 | } |
| 1749 | 1749 | ||
| 1750 | #if !HAVE_THREADS | ||
| 1751 | enum ThreadingStatus ff_thread_sync_ref(AVCodecContext *avctx, size_t offset) | ||
| 1752 | { | ||
| 1753 | return FF_THREAD_NO_FRAME_THREADING; | ||
| 1754 | } | ||
| 1755 | #endif /* !HAVE_THREADS */ | ||
| 1756 | |||
| 1750 | static av_cold int progress_frame_pool_init_cb(FFRefStructOpaque opaque, void *obj) | 1757 | static av_cold int progress_frame_pool_init_cb(FFRefStructOpaque opaque, void *obj) |
| 1751 | { | 1758 | { |
| 1752 | const AVCodecContext *avctx = opaque.nc; | 1759 | const AVCodecContext *avctx = opaque.nc; |
| @@ -1013,3 +1013,23 @@ void ff_thread_release_ext_buffer(ThreadFrame *f) · 1012 unmodified lines | |||
| 1013 | if (f->f) | 1013 | if (f->f) |
| 1014 | av_frame_unref(f->f); | 1014 | av_frame_unref(f->f); |
| 1015 | } | 1015 | } |
| 1016 | |||
| 1017 | enum ThreadingStatus ff_thread_sync_ref(AVCodecContext *avctx, size_t offset) | ||
| 1018 | { | ||
| 1019 | PerThreadContext *p; | ||
| 1020 | const void *ref; | ||
| 1021 | |||
| 1022 | if (!avctx->internal->is_copy) | ||
| 1023 | return avctx->active_thread_type & FF_THREAD_FRAME ? | ||
| 1024 | FF_THREAD_IS_FIRST_THREAD : FF_THREAD_NO_FRAME_THREADING; | ||
| 1025 | |||
| 1026 | p = avctx->internal->thread_ctx; | ||
| 1027 | |||
| 1028 | av_assert1(memcpy(&ref, (char*)avctx->priv_data + offset, sizeof(ref)) && ref == NULL); | ||
| 1029 | |||
| 1030 | memcpy(&ref, (const char*)p->parent->threads[0].avctx->priv_data + offset, sizeof(ref)); | ||
| 1031 | av_assert1(ref); | ||
| 1032 | ff_refstruct_replace((char*)avctx->priv_data + offset, ref); | ||
| 1033 | |||
| 1034 | return FF_THREAD_IS_COPY; | ||
| 1035 | } | ||
| @@ -84,4 +84,34 @@ int ff_slice_thread_init_progress(AVCodecContext *avctx); · 83 unmodified lines | |||
| 84 | void ff_thread_report_progress2(AVCodecContext *avctx, int field, int thread, int n); | 84 | void ff_thread_report_progress2(AVCodecContext *avctx, int field, int thread, int n); |
| 85 | void ff_thread_await_progress2(AVCodecContext *avctx, int field, int thread, int shift); | 85 | void ff_thread_await_progress2(AVCodecContext *avctx, int field, int thread, int shift); |
| 86 | 86 | ||
| 87 | enum ThreadingStatus { | ||
| 88 | FF_THREAD_IS_COPY, | ||
| 89 | FF_THREAD_IS_FIRST_THREAD, | ||
| 90 | FF_THREAD_NO_FRAME_THREADING, | ||
| 91 | }; | ||
| 92 | |||
| 93 | /** | ||
| 94 | * Allows to synchronize objects whose lifetime is the whole decoding | ||
| 95 | * process among all frame threads. | ||
| 96 | * | ||
| 97 | * When called from a non-copy thread, do nothing. | ||
| 98 | * When called from another thread, place a new RefStruct reference | ||
| 99 | * at the given offset in the calling thread's private data from | ||
| 100 | * the RefStruct reference in the private data of the first decoding thread. | ||
| 101 | * The first thread must have a valid RefStruct reference at the given | ||
| 102 | * offset in its private data; the calling thread must not have | ||
| 103 | * a reference at this offset in its private data (must be NULL). | ||
| 104 | * | ||
| 105 | * @param avctx an AVCodecContext | ||
| 106 | * @param offset offset of the RefStruct reference in avctx's private data | ||
| 107 | * | ||
| 108 | * @retval FF_THREAD_IS_COPY if frame-threading is in use and the | ||
| 109 | * calling thread is a copy; in this case, the RefStruct reference | ||
| 110 | * will be set. | ||
| 111 | * @retval FF_THREAD_IS_MAIN_THREAD if frame-threading is in use | ||
| 112 | * and the calling thread is the main thread. | ||
| 113 | * @retval FF_THREAD_NO_FRAME_THREADING if frame-threading is not in use. | ||
| 114 | */ | ||
| 115 | enum ThreadingStatus ff_thread_sync_ref(AVCodecContext *avctx, size_t offset); | ||
| 116 | |||
| 87 | #endif /* AVCODEC_THREAD_H */ | 117 | #endif /* AVCODEC_THREAD_H */ |