From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id BB79F405D7 for ; Wed, 26 Jan 2022 21:36:48 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 78AFA68B1A5; Wed, 26 Jan 2022 23:35:27 +0200 (EET) Received: from EUR03-VE1-obe.outbound.protection.outlook.com (mail-oln040092072020.outbound.protection.outlook.com [40.92.72.20]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2EC9F68B11F for ; Wed, 26 Jan 2022 23:35:23 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=buGPbw4RHQSD3z2gGE9OW5BmhlzI61N5q6zknechIwhjb8PPOW5AgpHv6VisCyFyEHjoYI9VcUJ/DyuNTDjBAL8fmwDwAXEsBzD6xDlxuh4ACZeWuW85QNOSoeFhTuQL57H5TkbE/uEpbESBH7r5DfW03mC9oL9NZvCjfsYe8exIQ86awFOmK0fKBnSxcW5ii6k/Vt1w+Xl34M8Zu/xyZ/5+21zhVPkzBh+I0G12tOkvK5Sakc0w+RLMQgqfWKP8F0DAlCymup0/gPt9TWuV3rJdYHNSqTdBj0uWErEWlOP1IqTQyEm7qISkX8Dr4FeCw/pCoNPtyk61o5N+n8FZDw== 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=jqcpjjvpFP1du1TkfwKaz8xT4K5++TWP9lhiQ3CFz+o=; b=VREG7SJV19orIow58R3atIBEOoGR1g9gQcY3X0NXXkuy4SlGyfxiGos9WA9GjBrAO8JoYO9l5eFCFkOL5dJC2y5KCOzwri3LT0RNlSoUP+BT7iW8dUup+00u1cPw8fGcyCNYfTI/rdzpbK1rZJewcDWO8tNsd9zXPNDCO6KWvh8WMdnfD9nukH8mOXHT2/LQjNXX84kwkJaJVEhIaUmfPhjtvZ7MEV1h+Gpx7ea/uxrgYL9IaY/DkNk7RZM4v0voZz+QDvgu87si4To4BLvrSnmueCYufMLDaPHrX21K39gIOclxC9kDZyMX5HiyAOSU+ASi6cgMUaUSD43WV8pr+w== 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=jqcpjjvpFP1du1TkfwKaz8xT4K5++TWP9lhiQ3CFz+o=; b=imZiBQ0h/7+hVoc8pG5If8aBWOs8/9vIo96qWmPzqhQZ6ut7ASno+Zmmicq9d26zs/55wDmK69uqr0gvgXeywXIlJ1ZybyXfptSXPQpEYu2myloaJPqqi3Ur7C1DCvbPdiD5P7qFNi4EXx3qT22py0iQ0u3sYuD9rE79e7FFKq56wiuQpNRkM9jnCvfvp/vc1QwQTTqW6gE8Z6xaSFcJRJU6slU4R5PiugHE+0WYPb1sRPdn4DyXW8a+Jpdemg2iHe+TC0w8daVuFFvsvRL3pGCjrGAv96yRKpes6lDDZwCGtuZnNvnzSz4vqzeOM7FgBuFVRuDZaHqzrRW1MJd+4w== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM9PR03MB7852.eurprd03.prod.outlook.com (2603:10a6:20b:433::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.17; Wed, 26 Jan 2022 21:35:18 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::ac56:2ff4:d304:ab22]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::ac56:2ff4:d304:ab22%4]) with mapi id 15.20.4930.017; Wed, 26 Jan 2022 21:35:17 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 26 Jan 2022 22:34:50 +0100 Message-ID: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-TMN: [UbuwKyclZBwWktdjeYZPMtNQLdO3gaOc] X-ClientProxiedBy: AM3PR03CA0066.eurprd03.prod.outlook.com (2603:10a6:207:5::24) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20220126213451.1887291-11-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fabc81ad-a838-4a19-73cd-08d9e113bf34 X-MS-TrafficTypeDiagnostic: AM9PR03MB7852:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wWJVCX0P1T1+okz0aFbVjDjhpLyVVoz7+9JUts+omQtFo8nuVSISwH87hrG1Ro/adk7rp501iGCL5hREztwR8nvsLBWJBBaMPz92Bs544m6hm4Roe7i5F+CCPbjQXymWmFz9j6aMFmPx2j8zuX2fA9+sainOFVhRymIzVAnuG8wc9iggPfY6SNOXO8uStT4657YrX8FQ4XpJ8kHrj1pHSV1N3HjtJu56SswEOqUL0m48INWx6xbSqMcmxWPlt2nrQtsRM3PmwAo9KAp7dlbvnOFzMFjG1u3i41TySIZG1gmtSEmXpZHSF+jAZKGheIryxUHXpLnPtfag/aOK/k7p3+CuAdBlUn4dTf745Ej8azAqtbWdrV9TL41sew6v+l+1fs0fi632n/fwcwHSfAcSsBJS+K3aFz3LuHJkgMt7xlrpdmLjIPtjohlnVrBACjz25CiUOl3mTANPZ9QYxCHl6VGRyr0V6Fbo5bhQhy9ow16r9T8C1yJwX51rADZ9xo5+4F0yhlwuNFiJ6dm+uzXN3RRCjpsUGklv7Mm3PECKZAH4GVnj2x3gDlUVxEtnrXeS X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?tr75c5PGFvb+nxgfZuE1Ep/67zelozAeAb4CUJZkkomLOAtLAo9tQUzNfqO+?= =?us-ascii?Q?6hCP89A6LXCCxy7yX7MbK3JQq07wCxiMz7ljOnCUvS6WtSh81K284Y3aFyM7?= =?us-ascii?Q?bOB511jCwrgGNsVrqLSesJUkxzLugRhhBJwN66VZpXOZdguALPz8QHwj5wjD?= =?us-ascii?Q?k+s3bljBOqXuOCCkulBZWGQQKyDq1lny9TP1rbwyWfxBUVC5k9iYZEdIXyGI?= =?us-ascii?Q?XdO1RttC2gl0Y0io6gG2UDlWNOs2KuZLr7cVMNC0I2R4ZhvvEHIcVwNurwwo?= =?us-ascii?Q?xAX+oNoxIvMHVxicZmZYKTCGFdfw9VfF31G58ZjlTcuV3EBz+qJVsjEIY64J?= =?us-ascii?Q?PV6Tqf4RHD2T5iGBFI7zjROMEX9L9YHscHW4Ps0Tg9KIn+rEWm3YdgLJkdR9?= =?us-ascii?Q?wx6C5m6tThGSf7lR0Oa4leVsBY9WlOxu09RcttAnXq1erlEfw9DhbABqjhbM?= =?us-ascii?Q?mUd94fgSLiopiQ/lUqTCMe73WozuNo5DDGMkESiImzpvKNDgnoCdE94c1dyw?= =?us-ascii?Q?JlZFxUwcxCrOc7Rk28A4AuMtI8JuR1iPtKKjtaC6gkCPE6Tg9ANKjrRSw2UG?= =?us-ascii?Q?uT1t6r87H7eyOJ/2/6j4JVRIKLxRXdvGS7cVx0irRhwX1Y9516OCjgoIJDii?= =?us-ascii?Q?LclQcHA0QIkt4rZd5jeZ6zyfvDbhYLFA0bO2XL6I5SGcoTTYQMFyEg6JBYjd?= =?us-ascii?Q?bfFdgZnTY4WSaskNo2zI2UA0Wx6O91d/Si6ppJCqBtJORfpcUf3Y54obJKcB?= =?us-ascii?Q?uHrJj3yUZV6qfkooNmU4azBh8s7gZ7DnfKUuMmLPCihJY4U5y9vsraIVNI9V?= =?us-ascii?Q?2llu6uOj8caFvKtG99gGccS3cqQmYaHLf0GK+x6Vhyy9o410b0i8LnhGF9Cg?= =?us-ascii?Q?D/AqpaKsmEcwsKuNoNLq5JL+wbMrom15nP5T6+KTBBpkWSJS22Y/rLvBdJ0l?= =?us-ascii?Q?WllKAiAd9FgdVxsoSYbtWQ=3D=3D?= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: fabc81ad-a838-4a19-73cd-08d9e113bf34 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2022 21:35:17.9086 (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: AM9PR03MB7852 Subject: [FFmpeg-devel] [PATCH 32/33] avcodec/mpegvideo: Use offset instead of pointer for vbv_delay 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: An offset has the advantage of not needing to be updated when the buffer is reallocated. Furthermore, the way the pointer is currently updated is undefined behaviour in case the pointer is not already set (i.e. when not encoding MPEG-1/2), because it calculates the nonsense NULL - s->pb.buf. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpeg12enc.c | 2 +- libavcodec/mpegvideo.h | 2 +- libavcodec/mpegvideo_enc.c | 15 +++++++-------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c index ecb90d1a41..9c0be69ded 100644 --- a/libavcodec/mpeg12enc.c +++ b/libavcodec/mpeg12enc.c @@ -465,7 +465,7 @@ void ff_mpeg1_encode_picture_header(MpegEncContext *s, int picture_number) (s->picture_number - mpeg12->gop_picture_number) & 0x3ff); put_bits(&s->pb, 3, s->pict_type); - s->vbv_delay_ptr = s->pb.buf + put_bytes_count(&s->pb, 0); + s->vbv_delay_pos = put_bytes_count(&s->pb, 0); put_bits(&s->pb, 16, 0xFFFF); /* vbv_delay */ // RAL: Forward f_code also needed for B-frames diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 325f62e01f..fa0ea51046 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -429,7 +429,7 @@ typedef struct MpegEncContext { /* MPEG-1 specific */ int last_mv_dir; ///< last mv_dir, used for B-frame encoding - uint8_t *vbv_delay_ptr; ///< pointer to vbv_delay in the bitstream + int vbv_delay_pos; ///< offset of vbv_delay in the bitstream /* MPEG-2-specific - I wished not to have to support this mess. */ int progressive_sequence; diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index baa45d20ab..d27a74f9e0 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -1840,8 +1840,9 @@ vbv_retry: double inbits = avctx->rc_max_rate * av_q2d(avctx->time_base); int minbits = s->frame_bits - 8 * - (s->vbv_delay_ptr - s->pb.buf - 1); + (s->vbv_delay_pos - 1); double bits = s->rc_context.buffer_index + minbits - inbits; + uint8_t *const vbv_delay_ptr = s->pb.buf + s->vbv_delay_pos; if (bits < 0) av_log(avctx, AV_LOG_ERROR, @@ -1857,11 +1858,11 @@ vbv_retry: av_assert0(vbv_delay < 0xFFFF); - s->vbv_delay_ptr[0] &= 0xF8; - s->vbv_delay_ptr[0] |= vbv_delay >> 13; - s->vbv_delay_ptr[1] = vbv_delay >> 5; - s->vbv_delay_ptr[2] &= 0x07; - s->vbv_delay_ptr[2] |= vbv_delay << 3; + vbv_delay_ptr[0] &= 0xF8; + vbv_delay_ptr[0] |= vbv_delay >> 13; + vbv_delay_ptr[1] = vbv_delay >> 5; + vbv_delay_ptr[2] &= 0x07; + vbv_delay_ptr[2] |= vbv_delay << 3; props = av_cpb_properties_alloc(&props_size); if (!props) @@ -2721,7 +2722,6 @@ int ff_mpv_reallocate_putbitbuffer(MpegEncContext *s, size_t threshold, size_t s && s->slice_context_count == 1 && s->pb.buf == s->avctx->internal->byte_buffer) { int lastgob_pos = s->ptr_lastgob - s->pb.buf; - int vbv_pos = s->vbv_delay_ptr - s->pb.buf; uint8_t *new_buffer = NULL; int new_buffer_size = 0; @@ -2744,7 +2744,6 @@ int ff_mpv_reallocate_putbitbuffer(MpegEncContext *s, size_t threshold, size_t s s->avctx->internal->byte_buffer_size = new_buffer_size; rebase_put_bits(&s->pb, new_buffer, new_buffer_size); s->ptr_lastgob = s->pb.buf + lastgob_pos; - s->vbv_delay_ptr = s->pb.buf + vbv_pos; } if (put_bytes_left(&s->pb, 0) < threshold) return AVERROR(EINVAL); -- 2.32.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".