Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions code/include/IAMF_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ int IAMF_layout_sound_system_channels_count(IAMF_SoundSystem ss);
* @brief Get the number of channels of binaural pattern.
* @return the number of channels.
*/
int IAMF_layout_binaural_channels_count();
int IAMF_layout_binaural_channels_count(void);

/**
* @brief Get the codec capability of iamf. Need to free string manually.
Expand All @@ -129,7 +129,7 @@ int IAMF_layout_binaural_channels_count();
* is three digits to indicate the value of the additional_profile.
* @return the supported codec string.
*/
char *IAMF_decoder_get_codec_capability();
char *IAMF_decoder_get_codec_capability(void);

/**
* @brief Set target normalization loudness value, then loudness will be
Expand Down
12 changes: 12 additions & 0 deletions code/include/IAMF_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ typedef enum IAMF_AnimationType {
ANIMATION_TYPE_LINEAR,
ANIMATION_TYPE_BEZIER
} IAMF_AnimationType;

/**
* Layout Syntax:
*
Expand Down Expand Up @@ -130,6 +131,12 @@ typedef struct IAMF_Layout {
* signed int (16) anchored_loudness;
* }
* }
*
* if (info_type & 0b11111100 > 0) {
* leb128() info_type_size;
* unsigned int (8 x info_type_size) info_type_bytes;
* }
*
* }
*
* */
Expand All @@ -143,9 +150,14 @@ typedef struct IAMF_LoudnessInfo {
uint8_t info_type;
int16_t integrated_loudness;
int16_t digital_peak;

int16_t true_peak;

uint8_t num_anchor_loudness;
anchor_loudness_t *anchor_loudness;

uint64_t info_type_size;
uint8_t *info_type_bytes;
} IAMF_LoudnessInfo;

/**
Expand Down
12 changes: 8 additions & 4 deletions code/src/iamf_dec/IAMF_OBU.c
Original file line number Diff line number Diff line change
Expand Up @@ -967,8 +967,10 @@ IAMF_MixPresentation *iamf_mix_presentation_new(IAMF_OBU *obu) {
}

if (loudness[i].info_type & ~LOUDNESS_INFO_TYPE_ALL) {
size = bs_getAleb128(&b);
bs_skipABytes(&b, size);
loudness[i].info_type_size = bs_getAleb128(&b);
loudness[i].info_type_bytes =
IAMF_MALLOC(uint8_t, loudness[i].info_type_size);
bs_read(&b, loudness[i].info_type_bytes, loudness[i].info_type_size);
ia_logd("extension loudness info size %" PRIu64, size);
}
}
Expand Down Expand Up @@ -1049,10 +1051,12 @@ void iamf_mix_presentation_free(IAMF_MixPresentation *obj) {
}

if (sub->loudness) {
for (int i = 0; i < sub->num_layouts; ++i)
for (int i = 0; i < sub->num_layouts; ++i) {
IAMF_FREE(sub->loudness[i].anchor_loudness);
IAMF_FREE(sub->loudness[i].info_type_bytes);
}
free(sub->loudness);
}
IAMF_FREE(sub->loudness);
}

free(obj->sub_mixes);
Expand Down
113 changes: 69 additions & 44 deletions code/src/iamf_dec/IAMF_decoder.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,46 @@ static int iamf_layout_channels_count(IAMF_Layout *layout) {
return ret;
}

static void iamf_layout_reset(IAMF_Layout *layout) {
if (layout) memset(layout, 0, sizeof(IAMF_Layout));
}

static int iamf_layout_copy(IAMF_Layout *dst, IAMF_Layout *src) {
memcpy(dst, src, sizeof(IAMF_Layout));
return IAMF_OK;
}

static int iamf_loudness_info_copy(IAMF_LoudnessInfo *dst,
IAMF_LoudnessInfo *src) {
if (!dst || !src) return IAMF_ERR_BAD_ARG;

dst->info_type = src->info_type;
dst->integrated_loudness = src->integrated_loudness;
dst->digital_peak = src->digital_peak;
dst->true_peak = src->true_peak;
dst->num_anchor_loudness = src->num_anchor_loudness;
if (src->num_anchor_loudness > 0) {
dst->anchor_loudness =
IAMF_MALLOCZ(anchor_loudness_t, src->num_anchor_loudness);

if (!dst->anchor_loudness) goto loudness_info_copy_fail;
for (int i = 0; i < src->num_anchor_loudness; i++) {
dst->anchor_loudness[i].anchor_element =
src->anchor_loudness[i].anchor_element;
dst->anchor_loudness[i].anchored_loudness =
src->anchor_loudness[i].anchored_loudness;
}
}
if (src->info_type_bytes) {
dst->info_type_bytes = IAMF_MALLOC(uint8_t, src->info_type_size);
if (!dst->info_type_bytes) goto loudness_info_copy_fail;
memcpy(dst->info_type_bytes, src->info_type_bytes, src->info_type_size);
dst->info_type_size = src->info_type_size;
}
return IAMF_OK;

loudness_info_copy_fail:
IAMF_FREE(dst->anchor_loudness);
IAMF_FREE(dst->info_type_bytes);
return IAMF_ERR_ALLOC_FAIL;
}

static int iamf_layout_copy2(IAMF_Layout *dst, TargetLayout *src) {
if (!src) return IAMF_ERR_BAD_ARG;
dst->type = src->type;
Expand All @@ -244,9 +275,7 @@ static void iamf_layout_dump(IAMF_Layout *layout) {

static void iamf_layout_info_free(LayoutInfo *layout) {
if (layout) {
if (layout->sp.sp_layout.predefined_sp)
free(layout->sp.sp_layout.predefined_sp);
iamf_layout_reset(&layout->layout);
IAMF_FREE(layout->sp.sp_layout.predefined_sp);
free(layout);
}
}
Expand Down Expand Up @@ -1401,7 +1430,6 @@ static int iamf_database_add_object(IAMF_DataBase *db, IAMF_Object *obj) {

if (version->primary_profile > db->profile) {
ia_loge("Unimplemented profile %u", version->primary_profile);
free(obj);
ret = IAMF_ERR_UNIMPLEMENTED;
break;
}
Expand Down Expand Up @@ -1676,7 +1704,7 @@ static IAMF_StreamDecoder *iamf_presentation_take_decoder(
IAMF_Presentation *pst, IAMF_Stream *stream) {
IAMF_StreamDecoder *decoder = 0;
for (int i = 0; i < pst->nb_streams; ++i) {
if (pst->decoders[i]->stream == stream) {
if (pst->decoders[i] && pst->decoders[i]->stream == stream) {
decoder = pst->decoders[i];
pst->decoders[i] = 0;
break;
Expand All @@ -1690,7 +1718,7 @@ static IAMF_StreamRenderer *iamf_presentation_take_renderer(
IAMF_Presentation *pst, IAMF_Stream *stream) {
IAMF_StreamRenderer *renderer = 0;
for (int i = 0; i < pst->nb_streams; ++i) {
if (pst->renderers[i]->stream == stream) {
if (pst->renderers[i] && pst->renderers[i]->stream == stream) {
renderer = pst->renderers[i];
pst->renderers[i] = 0;
break;
Expand Down Expand Up @@ -2258,7 +2286,7 @@ static uint32_t iamf_set_stream_info(IAMF_DecoderHandle handle) {
decoder = pst->decoders[i];
stream = pst->streams[i];
if (ctx->info.max_frame_size > stream->max_frame_size) {
for (int n = 0; i < DEC_BUF_CNT; ++n) {
for (int n = 0; n < DEC_BUF_CNT; ++n) {
float *buffer =
IAMF_REALLOC(float, decoder->buffers[n],
ctx->info.max_frame_size * stream->nb_channels);
Expand Down Expand Up @@ -2977,6 +3005,10 @@ static int iamf_stream_render(IAMF_StreamRenderer *sr, float *in, float *out,
return IAMF_OK;
}

static void iamf_mixer_clear(IAMF_Mixer *m) {
memset(m->frames, 0, m->nb_elements);
}

void iamf_mixer_reset(IAMF_Mixer *m) {
IAMF_FREE(m->element_ids);
IAMF_FREE(m->frames);
Expand Down Expand Up @@ -3300,15 +3332,6 @@ int iamf_decoder_internal_deliver(IAMF_DecoderHandle handle, IAMF_Frame *obj) {
if (obj->trim_start > 0)
ia_logd("trimming start %" PRIu64 " ", obj->trim_start);
if (obj->trim_end > 0) ia_logd("trimming end %" PRIu64, obj->trim_end);

#if 0
if (decoder->packet.sub_packets[idx]) {
/* when the frame of stream has been overwrite, the timestamp of stream
* should be elapsed and the global time should be updated together. */

stream->timestamp += decoder->frame_size;
}
#endif
}
iamf_stream_decoder_receive_packet(decoder, idx, obj);
}
Expand Down Expand Up @@ -4060,9 +4083,9 @@ static int iamf_extra_data_init(IAMF_DecoderHandle handle) {
for (int i = 0; i < metadata->num_loudness_layouts; ++i) {
iamf_layout_copy2(&metadata->loudness_layout[i],
ctx->presentation->obj->sub_mixes->layouts[i]);
iamf_loudness_info_copy(&metadata->loudness[i],
&pst->obj->sub_mixes->loudness[i]);
}
memcpy(metadata->loudness, pst->obj->sub_mixes->loudness,
sizeof(IAMF_LoudnessInfo) * metadata->num_loudness_layouts);

if (pst) {
ElementItem *ei;
Expand All @@ -4086,55 +4109,57 @@ static int iamf_extra_data_init(IAMF_DecoderHandle handle) {
}

static int iamf_extra_data_copy(IAMF_extradata *dst, IAMF_extradata *src) {
if (!src) return IAMF_ERR_BAD_ARG;

if (!dst) return IAMF_ERR_INTERNAL;
if (!src || !dst) return IAMF_ERR_BAD_ARG;

dst->output_sound_system = src->output_sound_system;
dst->number_of_samples = src->number_of_samples;
dst->bitdepth = src->bitdepth;
dst->sampling_rate = src->sampling_rate;
dst->num_loudness_layouts = src->num_loudness_layouts;
dst->output_sound_mode = src->output_sound_mode;
dst->loudness_layout = 0;
dst->loudness = 0;
dst->param = 0;

if (dst->num_loudness_layouts) {
dst->loudness_layout = IAMF_MALLOCZ(IAMF_Layout, dst->num_loudness_layouts);
dst->loudness = IAMF_MALLOCZ(IAMF_LoudnessInfo, dst->num_loudness_layouts);

if (!dst->loudness_layout || !dst->loudness) return IAMF_ERR_ALLOC_FAIL;
if (!dst->loudness_layout || !dst->loudness) goto alloc_fail;
for (int i = 0; i < dst->num_loudness_layouts; ++i) {
iamf_layout_copy(&dst->loudness_layout[i], &src->loudness_layout[i]);
memcpy(&dst->loudness[i], &src->loudness[i], sizeof(IAMF_LoudnessInfo));
iamf_loudness_info_copy(&dst->loudness[i], &src->loudness[i]);
}
} else {
dst->loudness_layout = 0;
dst->loudness = 0;
}

dst->num_parameters = src->num_parameters;

if (dst->num_parameters) {
dst->param = IAMF_MALLOCZ(IAMF_Param, dst->num_parameters);
if (!dst->param) return IAMF_ERR_ALLOC_FAIL;
if (!dst->param) goto alloc_fail;
for (int i = 0; i < src->num_parameters; ++i)
memcpy(&dst->param[i], &src->param[i], sizeof(IAMF_Param));
} else {
dst->param = 0;
}

return IAMF_OK;

alloc_fail:
IAMF_FREE(dst->loudness_layout);
IAMF_FREE(dst->loudness);
IAMF_FREE(dst->param);
return IAMF_ERR_ALLOC_FAIL;
}

void iamf_extra_data_reset(IAMF_extradata *data) {
if (data) {
if (data->loudness_layout) {
for (int i = 0; i < data->num_loudness_layouts; ++i)
iamf_layout_reset(&data->loudness_layout[i]);

free(data->loudness_layout);
IAMF_FREE(data->loudness_layout);
for (int i = 0; i < data->num_loudness_layouts; ++i) {
if (data->loudness) {
IAMF_FREE(data->loudness[i].anchor_loudness);
IAMF_FREE(data->loudness[i].info_type_bytes);
}
}

if (data->loudness) free(data->loudness);
IAMF_FREE(data->loudness);
if (data->param) free(data->param);

memset(data, 0, sizeof(IAMF_extradata));
Expand Down Expand Up @@ -4418,24 +4443,24 @@ char *IAMF_decoder_get_codec_capability() {

if (!ccs_str) return 0;

snprintf(cc_str, STRING_SIZE, "iamf.%.03u.%.03u.ipcm", IAMF_PROFILE_DEFAULT,
snprintf(cc_str, STRING_SIZE, "iamf.%.03d.%.03d.ipcm", IAMF_PROFILE_DEFAULT,
IAMF_PROFILE_DEFAULT);
strcat(ccs_str, cc_str);

#ifdef CONFIG_OPUS_CODEC
snprintf(cc_str, STRING_SIZE, ";iamf.%.03u.%.03u.Opus", IAMF_PROFILE_DEFAULT,
snprintf(cc_str, STRING_SIZE, ";iamf.%.03d.%.03d.Opus", IAMF_PROFILE_DEFAULT,
IAMF_PROFILE_DEFAULT);
strcat(ccs_str, cc_str);
#endif

#ifdef CONFIG_AAC_CODEC
snprintf(cc_str, STRING_SIZE, ";iamf.%.03u.%.03u.mp4a.40.2",
snprintf(cc_str, STRING_SIZE, ";iamf.%.03d.%.03d.mp4a.40.2",
IAMF_PROFILE_DEFAULT, IAMF_PROFILE_DEFAULT);
strcat(ccs_str, cc_str);
#endif

#ifdef CONFIG_FLAC_CODEC
snprintf(cc_str, STRING_SIZE, ";iamf.%.03u.%.03u.fLaC", IAMF_PROFILE_DEFAULT,
snprintf(cc_str, STRING_SIZE, ";iamf.%.03d.%.03d.fLaC", IAMF_PROFILE_DEFAULT,
IAMF_PROFILE_DEFAULT);
strcat(ccs_str, cc_str);
#endif
Expand Down
2 changes: 1 addition & 1 deletion code/src/iamf_dec/vlogging_tool_sr.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ static void write_codec_config_log(uint64_t idx, void* obu, char* log) {
log += write_yaml_form(log, 6, "total_samples_in_stream: %llu",
total_samples_in_stream);

char hex_string[20] = {
char hex_string[34] = {
0,
};
int pos = 0;
Expand Down
2 changes: 1 addition & 1 deletion code/test/tools/iamfdec/include/mp4demux.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ typedef struct {
int num_a_trak;
int sel_a_trak;
int cur_r_trak;
int trak_type[8];
int trak_type[32];
// video_wtr_t v_trak;
audio_rtr_t *a_trak;
struct {
Expand Down