From patchwork Sun Apr 30 17:40:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 3519 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.3.129 with SMTP id 123csp1109811vsd; Sun, 30 Apr 2017 10:41:23 -0700 (PDT) X-Received: by 10.223.157.11 with SMTP id k11mr13145449wre.71.1493574083359; Sun, 30 Apr 2017 10:41:23 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id d65si5908865wmd.105.2017.04.30.10.41.22; Sun, 30 Apr 2017 10:41:23 -0700 (PDT) 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=@gmail.com; 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=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BE7AB689913; Sun, 30 Apr 2017 20:41:16 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk0-f194.google.com (mail-qk0-f194.google.com [209.85.220.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 82F5D6898DC for ; Sun, 30 Apr 2017 20:41:09 +0300 (EEST) Received: by mail-qk0-f194.google.com with SMTP id o85so15102163qkh.0 for ; Sun, 30 Apr 2017 10:41:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=xXYkZ5RE17pCmUREGdFjUrnDufUKLreJtSdnu8cOYHU=; b=ax/o0AJ9m5VaLgfe/mUNaAQOilGhicPrCyy9Aoe/ufccwy2gLOsch3U57x5J6YwnLk ghWx2m/hkWS/aggcZYBuN1x+uOLctQzwLACdicYS6+l/9M0gCi9NM7GpGYjhFL0COkmP nGwrz4WpPppPXk/F6ljpCxrITsUIJOG2cgVjgTnZCEuPhJ4jLDlr53+A4sX1VgaoVqPp s5XG5Du0SPP0P2x4NDbxMF0xkU3yygw3x8fGPEoP8r0IbNYp2cpTyecjkrOL0xyrHA4L seuA1NAH23sfaUIRcunhUZiF9BWlmzCGK4paIXkcCLu4oGKKoLJKYYwFP3cOXR+tcduE hwmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=xXYkZ5RE17pCmUREGdFjUrnDufUKLreJtSdnu8cOYHU=; b=mpWOgnholBL+zaCUMC5VewnbdydPp0Vak8YkkyLKePTxtjtaQgg63Xo9RNyphtXqOa pC3DtgIIxEC1fk4iQA7SPltv1x2Z9kGxuu7F7Tcj1e2+iwE86p6h7ENoh1YDGorMPUJN 2eXdPPsDCHcusQqWexT+AMEPg0QZhXmcLU+5GNAOzqOyvRtkYt7htJzH/Lp4M0DTcERc n6Yh47ZfFlAge/yIyVQpd1WG9wR7MhZMEywm7y0v2wWs0u/KuHX4NWwdiQicJXhkKV6w RKg0gjW55jwAp4AXYdBSKud4Kv1NAND7ChBN4FflNmSYYDMNxB/uBl2jjX4uOAtEdAqP ZAqw== X-Gm-Message-State: AN3rC/7oXxRXDqrfnEFTwXXAor3vXssKgyA+KaWpEQlMlx/6MfyxbVLl bKaQMA98ku4nWTBr X-Received: by 10.55.19.205 with SMTP id 74mr17066840qkt.220.1493574071096; Sun, 30 Apr 2017 10:41:11 -0700 (PDT) Received: from localhost.localdomain ([181.231.62.139]) by smtp.gmail.com with ESMTPSA id o91sm8586586qte.42.2017.04.30.10.41.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 30 Apr 2017 10:41:10 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Sun, 30 Apr 2017 14:40:45 -0300 Message-Id: <20170430174045.7020-1-jamrial@gmail.com> X-Mailer: git-send-email 2.12.1 Subject: [FFmpeg-devel] [PATCH] hevc_parser: use ff_h2645_packet_split() to parse NAL units 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This simplifies the code considerably. --- libavcodec/hevc_parser.c | 50 ++++++++++-------------------------------------- 1 file changed, 10 insertions(+), 40 deletions(-) diff --git a/libavcodec/hevc_parser.c b/libavcodec/hevc_parser.c index 310428d0ff..5b9cd87d88 100644 --- a/libavcodec/hevc_parser.c +++ b/libavcodec/hevc_parser.c @@ -192,11 +192,8 @@ static inline int parse_nal_units(AVCodecParserContext *s, const uint8_t *buf, GetBitContext *gb; SliceHeader *sh = &h->sh; HEVCParamSets *ps = &h->ps; - H2645Packet *pkt = &ctx->pkt; - const uint8_t *buf_end = buf + buf_size; - int state = -1, i; - H2645NAL *nal; int is_global = buf == avctx->extradata; + int i, ret; if (!h->HEVClc) h->HEVClc = av_mallocz(sizeof(HEVCLocalContext)); @@ -214,44 +211,18 @@ static inline int parse_nal_units(AVCodecParserContext *s, const uint8_t *buf, ff_hevc_reset_sei(h); - if (!buf_size) - return 0; - - if (pkt->nals_allocated < 1) { - H2645NAL *tmp = av_realloc_array(pkt->nals, 1, sizeof(*tmp)); - if (!tmp) - return AVERROR(ENOMEM); - pkt->nals = tmp; - memset(pkt->nals, 0, sizeof(*tmp)); - pkt->nals_allocated = 1; - } - - nal = &pkt->nals[0]; + ret = ff_h2645_packet_split(&ctx->pkt, buf, buf_size, avctx, 0, 0, + AV_CODEC_ID_HEVC, 1); + if (ret < 0) + return ret; - for (;;) { - int src_length, consumed; - int ret; + for (i = 0; i < ctx->pkt.nb_nals; i++) { + H2645NAL *nal = &ctx->pkt.nals[i]; int num = 0, den = 0; - buf = avpriv_find_start_code(buf, buf_end, &state); - if (--buf + 2 >= buf_end) - break; - src_length = buf_end - buf; - - h->nal_unit_type = (*buf >> 1) & 0x3f; - h->temporal_id = (*(buf + 1) & 0x07) - 1; - if (h->nal_unit_type <= HEVC_NAL_CRA_NUT) { - // Do not walk the whole buffer just to decode slice segment header - if (src_length > 20) - src_length = 20; - } - - consumed = ff_h2645_extract_rbsp(buf, src_length, nal, 1); - if (consumed < 0) - return consumed; - ret = init_get_bits8(gb, nal->data + 2, nal->size); - if (ret < 0) - return ret; + h->nal_unit_type = nal->type; + h->temporal_id = nal->temporal_id; + *gb = nal->gb; switch (h->nal_unit_type) { case HEVC_NAL_VPS: @@ -394,7 +365,6 @@ static inline int parse_nal_units(AVCodecParserContext *s, const uint8_t *buf, return 0; /* no need to evaluate the rest */ } - buf += consumed; } /* didn't find a picture! */ if (!is_global)