Commit 111e4939 authored by Francois Cartegnie's avatar Francois Cartegnie

demux: libmp4: add generic string reading function

parent 602ef2d0
......@@ -2852,27 +2852,27 @@ static int MP4_ReadBox_drms( stream_t *p_stream, MP4_Box_t *p_box )
return 1;
}
static int MP4_ReadBox_name( stream_t *p_stream, MP4_Box_t *p_box )
static int MP4_ReadBox_String( stream_t *p_stream, MP4_Box_t *p_box )
{
MP4_READBOX_ENTER( MP4_Box_data_name_t );
MP4_READBOX_ENTER( MP4_Box_data_string_t );
p_box->data.p_name->psz_text = malloc( p_box->i_size + 1 - 8 ); /* +\0, -name, -size */
if( p_box->data.p_name->psz_text == NULL )
p_box->data.p_string->psz_text = malloc( p_box->i_size + 1 - 8 ); /* +\0, -name, -size */
if( p_box->data.p_string->psz_text == NULL )
MP4_READBOX_EXIT( 0 );
memcpy( p_box->data.p_name->psz_text, p_peek, p_box->i_size - 8 );
p_box->data.p_name->psz_text[p_box->i_size - 8] = '\0';
memcpy( p_box->data.p_string->psz_text, p_peek, p_box->i_size - 8 );
p_box->data.p_string->psz_text[p_box->i_size - 8] = '\0';
#ifdef MP4_VERBOSE
msg_Dbg( p_stream, "read box: \"name\" text=`%s'",
p_box->data.p_name->psz_text );
msg_Dbg( p_stream, "read box: \"%4.4s\" text=`%s'", (char *) & p_box->i_type,
p_box->data.p_string->psz_text );
#endif
MP4_READBOX_EXIT( 1 );
}
static void MP4_FreeBox_name( MP4_Box_t *p_box )
static void MP4_FreeBox_String( MP4_Box_t *p_box )
{
FREENULL( p_box->data.p_name->psz_text );
FREENULL( p_box->data.p_string->psz_text );
}
static int MP4_ReadBox_data( stream_t *p_stream, MP4_Box_t *p_box )
......@@ -2902,9 +2902,9 @@ static int MP4_ReadBox_0xa9xxx( stream_t *p_stream, MP4_Box_t *p_box )
{
uint16_t i16;
MP4_READBOX_ENTER( MP4_Box_data_0xa9xxx_t );
MP4_READBOX_ENTER( MP4_Box_data_string_t );
p_box->data.p_0xa9xxx->psz_text = NULL;
p_box->data.p_string->psz_text = NULL;
MP4_GET2BYTES( i16 );
......@@ -2915,20 +2915,20 @@ static int MP4_ReadBox_0xa9xxx( stream_t *p_stream, MP4_Box_t *p_box )
MP4_GET2BYTES( i16 );
if( i_length >= i_read ) i_length = i_read + 1;
p_box->data.p_0xa9xxx->psz_text = malloc( i_length );
if( p_box->data.p_0xa9xxx->psz_text == NULL )
p_box->data.p_string->psz_text = malloc( i_length );
if( p_box->data.p_string->psz_text == NULL )
MP4_READBOX_EXIT( 0 );
i_length--;
memcpy( p_box->data.p_0xa9xxx->psz_text,
memcpy( p_box->data.p_string->psz_text,
p_peek, i_length );
p_box->data.p_0xa9xxx->psz_text[i_length] = '\0';
p_box->data.p_string->psz_text[i_length] = '\0';
#ifdef MP4_VERBOSE
msg_Dbg( p_stream,
"read box: \"c%3.3s\" text=`%s'",
((char*)&p_box->i_type + 1),
p_box->data.p_0xa9xxx->psz_text );
p_box->data.p_string->psz_text );
#endif
}
else
......@@ -2955,18 +2955,18 @@ static int MP4_ReadBox_0xa9xxx( stream_t *p_stream, MP4_Box_t *p_box )
{
// the rest is the text
i_data_len -= 12;
p_box->data.p_0xa9xxx->psz_text = malloc( i_data_len + 1 );
if( p_box->data.p_0xa9xxx->psz_text == NULL )
p_box->data.p_string->psz_text = malloc( i_data_len + 1 );
if( p_box->data.p_string->psz_text == NULL )
MP4_READBOX_EXIT( 0 );
memcpy( p_box->data.p_0xa9xxx->psz_text,
memcpy( p_box->data.p_string->psz_text,
p_peek, i_data_len );
p_box->data.p_0xa9xxx->psz_text[i_data_len] = '\0';
p_box->data.p_string->psz_text[i_data_len] = '\0';
#ifdef MP4_VERBOSE
msg_Dbg( p_stream,
"read box: \"c%3.3s\" text=`%s'",
((char*)&p_box->i_type+1),
p_box->data.p_0xa9xxx->psz_text );
p_box->data.p_string->psz_text );
#endif
}
else
......@@ -2980,7 +2980,7 @@ static int MP4_ReadBox_0xa9xxx( stream_t *p_stream, MP4_Box_t *p_box )
}
static void MP4_FreeBox_0xa9xxx( MP4_Box_t *p_box )
{
FREENULL( p_box->data.p_0xa9xxx->psz_text );
FREENULL( p_box->data.p_string->psz_text );
}
/* Chapter support */
......@@ -3735,7 +3735,7 @@ static const struct
{ ATOM_chpl, MP4_ReadBox_chpl, MP4_FreeBox_chpl, ATOM_udta },
{ ATOM_covr, MP4_ReadBoxContainer, MP4_FreeBox_Common, ATOM_udta },
{ ATOM_gnre, MP4_ReadBox_gnre, MP4_FreeBox_Common, ATOM_udta },
{ ATOM_name, MP4_ReadBox_name, MP4_FreeBox_name, ATOM_udta },
{ ATOM_name, MP4_ReadBox_String, MP4_FreeBox_String, ATOM_udta },
{ ATOM_trkn, MP4_ReadBox_trkn, MP4_FreeBox_Common, ATOM_udta },
/* iTunes/Quicktime meta info */
......
......@@ -1007,7 +1007,7 @@ typedef struct
{
char *psz_text;
} MP4_Box_data_name_t;
} MP4_Box_data_string_t;
typedef struct
{
......@@ -1382,10 +1382,8 @@ typedef union MP4_Box_data_s
MP4_Box_data_rmqu_t *p_rmqu;
MP4_Box_data_rmvc_t *p_rmvc;
MP4_Box_data_0xa9xxx_t *p_0xa9xxx;
MP4_Box_data_chpl_t *p_chpl;
MP4_Box_data_tref_generic_t *p_tref_generic;
MP4_Box_data_name_t *p_name;
MP4_Box_data_tfrf_t *p_tfrf;
MP4_Box_data_tfxd_t *p_tfxd;
......@@ -1394,6 +1392,8 @@ typedef union MP4_Box_data_s
MP4_Box_data_strf_t *p_strf; /* flip4mac Little endian video config */
MP4_Box_data_ASF_t *p_asf; /* flip4mac asf streams indicator */
/* for generic handlers */
MP4_Box_data_string_t *p_string;
MP4_Box_data_data_t *p_data;
void *p_payload; /* for unknow type */
......
......@@ -1476,7 +1476,7 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
case DEMUX_GET_META:
{
vlc_meta_t *p_meta = (vlc_meta_t *)va_arg( args, vlc_meta_t*);
MP4_Box_t *p_0xa9xxx;
MP4_Box_t *p_string;
MP4_Box_t *p_covr = MP4_BoxGet( p_sys->p_root, "/moov/udta/meta/ilst/covr/data[0]" );
if ( p_covr )
......@@ -1492,21 +1492,21 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
return VLC_SUCCESS;
}
for( p_0xa9xxx = p_udta->p_first; p_0xa9xxx != NULL;
p_0xa9xxx = p_0xa9xxx->p_next )
for( p_string = p_udta->p_first; p_string != NULL;
p_string = p_string->p_next )
{
if( !p_0xa9xxx || !BOXDATA(p_0xa9xxx) )
if( !p_string || !BOXDATA(p_string) )
continue;
/* FIXME FIXME: should convert from whatever the character
* encoding of MP4 meta data is to UTF-8. */
#define SET(fct) do { char *psz_utf = strdup( BOXDATA(p_0xa9xxx)->psz_text ? BOXDATA(p_0xa9xxx)->psz_text : "" ); \
#define SET(fct) do { char *psz_utf = strdup( BOXDATA(p_string)->psz_text ? BOXDATA(p_string)->psz_text : "" ); \
if( psz_utf ) { EnsureUTF8( psz_utf ); \
fct( p_meta, psz_utf ); free( psz_utf ); } } while(0)
/* XXX Becarefull p_udta can have box that are not 0xa9xx */
switch( p_0xa9xxx->i_type )
switch( p_string->i_type )
{
case ATOM_0xa9nam: /* Full name */
SET( vlc_meta_SetTitle );
......@@ -1531,8 +1531,8 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
break;
case ATOM_gnre:
if( p_0xa9xxx->data.p_gnre->i_genre <= NUM_GENRES )
vlc_meta_SetGenre( p_meta, ppsz_genres[p_0xa9xxx->data.p_gnre->i_genre - 1] );
if( p_string->data.p_gnre->i_genre <= NUM_GENRES )
vlc_meta_SetGenre( p_meta, ppsz_genres[p_string->data.p_gnre->i_genre - 1] );
break;
case ATOM_0xa9alb: /* Album */
......@@ -1546,12 +1546,12 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
{
char psz_trck[11];
snprintf( psz_trck, sizeof( psz_trck ), "%i",
p_0xa9xxx->data.p_trkn->i_track_number );
p_string->data.p_trkn->i_track_number );
vlc_meta_SetTrackNum( p_meta, psz_trck );
if( p_0xa9xxx->data.p_trkn->i_track_total > 0 )
if( p_string->data.p_trkn->i_track_total > 0 )
{
snprintf( psz_trck, sizeof( psz_trck ), "%i",
p_0xa9xxx->data.p_trkn->i_track_total );
p_string->data.p_trkn->i_track_total );
vlc_meta_Set( p_meta, vlc_meta_TrackTotal, psz_trck );
}
break;
......@@ -1620,9 +1620,9 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
};
for( unsigned i = 0; xa9typetoextrameta[i].xa9_type; i++ )
{
if( p_0xa9xxx->i_type == xa9typetoextrameta[i].xa9_type )
if( p_string->i_type == xa9typetoextrameta[i].xa9_type )
{
char *psz_utf = strdup( BOXDATA(p_0xa9xxx)->psz_text ? BOXDATA(p_0xa9xxx)->psz_text : "" );
char *psz_utf = strdup( BOXDATA(p_string)->psz_text ? BOXDATA(p_string)->psz_text : "" );
if( psz_utf )
{
EnsureUTF8( psz_utf );
......@@ -2739,12 +2739,10 @@ static void MP4_TrackCreate( demux_t *p_demux, mp4_track_t *p_track,
switch( p_box_iter->i_type )
{
case ATOM_0xa9nam:
p_track->fmt.psz_description =
strdup( p_box_iter->data.p_0xa9xxx->psz_text );
break;
case ATOM_name:
p_track->fmt.psz_description =
strdup( p_box_iter->data.p_name->psz_text );
strdup( p_box_iter->data.p_string->psz_text );
default:
break;
}
}
......
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