Skip to content

Commit 067a207

Browse files
committed
1, Add more profile limitation. 2, fix some bugs in h2m
1 parent b93cf43 commit 067a207

8 files changed

Lines changed: 82 additions & 46 deletions

File tree

-1.96 MB
Binary file not shown.

code/dep_external/src/binaural/iamf2bear/iamf2bear.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ static int getmodulepath(char *path, int buffsize)
102102
int count = 0, i = 0;
103103
#if defined(_WIN32)
104104
count = GetModuleFileName(NULL, path, buffsize);
105-
#elifdef __APPLE__
105+
#elif defined(__APPLE__)
106106
uint32_t size = MAX_PATH;
107107
_NSGetExecutablePath(path, &size);
108108
count = size;
@@ -231,17 +231,17 @@ extern "C" EXPORT_API int ConfigureBearDirectSpeakerChannel(void *pv_thiz,
231231
std::make_pair(-180.0, 180.0),
232232
std::make_pair(-90.0, 90.0),
233233
true},
234-
Channel{"M+110",
235-
PolarPosition{110.0, 0.0},
236-
PolarPosition{110.0, 0.0},
237-
std::make_pair(100.0, 120.0),
238-
std::make_pair(0.0, 15.0),
234+
Channel{"U+030",
235+
PolarPosition{30.0, 30.0},
236+
PolarPosition{30.0, 30.0},
237+
std::make_pair(30.0, 45.0),
238+
std::make_pair(30.0, 55.0),
239239
false},
240-
Channel{"M-110",
241-
PolarPosition{-110.0, 0.0},
242-
PolarPosition{-110.0, 0.0},
243-
std::make_pair(-120.0, -100.0),
244-
std::make_pair(0.0, 15.0),
240+
Channel{"U-030",
241+
PolarPosition{-30.0, 30.0},
242+
PolarPosition{-30.0, 30.0},
243+
std::make_pair(-45.0, -30.0),
244+
std::make_pair(30.0, 55.0),
245245
false},
246246
}};
247247

code/include/IAMF_defines.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,4 @@ typedef enum {
192192
IA_CHANNEL_LAYOUT_BINAURAL, // binaural
193193
IA_CHANNEL_LAYOUT_COUNT
194194
} IAChannelLayoutType;
195-
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
200195
#endif /* IAMF_DEFINES_H */

code/src/iamf_dec/IAMF_OBU.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,8 @@ uint32_t iamf_obu_get_payload_size(IAMF_OBU *obu) {
247247
return obu->size - (uint32_t)(obu->payload - obu->data);
248248
}
249249

250-
static int _valid_profile(uint8_t profile) {
251-
return profile == IAMF_PROFILE_SIMPLE || profile == IAMF_PROFILE_BASE;
250+
static int _valid_profile(uint8_t primary, uint8_t addional) {
251+
return primary < IAMF_PROFILE_COUNT && primary <= addional;
252252
}
253253

254254
IAMF_Version *iamf_version_new(IAMF_OBU *obu) {
@@ -273,9 +273,11 @@ IAMF_Version *iamf_version_new(IAMF_OBU *obu) {
273273
"%u.",
274274
(char *)&ver->iamf_code, ver->primary_profile, ver->additional_profile);
275275

276-
if (!_valid_profile(ver->primary_profile)) {
277-
ia_loge("ia sequence header object: Invalid profile %u",
278-
ver->primary_profile);
276+
if (!_valid_profile(ver->primary_profile, ver->additional_profile)) {
277+
ia_loge(
278+
"ia sequence header object: Invalid primary profile %u or additional "
279+
"profile %u.",
280+
ver->primary_profile, ver->additional_profile);
279281
goto version_fail;
280282
}
281283

@@ -756,11 +758,6 @@ IAMF_MixPresentation *iamf_mix_presentation_new(IAMF_OBU *obu) {
756758
"Mix Presentation Object: num_audio_elements should not be set to "
757759
"0.");
758760
goto mix_presentation_fail;
759-
} else if (val > 2) {
760-
ia_logw(
761-
"Mix Presentation Object: Do not support num_audio_elements more "
762-
"than 2.");
763-
goto mix_presentation_fail;
764761
}
765762

766763
conf_s = IAMF_MALLOCZ(ElementConf, val);

code/src/iamf_dec/IAMF_decoder.c

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,10 @@ static int32_t FLOAT2INT24(float x) {
9494

9595
static int32_t FLOAT2INT32(float x) {
9696
x = x * 2147483648.f;
97-
x = MAX(x, -2147483648.f);
98-
x = MIN(x, 2147483647.f);
99-
return (int32_t)lrintf(x);
97+
if (x > -2147483648.f && x < 2147483647.f)
98+
return (int32_t)lrintf(x);
99+
else
100+
return (x > 0.0f ? 2147483647 : (-2147483647 - 1));
100101
}
101102

102103
static void iamf_decoder_plane2stride_out(void *dst, const float *src,
@@ -1183,6 +1184,16 @@ static int iamf_database_element_add(IAMF_DataBase *db, IAMF_Object *obj) {
11831184
return ret;
11841185
}
11851186

1187+
static struct {
1188+
uint32_t max_elements;
1189+
uint32_t max_channels;
1190+
} _profile_limit[IAMF_PROFILE_COUNT] = {
1191+
{IAMF_SIMPLE_PROFILE_MIX_PRESENTATION_MAX_ELEMENTS,
1192+
IAMF_SIMPLE_PROFILE_MIX_PRESENTATION_MAX_CHANNELS},
1193+
{IAMF_BASE_PROFILE_MIX_PRESENTATION_MAX_ELEMENTS,
1194+
IAMF_BASE_PROFILE_MIX_PRESENTATION_MAX_CHANNELS},
1195+
};
1196+
11861197
static int iamf_database_mix_presentation_is_valid(IAMF_DataBase *db,
11871198
IAMF_MixPresentation *mp) {
11881199
int ret = IAMF_OK;
@@ -1193,7 +1204,7 @@ static int iamf_database_mix_presentation_is_valid(IAMF_DataBase *db,
11931204

11941205
if (mp->num_sub_mixes < IAMF_MIX_PRESENTATION_MAX_SUBS) return 0;
11951206
sub = mp->sub_mixes;
1196-
if (sub->nb_elements > IAMF_MIX_PRESENTATION_MAX_ELEMENTS) return 0;
1207+
if (sub->nb_elements > _profile_limit[db->profile].max_elements) return 0;
11971208

11981209
for (int e = 0; e < sub->nb_elements; ++e) {
11991210
econf = &sub->conf_s[e];
@@ -1222,10 +1233,10 @@ static int iamf_database_mix_presentation_is_valid(IAMF_DataBase *db,
12221233
}
12231234

12241235
if (ret != IAMF_OK) return !ret;
1225-
if (channels > IAMF_MIX_PRESENTATION_MAX_CHANNELS) {
1236+
if (channels > _profile_limit[db->profile].max_channels) {
12261237
ia_logw("Mix Presentation %" PRId64 " has %d channels, more than %u",
12271238
mp->mix_presentation_id, channels,
1228-
IAMF_MIX_PRESENTATION_MAX_CHANNELS);
1239+
_profile_limit[db->profile].max_channels);
12291240
return 0;
12301241
}
12311242

@@ -1261,6 +1272,7 @@ int iamf_database_init(IAMF_DataBase *db) {
12611272
db->mixPresentation = iamf_object_set_new(iamf_object_free);
12621273
db->eViewer.freeF = free;
12631274
db->pViewer.freeF = iamf_parameter_item_free;
1275+
db->profile = IAMF_PROFILE_DEFAULT;
12641276

12651277
if (!db->codecConf || !db->element || !db->mixPresentation) {
12661278
iamf_database_reset(db);
@@ -1288,13 +1300,27 @@ static int iamf_database_add_object(IAMF_DataBase *db, IAMF_Object *obj) {
12881300
if (!obj) return IAMF_ERR_BAD_ARG;
12891301

12901302
switch (obj->type) {
1291-
case IAMF_OBU_SEQUENCE_HEADER:
1303+
case IAMF_OBU_SEQUENCE_HEADER: {
1304+
IAMF_Version *version = (IAMF_Version *)obj;
1305+
1306+
if (version->primary_profile > db->profile) {
1307+
ia_loge("Unimplemented profile %u", version->primary_profile);
1308+
free(obj);
1309+
ret = IAMF_ERR_UNIMPLEMENTED;
1310+
break;
1311+
}
1312+
1313+
if (version->additional_profile < db->profile)
1314+
db->profile = version->additional_profile;
1315+
12921316
if (db->version) {
12931317
ia_logw("WARNING : Receive Multiple START CODE OBUs !!!");
12941318
free(db->version);
12951319
}
1320+
12961321
db->version = obj;
12971322
break;
1323+
}
12981324
case IAMF_OBU_CODEC_CONFIG:
12991325
ret = iamf_object_set_add(db->codecConf, (void *)obj);
13001326
break;

code/src/iamf_dec/IAMF_decoder_private.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ typedef struct IAMF_DataBase {
136136

137137
Viewer eViewer;
138138
Viewer pViewer;
139+
140+
IAMF_Profile profile;
139141
} IAMF_DataBase;
140142

141143
/* <<<<<<<<<<<<<<<<<< DATABASE <<<<<<<<<<<<<<<<<< */

code/src/iamf_dec/IAMF_types.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,12 @@ typedef struct MixFactors {
9292
int w_idx_offset;
9393
} MixFactors;
9494

95-
typedef enum { IAMF_PROFILE_SIMPLE, IAMF_PROFILE_BASE } IAMF_Profile;
95+
typedef enum {
96+
IAMF_PROFILE_SIMPLE,
97+
IAMF_PROFILE_BASE,
98+
IAMF_PROFILE_DEFAULT = IAMF_PROFILE_BASE,
99+
IAMF_PROFILE_COUNT,
100+
} IAMF_Profile;
96101

97102
#define U8_MASK 0xFF
98103
#define U16_MASK 0xFFFF
@@ -112,4 +117,15 @@ typedef enum { IAMF_PROFILE_SIMPLE, IAMF_PROFILE_BASE } IAMF_Profile;
112117
#define IA_CH_CATE_WEIGHT 0X200
113118
#define IA_CH_CATE_TOP 0X400
114119

120+
#define IAMF_AMBISONICS_MAX_CHANNELS 16
121+
#define IAMF_MIX_PRESENTATION_MAX_SUBS 1
122+
/// @brief should be able to reconstruct one Audio Element. in simple profile.
123+
#define IAMF_SIMPLE_PROFILE_MIX_PRESENTATION_MAX_ELEMENTS 1
124+
/// @brief should be able to handle up to 16 channels in simple profile.
125+
#define IAMF_SIMPLE_PROFILE_MIX_PRESENTATION_MAX_CHANNELS 16
126+
/// @brief should be able to mix two Audio Elements in base profile.
127+
#define IAMF_BASE_PROFILE_MIX_PRESENTATION_MAX_ELEMENTS 2
128+
/// @brief should be able to handle up to 18 channels in base profile.
129+
#define IAMF_BASE_PROFILE_MIX_PRESENTATION_MAX_CHANNELS 18
130+
115131
#endif /* IAMF_TYPES_H_ */

code/src/iamf_dec/h2m_rdr.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -995,9 +995,9 @@ struct h2m_rdr_t h2m_rdr_tab[] = {
995995
{IAMF_ZOA, BS2051_C, 8, 3, -1, (float *)zoa_bs250, 1, 7},
996996
{IAMF_ZOA, BS2051_D, 10, 3, -1, (float *)zoa_bs450, 1, 9},
997997
{IAMF_ZOA, BS2051_E, 11, 3, -1, (float *)zoa_bs451, 1, 10},
998-
{IAMF_ZOA, BS2051_F, 11, 10, 11, (float *)zoa_bs370, 1, 10},
999-
{IAMF_ZOA, BS2051_G, 12, 3, -1, (float *)zoa_bs490, 1, 13},
1000-
{IAMF_ZOA, BS2051_H, 24, 3, -1, (float *)zoa_bs9A3, 1, 22},
998+
{IAMF_ZOA, BS2051_F, 12, 10, 11, (float *)zoa_bs370, 1, 10},
999+
{IAMF_ZOA, BS2051_G, 14, 3, -1, (float *)zoa_bs490, 1, 13},
1000+
{IAMF_ZOA, BS2051_H, 24, 3, 9, (float *)zoa_bs9A3, 1, 22},
10011001
{IAMF_ZOA, BS2051_I, 8, 3, -1, (float *)zoa_bs070, 1, 7},
10021002
{IAMF_ZOA, BS2051_J, 12, 3, -1, (float *)zoa_bs470, 1, 11},
10031003
{IAMF_ZOA, IAMF_312, 6, 3, -1, (float *)zoa_iamf312, 1, 5},
@@ -1010,9 +1010,9 @@ struct h2m_rdr_t h2m_rdr_tab[] = {
10101010
{IAMF_FOA, BS2051_C, 8, 3, -1, (float *)foa_bs250, 4, 7},
10111011
{IAMF_FOA, BS2051_D, 10, 3, -1, (float *)foa_bs450, 4, 9},
10121012
{IAMF_FOA, BS2051_E, 11, 3, -1, (float *)foa_bs451, 4, 10},
1013-
{IAMF_FOA, BS2051_F, 11, 10, 11, (float *)foa_bs370, 4, 10},
1014-
{IAMF_FOA, BS2051_G, 12, 3, -1, (float *)foa_bs490, 4, 13},
1015-
{IAMF_FOA, BS2051_H, 24, 3, -1, (float *)foa_bs9A3, 4, 22},
1013+
{IAMF_FOA, BS2051_F, 12, 10, 11, (float *)foa_bs370, 4, 10},
1014+
{IAMF_FOA, BS2051_G, 14, 3, -1, (float *)foa_bs490, 4, 13},
1015+
{IAMF_FOA, BS2051_H, 24, 3, 9, (float *)foa_bs9A3, 4, 22},
10161016
{IAMF_FOA, BS2051_I, 8, 3, -1, (float *)foa_bs070, 4, 7},
10171017
{IAMF_FOA, BS2051_J, 12, 3, -1, (float *)foa_bs470, 4, 11},
10181018
{IAMF_FOA, IAMF_312, 6, 3, -1, (float *)foa_iamf312, 4, 5},
@@ -1025,9 +1025,9 @@ struct h2m_rdr_t h2m_rdr_tab[] = {
10251025
{IAMF_SOA, BS2051_C, 8, 3, -1, (float *)soa_bs250, 9, 7},
10261026
{IAMF_SOA, BS2051_D, 10, 3, -1, (float *)soa_bs450, 9, 9},
10271027
{IAMF_SOA, BS2051_E, 11, 3, -1, (float *)soa_bs451, 9, 10},
1028-
{IAMF_SOA, BS2051_F, 11, 10, 11, (float *)soa_bs370, 9, 10},
1029-
{IAMF_SOA, BS2051_G, 12, 3, -1, (float *)soa_bs490, 9, 13},
1030-
{IAMF_SOA, BS2051_H, 24, 3, -1, (float *)soa_bs9A3, 9, 22},
1028+
{IAMF_SOA, BS2051_F, 12, 10, 11, (float *)soa_bs370, 9, 10},
1029+
{IAMF_SOA, BS2051_G, 14, 3, -1, (float *)soa_bs490, 9, 13},
1030+
{IAMF_SOA, BS2051_H, 24, 3, 9, (float *)soa_bs9A3, 9, 22},
10311031
{IAMF_SOA, BS2051_I, 8, 3, -1, (float *)soa_bs070, 9, 7},
10321032
{IAMF_SOA, BS2051_J, 12, 3, -1, (float *)soa_bs470, 9, 11},
10331033
{IAMF_SOA, IAMF_312, 6, 3, -1, (float *)soa_iamf312, 9, 5},
@@ -1040,9 +1040,9 @@ struct h2m_rdr_t h2m_rdr_tab[] = {
10401040
{IAMF_TOA, BS2051_C, 8, 3, -1, (float *)toa_bs250, 16, 7},
10411041
{IAMF_TOA, BS2051_D, 10, 3, -1, (float *)toa_bs450, 16, 9},
10421042
{IAMF_TOA, BS2051_E, 11, 3, -1, (float *)toa_bs451, 16, 10},
1043-
{IAMF_TOA, BS2051_F, 11, 10, 11, (float *)toa_bs370, 16, 10},
1044-
{IAMF_TOA, BS2051_G, 12, 3, -1, (float *)toa_bs490, 16, 13},
1045-
{IAMF_TOA, BS2051_H, 24, 3, -1, (float *)toa_bs9A3, 16, 22},
1043+
{IAMF_TOA, BS2051_F, 12, 10, 11, (float *)toa_bs370, 16, 10},
1044+
{IAMF_TOA, BS2051_G, 14, 3, -1, (float *)toa_bs490, 16, 13},
1045+
{IAMF_TOA, BS2051_H, 24, 3, 9, (float *)toa_bs9A3, 16, 22},
10461046
{IAMF_TOA, BS2051_I, 8, 3, -1, (float *)toa_bs070, 16, 7},
10471047
{IAMF_TOA, BS2051_J, 12, 3, -1, (float *)toa_bs470, 16, 11},
10481048
{IAMF_TOA, IAMF_312, 6, 3, -1, (float *)toa_iamf312, 16, 5},

0 commit comments

Comments
 (0)