Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
185 changes: 150 additions & 35 deletions test/impegh_mp4_mux_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -978,25 +978,88 @@ static ia_downmixInstruction* selectDownmixInstructions(ia_mpegh3daUniDrcConfig
return NULL;
}

static void deriveDrcChannelGroups(
const WORD32 drcSetEffect, /* in */
const WORD32 channelCount, /* in */
const WORD8* gainSetIndex, /* in */
UWORD8* nDrcChannelGroups, /* out */
WORD8* uniqueIndex, /* out (gainSetIndexForChannelGroup) */
WORD8* groupForChannel /* out */
)
{
WORD32 duckingSequence = -1;
WORD32 c, n, g, match, idx;
WORD16 uniqueScaling[28];

for (g = 0; g < 28; g++) {
uniqueIndex[g] = -10;
uniqueScaling[g] = (WORD16)(-1.0f);
}

g = 0;

{ /* no ducking */
for (c = 0; c < channelCount; c++) {
idx = gainSetIndex[c];
match = 0;
if (idx >= 0) {
for (n = 0; n < g; n++) {
if (uniqueIndex[n] == idx) {
match = 1;
groupForChannel[c] = n;
break;
}
}
if (match == 0) {
uniqueIndex[g] = idx;
groupForChannel[c] = g;
g++;
}
}
else {
groupForChannel[c] = -1;
}
}
}
*nDrcChannelGroups = g;
}

static VOID drcInstructionsUniDrc(ia_mpegh3daUniDrcConfig *mpegh3daUniDrcConfig_data, WORD32 idx, ia_bit_buf_struct *ptr_bit_buf, WORD32 baseChannelCount)
{
WORD32 channel_count = 0;
ia_drcInstructionsUniDrc *drcInstructionsUniDrc_data = &mpegh3daUniDrcConfig_data->drcInstructionsUniDrc_data[idx];
WORD8* gainSetIndex = drcInstructionsUniDrc_data->gainSetIndex;
WORD32 bsRepeatParametersCount;
WORD32 repeatParameters;
WORD32 repeatGainSetIndex;
WORD32 bsRepeatGainSetIndexCount;
WORD32 bsGainSetIndex;
WORD8 channelGroupForChannel[2 * 28];
drcInstructionsUniDrc_data->drcSetId = impegh_read_bits_buf(ptr_bit_buf, 6);
drcInstructionsUniDrc_data->drcLocation = impegh_read_bits_buf(ptr_bit_buf, 4);
drcInstructionsUniDrc_data->downmixId = impegh_read_bits_buf(ptr_bit_buf, 7);
drcInstructionsUniDrc_data->downmixId[0] = impegh_read_bits_buf(ptr_bit_buf, 7);
if (drcInstructionsUniDrc_data->downmixId[0] == 0)
{
drcInstructionsUniDrc_data->drcApplyToDownmix = 0;
}
else
{
drcInstructionsUniDrc_data->drcApplyToDownmix = 1;
}
drcInstructionsUniDrc_data->additionalDownmixIdPresent = impegh_read_bits_buf(ptr_bit_buf, 1);
if (drcInstructionsUniDrc_data->additionalDownmixIdPresent == 1)
{
drcInstructionsUniDrc_data->additionalDownmixIdCount = impegh_read_bits_buf(ptr_bit_buf, 3);
for (int j = 0; j < drcInstructionsUniDrc_data->additionalDownmixIdCount; j++)
{
drcInstructionsUniDrc_data->additionalDownmixId[j] = impegh_read_bits_buf(ptr_bit_buf, 7);
drcInstructionsUniDrc_data->downmixId[j + 1] = impegh_read_bits_buf(ptr_bit_buf, 7);
}
drcInstructionsUniDrc_data->downmixIdCount = 1 + drcInstructionsUniDrc_data->additionalDownmixIdCount;
}
else
{
drcInstructionsUniDrc_data->additionalDownmixIdCount = 0;
drcInstructionsUniDrc_data->downmixIdCount = 1;
}
drcInstructionsUniDrc_data->drcSetEffect = impegh_read_bits_buf(ptr_bit_buf, 16);
if ((drcInstructionsUniDrc_data->drcSetEffect & (3 << 10)) == 0)
Expand Down Expand Up @@ -1028,49 +1091,93 @@ static VOID drcInstructionsUniDrc(ia_mpegh3daUniDrcConfig *mpegh3daUniDrcConfig_
drcInstructionsUniDrc_data->noIndependentUse = impegh_read_bits_buf(ptr_bit_buf, 1);
}
channel_count = baseChannelCount;
drcInstructionsUniDrc_data->drcChannelCount = baseChannelCount;
if ((drcInstructionsUniDrc_data->drcSetEffect & (3 << 10)) != 0)
{
for (int i = 0; i < channel_count; i++)
int i = 0;
while (i < channel_count)
{
drcInstructionsUniDrc_data->bsGainSetIndex[i] = impegh_read_bits_buf(ptr_bit_buf, 6);
bsGainSetIndex = impegh_read_bits_buf(ptr_bit_buf, 6);
gainSetIndex[i] = bsGainSetIndex - 1;
drcInstructionsUniDrc_data->duckingScalingPresent[i] = impegh_read_bits_buf(ptr_bit_buf, 1);
if (drcInstructionsUniDrc_data->duckingScalingPresent[i] == 1)
{
drcInstructionsUniDrc_data->bsDuckingScaling[i] = impegh_read_bits_buf(ptr_bit_buf, 4);
}
drcInstructionsUniDrc_data->repeatParameters[i] = impegh_read_bits_buf(ptr_bit_buf, 1);
if (drcInstructionsUniDrc_data->repeatParameters[i])
i++;
repeatParameters = impegh_read_bits_buf(ptr_bit_buf, 1);
if (repeatParameters)
{
drcInstructionsUniDrc_data->bsRepeatParametersCount[i] = impegh_read_bits_buf(ptr_bit_buf, 5);
i = i + drcInstructionsUniDrc_data->bsRepeatParametersCount[i] + 1;
bsRepeatParametersCount = impegh_read_bits_buf(ptr_bit_buf, 5);
bsRepeatParametersCount += 1;
for (int j = 0; j < bsRepeatParametersCount; j++) {
gainSetIndex[i] = gainSetIndex[i - 1];
i++;
}
}
}
// deriveDrcChannelGroups()
}
else
{
WORD32 dmix_id = drcInstructionsUniDrc_data->downmixId;
WORD32 deriveChannelCount = 0;
WORD32 dmix_id = drcInstructionsUniDrc_data->downmixId[0];
WORD32 additional_dmix_id_cnt = drcInstructionsUniDrc_data->additionalDownmixIdCount;
if (dmix_id != 0 && dmix_id != 0x7F && additional_dmix_id_cnt == 0)
{
ia_downmixInstruction *pDmix = selectDownmixInstructions(mpegh3daUniDrcConfig_data, dmix_id);
channel_count = pDmix->targetChannelCount;
if (mpegh3daUniDrcConfig_data->downmixInstructions != 0)
{
ia_downmixInstruction *pDmix = selectDownmixInstructions(mpegh3daUniDrcConfig_data, dmix_id);
channel_count = pDmix->targetChannelCount; /* targetChannelCountFromDownmixId*/
}
else
{
deriveChannelCount = 1;
channel_count = 1;
}
}
else if (dmix_id != 0x7F || additional_dmix_id_cnt != 0)
else if (dmix_id == 0x7F || additional_dmix_id_cnt != 0)
{
channel_count = 1;
drcInstructionsUniDrc_data->drcChannelCount = 2 * 28;
channel_count = 1;
}
for (int i = 0; i < channel_count; i++)
int i = 0;
while (i < channel_count)
{
drcInstructionsUniDrc_data->bsGainSetIndex[i] = impegh_read_bits_buf(ptr_bit_buf, 6);
drcInstructionsUniDrc_data->repeatGainSetIndex[i] = impegh_read_bits_buf(ptr_bit_buf, 1);
if (drcInstructionsUniDrc_data->repeatGainSetIndex[i])
bsGainSetIndex = impegh_read_bits_buf(ptr_bit_buf, 6);
gainSetIndex[i] = bsGainSetIndex - 1;
i++;
repeatGainSetIndex = impegh_read_bits_buf(ptr_bit_buf, 1);
if (repeatGainSetIndex == 1)
{
drcInstructionsUniDrc_data->bsRepeatGainSetIndexCount[i] = impegh_read_bits_buf(ptr_bit_buf, 5);
i = i + drcInstructionsUniDrc_data->bsRepeatGainSetIndexCount[i] + 1;
bsRepeatGainSetIndexCount = impegh_read_bits_buf(ptr_bit_buf, 5);
bsRepeatGainSetIndexCount += 1;
if (deriveChannelCount)
{
channel_count = 1 + bsRepeatGainSetIndexCount;
}
for (int j = 0; j < bsRepeatGainSetIndexCount; j++)
{
gainSetIndex[i] = bsGainSetIndex - 1;
i++;
}
}
}
WORD32 nDrcChannelGroups = 0; // calculateNumDrcChannelGroups (Derivation of drcChannelGroups from gainSetIndices)
for (int i = 0; i < nDrcChannelGroups; i++)
if (deriveChannelCount) {
drcInstructionsUniDrc_data->drcChannelCount = channel_count;
}
/* DOWNMIX_ID_ANY_DOWNMIX: channelCount is 1. Distribute gainSetIndex to all channels. */
if ((drcInstructionsUniDrc_data->downmixId[0] == 0x7f) || (drcInstructionsUniDrc_data->downmixIdCount > 1)) {
for (int c = 1; c < drcInstructionsUniDrc_data->drcChannelCount; c++) {
gainSetIndex[c] = gainSetIndex[0];
}
}

deriveDrcChannelGroups(drcInstructionsUniDrc_data->drcSetEffect, drcInstructionsUniDrc_data->drcChannelCount, gainSetIndex,
&drcInstructionsUniDrc_data->nDrcChannelGroups, drcInstructionsUniDrc_data->gainSetIndexForChannelGroup,
channelGroupForChannel);

for (int i = 0; i < drcInstructionsUniDrc_data->nDrcChannelGroups; i++)
{
drcInstructionsUniDrc_data->gainScalingPresent[i] = impegh_read_bits_buf(ptr_bit_buf, 1);
if (drcInstructionsUniDrc_data->gainScalingPresent[i] == 1)
Expand Down Expand Up @@ -1247,8 +1354,8 @@ static VOID mpegh3daUniDrcConfig(ia_mpegh3daExtElementConfig *extElementConfig,
{
mpegh3daUniDrcConfig_data->mae_groupID[i] = impegh_read_bits_buf(ptr_bit_buf, 7);
}
drcInstructionsUniDrc(mpegh3daUniDrcConfig_data, i, ptr_bit_buf, baseChannelCount);
}
drcInstructionsUniDrc(mpegh3daUniDrcConfig_data, i, ptr_bit_buf, baseChannelCount);
}
mpegh3daUniDrcConfig_data->uniDrcConfigExtPresent = impegh_read_bits_buf(ptr_bit_buf, 1);
if (mpegh3daUniDrcConfig_data->uniDrcConfigExtPresent == 1)
Expand Down Expand Up @@ -1731,7 +1838,7 @@ WORD32 mpegh3daExtElementConfig(ia_bit_buf_struct *ptr_bit_buf, ia_mpegh3daCoreC
cnt_bits = ptr_bit_buf->cnt_bits;
EnhancedObjectMetadataConfig(pstr_mpegh3daExtElementConfig_data, ptr_bit_buf, numAudioObjects);
cnt_bits = cnt_bits - ptr_bit_buf->cnt_bits;
assert(cnt_bits < temp_bits_to_skip);
assert(cnt_bits <= temp_bits_to_skip);
temp_bits_to_skip = temp_bits_to_skip - cnt_bits;
impegh_read_bits_buf(ptr_bit_buf, temp_bits_to_skip);
break;
Expand Down Expand Up @@ -1770,7 +1877,7 @@ WORD32 mpegh3daExtElementConfig(ia_bit_buf_struct *ptr_bit_buf, ia_mpegh3daCoreC
*uniDrcConfigPresent = 1;
mpegh3daUniDrcConfig(pstr_mpegh3daExtElementConfig_data, ptr_bit_buf);
cnt_bits = cnt_bits - ptr_bit_buf->cnt_bits;
assert(cnt_bits < temp_bits_to_skip);
assert(cnt_bits <= temp_bits_to_skip);
temp_bits_to_skip = temp_bits_to_skip - cnt_bits;
impegh_read_bits_buf(ptr_bit_buf, temp_bits_to_skip);
//DRC data
Expand Down Expand Up @@ -1903,7 +2010,7 @@ WORD32 mpegh3daConfigExtension(ia_bit_buf_struct *ptr_bit_buf, ia_3d_audio_cnfg_
cnt_bits = ptr_bit_buf->cnt_bits;
downmixConfig(ptr_bit_buf, &pstr_mpegh3daConfigExtension_data->downmixConfig);
cnt_bits = cnt_bits - ptr_bit_buf->cnt_bits;
assert(cnt_bits < temp_bits_to_skip);
assert(cnt_bits <= temp_bits_to_skip);
temp_bits_to_skip = temp_bits_to_skip - cnt_bits;
impegh_read_bits_buf(ptr_bit_buf, temp_bits_to_skip);
break;
Expand Down Expand Up @@ -2011,13 +2118,13 @@ VOID ia_write_mhaD_dat(ia_bit_buf_struct *ptr_bit_buf, ia_3d_audio_cnfg_data *au
impegh_write_bits_buf(ptr_bit_buf, 0, 2); // reserved
impegh_write_bits_buf(ptr_bit_buf, drcCfg->drcInstructionsUniDrc_data[i].drcSetId, 6);
impegh_write_bits_buf(ptr_bit_buf, 0, 1); // reserved
impegh_write_bits_buf(ptr_bit_buf, drcCfg->drcInstructionsUniDrc_data[i].downmixId, 7);
impegh_write_bits_buf(ptr_bit_buf, drcCfg->drcInstructionsUniDrc_data[i].downmixId[0], 7);
impegh_write_bits_buf(ptr_bit_buf, 0, 5); // reserved
impegh_write_bits_buf(ptr_bit_buf, drcCfg->drcInstructionsUniDrc_data[i].additionalDownmixIdCount, 3);
for (int j = 0; j < drcCfg->drcInstructionsUniDrc_data[i].additionalDownmixIdCount; j++)
{
impegh_write_bits_buf(ptr_bit_buf, 0, 1); // reserved
impegh_write_bits_buf(ptr_bit_buf, drcCfg->drcInstructionsUniDrc_data[i].additionalDownmixId[j], 7);
impegh_write_bits_buf(ptr_bit_buf, drcCfg->drcInstructionsUniDrc_data[i].downmixId[j + 1], 7);
}
impegh_write_bits_buf(ptr_bit_buf, drcCfg->drcInstructionsUniDrc_data[i].drcSetEffect, 16);
impegh_write_bits_buf(ptr_bit_buf, 0, 7); // reserved
Expand Down Expand Up @@ -2204,13 +2311,17 @@ IA_ERRORCODE impegh_mhas_parse(ia_bit_buf_struct *ptr_bit_buf, ia_mhas_pac_info

WORD32 asi_packet_bits = 0, final_bits = 0;
asi_packet_bits = ptr_bit_buf->cnt_bits;

error = impegh_audio_scene_info_process(ptr_bit_buf, header_info);
if (error != IA_NO_ERROR)
if (header_info->asi_box_complete == 0)
{
return error;
//write only the first AUDIOSCENEINFO packet to mp4 box, later on skip parsing
error = impegh_audio_scene_info_process(ptr_bit_buf, header_info);
if (error != IA_NO_ERROR)
{
return error;
}
}

header_info->asi_box_complete = 1;
final_bits = asi_packet_bits - ptr_bit_buf->cnt_bits;
if (final_bits < (packet_length << 3))
{
Expand All @@ -2230,13 +2341,17 @@ IA_ERRORCODE impegh_mhas_parse(ia_bit_buf_struct *ptr_bit_buf, ia_mhas_pac_info
WORD32 config_packet_bits = 0, final_bits = 0;
config_packet_bits = ptr_bit_buf->cnt_bits;


error = impegh_3d_audio_config_data_process(ptr_bit_buf, header_info);
if (error != IA_NO_ERROR)
if (header_info->cnfg_box_complete == 0)
{
return error;
//write only the first MPEGH3DACFG packet to mp4 box, later on skip parsing
error = impegh_3d_audio_config_data_process(ptr_bit_buf, header_info);
if (error != IA_NO_ERROR)
{
return error;
}
}

header_info->cnfg_box_complete = 1;
final_bits = config_packet_bits - ptr_bit_buf->cnt_bits;
if (final_bits < (packet_length << 3))
{
Expand Down
28 changes: 13 additions & 15 deletions test/impegh_mp4_mux_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#include "impegh_error_codes_mux.h"
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX_SAMPLE_RATE (96000)
#define MAX_MAE_BUFFER_SIZE (100)
#define MAX_MAE_BUFFER_SIZE (10000)
#define MAX_MAE_NUM_DATASETS (15)

#define ID_MAE_GROUP_DESCRIPTION (0)
Expand Down Expand Up @@ -84,7 +84,7 @@
#define MAX_METADATA_ELEMENT_ID_COUNT (128)
#define MAX_GAIN_SET_COUNT (64)
#define MAX_BAND_COUNT (16)
#define MAX_ADDITIONAL_DMIX_COUNT (12)
#define MAX_DMIX_COUNT (8)
#define MAX_BASE_CHANNEL_COUNT (128)
#define MAX_DOWNMIX_ID_COUNT (32)
#define MAX_DOWNMIX_MATRIX_COUNT (16)
Expand Down Expand Up @@ -181,6 +181,8 @@ typedef struct packet_info
{
WORD32 sync_packet_bits;
WORD32 sync_packet_length;
WORD32 cnfg_box_complete;
WORD32 asi_box_complete;
WORD32 asi_packet_length;
WORD32 asi_packet_bits;
UWORD8 mhaD_buff[MAX_MAE_BUFFER_SIZE];
Expand Down Expand Up @@ -282,7 +284,7 @@ typedef struct
WORD8 mae_ContentDataGroupID[MAX_NUM_CONTENT_BLOCKS];
WORD8 mae_contentKind[MAX_NUM_CONTENT_BLOCKS];
WORD8 mae_hasContentLanguage[MAX_NUM_CONTENT_BLOCKS];
WORD32 mae_contentLanguage[MAX_NUM_DESCR_LANGUAGES];
WORD32 mae_contentLanguage[MAX_NUM_CONTENT_BLOCKS];
} ia_content_data_structure;

typedef struct
Expand Down Expand Up @@ -403,10 +405,11 @@ typedef struct
{
WORD8 drcSetId;
WORD8 drcLocation;
WORD8 downmixId;
WORD8 downmixIdCount;
WORD8 downmixId[MAX_DMIX_COUNT];
WORD8 drcApplyToDownmix;
WORD8 additionalDownmixIdPresent;
WORD8 additionalDownmixIdCount;
WORD8 additionalDownmixId[MAX_ADDITIONAL_DMIX_COUNT];
WORD32 drcSetEffect;
WORD8 limiterPeakTargetPresent;
WORD16 bsLimiterPeakTarget;
Expand All @@ -417,19 +420,14 @@ typedef struct
WORD8 dependsOnDrcSetPresent;
WORD8 dependsOnDrcSet;
WORD8 noIndependentUse;
WORD8 bsGainSetIndex[MAX_BASE_CHANNEL_COUNT];
WORD8 repeatGainSetIndex[MAX_BASE_CHANNEL_COUNT];
WORD8 gainSetIndex[2 * 28];
UWORD8 drcChannelCount;

//nDrcChannelGroups
WORD8 bsRepeatGainSetIndexCount[MAX_BASE_CHANNEL_COUNT];
WORD8 nDrcChannelGroups;
WORD8 gainSetIndexForChannelGroup[28];
WORD8 duckingScalingPresent[MAX_BASE_CHANNEL_COUNT];
WORD8 bsDuckingScaling[MAX_BASE_CHANNEL_COUNT];
WORD8 repeatParameters[MAX_BASE_CHANNEL_COUNT];
WORD8 bsRepeatParametersCount[MAX_BASE_CHANNEL_COUNT];
WORD8 nDrcChannelGroups[MAX_BASE_CHANNEL_COUNT];
WORD8 targetCharacteristicLeftIndex[MAX_BASE_CHANNEL_COUNT];
WORD8 targetCharacteristicRightPresent[MAX_BASE_CHANNEL_COUNT];
WORD8 targetCharacteristicRightIndex[MAX_BASE_CHANNEL_COUNT];
WORD8 gainScalingPresent[MAX_BASE_CHANNEL_COUNT];
WORD8 bsAttenuationScaling[MAX_BASE_CHANNEL_COUNT];
WORD8 bsAmplificationScaling[MAX_BASE_CHANNEL_COUNT];
Expand Down Expand Up @@ -539,7 +537,7 @@ typedef struct
typedef struct
{
WORD32 usacExtElementType;
WORD8 usacExtElementConfigLength;
WORD32 usacExtElementConfigLength;
WORD32 usacExtElementDefaultLengthPresent;
WORD32 usacExtElementDefaultLength;
WORD8 usacExtElementPayloadFrag;
Expand Down