From patchwork Thu Sep 7 17:55:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilia X-Patchwork-Id: 5038 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.15.201 with SMTP id 70csp489847jao; Thu, 7 Sep 2017 10:56:52 -0700 (PDT) X-Received: by 10.223.141.143 with SMTP id o15mr131618wrb.228.1504807012536; Thu, 07 Sep 2017 10:56:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504807012; cv=none; d=google.com; s=arc-20160816; b=GylHAQuE3T0vJPklzYdAWqveZtSBLcAkdCAvU3T1qNkz8nG9WlJbi2CeLtbLdrywH3 72IWiaoKoLkV/qiDh5+qahegh7tNcsDWmpQ+dWThELntNAMVGUdFqViPIt+AhXKSPoRC uV31KEnr6FX3r+b8Z2HAdz0MW6wdm6DKq9bucgQ4E707S5sT73uSU4+gfB41QaRcLD3w v1UuYpaweIu6cwK+Xrksmehof5rXjzrr47VjpiVPl3vY7/BIs2yKAhFcoWkioburysVw XOstsfkgKMPLi7vb6GVCgVw4M46XZfcSfo4v3ptym592/Tmu3cGTPVcIDtOW81GT0AYR 2IfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=K+zM7SGrZxv89yR+CYOixiBKkfQPGUgxO3nv9AmlYz8=; b=l3PeQdjUWsrcR/cs0RqnINzn7QlwF2+ak+o+oMNQfW7WwG98+YEdiBHpJrRmeGRWbQ XAYusjaU+ID/ZIprjK1YjCT2d5PsO4wZdvKBwoU+ZFnMjG+G8vUa5Op+ZAn26Njq7rTr ZG5ABFXLeIzht719ufI/RzU9hAGUid6rSOrudNi5PPYtYqT9N/kpKb+lUBsp54OLOfKW mVWeEqb4a0a7YKyDWzyPE003CJ1On6wsqKRQI8aiBm62XwW/4cP0lIsl+cOaCEyaj/dW KBd6cqQLxOttd3JomsJEDYSB1EGDvqinmzSaYpYhCTjFF9USX2Q4IDVTlEmrXcwk1YM+ Veqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=qm88m7OX; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id y99si120255wmh.56.2017.09.07.10.56.51; Thu, 07 Sep 2017 10:56:52 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=qm88m7OX; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 36781689E7B; Thu, 7 Sep 2017 20:56:45 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf0-f68.google.com (mail-lf0-f68.google.com [209.85.215.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8C13B689E67 for ; Thu, 7 Sep 2017 20:56:38 +0300 (EEST) Received: by mail-lf0-f68.google.com with SMTP id h80so158556lfe.1 for ; Thu, 07 Sep 2017 10:56:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=m5qCX5QWuyWES8U6IWaGr4vTJ8oe8DidvsmHF7zpXaA=; b=qm88m7OXEbzMa9CLY6eytpIfpNSZeJ5NtszO6GBtkx3trpsRnylZSkS63IsGcmpnR/ BIbMGXtWYG0bNg277GxwvLb+iHwj/R9NPZXv2Nb2LSzouFmVZDv3UQeMETv0rGBFZlNY 1/DmENDClP0Udq35vLSB3WbKF2pzRQRlbAb/cjh+VOze/ap+uOlwaSoDPosfqIUYrYEx uCsju4yyYaKJsVSl1A7jePDJokP4dq0tDiiv16JGZzuQT6DrB3KNNzHXaET2sCwhuWTs pgCrrcAMkgWA196YufBr5qsfkHWKrv1R0KOE2okDdamxd0QUIbu9PhZ5Q33BX69u+Fan MiMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=m5qCX5QWuyWES8U6IWaGr4vTJ8oe8DidvsmHF7zpXaA=; b=owu6+mIPiiOmD5+46HKa6aDUbHfryhFgmlvL6aiPdCKzjLbwJz3TMh32Dllbhwfz9B UIHRFbG8ZWdD/jzKtGTUfauZKMteei5rE9eFDOTswZk+Glpncc+ljRIJkrF3dyxx7TDI DGpqmDU/kUwTWT8sRz3jaq3UXDbFSaJGHwc5V55pI+WPLCw0kb9ged9BPLvcC5oSzLEP c8DwcckPZluX3EAfKk32AtUKHdufhBHT9Q81qoFfq6k0MK/dIqdFgOcvQN9QHPTf98T1 eCJUqgiSjxEFDZZ+rE+I1GGbir1yth45PK2Od+syDP+VUu+As2yZxmOMsvYdj69gl72i 9zYA== X-Gm-Message-State: AHPjjUiFuaQiWFEG15FH9KnwLs1EGdMetGS++omHpvrhb/sf1UkZOlhr o/YbytIMGYhaPyYf X-Google-Smtp-Source: AOwi7QDxRs0sZU8k/L5UCWKiFUi598SGqNOYxABOAFzGexkpwwByBX4hKq2KuR34ryayOXmuhDLNaQ== X-Received: by 10.46.68.154 with SMTP id b26mr12600ljf.159.1504807001774; Thu, 07 Sep 2017 10:56:41 -0700 (PDT) Received: from localhost.localdomain ([95.191.192.76]) by smtp.gmail.com with ESMTPSA id j126sm30168lfg.86.2017.09.07.10.56.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Sep 2017 10:56:40 -0700 (PDT) From: Ilia Valiakhmetov To: ffmpeg-devel@ffmpeg.org Date: Fri, 8 Sep 2017 00:55:29 +0700 Message-Id: <20170907175529.4420-2-zakne0ne@gmail.com> X-Mailer: git-send-email 2.8.3 In-Reply-To: <20170907175529.4420-1-zakne0ne@gmail.com> References: <20170907175529.4420-1-zakne0ne@gmail.com> Subject: [FFmpeg-devel] [PATCH 2/2] avcodec/pthread_slice: add main function support for avpriv_slicethread_create() X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Ilia Valiakhmetov MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" --- libavcodec/internal.h | 4 ++++ libavcodec/pthread_slice.c | 33 ++++++++++++++------------------- libavcodec/thread.h | 1 + libavutil/slicethread.h | 18 ++++++++++++++++++ 4 files changed, 37 insertions(+), 19 deletions(-) diff --git a/libavcodec/internal.h b/libavcodec/internal.h index 64120ea..4668952 100644 --- a/libavcodec/internal.h +++ b/libavcodec/internal.h @@ -64,6 +64,10 @@ * dimensions to coded rather than display values. */ #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 # define ff_tlog(ctx, ...) av_log(ctx, AV_LOG_TRACE, __VA_ARGS__) diff --git a/libavcodec/pthread_slice.c b/libavcodec/pthread_slice.c index c781d35..65e5abf 100644 --- a/libavcodec/pthread_slice.c +++ b/libavcodec/pthread_slice.c @@ -38,21 +38,13 @@ typedef int (action_func)(AVCodecContext *c, void *arg); typedef int (action_func2)(AVCodecContext *c, void *arg, int jobnr, int threadnr); +typedef int (main_func)(AVCodecContext *c); -typedef struct SliceThreadContext { - AVSliceThread *thread; - action_func *func; - action_func2 *func2; - void *args; - int *rets; - int job_size; - - int *entries; - int entries_count; - int thread_count; - pthread_cond_t *progress_cond; - pthread_mutex_t *progress_mutex; -} SliceThreadContext; +static void main_function(void *priv) { + AVCodecContext *avctx = priv; + SliceThreadContext *c = avctx->internal->thread_ctx; + c->m_func(avctx); +} static void worker_func(void *priv, int jobnr, int threadnr, int nb_jobs, int nb_threads) { @@ -84,7 +76,7 @@ void ff_slice_thread_free(AVCodecContext *avctx) av_freep(&avctx->internal->thread_ctx); } -static int thread_execute(AVCodecContext *avctx, action_func* func, void *arg, int *ret, int job_count, int job_size) +int ff_thread_execute(AVCodecContext *avctx, action_func* func, void *arg, int *ret, int job_count, int job_size) { SliceThreadContext *c = avctx->internal->thread_ctx; @@ -99,7 +91,7 @@ static int thread_execute(AVCodecContext *avctx, action_func* func, void *arg, i c->func = func; c->rets = ret; - avpriv_slicethread_execute(c->thread, job_count, 0); + avpriv_slicethread_execute(c->thread, job_count, !!c->m_func); return 0; } @@ -107,13 +99,14 @@ static int thread_execute2(AVCodecContext *avctx, action_func2* func2, void *arg { SliceThreadContext *c = avctx->internal->thread_ctx; c->func2 = func2; - return thread_execute(avctx, NULL, arg, ret, job_count, 0); + return ff_thread_execute(avctx, NULL, arg, ret, job_count, 0); } int ff_slice_thread_init(AVCodecContext *avctx) { SliceThreadContext *c; int thread_count = avctx->thread_count; + static void (*main_f)(void *); #if HAVE_W32THREADS w32thread_init(); @@ -142,7 +135,8 @@ int ff_slice_thread_init(AVCodecContext *avctx) } 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) { + main_f = 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, main_f, thread_count)) <= 1) { if (c) avpriv_slicethread_free(&c->thread); av_freep(&avctx->internal->thread_ctx); @@ -150,9 +144,10 @@ int ff_slice_thread_init(AVCodecContext *avctx) avctx->active_thread_type = 0; return 0; } + c->m_func = NULL; avctx->thread_count = thread_count; - avctx->execute = thread_execute; + avctx->execute = ff_thread_execute; avctx->execute2 = thread_execute2; return 0; } diff --git a/libavcodec/thread.h b/libavcodec/thread.h index 90864b5..dd8f5fe 100644 --- a/libavcodec/thread.h +++ b/libavcodec/thread.h @@ -133,6 +133,7 @@ void ff_thread_release_buffer(AVCodecContext *avctx, ThreadFrame *f); int ff_thread_ref_frame(ThreadFrame *dst, ThreadFrame *src); int ff_thread_init(AVCodecContext *s); +int ff_thread_execute(AVCodecContext *avctx, int (*func)(AVCodecContext *c, void *arg), void *arg, int *ret, int job_count, int job_size); void ff_thread_free(AVCodecContext *s); int ff_alloc_entries(AVCodecContext *avctx, int count); diff --git a/libavutil/slicethread.h b/libavutil/slicethread.h index f6f6f30..9d15c96 100644 --- a/libavutil/slicethread.h +++ b/libavutil/slicethread.h @@ -16,11 +16,29 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavcodec/avcodec.h" + #ifndef AVUTIL_SLICETHREAD_H #define AVUTIL_SLICETHREAD_H typedef struct AVSliceThread AVSliceThread; +typedef struct SliceThreadContext { + AVSliceThread *thread; + int (*func)(AVCodecContext *c, void *arg); + int (*func2)(AVCodecContext *c, void *arg, int jobnr, int threadnr); + int (*m_func)(AVCodecContext *c); + void *args; + int *rets; + int job_size; + + int *entries; + int entries_count; + int thread_count; + pthread_cond_t *progress_cond; + pthread_mutex_t *progress_mutex; +} SliceThreadContext; + /** * Create slice threading context. * @param pctx slice threading context returned here