|
23 | 23 | #include "IAMF_debug.h" |
24 | 24 | #include "IAMF_types.h" |
25 | 25 | #include "aac_multistream_decoder.h" |
| 26 | +#include "bitstream.h" |
26 | 27 |
|
27 | 28 | #ifdef IA_TAG |
28 | 29 | #undef IA_TAG |
@@ -58,35 +59,28 @@ typedef struct IAMF_AAC_Context { |
58 | 59 | static int iamf_aac_init(IAMF_CodecContext *ths) { |
59 | 60 | IAMF_AAC_Context *ctx = (IAMF_AAC_Context *)ths->priv; |
60 | 61 | uint8_t *config = ths->cspec; |
61 | | - int len = ths->clen; |
| 62 | + BitStream b; |
62 | 63 | int ret = 0; |
63 | 64 |
|
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); |
67 | 68 |
|
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)) |
72 | 70 | return IAMF_ERR_BAD_ARG; |
73 | | - } |
74 | | - idx += 13; |
75 | | - if (config[idx] != 0x05) { |
76 | | - return IAMF_ERR_BAD_ARG; // MP4DecSpecificDescrTag |
77 | | - } |
78 | | - ++idx; |
79 | 71 |
|
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); |
82 | 78 | ia_logd("aac codec spec info size %d", ths->clen); |
83 | 79 |
|
84 | 80 | ctx->dec = aac_multistream_decoder_open(ths->cspec, ths->clen, ths->streams, |
85 | 81 | ths->coupled_streams, |
86 | 82 | AUDIO_FRAME_PLANE, &ret); |
87 | | - if (!ctx->dec) { |
88 | | - return IAMF_ERR_INVALID_STATE; |
89 | | - } |
| 83 | + if (!ctx->dec) return IAMF_ERR_INVALID_STATE; |
90 | 84 |
|
91 | 85 | ctx->out = (short *)malloc(sizeof(short) * MAX_AAC_FRAME_SIZE * |
92 | 86 | (ths->streams + ths->coupled_streams)); |
|
0 commit comments