From patchwork Thu Jul 9 19:17:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 20929 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 9440344AA01 for ; Thu, 9 Jul 2020 22:18:45 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7295A68B543; Thu, 9 Jul 2020 22:18:45 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C19F7689E53 for ; Thu, 9 Jul 2020 22:18:38 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id f2so3525498wrp.7 for ; Thu, 09 Jul 2020 12:18:38 -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=lSl5oFVpruvh+QvPLyhF06kPvKek3v9K0l0emEgqdkI=; b=DYLiG9LLhLEEjnFRBVm4/5gBweY3u77LGaQYze5iok6+HyKC0HJeeCSO1C24cyN8Rs 6kFfGgS+I5JtzxOy3n8FddVhwHLoFgBRk2PsE05eq1iAGZuIcUMGEKb4/Jj73D2PpTbE a0M3EECj3i9a5Ud9Fmcwkx6EbECSleSm2BZngCtT4d5A4kn/QwtfRuklF6tf1RvXXlQM qSMaFTRWKF3u+pYS2rUcS0vO7V3+czai+QFQqgUTp/FKzTSWUPmbN8H2Bm64yqhrXBn4 Ex34dH+vj+sNM2fj06AitqgbwavEgw+3AezXxMiAEMYlGYWNzoJDkn72/viU6xDLkLAw 9B3g== 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=lSl5oFVpruvh+QvPLyhF06kPvKek3v9K0l0emEgqdkI=; b=s3Sw6mtbx11s3zsAxLVQ+2QladIgjgjX+2uVV6qc83TYxOgNzb7Rhu20edFPk6eduq 4pQt0YotQPgiqCg69P72UnKhYR5WWDSo7Gcpb1Upiph3nWSf+mySgfaVu/gPxBZZfmKK XBYMdmw3bqxOMN7/R4Oq5sEcJa/lKny8jWuuCbj6gZbc3xcc8ng074lIE6hpSxpAv1EA hE3LjMWVJ/fvd4ngRNSVINKwvk1S2wf3FE6oJjuHKrjXiA7Xx3ug1uAmRzyWW/QrPfL5 e2PcSI0w3NFQaSNWoWE+C9/Yow5FPV63lraQnGmccDFQ2NSstCeeWRpHukBw50GQPmri 3JpQ== X-Gm-Message-State: AOAM533dZfyVbAWHwttoAS3WFnSBj10YsW/ASq6CCREG18tcW8h+h8ey Zq02G9LhoPQOeZB+cR4NSvnRDYUv X-Google-Smtp-Source: ABdhPJwYe/b9WGp61xpJT6nyQliKwBgC0cYZiB6iMhX/YQAkrMeHuVTMpWPC/ZFvY9qoE5n8zpEGAw== X-Received: by 2002:a05:6000:10c4:: with SMTP id b4mr60768136wrx.50.1594322317833; Thu, 09 Jul 2020 12:18:37 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc10296.dynamic.kabel-deutschland.de. [188.193.2.150]) by smtp.gmail.com with ESMTPSA id y77sm6574988wmd.36.2020.07.09.12.18.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jul 2020 12:18:37 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 9 Jul 2020 21:17:55 +0200 Message-Id: <20200709191805.21648-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200709103542.19909-1-andreas.rheinhardt@gmail.com> References: <20200709103542.19909-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 08/17] avformat/avc: Add helper function to parse annex B NAL unit in one go 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" Up until now, a caller had no function to easily parse a single annex B NAL unit. There was a "low-level" function that returned the position of the beginning of the next start code, which could be used to get the beginning and the end of NAL units. Yet using this function still required calling the startcode function twice and actually getting the start of the NAL unit data required a loop (because the offset from the start of the unit might be three or four). In practice, several functions that transformed from annex B to mp4 used the same scheme to do so while other (the functions to write H.264/HEVC extradata) used the former to at first transform the input into something more manageable. This commit adds a helper function to easily parse one annex B NAL unit in one go. Signed-off-by: Andreas Rheinhardt --- libavformat/avc.c | 30 +++++++++++++++++++++++++++++- libavformat/avc.h | 2 ++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/libavformat/avc.c b/libavformat/avc.c index cc92fb1038..39078aa5be 100644 --- a/libavformat/avc.c +++ b/libavformat/avc.c @@ -79,15 +79,43 @@ rest: return p; } - return end; + return NULL; } const uint8_t *ff_avc_find_startcode(const uint8_t *p, const uint8_t *end){ const uint8_t *out = avc_find_startcode_internal(p, end); + out = out ? out : end; if(p p && !next[-1] ? next - 1 : next; + next += 3; + } else { + *nal_end = end; + } + *start = next; + return p; +} + int ff_avc_parse_nal_units(AVIOContext *pb, const uint8_t *buf_in, int size) { const uint8_t *p = buf_in; diff --git a/libavformat/avc.h b/libavformat/avc.h index 9792b77913..b3df0a7b6b 100644 --- a/libavformat/avc.h +++ b/libavformat/avc.h @@ -29,6 +29,8 @@ int ff_avc_parse_nal_units(AVIOContext *s, const uint8_t *buf, int size); int ff_avc_parse_nal_units_buf(const uint8_t *buf_in, uint8_t **buf, int *size); int ff_isom_write_avcc(AVIOContext *pb, const uint8_t *data, int len); const uint8_t *ff_avc_find_startcode(const uint8_t *p, const uint8_t *end); +const uint8_t *ff_avc_parse_nalu(const uint8_t **start, const uint8_t **nal_end, + const uint8_t *end); int ff_avc_write_annexb_extradata(const uint8_t *in, uint8_t **buf, int *size); const uint8_t *ff_avc_mp4_find_startcode(const uint8_t *start, const uint8_t *end,