From patchwork Sat Feb 2 19:34:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 11957 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 35032446953 for ; Sat, 2 Feb 2019 21:49:02 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1628468A4C3; Sat, 2 Feb 2019 21:49:02 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 238F568A4B6 for ; Sat, 2 Feb 2019 21:48:56 +0200 (EET) Received: by mail-wr1-f68.google.com with SMTP id a16so4946878wrv.0 for ; Sat, 02 Feb 2019 11:48:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gWqtM0mmdA+JuKJki5uQeCkQATi0YUV9HdJz1olVqHg=; b=pbIF3lsI5oZkjzeQ+AOQR+80V6M6CMNhsfwO6S0QhsIdT3npsgiBbPxBvgFULoAKRh yYOaVmOtG6I3JDKKwNPVdxWSP0tk0DF0+5pI2KsiFtvODvMZgLEXmvLVXePe/yLmTrCM DFNttAxshiwvS2WYHJ8T+QwREVPULEXAX2zQpf/n5jLsOvNP/kfwURrv+drTZwcrGn1V mu/hjd6ru8722o+xYwV0Hp75t1RGL01JbH8WFB9oOXyxz8Iwzu0JMOGpq4eqy1Lv7HRS rib3JumORFctMvbi55FE++d6u25NmXNAj5xFFMKzwEOkDz6+tzhTKpTXsDhKZle2MFkA CsxQ== 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=gWqtM0mmdA+JuKJki5uQeCkQATi0YUV9HdJz1olVqHg=; b=DFx5tgSOwoaCIcVmCyR9uJaaLD8fOV4smAbRVfpnrHkMP2Dwzbc9kTimSkYqAr/rdW FhIMPqYx86I+0EMmoPwF6GFeY8gbKrHr9vq0eQvkWzgkaFRaE5Yww4QXgsTeGXh+pP5p Fr/Las2vbC2O6HBBxkY4NoUkYaDiLYsQAhS/+jxSnMzi2WC2nbkvRgwWL9iuxG/klY+t 0sC2JWvWTQQhuS+HEc2+mBaGOuXvoOzzEiYemCaO7KyFlQtsYqArCVEbVw0aJq6NfIvt pMO0MveH2YjO0SIwFSsd1b/oB9ZgHw9ePNCm0VSdZFHJXp3EUcyMNrUsVu9602iDyuRC VgGg== X-Gm-Message-State: AHQUAuZ+/KySwvF/RuqOPT4v58oDWff6Yy8cPANgrtuReSrHboYsRkzC f41kbNXBW1JwXLsj+4xQM0CTEoXx X-Google-Smtp-Source: AHgI3IZY+85PgFDF8U2ayqGS/Gu612XY6l4NkzmkqlRj/pf8vqU6zLJJTVV2nTvj+CryIPwGM1Ibnw== X-Received: by 2002:a5d:480a:: with SMTP id l10mr1895475wrq.101.1549136619559; Sat, 02 Feb 2019 11:43:39 -0800 (PST) Received: from localhost.localdomain (ipbcc08c44.dynamic.kabel-deutschland.de. [188.192.140.68]) by smtp.googlemail.com with ESMTPSA id z206sm9137622wmc.18.2019.02.02.11.43.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Feb 2019 11:43:38 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 2 Feb 2019 20:34:11 +0100 Message-Id: <20190202193412.572-2-andreas.rheinhardt@googlemail.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190202193412.572-1-andreas.rheinhardt@googlemail.com> References: <20190202193412.572-1-andreas.rheinhardt@googlemail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/3] avcodec/mpeg4_unpack_bframes_bsf: Use avpriv_find_start_code 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" instead of an ad-hoc function to search for start codes in order to remove code duplication and to improve performance. Improved performance of finding startcodes from 52606 decicycles to 9543 decicycles based upon 262144 runs for a 1 Mb/s MPEG4 video. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpeg4_unpack_bframes_bsf.c | 34 ++++++++------------------- 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/libavcodec/mpeg4_unpack_bframes_bsf.c b/libavcodec/mpeg4_unpack_bframes_bsf.c index e9c535f390..1daf133ce5 100644 --- a/libavcodec/mpeg4_unpack_bframes_bsf.c +++ b/libavcodec/mpeg4_unpack_bframes_bsf.c @@ -21,50 +21,36 @@ #include "avcodec.h" #include "bsf.h" +#include "internal.h" #include "mpeg4video.h" typedef struct UnpackBFramesBSFContext { AVPacket *b_frame; } UnpackBFramesBSFContext; -/* search next start code */ -static unsigned int find_startcode(const uint8_t *buf, int buf_size, int *pos) -{ - unsigned int startcode = 0xFF; - - for (; *pos < buf_size;) { - startcode = ((startcode << 8) | buf[*pos]) & 0xFFFFFFFF; - *pos +=1; - if ((startcode & 0xFFFFFF00) != 0x100) - continue; /* no startcode */ - return startcode; - } - - return 0; -} - /* determine the position of the packed marker in the userdata, * the number of VOPs and the position of the second VOP */ static void scan_buffer(const uint8_t *buf, int buf_size, int *pos_p, int *nb_vop, int *pos_vop2) { - unsigned int startcode; - int pos, i; + uint32_t startcode; + const uint8_t *end = buf + buf_size, *pos = buf; - for (pos = 0; pos < buf_size;) { - startcode = find_startcode(buf, buf_size, &pos); + while (pos < end) { + startcode = -1; + pos = avpriv_find_start_code(pos, end, &startcode); if (startcode == USER_DATA_STARTCODE && pos_p) { /* check if the (DivX) userdata string ends with 'p' (packed) */ - for (i = 0; i < 255 && pos + i + 1 < buf_size; i++) { - if (buf[pos + i] == 'p' && buf[pos + i + 1] == '\0') { - *pos_p = pos + i; + for (int i = 0; i < 255 && pos + i + 1 < end; i++) { + if (pos[i] == 'p' && pos[i + 1] == '\0') { + *pos_p = pos + i - buf; break; } } } else if (startcode == VOP_STARTCODE && nb_vop) { *nb_vop += 1; if (*nb_vop == 2 && pos_vop2) { - *pos_vop2 = pos - 4; /* subtract 4 bytes startcode */ + *pos_vop2 = pos - buf - 4; /* subtract 4 bytes startcode */ } } }