Skip to content

Commit

Permalink
Merge pull request #811 from aureliendavid/udta-boxes
Browse files Browse the repository at this point in the history
udta boxes
  • Loading branch information
jeanlf committed Apr 26, 2017
2 parents 552a86d + 90c430e commit 0639a09
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 21 deletions.
7 changes: 4 additions & 3 deletions applications/mp4box/fileimport.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ typedef struct
GF_Err set_file_udta(GF_ISOFile *dest, u32 tracknum, u32 udta_type, char *src, Bool is_box_array)
{
char *data = NULL;
GF_Err res = GF_OK;
u32 size;
bin128 uuid;
memset(uuid, 0 , 16);
Expand Down Expand Up @@ -92,13 +93,13 @@ GF_Err set_file_udta(GF_ISOFile *dest, u32 tracknum, u32 udta_type, char *src, B

if (size && data) {
if (is_box_array) {
gf_isom_add_user_data_boxes(dest, tracknum, data, size);
res = gf_isom_add_user_data_boxes(dest, tracknum, data, size);
} else {
gf_isom_add_user_data(dest, tracknum, udta_type, uuid, data, size);
res = gf_isom_add_user_data(dest, tracknum, udta_type, uuid, data, size);
}
gf_free(data);
}
return GF_OK;
return res;
}

#ifndef GPAC_DISABLE_MEDIA_IMPORT
Expand Down
3 changes: 2 additions & 1 deletion applications/mp4box/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4879,7 +4879,8 @@ int mp4boxMain(int argc, char **argv)
needSave = GF_TRUE;
break;
case TRAC_ACTION_SET_UDTA:
set_file_udta(file, track, tka->udta_type, tka->src_name, tka->sample_num ? GF_TRUE : GF_FALSE);
e = set_file_udta(file, track, tka->udta_type, tka->src_name, tka->sample_num ? GF_TRUE : GF_FALSE);
if (e) goto err_exit;
needSave = GF_TRUE;
break;
default:
Expand Down
31 changes: 20 additions & 11 deletions src/isomedia/box_code_base.c
Original file line number Diff line number Diff line change
Expand Up @@ -3030,7 +3030,7 @@ GF_Err mdia_Read(GF_Box *s, GF_BitStream *bs)
if (!((GF_MediaBox *)s)->information) {
GF_LOG(GF_LOG_ERROR, GF_LOG_CONTAINER, ("[iso file] Missing MediaInformationBox\n"));
return GF_ISOM_INVALID_FILE;
}
}
if (!((GF_MediaBox *)s)->handler) {
GF_LOG(GF_LOG_ERROR, GF_LOG_CONTAINER, ("[iso file] Missing HandlerBox\n"));
return GF_ISOM_INVALID_FILE;
Expand Down Expand Up @@ -3753,7 +3753,7 @@ GF_Err moov_Read(GF_Box *s, GF_BitStream *bs)
if (!((GF_MovieBox *)s)->mvhd) {
GF_LOG(GF_LOG_ERROR, GF_LOG_CONTAINER, ("[iso file] Missing MovieHeaderBox\n"));
return GF_ISOM_INVALID_FILE;
}
}
}
return e;
}
Expand Down Expand Up @@ -5600,7 +5600,7 @@ GF_Err stsd_Read(GF_Box *s, GF_BitStream *bs)
{
gf_bs_read_u32(bs);
ISOM_DECREASE_SIZE(s, 4)

return gf_isom_box_array_read(s, bs, stsd_AddBox);
}

Expand Down Expand Up @@ -7431,7 +7431,7 @@ GF_Err reftype_Write(GF_Box *s, GF_BitStream *bs)
GF_TrackReferenceTypeBox *ptr = (GF_TrackReferenceTypeBox *)s;
ptr->type = ptr->reference_type;
if (!ptr->trackIDCount) return GF_OK;

e = gf_isom_box_write_header(s, bs);
ptr->type = GF_ISOM_BOX_TYPE_REFT;
if (e) return e;
Expand Down Expand Up @@ -7817,18 +7817,27 @@ GF_UserDataMap *udta_getEntry(GF_UserDataBox *ptr, u32 box_type, bin128 *uuid)
GF_Err udta_AddBox(GF_Box *s, GF_Box *a)
{
GF_Err e;
u32 box_type;
GF_UserDataMap *map;
GF_UserDataBox *ptr = (GF_UserDataBox *)s;
if (!ptr) return GF_BAD_PARAM;
if (!a) return GF_OK;

map = udta_getEntry(ptr, a->type, (a->type==GF_ISOM_BOX_TYPE_UUID) ? & ((GF_UUIDBox *)a)->uuid : NULL);
/* for unknown udta boxes, we reference them by their original box type */
box_type = a->type;
if (box_type == GF_ISOM_BOX_TYPE_UNKNOWN) {
GF_UnknownBox* unkn = (GF_UnknownBox *)a;
if (unkn)
box_type = unkn->original_4cc;
}

map = udta_getEntry(ptr, box_type, (a->type==GF_ISOM_BOX_TYPE_UUID) ? & ((GF_UUIDBox *)a)->uuid : NULL);
if (map == NULL) {
map = (GF_UserDataMap *) gf_malloc(sizeof(GF_UserDataMap));
if (map == NULL) return GF_OUT_OF_MEM;
memset(map, 0, sizeof(GF_UserDataMap));

map->boxType = a->type;
map->boxType = box_type;
if (a->type == GF_ISOM_BOX_TYPE_UUID)
memcpy(map->uuid, ((GF_UUIDBox *)a)->uuid, 16);
map->other_boxes = gf_list_new();
Expand Down Expand Up @@ -8072,7 +8081,7 @@ GF_Err sdtp_Read(GF_Box *s, GF_BitStream *bs)
/*out-of-order sdtp, assume no padding at the end*/
if (!ptr->sampleCount) ptr->sampleCount = (u32) ptr->size;
else if (ptr->sampleCount > (u32) ptr->size) return GF_ISOM_INVALID_FILE;

ptr->sample_info = (u8 *) gf_malloc(sizeof(u8)*ptr->sampleCount);
gf_bs_read_data(bs, (char*)ptr->sample_info, ptr->sampleCount);
ISOM_DECREASE_SIZE(ptr, ptr->sampleCount);
Expand Down Expand Up @@ -8969,7 +8978,7 @@ GF_Err leva_Read(GF_Box *s, GF_BitStream *bs)
level->grouping_type_parameter = gf_bs_read_u32(bs);
}
else if (level->type == 4) {
level->sub_track_id = gf_bs_read_u32(bs);
level->sub_track_id = gf_bs_read_u32(bs);
}
}
return GF_OK;
Expand Down Expand Up @@ -9416,7 +9425,7 @@ GF_Err sbgp_Size(GF_Box *s)

p->size += 8;
if (p->grouping_type_parameter) p->version=1;

if (p->version==1) p->size += 4;
p->size += 8*p->entry_count;
return GF_OK;
Expand Down Expand Up @@ -9514,7 +9523,7 @@ static void *sgpd_parse_entry(u32 grouping_type, GF_BitStream *bs, u32 entry_siz
}
return ptr;
}

case GF_ISOM_SAMPLE_GROUP_TRIF:
if (! entry_size) {
u32 flags = gf_bs_peek_bits(bs, 24, 0);
Expand Down Expand Up @@ -9756,7 +9765,7 @@ GF_Err sgpd_Size(GF_Box *s)
//we force all sample groups to version 1, v0 being deprecated
p->version=1;
p->size += 4;

if (p->version>=2) p->size += 4;
p->default_length = 0;

Expand Down
13 changes: 7 additions & 6 deletions src/isomedia/isom_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ static GF_Err isom_create_init_from_mem(const char *fileName, GF_ISOFile *file)
while (1) {
sep = strchr(val, ' ');
if (sep) sep[0] = 0;

if (!strncmp(val, "4cc=", 4)) strcpy(sz4cc, val+4);
else if (!strncmp(val, "init=", 5)) {
char szH[3], *data = val+5;
Expand Down Expand Up @@ -204,7 +204,7 @@ static GF_Err isom_create_init_from_mem(const char *fileName, GF_ISOFile *file)
if (!stricmp(sz4cc, "H264")) {
}
else if (!stricmp(sz4cc, "AACL")) {
}
}
else {
GF_LOG(GF_LOG_WARNING, GF_LOG_CONTAINER, ("[iso file] Cannot convert smooth media type %s to ISO init segment\n", sz4cc));
return GF_NOT_SUPPORTED;
Expand All @@ -224,7 +224,7 @@ static GF_Err isom_create_init_from_mem(const char *fileName, GF_ISOFile *file)
trak = (GF_TrackBox *) gf_isom_box_new(GF_ISOM_BOX_TYPE_TRAK);
trak->moov = file->moov;
gf_list_add(file->moov->trackList, trak);

trak->Header = (GF_TrackHeaderBox *) gf_isom_box_new(GF_ISOM_BOX_TYPE_TKHD);
trak->Header->trackID = 1;
trak->Header->flags |= 1;
Expand All @@ -251,7 +251,7 @@ static GF_Err isom_create_init_from_mem(const char *fileName, GF_ISOFile *file)

trak->dts_at_seg_start = tfdt;


if (!stricmp(sz4cc, "H264")) {
u32 pos = 0;
u32 end, sc_size=0;
Expand Down Expand Up @@ -327,7 +327,7 @@ static GF_Err isom_create_init_from_mem(const char *fileName, GF_ISOFile *file)

gf_list_add(trak->Media->information->sampleTable->SampleDescription->other_boxes, aac);
}

return GF_OK;
}

Expand Down Expand Up @@ -2296,6 +2296,7 @@ GF_Err gf_isom_get_user_data(GF_ISOFile *movie, u32 trackNumber, u32 UserDataTyp
data_size = p_uuid->dataSize;
data = p_uuid->data;
} else {
gf_isom_box_write((GF_Box *)ptr, bs);
continue;
}
s = data_size+8;
Expand Down Expand Up @@ -2609,7 +2610,7 @@ GF_Err gf_isom_reset_data_offset(GF_ISOFile *movie, u64 *top_box_start)
gf_isom_box_del((GF_Box *)_a);\
_a = __cast gf_isom_box_new(type);\
}\


GF_EXPORT
GF_Err gf_isom_reset_tables(GF_ISOFile *movie, Bool reset_sample_count)
Expand Down
1 change: 1 addition & 0 deletions src/isomedia/isom_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -2546,6 +2546,7 @@ GF_Err gf_isom_add_user_data_boxes(GF_ISOFile *movie, u32 trackNumber, char *dat
if (!trak->udta) trak_AddBox((GF_Box*)trak, gf_isom_box_new(GF_ISOM_BOX_TYPE_UDTA));
udta = trak->udta;
} else {
if (!movie->moov) return GF_BAD_PARAM;
if (!movie->moov->udta) moov_AddBox((GF_Box*)movie->moov, gf_isom_box_new(GF_ISOM_BOX_TYPE_UDTA));
udta = movie->moov->udta;
}
Expand Down

0 comments on commit 0639a09

Please sign in to comment.