From patchwork Thu Sep 7 20:48:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilia X-Patchwork-Id: 5043 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.15.201 with SMTP id 70csp644889jao; Thu, 7 Sep 2017 13:49:16 -0700 (PDT) X-Received: by 10.28.165.75 with SMTP id o72mr108548wme.12.1504817356838; Thu, 07 Sep 2017 13:49:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504817356; cv=none; d=google.com; s=arc-20160816; b=pYD97DBD5ere/LCBBacHKW85IrpO81M1d09I9T6d6BmyE3lKZj4v/jK5wLwAzb1wGf WplFcPZ955OJDz4e0z2PivbPPklg5Gi/wZJzXl1kGDHdTyA2cpk0V9pNJUdb249s+Zfn 1nG64lGhcWRryizwQVWgOP6RSE6YiLdCTUBnpH7aFyTlo6zK2s1Kjh66Aj9vtipHfg6p YoTO+w7YRXwX6RCxQn/WJFvSj3Qp/n6gqHyTNLykEadZEjJOFzQruewnaegk83pBMID4 atK29ctPc8mBUXxu+wfZT9uSEILoOrAZN7mrySasKjsfCB15u/2hfk4WXQCFz1Nw5f7K XJNw== 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=NKTjMVvsKnLlQ5lSpmHpCfsyqAM1IZJThY3L/VtESPM=; b=YvVsJe8hVyoKBT3BYzPkxgxaw8u3hNPbwfqZRkGJpkExpIN08dXgHrFkkC/5MbrIA8 HWpww81UAOp8us7PKrjESBZhqNLC3rCooEQblbl0PpSC538Ze+NpZTJ2/JBAt3VbdZe7 hqzaZgc97DHTt7wQMrmulFpjYFOQxEf5jF8Sb+mF46wQFjaYp9tkrFWib1GdVZhF/crx bgwMqUFF5Ru9znqOuBsZnBJusF6Eq3oDM0NJoVQ4VaMSA3Q6comdXrQYeZWXOAr1m12I +gvVXpqBw5FuMGWL4jAFdVDbpoaPT4ovJCZKuqmnAtWcaF5F5ju+xhpjs13N1oXjNs3J 0OfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=eI4gbdFX; 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 u53si142545wrc.538.2017.09.07.13.49.16; Thu, 07 Sep 2017 13:49:16 -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=eI4gbdFX; 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 154F3689E21; Thu, 7 Sep 2017 23:49:10 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf0-f65.google.com (mail-lf0-f65.google.com [209.85.215.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 19786689D6A for ; Thu, 7 Sep 2017 23:49:04 +0300 (EEST) Received: by mail-lf0-f65.google.com with SMTP id y15so324130lfd.0 for ; Thu, 07 Sep 2017 13:49:08 -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=kgUDJfVqm06+9DFopsl3oF6KQDHzRxaPDyAJzbyozi4=; b=eI4gbdFXPJTMbYoxJDnFH3+UuyHJE5w4yDwoRnzLQzA7Gjpg1likcu81vXxEgUIySI 4iBkZgjRbQzjAoBdYPZlnLgi2CWoGtd7C0RvbzV7WND+hCrjH/o2MNFZDTZeooBnp0yb cnEJErffUGsSnYe2DT1caR3ys8oYGODVTM4ek8Y5tgqLExI/PbZ86tDtYCantmytAw5n LyHZMg+E8wz5cn8S7MddvYxYAgbh3ZKe4jqu/A7yvZRS4aBPkmfkEgkq2k6QmmYud51K uRPI0soupAjJKLtj9aySg4jEOmruBluh497xajKHpaQ8X4+JpaX46TzebPUWj/VSIK6e eNkA== 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=kgUDJfVqm06+9DFopsl3oF6KQDHzRxaPDyAJzbyozi4=; b=r452gn9vFX03h9cvezPLEEhqfa8TZuWT5gPwswayWLQuENd/tg6IofFCsL23OPt4Jn ctnfJfXeu3D5mccF5VK75myF8kvr7esJIJejC7el3w01YG22RDjxtQw0DQIsJavx34WO 4GDW4jYfF+91WTfMIQ9OZbNxa86mjKhJCc/P7hraw0ATwuZYcKQiXbCGjClJDW4bGZoe fNyD1Ld5O8zj8pRh0BRposJ+2R/Ib9nGtGylgi5vMhsKGDc5dng55JkkpgiLQpMn1CC5 eKqN5KA0A0I60oH6T5AnIAjeDxtLnQhQ6RxkuEb6lmqQ0Pw8vNoQV+n3NCk6OchIhHum 8yDw== X-Gm-Message-State: AHPjjUgmv4eLM2sRY7bRS0/H1vucB60P1Eh/xmNdt0YAh+z/iqQghmgq IeJpD45nc0IUyASh X-Google-Smtp-Source: ADKCNb70I+JOARmINEMiKZ/lKDICCRDK+1vd/cDwmMn1hZ7h9mXLGeXBGgGHtqG1rlsYbwdZSvrvHA== X-Received: by 10.46.33.82 with SMTP id h79mr173271ljh.104.1504817347099; Thu, 07 Sep 2017 13:49:07 -0700 (PDT) Received: from localhost.localdomain ([95.191.192.76]) by smtp.gmail.com with ESMTPSA id v9sm36390lja.61.2017.09.07.13.49.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Sep 2017 13:49:06 -0700 (PDT) From: Ilia Valiakhmetov To: ffmpeg-devel@ffmpeg.org Date: Fri, 8 Sep 2017 03:48:17 +0700 Message-Id: <20170907204817.5248-1-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] [PATCHv2 2/2] avcodec/pthread_slice: add ff_slice_thread_execute_with_mainfunc() 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" Signed-off-by: Ilia Valiakhmetov v2: --- libavcodec/internal.h | 4 ++++ libavcodec/pthread_slice.c | 22 ++++++++++++++++++++-- libavcodec/thread.h | 4 +++- 3 files changed, 27 insertions(+), 3 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..d659f9b 100644 --- a/libavcodec/pthread_slice.c +++ b/libavcodec/pthread_slice.c @@ -38,11 +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; + main_func *mainfunc; void *args; int *rets; int job_size; @@ -54,6 +56,12 @@ typedef struct SliceThreadContext { pthread_mutex_t *progress_mutex; } 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) { AVCodecContext *avctx = priv; @@ -99,7 +107,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->mainfunc ); 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); } +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) { SliceThreadContext *c; int thread_count = avctx->thread_count; + static void (*mainfunc)(void *); #if HAVE_W32THREADS w32thread_init(); @@ -142,7 +159,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) { + 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) avpriv_slicethread_free(&c->thread); av_freep(&avctx->internal->thread_ctx); diff --git a/libavcodec/thread.h b/libavcodec/thread.h index 90864b5..3186193 100644 --- a/libavcodec/thread.h +++ b/libavcodec/thread.h @@ -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_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); - int ff_alloc_entries(AVCodecContext *avctx, int count); void ff_reset_entries(AVCodecContext *avctx); void ff_thread_report_progress2(AVCodecContext *avctx, int field, int thread, int n);