From patchwork Mon Jul 29 19:56:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 14133 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id CE609449190 for ; Mon, 29 Jul 2019 23:11:24 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A44EB68A7C5; Mon, 29 Jul 2019 23:11:24 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 98B6D680687 for ; Mon, 29 Jul 2019 23:11:18 +0300 (EEST) Received: by mail-wr1-f65.google.com with SMTP id p17so63193609wrf.11 for ; Mon, 29 Jul 2019 13:11:18 -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 :mime-version:content-transfer-encoding; bh=XVi6I6dFT9tkzmdxa+t2XjEjVcTUou2MhjWPmc/ZeOA=; b=p7vCGDYyqmz1RAzKBwhTP+BFmZsbceDPlG2qdvSvUQCh1xz5mOJQPv09PNqFD8j80Z ALuZaFuEBPwHmlZm15ciCWS3e9Mou1/BuKqHgzwG4YRpnIekcR+wifKIVDe0kIVqd4Qw HedBkl/rc5E2hb8+w/hOAZb+tDFkClTY2cvX5Y1temvXo+++veY0PPnKnlam3TzAWH7l GKFvwMUxytTheQzqDT/K61QG64z/7KmBKufsOmM6Do81v7WOA96UZthLwQnjlkNu33aw CNUZ4frjQkt0HRpjBeX2MSYznen5WnXJDxgFrP2Asev50yTJOMREaNxY3ks0o7MaHS+G JM/A== 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:mime-version:content-transfer-encoding; bh=XVi6I6dFT9tkzmdxa+t2XjEjVcTUou2MhjWPmc/ZeOA=; b=dWICFllOAeuZgKp9GhW0puNSRt63do9M9cHJUlANAcxN6U3HmVjwWaQ8DsFYSttGQS P2b/dFzirL6imh/0hpNvscdORU78qGfE6tBiUzFQ9IBduSdQYL6zk4lYsRkj+i4ou2tK 9FGtF5o/WLndFZ/2zhDqsaYjeSoM/bPly186C7h8dl6U4E4iRVpvFggGecarQpgKMXWL 24utwv4nJsG0YznJ3X4VH+pDWVm/0v1gwlOYSk9CQK4XWyOA9xrMk11dCyQEh9Te+NUd Xo9JTcjG4xNK9JQ1n/fdkxNqscgfZL93LautubHIHGJbwfqTdOcP2yEEgfq2lSmA4J+e kPKQ== X-Gm-Message-State: APjAAAU3UKHXBSdCvMRy9ob6ZhuZOoBiIOr6Fi+oyqrhf3PpsYYsrcTD nDuPeioMgmP+or6mTtZm78GLUm/C X-Google-Smtp-Source: APXvYqzJc2w/9S1UL6PqwizI1cbKKhVc+vPd57h2yESoCOGRBN8V2cmAEf6A179v112jJh6MPN2wvQ== X-Received: by 2002:adf:e2c1:: with SMTP id d1mr127944074wrj.283.1564430617897; Mon, 29 Jul 2019 13:03:37 -0700 (PDT) Received: from localhost.localdomain (ipbcc08b8f.dynamic.kabel-deutschland.de. [188.192.139.143]) by smtp.gmail.com with ESMTPSA id t24sm56602211wmj.14.2019.07.29.13.03.37 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 29 Jul 2019 13:03:37 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 29 Jul 2019 21:56:55 +0200 Message-Id: <20190729195658.56078-4-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190729195658.56078-1-andreas.rheinhardt@gmail.com> References: <20190729195658.56078-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/7] cbs_mpeg2: Rearrange start code search 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 1. Currently, cbs_mpeg2_split_fragment uses essentially three variables to hold the start code values found by avpriv_find_start_code. By rearranging the code, one of them can be omitted. 2. The return value of avpriv_find_start_code points to the byte after the byte containing the start code identifier (or to the byte after the last byte of the fragment's data if no start code was found), but cbs_mpeg2_split_fragment needs to work with the pointer to the byte containing the start code identifier; it already did this, but in a clumsy way. This has been changed. 3. Also use the correct type for the variable holding the CodedBitstreamUnitType. Signed-off-by: Andreas Rheinhardt --- libavcodec/cbs_mpeg2.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c index 9a584246c9..c529038fd9 100644 --- a/libavcodec/cbs_mpeg2.c +++ b/libavcodec/cbs_mpeg2.c @@ -167,41 +167,40 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx, int header) { const uint8_t *start, *end; - uint8_t *unit_data; - uint32_t start_code = -1, next_start_code = -1; + CodedBitstreamUnitType unit_type; + uint32_t start_code = -1; size_t unit_size; - int err, i, unit_type; + int err, i; start = avpriv_find_start_code(frag->data, frag->data + frag->data_size, &start_code); for (i = 0;; i++) { - end = avpriv_find_start_code(start, frag->data + frag->data_size, - &next_start_code); - unit_type = start_code & 0xff; - // The start and end pointers point at to the byte following the - // start_code_identifier in the start code that they found. + end = avpriv_find_start_code(start--, frag->data + frag->data_size, + &start_code); + + // start points to the byte containing the start_code_identifier + // (or to the last byte of fragment->data); end points to the byte + // following the byte containing the start code identifier (or to + // the end of fragment->data). if (end == frag->data + frag->data_size) { // We didn't find a start code, so this is the final unit. - unit_size = end - (start - 1); + unit_size = end - start; } else { // Unit runs from start to the beginning of the start code // pointed to by end (including any padding zeroes). - unit_size = (end - 4) - (start - 1); + unit_size = (end - 4) - start; } - unit_data = (uint8_t *)start - 1; - - err = ff_cbs_insert_unit_data(ctx, frag, i, unit_type, - unit_data, unit_size, frag->data_ref); + err = ff_cbs_insert_unit_data(ctx, frag, i, unit_type, (uint8_t*)start, + unit_size, frag->data_ref); if (err < 0) return err; if (end == frag->data + frag->data_size) break; - start_code = next_start_code; start = end; }