From patchwork Tue Feb 1 13:07:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 34038 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2c4e:0:0:0:0 with SMTP id x14csp613527iov; Tue, 1 Feb 2022 05:24:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJw8H6wFeT+fvV411SE9Ek/PwE8ue7kblLhFyaAgAwkH6lRanzQA8DJWOPFSwQM7U9K0+gR5 X-Received: by 2002:a17:906:fcd8:: with SMTP id qx24mr20626784ejb.391.1643721848969; Tue, 01 Feb 2022 05:24:08 -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 hv11si9011976ejc.176.2022.02.01.05.24.08; Tue, 01 Feb 2022 05:24:08 -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=ZekbRk9w; 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 5D0A668B485; Tue, 1 Feb 2022 15:09:32 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-oln040092074079.outbound.protection.outlook.com [40.92.74.79]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D62BC68B360 for ; Tue, 1 Feb 2022 15:09:28 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BYGkx5+28rtTsEWWByxybE0Mo9MsHuwaupOFwIc+q71zoJOg6H/H4MD8huVzrsOUsaWfndXcpWWUJTFokMzeRLJ2saG5T6d8DQjIdmkM+ShiGA41Cn2aTyb75gEQ+tcm9II5ot9zo4rnRXUCPsEjalPHKXyaEG1sOQqjPo2OAb9z8Vwp2R0ZhAr24z6NOrbM1LhUEtwzDGiumyj7gYBNovpqijutNr7DLwrQdAk7/TOUp04hd5KlTbdR/jw0hWr/oTv5qwBnY2I8d4m2FU4Y0xRD4px7lmw0tjAayQmA3787hSERohTJZsq/QEHdzsj2xd8b3HxvjYH171YybJeX4Q== 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=OI6slrNh4T5950gGm0UiYJQWugBVyh+Atsq1A4eeBKI=; b=RSG5v2WhS7SIzpqihntwKEB4XReGWgw4LpYRs9+MufpBxDUXk1v2dROG427df6S96IIUlU7mndE3OBnOARjxdHK/A6Pyp7yIYNzJ/U3MNZZJCT7bN5UdaGX+lhxOR9dGg0stnnVKIBfM57d66rSgNGE7cvND5K40fHhIJgETy6JKuaKkuFohJCNAnybkmXFWYVPEYLiUTiqdevDulTyyTNEDDNh2wSUBEVmKBLjzGiiJdRa4MAr6vw8muAREfn0zMAmYkC2q0axga4I7GhcJPIAVsoYxfwvrpn8t2sREs9Yk8fliewVWC3MB3ramzTZxm0+OP65bUOVDb5bL8w5FPA== 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=OI6slrNh4T5950gGm0UiYJQWugBVyh+Atsq1A4eeBKI=; b=ZekbRk9wz9g7kzwe48YFFTh4w9h2V7OIvCy4KggAI+9r7HVhslBjoB39goxngI4FzTmSa6FwxN95+qIPuch+joOHqxtH8aoslWLHXUCzqDbTRl6mJtxA2La0PejoXXNFmIYxRExna6/YQSJFJC3a/XBBto5C4CH1Aq4FoT5GM2E7FfCuvuIlJwkQDql6VjShr9CGGLl/G3IVuWrHCBg/X2I20TEdu5pVhrVgTr4+EGO/GLiONfoMaj2u7uYe60qp9qSRqpCp3+oynljkkHES681iaOh/700jZzu/VbwULX0rFeM0pkKbIoe+4MWCmG6zC6+c3bCX0MJrlAOYCnT0gQ== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM0PR03MB5025.eurprd03.prod.outlook.com (2603:10a6:208:102::19) 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:09:27 +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:09:27 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 1 Feb 2022 14:07:06 +0100 Message-ID: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-TMN: [VTVOJUyQxQ/kW9HQIIfMMmM9jmHdAG2E] 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-68-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5e510dcd-02de-4b21-35e3-08d9e584041e X-MS-TrafficTypeDiagnostic: AM0PR03MB5025:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: z2xfpTV5p97IZU3qzaDSGV3ucX2cOk9g/owv7Zft3KrjrSLt2fzkRMXVTwGHfgtfznHSZEiQJTzngxzfK+E+YJYNpfXknol48jhpuClMu6cr1rqSBtBPU1Ga9RoaOOG3W9rQztAfPGYGGLhZ9mSe7HprXMIolh6rnR5ivps6Aywv5aUQrt1wn2LZjO/x926ExUoEEnzNbY6vSPByC9Q+EUqzZrX+lZnPNGpoaOFAxHlfL1sYkMsipTXFqRMCif10Uk+xLx8MUEUfwTgxg0LuakJFs9P1LwXgD84izociZg6puuXbFW4vSssyS/r8FA0zaEAjH1fSWE7ACXvyNuEILGhUpVWtXVaOK34z8p3r70IXjvfq9NF4Lw5tjbYQAa8e1Z68jTk5Npk6NPr/N7FfuOYOcM2/h6ZGxJ/vh0L/l0LRH9ZrIgwZycmeau8aiQ8ySiJH2co/7nI+Ey7IqxjsP7vZdPSa2YX3WZGEnzPeLTGxAAzX400KJCfK/CzSqnDKIE4DVIWluq+oeqpn/HPlLL7//4L9vub3JfB3hPdPnhg= X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 2/OGomu4ATkkfB8+FbZFMxZfcd2gRVdGujyeOG/lixQWjHkBrQNmrrJIxr4dy1KM/TLMnsnRC+MFC5aCmOjZ7+M7FksG8BsNghxajNRRjeKELZS/yXmdD3OOISDo4kNAdpW4l5wBagbTYdSJu7WYARzPSLPWIo9eyU7n14kDwet2YvXozeoAXCnslzeIrEG6WRABsCK9tqlwGi+jGYdvWbhxm5DixZfBgLZEotcLfrueB4/frQYNzYhygUmKrX+P2IKZGxFZDVMw9nN4hN9/OsD6Qb1maDV151mI38ekDxNqpaRu130zxEH6BCT9ikhsYlVw0BQ63lFZtEnxay9vpaZm1Ag+T8V0kMZyIc0GdDXNqcEvGZ8HDNI/RpCV5rnu6SiKu6UOlUbQtLhWFq9FyBFenj856ZAK7WlBq5qbR7L1jMtQxvj4arpBZJqa+tiLnIbMQiP41I91k0FWk6Y0DBh+X463/ljk1cGR47pz00bGOoCANAM2Ij49P8w5mhIl/4yt1HVSL/XeAA8jOqjdhCozBYFAZpBEYRm85nsCDTF2XvqANvA2SR1VgArP+zSf71mTB9ZApJJGfMHAP6+mqZoWxE49sIwmyxu3wre+RLLJxPIwriTYu/j+kQTo3F5ryy6oPF+VDwczaj3xlEXcNBpnBzWrlC5eSKkRB7h8RFqFk7HeiTFd2lVQXpycDmjdWKBWXDQYmfzEj4BI6LFY/RrEsyCenohP91hy94trLikVdfoijEF866yXUnN8MhER05KQUJWDq8HDe3CZuu1RMiyQv9VNqzoSn7VhvgjSGW3BYcfUvtY/P54Ba5/P5i05CFKiGwXtRhQfW1ZfkYy8mIkTw/LhYkybCv4F2ULU33+nPpRf8+IlSBzAYApfoXfWQ/SVjrisGUsoQYVxyn/a+LXkUbDriukcclWVRa6hZlVlIOfISjxkDz8Udm3alY7Ug6OUiOdPZw0/aJ9jfqIF5g== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5e510dcd-02de-4b21-35e3-08d9e584041e 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:09:01.8119 (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: AM0PR03MB5025 Subject: [FFmpeg-devel] [PATCH v2 69/69] avcodec/mpegvideo: Move picture 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: h6u3wYtAIG5E Also avoid an allocation while at it. Signed-off-by: Andreas Rheinhardt --- libavcodec/h263dec.c | 7 ++--- libavcodec/mpegvideo.c | 14 +++------- libavcodec/mpegvideo.h | 5 +++- libavcodec/mpegvideo_dec.c | 54 +++++++++++++++++++------------------- libavcodec/mpegvideo_enc.c | 12 ++++----- 5 files changed, 45 insertions(+), 47 deletions(-) diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c index b502878a4a..dc09d2e15c 100644 --- a/libavcodec/h263dec.c +++ b/libavcodec/h263dec.c @@ -431,7 +431,8 @@ int ff_h263_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) { MPVMainDecContext *const m = avctx->priv_data; - MPVDecContext *const s = &m->s; + MPVMainContext *const m2 = m; + MPVDecContext *const s = &m2->s; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; int ret; @@ -547,10 +548,10 @@ retry: } if (!s->current_picture_ptr || s->current_picture_ptr->f->data[0]) { - int i = ff_find_unused_picture(s->avctx, s->picture, 0); + int i = ff_find_unused_picture(s->avctx, m2->picture, 0); if (i < 0) return i; - s->current_picture_ptr = &s->picture[i]; + s->current_picture_ptr = &m2->picture[i]; } avctx->has_b_frames = !s->low_delay; diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index c8eaafcc1c..7314f1b39e 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -645,7 +645,6 @@ static void clear_context(MPVMainContext *m) s->bitstream_buffer = NULL; s->allocated_bitstream_buffer_size = 0; - s->picture = NULL; for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) s->p_field_mv_table[i][j] = NULL; @@ -713,11 +712,9 @@ av_cold int ff_mpv_common_init(MPVMainContext *m) if (ret) return ret; - if (!FF_ALLOCZ_TYPED_ARRAY(s->picture, MAX_PICTURE_COUNT)) - return AVERROR(ENOMEM); for (i = 0; i < MAX_PICTURE_COUNT; i++) { - s->picture[i].f = av_frame_alloc(); - if (!s->picture[i].f) + m->picture[i].f = av_frame_alloc(); + if (!m->picture[i].f) goto fail_nomem; } @@ -801,11 +798,8 @@ void ff_mpv_common_end(MPVMainContext *m) if (!s->avctx) return; - if (s->picture) { - for (int i = 0; i < MAX_PICTURE_COUNT; i++) - ff_mpv_picture_free(s->avctx, &s->picture[i]); - } - av_freep(&s->picture); + for (int i = 0; i < MAX_PICTURE_COUNT; i++) + ff_mpv_picture_free(s->avctx, &m->picture[i]); ff_mpv_picture_free(s->avctx, &s->last_picture); ff_mpv_picture_free(s->avctx, &s->current_picture); ff_mpv_picture_free(s->avctx, &s->next_picture); diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index af1d9af2bd..ba081a9087 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -110,7 +110,6 @@ typedef struct MPVContext { int mb_num; ///< number of MBs of a picture ptrdiff_t linesize; ///< line size, in bytes, may be different from width ptrdiff_t uvlinesize; ///< line size, for chroma in bytes, may be different from width - Picture *picture; ///< main picture buffer /** bit output */ PutBitContext pb; @@ -498,6 +497,10 @@ typedef struct MPVContext { typedef struct MPVMainContext { MPVContext s; + /* The main picture buffer. The pictures therein are usable iff + * the context is initialized. */ + Picture picture[MAX_PICTURE_COUNT]; + int context_initialized; /* flag to indicate a reinitialization is required, e.g. after * a frame size change */ diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c index 137b47efa7..8f3c401aff 100644 --- a/libavcodec/mpegvideo_dec.c +++ b/libavcodec/mpegvideo_dec.c @@ -111,12 +111,11 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst, m->coded_picture_number = m1->coded_picture_number; s->picture_number = s1->picture_number; - av_assert0(!s->picture || s->picture != s1->picture); - if (s->picture) + if (m->context_initialized) for (int i = 0; i < MAX_PICTURE_COUNT; i++) { - ff_mpeg_unref_picture(s->avctx, &s->picture[i]); - if (s1->picture && s1->picture[i].f->buf[0] && - (ret = ff_mpeg_ref_picture(s->avctx, &s->picture[i], &s1->picture[i])) < 0) + ff_mpeg_unref_picture(s->avctx, &m->picture[i]); + if (m1->context_initialized && m1->picture[i].f->buf[0] && + (ret = ff_mpeg_ref_picture(s->avctx, &m->picture[i], &m1->picture[i])) < 0) return ret; } @@ -138,9 +137,9 @@ do {\ #define REBASE_PICTURE(pic, new_ctx, old_ctx) \ ((pic) ? &(new_ctx)->picture[(pic) - (old_ctx)->picture] : NULL) - s->last_picture_ptr = REBASE_PICTURE(s1->last_picture_ptr, s, s1); - s->current_picture_ptr = REBASE_PICTURE(s1->current_picture_ptr, s, s1); - s->next_picture_ptr = REBASE_PICTURE(s1->next_picture_ptr, s, s1); + s->last_picture_ptr = REBASE_PICTURE(s1->last_picture_ptr, m, m1); + s->current_picture_ptr = REBASE_PICTURE(s1->current_picture_ptr, m, m1); + s->next_picture_ptr = REBASE_PICTURE(s1->next_picture_ptr, m, m1); // Error/bug resilience s->workaround_bugs = s1->workaround_bugs; @@ -208,9 +207,8 @@ int ff_mpv_common_frame_size_change(MPVMainDecContext *m) ff_mpv_free_context_frame(m2); - if (s->picture) - for (int i = 0; i < MAX_PICTURE_COUNT; i++) - s->picture[i].needs_realloc = 1; + for (int i = 0; i < MAX_PICTURE_COUNT; i++) + m2->picture[i].needs_realloc = 1; s->last_picture_ptr = s->next_picture_ptr = @@ -283,7 +281,8 @@ static void gray_frame(AVFrame *frame) */ int ff_mpv_frame_start(MPVMainDecContext *m, AVCodecContext *avctx) { - MPVDecContext *const s = &m->s; + MPVMainContext *const m2 = m; + MPVDecContext *const s = &m2->s; Picture *pic; int idx, ret; @@ -304,10 +303,10 @@ int ff_mpv_frame_start(MPVMainDecContext *m, AVCodecContext *avctx) /* release forgotten pictures */ /* if (MPEG-124 / H.263) */ for (int i = 0; i < MAX_PICTURE_COUNT; i++) { - if (&s->picture[i] != s->last_picture_ptr && - &s->picture[i] != s->next_picture_ptr && - s->picture[i].reference && !s->picture[i].needs_realloc) { - ff_mpeg_unref_picture(s->avctx, &s->picture[i]); + if (&m2->picture[i] != s->last_picture_ptr && + &m2->picture[i] != s->next_picture_ptr && + m2->picture[i].reference && !m2->picture[i].needs_realloc) { + ff_mpeg_unref_picture(s->avctx, &m2->picture[i]); } } @@ -317,8 +316,8 @@ int ff_mpv_frame_start(MPVMainDecContext *m, AVCodecContext *avctx) /* release non reference frames */ for (int i = 0; i < MAX_PICTURE_COUNT; i++) { - if (!s->picture[i].reference) - ff_mpeg_unref_picture(s->avctx, &s->picture[i]); + if (!m2->picture[i].reference) + ff_mpeg_unref_picture(s->avctx, &m2->picture[i]); } if (s->current_picture_ptr && !s->current_picture_ptr->f->buf[0]) { @@ -326,12 +325,12 @@ int ff_mpv_frame_start(MPVMainDecContext *m, AVCodecContext *avctx) // (maybe it was set before reading the header) pic = s->current_picture_ptr; } else { - idx = ff_find_unused_picture(s->avctx, s->picture, 0); + idx = ff_find_unused_picture(s->avctx, m2->picture, 0); if (idx < 0) { av_log(s->avctx, AV_LOG_ERROR, "no frame buffer available\n"); return idx; } - pic = &s->picture[idx]; + pic = &m2->picture[idx]; } pic->reference = 0; @@ -390,12 +389,12 @@ int ff_mpv_frame_start(MPVMainDecContext *m, AVCodecContext *avctx) "warning: first frame is no keyframe\n"); /* Allocate a dummy frame */ - idx = ff_find_unused_picture(s->avctx, s->picture, 0); + idx = ff_find_unused_picture(s->avctx, m2->picture, 0); if (idx < 0) { av_log(s->avctx, AV_LOG_ERROR, "no frame buffer available\n"); return idx; } - s->last_picture_ptr = &s->picture[idx]; + s->last_picture_ptr = &m2->picture[idx]; s->last_picture_ptr->reference = 3; s->last_picture_ptr->f->key_frame = 0; @@ -432,12 +431,12 @@ int ff_mpv_frame_start(MPVMainDecContext *m, AVCodecContext *avctx) if ((!s->next_picture_ptr || !s->next_picture_ptr->f->buf[0]) && s->pict_type == AV_PICTURE_TYPE_B) { /* Allocate a dummy frame */ - idx = ff_find_unused_picture(s->avctx, s->picture, 0); + idx = ff_find_unused_picture(s->avctx, m2->picture, 0); if (idx < 0) { av_log(s->avctx, AV_LOG_ERROR, "no frame buffer available\n"); return idx; } - s->next_picture_ptr = &s->picture[idx]; + s->next_picture_ptr = &m2->picture[idx]; s->next_picture_ptr->reference = 3; s->next_picture_ptr->f->key_frame = 0; @@ -562,13 +561,14 @@ void ff_mpeg_draw_horiz_band(MPVDecContext *s, int y, int h) void ff_mpeg_flush(AVCodecContext *avctx) { MPVMainDecContext *const m = avctx->priv_data; - MPVDecContext *const s = &m->s; + MPVMainContext *const m2 = m; + MPVDecContext *const s = &m2->s; - if (!s->picture) + if (!m2->context_initialized) return; for (int i = 0; i < MAX_PICTURE_COUNT; i++) - ff_mpeg_unref_picture(s->avctx, &s->picture[i]); + ff_mpeg_unref_picture(s->avctx, &m2->picture[i]); s->current_picture_ptr = s->last_picture_ptr = s->next_picture_ptr = NULL; ff_mpeg_unref_picture(s->avctx, &s->current_picture); diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index d3e52126d7..1d1cd6e3d3 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -1123,11 +1123,11 @@ static int load_input_picture(MPVMainEncContext *m, const AVFrame *pic_arg) ff_dlog(s->avctx, "%d %d %"PTRDIFF_SPECIFIER" %"PTRDIFF_SPECIFIER"\n", pic_arg->linesize[0], pic_arg->linesize[1], s->linesize, s->uvlinesize); - i = ff_find_unused_picture(s->avctx, s->picture, direct); + i = ff_find_unused_picture(s->avctx, com->picture, direct); if (i < 0) return i; - pic = &s->picture[i]; + pic = &com->picture[i]; pic->reference = 3; if (direct) { @@ -1571,10 +1571,10 @@ no_output_pic: // one & ensure that the shared one is reuseable Picture *pic; - int i = ff_find_unused_picture(s->avctx, s->picture, 0); + int i = ff_find_unused_picture(s->avctx, m2->picture, 0); if (i < 0) return i; - pic = &s->picture[i]; + pic = &m2->picture[i]; pic->reference = m->reordered_input_picture[0]->reference; if (alloc_picture(s, pic, 0) < 0) { @@ -1967,8 +1967,8 @@ vbv_retry: /* release non-reference frames */ for (i = 0; i < MAX_PICTURE_COUNT; i++) { - if (!s->picture[i].reference) - ff_mpeg_unref_picture(avctx, &s->picture[i]); + if (!m2->picture[i].reference) + ff_mpeg_unref_picture(avctx, &m2->picture[i]); } av_assert1((m->frame_bits & 7) == 0);