Changeset 2fc62e061142cb3f3062a353678db6890fc6776b

Show
Ignore:
Timestamp:
06/28/02 21:31:40 (6 years ago)
Author:
Laurent Aimar <fenrir@videolan.org>
git-committer:
Laurent Aimar <fenrir@videolan.org> 1025292700 +0000
git-parent:

[660db6d87715f5b677edbb8fddd071ad236511eb]

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

plugins/avi/avi.c : audio seems to be better.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/avi/avi.c

    r3a31acc r2fc62e0  
    33 ***************************************************************************** 
    44 * Copyright (C) 2001 VideoLAN 
    5  * $Id: avi.c,v 1.24 2002/06/27 19:05:17 sam Exp $ 
     5 * $Id: avi.c,v 1.25 2002/06/28 19:31:40 fenrir Exp $ 
    66 * Authors: Laurent Aimar <fenrir@via.ecp.fr> 
    77 *  
     
    162162 
    163163 
    164 static inline int __AVI_GetESTypeFromTwoCC( u16 i_type ) 
     164static inline int AVI_GetESTypeFromTwoCC( u16 i_type ) 
    165165{ 
    166166    switch( i_type ) 
     
    171171         case( TWOCC_db ): 
    172172            return( VIDEO_ES ); 
    173     } 
    174     return( UNKNOWN_ES ); 
     173         default: 
     174            return( UNKNOWN_ES ); 
     175    } 
    175176} 
    176177 
     
    222223            return( MSMPEG4v3_VIDEO_ES ); 
    223224 
    224  
    225225        case( FOURCC_DIVX ): 
    226226        case( FOURCC_divx ): 
     
    332332 
    333333 
    334  
    335  
    336  
    337  
    338  
    339 static void __AVIFreeDemuxData( input_thread_t *p_input ) 
    340 { 
    341     int i; 
    342     demux_data_avi_file_t *p_avi_demux; 
    343     p_avi_demux = (demux_data_avi_file_t*)p_input->p_demux_data  ;  
    344      
    345     if( p_avi_demux->p_riff != NULL )  
    346             RIFF_DeleteChunk( p_input, p_avi_demux->p_riff ); 
    347     if( p_avi_demux->p_hdrl != NULL )  
    348             RIFF_DeleteChunk( p_input, p_avi_demux->p_hdrl ); 
    349     if( p_avi_demux->p_movi != NULL )  
    350             RIFF_DeleteChunk( p_input, p_avi_demux->p_movi ); 
    351     if( p_avi_demux->p_idx1 != NULL )  
    352             RIFF_DeleteChunk( p_input, p_avi_demux->p_idx1 ); 
    353     if( p_avi_demux->pp_info != NULL ) 
    354     { 
    355         for( i = 0; i < p_avi_demux->i_streams; i++ ) 
    356         { 
    357             if( p_avi_demux->pp_info[i] != NULL )  
    358             { 
    359                 if( p_avi_demux->pp_info[i]->p_index != NULL ) 
    360                 { 
    361                       free( p_avi_demux->pp_info[i]->p_index ); 
    362                       AVI_PESBuffer_Flush( p_input->p_method_data, p_avi_demux->pp_info[i] ); 
    363                 } 
    364                 free( p_avi_demux->pp_info[i] );  
    365             } 
    366         } 
    367          free( p_avi_demux->pp_info ); 
    368     } 
    369 } 
    370  
    371334static void AVI_ParseStreamHeader( u32 i_id, int *i_number, int *i_type ) 
    372335{ 
     
    503466            if( ( i_number <  p_avi_demux->i_streams ) 
    504467               &&(p_avi_demux->pp_info[i_number]->i_cat ==  
    505                      __AVI_GetESTypeFromTwoCC( i_type )))  
     468                     AVI_GetESTypeFromTwoCC( i_type )))  
    506469            { 
    507470                __AVI_AddEntryIndex( p_avi_demux->pp_info[i_number], 
     
    552515} 
    553516 
    554  
    555 #if 0 
    556 FILE *DumpAudio; 
    557 #endif 
     517/***************************************************************************** 
     518 * AVIEnd: frees unused data 
     519 *****************************************************************************/ 
     520static void AVIEnd( input_thread_t *p_input ) 
     521{    
     522    int i; 
     523    demux_data_avi_file_t *p_avi_demux; 
     524    p_avi_demux = (demux_data_avi_file_t*)p_input->p_demux_data  ;  
     525     
     526    if( p_avi_demux->p_riff )  
     527            RIFF_DeleteChunk( p_input, p_avi_demux->p_riff ); 
     528    if( p_avi_demux->p_hdrl )  
     529            RIFF_DeleteChunk( p_input, p_avi_demux->p_hdrl ); 
     530    if( p_avi_demux->p_movi )  
     531            RIFF_DeleteChunk( p_input, p_avi_demux->p_movi ); 
     532    if( p_avi_demux->p_idx1 )  
     533            RIFF_DeleteChunk( p_input, p_avi_demux->p_idx1 ); 
     534    if( p_avi_demux->pp_info ) 
     535    { 
     536        for( i = 0; i < p_avi_demux->i_streams; i++ ) 
     537        { 
     538            if( p_avi_demux->pp_info[i] )  
     539            { 
     540                if( p_avi_demux->pp_info[i]->p_index ) 
     541                { 
     542                      free( p_avi_demux->pp_info[i]->p_index ); 
     543                      AVI_PESBuffer_Flush( p_input->p_method_data,  
     544                                           p_avi_demux->pp_info[i] ); 
     545                } 
     546                free( p_avi_demux->pp_info[i] );  
     547            } 
     548        } 
     549         free( p_avi_demux->pp_info ); 
     550    } 
     551
    558552 
    559553/***************************************************************************** 
     
    590584    if( RIFF_TestFileHeader( p_input, &p_riff, FOURCC_AVI ) != 0 )     
    591585    { 
    592         __AVIFreeDemuxData( p_input ); 
     586        AVIEnd( p_input ); 
    593587        msg_Warn( p_input, "RIFF-AVI module discarded" ); 
    594588        return( -1 ); 
     
    598592    if ( RIFF_DescendChunk(p_input) != 0 ) 
    599593    { 
    600         __AVIFreeDemuxData( p_input ); 
     594        AVIEnd( p_input ); 
    601595        msg_Err( p_input, "cannot look for subchunk" ); 
    602596        return ( -1 ); 
     
    606600    if( RIFF_FindListChunk(p_input ,&p_hdrl,p_riff, FOURCC_hdrl) != 0 ) 
    607601    { 
    608         __AVIFreeDemuxData( p_input ); 
     602        AVIEnd( p_input ); 
    609603        msg_Err( p_input, "cannot find \"LIST-hdrl\"" ); 
    610604        return( -1 ); 
     
    614608    if( RIFF_DescendChunk(p_input) != 0 ) 
    615609    { 
    616         __AVIFreeDemuxData( p_input ); 
     610        AVIEnd( p_input ); 
    617611        msg_Err( p_input, "cannot look for subchunk" ); 
    618612        return ( -1 ); 
     
    622616                                    &p_avih, FOURCC_avih ) != 0 ) 
    623617    { 
    624         __AVIFreeDemuxData( p_input ); 
     618        AVIEnd( p_input ); 
    625619        msg_Err( p_input, "cannot find \"avih\" chunk" ); 
    626620        return( -1 ); 
     
    632626    /* no stream found, perhaps it would be cool to find it */ 
    633627    { 
    634         __AVIFreeDemuxData( p_input ); 
     628        AVIEnd( p_input ); 
    635629        msg_Err( p_input, "no stream defined!" ); 
    636630        return( -1 ); 
     
    642636    { 
    643637        vlc_mutex_unlock( &p_input->stream.stream_lock ); 
    644         __AVIFreeDemuxData( p_input ); 
     638        AVIEnd( p_input ); 
    645639        msg_Err( p_input, "cannot init stream" ); 
    646640        return( -1 ); 
     
    649643    { 
    650644        vlc_mutex_unlock( &p_input->stream.stream_lock ); 
    651         __AVIFreeDemuxData( p_input ); 
     645        AVIEnd( p_input ); 
    652646        msg_Err( p_input, "cannot add program" ); 
    653647        return( -1 ); 
     
    662656    p_avi_demux->pp_info = calloc( p_avi_demux->i_streams,  
    663657                                    sizeof( AVIStreamInfo_t* ) ); 
    664     memset( p_avi_demux->pp_info, 0,  
    665                         sizeof( AVIStreamInfo_t* ) * p_avi_demux->i_streams ); 
     658    memset( p_avi_demux->pp_info,  
     659            0,  
     660            sizeof( AVIStreamInfo_t* ) * p_avi_demux->i_streams ); 
    666661 
    667662    for( i = 0 ; i < p_avi_demux->i_streams; i++ ) 
     
    675670                ||( RIFF_DescendChunk(p_input) != 0 )) 
    676671        { 
    677             __AVIFreeDemuxData( p_input ); 
     672            AVIEnd( p_input ); 
    678673            msg_Err( p_input, "cannot find \"LIST-strl\"" ); 
    679674            return( -1 ); 
     
    685680        { 
    686681            RIFF_DeleteChunk( p_input, p_strl ); 
    687             __AVIFreeDemuxData( p_input ); 
     682            AVIEnd( p_input ); 
    688683            msg_Err( p_input, "cannot find \"strh\"" ); 
    689684            return( -1 ); 
     
    698693        { 
    699694            RIFF_DeleteChunk( p_input, p_strl ); 
    700             __AVIFreeDemuxData( p_input ); 
     695            AVIEnd( p_input ); 
    701696            msg_Err( p_input, "cannot find \"strf\"" ); 
    702697            return( -1 ); 
     
    707702            RIFF_DeleteChunk( p_input, p_strf ); 
    708703            RIFF_DeleteChunk( p_input, p_strl ); 
    709             __AVIFreeDemuxData( p_input ); 
     704            AVIEnd( p_input ); 
    710705            msg_Err( p_input, "cannot go out (\"strl\")" ); 
    711706            return( -1 ); 
     
    772767    if( RIFF_AscendChunk(p_input, p_hdrl) != 0) 
    773768    { 
    774         __AVIFreeDemuxData( p_input ); 
     769        AVIEnd( p_input ); 
    775770        msg_Err( p_input, "cannot go out (\"hdrl\")" ); 
    776771        return( -1 ); 
     
    781776    { 
    782777        msg_Err( p_input, "cannot find \"LIST-movi\"" ); 
    783         __AVIFreeDemuxData( p_input ); 
     778        AVIEnd( p_input ); 
    784779        return( -1 ); 
    785780    } 
     
    798793        if( RIFF_DescendChunk( p_input ) != 0 ) 
    799794        { 
    800             __AVIFreeDemuxData( p_input ); 
     795            AVIEnd( p_input ); 
    801796            msg_Err( p_input, "cannot go in (\"movi\")" ); 
    802797            return( -1 ); 
     
    833828                { 
    834829                    p_avi_demux->p_info_video = p_info; 
    835                     /* TODO add test to see if a decoder has been foud */ 
     830                    /* TODO add test to see if a decoder has been found */ 
    836831                    vlc_mutex_lock( &p_input->stream.stream_lock ); 
    837832                    input_SelectES( p_input, p_info->p_es ); 
     
    841836 
    842837            case( AUDIO_ES ): 
    843                 msg_Dbg( p_input, "audio(0x%x) %d channels %dHz %dbits %d bytes", 
     838                msg_Dbg( p_input, "audio(0x%x) %d channels %dHz %dbits (unit %d)", 
    844839                         p_info->audio_format.i_formattag, 
    845840                         p_info->audio_format.i_channels, 
     
    875870    p_input->stream.p_selected_program->b_is_ok = 1; 
    876871    vlc_mutex_unlock( &p_input->stream.stream_lock ); 
    877 #if 0 
    878     DumpAudio = fopen( "tmp.mp3", "w+" ); 
    879 #endif 
    880872 
    881873    return( 0 ); 
     
    883875 
    884876 
    885 /***************************************************************************** 
    886  * AVIEnd: frees unused data 
    887  *****************************************************************************/ 
    888 static void AVIEnd( input_thread_t *p_input ) 
    889 {    
    890 #if 0 
    891     fclose( DumpAudio ); 
    892 #endif 
    893     __AVIFreeDemuxData( p_input );  
    894     return; 
    895 
     877 
    896878 
    897879 
     
    904886                                        mtime_t i_pts ) 
    905887{ 
    906     return( (mtime_t)((double)i_pts * 
    907                       (double)p_info->header.i_rate / 
    908                       (double)p_info->header.i_scale / 
    909                       (double)1000000.0 ) ); 
     888    return( (mtime_t)((s64)i_pts * 
     889                      (s64)p_info->header.i_rate / 
     890                      (s64)p_info->header.i_scale / 
     891                      (s64)1000000 ) ); 
    910892} 
    911893static inline mtime_t AVI_PTSToByte( AVIStreamInfo_t *p_info, 
    912894                                       mtime_t i_pts ) 
    913895{ 
    914     return( (mtime_t)((double)i_pts *  
    915                       (double)p_info->header.i_samplesize * 
    916                       (double)p_info->header.i_rate / 
    917                       (double)p_info->header.i_scale / 
    918                       (double)1000000.0 ) ); 
     896    return( (mtime_t)((s64)i_pts *  
     897                      (s64)p_info->header.i_samplesize * 
     898                      (s64)p_info->header.i_rate / 
     899                      (s64)p_info->header.i_scale / 
     900                      (s64)1000000 ) ); 
    919901 
    920902} 
     
    925907    if( p_info->header.i_samplesize != 0 ) 
    926908    { 
    927         return( (mtime_t)( (double)1000000.0 * 
    928                    (double)(p_info->p_index[p_info->i_idxposc].i_lengthtotal + 
     909        return( (mtime_t)( (s64)1000000 * 
     910                   (s64)(p_info->p_index[p_info->i_idxposc].i_lengthtotal + 
    929911                             p_info->i_idxposb )* 
    930                     (double)p_info->header.i_scale / 
    931                     (double)p_info->header.i_rate / 
    932                     (double)p_info->header.i_samplesize ) ); 
    933     } 
    934     else 
    935     { 
    936         return( (mtime_t)( (double)1000000.0 * 
    937                     (double)(p_info->i_idxposc ) * 
    938                     (double)p_info->header.i_scale / 
    939                     (double)p_info->header.i_rate) ); 
     912                    (s64)p_info->header.i_scale / 
     913                    (s64)p_info->header.i_rate / 
     914                    (s64)p_info->header.i_samplesize ) ); 
     915    } 
     916    else 
     917    { 
     918        return( (mtime_t)( (s64)1000000 * 
     919                    (s64)(p_info->i_idxposc ) * 
     920                    (s64)p_info->header.i_scale / 
     921                    (s64)p_info->header.i_rate) ); 
    940922    } 
    941923} 
     
    10351017    { 
    10361018        if( ( p_info->p_pes_first->i_posc == p_info->i_idxposc )  
    1037 /*            &&( p_info->i_idxposb == p_info->p_pes_first->i_posb ) ) */ 
    10381019             &&( p_info->i_idxposb >= p_info->p_pes_first->i_posb ) 
    1039              &&( p_info->i_idxposb < p_info->p_pes_first->i_posb + p_info->p_pes_first->p_pes->i_pes_size ) ) 
     1020             &&( p_info->i_idxposb < p_info->p_pes_first->i_posb +  
     1021                     p_info->p_pes_first->p_pes->i_pes_size ) ) 
    10401022   
    10411023        { 
     
    10521034    if( p_other ) 
    10531035    { 
    1054         i_other_ck = p_other->p_pes_last ? p_other->p_pes_last->i_posc : p_other->i_idxposc - 1; 
     1036        i_other_ck = p_other->p_pes_last ? p_other->p_pes_last->i_posc :  
     1037                                               p_other->i_idxposc - 1; 
    10551038    } 
    10561039    else 
     
    11861169//            msg_Dbg( p_input, "ck: %4.4s", &p_ck->i_id ); 
    11871170            if( ( i >= p_avi_demux->i_streams ) 
    1188                 ||(__AVI_GetESTypeFromTwoCC( i_type ) != p_info_i->i_cat ) ) 
     1171                ||(AVI_GetESTypeFromTwoCC( i_type ) != p_info_i->i_cat ) ) 
    11891172            { 
    11901173                if( RIFF_NextChunk( p_input, p_avi_demux->p_movi ) != 0 ) 
     
    14251408        } 
    14261409    } 
    1427 #if 0 
    1428     fwrite( p_data->p_payload_start, 1, i_count, DumpAudio ); 
    1429 #endif 
    14301410   return( p_pes ); 
    14311411} 
     
    15101490#define p_info_video p_avi_demux->p_info_video 
    15111491#define p_info_audio p_avi_demux->p_info_audio 
    1512     if( ( p_info_video )&&( p_info_audio ) ) 
    1513     { 
    1514         /* now resynch audio video video */ 
    1515         /*don't care of AVIF_KEYFRAME */ 
    1516         if( !p_info_audio->header.i_samplesize ) 
    1517         { 
    1518             int i_chunk = AVI_PTSToChunk( p_info_audio,  
    1519                                             AVI_GetPTS( p_info_video )); 
    1520  
    1521             AVI_SetStreamChunk( p_input,  
    1522                                 p_info_audio,  
    1523                                 i_chunk ); 
    1524         } 
    1525         else 
    1526         { 
    1527             int i_byte = AVI_PTSToByte( p_info_audio,  
    1528                                           AVI_GetPTS( p_info_video ) ) ; 
    1529             AVI_SetStreamBytes( p_input, 
    1530                                  p_info_audio, 
    1531                                  i_byte ); 
    1532         } 
    1533    } 
     1492    if( ( !p_info_audio )||( !p_info_video ) ) 
     1493    { 
     1494        return; 
     1495    } 
     1496    /* now resynch audio video video */ 
     1497    /*don't care of AVIF_KEYFRAME */ 
     1498    if( !p_info_audio->header.i_samplesize ) 
     1499    { 
     1500        AVI_SetStreamChunk( p_input,  
     1501                            p_info_audio,  
     1502                            AVI_PTSToChunk( p_info_audio, 
     1503                                            AVI_GetPTS( p_info_video ) ) ); 
     1504    } 
     1505    else 
     1506    { 
     1507        AVI_SetStreamBytes( p_input, 
     1508                            p_info_audio, 
     1509                            AVI_PTSToByte( p_info_audio, 
     1510                                            AVI_GetPTS( p_info_video ) ) );  
     1511    } 
    15341512#undef p_info_video 
    15351513#undef p_info_audio 
     
    16141592    /* input_decode want only one pes, but AVI_GetFrameInPES give 
    16151593          multiple pes so send one by one */ 
    1616     /* we now that p_info != NULL */ 
    16171594    while( p_pes ) 
    16181595    { 
     
    16331610 * Returns -1 in case of error, 0 in case of EOF, 1 otherwise 
    16341611 *****************************************************************************/ 
     1612 
    16351613static int AVIDemux( input_thread_t *p_input ) 
    16361614{ 
     
    16521630        { 
    16531631            if( ( p_avi_demux->pp_info[i]->i_cat == VIDEO_ES ) 
    1654                   &&( p_avi_demux->pp_info[i]->p_es->p_decoder_fifo != NULL ) ) 
     1632                  &&( p_avi_demux->pp_info[i]->p_es->p_decoder_fifo ) ) 
    16551633            { 
    16561634                p_avi_demux->p_info_video = p_avi_demux->pp_info[i]; 
     
    16671645        { 
    16681646            if( ( p_avi_demux->pp_info[i]->i_cat == AUDIO_ES ) 
    1669                   &&( p_avi_demux->pp_info[i]->p_es->p_decoder_fifo != NULL ) ) 
     1647                  &&( p_avi_demux->pp_info[i]->p_es->p_decoder_fifo ) ) 
    16701648            { 
    16711649                p_avi_demux->p_info_audio = p_avi_demux->pp_info[i]; 
     
    17371715    input_ClockManageRef( p_input, 
    17381716                          p_input->stream.p_selected_program, 
    1739                           p_avi_demux->i_pcr );  
     1717                          p_avi_demux->i_pcr /*- DEFAULT_PTS_DELAY / 2 */);  
    17401718    /* calculate pcr, time when we must read the next data */ 
    17411719    /* 9/100 kludge ->need to convert to 1/1000000 clock unit to 1/90000 */ 
     
    17751753    return( p_pes ? 1 : 0 ); 
    17761754 
    1777 /*    return( p_info_master->i_idxposc > p_info_master->i_idxnb ? 0 : 1 );*/ 
    1778 
    1779  
     1755
     1756