Changeset a7466071b44f9b07a1e7ff1d35ed70a954052ebe

Show
Ignore:
Timestamp:
07/02/08 21:57:30 (2 months ago)
Author:
Laurent Aimar <fenrir@videolan.org>
git-committer:
Laurent Aimar <fenrir@videolan.org> 1215028650 +0000
git-parent:

[8770fee892dd00dfcc812acabb5a39619247698f]

git-author:
Laurent Aimar <fenrir@videolan.org> 1215022687 +0000
Message:

Changed ASF_ReadObject_metadata to work like other functions.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/demux/asf/libasf.c

    r8770fee ra746607  
    313313        (asf_object_metadata_t *)p_obj; 
    314314 
    315     int i_peek, i_entries, i; 
    316     const uint8_t *p_peek; 
     315    int i_peek; 
     316    unsigned int i; 
     317    const uint8_t *p_peek, *p_data; 
    317318#ifdef ASF_DEBUG 
    318319    unsigned int j; 
    319320#endif 
    320321 
    321     if( stream_Peek( s, &p_peek, p_meta->i_object_size ) < 
     322    if( ( i_peek = stream_Peek( s, &p_peek, p_meta->i_object_size ) ) < 
    322323        __MAX( (int)p_meta->i_object_size, 26 ) ) 
    323324       return VLC_EGENERIC; 
    324325 
    325     p_meta->i_record_entries_count = 0; 
    326     p_meta->record = NULL; 
    327  
    328     i_peek = 24; 
    329     i_entries = GetWLE( p_peek + i_peek ); i_peek += 2; 
    330     for( i = 0; i < i_entries && i_peek < (int)p_meta->i_object_size -12; i++ ) 
    331     { 
    332         asf_metadata_record_t record; 
    333         int i_name, i_data, j; 
    334  
    335         if( GetWLE( p_peek + i_peek ) != 0 ) 
    336         { 
    337             ASF_FreeObject_metadata( p_obj ); 
    338             return VLC_EGENERIC; 
    339         } 
    340  
    341         i_peek += 2; 
    342         record.i_stream = GetWLE( p_peek + i_peek ); i_peek += 2; 
    343         i_name = GetWLE( p_peek + i_peek ); i_peek += 2; 
    344         record.i_type = GetWLE( p_peek + i_peek ); i_peek += 2; 
    345         i_data = GetDWLE( p_peek + i_peek ); i_peek += 4; 
    346  
    347         if( record.i_type > ASF_METADATA_TYPE_WORD || 
    348             i_peek + i_data + i_name > (int)p_meta->i_object_size ) 
    349         { 
    350             ASF_FreeObject_metadata( p_obj ); 
    351             return VLC_EGENERIC; 
    352         } 
    353  
    354         record.i_val = 0; 
    355         record.i_data = 0; 
    356         record.p_data = 0; 
    357  
    358         /* get name */ 
    359         record.psz_name = malloc( i_name/2 + 1 ); 
     326    p_meta->i_record_entries_count = GetWLE( p_peek + 24 ); 
     327 
     328    p_data = p_peek + 26; 
     329 
     330    p_meta->record = calloc( p_meta->i_record_entries_count, 
     331                             sizeof(asf_metadata_record_t) ); 
     332 
     333    for( i = 0; i < p_meta->i_record_entries_count; i++ ) 
     334    { 
     335        asf_metadata_record_t *p_record = &p_meta->record[i]; 
     336        int i_name; 
     337        int i_data; 
     338        int j; 
     339 
     340        if( &p_data[2+2+2+2+4] > &p_peek[i_peek] ) 
     341            break; 
     342 
     343        if( GetWLE( p_data ) != 0 ) 
     344            break; 
     345        p_data += 2; 
     346 
     347        p_record->i_stream = GetWLE( p_data ); p_data += 2; 
     348        i_name = GetWLE( p_data ); p_data += 2; 
     349        p_record->i_type = GetWLE( p_data ); p_data += 2; 
     350        i_data = GetDWLE( p_data ); p_data += 4; 
     351 
     352        if( &p_data[i_name+i_data] > &p_peek[i_peek] ) 
     353            break; 
     354 
     355        /* Read name */ 
     356        p_record->psz_name = malloc( i_name/2 + 1 ); 
    360357        for( j = 0; j < i_name/2; j++ ) 
    361358        { 
    362             record.psz_name[j] = GetWLE( p_peek + i_peek ); i_peek += 2; 
    363         } 
    364         record.psz_name[j] = 0; /* just to make sure */ 
    365  
    366         /* get data */ 
    367         if( record.i_type == ASF_METADATA_TYPE_STRING ) 
    368         { 
    369             record.p_data = malloc( i_data/2 + 1 ); 
    370             record.i_data = i_data/2; 
     359            p_record->psz_name[j] = GetWLE( p_data ); p_data += 2; 
     360        } 
     361        p_record->psz_name[j] = 0; 
     362 
     363        /* Read data */ 
     364        if( p_record->i_type == ASF_METADATA_TYPE_STRING ) 
     365        { 
     366            p_record->p_data = malloc( i_data/2 + 1 ); 
     367            p_record->i_data = i_data/2; /* FIXME Is that needed ? */ 
    371368            for( j = 0; j < i_data/2; j++ ) 
    372369            { 
    373                 record.p_data[j] = GetWLE( p_peek + i_peek ); i_peek += 2
     370                p_record->p_data[j] = GetWLE( &p_data[2*j] )
    374371            } 
    375             record.p_data[j] = 0; /* just to make sure */ 
    376         } 
    377         else if( record.i_type == ASF_METADATA_TYPE_BYTE ) 
    378         { 
    379             record.p_data = malloc( i_data ); 
    380             record.i_data = i_data; 
    381             memcpy( record.p_data, p_peek + i_peek, i_data ); 
    382             p_peek += i_data; 
     372            p_record->p_data[j] = 0; /* just to make sure */ 
     373 
     374            p_data += i_data; 
     375        } 
     376        else if( p_record->i_type == ASF_METADATA_TYPE_BYTE ) 
     377        { 
     378            p_record->p_data = malloc( i_data ); 
     379            p_record->i_data = i_data; 
     380            if( i_data > 0 ) 
     381                memcpy( p_record->p_data, p_data, i_data ); 
     382 
     383            p_data += i_data; 
     384        } 
     385        else if( p_record->i_type == ASF_METADATA_TYPE_QWORD ) 
     386        { 
     387            p_record->i_val = GetQWLE( p_data ); p_data += 8; 
     388        } 
     389        else if( p_record->i_type == ASF_METADATA_TYPE_DWORD ) 
     390        { 
     391            p_record->i_val = GetDWLE( p_data ); p_data += 4; 
     392        } 
     393        else if( p_record->i_type == ASF_METADATA_TYPE_WORD ) 
     394        { 
     395            p_record->i_val = GetWLE( p_data ); p_data += 2; 
     396        } 
     397        else if( p_record->i_type == ASF_METADATA_TYPE_BOOL ) 
     398        { 
     399            p_record->i_val = GetWLE( p_data ); p_data += 2; 
    383400        } 
    384401        else 
    385402        { 
    386             if( record.i_type == ASF_METADATA_TYPE_QWORD ) 
    387             { 
    388                 record.i_val = GetQWLE( p_peek + i_peek ); i_peek += 8; 
    389             } 
    390             else if( record.i_type == ASF_METADATA_TYPE_DWORD ) 
    391             { 
    392                 record.i_val = GetDWLE( p_peek + i_peek ); i_peek += 4; 
    393             } 
    394             else 
    395             { 
    396                 record.i_val = GetWLE( p_peek + i_peek ); i_peek += 2; 
    397             } 
    398         } 
    399  
    400         p_meta->i_record_entries_count++; 
    401         p_meta->record = 
    402             realloc( p_meta->record, p_meta->i_record_entries_count * 
    403                      sizeof(asf_metadata_record_t) ); 
    404         memcpy( &p_meta->record[p_meta->i_record_entries_count-1], 
    405                 &record, sizeof(asf_metadata_record_t) ); 
    406     } 
     403            /* Unknown */ 
     404            p_data += i_data; 
     405        } 
     406    } 
     407    p_meta->i_record_entries_count = i; 
    407408 
    408409#ifdef ASF_DEBUG 
     
    598599    ASF_GetGUID( &p_cl->i_reserved, p_peek + 24 ); 
    599600    p_cl->i_codec_entries_count = GetWLE( p_peek + 40 ); 
     601 
     602    p_data = p_peek + 44; 
     603 
    600604    if( p_cl->i_codec_entries_count > 0 ) 
    601605    { 
     
    603607                              sizeof( asf_codec_entry_t ) ); 
    604608 
    605         p_data = p_peek + 44; 
    606609        for( i_codec = 0; i_codec < p_cl->i_codec_entries_count; i_codec++ ) 
    607610        {