Skip to content

Commit caeae33

Browse files
Merge pull request #118 from yilun-zhangs/main
[V1.0] 1,Verify opus version and iamf code validity 2, fix aac specific information parsing 3, vlogging changing(info_type->info_type_bit_masks)
2 parents b60e719 + 269b32f commit caeae33

9 files changed

Lines changed: 100 additions & 73 deletions

File tree

code/include/IAMF_defines.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ typedef enum IAMF_SoundSystem {
5858
SOUND_SYSTEM_J, // 4+7+0, 1
5959
SOUND_SYSTEM_EXT_712, // 2+7+0, 1
6060
SOUND_SYSTEM_EXT_312, // 2+3+0, 1
61-
SOUND_SYSTEM_MONO, // 0+1+0, 1
61+
SOUND_SYSTEM_MONO, // 0+1+0, 0
6262
SOUND_SYSTEM_END
6363
} IAMF_SoundSystem;
6464

code/src/common/audio_defines.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,6 @@
2525
#define LIMITER_ReleaseSec 0.200f
2626
#define LIMITER_LookAhead 240
2727

28-
typedef enum {
29-
CHANNELUNKNOWN = 0,
30-
CHANNELMONO,
31-
CHANNELSTEREO,
32-
CHANNEL51,
33-
CHANNEL512,
34-
CHANNEL514,
35-
CHANNEL71,
36-
CHANNEL712,
37-
CHANNEL714,
38-
CHANNEL312,
39-
CHANNELBINAURAL
40-
} channelLayout;
41-
4228
#define MAX_CHANNELS 12
4329
#define MAX_OUTPUT_CHANNELS 24
4430
#define MAX_DELAYSIZE 4096

code/src/iamf_dec/IAMF_OBU.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,10 @@ static int _valid_profile(uint8_t primary, uint8_t addional) {
254254
IAMF_Version *iamf_version_new(IAMF_OBU *obu) {
255255
IAMF_Version *ver = 0;
256256
BitStream b;
257+
union {
258+
uint32_t _id;
259+
uint8_t _4cc[4];
260+
} code = {._4cc = {'i', 'a', 'm', 'f'}};
257261

258262
ver = IAMF_MALLOCZ(IAMF_Version, 1);
259263
if (!ver) {
@@ -273,6 +277,12 @@ IAMF_Version *iamf_version_new(IAMF_OBU *obu) {
273277
"%u.",
274278
(char *)&ver->iamf_code, ver->primary_profile, ver->additional_profile);
275279

280+
if (ver->iamf_code != code._id) {
281+
ia_loge("ia sequence header object: Invalid iamf code %.4s.",
282+
(char *)&ver->iamf_code);
283+
goto version_fail;
284+
}
285+
276286
if (!_valid_profile(ver->primary_profile, ver->additional_profile)) {
277287
ia_loge(
278288
"ia sequence header object: Invalid primary profile %u or additional "
@@ -296,6 +306,18 @@ static int _valid_codec(uint32_t codec) {
296306
return iamf_codec_check(iamf_codec_4cc_get_codecID(codec));
297307
}
298308

309+
#define OPUS_VERSION_MAX 15
310+
static int _valid_decoder_config(uint32_t codec, uint8_t *conf, size_t size) {
311+
if (iamf_codec_4cc_get_codecID(codec) == IAMF_CODEC_OPUS) {
312+
if (conf[0] > OPUS_VERSION_MAX) {
313+
ia_logw("opus config invalid: version %u should less than %u.", conf[0],
314+
OPUS_VERSION_MAX);
315+
return 0;
316+
}
317+
}
318+
return 1;
319+
}
320+
299321
IAMF_CodecConf *iamf_codec_conf_new(IAMF_OBU *obu) {
300322
IAMF_CodecConf *conf = 0;
301323
BitStream b;
@@ -335,6 +357,12 @@ IAMF_CodecConf *iamf_codec_conf_new(IAMF_OBU *obu) {
335357
goto codec_conf_fail;
336358
}
337359

360+
if (!_valid_decoder_config(conf->codec_id, conf->decoder_conf,
361+
conf->decoder_conf_size)) {
362+
ia_logw("decoder config is invalid, codec: %.4s", (char *)&conf->codec_id);
363+
goto codec_conf_fail;
364+
}
365+
338366
#if SUPPORT_VERIFIER
339367
vlog_obu(IAMF_OBU_CODEC_CONFIG, conf, 0, 0);
340368
#endif

code/src/iamf_dec/IAMF_decoder.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -729,9 +729,15 @@ static int iamf_codec_conf_get_sampling_rate(IAMF_CodecConf *c) {
729729
static int sf[] = {96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050,
730730
16000, 12000, 11025, 8000, 7350, 0, 0, 0};
731731

732-
/* DecoderConfigDescriptor (14 bytes) + DecSpecificInfoTag (1 byte) */
733-
if (c->decoder_conf_size < 16) return IAMF_ERR_BAD_ARG;
734-
bs(&b, c->decoder_conf + 15, c->decoder_conf_size - 15);
732+
/* DecoderConfigDescriptor */
733+
bs(&b, c->decoder_conf, c->decoder_conf_size);
734+
bs_get32b(&b, 8);
735+
bs_getExpandableSize(&b);
736+
bs_skipABytes(&b, 13);
737+
738+
/* DecSpecificInfoTag */
739+
bs_get32b(&b, 8);
740+
bs_getExpandableSize(&b);
735741

736742
type = bs_get32b(&b, 5);
737743
if (type == 31) bs_get32b(&b, 6);

code/src/iamf_dec/aac/IAMF_aac_decoder.c

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "IAMF_debug.h"
2424
#include "IAMF_types.h"
2525
#include "aac_multistream_decoder.h"
26+
#include "bitstream.h"
2627

2728
#ifdef IA_TAG
2829
#undef IA_TAG
@@ -58,35 +59,28 @@ typedef struct IAMF_AAC_Context {
5859
static int iamf_aac_init(IAMF_CodecContext *ths) {
5960
IAMF_AAC_Context *ctx = (IAMF_AAC_Context *)ths->priv;
6061
uint8_t *config = ths->cspec;
61-
int len = ths->clen;
62+
BitStream b;
6263
int ret = 0;
6364

64-
if (!ths->cspec || ths->clen <= 0) {
65-
return IAMF_ERR_BAD_ARG;
66-
}
65+
bs(&b, ths->cspec, ths->clen);
66+
if (bs_get32b(&b, 8) != 0x04) return IAMF_ERR_BAD_ARG;
67+
bs_getExpandableSize(&b);
6768

68-
int idx = 1;
69-
if (config[idx] != 0x40 /* Audio ISO/IEC 14496-3 */
70-
|| (config[idx + 1] >> 2 & 0x3f) != 5 /* AudioStream */
71-
|| (config[idx + 1] >> 1 & 0x1) != 0) { /* upstream */
69+
if (bs_get32b(&b, 8) != 0x40 || bs_get32b(&b, 6) != 5 || bs_get32b(&b, 1))
7270
return IAMF_ERR_BAD_ARG;
73-
}
74-
idx += 13;
75-
if (config[idx] != 0x05) {
76-
return IAMF_ERR_BAD_ARG; // MP4DecSpecificDescrTag
77-
}
78-
++idx;
7971

80-
ths->cspec = &config[idx];
81-
ths->clen = len - idx;
72+
bs_skipABytes(&b, 11);
73+
74+
if (bs_get32b(&b, 8) != 0x05) return IAMF_ERR_BAD_ARG;
75+
76+
ths->clen = bs_getExpandableSize(&b);
77+
ths->cspec = config + bs_tell(&b);
8278
ia_logd("aac codec spec info size %d", ths->clen);
8379

8480
ctx->dec = aac_multistream_decoder_open(ths->cspec, ths->clen, ths->streams,
8581
ths->coupled_streams,
8682
AUDIO_FRAME_PLANE, &ret);
87-
if (!ctx->dec) {
88-
return IAMF_ERR_INVALID_STATE;
89-
}
83+
if (!ctx->dec) return IAMF_ERR_INVALID_STATE;
9084

9185
ctx->out = (short *)malloc(sizeof(short) * MAX_AAC_FRAME_SIZE *
9286
(ths->streams + ths->coupled_streams));

code/src/iamf_dec/bitstream.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,23 @@ uint64_t bs_getAleb128(BitStream *b) {
141141
return ret;
142142
}
143143

144+
/// @brief Read descriptor size of ISO/IEC 14496-1.
145+
uint32_t bs_getExpandableSize(BitStream *b) {
146+
uint32_t ret = 0;
147+
uint8_t byte;
148+
149+
for (uint32_t i = 0; i < 4; i++) {
150+
byte = b->data[b->b8sp + i];
151+
ret = (ret << 7) | (byte & 0x7f);
152+
if (!(byte & 0x80)) {
153+
b->b8sp += (i + 1);
154+
break;
155+
}
156+
}
157+
158+
return ret;
159+
}
160+
144161
int32_t bs_read(BitStream *b, uint8_t *data, int n) {
145162
bs_align(b);
146163
if (data) memcpy(data, &b->data[b->b8sp], n);

code/src/iamf_dec/bitstream.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ uint32_t bs_getA8b(BitStream *b);
4242
uint32_t bs_getA16b(BitStream *b);
4343
uint32_t bs_getA32b(BitStream *b);
4444
uint64_t bs_getAleb128(BitStream *b);
45+
uint32_t bs_getExpandableSize(BitStream *b);
4546
int32_t bs_read(BitStream *b, uint8_t *data, int n);
4647
int32_t bs_readString(BitStream *b, char *data, int n);
4748
uint32_t bs_tell(BitStream *b);

code/src/iamf_dec/h2m_rdr.c

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
AOM-IAMF Standard Deliverable Status:
1515
This software module is out of scope and not part of the IAMF Final Deliverable.
1616
*/
17-
17+
1818
/**
1919
* @file h2m_rdr.c
2020
* @brief HOA to Multichannels rendering.
@@ -486,20 +486,17 @@ float soa_bs470[][9] = {{1.31381003e-01, 1.48448976e-01, -1.90212725e-01,
486486
1.58493458e-01, -2.13843703e-01, 2.85769131e-04}};
487487

488488
float soa_iamf312[][9] = {
489-
{2.327932e-01, 2.848056e-01, -2.581401e-02, 3.031344e-01, 3.715644e-01,
490-
-3.044674e-02, 8.758713e-02, 1.078822e-03, -1.160062e-02}, // L
491-
{2.327919e-01, -2.848050e-01, -2.582280e-02, 3.031372e-01, -3.715555e-01,
492-
3.046395e-02, 8.761200e-02, 1.071232e-03, -1.159248e-02}, // R
493-
{1.02002565e-01, 1.16679273e-05, -1.32667792e-01, 1.91514833e-01,
494-
3.22324409e-05, -9.39024240e-06, 3.59275434e-02, -1.19192733e-01,
495-
2.13323852e-01}, // C
496-
{4.54071480e-01, 4.40034892e-01, 8.54014466e-03, -4.09726522e-01,
497-
-9.36552906e-02, 4.92427716e-03, 9.13601796e-02, 4.00474901e-03,
498-
-8.49272007e-02}, // Hfl
499-
{4.54065786e-01, -4.40013199e-01, 8.55303445e-03, -4.09744042e-01,
500-
9.36608249e-02, -4.92139383e-03, 9.13448355e-02, 4.01492543e-03,
501-
-8.49451616e-02} // Hfr
502-
};
489+
{4.726751e-01, 5.264195e-01, -1.779691e-01, -8.917566e-02, 2.168611e-01,
490+
-1.274446e-01, 6.197195e-02, -1.513111e-01, -9.806416e-02},
491+
{4.726787e-01, -5.264100e-01, -1.779698e-01, -8.916373e-02, -2.168667e-01,
492+
1.274678e-01, 6.195992e-02, -1.513142e-01, -9.804430e-02},
493+
{1.020026e-01, 1.166793e-05, -1.326678e-01, 1.915148e-01, 3.223244e-05,
494+
-9.390242e-06, 3.592754e-02, -1.191927e-01, 2.133239e-01},
495+
{1.148273e-01, 9.834126e-02, 2.237200e-01, 1.450837e-01, 1.251282e-01,
496+
1.420999e-01, 1.275855e-01, 2.195166e-01, 3.735070e-02},
497+
{1.148147e-01, -9.833212e-02, 2.237213e-01, 1.450532e-01, -1.251021e-01,
498+
-1.421055e-01, 1.276224e-01, 2.195205e-01, 3.731617e-02}};
499+
503500
float soa_iamf712[][9] = {
504501
{1.31381003e-01, 1.48448976e-01, -1.90212725e-01, 1.74601956e-01,
505502
2.49201104e-01, -1.12860844e-01, 3.90171076e-02, -1.38956589e-01,
@@ -930,26 +927,27 @@ float toa_bs470[][16] = {
930927
-3.35050564e-02, -9.10396767e-02, 1.32770538e-03, 2.85003118e-02}};
931928

932929
float toa_iamf312[][16] = {
933-
{4.600323e-01, 5.123392e-01, -1.732089e-01, -8.679045e-02, 2.110607e-01,
934-
-1.240358e-01, 6.031437e-02, -1.472639e-01, -9.544121e-02, 9.626710e-03,
930+
{4.600323e-01, 5.123393e-01, -1.732089e-01, -8.679045e-02, 2.110607e-01,
931+
-1.240358e-01, 6.031437e-02, -1.472639e-01, -9.544121e-02, 9.626709e-03,
935932
-1.475499e-01, -2.170848e-02, -1.757221e-02, -3.459537e-02, 5.974536e-03,
936933
-1.740531e-01},
937934
{4.600358e-01, -5.123299e-01, -1.732095e-01, -8.677885e-02, -2.110661e-01,
938935
1.240584e-01, 6.030266e-02, -1.472670e-01, -9.542189e-02, -9.640919e-03,
939936
1.475400e-01, 2.169693e-02, -1.758859e-02, -3.460532e-02, 5.974916e-03,
940937
-1.740174e-01},
941-
{9.92742752e-02, 1.13558421e-05, -1.29119291e-01, 1.86392335e-01,
942-
3.13703112e-05, -9.13907907e-06, 3.49665798e-02, -1.16004653e-01,
943-
2.07618022e-01, 3.94596117e-05, -2.87941415e-05, 4.17936507e-06,
944-
-6.57885105e-02, -1.79100086e-02, -8.36478901e-02, 2.21708712e-01},
945-
{4.41926308e-01, 4.28265161e-01, 8.31171912e-03, -3.98767457e-01,
946-
-9.11502674e-02, 4.79256619e-03, 8.89165443e-02, 3.89763292e-03,
947-
-8.26556301e-02, -1.64741393e-01, 7.34130565e-03, 4.55127066e-02,
948-
1.57174239e-03, -4.06651499e-02, -7.74208653e-03, -2.84149500e-02},
949-
{4.41920767e-01, -4.28244047e-01, 8.32426414e-03, -3.98784508e-01,
950-
9.11556537e-02, -4.78975999e-03, 8.89016107e-02, 3.90753714e-03,
951-
-8.26731106e-02, 1.64745462e-01, -7.35804577e-03, -4.55056466e-02,
952-
1.56664042e-03, -4.06703815e-02, -7.75179027e-03, -2.83998198e-02}};
938+
{9.927428e-02, 1.135584e-05, -1.291193e-01, 1.863923e-01, 3.137031e-05,
939+
-9.139079e-06, 3.496658e-02, -1.160047e-01, 2.076180e-01, 3.945961e-05,
940+
-2.879414e-05, 4.179365e-06, -6.578851e-02, -1.791001e-02, -8.364789e-02,
941+
2.217087e-01},
942+
{1.117560e-01, 9.571090e-02, 2.177361e-01, 1.412031e-01, 1.217814e-01,
943+
1.382991e-01, 1.241730e-01, 2.136451e-01, 3.635167e-02, 6.785955e-02,
944+
1.732515e-01, 6.485935e-02, -1.129651e-02, 1.236321e-01, 4.362752e-02,
945+
-5.882758e-03},
946+
{1.117437e-01, -9.570201e-02, 2.177374e-01, 1.411734e-01, -1.217560e-01,
947+
-1.383046e-01, 1.242088e-01, 2.136489e-01, 3.631807e-02, -6.782208e-02,
948+
-1.732464e-01, -6.488207e-02, -1.128750e-02, 1.236767e-01, 4.363238e-02,
949+
-5.932943e-03},
950+
};
953951

954952
float toa_iamf712[][16] = {
955953
{1.24843144e-01, 1.41061771e-01, -1.80747248e-01, 1.65913311e-01,
@@ -1150,8 +1148,7 @@ int IAMF_element_renderer_render_H2M(struct h2m_rdr_t *h2mMatrix, float *in[],
11501148
out[lfe1][j] = output * 0.5;
11511149
else
11521150
out[lfe1][j] = output / sqrt(n_size);
1153-
}
1154-
else { // lfe off
1151+
} else { // lfe off
11551152
out[lfe1][j] = 0;
11561153
}
11571154
}
@@ -1162,17 +1159,15 @@ int IAMF_element_renderer_render_H2M(struct h2m_rdr_t *h2mMatrix, float *in[],
11621159
if (lfe) { // lfe on
11631160
if (lfe1 >= 0) { // already compute lfe
11641161
out[lfe2][j] = out[lfe1][j];
1165-
}
1166-
else { // compute lfe
1162+
} else { // compute lfe
11671163
float output;
11681164
output = lfefilter_update(lfe, in[0][j]); // use W
11691165
if (n_size <= 2)
11701166
out[lfe2][j] = output * 0.5;
11711167
else
11721168
out[lfe2][j] = output / sqrt(n_size);
11731169
}
1174-
}
1175-
else { // lfe off
1170+
} else { // lfe off
11761171
out[lfe2][j] = 0;
11771172
}
11781173
}

code/src/iamf_dec/vlogging_tool_sr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ static void write_mix_presentation_log(uint64_t idx, void* obu, char* log) {
753753

754754
// loudness
755755
log += write_yaml_form(log, 3, "loudness:");
756-
log += write_yaml_form(log, 4, "info_type: %u",
756+
log += write_yaml_form(log, 4, "info_type_bit_masks: [%u]",
757757
submix->loudness[j].info_type);
758758
log += write_yaml_form(log, 4, "integrated_loudness: %d",
759759
submix->loudness[j].integrated_loudness);

0 commit comments

Comments
 (0)