From patchwork Tue Feb 1 13:06:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 34027 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2c4e:0:0:0:0 with SMTP id x14csp611456iov; Tue, 1 Feb 2022 05:21:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJyZxANX2x/ilqwey/DXAFHWY7BhrzoE/lMyHdrqPNAeI7JxDzCU+du1zLT9YPU1M1od85gP X-Received: by 2002:a50:ed16:: with SMTP id j22mr25815862eds.114.1643721680083; Tue, 01 Feb 2022 05:21:20 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id hr42si9568715ejc.818.2022.02.01.05.21.19; Tue, 01 Feb 2022 05:21:20 -0800 (PST) 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=@outlook.com header.s=selector1 header.b=gRoRRRuq; arc=fail (body hash mismatch); 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=QUARANTINE dis=NONE) header.from=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0F1B768B3DC; Tue, 1 Feb 2022 15:09:02 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05olkn2045.outbound.protection.outlook.com [40.92.91.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0B05468B3C6 for ; Tue, 1 Feb 2022 15:08:46 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MmNTXXyD5uAmZroiTK2tTeoM0ja1G3OsXXA29j5Xn7Ve1YusMDm6afQWqtoorZPo307PUDJ/TX3IQkTVRv72pqcEhEA2JwbA26iwuuKbUg3gGiFYFjFKZEdBUGMtbyb6BDOMAspbITHni/DzaC8QRnoblaox/lWmn/uD6l3vsnydG6lr7UAU7meoBVfMtufMciM4B099VDNDCZKBfilT9B4ZiJUeVFrl+k4yt/sWyWhdd1S3kSaiXBQmR+mHK0qEO4nnW5jITr5+uBgqOdywdEBUfVQ7sVkRwZ50JE5vTd2XS6X4OQlOFES4XsuDEEgsUQQYNseBOqCBgWTxHJhX/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=uBjdnAki5p2D7OfXfXAtIDiWfNkihoE1X2BP8WuzRbA=; b=jPQRfFVBuz7Y6A47gO3aeXCxckM5C8T6LxCfMeGmLPHxQCJ0JKWCG5wdiEyBxQKCj66tfrvoL4gPMrgfCh+OUv5sJ5rejoou+IEJo/vf38QV8ltXAh/6SeegBCkHkmaNFbf+AKxm/2KVDptKpypU+kAFoPVAoJ4SoPnkebFTQCchjWCv9P/8qCC2svOvXOI2ovTnvEagYOvDzxvdo+eRzUpVRZ2PjM0a/XGTTRRMuY72UO7eNgXRg0sBMOokh733unjN7UCgBdbL++7R90AgLlUGWs74S/HAsftQ2yzvCBKEWcLVQnl85ZNjJn/wqsKsToBwMLqrJmuHyYk5FL7Yvg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=uBjdnAki5p2D7OfXfXAtIDiWfNkihoE1X2BP8WuzRbA=; b=gRoRRRuq0GDFm3tEBQds54NtX4JGVgIlA8GNfmjyX0GvxznZxp/SczbscJqjEm5TJ3zbp3pf+sFqE6xY1nmt/P0W/bJDlrTrQLFvOD9ckmnzwVbDdY1Ds2AgECQ9ZHgB+EEX2WuN9TG+F+iIqDTCJdQNva1cwjqzslD7S7V4Y9QBhgWVNrEqxz7swPxcP8BEXKPzR8vaLVFAhhhWKXvKyyj/MzPMieOb8TnVOrHwU0fNzIbAB43A5wlAj+ES5U7Clwc5Pg/XcD51hA0aVbZp7NCT8Y7nrJpDlgXsg2IUPGNBbRK4Y9cijdI+xK43k95kf7hqC13AbQ5hyl4Pre+6zw== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM9PR03MB7962.eurprd03.prod.outlook.com (2603:10a6:20b:439::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.22; Tue, 1 Feb 2022 13:08:45 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::ac56:2ff4:d304:ab22]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::ac56:2ff4:d304:ab22%6]) with mapi id 15.20.4951.011; Tue, 1 Feb 2022 13:08:45 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 1 Feb 2022 14:06:55 +0100 Message-ID: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-TMN: [jTa4telLy9IxPHOHi/HcpgtedP6lFUTH] X-ClientProxiedBy: AM6P195CA0092.EURP195.PROD.OUTLOOK.COM (2603:10a6:209:86::33) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20220201130706.1420875-57-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1d9c9ad5-ab2d-46bc-31f8-08d9e583fa2e X-MS-TrafficTypeDiagnostic: AM9PR03MB7962:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: F/NiQbwBih84SeBd0MsksLW7BVMMCF8+n8zA0SoywmYowff0w07Dv0b6v8c5HrqsKyXY7oLwLC8Q6E/O+EvfzBs7UpyHqdxuNOWZMKs70LLBAfWfjAI+3avw1wi4IrOSwBlUwm0cdJ51GpLCZdLF2HwuXzyNABPw4COyE2GR+T+MljlIEGUnQdFCIyrm60nsrrrmFYGKW7vFhyj0hA7Yng31pil6VZJ0yM/rnd9fjrrjYSuPX4eDf55eOK+qrvEq4vQRMNm1N+ZfCQEPYXK+l02LS+ezBhkTaIMIMKh43F+CK3sQcH564Oj29+Ahlj8Cc6dYL0YX9d8YZ58L76RTu16bcUU21zP+ABDi8lTd88Q6EeueJ0rKtTtLLNiwKBiOaQ9dBwOQzON6w33MRGVhK36jUm7+ccSwrcmO5NsAWOjRUADlh4sjMLEAjHqZXPmtuf9xSCJIRPGnMKFXF95xnLUwnET2iqF2AQnj0CPJ6egnNo/8pMm/RagDTTP6pTSGKSomN/LYCv6uyDdL6AmkKMVphWU12d7LQ7TMtvSqF1c= X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: nplhTCE+g2383LuFKrd2ibl7jhWvO5Gyi/xmfPTdDeiNie8mHbdbuBZhETZvVkX59vE71QyrctC1kHc2Ex7LkG3Ff0V+L2MxzOpxwnMDHNt8HUgLaKuh2DsCRjlKiAwUWJB1LNwdSNS7zn1alJhybZVJK2d1jIHqIikO/M9LKDms56pHExrS9H1mogj9gjEPwhZZ2EXFJKDqSGgUnlS1gFqVmpnnNDcV05nzkT8kLJ0mJZE3wAp4o1q4ouWT7wmhQANe6Igw6IlM72d0yFu3R+hGlAzHn9ZlxheSdbwPtdrCjnIFar0ko79EaM4H9Euu9vbEnG1PX/2c2CePf51dC4ISY1ygi5wjZxtmOC1yqUuPj5u0kRAfTFkrzvnzxJGf/xskfa5TQMsJ32ke2BFSfg9jpgJw9ZeDay1V7hW9IS8bgWpokOZlG2MclHhgiZmgnF2rEDSf/pMDAw4WzMaIO9xfeed2hmHEyQa4GP0Lr2kvNaYClOoux4Acx739KrmD7lGupim0YgqIkZfpW3qPFUp+xtwHHuxxksiF6FVc/AHb00IPkS8w8DxtliNwdXoQrqfQm6GzWw6HAvnhRVlw6D3CWUkRSfyG2mqEr5te7iNuPGvvnhzox3aI9buX64EQC7pqprXWUniCMa7jMMrtYEcZEJgYlf/6s6yuaHl+AOmFPdrP57l528EomUUvNm0ustQ2vvkwM8pdwfXd3t3mbDh5lf/8m2MiX2CtovpOxx085ZtTwypSg5NhWuwk+wY5kSk0koH9Mc9O+KoOnevv9q47OQ272zT6VU/6346qhZATRN3WCT4no8wNvrf+BEA+4eH+FuPFIWz737bvTVHYBMyY3uQeBySDEmt6a7ab1AdF4r24Aeiwa2HItzxSLUEJ2WGxyjZE+g9/4o2WEiq9ihpiaWNBfLPEtY7/7mBddNrvTN0toINVCADjK28tNHR3ZJDQQg2V9nqJcrsMwZEmqg== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1d9c9ad5-ab2d-46bc-31f8-08d9e583fa2e X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Feb 2022 13:08:45.1455 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR03MB7962 Subject: [FFmpeg-devel] [PATCH v2 58/69] avcodec/mpegvideo: Move slice-context ptr array to MPVMainContext X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: VZzfAr/SZ+kT The slice contexts don't have sub-slice contexts, so it makes no sense for them to have an array of pointers to slice contexts. Signed-off-by: Andreas Rheinhardt --- libavcodec/mjpegenc.c | 2 +- libavcodec/mpeg12dec.c | 12 ++++++------ libavcodec/mpegvideo.c | 21 ++++++++++----------- libavcodec/mpegvideo.h | 3 ++- libavcodec/mpegvideo_dec.c | 11 ++++++----- libavcodec/mpegvideo_enc.c | 29 +++++++++++++++-------------- 6 files changed, 40 insertions(+), 38 deletions(-) diff --git a/libavcodec/mjpegenc.c b/libavcodec/mjpegenc.c index faf59566b1..70636ffc91 100644 --- a/libavcodec/mjpegenc.c +++ b/libavcodec/mjpegenc.c @@ -86,7 +86,7 @@ static void mjpeg_encode_picture_header(MPVMainEncContext *m) s->esc_pos = put_bytes_count(&s->pb, 0); for (int i = 1; i < s->slice_context_count; i++) - s->thread_context[i]->esc_pos = 0; + m2->thread_context[i]->esc_pos = 0; } void ff_mjpeg_amv_encode_picture_header(MPVMainEncContext *main) diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c index ef2fa80aba..925c72e8ff 100644 --- a/libavcodec/mpeg12dec.c +++ b/libavcodec/mpeg12dec.c @@ -2503,10 +2503,10 @@ static int decode_chunks(AVCodecContext *avctx, AVFrame *picture, av_assert0(avctx->thread_count > 1); avctx->execute(avctx, slice_decode_thread, - &s2->thread_context[0], NULL, + &m2->thread_context[0], NULL, s->slice_count, sizeof(void *)); for (i = 0; i < s->slice_count; i++) - s2->er.error_count += s2->thread_context[i]->er.error_count; + s2->er.error_count += m2->thread_context[i]->er.error_count; } ret = slice_end(avctx, picture); @@ -2575,10 +2575,10 @@ static int decode_chunks(AVCodecContext *avctx, AVFrame *picture, int i; avctx->execute(avctx, slice_decode_thread, - s2->thread_context, NULL, + m2->thread_context, NULL, s->slice_count, sizeof(void *)); for (i = 0; i < s->slice_count; i++) - s2->er.error_count += s2->thread_context[i]->er.error_count; + s2->er.error_count += m2->thread_context[i]->er.error_count; s->slice_count = 0; } if (last_code == 0 || last_code == SLICE_MIN_START_CODE) { @@ -2774,12 +2774,12 @@ static int decode_chunks(AVCodecContext *avctx, AVFrame *picture, s2->slice_context_count; av_assert0(avctx->thread_count > 1); if (threshold <= mb_y) { - MPVDecContext *const thread_context = s2->thread_context[s->slice_count]; + MPVDecContext *const thread_context = m2->thread_context[s->slice_count]; thread_context->start_mb_y = mb_y; thread_context->end_mb_y = s2->mb_height; if (s->slice_count) { - s2->thread_context[s->slice_count - 1]->end_mb_y = mb_y; + m2->thread_context[s->slice_count - 1]->end_mb_y = mb_y; ret = ff_update_duplicate_context(thread_context, s2); if (ret < 0) return ret; diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index 072a82e6b3..220f1c39f0 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -400,14 +400,15 @@ int ff_mpv_init_duplicate_contexts(MPVMainContext *m) * fields allocated in init_duplicate_context are NULL after * copying. This prevents double-frees upon allocation error. */ for (int i = 1; i < nb_slices; i++) { - s->thread_context[i] = av_memdup(s, sizeof(MPVContext)); - if (!s->thread_context[i]) + MPVContext *const s2 = av_memdup(s, sizeof(MPVContext)); + if (!s2) return AVERROR(ENOMEM); - if ((ret = init_duplicate_context(s->thread_context[i])) < 0) + m->thread_context[i] = s2; + if ((ret = init_duplicate_context(s2)) < 0) return ret; - s->thread_context[i]->start_mb_y = + s2->start_mb_y = (s->mb_height * (i ) + nb_slices / 2) / nb_slices; - s->thread_context[i]->end_mb_y = + s2->end_mb_y = (s->mb_height * (i + 1) + nb_slices / 2) / nb_slices; } s->start_mb_y = 0; @@ -441,8 +442,8 @@ static void free_duplicate_contexts(MPVMainContext *m) MPVContext *const s = &m->s; for (int i = 1; i < s->slice_context_count; i++) { - free_duplicate_context(s->thread_context[i]); - av_freep(&s->thread_context[i]); + free_duplicate_context(m->thread_context[i]); + av_freep(&m->thread_context[i]); } free_duplicate_context(s); } @@ -621,8 +622,7 @@ static void clear_context(MPVMainContext *m) memset(&s->current_picture, 0, sizeof(s->current_picture)); memset(&s->new_picture, 0, sizeof(s->new_picture)); - memset(s->thread_context, 0, sizeof(s->thread_context)); - + s->slice_context_count = 1; s->me.map = NULL; s->me.score_map = NULL; s->dct_error_sum = NULL; @@ -736,8 +736,7 @@ av_cold int ff_mpv_common_init(MPVMainContext *m) #endif s->context_initialized = 1; - memset(s->thread_context, 0, sizeof(s->thread_context)); - s->thread_context[0] = s; + m->thread_context[0] = s; s->slice_context_count = nb_slices; // if (s->width && s->height) { diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 9adadc5b02..9005dcb58a 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -120,7 +120,6 @@ typedef struct MPVContext { int start_mb_y; ///< start mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y) int end_mb_y; ///< end mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y) - struct MPVContext *thread_context[MAX_THREADS]; int slice_context_count; ///< number of used thread_contexts /** @@ -506,6 +505,8 @@ typedef struct MPVContext { */ typedef struct MPVMainContext { MPVContext s; + /* The first entry of this array points to the above MPVContext. */ + MPVContext *thread_context[MAX_THREADS]; } MPVMainContext; /** diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c index e70e306cf9..f202db33e9 100644 --- a/libavcodec/mpegvideo_dec.c +++ b/libavcodec/mpegvideo_dec.c @@ -197,13 +197,14 @@ do {\ int ff_mpv_common_frame_size_change(MPVMainDecContext *m) { + MPVMainContext *const m2 = m; MPVDecContext *const s = &m->s; int err = 0; if (!s->context_initialized) return AVERROR(EINVAL); - ff_mpv_free_context_frame(m); + ff_mpv_free_context_frame(m2); if (s->picture) for (int i = 0; i < MAX_PICTURE_COUNT; i++) @@ -233,11 +234,11 @@ int ff_mpv_common_frame_size_change(MPVMainDecContext *m) if ((err = ff_mpv_init_context_frame(m))) goto fail; - memset(s->thread_context, 0, sizeof(s->thread_context)); - s->thread_context[0] = s; + memset(m2->thread_context, 0, sizeof(m2->thread_context)); + m2->thread_context[0] = s; if (s->width && s->height) { - err = ff_mpv_init_duplicate_contexts(m); + err = ff_mpv_init_duplicate_contexts(m2); if (err < 0) goto fail; } @@ -245,7 +246,7 @@ int ff_mpv_common_frame_size_change(MPVMainDecContext *m) return 0; fail: - ff_mpv_free_context_frame(m); + ff_mpv_free_context_frame(m2); s->context_reinit = 1; return err; } diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 656aab04cf..735c9d322f 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -1778,13 +1778,13 @@ int ff_mpv_encode_picture(AVCodecContext *avctx, AVPacket *pkt, } for (i = 0; i < context_count; i++) { - int start_y = s->thread_context[i]->start_mb_y; - int end_y = s->thread_context[i]-> end_mb_y; + int start_y = m2->thread_context[i]->start_mb_y; + int end_y = m2->thread_context[i]-> end_mb_y; int h = s->mb_height; uint8_t *start = pkt->data + (size_t)(((int64_t) pkt->size) * start_y / h); uint8_t *end = pkt->data + (size_t)(((int64_t) pkt->size) * end_y / h); - init_put_bits(&s->thread_context[i]->pb, start, end - start); + init_put_bits(&m2->thread_context[i]->pb, start, end - start); } s->pict_type = s->new_picture.f->pict_type; @@ -1838,7 +1838,7 @@ vbv_retry: s->last_non_b_time = s->time - s->pp_time; } for (i = 0; i < context_count; i++) { - PutBitContext *pb = &s->thread_context[i]->pb; + PutBitContext *pb = &m2->thread_context[i]->pb; init_put_bits(pb, pb->buf, pb->buf_end - pb->buf); } s->vbv_ignore_qmax = 1; @@ -3602,7 +3602,7 @@ static int encode_picture(MPVMainEncContext *m, int picture_number) s->mb_intra=0; //for the rate distortion & bit compare functions for(i=1; ithread_context[i], s); + ret = ff_update_duplicate_context(m2->thread_context[i], s); if (ret < 0) return ret; } @@ -3617,11 +3617,11 @@ static int encode_picture(MPVMainEncContext *m, int picture_number) if (s->pict_type != AV_PICTURE_TYPE_B) { if ((m->me_pre && m->last_non_b_pict_type == AV_PICTURE_TYPE_I) || m->me_pre == 2) { - s->avctx->execute(s->avctx, pre_estimate_motion_thread, &s->thread_context[0], NULL, context_count, sizeof(void*)); + s->avctx->execute(s->avctx, pre_estimate_motion_thread, &m2->thread_context[0], NULL, context_count, sizeof(void*)); } } - s->avctx->execute(s->avctx, estimate_motion_thread, &s->thread_context[0], NULL, context_count, sizeof(void*)); + s->avctx->execute(s->avctx, estimate_motion_thread, &m2->thread_context[0], NULL, context_count, sizeof(void*)); }else /* if(s->pict_type == AV_PICTURE_TYPE_I) */{ /* I-Frame */ for(i=0; imb_stride*s->mb_height; i++) @@ -3629,11 +3629,11 @@ static int encode_picture(MPVMainEncContext *m, int picture_number) if (!m->fixed_qscale) { /* finding spatial complexity for I-frame rate control */ - s->avctx->execute(s->avctx, mb_var_thread, &s->thread_context[0], NULL, context_count, sizeof(void*)); + s->avctx->execute(s->avctx, mb_var_thread, &m2->thread_context[0], NULL, context_count, sizeof(void*)); } } for(i=1; ithread_context[i]); + merge_context_after_me(s, m2->thread_context[i]); } s->current_picture.mc_mb_var_sum= s->current_picture_ptr->mc_mb_var_sum= s->me.mc_mb_var_sum_temp; s->current_picture. mb_var_sum= s->current_picture_ptr-> mb_var_sum= s->me. mb_var_sum_temp; @@ -3819,13 +3819,14 @@ static int encode_picture(MPVMainEncContext *m, int picture_number) m->header_bits = bits - s->last_bits; for(i=1; ithread_context[i], s); + update_duplicate_context_after_me(m2->thread_context[i], s); } - s->avctx->execute(s->avctx, encode_thread, &s->thread_context[0], NULL, context_count, sizeof(void*)); + s->avctx->execute(s->avctx, encode_thread, &m2->thread_context[0], NULL, context_count, sizeof(void*)); for(i=1; ipb.buf_end == s->thread_context[i]->pb.buf) - set_put_bits_buffer_size(&s->pb, FFMIN(s->thread_context[i]->pb.buf_end - s->pb.buf, INT_MAX/8-BUF_BITS)); - merge_context_after_encode(s, s->thread_context[i]); + MPVEncContext *const slice = m2->thread_context[i]; + if (s->pb.buf_end == slice->pb.buf) + set_put_bits_buffer_size(&s->pb, FFMIN(slice->pb.buf_end - s->pb.buf, INT_MAX/8-BUF_BITS)); + merge_context_after_encode(s, slice); } emms_c(); return 0;