From patchwork Mon Apr 30 23:26:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 8706 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:155:0:0:0:0:0 with SMTP id c82-v6csp4003993jad; Mon, 30 Apr 2018 16:31:40 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpUJ0FURRIT3XdgCs7dhWhFaaabnKIKlFr7ccdy5Nn8QP7MlUImci5SUk+83ACONYIvPvYA X-Received: by 10.28.236.130 with SMTP id h2mr8183872wmi.137.1525131100223; Mon, 30 Apr 2018 16:31:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525131100; cv=none; d=google.com; s=arc-20160816; b=HED6RZ0Ndo07OTGy3YWFc9j4mYS1A6wAb8XYh3nQXAIgtZJDXtdB4RGyC1MqJHWGAq uzvceg5iGiM7yzasLuBOfXJqHk/VaO2LcwUdUBL84utLYmTfb9UkIGJR3bgGmQaZPO32 PcalWYIcXp7OoS8JNuy9WyfDghzQZeFnQjb5lvULiwsOg9Z4OZuTd9Jk4G9/17wUwgan 7p5Hb4ww/5X+fAvB79HpyiJlZ6APyGOkOTI37cE5Omjvaf8Oah8ujtOjDVzWXfm9v3uW rH7xFx0kthQd+0E7t8NkOhcliBHnVPx9YC7jCujW6dzyKoqEUgygjrM+lLZhfnNS0MX5 Prkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=vFWHA/3NIF/xuaU/NWZgMXWCpKXiw9JEnjRk82PVT3M=; b=cG904hjSVF68XiRpx/Xt9Ja9q7j2M7NsOt/OpfX5Y6VHVIX8h3iqdFm9RkZPuu5urs /QueEm1RcBS/ne5pSsQ4RE2L+uolf140hIWy62KdTJiGcMBoWBN6t7sByAneTfvB+Ypo Gzt7DniMeLngX+/zaj6oDRyfCxCWYfsIo4gR44vvbbKYWDytjiLySEQObDPoxyGSajUr DmQEqrkXFRdQLKlqj4T4Ssu2r7xz43a8HDiRrmVj58a6VO8Vi6KG9SjMleKJgo3eJQM0 VRHuxlC70uSVUkLnNzR2dAmf8nbBBO+SycUKaMQiJo51XhJ6ctHSPf6aRygCO+dq6QRv zjxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@jkqxz-net.20150623.gappssmtp.com header.s=20150623 header.b=Z9sgIozS; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id m23si6222063wmc.95.2018.04.30.16.31.39; Mon, 30 Apr 2018 16:31:40 -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=@jkqxz-net.20150623.gappssmtp.com header.s=20150623 header.b=Z9sgIozS; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5FEFD68A297; Tue, 1 May 2018 02:31:06 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B36A868A315 for ; Tue, 1 May 2018 02:30:59 +0300 (EEST) Received: by mail-wm0-f65.google.com with SMTP id l1so16839436wmb.2 for ; Mon, 30 Apr 2018 16:31:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jkqxz-net.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id; bh=Q8yT+OwRpsqspLw+3Y7bPXTJ7nEsn3AIRUkRKEuLIIk=; b=Z9sgIozSmiERy7LK94JbD4q4NgP5Z0ziu/mzyC9T5PtjuxnAZMe8syXxYSMsDeqyBF v5Q5bBa+t2Cnwbxmnb7RhVZGJniLZ8zJRH9fayzNaTKpGPI1eLulZoAKjc8TnIdrgNDf dcecBHw7pqZvX7Auf6uB47gNX8KfVVYV7Ab5kymSj2J+AcFVmdNxLjtS8wGrAPoaug0g roFYjbbGrsqLW/6/zeo915unmZdWhEfYT7kM8PrU3XoOGAyFlXJ6CCD3qG1isoaZL7xv Eu85i86NBudZ8PiAr9BWZKUXWW1lJJephdMcLbdm+mZN8nE449V75C9QUJVT+xvmVwOG hOcA== 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=Q8yT+OwRpsqspLw+3Y7bPXTJ7nEsn3AIRUkRKEuLIIk=; b=LBZGIol1bxox9Yz1r1zyV1PLQFeMWKB7qZxm2WgK5fyGslC5dP4TiYnoQWozGXHUq6 YOPHL1Bf2/75HmA+o2xREyzVjkjYS9sZkxd9IWljERvHgll6tdCCYVSRJ2fd2uhHN06w VBn9C/0MAlgJQImYBUmYhCleqT0HoxxAPwCw6uQwbIcL6y0Ul28hDI4XDz/DALZZWFe6 V+LjNyh8SlAvy90uBc0C2Xfhtw/+cekDzAJto1UJJoTTWlk0VB6AxRN2EyAuMjopIV68 yxskj6lluxVzninWq4YBRetuTCE06JziuoMgIq/1Hu+4uKbhW77wNSRrT+o8AjzLWuf9 LeLw== X-Gm-Message-State: ALQs6tD1+fPfpttT2wtWNCYbRMTjxK/GKwX7PzmASG7WRfjT0HHefpDm xMPqnlo0gG7ebKq77wt0J9xRHXA/ X-Received: by 10.28.178.69 with SMTP id b66mr8094687wmf.31.1525130770148; Mon, 30 Apr 2018 16:26:10 -0700 (PDT) Received: from rywe.jkqxz.net (cpc91242-cmbg18-2-0-cust650.5-4.cable.virginm.net. [82.8.130.139]) by smtp.gmail.com with ESMTPSA id f5-v6sm8777229wrh.35.2018.04.30.16.26.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Apr 2018 16:26:09 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Tue, 1 May 2018 00:26:00 +0100 Message-Id: <20180430232605.4846-1-sw@jkqxz.net> X-Mailer: git-send-email 2.16.3 Subject: [FFmpeg-devel] [PATCH 1/6] cbs: Fragment/unit data is always reference counted 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" Make this clear in the documentation and add some asserts to ensure that it is always true. --- As suggested earlier :) libavcodec/cbs.c | 18 ++++++++++++------ libavcodec/cbs.h | 10 ++++++---- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c index d81b4e03f7..0d6ffe8824 100644 --- a/libavcodec/cbs.c +++ b/libavcodec/cbs.c @@ -140,26 +140,30 @@ static int cbs_read_fragment_content(CodedBitstreamContext *ctx, int err, i, j; for (i = 0; i < frag->nb_units; i++) { + CodedBitstreamUnit *unit = &frag->units[i]; + if (ctx->decompose_unit_types) { for (j = 0; j < ctx->nb_decompose_unit_types; j++) { - if (ctx->decompose_unit_types[j] == frag->units[i].type) + if (ctx->decompose_unit_types[j] == unit->type) break; } if (j >= ctx->nb_decompose_unit_types) continue; } - av_buffer_unref(&frag->units[i].content_ref); - frag->units[i].content = NULL; + av_buffer_unref(&unit->content_ref); + unit->content = NULL; + + av_assert0(unit->data && unit->data_ref); - err = ctx->codec->read_unit(ctx, &frag->units[i]); + err = ctx->codec->read_unit(ctx, unit); if (err == AVERROR(ENOSYS)) { av_log(ctx->log_ctx, AV_LOG_VERBOSE, "Decomposition unimplemented for unit %d " - "(type %"PRIu32").\n", i, frag->units[i].type); + "(type %"PRIu32").\n", i, unit->type); } else if (err < 0) { av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to read unit %d " - "(type %"PRIu32").\n", i, frag->units[i].type); + "(type %"PRIu32").\n", i, unit->type); return err; } } @@ -277,6 +281,7 @@ int ff_cbs_write_fragment_data(CodedBitstreamContext *ctx, "(type %"PRIu32").\n", i, unit->type); return err; } + av_assert0(unit->data && unit->data_ref); } av_buffer_unref(&frag->data_ref); @@ -287,6 +292,7 @@ int ff_cbs_write_fragment_data(CodedBitstreamContext *ctx, av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to assemble fragment.\n"); return err; } + av_assert0(frag->data && frag->data_ref); return 0; } diff --git a/libavcodec/cbs.h b/libavcodec/cbs.h index 402eb39e00..487358afaf 100644 --- a/libavcodec/cbs.h +++ b/libavcodec/cbs.h @@ -84,8 +84,9 @@ typedef struct CodedBitstreamUnit { */ size_t data_bit_padding; /** - * If data is reference counted, a reference to the buffer containing - * data. Null if data is not reference counted. + * A reference to the buffer containing data. + * + * Must be set if data is not NULL. */ AVBufferRef *data_ref; @@ -130,8 +131,9 @@ typedef struct CodedBitstreamFragment { */ size_t data_bit_padding; /** - * If data is reference counted, a reference to the buffer containing - * data. Null if data is not reference counted. + * A reference to the buffer containing data. + * + * Must be set if data is not NULL. */ AVBufferRef *data_ref;