mirror of https://git.ffmpeg.org/ffmpeg.git
avcodec/pthread_slice: add ff_slice_thread_execute_with_mainfunc()
Signed-off-by: Ilia Valiakhmetov <zakne0ne@gmail.com> Signed-off-by: Ronald S. Bultje <rsbultje@gmail.com>
This commit is contained in:
parent
fde5c7dc79
commit
83c12fefd2
|
@ -64,6 +64,10 @@
|
||||||
* dimensions to coded rather than display values.
|
* dimensions to coded rather than display values.
|
||||||
*/
|
*/
|
||||||
#define FF_CODEC_CAP_EXPORTS_CROPPING (1 << 4)
|
#define FF_CODEC_CAP_EXPORTS_CROPPING (1 << 4)
|
||||||
|
/**
|
||||||
|
* Codec initializes slice-based threading with a main function
|
||||||
|
*/
|
||||||
|
#define FF_CODEC_CAP_SLICE_THREAD_HAS_MF (1 << 5)
|
||||||
|
|
||||||
#ifdef TRACE
|
#ifdef TRACE
|
||||||
# define ff_tlog(ctx, ...) av_log(ctx, AV_LOG_TRACE, __VA_ARGS__)
|
# define ff_tlog(ctx, ...) av_log(ctx, AV_LOG_TRACE, __VA_ARGS__)
|
||||||
|
|
|
@ -38,11 +38,13 @@
|
||||||
|
|
||||||
typedef int (action_func)(AVCodecContext *c, void *arg);
|
typedef int (action_func)(AVCodecContext *c, void *arg);
|
||||||
typedef int (action_func2)(AVCodecContext *c, void *arg, int jobnr, int threadnr);
|
typedef int (action_func2)(AVCodecContext *c, void *arg, int jobnr, int threadnr);
|
||||||
|
typedef int (main_func)(AVCodecContext *c);
|
||||||
|
|
||||||
typedef struct SliceThreadContext {
|
typedef struct SliceThreadContext {
|
||||||
AVSliceThread *thread;
|
AVSliceThread *thread;
|
||||||
action_func *func;
|
action_func *func;
|
||||||
action_func2 *func2;
|
action_func2 *func2;
|
||||||
|
main_func *mainfunc;
|
||||||
void *args;
|
void *args;
|
||||||
int *rets;
|
int *rets;
|
||||||
int job_size;
|
int job_size;
|
||||||
|
@ -54,6 +56,12 @@ typedef struct SliceThreadContext {
|
||||||
pthread_mutex_t *progress_mutex;
|
pthread_mutex_t *progress_mutex;
|
||||||
} SliceThreadContext;
|
} SliceThreadContext;
|
||||||
|
|
||||||
|
static void main_function(void *priv) {
|
||||||
|
AVCodecContext *avctx = priv;
|
||||||
|
SliceThreadContext *c = avctx->internal->thread_ctx;
|
||||||
|
c->mainfunc(avctx);
|
||||||
|
}
|
||||||
|
|
||||||
static void worker_func(void *priv, int jobnr, int threadnr, int nb_jobs, int nb_threads)
|
static void worker_func(void *priv, int jobnr, int threadnr, int nb_jobs, int nb_threads)
|
||||||
{
|
{
|
||||||
AVCodecContext *avctx = priv;
|
AVCodecContext *avctx = priv;
|
||||||
|
@ -99,7 +107,7 @@ static int thread_execute(AVCodecContext *avctx, action_func* func, void *arg, i
|
||||||
c->func = func;
|
c->func = func;
|
||||||
c->rets = ret;
|
c->rets = ret;
|
||||||
|
|
||||||
avpriv_slicethread_execute(c->thread, job_count, 0);
|
avpriv_slicethread_execute(c->thread, job_count, !!c->mainfunc );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,10 +118,19 @@ static int thread_execute2(AVCodecContext *avctx, action_func2* func2, void *arg
|
||||||
return thread_execute(avctx, NULL, arg, ret, job_count, 0);
|
return thread_execute(avctx, NULL, arg, ret, job_count, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ff_slice_thread_execute_with_mainfunc(AVCodecContext *avctx, action_func2* func2, main_func *mainfunc, void *arg, int *ret, int job_count)
|
||||||
|
{
|
||||||
|
SliceThreadContext *c = avctx->internal->thread_ctx;
|
||||||
|
c->func2 = func2;
|
||||||
|
c->mainfunc = mainfunc;
|
||||||
|
return thread_execute(avctx, NULL, arg, ret, job_count, 0);
|
||||||
|
}
|
||||||
|
|
||||||
int ff_slice_thread_init(AVCodecContext *avctx)
|
int ff_slice_thread_init(AVCodecContext *avctx)
|
||||||
{
|
{
|
||||||
SliceThreadContext *c;
|
SliceThreadContext *c;
|
||||||
int thread_count = avctx->thread_count;
|
int thread_count = avctx->thread_count;
|
||||||
|
static void (*mainfunc)(void *);
|
||||||
|
|
||||||
#if HAVE_W32THREADS
|
#if HAVE_W32THREADS
|
||||||
w32thread_init();
|
w32thread_init();
|
||||||
|
@ -142,7 +159,8 @@ int ff_slice_thread_init(AVCodecContext *avctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
avctx->internal->thread_ctx = c = av_mallocz(sizeof(*c));
|
avctx->internal->thread_ctx = c = av_mallocz(sizeof(*c));
|
||||||
if (!c || (thread_count = avpriv_slicethread_create(&c->thread, avctx, worker_func, NULL, thread_count)) <= 1) {
|
mainfunc = avctx->codec->caps_internal & FF_CODEC_CAP_SLICE_THREAD_HAS_MF ? &main_function : NULL;
|
||||||
|
if (!c || (thread_count = avpriv_slicethread_create(&c->thread, avctx, worker_func, mainfunc, thread_count)) <= 1) {
|
||||||
if (c)
|
if (c)
|
||||||
avpriv_slicethread_free(&c->thread);
|
avpriv_slicethread_free(&c->thread);
|
||||||
av_freep(&avctx->internal->thread_ctx);
|
av_freep(&avctx->internal->thread_ctx);
|
||||||
|
|
|
@ -133,8 +133,10 @@ void ff_thread_release_buffer(AVCodecContext *avctx, ThreadFrame *f);
|
||||||
int ff_thread_ref_frame(ThreadFrame *dst, ThreadFrame *src);
|
int ff_thread_ref_frame(ThreadFrame *dst, ThreadFrame *src);
|
||||||
|
|
||||||
int ff_thread_init(AVCodecContext *s);
|
int ff_thread_init(AVCodecContext *s);
|
||||||
|
int ff_slice_thread_execute_with_mainfunc(AVCodecContext *avctx,
|
||||||
|
int (*action_func2)(AVCodecContext *c, void *arg, int jobnr, int threadnr),
|
||||||
|
int (*main_func)(AVCodecContext *c), void *arg, int *ret, int job_count);
|
||||||
void ff_thread_free(AVCodecContext *s);
|
void ff_thread_free(AVCodecContext *s);
|
||||||
|
|
||||||
int ff_alloc_entries(AVCodecContext *avctx, int count);
|
int ff_alloc_entries(AVCodecContext *avctx, int count);
|
||||||
void ff_reset_entries(AVCodecContext *avctx);
|
void ff_reset_entries(AVCodecContext *avctx);
|
||||||
void ff_thread_report_progress2(AVCodecContext *avctx, int field, int thread, int n);
|
void ff_thread_report_progress2(AVCodecContext *avctx, int field, int thread, int n);
|
||||||
|
|
Loading…
Reference in New Issue