Skip to content

Commit 6aae4c1

Browse files
yilun-zhangstdaede
authored andcommitted
iamf v1.0 decoder enhance for future extension
1 parent 2301f65 commit 6aae4c1

7 files changed

Lines changed: 230 additions & 57 deletions

File tree

code/include/IAMF_defines.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,8 @@ typedef enum {
193193
IA_CHANNEL_LAYOUT_COUNT
194194
} IAChannelLayoutType;
195195

196+
#define IAMF_AMBISONICS_MAX_CHANNELS 16
197+
#define IAMF_MIX_PRESENTATION_MAX_SUBS 1
198+
#define IAMF_MIX_PRESENTATION_MAX_ELEMENTS 2
199+
#define IAMF_MIX_PRESENTATION_MAX_CHANNELS 18
196200
#endif /* IAMF_DEFINES_H */

code/src/iamf_dec/IAMF_OBU.c

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -445,9 +445,9 @@ IAMF_Element *iamf_element_new(IAMF_OBU *obu) {
445445
uint64_t size = bs_getAleb128(&b);
446446
bs_skipABytes(&b, size);
447447
ia_loge("Don't support parameter type %" PRIu64
448-
" in Audio Element, parameter "
449-
"definition bytes %" PRIu64 ".",
450-
type, size);
448+
" in Audio Element %" PRId64
449+
", parameter definition bytes %" PRIu64 ".",
450+
elem->element_id, type, size);
451451
continue;
452452
}
453453

@@ -473,6 +473,7 @@ IAMF_Element *iamf_element_new(IAMF_OBU *obu) {
473473

474474
if (elem->element_type == AUDIO_ELEMENT_TYPE_CHANNEL_BASED) {
475475
ScalableChannelLayoutConf *chs_conf;
476+
int channels = 0;
476477
chs_conf = IAMF_MALLOCZ(ScalableChannelLayoutConf, 1);
477478
if (!chs_conf) {
478479
ia_loge(
@@ -484,8 +485,8 @@ IAMF_Element *iamf_element_new(IAMF_OBU *obu) {
484485

485486
val = bs_get32b(&b, 3);
486487
bs_skip(&b, 5);
487-
chs_conf->nb_layers = val;
488-
ia_logd("scalable channel layers %d", chs_conf->nb_layers);
488+
chs_conf->num_layers = val;
489+
ia_logd("scalable channel layers %d", chs_conf->num_layers);
489490
if (val) {
490491
ChannelLayerConf *layer_conf_s;
491492
layer_conf_s = IAMF_MALLOCZ(ChannelLayerConf, val);
@@ -502,6 +503,22 @@ IAMF_Element *iamf_element_new(IAMF_OBU *obu) {
502503
layer_conf_s[i].recon_gain_flag = bs_get32b(&b, 1);
503504
layer_conf_s[i].nb_substreams = bs_getA8b(&b);
504505
layer_conf_s[i].nb_coupled_substreams = bs_getA8b(&b);
506+
channels += (layer_conf_s[i].nb_substreams +
507+
layer_conf_s[i].nb_coupled_substreams);
508+
if (chs_conf->nb_layers == i) {
509+
uint8_t loudspeaker_layout = layer_conf_s[i].loudspeaker_layout;
510+
if (ia_channel_layout_type_check(loudspeaker_layout) &&
511+
(layer_conf_s[i].nb_substreams > 0) &&
512+
(ia_channel_layout_get_channels_count(loudspeaker_layout) ==
513+
channels)) {
514+
++chs_conf->nb_layers;
515+
} else {
516+
ia_logw("element (%" PRId64
517+
") Layer %d: Invalid loudspeaker layout %d",
518+
elem->element_id, i, layer_conf_s[i].loudspeaker_layout);
519+
}
520+
}
521+
505522
ia_logd(
506523
"\tlayer[%d] info: layout %d, output gain %d, recon gain %d, "
507524
"sub-streams count %d, coupled sub-streams %d",
@@ -525,6 +542,7 @@ IAMF_Element *iamf_element_new(IAMF_OBU *obu) {
525542
g->output_gain_flag & U8_MASK, g->output_gain & U16_MASK);
526543
}
527544
}
545+
ia_logd("valid scalable channel layers %d", chs_conf->nb_layers);
528546
}
529547
} else if (elem->element_type == AUDIO_ELEMENT_TYPE_SCENE_BASED) {
530548
AmbisonicsConf *conf = IAMF_MALLOCZ(AmbisonicsConf, 1);
@@ -617,7 +635,7 @@ void iamf_element_free(IAMF_Element *obj) {
617635
obj->channels_conf) {
618636
ScalableChannelLayoutConf *conf = obj->channels_conf;
619637
if (conf->layer_conf_s) {
620-
for (int i = 0; i < conf->nb_layers; ++i) {
638+
for (int i = 0; i < conf->num_layers; ++i) {
621639
IAMF_FREE(conf->layer_conf_s[i].output_gain_info);
622640
}
623641
free(conf->layer_conf_s);
@@ -855,7 +873,8 @@ IAMF_MixPresentation *iamf_mix_presentation_new(IAMF_OBU *obu) {
855873
layouts[i] = TARGET_LAYOUT(b);
856874
ia_logd("\tLayout %d > binaural.", i);
857875
} else {
858-
ia_logw("Undefine layout type %d.", type);
876+
ia_logw("Undefine layout type %d in mix presentation %" PRId64 ".",
877+
type, mixp->mix_presentation_id);
859878
}
860879
bs_align(&b);
861880

code/src/iamf_dec/IAMF_OBU.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@ typedef struct ChannelLayerConf {
210210
} ChannelLayerConf;
211211

212212
struct ScalableChannelLayoutConf {
213-
uint32_t nb_layers;
213+
uint32_t nb_layers; // max valid layers
214+
uint32_t num_layers; // total layers
214215
ChannelLayerConf *layer_conf_s;
215216
};
216217

0 commit comments

Comments
 (0)