Skip to content

Commit

Permalink
fixed #2606
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanlf committed Oct 4, 2023
1 parent bdda789 commit 8e9d6b3
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 8 deletions.
14 changes: 14 additions & 0 deletions include/gpac/isomedia.h
Original file line number Diff line number Diff line change
Expand Up @@ -1465,9 +1465,23 @@ typedef struct
{
/*! stream structure flags, 1: has channel layout, 2: has objects*/
u8 stream_structure;
/*! order of formats in the stream : 0 unknown, 1: Channels, possibly followed by Objects, 2 Objects, possibly followed by Channels*/
u8 format_ordering;
/*! combined channel count of the channel layout and the object count*/
u8 base_channel_count;

/*! defined CICP channel layout*/
u8 definedLayout;
/*! indicates where the ordering of the audio channels for the definedLayout are specified
0: as listed for the ChannelConfigurations in ISO/IEC 23091-3
1: Default order of audio codec specification
2: Channel ordering #2 of audio codec specification
3: Channel ordering #3 of audio codec specification
4: Channel ordering #4 of audio codec specification
*/
u8 channel_order_definition;
/*! indicates if omittedChannelsMap is present*/
u8 omitted_channels_present;

/*! number of channels*/
u32 channels_count;
Expand Down
74 changes: 66 additions & 8 deletions src/isomedia/box_code_base.c
Original file line number Diff line number Diff line change
Expand Up @@ -12676,15 +12676,29 @@ GF_Err chnl_box_read(GF_Box *s,GF_BitStream *bs)
GF_ChannelLayoutBox *ptr = (GF_ChannelLayoutBox *) s;

ISOM_DECREASE_SIZE(s, 1)
ptr->layout.stream_structure = gf_bs_read_u8(bs);
if (ptr->version==0) {
ptr->layout.stream_structure = gf_bs_read_u8(bs);
} else {
ptr->layout.stream_structure = gf_bs_read_int(bs, 4);
ptr->layout.format_ordering = gf_bs_read_int(bs, 4);
ISOM_DECREASE_SIZE(s, 1)
ptr->layout.base_channel_count = gf_bs_read_u8(bs);
}
if (ptr->layout.stream_structure & 1) {
ISOM_DECREASE_SIZE(s, 1)
ptr->layout.definedLayout = gf_bs_read_u8(bs);
if (ptr->layout.definedLayout==0) {
u32 remain = (u32) ptr->size;
if (ptr->layout.stream_structure & 2) remain--;
ptr->layout.channels_count = 0;
u32 nb_channels = 0;
if (ptr->version) {
ISOM_DECREASE_SIZE(s, 1)
nb_channels = gf_bs_read_u8(bs);
}
while (remain) {
if (ptr->layout.channels_count==64) return GF_ISOM_INVALID_FILE;

ISOM_DECREASE_SIZE(s, 1)
ptr->layout.layouts[ptr->layout.channels_count].position = gf_bs_read_u8(bs);
remain--;
Expand All @@ -12694,13 +12708,31 @@ GF_Err chnl_box_read(GF_Box *s,GF_BitStream *bs)
ptr->layout.layouts[ptr->layout.channels_count].elevation = gf_bs_read_int(bs, 8);
remain-=3;
}
ptr->layout.channels_count++;
if (ptr->version) {
nb_channels--;
if (!nb_channels) break;
}
}
} else {
ISOM_DECREASE_SIZE(s, 8)
ptr->layout.omittedChannelsMap = gf_bs_read_u64(bs);
if (ptr->version==0) {
ISOM_DECREASE_SIZE(s, 8)
ptr->layout.omittedChannelsMap = gf_bs_read_u64(bs);
ptr->layout.omitted_channels_present = 1;
ptr->layout.channel_order_definition = 0;
} else {
ISOM_DECREASE_SIZE(s, 1)
gf_bs_read_int(bs, 4);
ptr->layout.channel_order_definition = gf_bs_read_int(bs, 3);
ptr->layout.omitted_channels_present = gf_bs_read_int(bs, 1);
if (ptr->layout.omitted_channels_present) {
ISOM_DECREASE_SIZE(s, 8)
ptr->layout.omittedChannelsMap = gf_bs_read_u64(bs);
}
}
}
}
if (ptr->layout.stream_structure & 2) {
if ((ptr->version==0) && (ptr->layout.stream_structure & 2)) {
ISOM_DECREASE_SIZE(s, 1)
ptr->layout.object_count = gf_bs_read_u8(bs);
}
Expand All @@ -12724,10 +12756,20 @@ GF_Err chnl_box_write(GF_Box *s, GF_BitStream *bs)
if (e) return e;

gf_bs_write_u8(bs, ptr->layout.stream_structure);
if (ptr->version==0) {
gf_bs_write_u8(bs, ptr->layout.stream_structure);
} else {
gf_bs_write_int(bs, ptr->layout.stream_structure, 4);
gf_bs_write_int(bs, ptr->layout.format_ordering, 4);
gf_bs_write_u8(bs, ptr->layout.base_channel_count);
}
if (ptr->layout.stream_structure & 1) {
gf_bs_write_u8(bs, ptr->layout.definedLayout);
if (ptr->layout.definedLayout==0) {
u32 i;
if (ptr->version==1) {
gf_bs_write_u8(bs, ptr->layout.channels_count);
}
for (i=0; i<ptr->layout.channels_count; i++) {
gf_bs_write_u8(bs, ptr->layout.layouts[i].position);
if (ptr->layout.layouts[i].position==126) {
Expand All @@ -12736,10 +12778,18 @@ GF_Err chnl_box_write(GF_Box *s, GF_BitStream *bs)
}
}
} else {
gf_bs_write_u64(bs, ptr->layout.omittedChannelsMap);
if (ptr->version==1) {
gf_bs_write_int(bs, 0, 4);
gf_bs_write_int(bs, ptr->layout.channel_order_definition, 3);
gf_bs_write_int(bs, ptr->layout.omitted_channels_present, 1);
if (ptr->layout.omitted_channels_present)
gf_bs_write_u64(bs, ptr->layout.omittedChannelsMap);
} else {
gf_bs_write_u64(bs, ptr->layout.omittedChannelsMap);
}
}
}
if (ptr->layout.stream_structure & 2) {
if ((ptr->version==0) && (ptr->layout.stream_structure & 2)) {
gf_bs_write_u8(bs, ptr->layout.object_count);
}
return GF_OK;
Expand All @@ -12749,20 +12799,28 @@ GF_Err chnl_box_size(GF_Box *s)
{
GF_ChannelLayoutBox *ptr = (GF_ChannelLayoutBox *) s;
s->size += 1;
if (ptr->version==1) s->size++;
if (ptr->layout.stream_structure & 1) {
s->size += 1;
if (ptr->layout.definedLayout==0) {
u32 i;
if (ptr->version==1) s->size++;
for (i=0; i<ptr->layout.channels_count; i++) {
s->size+=1;
if (ptr->layout.layouts[i].position==126)
s->size+=3;
}
} else {
s->size += 8;
if (ptr->version==1) {
s->size += 1;
if (ptr->layout.omitted_channels_present)
s->size += 8;
} else {
s->size += 8;
}
}
}
if (ptr->layout.stream_structure & 2) {
if ((ptr->version==0) && (ptr->layout.stream_structure & 2)) {
s->size += 1;
}
return GF_OK;
Expand Down
4 changes: 4 additions & 0 deletions src/isomedia/isom_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -2512,6 +2512,10 @@ GF_Err gf_isom_set_audio_layout(GF_ISOFile *movie, u32 trackNumber, u32 sampleDe
e = CanAccessMovie(movie, GF_ISOM_OPEN_WRITE);
if (e) return e;

if (!layout) return GF_BAD_PARAM;
if ((layout->stream_structure & 1) && (layout->definedLayout==0) && (layout->channels_count>=64))
return GF_BAD_PARAM;

trak = gf_isom_get_track_from_file(movie, trackNumber);
if (!trak) return GF_BAD_PARAM;

Expand Down

0 comments on commit 8e9d6b3

Please sign in to comment.