Skip to content

Commit

Permalink
1, Add more profile limitation. 2, fix some bugs in h2m
Browse files Browse the repository at this point in the history
  • Loading branch information
yilun-zhangs committed Jul 4, 2024
1 parent b93cf43 commit 067a207
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 46 deletions.
Binary file modified code/dep_external/lib/binaural/libiamf2bear.so
Binary file not shown.
22 changes: 11 additions & 11 deletions code/dep_external/src/binaural/iamf2bear/iamf2bear.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ static int getmodulepath(char *path, int buffsize)
int count = 0, i = 0;
#if defined(_WIN32)
count = GetModuleFileName(NULL, path, buffsize);
#elifdef __APPLE__
#elif defined(__APPLE__)
uint32_t size = MAX_PATH;
_NSGetExecutablePath(path, &size);
count = size;
Expand Down Expand Up @@ -231,17 +231,17 @@ extern "C" EXPORT_API int ConfigureBearDirectSpeakerChannel(void *pv_thiz,
std::make_pair(-180.0, 180.0),
std::make_pair(-90.0, 90.0),
true},
Channel{"M+110",
PolarPosition{110.0, 0.0},
PolarPosition{110.0, 0.0},
std::make_pair(100.0, 120.0),
std::make_pair(0.0, 15.0),
Channel{"U+030",
PolarPosition{30.0, 30.0},
PolarPosition{30.0, 30.0},
std::make_pair(30.0, 45.0),
std::make_pair(30.0, 55.0),
false},
Channel{"M-110",
PolarPosition{-110.0, 0.0},
PolarPosition{-110.0, 0.0},
std::make_pair(-120.0, -100.0),
std::make_pair(0.0, 15.0),
Channel{"U-030",
PolarPosition{-30.0, 30.0},
PolarPosition{-30.0, 30.0},
std::make_pair(-45.0, -30.0),
std::make_pair(30.0, 55.0),
false},
}};

Expand Down
5 changes: 0 additions & 5 deletions code/include/IAMF_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,4 @@ typedef enum {
IA_CHANNEL_LAYOUT_BINAURAL, // binaural
IA_CHANNEL_LAYOUT_COUNT
} IAChannelLayoutType;

#define IAMF_AMBISONICS_MAX_CHANNELS 16
#define IAMF_MIX_PRESENTATION_MAX_SUBS 1
#define IAMF_MIX_PRESENTATION_MAX_ELEMENTS 2
#define IAMF_MIX_PRESENTATION_MAX_CHANNELS 18
#endif /* IAMF_DEFINES_H */
17 changes: 7 additions & 10 deletions code/src/iamf_dec/IAMF_OBU.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ uint32_t iamf_obu_get_payload_size(IAMF_OBU *obu) {
return obu->size - (uint32_t)(obu->payload - obu->data);
}

static int _valid_profile(uint8_t profile) {
return profile == IAMF_PROFILE_SIMPLE || profile == IAMF_PROFILE_BASE;
static int _valid_profile(uint8_t primary, uint8_t addional) {
return primary < IAMF_PROFILE_COUNT && primary <= addional;
}

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

if (!_valid_profile(ver->primary_profile)) {
ia_loge("ia sequence header object: Invalid profile %u",
ver->primary_profile);
if (!_valid_profile(ver->primary_profile, ver->additional_profile)) {
ia_loge(
"ia sequence header object: Invalid primary profile %u or additional "
"profile %u.",
ver->primary_profile, ver->additional_profile);
goto version_fail;
}

Expand Down Expand Up @@ -756,11 +758,6 @@ IAMF_MixPresentation *iamf_mix_presentation_new(IAMF_OBU *obu) {
"Mix Presentation Object: num_audio_elements should not be set to "
"0.");
goto mix_presentation_fail;
} else if (val > 2) {
ia_logw(
"Mix Presentation Object: Do not support num_audio_elements more "
"than 2.");
goto mix_presentation_fail;
}

conf_s = IAMF_MALLOCZ(ElementConf, val);
Expand Down
40 changes: 33 additions & 7 deletions code/src/iamf_dec/IAMF_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ static int32_t FLOAT2INT24(float x) {

static int32_t FLOAT2INT32(float x) {
x = x * 2147483648.f;
x = MAX(x, -2147483648.f);
x = MIN(x, 2147483647.f);
return (int32_t)lrintf(x);
if (x > -2147483648.f && x < 2147483647.f)
return (int32_t)lrintf(x);
else
return (x > 0.0f ? 2147483647 : (-2147483647 - 1));
}

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

static struct {
uint32_t max_elements;
uint32_t max_channels;
} _profile_limit[IAMF_PROFILE_COUNT] = {
{IAMF_SIMPLE_PROFILE_MIX_PRESENTATION_MAX_ELEMENTS,
IAMF_SIMPLE_PROFILE_MIX_PRESENTATION_MAX_CHANNELS},
{IAMF_BASE_PROFILE_MIX_PRESENTATION_MAX_ELEMENTS,
IAMF_BASE_PROFILE_MIX_PRESENTATION_MAX_CHANNELS},
};

static int iamf_database_mix_presentation_is_valid(IAMF_DataBase *db,
IAMF_MixPresentation *mp) {
int ret = IAMF_OK;
Expand All @@ -1193,7 +1204,7 @@ static int iamf_database_mix_presentation_is_valid(IAMF_DataBase *db,

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

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

if (ret != IAMF_OK) return !ret;
if (channels > IAMF_MIX_PRESENTATION_MAX_CHANNELS) {
if (channels > _profile_limit[db->profile].max_channels) {
ia_logw("Mix Presentation %" PRId64 " has %d channels, more than %u",
mp->mix_presentation_id, channels,
IAMF_MIX_PRESENTATION_MAX_CHANNELS);
_profile_limit[db->profile].max_channels);
return 0;
}

Expand Down Expand Up @@ -1261,6 +1272,7 @@ int iamf_database_init(IAMF_DataBase *db) {
db->mixPresentation = iamf_object_set_new(iamf_object_free);
db->eViewer.freeF = free;
db->pViewer.freeF = iamf_parameter_item_free;
db->profile = IAMF_PROFILE_DEFAULT;

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

switch (obj->type) {
case IAMF_OBU_SEQUENCE_HEADER:
case IAMF_OBU_SEQUENCE_HEADER: {
IAMF_Version *version = (IAMF_Version *)obj;

if (version->primary_profile > db->profile) {
ia_loge("Unimplemented profile %u", version->primary_profile);
free(obj);
ret = IAMF_ERR_UNIMPLEMENTED;
break;
}

if (version->additional_profile < db->profile)
db->profile = version->additional_profile;

if (db->version) {
ia_logw("WARNING : Receive Multiple START CODE OBUs !!!");
free(db->version);
}

db->version = obj;
break;
}
case IAMF_OBU_CODEC_CONFIG:
ret = iamf_object_set_add(db->codecConf, (void *)obj);
break;
Expand Down
2 changes: 2 additions & 0 deletions code/src/iamf_dec/IAMF_decoder_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ typedef struct IAMF_DataBase {

Viewer eViewer;
Viewer pViewer;

IAMF_Profile profile;
} IAMF_DataBase;

/* <<<<<<<<<<<<<<<<<< DATABASE <<<<<<<<<<<<<<<<<< */
Expand Down
18 changes: 17 additions & 1 deletion code/src/iamf_dec/IAMF_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ typedef struct MixFactors {
int w_idx_offset;
} MixFactors;

typedef enum { IAMF_PROFILE_SIMPLE, IAMF_PROFILE_BASE } IAMF_Profile;
typedef enum {
IAMF_PROFILE_SIMPLE,
IAMF_PROFILE_BASE,
IAMF_PROFILE_DEFAULT = IAMF_PROFILE_BASE,
IAMF_PROFILE_COUNT,
} IAMF_Profile;

#define U8_MASK 0xFF
#define U16_MASK 0xFFFF
Expand All @@ -112,4 +117,15 @@ typedef enum { IAMF_PROFILE_SIMPLE, IAMF_PROFILE_BASE } IAMF_Profile;
#define IA_CH_CATE_WEIGHT 0X200
#define IA_CH_CATE_TOP 0X400

#define IAMF_AMBISONICS_MAX_CHANNELS 16
#define IAMF_MIX_PRESENTATION_MAX_SUBS 1
/// @brief should be able to reconstruct one Audio Element. in simple profile.
#define IAMF_SIMPLE_PROFILE_MIX_PRESENTATION_MAX_ELEMENTS 1
/// @brief should be able to handle up to 16 channels in simple profile.
#define IAMF_SIMPLE_PROFILE_MIX_PRESENTATION_MAX_CHANNELS 16
/// @brief should be able to mix two Audio Elements in base profile.
#define IAMF_BASE_PROFILE_MIX_PRESENTATION_MAX_ELEMENTS 2
/// @brief should be able to handle up to 18 channels in base profile.
#define IAMF_BASE_PROFILE_MIX_PRESENTATION_MAX_CHANNELS 18

#endif /* IAMF_TYPES_H_ */
24 changes: 12 additions & 12 deletions code/src/iamf_dec/h2m_rdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -995,9 +995,9 @@ struct h2m_rdr_t h2m_rdr_tab[] = {
{IAMF_ZOA, BS2051_C, 8, 3, -1, (float *)zoa_bs250, 1, 7},
{IAMF_ZOA, BS2051_D, 10, 3, -1, (float *)zoa_bs450, 1, 9},
{IAMF_ZOA, BS2051_E, 11, 3, -1, (float *)zoa_bs451, 1, 10},
{IAMF_ZOA, BS2051_F, 11, 10, 11, (float *)zoa_bs370, 1, 10},
{IAMF_ZOA, BS2051_G, 12, 3, -1, (float *)zoa_bs490, 1, 13},
{IAMF_ZOA, BS2051_H, 24, 3, -1, (float *)zoa_bs9A3, 1, 22},
{IAMF_ZOA, BS2051_F, 12, 10, 11, (float *)zoa_bs370, 1, 10},
{IAMF_ZOA, BS2051_G, 14, 3, -1, (float *)zoa_bs490, 1, 13},
{IAMF_ZOA, BS2051_H, 24, 3, 9, (float *)zoa_bs9A3, 1, 22},
{IAMF_ZOA, BS2051_I, 8, 3, -1, (float *)zoa_bs070, 1, 7},
{IAMF_ZOA, BS2051_J, 12, 3, -1, (float *)zoa_bs470, 1, 11},
{IAMF_ZOA, IAMF_312, 6, 3, -1, (float *)zoa_iamf312, 1, 5},
Expand All @@ -1010,9 +1010,9 @@ struct h2m_rdr_t h2m_rdr_tab[] = {
{IAMF_FOA, BS2051_C, 8, 3, -1, (float *)foa_bs250, 4, 7},
{IAMF_FOA, BS2051_D, 10, 3, -1, (float *)foa_bs450, 4, 9},
{IAMF_FOA, BS2051_E, 11, 3, -1, (float *)foa_bs451, 4, 10},
{IAMF_FOA, BS2051_F, 11, 10, 11, (float *)foa_bs370, 4, 10},
{IAMF_FOA, BS2051_G, 12, 3, -1, (float *)foa_bs490, 4, 13},
{IAMF_FOA, BS2051_H, 24, 3, -1, (float *)foa_bs9A3, 4, 22},
{IAMF_FOA, BS2051_F, 12, 10, 11, (float *)foa_bs370, 4, 10},
{IAMF_FOA, BS2051_G, 14, 3, -1, (float *)foa_bs490, 4, 13},
{IAMF_FOA, BS2051_H, 24, 3, 9, (float *)foa_bs9A3, 4, 22},
{IAMF_FOA, BS2051_I, 8, 3, -1, (float *)foa_bs070, 4, 7},
{IAMF_FOA, BS2051_J, 12, 3, -1, (float *)foa_bs470, 4, 11},
{IAMF_FOA, IAMF_312, 6, 3, -1, (float *)foa_iamf312, 4, 5},
Expand All @@ -1025,9 +1025,9 @@ struct h2m_rdr_t h2m_rdr_tab[] = {
{IAMF_SOA, BS2051_C, 8, 3, -1, (float *)soa_bs250, 9, 7},
{IAMF_SOA, BS2051_D, 10, 3, -1, (float *)soa_bs450, 9, 9},
{IAMF_SOA, BS2051_E, 11, 3, -1, (float *)soa_bs451, 9, 10},
{IAMF_SOA, BS2051_F, 11, 10, 11, (float *)soa_bs370, 9, 10},
{IAMF_SOA, BS2051_G, 12, 3, -1, (float *)soa_bs490, 9, 13},
{IAMF_SOA, BS2051_H, 24, 3, -1, (float *)soa_bs9A3, 9, 22},
{IAMF_SOA, BS2051_F, 12, 10, 11, (float *)soa_bs370, 9, 10},
{IAMF_SOA, BS2051_G, 14, 3, -1, (float *)soa_bs490, 9, 13},
{IAMF_SOA, BS2051_H, 24, 3, 9, (float *)soa_bs9A3, 9, 22},
{IAMF_SOA, BS2051_I, 8, 3, -1, (float *)soa_bs070, 9, 7},
{IAMF_SOA, BS2051_J, 12, 3, -1, (float *)soa_bs470, 9, 11},
{IAMF_SOA, IAMF_312, 6, 3, -1, (float *)soa_iamf312, 9, 5},
Expand All @@ -1040,9 +1040,9 @@ struct h2m_rdr_t h2m_rdr_tab[] = {
{IAMF_TOA, BS2051_C, 8, 3, -1, (float *)toa_bs250, 16, 7},
{IAMF_TOA, BS2051_D, 10, 3, -1, (float *)toa_bs450, 16, 9},
{IAMF_TOA, BS2051_E, 11, 3, -1, (float *)toa_bs451, 16, 10},
{IAMF_TOA, BS2051_F, 11, 10, 11, (float *)toa_bs370, 16, 10},
{IAMF_TOA, BS2051_G, 12, 3, -1, (float *)toa_bs490, 16, 13},
{IAMF_TOA, BS2051_H, 24, 3, -1, (float *)toa_bs9A3, 16, 22},
{IAMF_TOA, BS2051_F, 12, 10, 11, (float *)toa_bs370, 16, 10},
{IAMF_TOA, BS2051_G, 14, 3, -1, (float *)toa_bs490, 16, 13},
{IAMF_TOA, BS2051_H, 24, 3, 9, (float *)toa_bs9A3, 16, 22},
{IAMF_TOA, BS2051_I, 8, 3, -1, (float *)toa_bs070, 16, 7},
{IAMF_TOA, BS2051_J, 12, 3, -1, (float *)toa_bs470, 16, 11},
{IAMF_TOA, IAMF_312, 6, 3, -1, (float *)toa_iamf312, 16, 5},
Expand Down

0 comments on commit 067a207

Please sign in to comment.