Skip to content

Commit f4dad69

Browse files
committed
fix DecoderConfigDescriptor parsing
1 parent 3239cdc commit f4dad69

5 files changed

Lines changed: 41 additions & 23 deletions

File tree

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/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)