Commit a1cc1ad6 authored by François Cartegnie's avatar François Cartegnie 🤞

demux: libmp4: add box reader iref

parent 17b98fe8
......@@ -4254,6 +4254,78 @@ static int MP4_ReadBox_SA3D( stream_t *p_stream, MP4_Box_t *p_box )
MP4_READBOX_EXIT( 1 );
}
static void MP4_FreeBox_Reference( MP4_Box_t *p_box )
{
MP4_Box_data_refbox_t *p_data = p_box->data.p_refbox;
free( p_data->p_references );
}
static int MP4_ReadBox_Reference( stream_t *p_stream, MP4_Box_t *p_box )
{
MP4_READBOX_ENTER( MP4_Box_data_refbox_t, MP4_FreeBox_Reference );
MP4_Box_data_refbox_t *p_data = p_box->data.p_refbox;
if( p_box->p_father->data.p_iref->i_flags == 0 )
MP4_GET2BYTES( p_data->i_from_item_id );
else
MP4_GET4BYTES( p_data->i_from_item_id );
MP4_GET2BYTES( p_data->i_reference_count );
if( i_read / sizeof(*p_data->p_references) < p_data->i_reference_count )
MP4_READBOX_EXIT( 0 );
p_data->p_references = malloc( sizeof(*p_data->p_references) *
p_data->i_reference_count );
if( !p_data->p_references )
MP4_READBOX_EXIT( 0 );
for( uint16_t i=0; i<p_data->i_reference_count; i++ )
{
if( p_box->p_father->data.p_iref == 0 )
MP4_GET2BYTES( p_data->p_references[i].i_to_item_id );
else
MP4_GET4BYTES( p_data->p_references[i].i_to_item_id );
}
MP4_READBOX_EXIT( 1 );
}
static int MP4_ReadBox_iref( stream_t *p_stream, MP4_Box_t *p_box )
{
MP4_READBOX_ENTER_PARTIAL( MP4_Box_data_iref_t, 12, NULL );
MP4_Box_data_iref_t *p_data = p_box->data.p_iref;
if( i_read < 4 )
MP4_READBOX_EXIT( 0 );
MP4_GET1BYTE( p_data->i_version );
MP4_GET3BYTES( p_data->i_flags );
if( p_data->i_version > 0 )
MP4_READBOX_EXIT( 0 );
assert( i_read == 0 );
uint32_t i = 0;
uint64_t i_remain = p_box->i_size - 12;
while ( i_remain > 8 )
{
MP4_Box_t *p_childbox = MP4_ReadBoxUsing( p_stream, p_box,
MP4_ReadBox_Reference );
if( !p_childbox || i_remain < p_childbox->i_size )
{
MP4_BoxFree( p_childbox );
break;
}
MP4_BoxAddChild( p_box, p_childbox );
i_remain -= p_childbox->i_size;
i++;
}
if ( MP4_Seek( p_stream, p_box->i_pos + p_box->i_size ) )
MP4_READBOX_EXIT( 0 );
MP4_READBOX_EXIT( 1 );
}
static void MP4_FreeBox_iloc( MP4_Box_t *p_box )
{
MP4_Box_data_iloc_t *p_data = p_box->data.p_iloc;
......@@ -5078,6 +5150,7 @@ static const struct
{ ATOM_iloc, MP4_ReadBox_iloc, ATOM_meta },
{ ATOM_iinf, MP4_ReadBox_iinf, ATOM_meta },
{ ATOM_infe, MP4_ReadBox_infe, ATOM_iinf },
{ ATOM_iref, MP4_ReadBox_iref, ATOM_meta },
{ ATOM_pitm, MP4_ReadBox_pitm, ATOM_meta },
/* HEIF specific meta references */
......
......@@ -400,6 +400,7 @@ typedef int64_t stime_t;
#define ATOM_iloc VLC_FOURCC('i','l','o','c')
#define ATOM_iinf VLC_FOURCC('i','i','n','f')
#define ATOM_infe VLC_FOURCC('i','n','f','e')
#define ATOM_iref VLC_FOURCC('i','r','e','f')
#define ATOM_pitm VLC_FOURCC('p','i','t','m')
/* HEIF specific meta */
#define ATOM_iprp VLC_FOURCC('i','p','r','p')
......@@ -1635,6 +1636,22 @@ typedef struct
uint32_t i_num_channels;
} MP4_Box_data_SA3D_t;
typedef struct
{
uint32_t i_from_item_id;
uint16_t i_reference_count;
struct
{
uint32_t i_to_item_id;
} *p_references;
} MP4_Box_data_refbox_t;
typedef struct
{
uint8_t i_version;
uint32_t i_flags;
} MP4_Box_data_iref_t;
typedef struct
{
uint8_t i_offset_size;
......@@ -1815,6 +1832,8 @@ typedef union MP4_Box_data_s
MP4_Box_data_cbmp_t *p_cbmp;
MP4_Box_data_SA3D_t *p_SA3D;
MP4_Box_data_refbox_t *p_refbox;
MP4_Box_data_iref_t *p_iref;
MP4_Box_data_iloc_t *p_iloc;
MP4_Box_data_iinf_t *p_iinf;
MP4_Box_data_infe_t *p_infe;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment