From: James Almer <jamrial@gmail.com> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH] avformat/framecrcenc: support calculating checksum of IAMF side data Date: Thu, 2 May 2024 12:05:49 -0300 Message-ID: <20240502150549.1733-1-jamrial@gmail.com> (raw) In-Reply-To: <20240430231926.2506728-1-michael@niedermayer.cc> The total allocated size for types is arch dependent, so instead calculate a checksum of the fields only. Signed-off-by: James Almer <jamrial@gmail.com> --- 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".
next prev parent reply other threads:[~2024-05-02 15:06 UTC|newest] Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-04-30 23:19 [FFmpeg-devel] [PATCH v3] avformat/framecrcenc: compute the checksum for " Michael Niedermayer 2024-05-02 15:05 ` James Almer [this message] 2024-05-02 15:16 ` [FFmpeg-devel] [PATCH] avformat/framecrcenc: support calculating checksum of IAMF " Andreas Rheinhardt 2024-05-02 18:33 ` James Almer 2024-05-02 21:23 ` [FFmpeg-devel] [PATCH v3] avformat/framecrcenc: compute the checksum for " Marton Balint 2024-05-02 21:29 ` James Almer 2024-05-04 8:34 ` Marton Balint 2024-05-04 15:16 ` James Almer 2024-05-04 17:17 ` Marton Balint 2024-05-04 20:58 ` Michael Niedermayer 2024-05-04 21:02 ` James Almer 2024-05-05 1:45 ` Michael Niedermayer 2024-05-05 1:54 ` James Almer 2024-05-06 1:34 ` Michael Niedermayer 2024-05-02 23:27 ` Michael Niedermayer
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20240502150549.1733-1-jamrial@gmail.com \ --to=jamrial@gmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git