From patchwork Mon Jul 27 16:32:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 21291 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 261EC44B627 for ; Mon, 27 Jul 2020 19:32:53 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 03A3B68B8AB; Mon, 27 Jul 2020 19:32:53 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 456F068B859 for ; Mon, 27 Jul 2020 19:32:44 +0300 (EEST) Received: by mail-wm1-f66.google.com with SMTP id x5so14165870wmi.2 for ; Mon, 27 Jul 2020 09:32:44 -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=RY/Fd/av/rILUEw9f2LyNeN6+bTq44pkoueDT08eGs4=; b=c6/04O7g34wmQiCPKUEP7qtCDLom1TJA5CHKNLvZCS/9Day/o68i1gzTRoBK76gm4T y1kXDAbV0z5mBqh8EJQHursCg1frj/xN6T4fBHRZxJkBZse75GNnkS8lNFgPbwFyKFQj ja1DXuWnKtgyVZEtXkFU3lBhtfgoyD74UhkVXxyZEf1XQrXt+dBICZf9okeeWNTZm+k3 CSav27TMSjZarKRL/qaZCbrYIBKjrq1bHOUctLmtJCSBWjQsCCGuOSXzUe0hYVToDaJ6 kYVVj6AZzBKC4L8S8DCpcQ4KfwBLitbmWlslLJf8+OAjGSyqcMArYJFazxkXKs6ANmyz 7+Bw== 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=RY/Fd/av/rILUEw9f2LyNeN6+bTq44pkoueDT08eGs4=; b=G2GvFDrIH0M8OmrU6+jUi3SQyKXjtYdSN46KF6Q827uwOe9PGGAX0CYol13z1Wc9zn +2DZ9I/zdbtC1UbIS0cVpLDHCu+/eN3UqQxzNRyp1HTotxSQxp9MuMcDGQ2o4cRZjAJ0 kNLUlpNuBeZsUCMDagoRaaw7b2Tpcd3kTABZ/cF6yAlQvKE+CQa5T4F6E/L51hL6UXkA Hn2nj9D9MYOOHAHf/kWIE4q5RDUJpdHpehNHf43seiwrYyGnwslqeA8xY2seymxqJ6ic oSX4lRN6mSGSK5JQInGRLbuzrFUy6a6DaaeSXl0K4eJf9zHdjyjppOSGStJWYlqB3jdb r+MA== X-Gm-Message-State: AOAM530aJERlZqW7/SzPfepoprcDP1UPQqpPYRrJTEJcHp1tMWJcAvQv eYzjbHpDD6D8zt70PG3HG45ajbBClUU= X-Google-Smtp-Source: ABdhPJxyecaAebEb08DfrS3siAuVzCQ90sgNmqE/0tudnhFIk+miX8pNaU9Fio6NLWEfHKJ22ck20A== X-Received: by 2002:a1c:f60d:: with SMTP id w13mr113042wmc.51.1595867563577; Mon, 27 Jul 2020 09:32:43 -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 w16sm14706791wrg.95.2020.07.27.09.32.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2020 09:32:42 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Mon, 27 Jul 2020 17:32:16 +0100 Message-Id: <20200727163237.23371-2-sw@jkqxz.net> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727163237.23371-1-sw@jkqxz.net> References: <20200727163237.23371-1-sw@jkqxz.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 01/22] cbs: Mention all codecs in unit type comment 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" --- libavcodec/cbs.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavcodec/cbs.h b/libavcodec/cbs.h index e897e348a2..07faf18c5b 100644 --- a/libavcodec/cbs.h +++ b/libavcodec/cbs.h @@ -45,8 +45,10 @@ struct CodedBitstreamType; /** * The codec-specific type of a bitstream unit. * + * AV1: obu_type * H.264 / AVC: nal_unit_type * H.265 / HEVC: nal_unit_type + * JPEG: marker value (without 0xff prefix) * MPEG-2: start code value (without prefix) * VP9: unused, set to zero (every unit is a frame) */ From patchwork Mon Jul 27 16:32:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 21292 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 5894244B627 for ; Mon, 27 Jul 2020 19:32:54 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 38EA868B89E; Mon, 27 Jul 2020 19:32:54 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9414C68B885 for ; Mon, 27 Jul 2020 19:32:45 +0300 (EEST) Received: by mail-wr1-f43.google.com with SMTP id a14so15548722wra.5 for ; Mon, 27 Jul 2020 09:32:45 -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=H6DhSYcTIwuq/dXYGZlEZWrouOjI0Vpkjmj6j+NMuxg=; b=XSxyQLK4QrLlVTKGiXruADk3UVIbVI1mwGAXelwVR+NP1MPZUi6SA9YwsqLzb0xxeW cMsO5KSecZDbu+MxLrVrtsj0eLFfgf9yGO22cd7zQQgg14+R8a8bay8GHW6TLEOpaRwm ZqZysUqzmFTkNa/gCnZsFP9oOrvC1j/iLhmqqAt8RPJ5mPBl45Tk0fxghJ6cEUaUS1rS +n2vMcZJai2/OLnTem1YhWuSqJo2MWkSyNP5WCCc+GPKr4NjEtpbaS0ghXrVatANjUvO GdYpVeYsrbl1JDPJpWWgYdOMBZnadHwAgxhKZuwd2CziqcFpk/k5Pb9liGaxSh2Kp2l4 obNQ== 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=H6DhSYcTIwuq/dXYGZlEZWrouOjI0Vpkjmj6j+NMuxg=; b=nOh1vyC+L+55/mCYHvDnYQrO4VnsxLYrz5vljIIUgCx5HifpzYAKTahifCHarKBENW TCXO+tceKF6HfPZfdEPTlFLJWRab89xj76JxIh8P1X91F8FIhkNAsyXIf/HxodCqlhU1 FtWoRIsojI9AudiuowE0C2eLJ7uEWG5pRiIGIYbP5kPbkqYw6Meqp2QRuqHeCTr1xXVi /9h0agAVRUQ6FYaQcIuWBAdFEUfco2Om/nBSB/4NG/RPs8TkyfUhdcZ1gl58i0M75MI2 2dXk4L4pxsri/nuGOEqetmmd7oPQD2e0ySL5KD/X//pT+LT5gija7ywaPqJUfoXhzQtt WGYA== X-Gm-Message-State: AOAM53184oYSMxtg3a41pXT8QaR3D/umTYbIRHTl1UgmnhWjZqXGKYTI o0qbEaX5FMI9hljNaWflQl+IMs0oBjQ= X-Google-Smtp-Source: ABdhPJxwRb6eZXkaVKSVzRMwbGJGMPSxvUcIyJ7gFEmmPFDM1xl5kuq3GYKb7c/H6AsvzfA9kSHOJA== X-Received: by 2002:adf:dfc8:: with SMTP id q8mr20374394wrn.231.1595867564542; Mon, 27 Jul 2020 09:32:44 -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 w16sm14706791wrg.95.2020.07.27.09.32.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2020 09:32:43 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Mon, 27 Jul 2020 17:32:17 +0100 Message-Id: <20200727163237.23371-3-sw@jkqxz.net> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727163237.23371-1-sw@jkqxz.net> References: <20200727163237.23371-1-sw@jkqxz.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 02/22] cbs: Ensure that reference fields always follow the associated pointer 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" Having these together allows us to find both pointers given the address of only one of them. --- libavcodec/cbs_av1.h | 6 +++--- libavcodec/cbs_h264.h | 18 +++++++++--------- libavcodec/cbs_h265.h | 16 ++++++++-------- libavcodec/cbs_jpeg.h | 2 +- libavcodec/cbs_mpeg2.h | 10 +++++----- libavcodec/cbs_vp9.h | 2 +- 6 files changed, 27 insertions(+), 27 deletions(-) diff --git a/libavcodec/cbs_av1.h b/libavcodec/cbs_av1.h index f5fed220a5..85ff628008 100644 --- a/libavcodec/cbs_av1.h +++ b/libavcodec/cbs_av1.h @@ -284,8 +284,8 @@ typedef struct AV1RawFrameHeader { typedef struct AV1RawTileData { uint8_t *data; - size_t data_size; AVBufferRef *data_ref; + size_t data_size; } AV1RawTileData; typedef struct AV1RawTileGroup { @@ -346,8 +346,8 @@ typedef struct AV1RawMetadataITUTT35 { uint8_t itu_t_t35_country_code_extension_byte; uint8_t *payload; - size_t payload_size; AVBufferRef *payload_ref; + size_t payload_size; } AV1RawMetadataITUTT35; typedef struct AV1RawMetadataTimecode { @@ -379,8 +379,8 @@ typedef struct AV1RawMetadata { typedef struct AV1RawPadding { uint8_t *payload; - size_t payload_size; AVBufferRef *payload_ref; + size_t payload_size; } AV1RawPadding; diff --git a/libavcodec/cbs_h264.h b/libavcodec/cbs_h264.h index f54ccd3b36..a6fe0a6af2 100644 --- a/libavcodec/cbs_h264.h +++ b/libavcodec/cbs_h264.h @@ -277,16 +277,16 @@ typedef struct H264RawSEIPanScanRect { typedef struct H264RawSEIUserDataRegistered { uint8_t itu_t_t35_country_code; uint8_t itu_t_t35_country_code_extension_byte; - uint8_t *data; - size_t data_length; + uint8_t *data; AVBufferRef *data_ref; + size_t data_length; } H264RawSEIUserDataRegistered; typedef struct H264RawSEIUserDataUnregistered { uint8_t uuid_iso_iec_11578[16]; - uint8_t *data; - size_t data_length; + uint8_t *data; AVBufferRef *data_ref; + size_t data_length; } H264RawSEIUserDataUnregistered; typedef struct H264RawSEIRecoveryPoint { @@ -334,9 +334,9 @@ typedef struct H264RawSEIPayload { H264RawSEIAlternativeTransferCharacteristics alternative_transfer_characteristics; struct { - uint8_t *data; - size_t data_length; + uint8_t *data; AVBufferRef *data_ref; + size_t data_length; } other; } payload; } H264RawSEIPayload; @@ -429,10 +429,10 @@ typedef struct H264RawSliceHeader { typedef struct H264RawSlice { H264RawSliceHeader header; - uint8_t *data; - size_t data_size; - int data_bit_start; + uint8_t *data; AVBufferRef *data_ref; + size_t data_size; + int data_bit_start; } H264RawSlice; typedef struct H264RawFiller { diff --git a/libavcodec/cbs_h265.h b/libavcodec/cbs_h265.h index 73897f77a4..c14cd4cd66 100644 --- a/libavcodec/cbs_h265.h +++ b/libavcodec/cbs_h265.h @@ -184,8 +184,8 @@ typedef struct H265RawVUI { typedef struct H265RawExtensionData { uint8_t *data; - size_t bit_length; AVBufferRef *data_ref; + size_t bit_length; } H265RawExtensionData; typedef struct H265RawVPS { @@ -541,10 +541,10 @@ typedef struct H265RawSliceHeader { typedef struct H265RawSlice { H265RawSliceHeader header; - uint8_t *data; - size_t data_size; - int data_bit_start; + uint8_t *data; AVBufferRef *data_ref; + size_t data_size; + int data_bit_start; } H265RawSlice; @@ -600,15 +600,15 @@ typedef struct H265RawSEIUserDataRegistered { uint8_t itu_t_t35_country_code; uint8_t itu_t_t35_country_code_extension_byte; uint8_t *data; - size_t data_length; AVBufferRef *data_ref; + size_t data_length; } H265RawSEIUserDataRegistered; typedef struct H265RawSEIUserDataUnregistered { uint8_t uuid_iso_iec_11578[16]; uint8_t *data; - size_t data_length; AVBufferRef *data_ref; + size_t data_length; } H265RawSEIUserDataUnregistered; typedef struct H265RawSEIRecoveryPoint { @@ -710,9 +710,9 @@ typedef struct H265RawSEIPayload { alternative_transfer_characteristics; H265RawSEIAlphaChannelInfo alpha_channel_info; struct { - uint8_t *data; - size_t data_length; + uint8_t *data; AVBufferRef *data_ref; + size_t data_length; } other; } payload; H265RawExtensionData extension_data; diff --git a/libavcodec/cbs_jpeg.h b/libavcodec/cbs_jpeg.h index ff1961106f..6305f0ee86 100644 --- a/libavcodec/cbs_jpeg.h +++ b/libavcodec/cbs_jpeg.h @@ -80,8 +80,8 @@ typedef struct JPEGRawScanHeader { typedef struct JPEGRawScan { JPEGRawScanHeader header; uint8_t *data; - size_t data_size; AVBufferRef *data_ref; + size_t data_size; } JPEGRawScan; typedef struct JPEGRawQuantisationTable { diff --git a/libavcodec/cbs_mpeg2.h b/libavcodec/cbs_mpeg2.h index 5bcafd09f0..f7075a460d 100644 --- a/libavcodec/cbs_mpeg2.h +++ b/libavcodec/cbs_mpeg2.h @@ -76,9 +76,9 @@ typedef struct MPEG2RawSequenceHeader { typedef struct MPEG2RawUserData { uint8_t user_data_start_code; - uint8_t *user_data; - size_t user_data_length; + uint8_t *user_data; AVBufferRef *user_data_ref; + size_t user_data_length; } MPEG2RawUserData; typedef struct MPEG2RawSequenceExtension { @@ -206,10 +206,10 @@ typedef struct MPEG2RawSliceHeader { typedef struct MPEG2RawSlice { MPEG2RawSliceHeader header; - uint8_t *data; - size_t data_size; - int data_bit_start; + uint8_t *data; AVBufferRef *data_ref; + size_t data_size; + int data_bit_start; } MPEG2RawSlice; typedef struct MPEG2RawSequenceEnd { diff --git a/libavcodec/cbs_vp9.h b/libavcodec/cbs_vp9.h index 40e62476ed..af15eb4bac 100644 --- a/libavcodec/cbs_vp9.h +++ b/libavcodec/cbs_vp9.h @@ -165,8 +165,8 @@ typedef struct VP9RawFrame { VP9RawFrameHeader header; uint8_t *data; - size_t data_size; AVBufferRef *data_ref; + size_t data_size; } VP9RawFrame; typedef struct VP9RawSuperframeIndex { From patchwork Mon Jul 27 16:32:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 21293 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 C9FBE44B627 for ; Mon, 27 Jul 2020 19:32:55 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B10FE68B8E2; Mon, 27 Jul 2020 19:32:55 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id ABCD868B85C for ; Mon, 27 Jul 2020 19:32:46 +0300 (EEST) Received: by mail-wr1-f48.google.com with SMTP id f1so14991112wro.2 for ; Mon, 27 Jul 2020 09:32:46 -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=K6d7ai7ekyIRwQXRupTN4kFAIUaawsw3lH5rU7Oc7BA=; b=WfWcVKVVEGHzu3eDTsxOyKTtUupxIDAyBC2NQZ1VhxdUL+EartpOFaR+HYztqXcqFN X4oyraTTKGR0y5EzarTgkF5vgF8FNfZG31O/f+f0Hd9LhlH6zCQq+swnoZVRNVLa9I3j gP+Z6uo8FOMtAvrOupz1UeT+hlw/rROnvqEqmBQJPvvgF+kMpX7ie53Fg3xNevarfcYn i5lM0s123Yiv5TJRpjEthqJ1Lzb0iZgQ4laR8vVxMSRsyyiaWztCJRwcjrUHK/mXyLZ2 cq/QtnMMDUDsNRTIm+y/dIymyqftvGXjIXrpV2zeirZjYzHtJvLneV5MOUeRNDdCgDFn wIxg== 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=K6d7ai7ekyIRwQXRupTN4kFAIUaawsw3lH5rU7Oc7BA=; b=UC0X2HB68IiwPw/e/wBq3B4AKh1f6nJ84yYuRzXZBQkIedmzzk+mbBx+ioiN0irIlJ ODBb4B30FdZM69HPBzDw0b3if2gt7sGzruwYr7l/Ace6yeWcG9bH/NxkSaOh4iVQRrag IOeRN1Q5In6ZdMPqc0QSgCr85y8/QBkspa7SLTWh0EhKSMWYf+OHxpPXmgL3DsOQLJhi wPe7vyYPWMYxZKIzvynYS1pRkv2DiUJmNqFr/IfWKFjTKXscLRjadjWdOCdV/o541non up5Qpb/h0GHJL6TrDvBFV3GUuGFqhp39mMe+iZVTPCh2UFk33GOgPPMPczCpqoam8fsQ Xp0w== X-Gm-Message-State: AOAM531JtVFAt4Qn+IbY9zqWPjnCKqt4FOYuZNrQMhzbQffb0o5XSoPT 5AN7dHp1gY1LMXdbDvr5e7j6o19ZOGI= X-Google-Smtp-Source: ABdhPJzC9ec4v31Ey+T/xotP2xBc7iSbjDXflmsBbFufZwuQycfWcmZ+DWBMnPXk8/MlCZTGzEbfQQ== X-Received: by 2002:adf:b18d:: with SMTP id q13mr20761068wra.256.1595867565649; Mon, 27 Jul 2020 09:32:45 -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 w16sm14706791wrg.95.2020.07.27.09.32.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2020 09:32:44 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Mon, 27 Jul 2020 17:32:18 +0100 Message-Id: <20200727163237.23371-4-sw@jkqxz.net> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727163237.23371-1-sw@jkqxz.net> References: <20200727163237.23371-1-sw@jkqxz.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 03/22] cbs: Describe allocate/free methods in tabular form 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" Unit types are split into three categories, depending on how their content is managed: * POD structure - these require no special treatment. * Structure containing references to refcounted buffers - these can use a common free function when the offsets of all the internal references are known. * More complex structures - these still require ad-hoc treatment. For each codec we can then maintain a table of descriptors for each set of equivalent unit types, defining the mechanism needed to allocate/free that unit content. This is not required to be used immediately - a new alloc function supports this, but does not replace the old one which works without referring to these tables. --- libavcodec/cbs.c | 69 +++++++++++++++++++++++++++++++++++++++ libavcodec/cbs.h | 9 +++++ libavcodec/cbs_internal.h | 61 ++++++++++++++++++++++++++++++++++ 3 files changed, 139 insertions(+) diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c index 6464980c8e..61cf8e3466 100644 --- a/libavcodec/cbs.c +++ b/libavcodec/cbs.c @@ -802,3 +802,72 @@ void ff_cbs_delete_unit(CodedBitstreamFragment *frag, frag->units + position + 1, (frag->nb_units - position) * sizeof(*frag->units)); } + +static void cbs_default_free_unit_content(void *opaque, uint8_t *data) +{ + const CodedBitstreamUnitTypeDescriptor *desc = opaque; + if (desc->content_type == CBS_CONTENT_TYPE_INTERNAL_REFS) { + int i; + for (i = 0; i < desc->nb_ref_offsets; i++) { + void **ptr = (void**)(data + desc->ref_offsets[i]); + av_buffer_unref((AVBufferRef**)(ptr + 1)); + } + } + av_free(data); +} + +static const CodedBitstreamUnitTypeDescriptor + *cbs_find_unit_type_desc(CodedBitstreamContext *ctx, + CodedBitstreamUnit *unit) +{ + const CodedBitstreamUnitTypeDescriptor *desc; + int i, j; + + if (!ctx->codec->unit_types) + return NULL; + + for (i = 0;; i++) { + desc = &ctx->codec->unit_types[i]; + if (desc->nb_unit_types == 0) + break; + if (desc->nb_unit_types == CBS_UNIT_TYPE_RANGE) { + if (unit->type >= desc->unit_type_range_start && + unit->type <= desc->unit_type_range_end) + return desc; + } else { + for (j = 0; j < desc->nb_unit_types; j++) { + if (desc->unit_types[j] == unit->type) + return desc; + } + } + } + return NULL; +} + +int ff_cbs_alloc_unit_content2(CodedBitstreamContext *ctx, + CodedBitstreamUnit *unit) +{ + const CodedBitstreamUnitTypeDescriptor *desc; + + av_assert0(!unit->content && !unit->content_ref); + + desc = cbs_find_unit_type_desc(ctx, unit); + if (!desc) + return AVERROR(ENOSYS); + + unit->content = av_mallocz(desc->content_size); + if (!unit->content) + return AVERROR(ENOMEM); + + unit->content_ref = + av_buffer_create(unit->content, desc->content_size, + desc->content_free ? desc->content_free + : cbs_default_free_unit_content, + (void*)desc, 0); + if (!unit->content_ref) { + av_freep(&unit->content); + return AVERROR(ENOMEM); + } + + return 0; +} diff --git a/libavcodec/cbs.h b/libavcodec/cbs.h index 07faf18c5b..ea8d942894 100644 --- a/libavcodec/cbs.h +++ b/libavcodec/cbs.h @@ -349,6 +349,15 @@ int ff_cbs_alloc_unit_content(CodedBitstreamUnit *unit, size_t size, void (*free)(void *opaque, uint8_t *content)); +/** + * Allocate a new internal content buffer matching the type of the unit. + * + * The content will be zeroed. + */ +int ff_cbs_alloc_unit_content2(CodedBitstreamContext *ctx, + CodedBitstreamUnit *unit); + + /** * Allocate a new internal data buffer of the given size in the unit. * diff --git a/libavcodec/cbs_internal.h b/libavcodec/cbs_internal.h index 4c5a535ca6..282492bc88 100644 --- a/libavcodec/cbs_internal.h +++ b/libavcodec/cbs_internal.h @@ -25,11 +25,72 @@ #include "put_bits.h" +enum CBSContentType { + // Unit content is a simple structure. + CBS_CONTENT_TYPE_POD, + // Unit content contains some references to other structures, but all + // managed via buffer reference counting. The descriptor defines the + // structure offsets of every buffer reference. + CBS_CONTENT_TYPE_INTERNAL_REFS, + // Unit content is something more complex. The descriptor defines + // special functions to manage the content. + CBS_CONTENT_TYPE_COMPLEX, +}; + +enum { + // Maximum number of unit types described by the same unit type + // descriptor. + CBS_MAX_UNIT_TYPES = 3, + // Maximum number of reference buffer offsets in any one unit. + CBS_MAX_REF_OFFSETS = 2, + // Special value used in a unit type descriptor to indicate that it + // applies to a large range of types rather than a set of discrete + // values. + CBS_UNIT_TYPE_RANGE = -1, +}; + +typedef const struct CodedBitstreamUnitTypeDescriptor { + // Number of entries in the unit_types array, or the special value + // CBS_UNIT_TYPE_RANGE to indicate that the range fields should be + // used instead. + int nb_unit_types; + + // Array of unit types that this entry describes. + const CodedBitstreamUnitType unit_types[CBS_MAX_UNIT_TYPES]; + + // Start and end of unit type range, used if nb_unit_types is + // CBS_UNIT_TYPE_RANGE. + const CodedBitstreamUnitType unit_type_range_start; + const CodedBitstreamUnitType unit_type_range_end; + + // The type of content described. + enum CBSContentType content_type; + // The size of the structure which should be allocated to contain + // the decomposed content of this type of unit. + size_t content_size; + + // Number of entries in the ref_offsets array. Only used if the + // content_type is CBS_CONTENT_TYPE_INTERNAL_REFS. + int nb_ref_offsets; + // The structure must contain two adjacent elements: + // type *field; + // AVBufferRef *field_ref; + // where field points to something in the buffer referred to by + // field_ref. This offset is then set to offsetof(struct, field). + size_t ref_offsets[CBS_MAX_REF_OFFSETS]; + + void (*content_free)(void *opaque, uint8_t *data); +} CodedBitstreamUnitTypeDescriptor; + typedef struct CodedBitstreamType { enum AVCodecID codec_id; size_t priv_data_size; + // List of unit type descriptors for this codec. + // Terminated by a descriptor with nb_unit_types equal to zero. + const CodedBitstreamUnitTypeDescriptor *unit_types; + // Split frag->data into coded bitstream units, creating the // frag->units array. Fill data but not content on each unit. // The header argument should be set if the fragment came from From patchwork Mon Jul 27 16:32:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 21294 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 237B644B627 for ; Mon, 27 Jul 2020 19:32:57 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F22E068B8F8; Mon, 27 Jul 2020 19:32:56 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E893068B861 for ; Mon, 27 Jul 2020 19:32:47 +0300 (EEST) Received: by mail-wr1-f54.google.com with SMTP id a5so5553954wrm.6 for ; Mon, 27 Jul 2020 09:32:47 -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=aW2MuC9bq9z7C0Tb4vwqgdvFoT6YoNfsCoXPK6fsugc=; b=HhNPrM2oUS8/3EKshyHtXWk5+NHresJZYX3MnaEm0aRZMWy587NlVn8zqkbP96Awhz Ii0GGzFv8jB3fhvDOZkAmAp2irN/12qFg/xhbP1FN/G+QG5uQCD8r8+bD7f70Oe2i+Ik VmmMA+80L94sZr9jEOoGBKg0LVG3Ki4dyA7TAbAMNCtmmOgZcnQLB8tAlOvkf49z7+le RFYBMaLxDzJWyic6Xnr5QYFi1/bmg2Dk49+LDUWSIGJWppl6J5WPZI0xTqrNcN9uZXlv PCatMnfC+hZBbyIhJuLHjeswIB4oyX5vPQTnqZm0KMnN62EPfHokFuTNLlPN0SbRgBDu 4MHQ== 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=aW2MuC9bq9z7C0Tb4vwqgdvFoT6YoNfsCoXPK6fsugc=; b=VYdzHYx0TRF/cNsfiQommOLCxvIOPzSLifR0AyIuOPCjSGa/+1AfWhjRN0B18SA+/k xuCkMxz7kMVAkkeNlcW3d7nJ0kMnH8yAC0SYdS0NbaAKG/K24CxIA7+mGd/l3yuj35gJ cvvlU9ezEAByZr54s2R8u7+gsSKUY+ICvzX08KEtGThRT4PI7LNFZ6c+ikQSYR7NFJvJ 7wWOEc+/ukmIU6Hkq1AJIG9iOXvq9NQsFTRTczSkWUOMfH5tUlQEz0azVHiWfOhCh2Sz sSzeJQMPdSWbL3FXGk8Tnhj4+4uLYUu2qqsH3ULHsbaQvc7dlMqXl4h4q+kLibphdB8W Rnzg== X-Gm-Message-State: AOAM533gguJ4eaS5hqxEImcUH5AkpgeTyz8JWvTExdknu3is73h2Qx3S e/DKYnavzPwlHsRbyqFI4d6wYcTE6nA= X-Google-Smtp-Source: ABdhPJxkCDieEyuKN42xFzohaceOi6Z0fLk93/2tSCcCrocUgRfIr4YhVM2tkimoUpLdJHAwffc8ow== X-Received: by 2002:adf:8486:: with SMTP id 6mr21247702wrg.109.1595867567092; Mon, 27 Jul 2020 09:32:47 -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 w16sm14706791wrg.95.2020.07.27.09.32.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2020 09:32:46 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Mon, 27 Jul 2020 17:32:19 +0100 Message-Id: <20200727163237.23371-5-sw@jkqxz.net> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727163237.23371-1-sw@jkqxz.net> References: <20200727163237.23371-1-sw@jkqxz.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 04/22] cbs: Add macros to support defining unit type tables 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" --- libavcodec/cbs_internal.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/libavcodec/cbs_internal.h b/libavcodec/cbs_internal.h index 282492bc88..35159f9c5f 100644 --- a/libavcodec/cbs_internal.h +++ b/libavcodec/cbs_internal.h @@ -167,6 +167,30 @@ int ff_cbs_write_signed(CodedBitstreamContext *ctx, PutBitContext *pbc, #define MIN_INT_BITS(length) (-(INT64_C(1) << ((length) - 1))) +#define CBS_UNIT_TYPE_POD(type, structure) { \ + .nb_unit_types = 1, \ + .unit_types = { type }, \ + .content_type = CBS_CONTENT_TYPE_POD, \ + .content_size = sizeof(structure), \ + } +#define CBS_UNIT_TYPE_INTERNAL_REF(type, structure, ref_field) { \ + .nb_unit_types = 1, \ + .unit_types = { type }, \ + .content_type = CBS_CONTENT_TYPE_INTERNAL_REFS, \ + .content_size = sizeof(structure), \ + .nb_ref_offsets = 1, \ + .ref_offsets = { offsetof(structure, ref_field) }, \ + } +#define CBS_UNIT_TYPE_COMPLEX(type, structure, free_func) { \ + .nb_unit_types = 1, \ + .unit_types = { type }, \ + .content_type = CBS_CONTENT_TYPE_COMPLEX, \ + .content_size = sizeof(structure), \ + .content_free = free_func, \ + } +#define CBS_UNIT_TYPE_END_OF_LIST { .nb_unit_types = 0 } + + extern const CodedBitstreamType ff_cbs_type_av1; extern const CodedBitstreamType ff_cbs_type_h264; extern const CodedBitstreamType ff_cbs_type_h265; From patchwork Mon Jul 27 16:32:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 21296 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 F3FF544B627 for ; Mon, 27 Jul 2020 19:32:59 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D902368B90E; Mon, 27 Jul 2020 19:32:59 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D2A2168B89E for ; Mon, 27 Jul 2020 19:32:48 +0300 (EEST) Received: by mail-wr1-f67.google.com with SMTP id f1so14991231wro.2 for ; Mon, 27 Jul 2020 09:32:48 -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=eW/ZKo/caiFBwv4/Xf9w9A1FQN+xQagm4TwH+tAAK8E=; b=0l+7doT0JVJdBf0sWOgBwXOrdA9Iz4KokQ1DjRRhHhSzq1WERfTPquHJQ2mLM00ZnP 6m7SvoErI8n2HBeCIMTAUCxJgyecQjX3dBAYol/zbVRAqLvjiFNFfTW3FfP6zs4CjdGc y8T8E7fAhBLrzFWctyAumTvwHsZfVb4edzoqePi2cvJNPzUUZM6S1sTaIQQrDtsjbtzl aESaLl+PwHCUK0SGSCn0E/+Ghbn7OFAm1fMBC+slK46lOgNtqtuvKaKVObiVMtRBMtff Q3F48xPcF3Gbwdh5191nEU/FKn019zcTx0v2zIQ1e0lrMU1rr7C5qqndLnL1Non9q1e0 Q7AA== 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=eW/ZKo/caiFBwv4/Xf9w9A1FQN+xQagm4TwH+tAAK8E=; b=MVIhRX4YpC0Tw2sbmnUtf1JL4zjvzdfx7NAo7M9KJJZ1OG0fxXG6mykZWPHZUVylUn jskTmY+2+1ucJwW/1WY0n20z71oImBOZPFhKZaWhABtqB3j6NrlqbafLi2JA8quHc9Qg SqwY0O7pLGsOWAz6BaQWH8ExsazeGd2VfJnvomge9hAnPcxv05XnFnF48Wvrew9Ge8qZ v03+Sx/HlSZrpPN2VrkiX8XdoA4ckpuDM3Xs3irUyGXQLr2Gfey5hUMguBd9vRsRWQNG UVoUKu+ADLeyfh3EwD1Np24ymUtNZ/5+TMjkGubb3goBEf+KlGnS6Y+yrb+Ab6BQgHr6 OeyQ== X-Gm-Message-State: AOAM532u/SYh+fx2bNpB6GP9mrGlsDs4G+4+8gUVhB9dVFNBrVsnAJd3 jjTTcwxY84klVPEJaPbUpdsFnLJoVvM= X-Google-Smtp-Source: ABdhPJzX4msip7Lc3hLv8vmXEST14DAbg9zDkFu9vmQ4AolHvcPEWu4g1rs08eji/4IZ3SyDFfKeYA== X-Received: by 2002:a5d:6748:: with SMTP id l8mr22119124wrw.358.1595867568015; Mon, 27 Jul 2020 09:32:48 -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 w16sm14706791wrg.95.2020.07.27.09.32.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2020 09:32:47 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Mon, 27 Jul 2020 17:32:20 +0100 Message-Id: <20200727163237.23371-6-sw@jkqxz.net> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727163237.23371-1-sw@jkqxz.net> References: <20200727163237.23371-1-sw@jkqxz.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 05/22] cbs_h264: Use table-based alloc/free 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" --- libavcodec/cbs_h2645.c | 163 ++++++++++++++++++----------------------- 1 file changed, 70 insertions(+), 93 deletions(-) diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c index e5c8012d39..5725539e60 100644 --- a/libavcodec/cbs_h2645.c +++ b/libavcodec/cbs_h2645.c @@ -454,52 +454,6 @@ static int cbs_h2645_read_more_rbsp_data(GetBitContext *gbc) #undef allocate -static void cbs_h264_free_pps(void *opaque, uint8_t *content) -{ - H264RawPPS *pps = (H264RawPPS*)content; - av_buffer_unref(&pps->slice_group_id_ref); - av_freep(&content); -} - -static void cbs_h264_free_sei_payload(H264RawSEIPayload *payload) -{ - switch (payload->payload_type) { - case H264_SEI_TYPE_BUFFERING_PERIOD: - case H264_SEI_TYPE_PIC_TIMING: - case H264_SEI_TYPE_PAN_SCAN_RECT: - case H264_SEI_TYPE_RECOVERY_POINT: - case H264_SEI_TYPE_DISPLAY_ORIENTATION: - case H264_SEI_TYPE_MASTERING_DISPLAY_COLOUR_VOLUME: - case H264_SEI_TYPE_ALTERNATIVE_TRANSFER: - break; - case H264_SEI_TYPE_USER_DATA_REGISTERED: - av_buffer_unref(&payload->payload.user_data_registered.data_ref); - break; - case H264_SEI_TYPE_USER_DATA_UNREGISTERED: - av_buffer_unref(&payload->payload.user_data_unregistered.data_ref); - break; - default: - av_buffer_unref(&payload->payload.other.data_ref); - break; - } -} - -static void cbs_h264_free_sei(void *opaque, uint8_t *content) -{ - H264RawSEI *sei = (H264RawSEI*)content; - int i; - for (i = 0; i < sei->payload_count; i++) - cbs_h264_free_sei_payload(&sei->payload[i]); - av_freep(&content); -} - -static void cbs_h264_free_slice(void *opaque, uint8_t *content) -{ - H264RawSlice *slice = (H264RawSlice*)content; - av_buffer_unref(&slice->data_ref); - av_freep(&content); -} - static void cbs_h265_free_vps(void *opaque, uint8_t *content) { H265RawVPS *vps = (H265RawVPS*)content; @@ -802,15 +756,14 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext *ctx, if (err < 0) return err; + err = ff_cbs_alloc_unit_content2(ctx, unit); + if (err < 0) + return err; + switch (unit->type) { case H264_NAL_SPS: { - H264RawSPS *sps; - - err = ff_cbs_alloc_unit_content(unit, sizeof(*sps), NULL); - if (err < 0) - return err; - sps = unit->content; + H264RawSPS *sps = unit->content; err = cbs_h264_read_sps(ctx, &gbc, sps); if (err < 0) @@ -824,12 +777,6 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext *ctx, case H264_NAL_SPS_EXT: { - err = ff_cbs_alloc_unit_content(unit, - sizeof(H264RawSPSExtension), - NULL); - if (err < 0) - return err; - err = cbs_h264_read_sps_extension(ctx, &gbc, unit->content); if (err < 0) return err; @@ -838,13 +785,7 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext *ctx, case H264_NAL_PPS: { - H264RawPPS *pps; - - err = ff_cbs_alloc_unit_content(unit, sizeof(*pps), - &cbs_h264_free_pps); - if (err < 0) - return err; - pps = unit->content; + H264RawPPS *pps = unit->content; err = cbs_h264_read_pps(ctx, &gbc, pps); if (err < 0) @@ -860,15 +801,9 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext *ctx, case H264_NAL_IDR_SLICE: case H264_NAL_AUXILIARY_SLICE: { - H264RawSlice *slice; + H264RawSlice *slice = unit->content; int pos, len; - err = ff_cbs_alloc_unit_content(unit, sizeof(*slice), - &cbs_h264_free_slice); - if (err < 0) - return err; - slice = unit->content; - err = cbs_h264_read_slice_header(ctx, &gbc, &slice->header); if (err < 0) return err; @@ -890,11 +825,6 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext *ctx, case H264_NAL_AUD: { - err = ff_cbs_alloc_unit_content(unit, - sizeof(H264RawAUD), NULL); - if (err < 0) - return err; - err = cbs_h264_read_aud(ctx, &gbc, unit->content); if (err < 0) return err; @@ -903,11 +833,6 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext *ctx, case H264_NAL_SEI: { - err = ff_cbs_alloc_unit_content(unit, sizeof(H264RawSEI), - &cbs_h264_free_sei); - if (err < 0) - return err; - err = cbs_h264_read_sei(ctx, &gbc, unit->content); if (err < 0) return err; @@ -916,11 +841,6 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext *ctx, case H264_NAL_FILLER_DATA: { - err = ff_cbs_alloc_unit_content(unit, - sizeof(H264RawFiller), NULL); - if (err < 0) - return err; - err = cbs_h264_read_filler(ctx, &gbc, unit->content); if (err < 0) return err; @@ -930,12 +850,6 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext *ctx, case H264_NAL_END_SEQUENCE: case H264_NAL_END_STREAM: { - err = ff_cbs_alloc_unit_content(unit, - sizeof(H264RawNALUnitHeader), - NULL); - if (err < 0) - return err; - err = (unit->type == H264_NAL_END_SEQUENCE ? cbs_h264_read_end_of_sequence : cbs_h264_read_end_of_stream)(ctx, &gbc, unit->content); @@ -1505,11 +1419,74 @@ static void cbs_h265_close(CodedBitstreamContext *ctx) av_buffer_unref(&h265->pps_ref[i]); } +static void cbs_h264_free_sei_payload(H264RawSEIPayload *payload) +{ + switch (payload->payload_type) { + case H264_SEI_TYPE_BUFFERING_PERIOD: + case H264_SEI_TYPE_PIC_TIMING: + case H264_SEI_TYPE_PAN_SCAN_RECT: + case H264_SEI_TYPE_RECOVERY_POINT: + case H264_SEI_TYPE_DISPLAY_ORIENTATION: + case H264_SEI_TYPE_MASTERING_DISPLAY_COLOUR_VOLUME: + case H264_SEI_TYPE_ALTERNATIVE_TRANSFER: + break; + case H264_SEI_TYPE_USER_DATA_REGISTERED: + av_buffer_unref(&payload->payload.user_data_registered.data_ref); + break; + case H264_SEI_TYPE_USER_DATA_UNREGISTERED: + av_buffer_unref(&payload->payload.user_data_unregistered.data_ref); + break; + default: + av_buffer_unref(&payload->payload.other.data_ref); + break; + } +} + +static void cbs_h264_free_sei(void *opaque, uint8_t *content) +{ + H264RawSEI *sei = (H264RawSEI*)content; + int i; + for (i = 0; i < sei->payload_count; i++) + cbs_h264_free_sei_payload(&sei->payload[i]); + av_freep(&content); +} + +static const CodedBitstreamUnitTypeDescriptor cbs_h264_unit_types[] = { + CBS_UNIT_TYPE_POD(H264_NAL_SPS, H264RawSPS), + CBS_UNIT_TYPE_POD(H264_NAL_SPS_EXT, H264RawSPSExtension), + + CBS_UNIT_TYPE_INTERNAL_REF(H264_NAL_PPS, H264RawPPS, slice_group_id), + + { + .nb_unit_types = 3, + .unit_types = { + H264_NAL_IDR_SLICE, + H264_NAL_SLICE, + H264_NAL_AUXILIARY_SLICE, + }, + .content_type = CBS_CONTENT_TYPE_INTERNAL_REFS, + .content_size = sizeof(H264RawSlice), + .nb_ref_offsets = 1, + .ref_offsets = { offsetof(H264RawSlice, data) }, + }, + + CBS_UNIT_TYPE_POD(H264_NAL_AUD, H264RawAUD), + CBS_UNIT_TYPE_POD(H264_NAL_FILLER_DATA, H264RawFiller), + CBS_UNIT_TYPE_POD(H264_NAL_END_SEQUENCE, H264RawNALUnitHeader), + CBS_UNIT_TYPE_POD(H264_NAL_END_STREAM, H264RawNALUnitHeader), + + CBS_UNIT_TYPE_COMPLEX(H264_NAL_SEI, H264RawSEI, &cbs_h264_free_sei), + + CBS_UNIT_TYPE_END_OF_LIST +}; + const CodedBitstreamType ff_cbs_type_h264 = { .codec_id = AV_CODEC_ID_H264, .priv_data_size = sizeof(CodedBitstreamH264Context), + .unit_types = cbs_h264_unit_types, + .split_fragment = &cbs_h2645_split_fragment, .read_unit = &cbs_h264_read_nal_unit, .write_unit = &cbs_h264_write_nal_unit, From patchwork Mon Jul 27 16:32:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 21297 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 0EE8544B627 for ; Mon, 27 Jul 2020 19:33:01 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F001768B91B; Mon, 27 Jul 2020 19:33:00 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 25EF868B8A2 for ; Mon, 27 Jul 2020 19:32:50 +0300 (EEST) Received: by mail-wr1-f42.google.com with SMTP id r2so10448788wrs.8 for ; Mon, 27 Jul 2020 09:32:50 -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=69lDmasWXs+nBKGDdrwbBGR38r6lpKRVYX+lIMbskAo=; b=OecmJ8eAStnlljAPaGY5DgMBBT0+ncHjVK0shH2oUuQfT+D5B87jEnPVLryX2gt9pJ OO5ezaCe1S7cDcZ6WQPN0JmnzI4pwK5ktVco6g9Jnvgbtk6XZmAlPE1Seth6y2wGlvjS c57txn/MZR3KIA5ErVP1UfwVxN8R88awD+6i55log0+9cB67lVmZ2v6YhjJZKKbChKWF U36F7sByT6EJ84421ZmuaVBon9cew7VFmc82WYHaIfNWPvsv7RNFJKzEr43/cJ+hcuBd LldorUf+K+iUmfAVHqOjBmKW2lMWT+KLeyJxNf0zvZxMYTquMRWsKZ71xIcbgqu/0Td4 jBhg== 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=69lDmasWXs+nBKGDdrwbBGR38r6lpKRVYX+lIMbskAo=; b=FQ7Et3c3Vpk6MSAYtD5sgpIcMiEK9zxRUrMXZTAe5NS6UjHIKKGGC5Qz4njLtRvoQp irZIKEAY14hDpLBl6L3k/6QT4bNTPq1CRdER8uW6PukBta6Rfnmd4OQIFqfnD4CY3P3B V0E8uSvXLyvKxo/mHUPUDbsPy9x7J8nXJqzPxBfk5Rh6OrLBkW17Ob04rYgKCHB7kgGX zLPgm01EIhOdwKj8ekfDyYZcRwETqILJj/MfMdgNYGElv3umCDKwlexOKi6K5us1QK4D 8+VGjhIArBMNtmWBaNZghEaSpnWRWwUTxnrg9VOl43q/Xv/B54dyl2gRChwH7qgN8ENx V0Pg== X-Gm-Message-State: AOAM530SchpTQ2y3QfT2plpUDS7OjPdn4IMXpAXg+a7qI920rqprFZYT p+wyB6kgvnIOi/kou1DnrdzIBN8h0AM= X-Google-Smtp-Source: ABdhPJzqtgFpqhnV5SolF+i4v5OMw9hn9tGgMQSG96sxLh/OMOYAAXcgCTgSxSHTC5i3ppGm2svs9g== X-Received: by 2002:a5d:4710:: with SMTP id y16mr21782388wrq.189.1595867569145; Mon, 27 Jul 2020 09:32:49 -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 w16sm14706791wrg.95.2020.07.27.09.32.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2020 09:32:48 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Mon, 27 Jul 2020 17:32:21 +0100 Message-Id: <20200727163237.23371-7-sw@jkqxz.net> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727163237.23371-1-sw@jkqxz.net> References: <20200727163237.23371-1-sw@jkqxz.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 06/22] cbs: Add support functions for handling unit content references 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" Use the unit type table to determine what we need to do to clone the internals of the unit content when making copies for refcounting or writeability. (This will still fail for units with complex content if they do not have a defined clone function.) Setup and naming from a patch by Andreas Rheinhardt , but with the implementation changed to use the unit type information if possible rather than requiring a codec-specific function. --- libavcodec/cbs.c | 163 ++++++++++++++++++++++++++++++++++++++ libavcodec/cbs.h | 29 +++++++ libavcodec/cbs_internal.h | 1 + 3 files changed, 193 insertions(+) diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c index 61cf8e3466..7c1aa005c2 100644 --- a/libavcodec/cbs.c +++ b/libavcodec/cbs.c @@ -871,3 +871,166 @@ int ff_cbs_alloc_unit_content2(CodedBitstreamContext *ctx, return 0; } + +static int cbs_clone_unit_content(AVBufferRef **clone_ref, + CodedBitstreamUnit *unit, + const CodedBitstreamUnitTypeDescriptor *desc) +{ + uint8_t *src, *copy; + uint8_t **src_ptr, **copy_ptr; + AVBufferRef **src_buf, **copy_buf; + int err, i; + + av_assert0(unit->content); + src = unit->content; + + copy = av_memdup(src, desc->content_size); + if (!copy) + return AVERROR(ENOMEM); + + for (i = 0; i < desc->nb_ref_offsets; i++) { + src_ptr = (uint8_t**)(src + desc->ref_offsets[i]); + src_buf = (AVBufferRef**)(src_ptr + 1); + copy_ptr = (uint8_t**)(copy + desc->ref_offsets[i]); + copy_buf = (AVBufferRef**)(copy_ptr + 1); + + if (!*src_ptr) { + av_assert0(!*src_buf); + continue; + } + if (!*src_buf) { + // We can't handle a non-refcounted pointer here - we don't + // have enough information to handle whatever structure lies + // at the other end of it. + err = AVERROR(EINVAL); + goto fail; + } + + // src_ptr is required to point somewhere inside src_buf. If it + // doesn't, there is a bug somewhere. + av_assert0(*src_ptr >= (*src_buf)->data && + *src_ptr < (*src_buf)->data + (*src_buf)->size); + + *copy_buf = av_buffer_ref(*src_buf); + if (!*copy_buf) { + err = AVERROR(ENOMEM); + goto fail; + } + *copy_ptr = (*copy_buf)->data + (*src_ptr - (*src_buf)->data); + } + + *clone_ref = av_buffer_create(copy, desc->content_size, + desc->content_free ? desc->content_free : + cbs_default_free_unit_content, + (void*)desc, 0); + if (!*clone_ref) { + err = AVERROR(ENOMEM); + goto fail; + } + + return 0; + +fail: + for (--i; i >= 0; i--) + av_buffer_unref((AVBufferRef**)(copy + desc->ref_offsets[i])); + av_freep(©); + *clone_ref = NULL; + return err; +} + +int ff_cbs_make_unit_refcounted(CodedBitstreamContext *ctx, + CodedBitstreamUnit *unit) +{ + const CodedBitstreamUnitTypeDescriptor *desc; + AVBufferRef *ref; + int err; + + av_assert0(unit->content); + if (unit->content_ref) { + // Already refcounted, nothing to do. + return 0; + } + + desc = cbs_find_unit_type_desc(ctx, unit); + if (!desc) + return AVERROR(ENOSYS); + + switch (desc->content_type) { + case CBS_CONTENT_TYPE_POD: + ref = av_buffer_alloc(desc->content_size); + if (!ref) + return AVERROR(ENOMEM); + memcpy(ref->data, unit->content, desc->content_size); + err = 0; + break; + + case CBS_CONTENT_TYPE_INTERNAL_REFS: + err = cbs_clone_unit_content(&ref, unit, desc); + break; + + case CBS_CONTENT_TYPE_COMPLEX: + if (!desc->content_clone) + return AVERROR_PATCHWELCOME; + err = desc->content_clone(&ref, unit); + break; + + default: + av_assert0(0 && "Invalid content type."); + } + + if (err < 0) + return err; + + unit->content_ref = ref; + unit->content = ref->data; + return 0; +} + +int ff_cbs_make_unit_writable(CodedBitstreamContext *ctx, + CodedBitstreamUnit *unit) +{ + const CodedBitstreamUnitTypeDescriptor *desc; + AVBufferRef *ref; + int err; + + // This can only be applied to refcounted units. + err = ff_cbs_make_unit_refcounted(ctx, unit); + if (err < 0) + return err; + av_assert0(unit->content && unit->content_ref); + + if (av_buffer_is_writable(unit->content_ref)) + return 0; + + desc = cbs_find_unit_type_desc(ctx, unit); + if (!desc) + return AVERROR(ENOSYS); + + switch (desc->content_type) { + case CBS_CONTENT_TYPE_POD: + err = av_buffer_make_writable(&unit->content_ref); + break; + + case CBS_CONTENT_TYPE_INTERNAL_REFS: + err = cbs_clone_unit_content(&ref, unit, desc); + break; + + case CBS_CONTENT_TYPE_COMPLEX: + if (!desc->content_clone) + return AVERROR_PATCHWELCOME; + err = desc->content_clone(&ref, unit); + break; + + default: + av_assert0(0 && "Invalid content type."); + } + if (err < 0) + return err; + + if (desc->content_type != CBS_CONTENT_TYPE_POD) { + av_buffer_unref(&unit->content_ref); + unit->content_ref = ref; + } + unit->content = unit->content_ref->data; + return 0; +} diff --git a/libavcodec/cbs.h b/libavcodec/cbs.h index ea8d942894..3a054aa8f3 100644 --- a/libavcodec/cbs.h +++ b/libavcodec/cbs.h @@ -400,4 +400,33 @@ void ff_cbs_delete_unit(CodedBitstreamFragment *frag, int position); +/** + * Make the content of a unit refcounted. + * + * If the unit is not refcounted, this will do a deep copy of the unit + * content to new refcounted buffers. + * + * It is not valid to call this function on a unit which does not have + * decomposed content. + */ +int ff_cbs_make_unit_refcounted(CodedBitstreamContext *ctx, + CodedBitstreamUnit *unit); + +/** + * Make the content of a unit writable so that internal fields can be + * modified. + * + * If it is known that there are no other references to the content of + * the unit, does nothing and returns success. Otherwise (including the + * case where the unit content is not refcounted), it does a full clone + * of the content (including any internal buffers) to make a new copy, + * and replaces the existing references inside the unit with that. + * + * It is not valid to call this function on a unit which does not have + * decomposed content. + */ +int ff_cbs_make_unit_writable(CodedBitstreamContext *ctx, + CodedBitstreamUnit *unit); + + #endif /* AVCODEC_CBS_H */ diff --git a/libavcodec/cbs_internal.h b/libavcodec/cbs_internal.h index 35159f9c5f..d991e1eedf 100644 --- a/libavcodec/cbs_internal.h +++ b/libavcodec/cbs_internal.h @@ -80,6 +80,7 @@ typedef const struct CodedBitstreamUnitTypeDescriptor { size_t ref_offsets[CBS_MAX_REF_OFFSETS]; void (*content_free)(void *opaque, uint8_t *data); + int (*content_clone)(AVBufferRef **ref, CodedBitstreamUnit *unit); } CodedBitstreamUnitTypeDescriptor; typedef struct CodedBitstreamType { From patchwork Mon Jul 27 16:32:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 21317 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:80ca:0:0:0:0:0 with SMTP id c10csp4278255ybm; Mon, 27 Jul 2020 09:34:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwTDDwsj2RqqIMsNO58vBluJwj5YHf54LVc/mhpalBBueCXT+mVh6Q9nhoh5Vbcw7OYwHYi X-Received: by 2002:a1c:5451:: with SMTP id p17mr134496wmi.180.1595867684916; Mon, 27 Jul 2020 09:34:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595867684; cv=none; d=google.com; s=arc-20160816; b=aLoO4FitQ5dW0JbZ5u1iKKiC2y121qX1wgIZRBuO7qIx04hgGfHNkimhYxSjlm1ZhV zYYzOvxn8RXv9n2085P5u1ULtQwa2XCMvtWhHOzqGmjjc8j/Jg0ykq5uFSfwTPw1Dlmz TweiGiL5trqd01aJbvJjCeSAJyNTcd/nZwG7Z1C5TqferDH19cyrZMDGSFWExjDLfwbW 4Dgvv4vgILmYewuUWoa/+L7ixouWjoOhfkfZmgEprKvwmhULbDCvtsZ/93gXDT4jpRgE a8tUvoJtClPBb1DgPCdLF64I4Wa4w7TsYL2byuVTJFrk3HfCGPYmxVMi1LrRtMChPdAA OxVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=2tQSbmD0wNCE1Tz4jxNNIqxxRhINoVP0Lp/xzJYS1Zc=; b=beldYgPyxo2m+oTxyazQB0yq5U0dY7nTCFf351bEiEBt37oLu3Ky7hN1/1EEDb8zPm B3pdxfz9448DsHFBijdZcWlbvAiZLxzscgiLTYzGA+6Nswd8g2mHIflUbwJbunuPS4oZ /5/eKJt0x7BEhCDZiSq26S77eBHswOW3hyxUvZsA6oF1pe0ua47aicVPJzOYryWJIrMq W7w8yEiH3OpmTRaLSgUuzdm6CPTREKKSNWSgaBO6c8DnvkrAx7MyNEqqGLm6x0k5wi8c eqcQNu08rQp5S436q67P8n6yjZFPFFUwkVcxAke1iRzJnxxa/Q6O3bcEyakOOj3SF139 4aiA== 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=v7bvLI+Z; 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 h13si99025wmb.87.2020.07.27.09.34.44; Mon, 27 Jul 2020 09:34:44 -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=v7bvLI+Z; 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 E8D5B68B93F; Mon, 27 Jul 2020 19:33:03 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2E94068B8C3 for ; Mon, 27 Jul 2020 19:32:51 +0300 (EEST) Received: by mail-wm1-f68.google.com with SMTP id 3so8470189wmi.1 for ; Mon, 27 Jul 2020 09:32:51 -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=7nRWEJMAoUmKsE1pxDHaYWVcugsu+Q3qR3ggn/FOgvw=; b=v7bvLI+Zr8tnsb5Cr7l1LcMpS+PO65Nrr8MXsOYHNa0pRh7Db4eiBt9DxpSUw1MMW0 CIpGdQytwFUXjpt/fJJX+UAGVS+pJgsy8Am9bmCoyDcpRGaA3u2o/5NqkFXcQ9HcbI5e UARClIx/JLQz1gvRnmaKRxVaWRbAvwh08XWrEB1/J6TYSiIXhy1POV7dkDYKBBLyFcQC qo1+dGisUI2jBdv3X8pbvYXcXAN22XUu+MxyLbPwHS9TPFV+c3PUa0aPo/wBcudf+P2M zJ5PbP+c1ChY/41sbylC7IGhL6rq5YIgg3f80yX5MaPhKQ3+InQBSfQ65mOQHua1rKFK SxLQ== 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=7nRWEJMAoUmKsE1pxDHaYWVcugsu+Q3qR3ggn/FOgvw=; b=Th3/ITD1iU3U6AcGMy11Y23WfE9hmIxeMwybXOC0JIoUIMH/jmgKwr6Bg1E7qV5aLp ZAIsKxCWSpi6pevwCjusQmyR81++Y52e0imT9sw8W/M8X3CUGIWjBpxyEDYpV8bJvLTM 8cIo/nDT4uwoc7fst3cj+5oSkwlPNQW1HNfV70B0tWtSyjBmTqCmjxPCSuOJ4U/MLZzo MCC8966LyQuyM0dHvmVQuTWXQGuXHULRgUhrqvQhqRZkj+QP4qLE0uGCB+xV8LPK94ml NxvfupI5M/Xsp5GttlDReuUAoMe9D7mpZ3ZW0iBzUdI2ONxMlud9/fm2G5QhmmmTxwwy J3pA== X-Gm-Message-State: AOAM533cgAqNkr8IzYVGKYWnDVqguHBvUwrdWf/cX1HpMGa/1u5ja8HW vaqC1sYVGySaSRY5J3a3HYi98dSSbE4= X-Received: by 2002:a1c:26c4:: with SMTP id m187mr132177wmm.90.1595867570151; Mon, 27 Jul 2020 09:32:50 -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 w16sm14706791wrg.95.2020.07.27.09.32.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2020 09:32:49 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Mon, 27 Jul 2020 17:32:22 +0100 Message-Id: <20200727163237.23371-8-sw@jkqxz.net> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727163237.23371-1-sw@jkqxz.net> References: <20200727163237.23371-1-sw@jkqxz.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 07/22] cbs_h2645: Ensure that non-refcounted parameter sets are fully copied 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" X-TUID: NvzdumTcn/p9 Content-Length: 2456 Only copying the main structure is not necessarily sufficient - there could be references to substructures. --- libavcodec/cbs_h2645.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c index 5725539e60..e19fa5249d 100644 --- a/libavcodec/cbs_h2645.c +++ b/libavcodec/cbs_h2645.c @@ -720,18 +720,20 @@ static int cbs_h26 ## h26n ## _replace_ ## ps_var(CodedBitstreamContext *ctx, \ CodedBitstreamH26 ## h26n ## Context *priv = ctx->priv_data; \ H26 ## h26n ## Raw ## ps_name *ps_var = unit->content; \ unsigned int id = ps_var->id_element; \ + int err; \ if (id >= FF_ARRAY_ELEMS(priv->ps_var)) { \ av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid " #ps_name \ " id : %d.\n", id); \ return AVERROR_INVALIDDATA; \ } \ + err = ff_cbs_make_unit_refcounted(ctx, unit); \ + if (err < 0) \ + return err; \ if (priv->ps_var[id] == priv->active_ ## ps_var) \ priv->active_ ## ps_var = NULL ; \ av_buffer_unref(&priv->ps_var ## _ref[id]); \ - if (unit->content_ref) \ - priv->ps_var ## _ref[id] = av_buffer_ref(unit->content_ref); \ - else \ - priv->ps_var ## _ref[id] = av_buffer_alloc(sizeof(*ps_var)); \ + av_assert0(unit->content_ref); \ + priv->ps_var ## _ref[id] = av_buffer_ref(unit->content_ref); \ if (!priv->ps_var ## _ref[id]) \ return AVERROR(ENOMEM); \ priv->ps_var[id] = (H26 ## h26n ## Raw ## ps_name *)priv->ps_var ## _ref[id]->data; \ From patchwork Mon Jul 27 16:32:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 21330 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:80ca:0:0:0:0:0 with SMTP id c10csp4278476ybm; Mon, 27 Jul 2020 09:35:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx8zfa5kPYIUYXuiFlEpz+kW+bOgUNo5AqFNtPlUNfAKCcbhTC52KxkeBqj8JuAcuTfB0hL X-Received: by 2002:a05:6000:1141:: with SMTP id d1mr22932528wrx.229.1595867704397; Mon, 27 Jul 2020 09:35:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595867704; cv=none; d=google.com; s=arc-20160816; b=Cz6NTKWe6761UUy86aBsyiouRbYmezfCU2AecBueyvmFqNrFBg08CEziIyhSRn3RhT iE5Pvmgc+mitk+M2Yr8PgPjvMbEqyItX7ZUcGLdR2xr9J+nWwRFe2EZeq3127smWQFtx Ox/IWEFMIEeXr2XPJG/DWYtsKcUQRNW72pwGDkMhxPuL5xq182aGZi+Iq6/bDd+acmjU gEBYlHfC40zdiWp5z70jSX7GAnDHCbxSEomYxSn+1aL1kzkBl3461+b8rAHZfPuvuv7U aLxyNqyCf1ymyNZebyLn9m+swmF/AW4b+zBgNra4T8je2+Rbp5KozF/fIiA1H+sTV3Vr Ej9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=16Z5Eydx7wWDpxIOFSLv9kL+YhiSAXdv8pebvXB+bFs=; b=vUAoPRmSIo6OASodkEaLWSLMWZ8lDmjihVuaiCW+8p3bAgICvsnIO0duoMnfjeR4fg 4KUn3VVWf4wDHRZNw6A6UXH71HrBzceIlo7RcPILzhJnJ+q65Pg41HLyT24rRYZNAr6K 7JjjduyKlYEKvawH74VAGIgnroWE8MadxB8trt0KpTVWt58wf+aGwDw5QSnb6lN5hkBF rWTX938gGRTB0JEKVPocCp4jPKc6EMIvHLDUPiAQefsVacWbmEFMWESlXot3xGirIYis M5AU/uKgga0aJbVScFN9krHwJwxy47JH/uFWmxeue6olcNsarmfSLaQZ6DxI4+VwQ2Jl UBZQ== 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=tfdVv5bJ; 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 135si89233wmb.151.2020.07.27.09.35.04; Mon, 27 Jul 2020 09:35:04 -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=tfdVv5bJ; 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 668CE68B930; Mon, 27 Jul 2020 19:33:05 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3477B68B8FD for ; Mon, 27 Jul 2020 19:32:52 +0300 (EEST) Received: by mail-wm1-f65.google.com with SMTP id f18so15414507wml.3 for ; Mon, 27 Jul 2020 09:32: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=XoB4QgSwCSAsg7+MsbgcxbxzrrA71UXNqI+b5edn9Rs=; b=tfdVv5bJ3m1xkeIQroNnkQSbWv29wxB/EtV/XlEpMgoP9hVWFXnGtr9z3py0/TyMsc uK/4v5C4mjN8ERs3e5W5Bx1WS9oVcVu+eYob8KfyK+Wg4OWnaHO6nSNmJlqnygb/HVAq W6PnMrEBnyakkynlbOOOvjCffFWHZ4V7MiK2ZQaG1pYS+J5BAMo4PtaS3n3J2Q0Jupvr Pv5qjO+Ir4P+8YNMHLJcOwzN7DSufCYPo/Jahw74km1YKvaxFsDjgBzxfMo/LREqFeU0 YDCyFTX59zzudRDujzrjRdofcqi7sdKq0ksgZkv4JCAcy+RLTTIyAS3HCgGAGq2BcM/5 om2g== 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=XoB4QgSwCSAsg7+MsbgcxbxzrrA71UXNqI+b5edn9Rs=; b=GlOcohpY2P0NZadC7LqxOgQUtzPStUpEXwpwfNKfHzuAfmzmPvF+7pvc0OICggt6lB tMAnQ+YKvtmyuOY1+RUC4f0coDlqpxpa42YvMquQi6dWyo6wFWcRBQHWCoy6I5tcgV7l aOD8EYFIyZavL8M+OMVzL38Ca/gTpr/qKxr8uGww8+eEcUgg7wx5tYhPVIlidhPHBN5p 234of+dxQIaRkReOUsoftA4D5hZyJ5boiHWrXTtiXCNP7jyOxTzlqoWXsqVbmsf4S7z7 WcDMAEIQejcUGSXiai2/dWUz5BbReuXOztFhZL8JP5q6LmGQrENvp6xY8/B1c3XM4ao5 Bjfw== X-Gm-Message-State: AOAM531SF8jDcrZqShWHmuC0CmTfuYIOHrKLPyfudP/PlmHrzyoiV7Ny eGLY0fxhCWtLlRXruNlNFfNxMPofgX8= X-Received: by 2002:a7b:c941:: with SMTP id i1mr100264wml.73.1595867571213; Mon, 27 Jul 2020 09:32: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 w16sm14706791wrg.95.2020.07.27.09.32.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2020 09:32:50 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Mon, 27 Jul 2020 17:32:23 +0100 Message-Id: <20200727163237.23371-9-sw@jkqxz.net> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727163237.23371-1-sw@jkqxz.net> References: <20200727163237.23371-1-sw@jkqxz.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 08/22] h264_redundant_pps: Make it reference-compatible 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" X-TUID: iS64+myQQIzv Content-Length: 3818 From: Andreas Rheinhardt Since c6a63e11092c975b89d824f08682fe31948d3686, the parameter sets modified as content of PPS units were references shared with the CodedBitstreamH264Context, so modifying them alters the parsing process of future access units which meant that frames often got discarded because invalid values were parsed. This patch makes h264_redundant_pps compatible with the reality of reference-counted parameter sets. Fixes #7807. Signed-off-by: Andreas Rheinhardt Signed-off-by: Mark Thompson --- libavcodec/h264_redundant_pps_bsf.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/libavcodec/h264_redundant_pps_bsf.c b/libavcodec/h264_redundant_pps_bsf.c index a8af4105cf..cf41abe96c 100644 --- a/libavcodec/h264_redundant_pps_bsf.c +++ b/libavcodec/h264_redundant_pps_bsf.c @@ -41,8 +41,19 @@ typedef struct H264RedundantPPSContext { static int h264_redundant_pps_fixup_pps(H264RedundantPPSContext *ctx, - H264RawPPS *pps) + CodedBitstreamUnit *unit) { + H264RawPPS *pps; + int err; + + // The changes we are about to perform affect the parsing process, + // so we must make sure that the PPS is writable, otherwise the + // parsing of future slices will be incorrect and even raise errors. + err = ff_cbs_make_unit_writable(ctx->input, unit); + if (err < 0) + return err; + pps = unit->content; + // Record the current value of pic_init_qp in order to fix up // following slices, then overwrite with the global value. ctx->current_pic_init_qp = pps->pic_init_qp_minus26 + 26; @@ -89,7 +100,7 @@ static int h264_redundant_pps_filter(AVBSFContext *bsf, AVPacket *pkt) if (nal->type == H264_NAL_SPS) au_has_sps = 1; if (nal->type == H264_NAL_PPS) { - err = h264_redundant_pps_fixup_pps(ctx, nal->content); + err = h264_redundant_pps_fixup_pps(ctx, nal); if (err < 0) goto fail; if (!au_has_sps) { @@ -145,7 +156,7 @@ static int h264_redundant_pps_init(AVBSFContext *bsf) for (i = 0; i < au->nb_units; i++) { if (au->units[i].type == H264_NAL_PPS) { - err = h264_redundant_pps_fixup_pps(ctx, au->units[i].content); + err = h264_redundant_pps_fixup_pps(ctx, &au->units[i]); if (err < 0) goto fail; } From patchwork Mon Jul 27 16:32:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 21295 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 9529B44B627 for ; Mon, 27 Jul 2020 19:32:58 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6BDA268B905; Mon, 27 Jul 2020 19:32:58 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 92B4F68B8BB for ; Mon, 27 Jul 2020 19:32:53 +0300 (EEST) Received: by mail-wm1-f52.google.com with SMTP id g10so13734828wmc.1 for ; Mon, 27 Jul 2020 09:32:53 -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=MWk1i7mCebCsG8cyMOOBVBNAgUhx1Ogyp7LmsbwmrqI=; b=iQ7wY5EHFyMfQOd/YqT8OdUSu50FPcZcYMxz9RYvkdM8tQDRDi9R76CESJQw6A9OWG LcXUFhrZ5KDcRa+SmXZHacADjnvY0bu0RwFlfB6hAFPoRqiO0D3FBG2IeFFCxOZOfQ43 klwLOgTrR3wWgTHsnMJxtXhrp+zk2CU6sS58mLdisV6onWiuosXefr2zP3OWUmTmOlWk Dgy7mSixw53elFNWiQes4oa9B6EnR7VKbxz7DyD9nhxqi4sXUg7J/VkxA1lBQmkNXOCd tx+Ac8odGeXz37rbxc+C9M3+a3tic3W99lHflTwZDI/6i8V48ngC2RYS7wMvO5Ecjzth xVEg== 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=MWk1i7mCebCsG8cyMOOBVBNAgUhx1Ogyp7LmsbwmrqI=; b=TasaFL6V6d/0kWt8JvAbFjXACnNslp7pqx1WHQBwjrjl5YgiYIW6/Qm7NYy3TUtrPN c0tkuUTCMSIL9YbraG+axkIFJQMKEaAzEQHWJu70FaeEj8aioWC00L0TumeibEdzU5rZ cEHE4FmSiXQmez4OFOZv0v5GBL3lRQUMmjsBNNowEKEgLxow5oX9ip8hAnKKndjtqj0A 4yj5SkcE9MUr66m4D3VhhEF4aNJ3ZiCSumMP+OMNh5CKsMOHu+4/a40MBpw1ktSS+EOu a8Qf9tNdESnQpBch4jR6svwRpwmkv00uGDuBbWhbxRgckFCAxGE82/RWgoJXHKa9ayf4 c3uw== X-Gm-Message-State: AOAM531G0EOgPbdYscgdbVJYf57htSJpNnAYATSDTZJzLDEJ2OCSIu38 VExJGclnkq/XTX8Gwr4X1tpughzdfxc= X-Google-Smtp-Source: ABdhPJyWrsaxsbrd5BRC8s89nLjxALuHq9q/xpXBu4hzz54Kyrstp4Tw96mqL3Xn/2IAgnxuWVPq2Q== X-Received: by 2002:a1c:3983:: with SMTP id g125mr132053wma.64.1595867572411; Mon, 27 Jul 2020 09:32:52 -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 w16sm14706791wrg.95.2020.07.27.09.32.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2020 09:32:51 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Mon, 27 Jul 2020 17:32:24 +0100 Message-Id: <20200727163237.23371-10-sw@jkqxz.net> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727163237.23371-1-sw@jkqxz.net> References: <20200727163237.23371-1-sw@jkqxz.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 09/22] cbs_h265: Use table-based alloc/free 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" --- libavcodec/cbs_h2645.c | 198 +++++++++++++++++++---------------------- 1 file changed, 93 insertions(+), 105 deletions(-) diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c index e19fa5249d..b9233f4df7 100644 --- a/libavcodec/cbs_h2645.c +++ b/libavcodec/cbs_h2645.c @@ -454,72 +454,6 @@ static int cbs_h2645_read_more_rbsp_data(GetBitContext *gbc) #undef allocate -static void cbs_h265_free_vps(void *opaque, uint8_t *content) -{ - H265RawVPS *vps = (H265RawVPS*)content; - av_buffer_unref(&vps->extension_data.data_ref); - av_freep(&content); -} - -static void cbs_h265_free_sps(void *opaque, uint8_t *content) -{ - H265RawSPS *sps = (H265RawSPS*)content; - av_buffer_unref(&sps->extension_data.data_ref); - av_freep(&content); -} - -static void cbs_h265_free_pps(void *opaque, uint8_t *content) -{ - H265RawPPS *pps = (H265RawPPS*)content; - av_buffer_unref(&pps->extension_data.data_ref); - av_freep(&content); -} - -static void cbs_h265_free_slice(void *opaque, uint8_t *content) -{ - H265RawSlice *slice = (H265RawSlice*)content; - av_buffer_unref(&slice->data_ref); - av_freep(&content); -} - -static void cbs_h265_free_sei_payload(H265RawSEIPayload *payload) -{ - switch (payload->payload_type) { - case HEVC_SEI_TYPE_BUFFERING_PERIOD: - case HEVC_SEI_TYPE_PICTURE_TIMING: - case HEVC_SEI_TYPE_PAN_SCAN_RECT: - case HEVC_SEI_TYPE_RECOVERY_POINT: - case HEVC_SEI_TYPE_DISPLAY_ORIENTATION: - case HEVC_SEI_TYPE_ACTIVE_PARAMETER_SETS: - case HEVC_SEI_TYPE_DECODED_PICTURE_HASH: - case HEVC_SEI_TYPE_TIME_CODE: - case HEVC_SEI_TYPE_MASTERING_DISPLAY_INFO: - case HEVC_SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO: - case HEVC_SEI_TYPE_ALTERNATIVE_TRANSFER_CHARACTERISTICS: - case HEVC_SEI_TYPE_ALPHA_CHANNEL_INFO: - break; - case HEVC_SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35: - av_buffer_unref(&payload->payload.user_data_registered.data_ref); - break; - case HEVC_SEI_TYPE_USER_DATA_UNREGISTERED: - av_buffer_unref(&payload->payload.user_data_unregistered.data_ref); - break; - default: - av_buffer_unref(&payload->payload.other.data_ref); - break; - } - av_buffer_unref(&payload->extension_data.data_ref); -} - -static void cbs_h265_free_sei(void *opaque, uint8_t *content) -{ - H265RawSEI *sei = (H265RawSEI*)content; - int i; - for (i = 0; i < sei->payload_count; i++) - cbs_h265_free_sei_payload(&sei->payload[i]); - av_freep(&content); -} - static int cbs_h2645_fragment_add_nals(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const H2645Packet *packet) @@ -877,16 +811,14 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext *ctx, if (err < 0) return err; + err = ff_cbs_alloc_unit_content2(ctx, unit); + if (err < 0) + return err; + switch (unit->type) { case HEVC_NAL_VPS: { - H265RawVPS *vps; - - err = ff_cbs_alloc_unit_content(unit, sizeof(*vps), - &cbs_h265_free_vps); - if (err < 0) - return err; - vps = unit->content; + H265RawVPS *vps = unit->content; err = cbs_h265_read_vps(ctx, &gbc, vps); if (err < 0) @@ -899,13 +831,7 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext *ctx, break; case HEVC_NAL_SPS: { - H265RawSPS *sps; - - err = ff_cbs_alloc_unit_content(unit, sizeof(*sps), - &cbs_h265_free_sps); - if (err < 0) - return err; - sps = unit->content; + H265RawSPS *sps = unit->content; err = cbs_h265_read_sps(ctx, &gbc, sps); if (err < 0) @@ -919,13 +845,7 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext *ctx, case HEVC_NAL_PPS: { - H265RawPPS *pps; - - err = ff_cbs_alloc_unit_content(unit, sizeof(*pps), - &cbs_h265_free_pps); - if (err < 0) - return err; - pps = unit->content; + H265RawPPS *pps = unit->content; err = cbs_h265_read_pps(ctx, &gbc, pps); if (err < 0) @@ -954,15 +874,9 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext *ctx, case HEVC_NAL_IDR_N_LP: case HEVC_NAL_CRA_NUT: { - H265RawSlice *slice; + H265RawSlice *slice = unit->content; int pos, len; - err = ff_cbs_alloc_unit_content(unit, sizeof(*slice), - &cbs_h265_free_slice); - if (err < 0) - return err; - slice = unit->content; - err = cbs_h265_read_slice_segment_header(ctx, &gbc, &slice->header); if (err < 0) return err; @@ -984,11 +898,6 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext *ctx, case HEVC_NAL_AUD: { - err = ff_cbs_alloc_unit_content(unit, - sizeof(H265RawAUD), NULL); - if (err < 0) - return err; - err = cbs_h265_read_aud(ctx, &gbc, unit->content); if (err < 0) return err; @@ -998,12 +907,6 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext *ctx, case HEVC_NAL_SEI_PREFIX: case HEVC_NAL_SEI_SUFFIX: { - err = ff_cbs_alloc_unit_content(unit, sizeof(H265RawSEI), - &cbs_h265_free_sei); - - if (err < 0) - return err; - err = cbs_h265_read_sei(ctx, &gbc, unit->content, unit->type == HEVC_NAL_SEI_PREFIX); @@ -1482,6 +1385,89 @@ static const CodedBitstreamUnitTypeDescriptor cbs_h264_unit_types[] = { CBS_UNIT_TYPE_END_OF_LIST }; +static void cbs_h265_free_sei_payload(H265RawSEIPayload *payload) +{ + switch (payload->payload_type) { + case HEVC_SEI_TYPE_BUFFERING_PERIOD: + case HEVC_SEI_TYPE_PICTURE_TIMING: + case HEVC_SEI_TYPE_PAN_SCAN_RECT: + case HEVC_SEI_TYPE_RECOVERY_POINT: + case HEVC_SEI_TYPE_DISPLAY_ORIENTATION: + case HEVC_SEI_TYPE_ACTIVE_PARAMETER_SETS: + case HEVC_SEI_TYPE_DECODED_PICTURE_HASH: + case HEVC_SEI_TYPE_TIME_CODE: + case HEVC_SEI_TYPE_MASTERING_DISPLAY_INFO: + case HEVC_SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO: + case HEVC_SEI_TYPE_ALTERNATIVE_TRANSFER_CHARACTERISTICS: + case HEVC_SEI_TYPE_ALPHA_CHANNEL_INFO: + break; + case HEVC_SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35: + av_buffer_unref(&payload->payload.user_data_registered.data_ref); + break; + case HEVC_SEI_TYPE_USER_DATA_UNREGISTERED: + av_buffer_unref(&payload->payload.user_data_unregistered.data_ref); + break; + default: + av_buffer_unref(&payload->payload.other.data_ref); + break; + } + av_buffer_unref(&payload->extension_data.data_ref); +} + +static void cbs_h265_free_sei(void *opaque, uint8_t *content) +{ + H265RawSEI *sei = (H265RawSEI*)content; + int i; + for (i = 0; i < sei->payload_count; i++) + cbs_h265_free_sei_payload(&sei->payload[i]); + av_freep(&content); +} + +static const CodedBitstreamUnitTypeDescriptor cbs_h265_unit_types[] = { + CBS_UNIT_TYPE_INTERNAL_REF(HEVC_NAL_VPS, H265RawVPS, extension_data.data), + CBS_UNIT_TYPE_INTERNAL_REF(HEVC_NAL_SPS, H265RawSPS, extension_data.data), + CBS_UNIT_TYPE_INTERNAL_REF(HEVC_NAL_PPS, H265RawPPS, extension_data.data), + + CBS_UNIT_TYPE_POD(HEVC_NAL_AUD, H265RawAUD), + + { + // Slices of non-IRAP pictures. + .nb_unit_types = CBS_UNIT_TYPE_RANGE, + .unit_type_range_start = HEVC_NAL_TRAIL_N, + .unit_type_range_end = HEVC_NAL_RASL_R, + + .content_type = CBS_CONTENT_TYPE_INTERNAL_REFS, + .content_size = sizeof(H265RawSlice), + .nb_ref_offsets = 1, + .ref_offsets = { offsetof(H265RawSlice, data) }, + }, + + { + // Slices of IRAP pictures. + .nb_unit_types = CBS_UNIT_TYPE_RANGE, + .unit_type_range_start = HEVC_NAL_BLA_W_LP, + .unit_type_range_end = HEVC_NAL_CRA_NUT, + + .content_type = CBS_CONTENT_TYPE_INTERNAL_REFS, + .content_size = sizeof(H265RawSlice), + .nb_ref_offsets = 1, + .ref_offsets = { offsetof(H265RawSlice, data) }, + }, + + { + .nb_unit_types = 2, + .unit_types = { + HEVC_NAL_SEI_PREFIX, + HEVC_NAL_SEI_SUFFIX + }, + .content_type = CBS_CONTENT_TYPE_COMPLEX, + .content_size = sizeof(H265RawSEI), + .content_free = &cbs_h265_free_sei, + }, + + CBS_UNIT_TYPE_END_OF_LIST +}; + const CodedBitstreamType ff_cbs_type_h264 = { .codec_id = AV_CODEC_ID_H264, @@ -1502,6 +1488,8 @@ const CodedBitstreamType ff_cbs_type_h265 = { .priv_data_size = sizeof(CodedBitstreamH265Context), + .unit_types = cbs_h265_unit_types, + .split_fragment = &cbs_h2645_split_fragment, .read_unit = &cbs_h265_read_nal_unit, .write_unit = &cbs_h265_write_nal_unit, From patchwork Mon Jul 27 16:32:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 21298 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 DFE6644B627 for ; Mon, 27 Jul 2020 19:33:01 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CD03268B920; Mon, 27 Jul 2020 19:33:01 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4602568B8C8 for ; Mon, 27 Jul 2020 19:32:54 +0300 (EEST) Received: by mail-wr1-f45.google.com with SMTP id b6so15531360wrs.11 for ; Mon, 27 Jul 2020 09:32:54 -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=4NxB4LUg8yXIFgK731yG9WpPfpsSOcpBwnzJbUVGo2k=; b=AsuQTUyB0E21lvNmNFwXAhB/vUQu8FowTN9JfKhcHH+fAwSQhfTQejzYB8Qwdt8eAk XRVh58hUUwkpLAI5IYMG667WTXJXe+nfjsKsCU5fIU5YxAKX1WqFJBpgtBZGyzqrK6Ry 1JcPA/Q9/N1UluszPUc9xF7t2xzzyeEP1+vPg6ZjxgRReGM8rETFl6xLOErhN6OpjVZP KnzGACgy19UA9mpTBQs4MUSNhsWEMQP8js3kEm4At18khBXjAWAXUlFCvUQ0n/5hXhK/ Hy1xK1WCoGUhY58y5LMTijjeq0P5+MwG4CMsL935oF4rEDLXb+Ra+wFVTxpkIqWrWFLO snPw== 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=4NxB4LUg8yXIFgK731yG9WpPfpsSOcpBwnzJbUVGo2k=; b=bXzU+gYxGQswQZHXEOsf9u+IArrEeF7wiro+fcOG6K+xWBFym/pnUC87Ug9ibxb05L KE/6VGLVCskWncvRPXovHpVTxMTLyYB+YKjIKTnkK41czMB6U6uvX4tFEMFKVAdiBzsw hWtD5+C3exWVH0ifkb/xEC9CmJATKlY4VXFlPHgLkwSEk0auqOH9eT2J2e9GPTYoGo8S WZ9YUCHJrZ7OVShW08qsQFD6aXUhRpZCu1UwREEEREMSBRCkLe2zTXXtnoGoxnxRPWj5 P1XF5bZUSqZqkcjPHZphweLhC4mBmR3MPVh37quEqKz4HiPm/EVdmWYxGL3/AHPin/rH Jb8g== X-Gm-Message-State: AOAM530EHF+Q+rIv+0ux0oaTXZJ55dgXgFk+H3MFiS5kxKIFzvLg/xBN fr3CufT/tMSkQc9IE6q35xpJWkwibQw= X-Google-Smtp-Source: ABdhPJz3WV2Wkuils/W15kozQbYNUlaBOxriidRUdxgRzCxaMX2Bt3eNFZlZ/SHGjguxR+tay+Y8pw== X-Received: by 2002:adf:f44b:: with SMTP id f11mr3459168wrp.114.1595867573446; Mon, 27 Jul 2020 09:32:53 -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 w16sm14706791wrg.95.2020.07.27.09.32.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2020 09:32:52 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Mon, 27 Jul 2020 17:32:25 +0100 Message-Id: <20200727163237.23371-11-sw@jkqxz.net> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727163237.23371-1-sw@jkqxz.net> References: <20200727163237.23371-1-sw@jkqxz.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 10/22] cbs_vp9: Use table-based alloc/free 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" --- libavcodec/cbs_vp9.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/libavcodec/cbs_vp9.c b/libavcodec/cbs_vp9.c index 6e0a7dcbea..6a480b4ce3 100644 --- a/libavcodec/cbs_vp9.c +++ b/libavcodec/cbs_vp9.c @@ -479,13 +479,6 @@ static int cbs_vp9_split_fragment(CodedBitstreamContext *ctx, return 0; } -static void cbs_vp9_free_frame(void *opaque, uint8_t *content) -{ - VP9RawFrame *frame = (VP9RawFrame*)content; - av_buffer_unref(&frame->data_ref); - av_freep(&frame); -} - static int cbs_vp9_read_unit(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit) { @@ -497,8 +490,7 @@ static int cbs_vp9_read_unit(CodedBitstreamContext *ctx, if (err < 0) return err; - err = ff_cbs_alloc_unit_content(unit, sizeof(*frame), - &cbs_vp9_free_frame); + err = ff_cbs_alloc_unit_content2(ctx, unit); if (err < 0) return err; frame = unit->content; @@ -642,11 +634,18 @@ static int cbs_vp9_assemble_fragment(CodedBitstreamContext *ctx, return 0; } +static const CodedBitstreamUnitTypeDescriptor cbs_vp9_unit_types[] = { + CBS_UNIT_TYPE_INTERNAL_REF(0, VP9RawFrame, data), + CBS_UNIT_TYPE_END_OF_LIST +}; + const CodedBitstreamType ff_cbs_type_vp9 = { .codec_id = AV_CODEC_ID_VP9, .priv_data_size = sizeof(CodedBitstreamVP9Context), + .unit_types = cbs_vp9_unit_types, + .split_fragment = &cbs_vp9_split_fragment, .read_unit = &cbs_vp9_read_unit, .write_unit = &cbs_vp9_write_unit, From patchwork Mon Jul 27 16:32:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 21309 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:80ca:0:0:0:0:0 with SMTP id c10csp4278103ybm; Mon, 27 Jul 2020 09:34:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwa9BhLPGIFz8UaWYC81kJRFcDZKW8qgvyv/MB4QMH9hvE1NosAiC0n4rxWhwIai/0aTWRi X-Received: by 2002:a05:600c:2209:: with SMTP id z9mr143250wml.70.1595867672903; Mon, 27 Jul 2020 09:34:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595867672; cv=none; d=google.com; s=arc-20160816; b=MdglrwD8SJsHAv47T5ZFUDHrHTgJCqsqtKwucJgmxGi6FVgrsyTjaThSWC7x+qyqly kiuFos/sX3H036/Re6DrEXSWNpjelw6HhuuESUZAWRvCYQ6u2gJ0xa/+wBw0vQtv7pit v/MIzwciUKKqJ625BkbvvthGcyPphnN7PDxRTXJKk1e25OvgVZq9QxrQdhxcBVx2+9oo 8IEUjD6anTdWpObxGMlhByVp6Z4rt7C9b84/erg/jjUUykMMBRmI6oT3XdfVweyHzd0J wGHurxtUBMzebK21Nvga3GF4ewfNcH44uxj2R+v9R5Sk0ek2EPQLs2FFq+nfPTKH9B24 vA8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=ohMyD6BoYjFgh+d6UqBhnt3BSm6y6WjP/1YM1OOkiRU=; b=I5MUzBV6xED4PRYOA6HWpfTEsdc3phcQv0vkeaRvvOjIJ4QTWiWOBJ6Hn+vaN1kS/V 1vDcSsGMH1MTq4bn9pORk7ON/1Di4soAWv8chtvVZKowlNqUo6/HDC1tIH+E2sVuY/Lz MIwHviaOmmqDPpLkD2WJllYyIqIb+iAk7M6NZtBSVpROAXuRjFjQ4jx95ZhjalWhA5Hp DXyJThTHvzVsNgLnofwuf8cxhJOqYv2G+VETM8vEq9INYf9K3PFVEhRH/gtRqY3H4nGW bU2pW5JBg9vR/2ImCDZq7//SXhyESGNq4Wc1e0ixHTIKQ3jQi/4DRaHBbVCyrH2Y9ILY z03w== 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=1D1Zr+18; 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 n65si137077wme.59.2020.07.27.09.34.32; Mon, 27 Jul 2020 09:34:32 -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=1D1Zr+18; 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 D546368B933; Mon, 27 Jul 2020 19:33:02 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7838E68B8A2 for ; Mon, 27 Jul 2020 19:32:55 +0300 (EEST) Received: by mail-wr1-f65.google.com with SMTP id f18so15547135wrs.0 for ; Mon, 27 Jul 2020 09:32:55 -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=FbVWsCuJwYXTneO8I5nqm0jPf6MPta3VmneDCKmO148=; b=1D1Zr+180scqv1cDAC/X9hayOYSzMwF3TVKCzqVuT7J+oZWrbksXKZGqoYHA/K4AuY sYsSv+B9JU4V5/CryzvYpHCBJDqaWcq55VHq/OZtgvO+c+7VJ5Z6Iu81Z286tJZO3OLb gSliiyZh6pZfRDuVV1ee1r2ci/rgCKFZ9D3NJXqaeBIdyYnuO0A6ep5R3dojCGZjPy3T YmYV3BqGKC0M+Z0IXpLj9IPgFuHOjqwUr4cnaFMxt18FatROTqUj7Aqm/nczi98CdtJa hK64ZrnVOHQMdUbPlNCCGxPxYasDTUdIBK0qguIvSvz/qxySOhqZjYBihif8QJCTtciS yJYw== 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=FbVWsCuJwYXTneO8I5nqm0jPf6MPta3VmneDCKmO148=; b=CzNp75tz8B7AdAe36wNzVz4/cCPiPFk7Fz/mS1idfAIt23YKUPy4g1p0eiBKlZcZPG d5w055mnSh5+pl31YDJkji0UKziqdbrT09sQjhjMzNAPCXKWPBGtW40W8YkRbQHDePvs DuuJA4DZ+Ol45XvxTbKhWZOU4ERuqLm9XYNa9sPBW7Mte9b5bGssnZHbytrBn0u8ZA+C 94Mw612aliHB8j3YqzQ2mCrHemkJYw1wg8CH//7g0tILZsJPWrvMMR9BjlhSH7VU8Kao u0G0zr8iK+iym5tTc6U1kvx3KSrJG2WNocDShcrShrCidDmwF/WFO+t01aA51vaMBZOs o2oA== X-Gm-Message-State: AOAM5326LADN/sstFrQWVs8vImAWOiIhKwuWL6LZG0PKMmcjc3rVh8fa R1Cz+AK0GCCwa8NJRovls/e/RHJRdWA= X-Received: by 2002:a5d:664e:: with SMTP id f14mr21058747wrw.6.1595867574461; Mon, 27 Jul 2020 09:32:54 -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 w16sm14706791wrg.95.2020.07.27.09.32.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2020 09:32:53 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Mon, 27 Jul 2020 17:32:26 +0100 Message-Id: <20200727163237.23371-12-sw@jkqxz.net> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727163237.23371-1-sw@jkqxz.net> References: <20200727163237.23371-1-sw@jkqxz.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 11/22] cbs_av1: Use table-based alloc/free 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" X-TUID: 0V8yVn5JGKEX Content-Length: 5557 --- libavcodec/cbs_av1.c | 85 ++++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 46 deletions(-) diff --git a/libavcodec/cbs_av1.c b/libavcodec/cbs_av1.c index 75e9cb78df..dd2bc83bd4 100644 --- a/libavcodec/cbs_av1.c +++ b/libavcodec/cbs_av1.c @@ -809,50 +809,6 @@ fail: return err; } -static void cbs_av1_free_tile_data(AV1RawTileData *td) -{ - av_buffer_unref(&td->data_ref); -} - -static void cbs_av1_free_padding(AV1RawPadding *pd) -{ - av_buffer_unref(&pd->payload_ref); -} - -static void cbs_av1_free_metadata(AV1RawMetadata *md) -{ - switch (md->metadata_type) { - case AV1_METADATA_TYPE_ITUT_T35: - av_buffer_unref(&md->metadata.itut_t35.payload_ref); - break; - } -} - -static void cbs_av1_free_obu(void *opaque, uint8_t *content) -{ - AV1RawOBU *obu = (AV1RawOBU*)content; - - switch (obu->header.obu_type) { - case AV1_OBU_TILE_GROUP: - cbs_av1_free_tile_data(&obu->obu.tile_group.tile_data); - break; - case AV1_OBU_FRAME: - cbs_av1_free_tile_data(&obu->obu.frame.tile_group.tile_data); - break; - case AV1_OBU_TILE_LIST: - cbs_av1_free_tile_data(&obu->obu.tile_list.tile_data); - break; - case AV1_OBU_METADATA: - cbs_av1_free_metadata(&obu->obu.metadata); - break; - case AV1_OBU_PADDING: - cbs_av1_free_padding(&obu->obu.padding); - break; - } - - av_freep(&obu); -} - static int cbs_av1_ref_tile_data(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, GetBitContext *gbc, @@ -887,8 +843,7 @@ static int cbs_av1_read_unit(CodedBitstreamContext *ctx, GetBitContext gbc; int err, start_pos, end_pos; - err = ff_cbs_alloc_unit_content(unit, sizeof(*obu), - &cbs_av1_free_obu); + err = ff_cbs_alloc_unit_content2(ctx, unit); if (err < 0) return err; obu = unit->content; @@ -1253,11 +1208,49 @@ static void cbs_av1_close(CodedBitstreamContext *ctx) av_buffer_unref(&priv->frame_header_ref); } +static void cbs_av1_free_metadata(void *unit, uint8_t *content) +{ + AV1RawOBU *obu = (AV1RawOBU*)content; + AV1RawMetadata *md; + + av_assert0(obu->header.obu_type == AV1_OBU_METADATA); + md = &obu->obu.metadata; + + switch (md->metadata_type) { + case AV1_METADATA_TYPE_ITUT_T35: + av_buffer_unref(&md->metadata.itut_t35.payload_ref); + break; + } +} + +static const CodedBitstreamUnitTypeDescriptor cbs_av1_unit_types[] = { + CBS_UNIT_TYPE_POD(AV1_OBU_SEQUENCE_HEADER, AV1RawOBU), + CBS_UNIT_TYPE_POD(AV1_OBU_TEMPORAL_DELIMITER, AV1RawOBU), + CBS_UNIT_TYPE_POD(AV1_OBU_FRAME_HEADER, AV1RawOBU), + CBS_UNIT_TYPE_POD(AV1_OBU_REDUNDANT_FRAME_HEADER, AV1RawOBU), + + CBS_UNIT_TYPE_INTERNAL_REF(AV1_OBU_TILE_GROUP, AV1RawOBU, + obu.tile_group.tile_data.data), + CBS_UNIT_TYPE_INTERNAL_REF(AV1_OBU_FRAME, AV1RawOBU, + obu.frame.tile_group.tile_data.data), + CBS_UNIT_TYPE_INTERNAL_REF(AV1_OBU_TILE_LIST, AV1RawOBU, + obu.tile_list.tile_data.data), + CBS_UNIT_TYPE_INTERNAL_REF(AV1_OBU_PADDING, AV1RawOBU, + obu.padding.payload), + + CBS_UNIT_TYPE_COMPLEX(AV1_OBU_METADATA, AV1RawOBU, + &cbs_av1_free_metadata), + + CBS_UNIT_TYPE_END_OF_LIST +}; + const CodedBitstreamType ff_cbs_type_av1 = { .codec_id = AV_CODEC_ID_AV1, .priv_data_size = sizeof(CodedBitstreamAV1Context), + .unit_types = cbs_av1_unit_types, + .split_fragment = &cbs_av1_split_fragment, .read_unit = &cbs_av1_read_unit, .write_unit = &cbs_av1_write_obu, From patchwork Mon Jul 27 16:32:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 21329 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:80ca:0:0:0:0:0 with SMTP id c10csp4278336ybm; Mon, 27 Jul 2020 09:34:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw9K8vGmCVVTg6C3Fq5u5YHdlxR1sLEvuDQqAWz5XQ2qqWM7gCG0B4zcmmTxk0FnxCKs5hR X-Received: by 2002:adf:e48f:: with SMTP id i15mr20032357wrm.327.1595867691186; Mon, 27 Jul 2020 09:34:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595867691; cv=none; d=google.com; s=arc-20160816; b=F7rLuBkhEGlGdTpup/iDhnnpIpjxkLgqgXtfkeEjZyWJm2QOTMEHfGh3RcKE9ezl86 Losz59y82i+mKgXW1njR2QI4yhmkgDrMfeZD/SMr44Qnm8dOMTJubO62OMkN/J8dW5+V MVXrlHHqS5ZBZ+HHLLGz8XHfdUDMsCQu+k/PENupvSEmUVD8ldYmyaZwjt02l9bXnIou Zeb/z7zeGpfPm4tZ/w4tbgP6Atpj4ayZg8zCtwRH+sULjmO6lwDeKLu0x8tV+vqNAQEr ZNTuxiNga1x1NSsq4Iac5Y9H4VsFETBRrcJX31TUAI3k5fh93eNd9QN0lUdL0wWHUboY 3q0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=oKnJM3wE0O25vI8TLK5N9hwoRBwzyUvHJo4QVGNpHXQ=; b=tX6+pJVg2pG/OIKB/vvtdJW94UcD0MnxSydEVGt9cSAmUFK5wGrPj1qAotWitJsDyA FWFaOQEJp7FUbRUdTJqIiwigF/j7WaqmmrtfUrJ9fyABV/mnSn9spg1zpK+lcIwI9Pc7 2Hy82Y2lBKiDa+6nNbn6rjKMrv/Gf3X4v9Fcloi+NLBh4dBvg5jGzBRIyTVD9JUDGZqP +2PdNoiA41aHCM78Jmbq4DKKajNrHmJIZ/GYdGv/pDHTn/Yc+P9SH5JkuBIml1YnQeTi 9IR0mCHKiyRJvPziOtbdo8h9oyVHX6SbLQeF1IqY2qCJx6u+hiZhAZb+F9bFIW89ak56 gNAA== 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=uqAg2jSI; 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 d4si8165959wrr.224.2020.07.27.09.34.50; Mon, 27 Jul 2020 09:34:51 -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=uqAg2jSI; 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 4F40D68B88E; Mon, 27 Jul 2020 19:33:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5711E68B864 for ; Mon, 27 Jul 2020 19:32:56 +0300 (EEST) Received: by mail-wm1-f65.google.com with SMTP id 9so14710718wmj.5 for ; Mon, 27 Jul 2020 09:32:56 -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=ozWdNrPF+0GM5GGSF2GF9BGmcXC0v7ch0CVQCcp+1a0=; b=uqAg2jSIdrSNJsLcVgH3L9e4YkY3a2n0NE6ZCwqhDoUtp2I3T3NcmJlBO+ymSMWj2K 3iHwYl5XYIvu/H+ZKVO9NTCsxnlJpnj21eeKyj7UvuvER0BHuC7SSg+rx37H2XRtbmzu gxmLjAKHOoVlP7kVf/Ho2JUA15E7TTNxZFTVolGiWRcBnwvuhbdxl+FmUvulIO0twhKa +AhsZ6c2kmCBwD55kdfIXnN+tJ34DkHwVbHIk6JvUu3755baD3No7vEf+hOAJF2qO+WC 3hgv2ueBo/6zDacbj8QPvgtMBCHame0MZ4fGVqFmc7ogECDgAWbPzPtxQ+kNl3ELjQxC /9xg== 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=ozWdNrPF+0GM5GGSF2GF9BGmcXC0v7ch0CVQCcp+1a0=; b=g+ZDRDEDBFB12QB7mh53NdZaFzPeoGZ7/lTqC0kik6r+E23dI2/yIYO8WIyteDWSy0 AIGpgql3aDeesuvZ70worKx0funPorWaU7jjq84DAS1OFUIE5svKLjbf7Xnkb6ituuPy hcYyvO3ugW2i8ui9YckPB1EUZarslgARW+2Sxe/mT3ryqFlFByB+8FK/uIy7jjyQTRKw pZ55bur20LHVgD4sx21c90UqNvaFDoPFJJ9+C3gDZpC7tm3ETDaUdOOgWHt6oeYE8Ixg kR8vxT5cjj60VsBjg6MmJB0LwQsX96YqK18XUcdvfD4e/wjqc0LMPu3YJxNO2yhqajpb rgIQ== X-Gm-Message-State: AOAM533e+msOn7prA26PbOMUtzDwBdP+vuDScBwuEhA8ZeXOKfXttRzU /kc5WDfZw+XBMOZEh2Os8VnKkDKNpHU= X-Received: by 2002:a7b:cb51:: with SMTP id v17mr125295wmj.146.1595867575461; Mon, 27 Jul 2020 09:32:55 -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 w16sm14706791wrg.95.2020.07.27.09.32.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2020 09:32:54 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Mon, 27 Jul 2020 17:32:27 +0100 Message-Id: <20200727163237.23371-13-sw@jkqxz.net> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727163237.23371-1-sw@jkqxz.net> References: <20200727163237.23371-1-sw@jkqxz.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 12/22] cbs_mpeg2: Use table-based alloc/free 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" X-TUID: S2JKBdO3Ahs7 Content-Length: 6051 --- libavcodec/cbs_mpeg2.c | 70 +++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c index 8b6e5a9852..26400f279f 100644 --- a/libavcodec/cbs_mpeg2.c +++ b/libavcodec/cbs_mpeg2.c @@ -140,28 +140,6 @@ #undef infer -static void cbs_mpeg2_free_picture_header(void *opaque, uint8_t *content) -{ - MPEG2RawPictureHeader *picture = (MPEG2RawPictureHeader*)content; - av_buffer_unref(&picture->extra_information_picture.extra_information_ref); - av_freep(&content); -} - -static void cbs_mpeg2_free_user_data(void *opaque, uint8_t *content) -{ - MPEG2RawUserData *user = (MPEG2RawUserData*)content; - av_buffer_unref(&user->user_data_ref); - av_freep(&content); -} - -static void cbs_mpeg2_free_slice(void *opaque, uint8_t *content) -{ - MPEG2RawSlice *slice = (MPEG2RawSlice*)content; - av_buffer_unref(&slice->header.extra_information_slice.extra_information_ref); - av_buffer_unref(&slice->data_ref); - av_freep(&content); -} - static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int header) @@ -231,16 +209,14 @@ static int cbs_mpeg2_read_unit(CodedBitstreamContext *ctx, if (err < 0) return err; + err = ff_cbs_alloc_unit_content2(ctx, unit); + if (err < 0) + return err; + if (MPEG2_START_IS_SLICE(unit->type)) { - MPEG2RawSlice *slice; + MPEG2RawSlice *slice = unit->content; int pos, len; - err = ff_cbs_alloc_unit_content(unit, sizeof(*slice), - &cbs_mpeg2_free_slice); - if (err < 0) - return err; - slice = unit->content; - err = cbs_mpeg2_read_slice_header(ctx, &gbc, &slice->header); if (err < 0) return err; @@ -264,12 +240,7 @@ static int cbs_mpeg2_read_unit(CodedBitstreamContext *ctx, #define START(start_code, type, read_func, free_func) \ case start_code: \ { \ - type *header; \ - err = ff_cbs_alloc_unit_content(unit, \ - sizeof(*header), free_func); \ - if (err < 0) \ - return err; \ - header = unit->content; \ + type *header = unit->content; \ err = cbs_mpeg2_read_ ## read_func(ctx, &gbc, header); \ if (err < 0) \ return err; \ @@ -420,11 +391,40 @@ static int cbs_mpeg2_assemble_fragment(CodedBitstreamContext *ctx, return 0; } +static const CodedBitstreamUnitTypeDescriptor cbs_mpeg2_unit_types[] = { + CBS_UNIT_TYPE_INTERNAL_REF(MPEG2_START_PICTURE, MPEG2RawPictureHeader, + extra_information_picture.extra_information), + + { + .nb_unit_types = CBS_UNIT_TYPE_RANGE, + .unit_type_range_start = 0x01, + .unit_type_range_end = 0xaf, + + .content_type = CBS_CONTENT_TYPE_INTERNAL_REFS, + .content_size = sizeof(MPEG2RawSlice), + .nb_ref_offsets = 2, + .ref_offsets = { offsetof(MPEG2RawSlice, header.extra_information_slice.extra_information), + offsetof(MPEG2RawSlice, data) }, + }, + + CBS_UNIT_TYPE_INTERNAL_REF(MPEG2_START_USER_DATA, MPEG2RawUserData, + user_data), + + CBS_UNIT_TYPE_POD(MPEG2_START_SEQUENCE_HEADER, MPEG2RawSequenceHeader), + CBS_UNIT_TYPE_POD(MPEG2_START_EXTENSION, MPEG2RawExtensionData), + CBS_UNIT_TYPE_POD(MPEG2_START_SEQUENCE_END, MPEG2RawSequenceEnd), + CBS_UNIT_TYPE_POD(MPEG2_START_GROUP, MPEG2RawGroupOfPicturesHeader), + + CBS_UNIT_TYPE_END_OF_LIST +}; + const CodedBitstreamType ff_cbs_type_mpeg2 = { .codec_id = AV_CODEC_ID_MPEG2VIDEO, .priv_data_size = sizeof(CodedBitstreamMPEG2Context), + .unit_types = cbs_mpeg2_unit_types, + .split_fragment = &cbs_mpeg2_split_fragment, .read_unit = &cbs_mpeg2_read_unit, .write_unit = &cbs_mpeg2_write_unit, From patchwork Mon Jul 27 16:32:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 21324 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:80ca:0:0:0:0:0 with SMTP id c10csp4278539ybm; Mon, 27 Jul 2020 09:35:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw2nDRD1IOwker5ptMh+UWliLBLDzrtrHido3nKUYHwz0bDfOIvyB5V6qLcCoT35o4xj5zs X-Received: by 2002:a7b:c05a:: with SMTP id u26mr131582wmc.134.1595867711482; Mon, 27 Jul 2020 09:35:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595867711; cv=none; d=google.com; s=arc-20160816; b=LYl/ASzP7cA0hbj0qcdMG3WV4nVBwaNlI/7wONZIla/i9H5HB/qatjkCqKxFVzmqPr qTs5epVCUZYXbQTQwRFWOcBpCaUM9xv1sLpOGtGxale5kladgG65BYBXOTrlmW6WCawS Fk3+QBT245T6gBmWrOvJmaVpoNfpwagpZHBN4pdojGcG9INK+x8EDq+4Pg96vzJb/bkK sYktrYwGuERiVCNCsEJKOy4YBWXCU2Vmh6wdHNNzqpryulq2UhszasKlk/e44aeA3sPo W8r3eau4avQbO3yCsZr2BQ0HLyQh6dMMGHJVZDfsgkw7e9s0vCJwM7c6gLgLTcoBMAHn 5EGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=gKWuUx6WYnNKpYlnXs/uhsU/keOOOLh9f7q115qBk4I=; b=Ho2k5/rONHE/5oB8N2SiZHO+8Z8KJ0EG0t0DMAo1dEMVXViBHJR/WEeGhJe2ZfXMCW MsrBkKjIye19GlpFU4wOkSUPvYoccDTQY+YF9owYHjIsTmvySto6lve7DT7Gsg+Z6T52 S8oqSFk97x1ecHqQl2mrkALtvsZhZ9WMX7xlu4Z+SH+6sF65se2urdmVLXbO1hoUE4IV LkcKcy9yvIzZnQm9lTcd88ssvB+e+Dp0D8d2rSdnmb3iQMobPKCHHJlLH0qxLHkbmWus Jdk8eUOrFbSo7KtIye9E99n4s3WGmnSbhnXDoQxqg08pHLwUJxUW3S5exXCgv+G7HA45 Y1Mg== 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=DXHQUkLY; 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 o7si8229088wru.551.2020.07.27.09.35.11; Mon, 27 Jul 2020 09:35:11 -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=DXHQUkLY; 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 D3FD368B94E; Mon, 27 Jul 2020 19:33:05 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1AE7E68B8F9 for ; Mon, 27 Jul 2020 19:32:57 +0300 (EEST) Received: by mail-wm1-f65.google.com with SMTP id c80so14724105wme.0 for ; Mon, 27 Jul 2020 09:32:57 -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=630TkcTWsrQBMFnt5DDOEo041VWfCAXqSpFq4KeJUDo=; b=DXHQUkLY0S0lchRTv6cMZhIzHDpD0F9/zh0y45HyYRGeEqGVPugHIe8XXKV2dHAYoz dGDFGgSps25+mMY2whiGRekZzeUP1AJBZ7OnQbVGqjUNSOogl1IIRyuWvYQ7gVuajMe7 0MHDyPWXTKCBLGwfAqABFTEiWhUtE5vwHu+ej5hYBGKftuvO1+xQ6yfdbZx3bIh6oO2g TnU4V+AdfxdgCfZWE8/pRNQ8CX5ZbCfL/3kdZJmp6CkZJ0OG/lmie/T1gttQkg5dqtez /KiMCsO1hgSmOnbMpcs0Hbg8kVCXbOUyXjuzqVpq4KO7EJH+bfAzS6l7LGcwADbAUkOh FMdg== 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=630TkcTWsrQBMFnt5DDOEo041VWfCAXqSpFq4KeJUDo=; b=OiWhSx4tEJ538r77hVjN3AWdkjlRLoSQNKoKDVaeGrRQm60NMoSjUncbMN3y4NOy73 BJtSxN0fjDsXnzBrc9/g4b47sf1bPDw6wytBP2s+Dtd8GH/Ab31D7TyJZFUOrtYvf85K pF7B/o/wikWclhRTq25JcaMRWm/7nzrPQn+23qG931wBgHEAQqw9KW7QgXT4NEQQI3Vn 8w59SUP0T9dyU99dQ1NbKARFkiz/PHcgY5dNQO7VPrLJKeLUlO3xMTYRFNoT4Piejsmf HdBj5a4jyD+OM8XzltOzSGhOs9IdLlr+wWGB457quUAwU6IG9C6S0dTfhsIzsvuMYdqW /71w== X-Gm-Message-State: AOAM5309prWKzqh2zE+X+TYtJShtsfo80m6wVfMTX2BrJ5ii+ZexhSPV pAiD7Y5ORXW/4nTpe+c51y18aey74n8= X-Received: by 2002:a1c:dc02:: with SMTP id t2mr104811wmg.55.1595867576282; Mon, 27 Jul 2020 09:32:56 -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 w16sm14706791wrg.95.2020.07.27.09.32.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2020 09:32:55 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Mon, 27 Jul 2020 17:32:28 +0100 Message-Id: <20200727163237.23371-14-sw@jkqxz.net> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727163237.23371-1-sw@jkqxz.net> References: <20200727163237.23371-1-sw@jkqxz.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 13/22] cbs: Expose the function to insert a new empty unit into a fragment 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" X-TUID: BAOL+fyxMjvr Content-Length: 2716 This will be helpful when adding new SEI to an existing access unit. --- libavcodec/cbs.c | 8 ++++---- libavcodec/cbs.h | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c index 7c1aa005c2..6677442d10 100644 --- a/libavcodec/cbs.c +++ b/libavcodec/cbs.c @@ -674,8 +674,8 @@ int ff_cbs_alloc_unit_data(CodedBitstreamUnit *unit, return 0; } -static int cbs_insert_unit(CodedBitstreamFragment *frag, - int position) +int ff_cbs_insert_unit(CodedBitstreamFragment *frag, + int position) { CodedBitstreamUnit *units; @@ -734,7 +734,7 @@ int ff_cbs_insert_unit_content(CodedBitstreamFragment *frag, content_ref = NULL; } - err = cbs_insert_unit(frag, position); + err = ff_cbs_insert_unit(frag, position); if (err < 0) { av_buffer_unref(&content_ref); return err; @@ -772,7 +772,7 @@ int ff_cbs_insert_unit_data(CodedBitstreamFragment *frag, return AVERROR(ENOMEM); } - err = cbs_insert_unit(frag, position); + err = ff_cbs_insert_unit(frag, position); if (err < 0) { av_buffer_unref(&data_ref); return err; diff --git a/libavcodec/cbs.h b/libavcodec/cbs.h index 3a054aa8f3..9152d655d2 100644 --- a/libavcodec/cbs.h +++ b/libavcodec/cbs.h @@ -366,6 +366,12 @@ int ff_cbs_alloc_unit_content2(CodedBitstreamContext *ctx, int ff_cbs_alloc_unit_data(CodedBitstreamUnit *unit, size_t size); +/** + * Insert a new empty unit into a fragment. + */ +int ff_cbs_insert_unit(CodedBitstreamFragment *frag, + int position); + /** * Insert a new unit into a fragment with the given content. * From patchwork Mon Jul 27 16:32:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 21299 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 BEA2B44A99C for ; Mon, 27 Jul 2020 19:35:19 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8864168B945; Mon, 27 Jul 2020 19:33:06 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 50C1068B900 for ; Mon, 27 Jul 2020 19:32:58 +0300 (EEST) Received: by mail-wm1-f49.google.com with SMTP id 3so8470580wmi.1 for ; Mon, 27 Jul 2020 09:32:58 -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=vnPmSnRo3ZyTqUCxZK0SI02YD/4lSTDK2S42FYK0+4M=; b=hm7bIRPE7QpRtlOCeAduU3KFSvbl47RoGwxCoeGI3gMdddZA+/7WoBP9lUGzUo9gmE XurTRVkGFoSbqh/C/WnnMAA7OcipOCfoIvJNVKkXPp/nnGseBSrNv8XgyfwdWxvRoGkK hZzexekiAYU4L3GrFhVjMI3pcUbn1tF3Ctj0dw6ONhaYBZLc4P8W0PwGEOoJB9HoQpkJ 4ZmUvhCsupuAfomUdmSS3Sa2kktuAUUKrKV79IA5SQhV2J5y+CegyxKSVzTq31uQ5OYV t4DwnhoMnbGYCDJjj/sQn2xnIbgbRs5YVqIsLUKNpx4ENEFHtMQSiO+EQVIbnpuxabjb sCFQ== 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=vnPmSnRo3ZyTqUCxZK0SI02YD/4lSTDK2S42FYK0+4M=; b=qXookiYjio0LxSyBNnHiTWbIjuVbnvJ+FqWJbLt3WZcATAjrdabmi+gTVO2PYJ9Tz2 xnVHh9kEOGRKn5PRI4qJO9uMqTa5iMt8KuLKVhk+NlV+aEbfQZlmFIVvPtYTUyYDjYng f1JWAbO2gCkNGmGfC5xkZdKCjVQw6Q1XxMyYrp0ZsIyimA42eqBpD0EPcY2CDw3qj1Tn d7mWEgmUzhLRKvvVLbOtdxeYC2imDuPZw6s6kCRAG072Kw1WrVk6wCG3uJhYlCL5OAIH shwoCMx03CqubMAR6dURdJ1fx+zDom3tzHFYcUL87ml/oPgp6gEWmd+RUgg/WXkHeylH M0Pw== X-Gm-Message-State: AOAM5320uR8mHIxAGkAmZ/sULHWn+RWb0g0+Whsto3huXnEJWDISmhDW 6eRoGCpIYFxZLmrTTORdsYMkyTDj0xA= X-Google-Smtp-Source: ABdhPJwGeMNeL8Ymh8qKugk1plrpebCfC71ve4k4eff3hRFF701ebfuFUl9g8k5bwMk3QvcXUksACg== X-Received: by 2002:a05:600c:2d1:: with SMTP id 17mr114695wmn.15.1595867577184; Mon, 27 Jul 2020 09:32:57 -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 w16sm14706791wrg.95.2020.07.27.09.32.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2020 09:32:56 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Mon, 27 Jul 2020 17:32:29 +0100 Message-Id: <20200727163237.23371-15-sw@jkqxz.net> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727163237.23371-1-sw@jkqxz.net> References: <20200727163237.23371-1-sw@jkqxz.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 14/22] cbs_h264: Simplify SEI addition 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" At the same time, move the H.264 SEI functions to a new file - the combined H.26[45] CBS file is already very large, and these functions do not require any of the common read/write elements. --- libavcodec/Makefile | 2 +- libavcodec/cbs_h264.c | 108 +++++++++++++++++++++++++++++++++++++++++ libavcodec/cbs_h264.h | 11 +++++ libavcodec/cbs_h2645.c | 94 +---------------------------------- 4 files changed, 122 insertions(+), 93 deletions(-) create mode 100644 libavcodec/cbs_h264.c diff --git a/libavcodec/Makefile b/libavcodec/Makefile index c48138d0ad..6394694617 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -70,7 +70,7 @@ OBJS-$(CONFIG_BSWAPDSP) += bswapdsp.o OBJS-$(CONFIG_CABAC) += cabac.o OBJS-$(CONFIG_CBS) += cbs.o OBJS-$(CONFIG_CBS_AV1) += cbs_av1.o -OBJS-$(CONFIG_CBS_H264) += cbs_h2645.o h2645_parse.o +OBJS-$(CONFIG_CBS_H264) += cbs_h2645.o cbs_h264.o h2645_parse.o OBJS-$(CONFIG_CBS_H265) += cbs_h2645.o h2645_parse.o OBJS-$(CONFIG_CBS_JPEG) += cbs_jpeg.o OBJS-$(CONFIG_CBS_MPEG2) += cbs_mpeg2.o diff --git a/libavcodec/cbs_h264.c b/libavcodec/cbs_h264.c new file mode 100644 index 0000000000..c86c6d565c --- /dev/null +++ b/libavcodec/cbs_h264.c @@ -0,0 +1,108 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "cbs_h264.h" +#include "cbs_internal.h" + +int ff_cbs_h264_add_sei_message(CodedBitstreamFragment *au, + H264RawSEIPayload *payload) +{ + H264RawSEI *sei = NULL; + int err, i; + + // Find an existing SEI NAL unit to add to. + for (i = 0; i < au->nb_units; i++) { + if (au->units[i].type == H264_NAL_SEI) { + sei = au->units[i].content; + if (sei->payload_count < H264_MAX_SEI_PAYLOADS) + break; + + sei = NULL; + } + } + + if (!sei) { + // Need to make a new SEI NAL unit. Insert it before the first + // slice data NAL unit; if no slice data, add at the end. + CodedBitstreamUnit *unit; + + for (i = 0; i < au->nb_units; i++) { + if (au->units[i].type == H264_NAL_SLICE || + au->units[i].type == H264_NAL_IDR_SLICE) + break; + } + + err = ff_cbs_insert_unit(au, i); + if (err < 0) + goto fail; + unit = &au->units[i]; + + // Needs a context for the type information but we don't have + // one, so forge one containing only the type information. + err = ff_cbs_alloc_unit_content2(&(CodedBitstreamContext) { + .codec = &ff_cbs_type_h264 }, unit); + if (err < 0) { + ff_cbs_delete_unit(au, i); + goto fail; + } + sei = unit->content; + + *sei = (H264RawSEI) { + .nal_unit_header = { + .nal_unit_type = H264_NAL_SEI, + }, + }; + } + + memcpy(&sei->payload[sei->payload_count], payload, sizeof(*payload)); + ++sei->payload_count; + + return 0; +fail: + ff_cbs_h264_free_sei_payload(payload); + return err; +} + +void ff_cbs_h264_delete_sei_message(CodedBitstreamFragment *au, + CodedBitstreamUnit *nal, + int position) +{ + H264RawSEI *sei = nal->content; + + av_assert0(nal->type == H264_NAL_SEI); + av_assert0(position >= 0 && position < sei->payload_count); + + if (position == 0 && sei->payload_count == 1) { + // Deleting NAL unit entirely. + int i; + + for (i = 0; i < au->nb_units; i++) { + if (&au->units[i] == nal) + break; + } + + ff_cbs_delete_unit(au, i); + } else { + ff_cbs_h264_free_sei_payload(&sei->payload[position]); + + --sei->payload_count; + memmove(sei->payload + position, + sei->payload + position + 1, + (sei->payload_count - position) * sizeof(*sei->payload)); + } +} diff --git a/libavcodec/cbs_h264.h b/libavcodec/cbs_h264.h index a6fe0a6af2..88313629f5 100644 --- a/libavcodec/cbs_h264.h +++ b/libavcodec/cbs_h264.h @@ -466,11 +466,22 @@ typedef struct CodedBitstreamH264Context { } CodedBitstreamH264Context; +/** + * Free an SEI payload structure. + * + * This is useful to have standalone when manipulating SEI messages inside + * an access unit. + */ +void ff_cbs_h264_free_sei_payload(H264RawSEIPayload *payload); + /** * Add an SEI message to an access unit. * * On success, the payload will be owned by a unit in access_unit; * on failure, the content of the payload will be freed. + * + * Adds at the end of an existing SEI NAL unit if one is present, otherwise + * creates a new SEI NAL unit to contain the message. */ int ff_cbs_h264_add_sei_message(CodedBitstreamFragment *access_unit, H264RawSEIPayload *payload); diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c index b9233f4df7..603017d8fe 100644 --- a/libavcodec/cbs_h2645.c +++ b/libavcodec/cbs_h2645.c @@ -1324,7 +1324,7 @@ static void cbs_h265_close(CodedBitstreamContext *ctx) av_buffer_unref(&h265->pps_ref[i]); } -static void cbs_h264_free_sei_payload(H264RawSEIPayload *payload) +void ff_cbs_h264_free_sei_payload(H264RawSEIPayload *payload) { switch (payload->payload_type) { case H264_SEI_TYPE_BUFFERING_PERIOD: @@ -1352,7 +1352,7 @@ static void cbs_h264_free_sei(void *opaque, uint8_t *content) H264RawSEI *sei = (H264RawSEI*)content; int i; for (i = 0; i < sei->payload_count; i++) - cbs_h264_free_sei_payload(&sei->payload[i]); + ff_cbs_h264_free_sei_payload(&sei->payload[i]); av_freep(&content); } @@ -1497,93 +1497,3 @@ const CodedBitstreamType ff_cbs_type_h265 = { .close = &cbs_h265_close, }; - -int ff_cbs_h264_add_sei_message(CodedBitstreamFragment *au, - H264RawSEIPayload *payload) -{ - H264RawSEI *sei = NULL; - int err, i; - - // Find an existing SEI NAL unit to add to. - for (i = 0; i < au->nb_units; i++) { - if (au->units[i].type == H264_NAL_SEI) { - sei = au->units[i].content; - if (sei->payload_count < H264_MAX_SEI_PAYLOADS) - break; - - sei = NULL; - } - } - - if (!sei) { - // Need to make a new SEI NAL unit. Insert it before the first - // slice data NAL unit; if no slice data, add at the end. - AVBufferRef *sei_ref; - - sei = av_mallocz(sizeof(*sei)); - if (!sei) { - err = AVERROR(ENOMEM); - goto fail; - } - - sei->nal_unit_header.nal_unit_type = H264_NAL_SEI; - sei->nal_unit_header.nal_ref_idc = 0; - - sei_ref = av_buffer_create((uint8_t*)sei, sizeof(*sei), - &cbs_h264_free_sei, NULL, 0); - if (!sei_ref) { - av_freep(&sei); - err = AVERROR(ENOMEM); - goto fail; - } - - for (i = 0; i < au->nb_units; i++) { - if (au->units[i].type == H264_NAL_SLICE || - au->units[i].type == H264_NAL_IDR_SLICE) - break; - } - - err = ff_cbs_insert_unit_content(au, i, H264_NAL_SEI, - sei, sei_ref); - av_buffer_unref(&sei_ref); - if (err < 0) - goto fail; - } - - memcpy(&sei->payload[sei->payload_count], payload, sizeof(*payload)); - ++sei->payload_count; - - return 0; -fail: - cbs_h264_free_sei_payload(payload); - return err; -} - -void ff_cbs_h264_delete_sei_message(CodedBitstreamFragment *au, - CodedBitstreamUnit *nal, - int position) -{ - H264RawSEI *sei = nal->content; - - av_assert0(nal->type == H264_NAL_SEI); - av_assert0(position >= 0 && position < sei->payload_count); - - if (position == 0 && sei->payload_count == 1) { - // Deleting NAL unit entirely. - int i; - - for (i = 0; i < au->nb_units; i++) { - if (&au->units[i] == nal) - break; - } - - ff_cbs_delete_unit(au, i); - } else { - cbs_h264_free_sei_payload(&sei->payload[position]); - - --sei->payload_count; - memmove(sei->payload + position, - sei->payload + position + 1, - (sei->payload_count - position) * sizeof(*sei->payload)); - } -} From patchwork Mon Jul 27 16:32:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 21300 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 5FEC744A99C for ; Mon, 27 Jul 2020 19:35:30 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 58BE768B948; Mon, 27 Jul 2020 19:33:07 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1A46268B89C for ; Mon, 27 Jul 2020 19:32:59 +0300 (EEST) Received: by mail-wm1-f68.google.com with SMTP id 184so15400949wmb.0 for ; Mon, 27 Jul 2020 09:32:59 -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=bg263UqY65lfaMe3NhiKSHDhEmMkC+KgEzpXVj8sar0=; b=nSPw3bhQdf+aTm/tgZjq0p95E+lbVUdxYkSzB4jSnXPTRYdBvTz+7s3vRPbfs5nwLD RdZURTxtqsfleWzubo7Ka51z9UyLxXilNV41HbQitMTF5f1Rrlf3jUDuIrpMgXDd6pYn yAVUsSLH2eWGJ4r/XpMXWMCqGjRkEtrkGM7kYdq5SZgwaSn2ZKWB47EFID4aXLRnr5Py VUcntfSfrm6MRcw8OJpqXRTYXNUkvbhm1HklcgDuBNWwjkJSDTfYn8208QSpod0jGhOE 0Nuz8PrAhaViuqKaxhWTejvzt47YXFIHqNxzrAZkT4PNIv7LowlDssGKcYLcWki/VzlO aVVw== 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=bg263UqY65lfaMe3NhiKSHDhEmMkC+KgEzpXVj8sar0=; b=gPkp1tB15rK1OcSym7BwgTwwycxSVbEgejp4Yujrt6nLcdO733eezuj/1CBjNJvaug 1qHY0lk1BaIDrrp92gubEVbX1vr94QvPwwSmvjPdj+1TjLam620b97cXYhU98cZ6iN/b Envd3FAoLMuFPROs0Z98SJWFpLtx8W4Q0D0NrBzegN17ebTY+SB7Hmfq7CsdtRNZ4hAZ P+7ZnE90IcU6/6jKwo+P/buMOwf8Gp7yFeUpvUMAIVyiVx8dzbecGEVkvzmsHJXQt54+ vMZwLL8OszW15x8bcfz1IN9m2WLzqM0g6XdU769EkA0Cf11lIK04xfvhkaaH8VWEQVT/ JNuA== X-Gm-Message-State: AOAM531GmxgtynFeu66TJQ8eue/M1VxBh63IIprBYNUfkak2FgnidYqd jurjAD7iZO7YSjXubOOE441fQzymK04= X-Google-Smtp-Source: ABdhPJxW+6vd4MfURXGHVxrLWwl6vknKWUfv9QM9m9Fyaug2w+mLiPrYN1Gz5IvL4Mw33IPVNGiaug== X-Received: by 2002:a7b:cb46:: with SMTP id v6mr109792wmj.73.1595867578263; Mon, 27 Jul 2020 09:32:58 -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 w16sm14706791wrg.95.2020.07.27.09.32.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2020 09:32:57 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Mon, 27 Jul 2020 17:32:30 +0100 Message-Id: <20200727163237.23371-16-sw@jkqxz.net> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727163237.23371-1-sw@jkqxz.net> References: <20200727163237.23371-1-sw@jkqxz.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 15/22] cbs_h264: Add support for frame packing arrangement SEI messages 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" --- libavcodec/cbs_h264.h | 24 ++++++++++++++++ libavcodec/cbs_h2645.c | 1 + libavcodec/cbs_h264_syntax_template.c | 40 +++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) diff --git a/libavcodec/cbs_h264.h b/libavcodec/cbs_h264.h index 88313629f5..ca717a3b57 100644 --- a/libavcodec/cbs_h264.h +++ b/libavcodec/cbs_h264.h @@ -296,6 +296,29 @@ typedef struct H264RawSEIRecoveryPoint { uint8_t changing_slice_group_idc; } H264RawSEIRecoveryPoint; +typedef struct H264RawSEIFramePackingArrangement { + uint32_t frame_packing_arrangement_id; + uint8_t frame_packing_arrangement_cancel_flag; + + uint8_t frame_packing_arrangement_type; + uint8_t quincunx_sampling_flag; + uint8_t content_interpretation_type; + uint8_t spatial_flipping_flag; + uint8_t frame0_flipped_flag; + uint8_t field_views_flag; + uint8_t current_frame_is_frame0_flag; + uint8_t frame0_self_contained_flag; + uint8_t frame1_self_contained_flag; + uint8_t frame0_grid_position_x; + uint8_t frame0_grid_position_y; + uint8_t frame1_grid_position_x; + uint8_t frame1_grid_position_y; + uint8_t frame_packing_arrangement_reserved_byte; + uint16_t frame_packing_arrangement_repetition_period; + + uint8_t frame_packing_arrangement_extension_flag; +} H264RawSEIFramePackingArrangement; + typedef struct H264RawSEIDisplayOrientation { uint8_t display_orientation_cancel_flag; uint8_t hor_flip; @@ -329,6 +352,7 @@ typedef struct H264RawSEIPayload { H264RawSEIUserDataRegistered user_data_registered; H264RawSEIUserDataUnregistered user_data_unregistered; H264RawSEIRecoveryPoint recovery_point; + H264RawSEIFramePackingArrangement frame_packing_arrangement; H264RawSEIDisplayOrientation display_orientation; H264RawSEIMasteringDisplayColourVolume mastering_display_colour_volume; H264RawSEIAlternativeTransferCharacteristics diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c index 603017d8fe..1677731db9 100644 --- a/libavcodec/cbs_h2645.c +++ b/libavcodec/cbs_h2645.c @@ -1331,6 +1331,7 @@ void ff_cbs_h264_free_sei_payload(H264RawSEIPayload *payload) case H264_SEI_TYPE_PIC_TIMING: case H264_SEI_TYPE_PAN_SCAN_RECT: case H264_SEI_TYPE_RECOVERY_POINT: + case H264_SEI_TYPE_FRAME_PACKING: case H264_SEI_TYPE_DISPLAY_ORIENTATION: case H264_SEI_TYPE_MASTERING_DISPLAY_COLOUR_VOLUME: case H264_SEI_TYPE_ALTERNATIVE_TRANSFER: diff --git a/libavcodec/cbs_h264_syntax_template.c b/libavcodec/cbs_h264_syntax_template.c index b65460996b..7880b1472c 100644 --- a/libavcodec/cbs_h264_syntax_template.c +++ b/libavcodec/cbs_h264_syntax_template.c @@ -779,6 +779,42 @@ static int FUNC(sei_recovery_point)(CodedBitstreamContext *ctx, RWContext *rw, return 0; } +static int FUNC(sei_frame_packing_arrangement)(CodedBitstreamContext *ctx, RWContext *rw, + H264RawSEIFramePackingArrangement *current) +{ + int err; + + HEADER("Frame Packing Arrangement"); + + ue(frame_packing_arrangement_id, 0, UINT32_MAX - 1); + flag(frame_packing_arrangement_cancel_flag); + + if (!current->frame_packing_arrangement_cancel_flag) { + u(7, frame_packing_arrangement_type, 0, 7); + flag(quincunx_sampling_flag); + u(6, content_interpretation_type, 0, 2); + flag(spatial_flipping_flag); + flag(frame0_flipped_flag); + flag(field_views_flag); + flag(current_frame_is_frame0_flag); + flag(frame0_self_contained_flag); + flag(frame1_self_contained_flag); + if (!current->quincunx_sampling_flag && + current->frame_packing_arrangement_type != 5) { + ub(4, frame0_grid_position_x); + ub(4, frame0_grid_position_y); + ub(4, frame1_grid_position_x); + ub(4, frame1_grid_position_y); + } + u(8, frame_packing_arrangement_reserved_byte, 0, 0); + ue(frame_packing_arrangement_repetition_period, 0, 16384); + } + + flag(frame_packing_arrangement_extension_flag); + + return 0; +} + static int FUNC(sei_display_orientation)(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEIDisplayOrientation *current) { @@ -879,6 +915,10 @@ static int FUNC(sei_payload)(CodedBitstreamContext *ctx, RWContext *rw, CHECK(FUNC(sei_display_orientation) (ctx, rw, ¤t->payload.display_orientation)); break; + case H264_SEI_TYPE_FRAME_PACKING: + CHECK(FUNC(sei_frame_packing_arrangement) + (ctx, rw, ¤t->payload.frame_packing_arrangement)); + break; case H264_SEI_TYPE_MASTERING_DISPLAY_COLOUR_VOLUME: CHECK(FUNC(sei_mastering_display_colour_volume) (ctx, rw, ¤t->payload.mastering_display_colour_volume)); From patchwork Mon Jul 27 16:32:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 21301 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 2678444A99C for ; Mon, 27 Jul 2020 19:35:40 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1BF5B68B952; Mon, 27 Jul 2020 19:33:08 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1C9C068B910 for ; Mon, 27 Jul 2020 19:33:00 +0300 (EEST) Received: by mail-wm1-f66.google.com with SMTP id k8so5079396wma.2 for ; Mon, 27 Jul 2020 09:33:00 -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=c8R5qEuIArDuIg822yqD5QWgkq8mY22l+hHJM1y3Dbg=; b=loHtcj6+QcSjCPSBkegfnfDTgfhk16syLVqElApP1q3v9SXpoewzVk6tlYdGfILcCL J/QwjcHrQCSgoXlcg9iJ7XhZHv0yF0YPGBud/Y3FAtc2oyZoIwRhdXL0vEm1JquNEkuI 9dAAa86BMEMAOaWqgSHkH+QMVu/pn77Pbh1wgCEGH3JLbdX4V/x0UmmvE4NwWP0Nn3VZ CtEB3pFpUSQhlEQvWXegY6sjZTgCG3fOge8RQ7QpL9dptAHBcnziwEnY/f+e8hynvnN3 ETG4K251xT5VnGe5rZJ8zqPwKujlFjxkxnTOY4qO6htJGIx1g+L/tX13QBV4I0IC/qeb ej2g== 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=c8R5qEuIArDuIg822yqD5QWgkq8mY22l+hHJM1y3Dbg=; b=gpbA+X3bHiFJy2vMjKqKQR90QkDrAzv+ngsHPk5oKP7qnKpP2IcWH8UH1kzyfx4u8m OgpEQ5ouYR2qSV31fsnXQ09L2ASD6jfq/Y3bG5XvZgCAOqrBbzVxBQfKqw4CEdcPzApT NW/PGc/6bauIV1r9p/GfOAq1RFT6yPSk010UWJcFDQaDMxu0SXmL0C5sXK2ZnDedZgnO dAdt2waJXzoj8XorjuY3oOlB/LTfGDPlindHYsaWyhMaSs1b70nOV/jlAsru+Ph24aYw G90JqJihMki3BtU+ok8eQXYe0jmjYk2UIvdXt9sIqMvjdWft/ZN7AmZEfH58RIPYmr69 cr1A== X-Gm-Message-State: AOAM530NUCIkJVppQIUcs/39ui6ZXjPYF05ia7PSJWaLJzWbP9Qoiaji j4dDotAx3khMu/TrrRcL9ws1RqxFnjk= X-Google-Smtp-Source: ABdhPJwvCL4WPiR0yyizFEbY0ITCEG9iGnqi/faKDQBjIoxns9RdA8h+F8V/yxlZD37CnqDXqqjLNA== X-Received: by 2002:a7b:c195:: with SMTP id y21mr145962wmi.20.1595867579205; Mon, 27 Jul 2020 09:32:59 -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 w16sm14706791wrg.95.2020.07.27.09.32.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2020 09:32:58 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Mon, 27 Jul 2020 17:32:31 +0100 Message-Id: <20200727163237.23371-17-sw@jkqxz.net> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727163237.23371-1-sw@jkqxz.net> References: <20200727163237.23371-1-sw@jkqxz.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 16/22] cbs_h264: Add a function to turn stereo 3D metadata into SEI 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" --- libavcodec/cbs_h264.c | 47 +++++++++++++++++++++++++++++++++++++++++++ libavcodec/cbs_h264.h | 8 ++++++++ 2 files changed, 55 insertions(+) diff --git a/libavcodec/cbs_h264.c b/libavcodec/cbs_h264.c index c86c6d565c..a128745799 100644 --- a/libavcodec/cbs_h264.c +++ b/libavcodec/cbs_h264.c @@ -16,6 +16,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/stereo3d.h" + #include "cbs_h264.h" #include "cbs_internal.h" @@ -106,3 +108,48 @@ void ff_cbs_h264_delete_sei_message(CodedBitstreamFragment *au, (sei->payload_count - position) * sizeof(*sei->payload)); } } + +void ff_cbs_h264_fill_sei_frame_packing_arrangement(H264RawSEIFramePackingArrangement *fp, + const AVStereo3D *st) +{ + static const uint8_t type_map[] = { + [AV_STEREO3D_2D] = 6, + [AV_STEREO3D_SIDEBYSIDE] = 3, + [AV_STEREO3D_TOPBOTTOM] = 4, + [AV_STEREO3D_FRAMESEQUENCE] = 5, + [AV_STEREO3D_CHECKERBOARD] = 0, + [AV_STEREO3D_SIDEBYSIDE_QUINCUNX] = 3, + [AV_STEREO3D_LINES] = 2, + [AV_STEREO3D_COLUMNS] = 1, + }; + + memset(fp, 0, sizeof(*fp)); + + if (st->type >= FF_ARRAY_ELEMS(type_map)) + return; + + fp->frame_packing_arrangement_type = type_map[st->type]; + + fp->quincunx_sampling_flag = + st->type == AV_STEREO3D_CHECKERBOARD || + st->type == AV_STEREO3D_SIDEBYSIDE_QUINCUNX; + + if (st->type == AV_STEREO3D_2D) + fp->content_interpretation_type = 0; + else if (st->flags & AV_STEREO3D_FLAG_INVERT) + fp->content_interpretation_type = 2; + else + fp->content_interpretation_type = 1; + + if (st->type == AV_STEREO3D_FRAMESEQUENCE) { + if (st->flags & AV_STEREO3D_FLAG_INVERT) + fp->current_frame_is_frame0_flag = + st->view == AV_STEREO3D_VIEW_RIGHT; + else + fp->current_frame_is_frame0_flag = + st->view == AV_STEREO3D_VIEW_LEFT; + } + + fp->frame_packing_arrangement_repetition_period = + st->type != AV_STEREO3D_FRAMESEQUENCE; +} diff --git a/libavcodec/cbs_h264.h b/libavcodec/cbs_h264.h index ca717a3b57..2f537564a7 100644 --- a/libavcodec/cbs_h264.h +++ b/libavcodec/cbs_h264.h @@ -523,4 +523,12 @@ void ff_cbs_h264_delete_sei_message(CodedBitstreamFragment *access_unit, CodedBitstreamUnit *nal_unit, int position); +struct AVStereo3D; +/** + * Fill an SEI Frame Packing Arrangement structure with values derived from + * the AVStereo3D side-data structure. + */ +void ff_cbs_h264_fill_sei_frame_packing_arrangement(H264RawSEIFramePackingArrangement *fp, + const struct AVStereo3D *st); + #endif /* AVCODEC_CBS_H264_H */ From patchwork Mon Jul 27 16:32:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 21302 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 F281D44A99C for ; Mon, 27 Jul 2020 19:35:49 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id ECE1968B956; Mon, 27 Jul 2020 19:33:08 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E71A768B8EB for ; Mon, 27 Jul 2020 19:33:00 +0300 (EEST) Received: by mail-wm1-f52.google.com with SMTP id p14so14375647wmg.1 for ; Mon, 27 Jul 2020 09:33:00 -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=2R0ormIUU9at0n6Lp2bzv6wTdgcn6yzZHYcwa5uyhog=; b=w9gNjh7rIZJBr0LD6ZEkSvg36ABUUngmaDCyfuwedP+rhsRAlbMT53znoLprE/qU9J GeYr17a0zYo+P7W6o+kk4BDeVobIwbBGFT56rpoyezP29bnKxZ0+RpZ6nnzfdTh/BDEp RzhplV00FHHbV3yvHG1C6abgBR6tbVvTLplKLrUJ6+5YdvXUXQ2cY6nAFM/Ws1PgCpey 9OAXaAir4mbz6lDOrMddTPKV3srKlZokcWXweh2LT1Tgz3+Baq2ZZp9bvVOWlqBa/FcX N2sIxdSJLdW1PoUP2LT/DiJSf9v1xmScNF60Q7xcKej7O/1dQJN+zf3hg1mqGIcmr372 zWzw== 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=2R0ormIUU9at0n6Lp2bzv6wTdgcn6yzZHYcwa5uyhog=; b=UoiCjIY0VQ23HPyqHnDRqWwvyCUnt0zCa6wK1hTOByjSI6TpIr0lvDiO4Ry5iSPM/+ rwdXo3hhvY9RvW2mTeqvN/vIR4Q0N6UU0ui+Snubd0u6hIwNfvDWyWrQiXcUM5wxs0XA m6NxtWH7UjuHZIQ8dUsGNWPbuUTyoT59rGP8o6sizCRydWifc2AMoKhFoDdaHIEyIOIw QG+XwYqxvPrTSpLXLfGkxQlXgXMTreWP9YS2gOOiMajHy40JszE3iVNmT3KR1QvcmjA9 3S105fYPLyZa+j6xTs6PwQlAo23zTbgqpeB9dRSrEfYVZHtI/8siOyw/VwAo78LGjIB/ kN6A== X-Gm-Message-State: AOAM5319TfFQeyBfQI7u2GQz0xpCZbkqtjfj/bmVbyuUz/Eb63Ki9O6d IQsYP+MWXf1SAKZCBKg9bgEQSvhDn0k= X-Google-Smtp-Source: ABdhPJxsjBeAC61iuN3IjTHErdm2d8YdseG4snbRrm35rV4KTvM5mekuTgmxLxZC3Sr0IgR9uPOrxQ== X-Received: by 2002:a1c:a54e:: with SMTP id o75mr82788wme.181.1595867580123; Mon, 27 Jul 2020 09:33:00 -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 w16sm14706791wrg.95.2020.07.27.09.32.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2020 09:32:59 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Mon, 27 Jul 2020 17:32:32 +0100 Message-Id: <20200727163237.23371-18-sw@jkqxz.net> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727163237.23371-1-sw@jkqxz.net> References: <20200727163237.23371-1-sw@jkqxz.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 17/22] vaapi_encode: Unify SEI types enum 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" This was in two disjoint parts in the H.264 and H.265 files. Unify them in the header to avoid any confusion, because they are really the same enum. --- libavcodec/vaapi_encode.h | 10 ++++++++++ libavcodec/vaapi_encode_h264.c | 6 ------ libavcodec/vaapi_encode_h265.c | 5 ----- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h index 6487a99604..3bb240ec68 100644 --- a/libavcodec/vaapi_encode.h +++ b/libavcodec/vaapi_encode.h @@ -476,4 +476,14 @@ int ff_vaapi_encode_close(AVCodecContext *avctx); VAAPI_ENCODE_RC_MODE(AVBR, "Average variable-bitrate") +// SEI types used in options for both H.264 and H.265. +enum { + SEI_TIMING = 0x01, + SEI_IDENTIFIER = 0x02, + SEI_RECOVERY_POINT = 0x04, + SEI_MASTERING_DISPLAY = 0x08, + SEI_CONTENT_LIGHT_LEVEL = 0x10, +}; + + #endif /* AVCODEC_VAAPI_ENCODE_H */ diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c index 5e1683e851..62f95ea59f 100644 --- a/libavcodec/vaapi_encode_h264.c +++ b/libavcodec/vaapi_encode_h264.c @@ -35,12 +35,6 @@ #include "internal.h" #include "vaapi_encode.h" -enum { - SEI_TIMING = 0x01, - SEI_IDENTIFIER = 0x02, - SEI_RECOVERY_POINT = 0x04, -}; - // Random (version 4) ISO 11578 UUID. static const uint8_t vaapi_encode_h264_sei_identifier_uuid[16] = { 0x59, 0x94, 0x8b, 0x28, 0x11, 0xec, 0x45, 0xaf, diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c index f6008778df..90fea83388 100644 --- a/libavcodec/vaapi_encode_h265.c +++ b/libavcodec/vaapi_encode_h265.c @@ -37,11 +37,6 @@ #include "put_bits.h" #include "vaapi_encode.h" -enum { - SEI_MASTERING_DISPLAY = 0x08, - SEI_CONTENT_LIGHT_LEVEL = 0x10, -}; - typedef struct VAAPIEncodeH265Picture { int pic_order_cnt; From patchwork Mon Jul 27 16:32:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 21303 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 C296044A99C for ; Mon, 27 Jul 2020 19:35:59 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A639468B95B; Mon, 27 Jul 2020 19:33:09 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3EC3068B923 for ; Mon, 27 Jul 2020 19:33:02 +0300 (EEST) Received: by mail-wm1-f68.google.com with SMTP id 3so8470835wmi.1 for ; Mon, 27 Jul 2020 09:33:02 -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=NJutcFYHQZcuwEuFjextxOqe9VgzkmBGv6NZzdAnQJM=; b=DRzs3286tbm3Ar6GU9TT5vdpA/fBVBThddxz3Nrly66d0/Lwdgzii0kQMzUTTt/Hpq XTbS42VOUa9Ei9hSU6eXOvmW1YeVEUue8yaqNUpmtoVM4esvqIabY/riHqL7amOnJbmB WIq11ESdh/O35hFnPJhxzvPhBGRVXtatnXeRKAWh7Ezt1HBVuW7i/pjio5NY6ohPXnu2 bP7xnxUDlbW/WFlNPzjQer1A8nD/GbprjpSO80NGnPtG6s4RK0+7k/cT0+ivWjf9/Lm8 +miI5GggC1C/zF8XAgdhpUigYoNuPM4SqNb8yvSaYtsznZDQrI5VbRpWsbxrfVbBGi+M Kh1A== 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=NJutcFYHQZcuwEuFjextxOqe9VgzkmBGv6NZzdAnQJM=; b=Oow41oYb5iQlTru5a2Lf0o3X+86nv8Yx/tkd/j1mnWsnM5uyy3cB7Cvub5xWQT2XHn 5En7RZ4lEab8OWibaYAJUseVJ9LRP4vrmvTQHFidxcQf1NXl34RmneRPIta4UR16UjzN AomeU23wlyyLVX38UcfckZcbG5mHpRT/tyhBeyd/wAIseKN2+UTaC/Fa/tfpG5dAsoSn PaI7hu00zUwqAzaqWq9CUEPum029Z+1NPgh9kbmtFxgsZOFygy4dwgalBMt9nmJRXOQX 9GlroxYVXpt0FkpAvs7NYWZyQJWUMIHD1x0G9Y0dcNytZLLqKct+7nCN5TXWoeDn2YcV INuw== X-Gm-Message-State: AOAM53026OuHBaLpoe6KcAtEaSu04W/Ib8lrozWEMRdNZpjFHjNurWSq XNHHljiSpR/rAn8RC8MStErJl0AIckc= X-Google-Smtp-Source: ABdhPJyyhWd8McVlRZZfuagCMb4quRbCMvXb/kwObJ0EVE4Tx2rJz9OxYuETM1T1EpxdSB9VVkQ+DA== X-Received: by 2002:a1c:5f44:: with SMTP id t65mr89204wmb.99.1595867581484; Mon, 27 Jul 2020 09:33:01 -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 w16sm14706791wrg.95.2020.07.27.09.33.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2020 09:33:00 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Mon, 27 Jul 2020 17:32:33 +0100 Message-Id: <20200727163237.23371-19-sw@jkqxz.net> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727163237.23371-1-sw@jkqxz.net> References: <20200727163237.23371-1-sw@jkqxz.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 18/22] vaapi_encode_h264: Support stereo 3D metadata 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" Insert frame packing arrangement messages into the stream when input frames have associated stereo 3D side-data. --- doc/encoders.texi | 3 +++ libavcodec/vaapi_encode.h | 1 + libavcodec/vaapi_encode_h264.c | 24 +++++++++++++++++++++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/doc/encoders.texi b/doc/encoders.texi index ed8ef63784..32870f5939 100644 --- a/doc/encoders.texi +++ b/doc/encoders.texi @@ -3175,6 +3175,9 @@ Include picture timing parameters (@emph{buffering_period} and @emph{pic_timing} messages). @item recovery_point Include recovery points where appropriate (@emph{recovery_point} messages). +@item frame_packing +Include stereo 3D metadata if the input frames have it +(@emph{frame_packing_arrangement} messages). @end table @end table diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h index 3bb240ec68..671b21f283 100644 --- a/libavcodec/vaapi_encode.h +++ b/libavcodec/vaapi_encode.h @@ -483,6 +483,7 @@ enum { SEI_RECOVERY_POINT = 0x04, SEI_MASTERING_DISPLAY = 0x08, SEI_CONTENT_LIGHT_LEVEL = 0x10, + SEI_FRAME_PACKING = 0x20, }; diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c index 62f95ea59f..f6d16b5c24 100644 --- a/libavcodec/vaapi_encode_h264.c +++ b/libavcodec/vaapi_encode_h264.c @@ -25,6 +25,7 @@ #include "libavutil/common.h" #include "libavutil/internal.h" #include "libavutil/opt.h" +#include "libavutil/stereo3d.h" #include "avcodec.h" #include "cbs.h" @@ -90,6 +91,7 @@ typedef struct VAAPIEncodeH264Context { H264RawSEIBufferingPeriod sei_buffering_period; H264RawSEIPicTiming sei_pic_timing; H264RawSEIRecoveryPoint sei_recovery_point; + H264RawSEIFramePackingArrangement sei_frame_packing; H264RawSEIUserDataUnregistered sei_identifier; char *sei_identifier_string; @@ -244,6 +246,12 @@ static int vaapi_encode_h264_write_extra_header(AVCodecContext *avctx, sei->payload[i].payload.recovery_point = priv->sei_recovery_point; ++i; } + if (priv->sei_needed & SEI_FRAME_PACKING) { + sei->payload[i].payload_type = H264_SEI_TYPE_FRAME_PACKING; + sei->payload[i].payload.frame_packing_arrangement = + priv->sei_frame_packing; + ++i; + } sei->payload_count = i; av_assert0(sei->payload_count > 0); @@ -693,6 +701,17 @@ static int vaapi_encode_h264_init_picture_params(AVCodecContext *avctx, priv->sei_needed |= SEI_RECOVERY_POINT; } + if (priv->sei & SEI_FRAME_PACKING) { + AVFrameSideData *sd = av_frame_get_side_data(pic->input_image, + AV_FRAME_DATA_STEREO3D); + if (sd) { + ff_cbs_h264_fill_sei_frame_packing_arrangement( + &priv->sei_frame_packing, (const AVStereo3D*)sd->data); + + priv->sei_needed |= SEI_FRAME_PACKING; + } + } + vpic->CurrPic = (VAPictureH264) { .picture_id = pic->recon_surface, .frame_idx = hpic->frame_num, @@ -1264,7 +1283,7 @@ static const AVOption vaapi_encode_h264_options[] = { { "sei", "Set SEI to include", OFFSET(sei), AV_OPT_TYPE_FLAGS, - { .i64 = SEI_IDENTIFIER | SEI_TIMING | SEI_RECOVERY_POINT }, + { .i64 = SEI_IDENTIFIER | SEI_TIMING | SEI_RECOVERY_POINT | SEI_FRAME_PACKING }, 0, INT_MAX, FLAGS, "sei" }, { "identifier", "Include encoder version identifier", 0, AV_OPT_TYPE_CONST, { .i64 = SEI_IDENTIFIER }, @@ -1275,6 +1294,9 @@ static const AVOption vaapi_encode_h264_options[] = { { "recovery_point", "Include recovery points where appropriate", 0, AV_OPT_TYPE_CONST, { .i64 = SEI_RECOVERY_POINT }, INT_MIN, INT_MAX, FLAGS, "sei" }, + { "frame_packing", "Include frame packing arrangement for stereo 3D", + 0, AV_OPT_TYPE_CONST, { .i64 = SEI_FRAME_PACKING }, + INT_MIN, INT_MAX, FLAGS, "sei" }, { "profile", "Set profile (profile_idc and constraint_set*_flag)", OFFSET(profile), AV_OPT_TYPE_INT, From patchwork Mon Jul 27 16:32:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 21304 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 A1A6244AF2C for ; Mon, 27 Jul 2020 19:36:09 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 676E268B919; Mon, 27 Jul 2020 19:33:11 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 69DE568B93A for ; Mon, 27 Jul 2020 19:33:03 +0300 (EEST) Received: by mail-wm1-f43.google.com with SMTP id o8so14711768wmh.4 for ; Mon, 27 Jul 2020 09:33:03 -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=3iE5lAawhLJ7lHvUlTtn/QqiQWcTSY3h/kwQkDxY2Cs=; b=D9QqEHeVH4Vp8nCE4DXVhVMDVmfBt8jT4RvfAAlDNgTaMe6c4sMto+fN2JPPoycsRB dDVqxOjxcYgeiSIL232nzuGz/kAeeATL1FuulFxkXpQgEns97WXZij0VkRBY8mowYBKB PPNXrg3sKHbnigQcJeLhBId+vpih2rQ3jw3/aPrHKBMEaGqSavUQU69ymYLhh/OO4UOf MI1YUPQK3+xhLiii3or15U2zzs+gwzdGYwZ84gRPkOKe4n6D2fXLB9JPjSMiNd8pja/8 MEUJtVVZI+7HUrMMMZyDDJtFRgur+wsbKdpnmkmCip4tsI30WHWhiNz0LRKDRcYSdosA BO/w== 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=3iE5lAawhLJ7lHvUlTtn/QqiQWcTSY3h/kwQkDxY2Cs=; b=n9xKU96390N6OQFkisvFwKFxgeRp4vElh9U953MXLj+Zv7zsEzsYmqE+rXcTjPPEo7 yGbcNTp1GiCmiRw6hN/b5VCMXPwtlEErqYthjcxkKXHTswja10Z1XgAPUPc78yISQPoR zXm4g5k2sDHSd+ue7QlKJecq6ZmIh8p9IRPLvee8lQCpz9tF8YSRx3DKyo5EoXClp+pU 9avNdqktfvmOXjLwrU5gbtW0NlkmFW60e4hPvmUDi/ELMLvxN9IhiohUwJYRSQ3xWord JgVqalzy4oYb1ClaZBA+GUdbruR9hvzx/pCM3Mfc1kPEwuPTibuzkEWh3l98593+nTHu gmVw== X-Gm-Message-State: AOAM532PIjrXD2aZyiyI0S1GozgUggvreDifhyjhmWZj1RGZmj4Wep3o oMS61wUTEvoQqgXx/ujW7nMVGBqFpHs= X-Google-Smtp-Source: ABdhPJx3naheevsiOAeoV/lDnnFDbwGWlIKH/rT/DMngrB1QxyEb8Z4H67r37C6uQaEhGV90qZ4yOQ== X-Received: by 2002:a1c:790b:: with SMTP id l11mr94401wme.127.1595867582292; Mon, 27 Jul 2020 09:33:02 -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 w16sm14706791wrg.95.2020.07.27.09.33.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2020 09:33:01 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Mon, 27 Jul 2020 17:32:34 +0100 Message-Id: <20200727163237.23371-20-sw@jkqxz.net> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727163237.23371-1-sw@jkqxz.net> References: <20200727163237.23371-1-sw@jkqxz.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 19/22] cbs_h265: Add functions to turn HDR metadata into SEI 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" --- libavcodec/Makefile | 2 +- libavcodec/cbs_h265.c | 100 ++++++++++++++++++++++++++++++++++++++++++ libavcodec/cbs_h265.h | 18 ++++++++ 3 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 libavcodec/cbs_h265.c diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 6394694617..96dc1df343 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -71,7 +71,7 @@ OBJS-$(CONFIG_CABAC) += cabac.o OBJS-$(CONFIG_CBS) += cbs.o OBJS-$(CONFIG_CBS_AV1) += cbs_av1.o OBJS-$(CONFIG_CBS_H264) += cbs_h2645.o cbs_h264.o h2645_parse.o -OBJS-$(CONFIG_CBS_H265) += cbs_h2645.o h2645_parse.o +OBJS-$(CONFIG_CBS_H265) += cbs_h2645.o cbs_h265.o h2645_parse.o OBJS-$(CONFIG_CBS_JPEG) += cbs_jpeg.o OBJS-$(CONFIG_CBS_MPEG2) += cbs_mpeg2.o OBJS-$(CONFIG_CBS_VP9) += cbs_vp9.o diff --git a/libavcodec/cbs_h265.c b/libavcodec/cbs_h265.c new file mode 100644 index 0000000000..afbdd37896 --- /dev/null +++ b/libavcodec/cbs_h265.c @@ -0,0 +1,100 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/mathematics.h" +#include "libavutil/mastering_display_metadata.h" + +#include "cbs_h265.h" + + +static uint32_t rescale_clip(AVRational value, uint32_t scale, uint32_t max) +{ + int64_t scaled = av_rescale(scale, value.num, value.den); + return av_clip64(scaled, 0, max); +} + +static uint32_t rescale_fraction(AVRational value, uint32_t max) +{ + return rescale_clip(value, max, max); +} + +void ff_cbs_h265_fill_sei_mastering_display(H265RawSEIMasteringDisplayColourVolume *mdcv, + const AVMasteringDisplayMetadata *mdm) +{ + memset(mdcv, 0, sizeof(*mdcv)); + + if (mdm->has_primaries) { + // The values in the metadata structure are fractions between 0 and 1, + // while the SEI message contains fixed-point values with an increment + // of 0.00002. So, scale up by 50000 to convert between them. + + for (int a = 0; a < 3; a++) { + // The metadata structure stores this in RGB order, but the SEI + // wants it in GBR order. + static const uint8_t mapping[] = { 1, 2, 0 }; + int b = mapping[a]; + mdcv->display_primaries_x[a] = + rescale_fraction(mdm->display_primaries[b][0], 50000); + mdcv->display_primaries_y[a] = + rescale_fraction(mdm->display_primaries[b][1], 50000); + } + + mdcv->white_point_x = rescale_fraction(mdm->white_point[0], 50000); + mdcv->white_point_y = rescale_fraction(mdm->white_point[1], 50000); + } + + if (mdm->has_luminance) { + // Metadata are rational values in candelas per square metre, SEI + // contains fixed point in units of 0.0001 candelas per square + // metre. So scale up by 10000 to convert between them, and clip to + // ensure that we don't overflow. + + mdcv->max_display_mastering_luminance = + rescale_clip(mdm->max_luminance, 10000, UINT32_MAX); + mdcv->min_display_mastering_luminance = + rescale_clip(mdm->min_luminance, 10000, UINT32_MAX); + + // The spec has a hard requirement that min is less than the max, + // and the SEI-writing code enforces that. + if (!(mdcv->min_display_mastering_luminance < + mdcv->max_display_mastering_luminance)) { + if (mdcv->max_display_mastering_luminance == UINT32_MAX) + mdcv->min_display_mastering_luminance = + mdcv->max_display_mastering_luminance - 1; + else + mdcv->max_display_mastering_luminance = + mdcv->min_display_mastering_luminance + 1; + } + } else { + mdcv->max_display_mastering_luminance = 1; + mdcv->min_display_mastering_luminance = 0; + } +} + +void ff_cbs_h265_fill_sei_content_light_level(H265RawSEIContentLightLevelInfo *cll, + const AVContentLightMetadata *clm) +{ + memset(cll, 0, sizeof(*cll)); + + // Both the metadata and the SEI are in units of candelas per square + // metre, so we only need to clip to ensure that they are in the valid + // range. + + cll->max_content_light_level = av_clip_uintp2(clm->MaxCLL, 16); + cll->max_pic_average_light_level = av_clip_uintp2(clm->MaxFALL, 16); +} diff --git a/libavcodec/cbs_h265.h b/libavcodec/cbs_h265.h index c14cd4cd66..999353f607 100644 --- a/libavcodec/cbs_h265.h +++ b/libavcodec/cbs_h265.h @@ -747,4 +747,22 @@ typedef struct CodedBitstreamH265Context { } CodedBitstreamH265Context; +struct AVMasteringDisplayMetadata; +struct AVContentLightMetadata; + +/** + * Fill an SEI Mastering Display Colour Volume structure with values derived + * from the AVMasteringDisplayMetadata side-data structure. + */ +void ff_cbs_h265_fill_sei_mastering_display(H265RawSEIMasteringDisplayColourVolume *mdcv, + const struct AVMasteringDisplayMetadata *mdm); + +/** + * Fill an SEI Content Light Level Info structure with values derived from + * the AVContentLightMetadata side-data structure. + */ +void ff_cbs_h265_fill_sei_content_light_level(H265RawSEIContentLightLevelInfo *cll, + const struct AVContentLightMetadata *clm); + + #endif /* AVCODEC_CBS_H265_H */ From patchwork Mon Jul 27 16:32:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 21305 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 2164044AF2C for ; Mon, 27 Jul 2020 19:36:20 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3ACE068B96D; Mon, 27 Jul 2020 19:33:12 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1A14568B940 for ; Mon, 27 Jul 2020 19:33:04 +0300 (EEST) Received: by mail-wm1-f65.google.com with SMTP id 184so15401262wmb.0 for ; Mon, 27 Jul 2020 09:33:04 -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=S6m0VRg/3VFP2B3/ycgcKCh6q9UEH3fat0oY9XTM6LE=; b=o8Q386jdss8CFkxnZ6joOX38a8ZGyQ8lxKIDOzdxlKWdEqXGMQYaXdf5OzI3BnGJT1 kvJ0jGGpzVHWTzAZMIpuVjrs73R563tmW3pbF0boglwuh0KN5+NXh6+WYKql9CsrU15y MIiGlGuVWPjxGq/CZ/lBklOWya3eOCj8XPGAKcPPdEW359yWhTX7gwGz5nBISZRlJt04 5swZpWyl9t8Suji3cWmHyF49X0I47Hcwuikaf46re3kSjuWp4ZiPVkYJR4+QnGk+gLv4 sgSrRHg6fq21uLqE8l1iSw0N5+Rj3GLYgSQl6gH3L73qoHBtK6J60gLFkMBs8d8tuLo7 SWxw== 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=S6m0VRg/3VFP2B3/ycgcKCh6q9UEH3fat0oY9XTM6LE=; b=S2cEBzv93WtcwWOMLsVNmjGq4FgYf4T20QnyfuvwsYAclDVVyoT8Pqx0MKHqf9/ATy Polq+3/K3/3uD5FtdoXv12VcqWJBIzEf4VC8K1o+P5ZY3HkjIfSKwmxNuHx/oQMG25+t JldcqX759uj2QrJMVQlW2b3uS+N2VK3ZwyD+gtsSrYh2QeNxHs+J+dMU5S24Y6am2e09 VGuAXoHW7VwTL+W8ZFJpbmYJ+NUq+YXHNiq/YhDRaKs9lU3ltdCvJjvizxSrgJw81YGd vMvAAGByeZFDai1/ClIdpg0up2lObWHBzmgWBFAR5OIBnzcXA+Wwf85702p1ps1iQ4O7 G+EQ== X-Gm-Message-State: AOAM530hQF3lin19eBdMW394/nLyAfoQ2npaZuG5LP2SZqN80WAuAWtN nWlBGyRtmjj8yAzehELfLdIeFvGoCoE= X-Google-Smtp-Source: ABdhPJyDisTKrVMWRJ7Z31d1i9P2vTfk9YI5omrn6uAEjs+wNuiVVg1k5LiNW9fgUPDR7jpamiTryA== X-Received: by 2002:a7b:cb51:: with SMTP id v17mr125761wmj.146.1595867583324; Mon, 27 Jul 2020 09:33:03 -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 w16sm14706791wrg.95.2020.07.27.09.33.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2020 09:33:02 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Mon, 27 Jul 2020 17:32:35 +0100 Message-Id: <20200727163237.23371-21-sw@jkqxz.net> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727163237.23371-1-sw@jkqxz.net> References: <20200727163237.23371-1-sw@jkqxz.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 20/22] vaapi_encode_h265: Use common handling for HDR metadata 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" --- libavcodec/vaapi_encode_h265.c | 45 +++++----------------------------- 1 file changed, 6 insertions(+), 39 deletions(-) diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c index 90fea83388..f996f78f8e 100644 --- a/libavcodec/vaapi_encode_h265.c +++ b/libavcodec/vaapi_encode_h265.c @@ -768,39 +768,10 @@ static int vaapi_encode_h265_init_picture_params(AVCodecContext *avctx, AVMasteringDisplayMetadata *mdm = (AVMasteringDisplayMetadata *)sd->data; - // SEI is needed when both the primaries and luminance are set + // Only needed when both primaries and luminance are set. if (mdm->has_primaries && mdm->has_luminance) { - H265RawSEIMasteringDisplayColourVolume *mdcv = - &priv->sei_mastering_display; - const int mapping[3] = {1, 2, 0}; - const int chroma_den = 50000; - const int luma_den = 10000; - - for (i = 0; i < 3; i++) { - const int j = mapping[i]; - mdcv->display_primaries_x[i] = - FFMIN(lrint(chroma_den * - av_q2d(mdm->display_primaries[j][0])), - chroma_den); - mdcv->display_primaries_y[i] = - FFMIN(lrint(chroma_den * - av_q2d(mdm->display_primaries[j][1])), - chroma_den); - } - - mdcv->white_point_x = - FFMIN(lrint(chroma_den * av_q2d(mdm->white_point[0])), - chroma_den); - mdcv->white_point_y = - FFMIN(lrint(chroma_den * av_q2d(mdm->white_point[1])), - chroma_den); - - mdcv->max_display_mastering_luminance = - lrint(luma_den * av_q2d(mdm->max_luminance)); - mdcv->min_display_mastering_luminance = - FFMIN(lrint(luma_den * av_q2d(mdm->min_luminance)), - mdcv->max_display_mastering_luminance); - + ff_cbs_h265_fill_sei_mastering_display( + &priv->sei_mastering_display, mdm); priv->sei_needed |= SEI_MASTERING_DISPLAY; } } @@ -813,13 +784,9 @@ static int vaapi_encode_h265_init_picture_params(AVCodecContext *avctx, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL); if (sd) { - AVContentLightMetadata *clm = - (AVContentLightMetadata *)sd->data; - H265RawSEIContentLightLevelInfo *clli = - &priv->sei_content_light_level; - - clli->max_content_light_level = FFMIN(clm->MaxCLL, 65535); - clli->max_pic_average_light_level = FFMIN(clm->MaxFALL, 65535); + ff_cbs_h265_fill_sei_content_light_level( + &priv->sei_content_light_level, + (const AVContentLightMetadata*)sd->data); priv->sei_needed |= SEI_CONTENT_LIGHT_LEVEL; } From patchwork Mon Jul 27 16:32:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 21306 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 2363D44AF2C for ; Mon, 27 Jul 2020 19:36:30 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1E1FE68B967; Mon, 27 Jul 2020 19:33:13 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D1D5568B93A for ; Mon, 27 Jul 2020 19:33:05 +0300 (EEST) Received: by mail-wm1-f68.google.com with SMTP id k8so5079711wma.2 for ; Mon, 27 Jul 2020 09:33:05 -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=BsylxChDhbw46Boc6z1+aZQkbAo5N7tJ7uwzRWKPGqc=; b=11O5oF150lYAFrfKebhFw0GFoP/DNDEsnDBPC7e5gv4PVzlW27k7jv5zITBaVIuCrZ YycGD0igBUFWA2oSdG1zVeRf4UlTNyddc36UevZgISx+kVLD/6xYeTSXGApmRdUJ4vIA 2qRrrahrHxWv5WusUjLeDlUTSh7SBIIaACqBjHa2lTG6+YsDDy5wA8PIi6z0JywRm4c6 i/HnAAxIhX4FVS6D0daPAEuMf8hf38ex6AqJbRGLJpN6YoElJ24txutPgPAHvJu2q2KB vfhTNm/BMnJrZaSp/YVws2ORViT6GDz28L/a5LbwLAHNkeGnCKF0qIwrchgIieOmx0Gw kIow== 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=BsylxChDhbw46Boc6z1+aZQkbAo5N7tJ7uwzRWKPGqc=; b=HPkF2kd9uWohFzqt9uTVAzipAR0rTNJ6cpVCFxR+maZXg9axGp1FN2VVTX/oNmHPBP YAvMw7kQSzjazO0eqRc84RevZ7b9Nbuzd4XQbqSifaZtJI9p/yZIiw5Ra5GuzNrvsEQ8 jrJCGUY8tQJ0L+lxdS077XkqZJk5gZjRidiLs00r50B1h+YpQJ/2pBoWq1R59RLM0jPp XahSoNWwOK4IAo2iiFH33JuGcENokb/u4DJs3/Z4vH9t/EiudvqzrVJ0sK/ZVuOFfPsp c1wu1bgxZiA9uk7AhxzrID4wGJWtdmP6Jr+g9/ZW5QxPnsOcSssjZlrh5TY8lSG5J2S+ QZTA== X-Gm-Message-State: AOAM532mFNnFDUET9ZqT1TIfR4lrgyXilmjHk0rGrpmsHC5PC77dnuRM w4GgGhWFu/03IOtI/X8wx/I1FTR7kzk= X-Google-Smtp-Source: ABdhPJwyXMTCC2h/WvhJXALBApOt/4qj/ctZGJSRekguzXiJqzLG5E7uc2CZmNrnI/UQddcTsH0s8A== X-Received: by 2002:a7b:cf2b:: with SMTP id m11mr132168wmg.110.1595867584340; Mon, 27 Jul 2020 09:33:04 -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 w16sm14706791wrg.95.2020.07.27.09.33.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2020 09:33:03 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Mon, 27 Jul 2020 17:32:36 +0100 Message-Id: <20200727163237.23371-22-sw@jkqxz.net> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727163237.23371-1-sw@jkqxz.net> References: <20200727163237.23371-1-sw@jkqxz.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 21/22] h264_metadata_bsf: Refactor the filter function into smaller parts 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" --- libavcodec/h264_metadata_bsf.c | 443 ++++++++++++++++++--------------- 1 file changed, 242 insertions(+), 201 deletions(-) diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c index eb1503159b..1d00ccdfb8 100644 --- a/libavcodec/h264_metadata_bsf.c +++ b/libavcodec/h264_metadata_bsf.c @@ -56,6 +56,7 @@ typedef struct H264MetadataContext { int done_first_au; int aud; + H264RawAUD aud_nal; AVRational sample_aspect_ratio; @@ -78,6 +79,7 @@ typedef struct H264MetadataContext { int crop_bottom; const char *sei_user_data; + H264RawSEIPayload sei_user_data_payload; int delete_filler; @@ -89,6 +91,59 @@ typedef struct H264MetadataContext { } H264MetadataContext; +static int h264_metadata_insert_aud(AVBSFContext *bsf, + CodedBitstreamFragment *au) +{ + H264MetadataContext *ctx = bsf->priv_data; + int primary_pic_type_mask = 0xff; + int err, i, j; + + static const int primary_pic_type_table[] = { + 0x084, // 2, 7 + 0x0a5, // 0, 2, 5, 7 + 0x0e7, // 0, 1, 2, 5, 6, 7 + 0x210, // 4, 9 + 0x318, // 3, 4, 8, 9 + 0x294, // 2, 4, 7, 9 + 0x3bd, // 0, 2, 3, 4, 5, 7, 8, 9 + 0x3ff, // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 + }; + + for (i = 0; i < au->nb_units; i++) { + if (au->units[i].type == H264_NAL_SLICE || + au->units[i].type == H264_NAL_IDR_SLICE) { + H264RawSlice *slice = au->units[i].content; + for (j = 0; j < FF_ARRAY_ELEMS(primary_pic_type_table); j++) { + if (!(primary_pic_type_table[j] & + (1 << slice->header.slice_type))) + primary_pic_type_mask &= ~(1 << j); + } + } + } + for (j = 0; j < FF_ARRAY_ELEMS(primary_pic_type_table); j++) + if (primary_pic_type_mask & (1 << j)) + break; + if (j >= FF_ARRAY_ELEMS(primary_pic_type_table)) { + av_log(bsf, AV_LOG_ERROR, "No usable primary_pic_type: " + "invalid slice types?\n"); + return AVERROR_INVALIDDATA; + } + + ctx->aud_nal = (H264RawAUD) { + .nal_unit_header.nal_unit_type = H264_NAL_AUD, + .primary_pic_type = j, + }; + + err = ff_cbs_insert_unit_content(au, 0, H264_NAL_AUD, + &ctx->aud_nal, NULL); + if (err < 0) { + av_log(bsf, AV_LOG_ERROR, "Failed to insert AUD.\n"); + return err; + } + + return 0; +} + static int h264_metadata_update_sps(AVBSFContext *bsf, H264RawSPS *sps) { @@ -320,219 +375,59 @@ static int h264_metadata_update_side_data(AVBSFContext *bsf, AVPacket *pkt) return 0; } -static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *pkt) +static int h264_metadata_handle_display_orientation(AVBSFContext *bsf, + AVPacket *pkt, + CodedBitstreamFragment *au, + int seek_point) { H264MetadataContext *ctx = bsf->priv_data; - CodedBitstreamFragment *au = &ctx->access_unit; - int err, i, j, has_sps; - H264RawAUD aud; - - err = ff_bsf_get_packet_ref(bsf, pkt); - if (err < 0) - return err; - - err = h264_metadata_update_side_data(bsf, pkt); - if (err < 0) - goto fail; - - err = ff_cbs_read_packet(ctx->input, au, pkt); - if (err < 0) { - av_log(bsf, AV_LOG_ERROR, "Failed to read packet.\n"); - goto fail; - } - - if (au->nb_units == 0) { - av_log(bsf, AV_LOG_ERROR, "No NAL units in packet.\n"); - err = AVERROR_INVALIDDATA; - goto fail; - } - - // If an AUD is present, it must be the first NAL unit. - if (au->units[0].type == H264_NAL_AUD) { - if (ctx->aud == REMOVE) - ff_cbs_delete_unit(au, 0); - } else { - if (ctx->aud == INSERT) { - static const int primary_pic_type_table[] = { - 0x084, // 2, 7 - 0x0a5, // 0, 2, 5, 7 - 0x0e7, // 0, 1, 2, 5, 6, 7 - 0x210, // 4, 9 - 0x318, // 3, 4, 8, 9 - 0x294, // 2, 4, 7, 9 - 0x3bd, // 0, 2, 3, 4, 5, 7, 8, 9 - 0x3ff, // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 - }; - int primary_pic_type_mask = 0xff; - - for (i = 0; i < au->nb_units; i++) { - if (au->units[i].type == H264_NAL_SLICE || - au->units[i].type == H264_NAL_IDR_SLICE) { - H264RawSlice *slice = au->units[i].content; - for (j = 0; j < FF_ARRAY_ELEMS(primary_pic_type_table); j++) { - if (!(primary_pic_type_table[j] & - (1 << slice->header.slice_type))) - primary_pic_type_mask &= ~(1 << j); - } - } - } - for (j = 0; j < FF_ARRAY_ELEMS(primary_pic_type_table); j++) - if (primary_pic_type_mask & (1 << j)) - break; - if (j >= FF_ARRAY_ELEMS(primary_pic_type_table)) { - av_log(bsf, AV_LOG_ERROR, "No usable primary_pic_type: " - "invalid slice types?\n"); - err = AVERROR_INVALIDDATA; - goto fail; - } - - aud = (H264RawAUD) { - .nal_unit_header.nal_unit_type = H264_NAL_AUD, - .primary_pic_type = j, - }; + int err, i, j; - err = ff_cbs_insert_unit_content(au, - 0, H264_NAL_AUD, &aud, NULL); - if (err < 0) { - av_log(bsf, AV_LOG_ERROR, "Failed to insert AUD.\n"); - goto fail; - } - } - } - - has_sps = 0; - for (i = 0; i < au->nb_units; i++) { - if (au->units[i].type == H264_NAL_SPS) { - err = h264_metadata_update_sps(bsf, au->units[i].content); - if (err < 0) - goto fail; - has_sps = 1; - } - } + for (i = au->nb_units - 1; i >= 0; i--) { + H264RawSEI *sei; + if (au->units[i].type != H264_NAL_SEI) + continue; + sei = au->units[i].content; - // Only insert the SEI in access units containing SPSs, and also - // unconditionally in the first access unit we ever see. - if (ctx->sei_user_data && (has_sps || !ctx->done_first_au)) { - H264RawSEIPayload payload = { - .payload_type = H264_SEI_TYPE_USER_DATA_UNREGISTERED, - }; - H264RawSEIUserDataUnregistered *udu = - &payload.payload.user_data_unregistered; + for (j = sei->payload_count - 1; j >= 0; j--) { + H264RawSEIDisplayOrientation *disp; + int32_t *matrix; - for (i = j = 0; j < 32 && ctx->sei_user_data[i]; i++) { - int c, v; - c = ctx->sei_user_data[i]; - if (c == '-') { + if (sei->payload[j].payload_type != + H264_SEI_TYPE_DISPLAY_ORIENTATION) continue; - } else if (av_isxdigit(c)) { - c = av_tolower(c); - v = (c <= '9' ? c - '0' : c - 'a' + 10); - } else { - goto invalid_user_data; - } - if (j & 1) - udu->uuid_iso_iec_11578[j / 2] |= v; - else - udu->uuid_iso_iec_11578[j / 2] = v << 4; - ++j; - } - if (j == 32 && ctx->sei_user_data[i] == '+') { - size_t len = strlen(ctx->sei_user_data + i + 1); - - udu->data_ref = av_buffer_alloc(len + 1); - if (!udu->data_ref) { - err = AVERROR(ENOMEM); - goto fail; - } - - udu->data = udu->data_ref->data; - udu->data_length = len + 1; - memcpy(udu->data, ctx->sei_user_data + i + 1, len + 1); + disp = &sei->payload[j].payload.display_orientation; - err = ff_cbs_h264_add_sei_message(au, &payload); - if (err < 0) { - av_log(bsf, AV_LOG_ERROR, "Failed to add user data SEI " - "message to access unit.\n"); - goto fail; - } - - } else { - invalid_user_data: - av_log(bsf, AV_LOG_ERROR, "Invalid user data: " - "must be \"UUID+string\".\n"); - err = AVERROR(EINVAL); - goto fail; - } - } - - if (ctx->delete_filler) { - for (i = au->nb_units - 1; i >= 0; i--) { - if (au->units[i].type == H264_NAL_FILLER_DATA) { - ff_cbs_delete_unit(au, i); + if (ctx->display_orientation == REMOVE || + ctx->display_orientation == INSERT) { + ff_cbs_h264_delete_sei_message(au, &au->units[i], j); continue; } - if (au->units[i].type == H264_NAL_SEI) { - // Filler SEI messages. - H264RawSEI *sei = au->units[i].content; - - for (j = sei->payload_count - 1; j >= 0; j--) { - if (sei->payload[j].payload_type == - H264_SEI_TYPE_FILLER_PAYLOAD) - ff_cbs_h264_delete_sei_message(au, &au->units[i], j); - } + matrix = av_malloc(9 * sizeof(int32_t)); + if (!matrix) + return AVERROR(ENOMEM); + + av_display_rotation_set(matrix, + disp->anticlockwise_rotation * + 180.0 / 65536.0); + av_display_matrix_flip(matrix, disp->hor_flip, disp->ver_flip); + + // If there are multiple display orientation messages in an + // access unit, then the last one added to the packet (i.e. + // the first one in the access unit) will prevail. + err = av_packet_add_side_data(pkt, AV_PKT_DATA_DISPLAYMATRIX, + (uint8_t*)matrix, + 9 * sizeof(int32_t)); + if (err < 0) { + av_log(bsf, AV_LOG_ERROR, "Failed to attach extracted " + "displaymatrix side data to packet.\n"); + av_free(matrix); + return AVERROR(ENOMEM); } } } - if (ctx->display_orientation != PASS) { - for (i = au->nb_units - 1; i >= 0; i--) { - H264RawSEI *sei; - if (au->units[i].type != H264_NAL_SEI) - continue; - sei = au->units[i].content; - - for (j = sei->payload_count - 1; j >= 0; j--) { - H264RawSEIDisplayOrientation *disp; - int32_t *matrix; - - if (sei->payload[j].payload_type != - H264_SEI_TYPE_DISPLAY_ORIENTATION) - continue; - disp = &sei->payload[j].payload.display_orientation; - - if (ctx->display_orientation == REMOVE || - ctx->display_orientation == INSERT) { - ff_cbs_h264_delete_sei_message(au, &au->units[i], j); - continue; - } - - matrix = av_malloc(9 * sizeof(int32_t)); - if (!matrix) { - err = AVERROR(ENOMEM); - goto fail; - } - - av_display_rotation_set(matrix, - disp->anticlockwise_rotation * - 180.0 / 65536.0); - av_display_matrix_flip(matrix, disp->hor_flip, disp->ver_flip); - - // If there are multiple display orientation messages in an - // access unit, then the last one added to the packet (i.e. - // the first one in the access unit) will prevail. - err = av_packet_add_side_data(pkt, AV_PKT_DATA_DISPLAYMATRIX, - (uint8_t*)matrix, - 9 * sizeof(int32_t)); - if (err < 0) { - av_log(bsf, AV_LOG_ERROR, "Failed to attach extracted " - "displaymatrix side data to packet.\n"); - av_free(matrix); - goto fail; - } - } - } - } if (ctx->display_orientation == INSERT) { H264RawSEIPayload payload = { .payload_type = H264_SEI_TYPE_DISPLAY_ORIENTATION, @@ -576,7 +471,7 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *pkt) } } - if (has_sps || !ctx->done_first_au) { + if (seek_point) { if (!isnan(ctx->rotate)) { disp->anticlockwise_rotation = (uint16_t)rint((ctx->rotate >= 0.0 ? ctx->rotate @@ -598,11 +493,107 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *pkt) if (err < 0) { av_log(bsf, AV_LOG_ERROR, "Failed to add display orientation " "SEI message to access unit.\n"); + return err; + } + } + } + + return 0; +} + +static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *pkt) +{ + H264MetadataContext *ctx = bsf->priv_data; + CodedBitstreamFragment *au = &ctx->access_unit; + int err, i, j, has_sps, seek_point; + + err = ff_bsf_get_packet_ref(bsf, pkt); + if (err < 0) + return err; + + err = h264_metadata_update_side_data(bsf, pkt); + if (err < 0) + goto fail; + + err = ff_cbs_read_packet(ctx->input, au, pkt); + if (err < 0) { + av_log(bsf, AV_LOG_ERROR, "Failed to read packet.\n"); + goto fail; + } + + if (au->nb_units == 0) { + av_log(bsf, AV_LOG_ERROR, "No NAL units in packet.\n"); + err = AVERROR_INVALIDDATA; + goto fail; + } + + // If an AUD is present, it must be the first NAL unit. + if (au->units[0].type == H264_NAL_AUD) { + if (ctx->aud == REMOVE) + ff_cbs_delete_unit(au, 0); + } else { + if (ctx->aud == INSERT) { + err = h264_metadata_insert_aud(bsf, au); + if (err < 0) goto fail; + } + } + + has_sps = 0; + for (i = 0; i < au->nb_units; i++) { + if (au->units[i].type == H264_NAL_SPS) { + err = h264_metadata_update_sps(bsf, au->units[i].content); + if (err < 0) + goto fail; + has_sps = 1; + } + } + + // The current packet should be treated as a seek point for metadata + // insertion if any of: + // - It is the first packet in the stream. + // - It contains an SPS, indicating that a sequence might start here. + // - It is marked as containing a key frame. + seek_point = !ctx->done_first_au || has_sps || + (pkt->flags & AV_PKT_FLAG_KEY); + + if (ctx->sei_user_data && seek_point) { + err = ff_cbs_h264_add_sei_message(au, &ctx->sei_user_data_payload); + if (err < 0) { + av_log(bsf, AV_LOG_ERROR, "Failed to add user data SEI " + "message to access unit.\n"); + goto fail; + } + } + + if (ctx->delete_filler) { + for (i = au->nb_units - 1; i >= 0; i--) { + if (au->units[i].type == H264_NAL_FILLER_DATA) { + ff_cbs_delete_unit(au, i); + continue; + } + + if (au->units[i].type == H264_NAL_SEI) { + // Filler SEI messages. + H264RawSEI *sei = au->units[i].content; + + for (j = sei->payload_count - 1; j >= 0; j--) { + if (sei->payload[j].payload_type == + H264_SEI_TYPE_FILLER_PAYLOAD) + ff_cbs_h264_delete_sei_message(au, + &au->units[i], j); + } } } } + if (ctx->display_orientation != PASS) { + err = h264_metadata_handle_display_orientation(bsf, pkt, au, + seek_point); + if (err < 0) + goto fail; + } + err = ff_cbs_write_packet(ctx->output, pkt, au); if (err < 0) { av_log(bsf, AV_LOG_ERROR, "Failed to write packet.\n"); @@ -625,7 +616,57 @@ static int h264_metadata_init(AVBSFContext *bsf) { H264MetadataContext *ctx = bsf->priv_data; CodedBitstreamFragment *au = &ctx->access_unit; - int err, i; + int err, i, j; + + if (ctx->sei_user_data) { + H264RawSEIUserDataUnregistered *udu; + int c, v; + size_t len; + + ctx->sei_user_data_payload = (H264RawSEIPayload) { + .payload_type = H264_SEI_TYPE_USER_DATA_UNREGISTERED, + }; + udu = &ctx->sei_user_data_payload.payload.user_data_unregistered; + + // Parse UUID. It must be a hex string of length 32, possibly + // containing '-'s which we ignore. + for (i = j = 0; j < 32 && ctx->sei_user_data[i]; i++) { + c = ctx->sei_user_data[i]; + if (c == '-') { + continue; + } else if (av_isxdigit(c)) { + c = av_tolower(c); + v = (c <= '9' ? c - '0' : c - 'a' + 10); + } else { + break; + } + if (j & 1) + udu->uuid_iso_iec_11578[j / 2] |= v; + else + udu->uuid_iso_iec_11578[j / 2] = v << 4; + ++j; + } + if (j < 32 || ctx->sei_user_data[i] != '+') { + av_log(bsf, AV_LOG_ERROR, "Invalid user data: " + "must be of the form \"UUID+string\".\n"); + return AVERROR(EINVAL); + } else { + // Skip over the '+'. + ++i; + + // Length of the actual data to insert (could be zero). + len = strlen(ctx->sei_user_data + i); + + udu->data_ref = av_buffer_alloc(len + 1); + if (!udu->data_ref) + return AVERROR(ENOMEM); + + udu->data_length = len + 1; + udu->data = udu->data_ref->data; + memcpy(udu->data, ctx->sei_user_data + 1, len); + udu->data[len] = 0; + } + } err = ff_cbs_init(&ctx->input, AV_CODEC_ID_H264, bsf); if (err < 0) From patchwork Mon Jul 27 16:32:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 21307 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 7C5F444AF2C for ; Mon, 27 Jul 2020 19:36:40 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C548C68B944; Mon, 27 Jul 2020 19:33:13 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E5E0968B94F for ; Mon, 27 Jul 2020 19:33:05 +0300 (EEST) Received: by mail-wm1-f65.google.com with SMTP id 184so15401360wmb.0 for ; Mon, 27 Jul 2020 09:33:05 -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=N/+ZycHUlam0nrlXCmiS0T86tkyZim1/W80+zjnNU8A=; b=qw2rkQyqE1dkriArJah3gR/rdR2DdiLYA2WbpqmxGgeKMw5hjTCgODgdaO4n7MDara 5IQqsPl695LdQ5HBifUaxuohJ8cjmlXY9NlyKzaBynvTCD8f80zWTBmgs1xATR6dnlKW 5H3CU9w9xGw7OhrR3qXq/8PElgTObsSmft1SSrfgyy0UB/q9Zl/GcgMnBIPivqB1tcCH jYGrUsb3holSbzdAkzULoPHOeYt5scyv+Bh3JQ/Ad+78ML7uB4dnGVXPkUrGMHQjh2qj GZGj+kf1yLjBqH7b1VD5bHtOzb+5kg1/3+07cohTFuiK3Nzrqk4FrhWEqquqYGudj96+ yAEA== 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=N/+ZycHUlam0nrlXCmiS0T86tkyZim1/W80+zjnNU8A=; b=cII/DEtCrzoWuKzKyzvvvzvwKD7B0oeAF+AT8NLxCfZuHIO3G5v9De91en2Sde3eO/ w2GgPoPjv974NJbnh8al1qN2LvJczrWHUF0+bsQR16qKWF4Vdovq/3udFsf0I6NngLG7 O5/hAIQtwBKkWBCJTVBzuUHgFmaQ+EwRnhTS8F2Z34F1jFFd/SFDdSyvxaRoTfbeWrM1 BidXx+ARZbKVgg/aZ9TM7FFCPxPSSIbYxma26jyAhkYbVHl2s6MhheOxFuNEH8wb5rxG Y+P+0hxjGRkWOWqpPmSvXxwBhwx4bT9tKEz8sKpjtNNsuWiA4UdNkhgkujLisqqFWaDE /VgA== X-Gm-Message-State: AOAM530P1odIHSu2cT+E9/UzXR316hXbsvvLJknLXw8X62H6CHsGcE+p eZs8+oYP5O4uMEqYunMAs9M5ZsqjnYU= X-Google-Smtp-Source: ABdhPJxMQiSlZt1xhBXlgcnuqwy9aQJEMrgQ4L9Z0vK0PAdOL6T32hQ5d5/BdJKrAk5w6m7dhaHLtA== X-Received: by 2002:a1c:2547:: with SMTP id l68mr86894wml.181.1595867585119; Mon, 27 Jul 2020 09:33:05 -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 w16sm14706791wrg.95.2020.07.27.09.33.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2020 09:33:04 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Mon, 27 Jul 2020 17:32:37 +0100 Message-Id: <20200727163237.23371-23-sw@jkqxz.net> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727163237.23371-1-sw@jkqxz.net> References: <20200727163237.23371-1-sw@jkqxz.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 22/22] h264_metadata_bsf: Improve interpretation of input display matrices 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" The previous code here only worked in more limited cases. --- libavcodec/h264_metadata_bsf.c | 42 +++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c index 1d00ccdfb8..38c9e7f6f5 100644 --- a/libavcodec/h264_metadata_bsf.c +++ b/libavcodec/h264_metadata_bsf.c @@ -441,23 +441,39 @@ static int h264_metadata_handle_display_orientation(AVBSFContext *bsf, data = av_packet_get_side_data(pkt, AV_PKT_DATA_DISPLAYMATRIX, &size); if (data && size >= 9 * sizeof(int32_t)) { int32_t matrix[9]; + double dmatrix[9]; int hflip, vflip; - double angle; + double scale_x, scale_y, angle; memcpy(matrix, data, sizeof(matrix)); - hflip = vflip = 0; - if (matrix[0] < 0 && matrix[4] > 0) - hflip = 1; - else if (matrix[0] > 0 && matrix[4] < 0) - vflip = 1; - av_display_matrix_flip(matrix, hflip, vflip); + for (i = 0; i < 9; i++) + dmatrix[i] = matrix[i] / 65536.0; + + // Extract scale factors. + scale_x = hypot(dmatrix[0], dmatrix[3]); + scale_y = hypot(dmatrix[1], dmatrix[4]); + + // Select flips to make the main diagonal positive. + hflip = dmatrix[0] < 0.0; + vflip = dmatrix[4] < 0.0; + if (hflip) + scale_x = -scale_x; + if (vflip) + scale_y = -scale_y; + + // Rescale. + for (i = 0; i < 9; i += 3) { + dmatrix[i] /= scale_x; + dmatrix[i + 1] /= scale_y; + } - angle = av_display_rotation_get(matrix); + // Extract rotation. + angle = atan2(dmatrix[3], dmatrix[0]); - if (!(angle >= -180.0 && angle <= 180.0 /* also excludes NaN */) || - matrix[2] != 0 || matrix[5] != 0 || - matrix[6] != 0 || matrix[7] != 0) { + if (!(angle >= -M_PI && angle <= M_PI) || + matrix[2] != 0.0 || matrix[5] != 0.0 || + matrix[6] != 0.0 || matrix[7] != 0.0) { av_log(bsf, AV_LOG_WARNING, "Input display matrix is not " "representable in H.264 parameters.\n"); } else { @@ -465,8 +481,8 @@ static int h264_metadata_handle_display_orientation(AVBSFContext *bsf, disp->ver_flip = vflip; disp->anticlockwise_rotation = (uint16_t)rint((angle >= 0.0 ? angle - : angle + 360.0) * - 65536.0 / 360.0); + : angle + 2 * M_PI) * + 32768.0 / M_PI); write = 1; } }