Skip to content

Commit

Permalink
Fragmented mp4 support (#47)
Browse files Browse the repository at this point in the history
* Fragmented mp4 support

Co-author: shikhashetgeri-861

[x] Added support for parsing boxes specific to
    fragmented MP4 (fMP4) format
Testing:
[x] Tested for conformance

* Addressed review comments

Testing:
[x] Same as previous commit

---------

Co-authored-by: Saketh Sathuvalli <100603@ittiam.com>
  • Loading branch information
SakethSathuvalli and Saketh Sathuvalli committed Mar 10, 2023
1 parent ec35a10 commit ecd1882
Show file tree
Hide file tree
Showing 7 changed files with 764 additions and 18 deletions.
16 changes: 1 addition & 15 deletions test/impeghd_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -726,25 +726,11 @@ IA_ERRORCODE impeghd_main_process(WORD32 argc, pWORD8 argv[])
{
pb_inp_buf[i] = pb_inp_buf[i + pstr_out_cfg->i_bytes_consumed];
}
g_pf_inp->is_execution = 1;
err_code = impeghd_mp4_fw_read(
g_pf_inp, (pUWORD8)(pb_inp_buf + i_buff_size - pstr_out_cfg->i_bytes_consumed),
((WORD32)ui_inp_size - (WORD32)(i_buff_size - pstr_out_cfg->i_bytes_consumed)),
(pUWORD32)&i_bytes_read);
if (err_code == 2)
{
if (g_pf_inp->is_mp4_file)
{
err_code = impeghd_mp4_get_datamp4(
g_pf_inp->mp4_cntxt, &offset_dash,
(pUWORD8)(pb_inp_buf + i_buff_size - pstr_out_cfg->i_bytes_consumed),
(ui_inp_size - (i_buff_size - pstr_out_cfg->i_bytes_consumed)),
(pUWORD32)&i_bytes_read, &size_dash, &loc);
if (err_code)
{
return err_code;
}
}
}
i_buff_size = i_buff_size - (pstr_out_cfg->i_bytes_consumed - i_bytes_read);
}
pstr_in_cfg->num_inp_bytes = i_buff_size;
Expand Down
134 changes: 134 additions & 0 deletions test/mp4/impeghd_mp4_atoms.h
Original file line number Diff line number Diff line change
Expand Up @@ -529,4 +529,138 @@ typedef struct ia_mp4_udta_atom
ia_mp4_udta_info udta_info;
} ia_mp4_udta_atom;

/*FMP4 Support atoms*/
typedef struct ia_mp4_mvex_atom
{
UWORD32 size;
UWORD32 type;
UWORD32 large_size;
UWORD32 version;
UWORD32 flags;
} ia_mp4_mvex_atom;

typedef struct ia_mp4_mehd_atom
{
UWORD32 size;
UWORD32 type;
UWORD32 large_size;
UWORD32 version;
UWORD32 flags;
UWORD32 duration;
} ia_mp4_mehd_atom;

typedef struct ia_mp4_trex_atom
{
UWORD32 size;
UWORD32 type;
UWORD32 large_size;
UWORD32 version;
UWORD32 flags;
UWORD32 track_ID;
UWORD8 is_initial_media_decode_time_added;
UWORD32 base_media_decode_time;
UWORD32 default_sample_description_index;
UWORD32 default_sample_duration;
UWORD32 default_sample_size;
UWORD32 default_sample_flags;
} ia_mp4_trex_atom;

typedef struct ia_mp4_pssh_atom
{
UWORD32 size;
UWORD32 type;
UWORD32 large_size;
UWORD32 version;
UWORD32 flags;
} ia_mp4_pssh_atom;

typedef struct ia_mp4_sidx_atom
{
UWORD32 size;
UWORD32 type;
UWORD32 large_size;
UWORD32 version;
UWORD32 flags;
UWORD32 Reference_ID;
UWORD32 time_scale;
UWORD32 earliest_presentation_time;
UWORD32 first_offset;
UWORD32 reserved;
UWORD32 reference_count;
} ia_mp4_sidx_atom;

typedef struct ia_mp4_moof_atom
{
UWORD32 size;
UWORD32 type;
UWORD32 large_size;
UWORD32 version;
UWORD32 flags;
} ia_mp4_moof_atom;

typedef struct ia_mp4_mfhd_atom
{
UWORD32 size;
UWORD32 type;
UWORD32 large_size;
UWORD32 version;
UWORD32 flags;
WORD32 sequence_number;
} ia_mp4_mfhd_atom;

typedef struct ia_mp4_tfhd_atom
{
UWORD32 size;
UWORD32 type;
UWORD32 large_size;
UWORD32 version;
UWORD32 flags;
UWORD32 track_ID;
UWORD64 base_data_offset;
UWORD32 sample_description_index;
UWORD32 default_sample_duration;
UWORD32 default_sample_size;
UWORD32 default_sample_flags;
} ia_mp4_tfhd_atom;

typedef struct ia_mp4_tfdt_atom
{
UWORD32 size;
UWORD32 type;
UWORD32 large_size;
UWORD32 version;
UWORD32 flags;
UWORD32 default_base_media_decode_time;
} ia_mp4_tfdt_atom;

typedef struct ia_mp4_trun_atom
{
UWORD32 size;
UWORD32 type;
UWORD32 large_size;
UWORD32 version;
UWORD32 flags;
UWORD32 samplecount;
WORD32 data_offset;
UWORD32 first_sample_flags;
} ia_mp4_trun_atom;

typedef struct ia_mp4_sbgp_atom
{
UWORD32 size;
UWORD32 type;
UWORD32 large_size;
UWORD32 version;
UWORD32 flags;
UWORD32 grouping_type;
WORD32 grouping_type_parameter_set;
UWORD32 entry_count;
} ia_mp4_sbgp_atom;

typedef struct ia_mp4_mdat_atom
{
UWORD32 size;
UWORD32 type;
UWORD32 large_size;
} ia_mp4_mdat_atom;
#endif /* IMPEGHD_MP4_ATOMS_H */
14 changes: 14 additions & 0 deletions test/mp4/impeghd_mp4_file_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
*/

WORD32 g_mhm1_tag;
WORD32 g_dash_tag;

/**
* impeghd_mp4_fw_open
Expand All @@ -72,6 +73,7 @@ ia_file_wrapper *impeghd_mp4_fw_open(WORD8 file_name[])
transport->is_mp4_mhm1 = 0;
transport->input_file = NULL;
g_mhm1_tag = 0;
g_dash_tag = 0;

transport->header_given = 0;
transport->file_cntxt = 0;
Expand Down Expand Up @@ -104,6 +106,7 @@ ia_file_wrapper *impeghd_mp4_fw_open(WORD8 file_name[])
}
transport->is_mp4_file = 1;
transport->is_mp4_mhm1 = g_mhm1_tag;
transport->is_mp4_dash = g_dash_tag;
transport->interim_buffer = impeghd_mp4_malloc_wrapper(IN_BUF_SIZE);
if (transport->interim_buffer == NULL)
{
Expand Down Expand Up @@ -152,6 +155,17 @@ WORD32 impeghd_mp4_fw_read(ia_file_wrapper *transport, pUWORD8 buffer, WORD32 bu
if (err_test == 2)
{
*length = 0;
if (transport->is_execution == 1)
{
err_test = impeghd_mp4_get_datamp4(
transport->mp4_cntxt, &(transport->offset_dash),
(pUWORD8)buffer, buf_size,
(pUWORD32)length, &(transport->size_dash), &(transport->loc));
if (err_test)
{
return err_test;
}
}
return IT_DASH;
}

Expand Down
5 changes: 5 additions & 0 deletions test/mp4/impeghd_mp4_file_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ typedef struct ia_file_wrapper
WORD32 header_given;
UWORD32 is_mp4_file;
UWORD32 is_mp4_mhm1;
UWORD32 is_mp4_dash;
FILE *input_file;
WORD32 size_dash;
WORD32 loc;
WORD32 offset_dash;
UWORD32 is_execution;

} ia_file_wrapper;

Expand Down
Loading

0 comments on commit ecd1882

Please sign in to comment.