From patchwork Thu Aug 6 08:04:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xu, Guangxin" X-Patchwork-Id: 21510 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 87A6E448957 for ; Thu, 6 Aug 2020 11:04:51 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6FC6468BAAD; Thu, 6 Aug 2020 11:04:51 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 57CC168B703 for ; Thu, 6 Aug 2020 11:04:44 +0300 (EEST) IronPort-SDR: W0eMhQvM837ZZvwCtCf4mxdkk6srQa4soFCY8013GGmLIcGdPEur8UQ19WMx5BYAmkRQFk6stw p87IuI1jaN8A== X-IronPort-AV: E=McAfee;i="6000,8403,9704"; a="140349967" X-IronPort-AV: E=Sophos;i="5.75,441,1589266800"; d="scan'208";a="140349967" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Aug 2020 01:04:41 -0700 IronPort-SDR: hDceBXgDsnu07I6472DKRtc86mpciYfJIcDtaWYxqmSkB5mEmrsnGffKB5TFbx83hTIQE2YNXV M2ICFSKcS9Dg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,441,1589266800"; d="scan'208";a="493587688" Received: from skl-e5-server.sh.intel.com ([10.239.43.170]) by fmsmga005.fm.intel.com with ESMTP; 06 Aug 2020 01:04:40 -0700 From: Xu Guangxin To: ffmpeg-devel@ffmpeg.org, jamrial@gmail.com Date: Thu, 6 Aug 2020 16:04:12 +0800 Message-Id: <20200806080416.17691-2-guangxin.xu@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200806080416.17691-1-guangxin.xu@intel.com> References: <20200806080416.17691-1-guangxin.xu@intel.com> Subject: [FFmpeg-devel] [PATCH 1/5] av1_parser: parser_obu_header, return has_size_flag 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: Xu Guangxin MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Xu Guangxin we need check has_size_flag for low overhead obu --- libavcodec/av1_parse.c | 4 ++-- libavcodec/av1_parse.h | 8 ++++---- libavformat/av1.c | 12 ++++++------ libavformat/av1dec.c | 10 +++++----- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/libavcodec/av1_parse.c b/libavcodec/av1_parse.c index 59ea0bc6e7..b59b4e5e45 100644 --- a/libavcodec/av1_parse.c +++ b/libavcodec/av1_parse.c @@ -29,11 +29,11 @@ int ff_av1_extract_obu(AV1OBU *obu, const uint8_t *buf, int length, void *logctx) { int64_t obu_size; - int start_pos, type, temporal_id, spatial_id; + int start_pos, type, temporal_id, spatial_id, has_size_flag; int len; len = parse_obu_header(buf, length, &obu_size, &start_pos, - &type, &temporal_id, &spatial_id); + &type, &temporal_id, &spatial_id, &has_size_flag); if (len < 0) return len; diff --git a/libavcodec/av1_parse.h b/libavcodec/av1_parse.h index 01bcd646c2..a3b39f039c 100644 --- a/libavcodec/av1_parse.h +++ b/libavcodec/av1_parse.h @@ -99,10 +99,10 @@ static inline int64_t leb128(GetBitContext *gb) { static inline int parse_obu_header(const uint8_t *buf, int buf_size, int64_t *obu_size, int *start_pos, int *type, - int *temporal_id, int *spatial_id) + int *temporal_id, int *spatial_id, int *has_size_flag) { GetBitContext gb; - int ret, extension_flag, has_size_flag; + int ret, extension_flag; int64_t size; ret = init_get_bits8(&gb, buf, FFMIN(buf_size, 2 + 8)); // OBU header fields + max leb128 length @@ -114,7 +114,7 @@ static inline int parse_obu_header(const uint8_t *buf, int buf_size, *type = get_bits(&gb, 4); extension_flag = get_bits1(&gb); - has_size_flag = get_bits1(&gb); + *has_size_flag = get_bits1(&gb); skip_bits1(&gb); // obu_reserved_1bit if (extension_flag) { @@ -125,7 +125,7 @@ static inline int parse_obu_header(const uint8_t *buf, int buf_size, *temporal_id = *spatial_id = 0; } - *obu_size = has_size_flag ? leb128(&gb) + *obu_size = *has_size_flag ? leb128(&gb) : buf_size - 1 - extension_flag; if (get_bits_left(&gb) < 0) diff --git a/libavformat/av1.c b/libavformat/av1.c index 0cbffb1fd8..10d6815d1f 100644 --- a/libavformat/av1.c +++ b/libavformat/av1.c @@ -34,7 +34,7 @@ static int av1_filter_obus(AVIOContext *pb, const uint8_t *buf, { const uint8_t *start = buf, *end = buf + size; int64_t obu_size; - int off, start_pos, type, temporal_id, spatial_id; + int off, start_pos, type, temporal_id, spatial_id, has_size_flag; enum { START_NOT_FOUND, START_FOUND, @@ -45,7 +45,7 @@ static int av1_filter_obus(AVIOContext *pb, const uint8_t *buf, off = size = 0; while (buf < end) { int len = parse_obu_header(buf, end - buf, &obu_size, &start_pos, - &type, &temporal_id, &spatial_id); + &type, &temporal_id, &spatial_id, &has_size_flag); if (len < 0) return len; @@ -334,14 +334,14 @@ static int parse_sequence_header(AV1SequenceParameters *seq_params, const uint8_ int ff_av1_parse_seq_header(AV1SequenceParameters *seq, const uint8_t *buf, int size) { int64_t obu_size; - int start_pos, type, temporal_id, spatial_id; + int start_pos, type, temporal_id, spatial_id, has_size_flag; if (size <= 0) return AVERROR_INVALIDDATA; while (size > 0) { int len = parse_obu_header(buf, size, &obu_size, &start_pos, - &type, &temporal_id, &spatial_id); + &type, &temporal_id, &spatial_id, &has_size_flag); if (len < 0) return len; @@ -369,7 +369,7 @@ int ff_isom_write_av1c(AVIOContext *pb, const uint8_t *buf, int size) uint8_t header[4], *meta; const uint8_t *seq; int64_t obu_size; - int start_pos, type, temporal_id, spatial_id; + int start_pos, type, temporal_id, spatial_id, has_size_flag; int ret, nb_seq = 0, seq_size, meta_size; if (size <= 0) @@ -381,7 +381,7 @@ int ff_isom_write_av1c(AVIOContext *pb, const uint8_t *buf, int size) while (size > 0) { int len = parse_obu_header(buf, size, &obu_size, &start_pos, - &type, &temporal_id, &spatial_id); + &type, &temporal_id, &spatial_id, &has_size_flag); if (len < 0) { ret = len; goto fail; diff --git a/libavformat/av1dec.c b/libavformat/av1dec.c index 1be2fac1c1..297e87cc52 100644 --- a/libavformat/av1dec.c +++ b/libavformat/av1dec.c @@ -57,13 +57,13 @@ static int leb(AVIOContext *pb, uint32_t *len) { return i; } -static int read_obu(const uint8_t *buf, int size, int64_t *obu_size, int *type) +static int read_obu(const uint8_t *buf, int size, int64_t *obu_size, int *type, int *has_size_flag) { int start_pos, temporal_id, spatial_id; int len; len = parse_obu_header(buf, size, obu_size, &start_pos, - type, &temporal_id, &spatial_id); + type, &temporal_id, &spatial_id, has_size_flag); if (len < 0) return len; @@ -76,7 +76,7 @@ static int annexb_probe(const AVProbeData *p) int64_t obu_size; uint32_t temporal_unit_size, frame_unit_size, obu_unit_size; int seq = 0; - int ret, type, cnt = 0; + int ret, type, cnt = 0, has_size_flag; ffio_init_context(&pb, p->buf, p->buf_size, 0, NULL, NULL, NULL, NULL); @@ -103,7 +103,7 @@ static int annexb_probe(const AVProbeData *p) return 0; // Check that the first OBU is a Temporal Delimiter. - ret = read_obu(p->buf + cnt, FFMIN(p->buf_size - cnt, obu_unit_size), &obu_size, &type); + ret = read_obu(p->buf + cnt, FFMIN(p->buf_size - cnt, obu_unit_size), &obu_size, &type, &has_size_flag); if (ret < 0 || type != AV1_OBU_TEMPORAL_DELIMITER || obu_size > 0) return 0; cnt += obu_unit_size; @@ -118,7 +118,7 @@ static int annexb_probe(const AVProbeData *p) if (pb.eof_reached || pb.error) return 0; - ret = read_obu(p->buf + cnt, FFMIN(p->buf_size - cnt, obu_unit_size), &obu_size, &type); + ret = read_obu(p->buf + cnt, FFMIN(p->buf_size - cnt, obu_unit_size), &obu_size, &type, &has_size_flag); if (ret < 0) return 0; cnt += obu_unit_size;