From: James Almer <jamrial@gmail.com> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 4/4] avformat/iamf: byteswap values in OpusHeader Date: Tue, 16 Jul 2024 22:49:25 -0300 Message-ID: <20240717014925.16517-4-jamrial@gmail.com> (raw) In-Reply-To: <20240717014925.16517-1-jamrial@gmail.com> Clause 3.11.1 of IAMF[1] states the values are stored in big endian, in contrast to the Ogg Encapsulation for Opus[2] where they are in little endian. [1]https://aomediacodec.github.io/iamf/v1.0.0-errata.html#opus-specific [2]https://datatracker.ietf.org/doc/html/rfc7845#section-5.1 Signed-off-by: James Almer <jamrial@gmail.com> --- libavformat/iamf_parse.c | 3 +++ libavformat/iamf_writer.c | 8 ++++++-- tests/ref/fate/iamf-5_1-copy | 8 ++++---- tests/ref/fate/iamf-5_1-demux | 8 ++++---- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/libavformat/iamf_parse.c b/libavformat/iamf_parse.c index 2674a5186d..8e9c48568f 100644 --- a/libavformat/iamf_parse.c +++ b/libavformat/iamf_parse.c @@ -272,6 +272,9 @@ static int update_extradata(AVCodecParameters *codecpar) switch(codecpar->codec_id) { case AV_CODEC_ID_OPUS: AV_WB8(codecpar->extradata + 9, codecpar->ch_layout.nb_channels); + AV_WL16(codecpar->extradata + 10, AV_RB16(codecpar->extradata + 10)); // Byte swap pre-skip + AV_WL32(codecpar->extradata + 12, AV_RB32(codecpar->extradata + 12)); // Byte swap sample rate + AV_WL16(codecpar->extradata + 16, AV_RB16(codecpar->extradata + 16)); // Byte swap Output Gain break; case AV_CODEC_ID_AAC: { uint8_t buf[5]; diff --git a/libavformat/iamf_writer.c b/libavformat/iamf_writer.c index af837ccb1f..7522f15548 100644 --- a/libavformat/iamf_writer.c +++ b/libavformat/iamf_writer.c @@ -42,8 +42,12 @@ static int update_extradata(IAMFCodecConfig *codec_config) if (codec_config->extradata_size < 19) return AVERROR_INVALIDDATA; codec_config->extradata_size -= 8; - memmove(codec_config->extradata, codec_config->extradata + 8, codec_config->extradata_size); - AV_WB8(codec_config->extradata + 1, 2); // set channels to stereo + AV_WB8(codec_config->extradata + 0, AV_RL8(codec_config->extradata + 8)); // version + AV_WB8(codec_config->extradata + 1, 2); // set channels to stereo + AV_WB16(codec_config->extradata + 2, AV_RL16(codec_config->extradata + 10)); // Byte swap pre-skip + AV_WB32(codec_config->extradata + 4, AV_RL32(codec_config->extradata + 12)); // Byte swap sample rate + AV_WB16(codec_config->extradata + 8, 0); // set Output Gain to 0 + AV_WB8(codec_config->extradata + 10, AV_RL8(codec_config->extradata + 18)); // Mapping family break; case AV_CODEC_ID_FLAC: { uint8_t buf[13]; diff --git a/tests/ref/fate/iamf-5_1-copy b/tests/ref/fate/iamf-5_1-copy index bc4df7c57f..ed2046fe3b 100644 --- a/tests/ref/fate/iamf-5_1-copy +++ b/tests/ref/fate/iamf-5_1-copy @@ -1,7 +1,7 @@ -#extradata 0: 19, 0x379c0490 -#extradata 1: 19, 0x379c0490 -#extradata 2: 19, 0x3792048f -#extradata 3: 19, 0x3792048f +#extradata 0: 19, 0x3a0e0490 +#extradata 1: 19, 0x3a0e0490 +#extradata 2: 19, 0x3a04048f +#extradata 3: 19, 0x3a04048f #tb 0: 1/48000 #media_type 0: audio #codec_id 0: opus diff --git a/tests/ref/fate/iamf-5_1-demux b/tests/ref/fate/iamf-5_1-demux index bc4df7c57f..ed2046fe3b 100644 --- a/tests/ref/fate/iamf-5_1-demux +++ b/tests/ref/fate/iamf-5_1-demux @@ -1,7 +1,7 @@ -#extradata 0: 19, 0x379c0490 -#extradata 1: 19, 0x379c0490 -#extradata 2: 19, 0x3792048f -#extradata 3: 19, 0x3792048f +#extradata 0: 19, 0x3a0e0490 +#extradata 1: 19, 0x3a0e0490 +#extradata 2: 19, 0x3a04048f +#extradata 3: 19, 0x3a04048f #tb 0: 1/48000 #media_type 0: audio #codec_id 0: opus -- 2.45.2 _______________________________________________ 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-07-17 1:50 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-07-17 1:49 [FFmpeg-devel] [PATCH 1/4] avformat/movenc: fix channel count and samplerate fields for IAMF tracks James Almer 2024-07-17 1:49 ` [FFmpeg-devel] [PATCH 2/4] avformat/iamf_writer: fix PCM endian-ness flag James Almer 2024-07-17 1:49 ` [FFmpeg-devel] [PATCH 3/4] avformat/iamf_writer: fix coded audio_roll_distance values James Almer 2024-07-17 1:49 ` James Almer [this message] 2024-07-17 6:18 ` [FFmpeg-devel] [PATCH 1/4] avformat/movenc: fix channel count and samplerate fields for IAMF tracks Anton Khirnov 2024-07-17 11:29 ` James Almer
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=20240717014925.16517-4-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