From patchwork Mon Apr 1 23:39:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 12558 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 95F2A447332 for ; Tue, 2 Apr 2019 02:39:59 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 813E068ABF7; Tue, 2 Apr 2019 02:39:59 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 85B3968ABEB for ; Tue, 2 Apr 2019 02:39:52 +0300 (EEST) Received: by mail-wm1-f48.google.com with SMTP id 4so1222768wmf.1 for ; Mon, 01 Apr 2019 16:39:52 -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:in-reply-to:references:mime-version :content-transfer-encoding; bh=G2T9bQivynpaBRrEUg7/51pSw6PeMb03TiSwMNNLIVc=; b=LIA11q/1RFtsQPphsd8VMApLCsgpPjTE54j/3gpIT80zFrb+eUEnzVza0b+q8r5ozM Ovj1xr7KeC7fRFtYH9v3UJxFZ/RDYZv8l0BbewR2VX27u6Qm11njIYCQ8E6oBYIB2rGM 1w0e9ibd4MKP2TVMVnx1R5JUU9KHou01bgnsYwPskOWSorzhu5gPPWMCe5dWwnMpqxke EGEGhvTF/TJVrMZ/aVdgL+7ZFd6b1fMKATyujyxqtA4U944G5ID3RdRBGiC0Vsl3h71d N2tcEoeKVFW6F7A0vI4wA73/9whoKYv4+CvAQxSM93MfflOq3+Xj0isshepEOQrP9Iad +3Zw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=G2T9bQivynpaBRrEUg7/51pSw6PeMb03TiSwMNNLIVc=; b=TQyA53DZ7348YiK7wEzHbAJkfl8lBZlLXeuxUjHokxXvq5/ANHFJBz4nopmREVs+7C ymdCNwJmyl/sanHXGEFTPJs7rt3xySnQBb35vnKVxU8pY/w3ci+IGo/p8F0DeS4ig5uT ibRc0LtlupLhoyYV8LafG0ZxyqhGUoVzG6z/lsj7z+U3jyPULTD2Us/yqHJNJqg9tT5p vY+14hkzuJT9UxZa7ejMPcge//M57yIFvvk9BULKTCJIRaIVmj9NZAmDA4SfUowvMXJK jOfPyTw73GWiYEvzqtZBd9bAE+YwMz0o9F4pMJODacH0B/+e/ufjHwhpDg9eC9ri3hFt Ht4A== X-Gm-Message-State: APjAAAX0SlEErIJMBuryG3UMdYV8C5nFLoeH0AC9vEjwYdJSi05dJmZd nh75KInK1SlIA0GAJBaB5QmdAkyZCUk= X-Google-Smtp-Source: APXvYqzLbCPqfDZD+mYh7k7Brt1RDsx7hkTA4hASkUxQfnNPokEcWeJlqTTHB6CjWnUwpKomgf+8Gg== X-Received: by 2002:a7b:c155:: with SMTP id z21mr483815wmi.1.1554161991728; Mon, 01 Apr 2019 16:39:51 -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 r30sm27943044wrr.46.2019.04.01.16.39.50 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 01 Apr 2019 16:39:50 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Tue, 2 Apr 2019 00:39:37 +0100 Message-Id: <20190401233940.5941-6-sw@jkqxz.net> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190401233940.5941-1-sw@jkqxz.net> References: <20190401233940.5941-1-sw@jkqxz.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 6/9] cbs_av1: Implement parser entrypoint 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" --- Unsure about this one - while the patch is short, it's rather invasive in a pretty ugly way with how it abuses the read call. It will still do allocations for the decomposition because of that, even though we don't really want them. Any ideas welcome. libavcodec/cbs_av1.c | 89 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 79 insertions(+), 10 deletions(-) diff --git a/libavcodec/cbs_av1.c b/libavcodec/cbs_av1.c index 02f168b58d..0b54b5820c 100644 --- a/libavcodec/cbs_av1.c +++ b/libavcodec/cbs_av1.c @@ -776,13 +776,15 @@ static int cbs_av1_get_relative_dist(const AV1RawSequenceHeader *seq, #undef byte_alignment -static int cbs_av1_split_fragment(CodedBitstreamContext *ctx, - CodedBitstreamFragment *frag, - int header) +typedef int (*cbs_av1_split_obu_callback)(CodedBitstreamContext *ctx, + void *priv, int obu_type, + const uint8_t *data, size_t size); + +static int cbs_av1_split_obus(CodedBitstreamContext *ctx, + void *priv, cbs_av1_split_obu_callback cb, + const uint8_t *data, size_t size) { GetBitContext gbc; - uint8_t *data; - size_t size; uint64_t obu_length; int pos, err, trace; @@ -790,9 +792,6 @@ static int cbs_av1_split_fragment(CodedBitstreamContext *ctx, trace = ctx->trace_enable; ctx->trace_enable = 0; - data = frag->data; - size = frag->data_size; - if (INT_MAX / 8 < size) { av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid fragment: " "too large (%"SIZE_SPECIFIER" bytes).\n", size); @@ -837,8 +836,7 @@ static int cbs_av1_split_fragment(CodedBitstreamContext *ctx, goto fail; } - err = ff_cbs_insert_unit_data(ctx, frag, -1, header.obu_type, - data, obu_length, frag->data_ref); + err = cb(ctx, priv, header.obu_type, data, obu_length); if (err < 0) goto fail; @@ -852,6 +850,23 @@ fail: return err; } +static int cbs_av1_insert_obu(CodedBitstreamContext *ctx, + void *priv, int obu_type, + const uint8_t *data, size_t size) +{ + CodedBitstreamFragment *frag = priv; + return ff_cbs_insert_unit_data(ctx, frag, -1, obu_type, + (uint8_t*)data, size, frag->data_ref); +} + +static int cbs_av1_split_fragment(CodedBitstreamContext *ctx, + CodedBitstreamFragment *frag, + int header) +{ + return cbs_av1_split_obus(ctx, frag, &cbs_av1_insert_obu, + frag->data, frag->data_size); +} + static void cbs_av1_free_tile_data(AV1RawTileData *td) { av_buffer_unref(&td->data_ref); @@ -895,6 +910,12 @@ static int cbs_av1_ref_tile_data(CodedBitstreamContext *ctx, { int pos; + if (!unit->data_ref) { + // Not refcounted - only parsing headers, so tile data will + // not be needed. + return 0; + } + pos = get_bits_count(gbc); if (pos >= 8 * unit->data_size) { av_log(ctx->log_ctx, AV_LOG_ERROR, "Bitstream ended before " @@ -1324,6 +1345,52 @@ static void cbs_av1_close(CodedBitstreamContext *ctx) av_freep(&priv->write_buffer); } +static int cbs_av1_parse_obu(CodedBitstreamContext *ctx, + void *priv, int obu_type, + const uint8_t *data, size_t data_size) +{ + CodedBitstreamUnit unit; + int err; + + // These OBU types will not affect parsing. + if (obu_type == AV1_OBU_METADATA || + obu_type == AV1_OBU_TILE_LIST || + obu_type == AV1_OBU_PADDING) + return 0; + + unit = (CodedBitstreamUnit) { + .type = obu_type, + .data = (uint8_t*)data, + .data_size = data_size, + }; + + err = cbs_av1_read_unit(ctx, &unit); + if (err >= 0 && priv) { + AV1RawOBU *obu = unit.content; + switch (obu->header.obu_type) { + case AV1_OBU_FRAME_HEADER: + case AV1_OBU_REDUNDANT_FRAME_HEADER: + memcpy(priv, &obu->obu.frame_header, + sizeof(obu->obu.frame_header)); + break; + case AV1_OBU_FRAME: + memcpy(priv, &obu->obu.frame.header, + sizeof(obu->obu.frame.header)); + break; + } + } + + av_buffer_unref(&unit.content_ref); + + return err; +} + +static int cbs_av1_parse_headers(CodedBitstreamContext *ctx, void *header, + const uint8_t *data, size_t size) +{ + return cbs_av1_split_obus(ctx, header, &cbs_av1_parse_obu, data, size); +} + const CodedBitstreamType ff_cbs_type_av1 = { .codec_id = AV_CODEC_ID_AV1, @@ -1335,4 +1402,6 @@ const CodedBitstreamType ff_cbs_type_av1 = { .assemble_fragment = &cbs_av1_assemble_fragment, .close = &cbs_av1_close, + + .parse_headers = &cbs_av1_parse_headers, };