avformat/iamf: byteswap values in OpusHeader

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>
This commit is contained in:
James Almer 2024-07-16 20:32:40 -03:00
parent 54b8d5e201
commit 7dabad079b
4 changed files with 17 additions and 10 deletions

View File

@ -272,6 +272,9 @@ static int update_extradata(AVCodecParameters *codecpar)
switch(codecpar->codec_id) { switch(codecpar->codec_id) {
case AV_CODEC_ID_OPUS: case AV_CODEC_ID_OPUS:
AV_WB8(codecpar->extradata + 9, codecpar->ch_layout.nb_channels); 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; break;
case AV_CODEC_ID_AAC: { case AV_CODEC_ID_AAC: {
uint8_t buf[5]; uint8_t buf[5];

View File

@ -42,8 +42,12 @@ static int update_extradata(IAMFCodecConfig *codec_config)
if (codec_config->extradata_size < 19) if (codec_config->extradata_size < 19)
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
codec_config->extradata_size -= 8; codec_config->extradata_size -= 8;
memmove(codec_config->extradata, codec_config->extradata + 8, codec_config->extradata_size); 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_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; break;
case AV_CODEC_ID_FLAC: { case AV_CODEC_ID_FLAC: {
uint8_t buf[13]; uint8_t buf[13];

View File

@ -1,7 +1,7 @@
#extradata 0: 19, 0x379c0490 #extradata 0: 19, 0x3a0e0490
#extradata 1: 19, 0x379c0490 #extradata 1: 19, 0x3a0e0490
#extradata 2: 19, 0x3792048f #extradata 2: 19, 0x3a04048f
#extradata 3: 19, 0x3792048f #extradata 3: 19, 0x3a04048f
#tb 0: 1/48000 #tb 0: 1/48000
#media_type 0: audio #media_type 0: audio
#codec_id 0: opus #codec_id 0: opus

View File

@ -1,7 +1,7 @@
#extradata 0: 19, 0x379c0490 #extradata 0: 19, 0x3a0e0490
#extradata 1: 19, 0x379c0490 #extradata 1: 19, 0x3a0e0490
#extradata 2: 19, 0x3792048f #extradata 2: 19, 0x3a04048f
#extradata 3: 19, 0x3792048f #extradata 3: 19, 0x3a04048f
#tb 0: 1/48000 #tb 0: 1/48000
#media_type 0: audio #media_type 0: audio
#codec_id 0: opus #codec_id 0: opus