From patchwork Sun Aug 27 19:22:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilia X-Patchwork-Id: 4859 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.15.201 with SMTP id 70csp1737699jao; Sun, 27 Aug 2017 12:29:45 -0700 (PDT) X-Received: by 10.28.51.200 with SMTP id z191mr2255437wmz.193.1503862184998; Sun, 27 Aug 2017 12:29:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1503862184; cv=none; d=google.com; s=arc-20160816; b=bftFejpkXnQ8jeLO4wZX8YaRMI0mYhru7eYe5rI3/v7kA6I92kZliIMbGasBEOj164 /FgMfVpta6mSfPROuR9S5xaIjqN6DAtZxcdyJXkJ0q8tx7vaURCPx8mcNAGvDXU5wWEP A1jaAHcjMc5JV2CpqumlF0NgD3LQmlyh1Z4H1hXouhCqYyB0Vx0s1U+DAxxUVqy/kOr2 SGyypKS01LqDBAllfeLXFctiQg7EVSw9dOgh5wZNBEHQkJDOYwkmmfTjRNcYU7CIsFhu vEI6lQhh8YkhOTzjyuZ08obIEziPkfp3fkxyXIF/oVnHFk3gOXxGaQ1RFikO/7zOiDdx Q59Q== 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=IbuaROhtxi3MJh47mioTP1Karot8m3EQSLw1hOMTbug=; b=jdyRwTsV1XDnnqIVtc3QbBovZNFDvYsY9OsU2cRdfFpsHl0ti7Ak+whjSTWMrqJfyz 9GXrH5h2T1EPlAeLQUHr0AnEUPDerk5hs862qIcby5vWNa2lgTaR3FkBSAT+so746dcG 4Vn6PDdLad45F8rtPcrAlEpjcqxTG48mCCnwbToEFPy79DCDq2fqgKb+hLc00BgMVKG5 mJmmaNn93rOxdZbfeJ+bnTKXYgBWEg9kL3uSwk1seDN0AIhOO3jprK5wQGMhUkV8sv82 n6Mhoa7IqQ+d6v1hnA/mKG/qTxaUDVs6g4O7drvaa6pDMfPVJ3BdNX/R0QJ9qXQCR/3D 4+Bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=d6Ytdsgc; 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 s79si9259033wrc.155.2017.08.27.12.29.44; Sun, 27 Aug 2017 12:29:44 -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=d6Ytdsgc; 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 09BAD689CFA; Sun, 27 Aug 2017 22:29:32 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf0-f67.google.com (mail-lf0-f67.google.com [209.85.215.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B63E368038A for ; Sun, 27 Aug 2017 22:29:24 +0300 (EEST) Received: by mail-lf0-f67.google.com with SMTP id g77so2672710lfg.2 for ; Sun, 27 Aug 2017 12:29:34 -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=G3EXE8ZeyQ3AHon9tsU+7T23AimJYZ3+yJcsJNXUJUM=; b=d6YtdsgcAaAW0YGmgie5rq8pLt1BI8741Mkq8jZBZFvTosmMRtxpPGi3YE9nIaIz8V BjqtuSQw+05XYOyrhZClfKVKzvcXNrGnyRwZLam1p1xYOiGoxiEw3F7M7cbq17kW9/Vj dg5ujnt1U+4ZcnSLnMpPlAP/k4ekkXhU5ezMHYPBg2u92HEURK9eFC031AXJwRlvbYXw yoDyeibLH6DDCP4VQi95GV3XXFV40o3TKLt892uEfhMtOrP7OU+h8dojJlrHGA+Gn8JV SmAL02O7wdQfF5nEiBmQ7Mi8vUKEhwusUT64VHgacYqTCKYL7yys/keKsd+SztWzeVHU IBng== 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=G3EXE8ZeyQ3AHon9tsU+7T23AimJYZ3+yJcsJNXUJUM=; b=Nil0MDL3sSFgdOXcmm3L7dOLDTX0wzkewp8yKVRmecMsgKk7XdGLZefF6jmDP40rrr vSEoAlOHO18qPZfwTyZT92uBx1BRHpjt98Xuz5c8js6uvQIZfSTBtFPx3+a2br2To2FK Xs2b3uWNyPeTOLHAhaDbme/v4W+qxAxQXt7Rn4arLNZzMUuVDpsPQrczJVOyX7LYXWTF liO6EwLvU/fCloygyGRxsxNoK7p2kaPmEVF7PKF9JYXAXLL+IobfLeLqBJ0Haq6mAwyn Xvpp6Nbr9lV2upfZua53xlSbDVq6Ibnu3cuIsE79MTtztPhlbKd6l8bOFn8vCx9pXLFX oXdA== X-Gm-Message-State: AHYfb5jXBDXigNdQo3XjVNy4VR3gE9N7HLK9ETfmNT9z5U6ZhuA2F2Sc yn0vImDLGqVYmm9i X-Received: by 10.46.64.85 with SMTP id n82mr2160156lja.120.1503861769963; Sun, 27 Aug 2017 12:22:49 -0700 (PDT) Received: from localhost.localdomain ([176.51.136.198]) by smtp.gmail.com with ESMTPSA id s203sm1950586lja.59.2017.08.27.12.22.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 27 Aug 2017 12:22:49 -0700 (PDT) From: Ilia Valiakhmetov To: ffmpeg-devel@ffmpeg.org Date: Mon, 28 Aug 2017 02:22:16 +0700 Message-Id: <20170827192217.6972-2-zakne0ne@gmail.com> X-Mailer: git-send-email 2.8.3 In-Reply-To: <20170827192217.6972-1-zakne0ne@gmail.com> References: <20170827192217.6972-1-zakne0ne@gmail.com> Subject: [FFmpeg-devel] [PATCH 1/2] avcodec: add execute3() api to utilize the main function of 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" Signed-off-by: Ilia Valiakhmetov --- libavcodec/avcodec.h | 7 ++++++- libavcodec/options.c | 1 + libavcodec/pthread_slice.c | 27 +++++++++++++++++++++++++-- libavcodec/utils.c | 13 +++++++++++++ 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 6555550..712f40c 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -1089,6 +1089,10 @@ typedef struct RcOverride{ */ #define AV_CODEC_CAP_AVOID_PROBING (1 << 17) /** + * Codec initializes slice-based threading with a main function + */ +#define AV_CODEC_SLICE_THREAD_HAS_MF (1 << 18) +/** * Codec is intra only. */ #define AV_CODEC_CAP_INTRA_ONLY 0x40000000 @@ -3233,7 +3237,7 @@ typedef struct AVCodecContext { * - decoding: Set by libavcodec, user can override. */ int (*execute2)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg, int jobnr, int threadnr), void *arg2, int *ret, int count); - + int (*execute3)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg, int jobnr, int threadnr), int (*m_func)(struct AVCodecContext *c3), void *arg2, int *ret, int count); /** * noise vs. sse weight for the nsse comparison function * - encoding: Set by user. @@ -5774,6 +5778,7 @@ const char *avcodec_profile_name(enum AVCodecID codec_id, int profile); int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size); int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int, int),void *arg, int *ret, int count); +int avcodec_default_execute3(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int jobnr, int threadnr), int (*m_func)(struct AVCodecContext *c3), void *arg, int *ret, int count); //FIXME func typedef /** diff --git a/libavcodec/options.c b/libavcodec/options.c index 82e1217..6d63bdb 100644 --- a/libavcodec/options.c +++ b/libavcodec/options.c @@ -117,6 +117,7 @@ static int init_context_defaults(AVCodecContext *s, const AVCodec *codec) s->get_format = avcodec_default_get_format; s->execute = avcodec_default_execute; s->execute2 = avcodec_default_execute2; + s->execute3 = avcodec_default_execute3; s->sample_aspect_ratio = (AVRational){0,1}; s->pix_fmt = AV_PIX_FMT_NONE; s->sw_pix_fmt = AV_PIX_FMT_NONE; diff --git a/libavcodec/pthread_slice.c b/libavcodec/pthread_slice.c index c781d35..08d19b9 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 *m_func; 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->m_func(avctx); +} + static void worker_func(void *priv, int jobnr, int threadnr, int nb_jobs, int nb_threads) { AVCodecContext *avctx = priv; @@ -99,7 +107,8 @@ 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; } @@ -110,10 +119,20 @@ static int thread_execute2(AVCodecContext *avctx, action_func2* func2, void *arg return thread_execute(avctx, NULL, arg, ret, job_count, 0); } +static int thread_execute3(AVCodecContext *avctx, action_func2* func2, main_func* m_func, void *arg, int *ret, int job_count) +{ + SliceThreadContext *c = avctx->internal->thread_ctx; + c->func2 = func2; + c->m_func = m_func; + 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 (*m_f)(void *); #if HAVE_W32THREADS w32thread_init(); @@ -142,7 +161,9 @@ 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) { + m_f = avctx->codec->capabilities & AV_CODEC_SLICE_THREAD_HAS_MF ? &main_function : NULL; + + if (!c || (thread_count = avpriv_slicethread_create(&c->thread, avctx, worker_func, m_f, thread_count)) <= 1) { if (c) avpriv_slicethread_free(&c->thread); av_freep(&avctx->internal->thread_ctx); @@ -150,10 +171,12 @@ 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->execute2 = thread_execute2; + avctx->execute3 = thread_execute3; return 0; } diff --git a/libavcodec/utils.c b/libavcodec/utils.c index baf4992..b7a9f56 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -558,6 +558,19 @@ int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, return 0; } +int avcodec_default_execute3(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int jobnr, int threadnr), int (*m_func)(struct AVCodecContext *c3), void *arg, int *ret, int count) +{ + int i; + m_func(c); + for (i = 0; i < count; i++) { + int r = func(c, arg, i, 0); + if (ret) + ret[i] = r; + } + emms_c(); + return 0; +} + enum AVPixelFormat avpriv_find_pix_fmt(const PixelFormatTag *tags, unsigned int fourcc) {