|
|
@ -46,7 +46,7 @@ |
|
|
|
#include "libavutil/mem.h" |
|
|
|
#include "libavutil/mem.h" |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Context used by codec threads and stored in their AVCodecContext thread_opaque. |
|
|
|
* Context used by codec threads and stored in their AVCodecInternal thread_ctx. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
typedef struct PerThreadContext { |
|
|
|
typedef struct PerThreadContext { |
|
|
|
struct FrameThreadContext *parent; |
|
|
|
struct FrameThreadContext *parent; |
|
|
@ -93,7 +93,7 @@ typedef struct PerThreadContext { |
|
|
|
} PerThreadContext; |
|
|
|
} PerThreadContext; |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Context stored in the client AVCodecContext thread_opaque. |
|
|
|
* Context stored in the client AVCodecInternal thread_ctx. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
typedef struct FrameThreadContext { |
|
|
|
typedef struct FrameThreadContext { |
|
|
|
PerThreadContext *threads; ///< The contexts for each thread.
|
|
|
|
PerThreadContext *threads; ///< The contexts for each thread.
|
|
|
@ -365,7 +365,7 @@ int ff_thread_decode_frame(AVCodecContext *avctx, |
|
|
|
AVFrame *picture, int *got_picture_ptr, |
|
|
|
AVFrame *picture, int *got_picture_ptr, |
|
|
|
AVPacket *avpkt) |
|
|
|
AVPacket *avpkt) |
|
|
|
{ |
|
|
|
{ |
|
|
|
FrameThreadContext *fctx = avctx->thread_opaque; |
|
|
|
FrameThreadContext *fctx = avctx->internal->thread_ctx; |
|
|
|
int finished = fctx->next_finished; |
|
|
|
int finished = fctx->next_finished; |
|
|
|
PerThreadContext *p; |
|
|
|
PerThreadContext *p; |
|
|
|
int err; |
|
|
|
int err; |
|
|
@ -441,7 +441,7 @@ void ff_thread_report_progress(ThreadFrame *f, int n, int field) |
|
|
|
|
|
|
|
|
|
|
|
if (!progress || progress[field] >= n) return; |
|
|
|
if (!progress || progress[field] >= n) return; |
|
|
|
|
|
|
|
|
|
|
|
p = f->owner->thread_opaque; |
|
|
|
p = f->owner->internal->thread_ctx; |
|
|
|
|
|
|
|
|
|
|
|
if (f->owner->debug&FF_DEBUG_THREADS) |
|
|
|
if (f->owner->debug&FF_DEBUG_THREADS) |
|
|
|
av_log(f->owner, AV_LOG_DEBUG, "%p finished %d field %d\n", progress, n, field); |
|
|
|
av_log(f->owner, AV_LOG_DEBUG, "%p finished %d field %d\n", progress, n, field); |
|
|
@ -459,7 +459,7 @@ void ff_thread_await_progress(ThreadFrame *f, int n, int field) |
|
|
|
|
|
|
|
|
|
|
|
if (!progress || progress[field] >= n) return; |
|
|
|
if (!progress || progress[field] >= n) return; |
|
|
|
|
|
|
|
|
|
|
|
p = f->owner->thread_opaque; |
|
|
|
p = f->owner->internal->thread_ctx; |
|
|
|
|
|
|
|
|
|
|
|
if (f->owner->debug&FF_DEBUG_THREADS) |
|
|
|
if (f->owner->debug&FF_DEBUG_THREADS) |
|
|
|
av_log(f->owner, AV_LOG_DEBUG, "thread awaiting %d field %d from %p\n", n, field, progress); |
|
|
|
av_log(f->owner, AV_LOG_DEBUG, "thread awaiting %d field %d from %p\n", n, field, progress); |
|
|
@ -471,7 +471,7 @@ void ff_thread_await_progress(ThreadFrame *f, int n, int field) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void ff_thread_finish_setup(AVCodecContext *avctx) { |
|
|
|
void ff_thread_finish_setup(AVCodecContext *avctx) { |
|
|
|
PerThreadContext *p = avctx->thread_opaque; |
|
|
|
PerThreadContext *p = avctx->internal->thread_ctx; |
|
|
|
|
|
|
|
|
|
|
|
if (!(avctx->active_thread_type&FF_THREAD_FRAME)) return; |
|
|
|
if (!(avctx->active_thread_type&FF_THREAD_FRAME)) return; |
|
|
|
|
|
|
|
|
|
|
@ -500,7 +500,7 @@ static void park_frame_worker_threads(FrameThreadContext *fctx, int thread_count |
|
|
|
|
|
|
|
|
|
|
|
void ff_frame_thread_free(AVCodecContext *avctx, int thread_count) |
|
|
|
void ff_frame_thread_free(AVCodecContext *avctx, int thread_count) |
|
|
|
{ |
|
|
|
{ |
|
|
|
FrameThreadContext *fctx = avctx->thread_opaque; |
|
|
|
FrameThreadContext *fctx = avctx->internal->thread_ctx; |
|
|
|
const AVCodec *codec = avctx->codec; |
|
|
|
const AVCodec *codec = avctx->codec; |
|
|
|
int i; |
|
|
|
int i; |
|
|
|
|
|
|
|
|
|
|
@ -544,16 +544,16 @@ void ff_frame_thread_free(AVCodecContext *avctx, int thread_count) |
|
|
|
|
|
|
|
|
|
|
|
if (i) { |
|
|
|
if (i) { |
|
|
|
av_freep(&p->avctx->priv_data); |
|
|
|
av_freep(&p->avctx->priv_data); |
|
|
|
av_freep(&p->avctx->internal); |
|
|
|
|
|
|
|
av_freep(&p->avctx->slice_offset); |
|
|
|
av_freep(&p->avctx->slice_offset); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
av_freep(&p->avctx->internal); |
|
|
|
av_freep(&p->avctx); |
|
|
|
av_freep(&p->avctx); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
av_freep(&fctx->threads); |
|
|
|
av_freep(&fctx->threads); |
|
|
|
pthread_mutex_destroy(&fctx->buffer_mutex); |
|
|
|
pthread_mutex_destroy(&fctx->buffer_mutex); |
|
|
|
av_freep(&avctx->thread_opaque); |
|
|
|
av_freep(&avctx->internal->thread_ctx); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int ff_frame_thread_init(AVCodecContext *avctx) |
|
|
|
int ff_frame_thread_init(AVCodecContext *avctx) |
|
|
@ -583,7 +583,7 @@ int ff_frame_thread_init(AVCodecContext *avctx) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
avctx->thread_opaque = fctx = av_mallocz(sizeof(FrameThreadContext)); |
|
|
|
avctx->internal->thread_ctx = fctx = av_mallocz(sizeof(FrameThreadContext)); |
|
|
|
|
|
|
|
|
|
|
|
fctx->threads = av_mallocz(sizeof(PerThreadContext) * thread_count); |
|
|
|
fctx->threads = av_mallocz(sizeof(PerThreadContext) * thread_count); |
|
|
|
pthread_mutex_init(&fctx->buffer_mutex, NULL); |
|
|
|
pthread_mutex_init(&fctx->buffer_mutex, NULL); |
|
|
@ -608,9 +608,16 @@ int ff_frame_thread_init(AVCodecContext *avctx) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
*copy = *src; |
|
|
|
*copy = *src; |
|
|
|
copy->thread_opaque = p; |
|
|
|
|
|
|
|
copy->pkt = &p->avpkt; |
|
|
|
copy->pkt = &p->avpkt; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
copy->internal = av_malloc(sizeof(AVCodecInternal)); |
|
|
|
|
|
|
|
if (!copy->internal) { |
|
|
|
|
|
|
|
err = AVERROR(ENOMEM); |
|
|
|
|
|
|
|
goto error; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
*copy->internal = *src->internal; |
|
|
|
|
|
|
|
copy->internal->thread_ctx = p; |
|
|
|
|
|
|
|
|
|
|
|
if (!i) { |
|
|
|
if (!i) { |
|
|
|
src = copy; |
|
|
|
src = copy; |
|
|
|
|
|
|
|
|
|
|
@ -625,12 +632,6 @@ int ff_frame_thread_init(AVCodecContext *avctx) |
|
|
|
goto error; |
|
|
|
goto error; |
|
|
|
} |
|
|
|
} |
|
|
|
memcpy(copy->priv_data, src->priv_data, codec->priv_data_size); |
|
|
|
memcpy(copy->priv_data, src->priv_data, codec->priv_data_size); |
|
|
|
copy->internal = av_malloc(sizeof(AVCodecInternal)); |
|
|
|
|
|
|
|
if (!copy->internal) { |
|
|
|
|
|
|
|
err = AVERROR(ENOMEM); |
|
|
|
|
|
|
|
goto error; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
*copy->internal = *src->internal; |
|
|
|
|
|
|
|
copy->internal->is_copy = 1; |
|
|
|
copy->internal->is_copy = 1; |
|
|
|
|
|
|
|
|
|
|
|
if (codec->init_thread_copy) |
|
|
|
if (codec->init_thread_copy) |
|
|
@ -654,9 +655,9 @@ error: |
|
|
|
void ff_thread_flush(AVCodecContext *avctx) |
|
|
|
void ff_thread_flush(AVCodecContext *avctx) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int i; |
|
|
|
int i; |
|
|
|
FrameThreadContext *fctx = avctx->thread_opaque; |
|
|
|
FrameThreadContext *fctx = avctx->internal->thread_ctx; |
|
|
|
|
|
|
|
|
|
|
|
if (!avctx->thread_opaque) return; |
|
|
|
if (!fctx) return; |
|
|
|
|
|
|
|
|
|
|
|
park_frame_worker_threads(fctx, avctx->thread_count); |
|
|
|
park_frame_worker_threads(fctx, avctx->thread_count); |
|
|
|
if (fctx->prev_thread) { |
|
|
|
if (fctx->prev_thread) { |
|
|
@ -681,7 +682,7 @@ void ff_thread_flush(AVCodecContext *avctx) |
|
|
|
|
|
|
|
|
|
|
|
int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags) |
|
|
|
int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags) |
|
|
|
{ |
|
|
|
{ |
|
|
|
PerThreadContext *p = avctx->thread_opaque; |
|
|
|
PerThreadContext *p = avctx->internal->thread_ctx; |
|
|
|
int err; |
|
|
|
int err; |
|
|
|
|
|
|
|
|
|
|
|
f->owner = avctx; |
|
|
|
f->owner = avctx; |
|
|
@ -743,7 +744,7 @@ FF_ENABLE_DEPRECATION_WARNINGS |
|
|
|
|
|
|
|
|
|
|
|
void ff_thread_release_buffer(AVCodecContext *avctx, ThreadFrame *f) |
|
|
|
void ff_thread_release_buffer(AVCodecContext *avctx, ThreadFrame *f) |
|
|
|
{ |
|
|
|
{ |
|
|
|
PerThreadContext *p = avctx->thread_opaque; |
|
|
|
PerThreadContext *p = avctx->internal->thread_ctx; |
|
|
|
FrameThreadContext *fctx; |
|
|
|
FrameThreadContext *fctx; |
|
|
|
AVFrame *dst, *tmp; |
|
|
|
AVFrame *dst, *tmp; |
|
|
|
FF_DISABLE_DEPRECATION_WARNINGS |
|
|
|
FF_DISABLE_DEPRECATION_WARNINGS |
|
|
|