From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 7742B4A5A1 for ; Thu, 2 May 2024 15:06:12 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E5E7868D810; Thu, 2 May 2024 18:06:08 +0300 (EEST) Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8778D68D7EC for ; Thu, 2 May 2024 18:06:02 +0300 (EEST) Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-6f42924ca64so1348431b3a.2 for ; Thu, 02 May 2024 08:06:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714662360; x=1715267160; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=8GhCyBFH8jcyfM5ILe7AepJQtb6S24YMxZ0gi2y8Lv8=; b=YY5v96NJVerLgiag6Y90OAetCt0Bai08RTfGDBaaVnN3mOu+gsuOPp7dYvNkM2Yc23 qEtYiMNdIIiAqRGHugspp2qqyWhZeJUZ+Z0rmD5q5oqjeNnRQY/KlrAkX7zaBoa5zMH1 MqJVJ0XPSiT43GcS26OMRFVEIjSjZVE9ndGOzZxe0aryRc5kujmJFd2ryGpMsBaDMxCR pMNylDyK6iVJoj9KTcyK/1DpANaj/WFQh3E/J7n/8cjcr6716CNJC+RBjH80/Iy6xMSk WywGwlp6GjYWWMmDqQOd7gIiZlon1sxyAkxO8JYoK9/feSPUB3UHQgh6hMu4LtzH0zr6 w3CQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714662360; x=1715267160; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8GhCyBFH8jcyfM5ILe7AepJQtb6S24YMxZ0gi2y8Lv8=; b=IBzU7deGX99n1ZPQK9amEvILPNYncaYhBdxbHvqILr/OXCQ0Io4FZ68GAh1yuN8yls TdiSqQYZ+sUMCIHeQm0D7rshgktLeXdqdbKw4XKXLbPTmK6g1Z7VFTBgAhXBHuTjSBtG JlDhwwWlMaDCU7uUDQnQ/r1xZkLVjihFQvaCdChK4o0wlBEbh3OfHhElnMewTejuMAZQ 6Px+1F69+aCEEqDqLRAvL9tsbY/uV8bRx0v7FcNN5OiQGZkP9kNYH1afg54kaAc60qnu V47AxR/I7W3vJKRurmu/8ibafoXrFPYJXYUv4jq1RVvLbk8d2MbC9pys6/zNMwrapc+Q qxng== X-Gm-Message-State: AOJu0Yw0RQu+WQfWBJzWr9c1eyUJ0j5+wkmunbQmASgzUKYUOqmyw+Mk uqxpoQhQROtmNkNwRnOQAguNjIJLUFgRFr/aIucjXcfQ8U5XxZKzxDRQtA== X-Google-Smtp-Source: AGHT+IEug/6Z9k+uV8bDU0JgwPpEQ2TpdM2iHdEpE62mkgZ17sYG7utY00Je5H68Uod9SQOcj0dWlw== X-Received: by 2002:a05:6a00:2312:b0:6f3:ebb3:6bc3 with SMTP id h18-20020a056a00231200b006f3ebb36bc3mr7105477pfh.3.1714662359959; Thu, 02 May 2024 08:05:59 -0700 (PDT) Received: from localhost.localdomain ([190.194.167.233]) by smtp.gmail.com with ESMTPSA id j18-20020a056a00175200b006ecfb733248sm1378887pfc.13.2024.05.02.08.05.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 May 2024 08:05:59 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Thu, 2 May 2024 12:05:49 -0300 Message-ID: <20240502150549.1733-1-jamrial@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240430231926.2506728-1-michael@niedermayer.cc> References: <20240430231926.2506728-1-michael@niedermayer.cc> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avformat/framecrcenc: support calculating checksum of IAMF side data X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: The total allocated size for types is arch dependent, so instead calculate a checksum of the fields only. Signed-off-by: James Almer --- Depends on "[PATCH v3] avformat/framecrcenc: compute the checksum for side data" libavformat/framecrcenc.c | 76 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 71 insertions(+), 5 deletions(-) diff --git a/libavformat/framecrcenc.c b/libavformat/framecrcenc.c index 8cc4a93053..6d46b51489 100644 --- a/libavformat/framecrcenc.c +++ b/libavformat/framecrcenc.c @@ -24,6 +24,7 @@ #include "config.h" #include "libavutil/adler32.h" #include "libavutil/avstring.h" +#include "libavutil/iamf.h" #include "libavutil/intreadwrite.h" #include "libavcodec/codec_id.h" @@ -76,7 +77,8 @@ static int framecrc_write_packet(struct AVFormatContext *s, AVPacket *pkt) for (int i = 0; i < pkt->side_data_elems; i++) { const AVPacketSideData *const sd = &pkt->side_data[i]; const uint8_t *data = sd->data; - int64_t side_data_crc = 0; + size_t size = sd->size; + uint32_t side_data_crc = 0; switch (sd->type) { #if HAVE_BIGENDIAN @@ -127,12 +129,76 @@ static int framecrc_write_packet(struct AVFormatContext *s, AVPacket *pkt) case AV_PKT_DATA_IAMF_MIX_GAIN_PARAM: case AV_PKT_DATA_IAMF_DEMIXING_INFO_PARAM: case AV_PKT_DATA_IAMF_RECON_GAIN_INFO_PARAM: - side_data_crc = -1; + { + const AVIAMFParamDefinition *param = (AVIAMFParamDefinition *)sd->data; + uint8_t buf[8]; + ptrdiff_t offset = 0; + size = 0; +#define READ_UINT32(struct, parent, child) do { \ + if ((offset + offsetof(struct, child) + sizeof(parent->child)) > sd->size) \ + goto iamf_end; \ + AV_WL32(buf, parent->child); \ + side_data_crc = av_adler32_update(side_data_crc, buf, 4); \ + size += 4; \ +} while (0) +#define READ_RATIONAL(struct, parent, child) do { \ + if ((offset + offsetof(struct, child) + sizeof(parent->child)) > sd->size) \ + goto iamf_end; \ + AV_WL32(buf + 0, parent->child.num); \ + AV_WL32(buf + 4, parent->child.den); \ + side_data_crc = av_adler32_update(side_data_crc, buf, 8); \ + size += 8; \ +} while (0) + READ_UINT32(AVIAMFParamDefinition, param, nb_subblocks); + READ_UINT32(AVIAMFParamDefinition, param, type); + READ_UINT32(AVIAMFParamDefinition, param, parameter_id); + READ_UINT32(AVIAMFParamDefinition, param, parameter_rate); + READ_UINT32(AVIAMFParamDefinition, param, duration); + READ_UINT32(AVIAMFParamDefinition, param, constant_subblock_duration); + for (unsigned int i = 0; i < param->nb_subblocks; i++) { + void *subblock = av_iamf_param_definition_get_subblock(param, i); + + offset = (intptr_t)subblock - (intptr_t)sd->data; + switch (param->type) { + case AV_IAMF_PARAMETER_DEFINITION_MIX_GAIN: { + const AVIAMFMixGain *mix = subblock; + READ_UINT32(AVIAMFMixGain, mix, subblock_duration); + READ_UINT32(AVIAMFMixGain, mix, animation_type); + READ_RATIONAL(AVIAMFMixGain, mix, start_point_value); + READ_RATIONAL(AVIAMFMixGain, mix, end_point_value); + READ_RATIONAL(AVIAMFMixGain, mix, control_point_value); + READ_RATIONAL(AVIAMFMixGain, mix, control_point_relative_time); + break; + } + case AV_IAMF_PARAMETER_DEFINITION_DEMIXING: { + const AVIAMFDemixingInfo *demix = subblock; + READ_UINT32(AVIAMFDemixingInfo, demix, subblock_duration); + READ_UINT32(AVIAMFDemixingInfo, demix, dmixp_mode); + break; + } + case AV_IAMF_PARAMETER_DEFINITION_RECON_GAIN: { + const AVIAMFReconGain *recon = subblock; + READ_UINT32(AVIAMFReconGain, recon, subblock_duration); + if ((offset + offsetof(AVIAMFReconGain, recon_gain) + + sizeof(recon->recon_gain)) > sd->size) + goto iamf_end; + side_data_crc = av_adler32_update(side_data_crc, + (uint8_t *)recon->recon_gain, + sizeof(recon->recon_gain)); + size += sizeof(recon->recon_gain); + break; + } + default: + break; + } + } + iamf_end: + break; + } } - av_strlcatf(buf, sizeof(buf), ", T=%2d, %8"SIZE_SPECIFIER, pkt->side_data[i].type, pkt->side_data[i].size); - if (side_data_crc >= 0) - av_strlcatf(buf, sizeof(buf), ", 0x%08"PRIx32, (uint32_t)side_data_crc); + av_strlcatf(buf, sizeof(buf), ", T=%2d, %8"SIZE_SPECIFIER, pkt->side_data[i].type, size); + av_strlcatf(buf, sizeof(buf), ", 0x%08"PRIx32, side_data_crc); } } av_strlcatf(buf, sizeof(buf), "\n"); -- 2.44.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".