Changeset 130

Show
Ignore:
Timestamp:
18/11/05 00:14:19 (3 years ago)
Author:
jpsaman
Message:

Added bytes transferred and bitrates between two PCR's to the verbose output.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/examples/decode_mpeg.c

    r129 r130  
    171171    memset( p_dst, 0, i_size ); 
    172172    i_rc = read( i_socket, p_dst, i_size ); 
     173    if( i_rc < 0 ) printf( "READ INTERRUPTED BY SIGNAL\n" ); 
     174    if( i_rc == 0 ) printf( "READ RETURNS 0\n" ); 
    173175    return (i_rc <= i_size ) ? 1 : 0; 
    174176} 
     
    418420    int i_mtu = 1316; /* (7 * 188) = 1316 < 1500 network MTU */ 
    419421#ifdef HAVE_SYS_SOCKET_H 
    420     int i_port = 0; 
    421     char *ipaddress = NULL; 
    422     time_t  time_prev = 0; 
    423     int     i_old_cc = -1;  
    424     mtime_t i_prev_pcr = 0;  /* 33 bits */ 
    425 #endif 
     422    int      i_port = 0; 
     423    char   * ipaddress = NULL; 
     424    time_t   time_prev = 0; 
     425    int      i_old_cc = -1;  
     426    mtime_t  i_prev_pcr = 0;  /* 33 bits */ 
     427#endif 
     428    uint32_t i_bytes = 0; /* bytes transmitted between PCR's */ 
    426429    char *filename = NULL; 
    427430     
     
    447450                i_mtu = atoi( optarg ); 
    448451                if( i_mtu < 0 ) i_mtu = 1316; 
     452                else i_mtu = (i_mtu / 188) * 188; 
    449453                break; 
    450454            case 'p': 
     
    466470    } while( next_option != -1 ); 
    467471 
     472#ifdef HAVE_SYS_SOCKET_H 
     473    if( b_verbose )  
     474    { 
     475        printf( "set mtu to %d\n", i_mtu ); 
     476    } 
     477#endif 
    468478    /* initialize */ 
    469479    if( filename ) 
     
    490500    /* Read first packet */ 
    491501    if( filename ) 
     502    { 
    492503        b_ok = ReadPacket( i_fd, p_data); 
    493 #ifdef HAVE_SYS_SOCKET_H 
    494     else 
     504        i_bytes += 188; 
     505    } 
     506#ifdef HAVE_SYS_SOCKET_H 
     507    else  
     508    { 
    495509        b_ok = ReadPacketFromSocket( i_fd, p_data, i_mtu ); 
    496      
     510        i_bytes += i_mtu; 
     511    } 
    497512    if( b_verbose ) 
    498         printf( "seqno, network (ms), PCR value (ms), PCR prev (ms), delta (ms)\n" ); 
     513        printf( "seqno, network (ms), PCR value (ms), PCR prev (ms), delta (ms), bytes, bitrate (bytes/delta)\n" ); 
    499514#endif 
    500515         
    501516    /* Enter infinite loop */     
    502517    p_stream->pat.handle = dvbpsi_AttachPAT( DumpPAT, p_stream );     
    503     while(b_ok
     518    while( b_ok
    504519    { 
    505520        int     i = 0; 
     
    538553                p_stream->pid[i_pid].i_cc = i_cc; 
    539554            } 
    540              
     555 
    541556            /* Other adaptation field */ 
    542557            if( b_adaptation ) 
     
    555570                { 
    556571                    mtime_t i_pcr;  /* 33 bits */ 
    557                     mtime_t i_delta = 0; 
    558                     struct timeval tv; 
     572                    mtime_t i_delta = 0; 
    559573 
    560574                    i_pcr = ( ( (mtime_t)p_tmp[6] << 25 ) | 
     
    572586                        time_t time_current; 
    573587                        time_t tv_delta; 
     588                        struct timeval tv; 
    574589 
    575590                        gettimeofday( &tv, NULL ); 
    576591                        time_current = (tv.tv_sec*1000) + (tv.tv_usec/1000); 
    577                         tv_delta = time_current - time_prev; 
    578                         printf( "arrival %.2ld, ", (long)tv_delta ); 
     592                        if( time_prev == 0 ) /* probably the first one */ 
     593                            printf( "arrival -, " ); 
     594                        else  
     595                        { 
     596                            tv_delta = time_current - time_prev; 
     597                            printf( "arrival %.2lld, ", (long long int)tv_delta ); 
     598                        } 
    579599                        time_prev = time_current; 
    580600                    } 
    581                     if( i_delta < 0 ) 
    582                         printf( "value %lld, previous %lld, delta %lld\n", 
     601                    if( i_delta <= 0 ) 
     602                        printf( "value %lld, previous %lld, delta %lld, bytes %u, ", 
    583603                                (long long int)p_stream->pid[i_pid].i_pcr, (long long int)i_prev_pcr, 
    584                                 (long long int)i_delta ); 
     604                                (long long int)i_delta, i_bytes ); 
    585605                    else if( b_verbose ) 
    586                         printf( "value %lld, previous %lld, delta %lld\n", 
     606                        printf( "value %lld, previous %lld, delta %lld, bytes %u, ", 
    587607                                (long long int)p_stream->pid[i_pid].i_pcr, (long long int)i_prev_pcr, 
    588                                 (long long int)i_delta ); 
     608                                (long long int)i_delta, i_bytes ); 
     609                    if( (i_delta > 0) ) 
     610                        printf( "%lld Kbps", ((i_bytes*8)/i_delta) ); 
     611                    else  
     612                        printf( "-" ); 
     613                    if( (i_delta <= 0) || b_verbose ) 
     614                        printf( "\n" ); 
     615 
     616                    i_bytes = 0; 
    589617                } 
    590618            } 
    591              
     619 
    592620            /* Handle discontinuities if they occured, 
    593621             * according to ISO/IEC 13818-1: DIS pages 20-22 */ 
     
    600628                { 
    601629                    if( b_pcr ) 
    602                         printf( "New PCR pid %d value %lld (previous %lld, delta %lld)\n", i_pid,  
    603                                 (long long int)p_stream->pid[i_pid].i_pcr, (long long int)i_prev_pcr, 
    604                                 (long long int)p_stream->pid[i_pid].i_pcr - (long long int)i_prev_pcr ); 
     630                    { 
     631                        mtime_t i_delta; 
     632                        struct timeval tv; 
     633 
     634                        i_delta = (long long int)p_stream->pid[i_pid].i_pcr - (long long int)i_prev_pcr; 
     635                        printf( "New PCR pid %d, value %lld, previous %lld, delta %lld, bytes %u, ", 
     636                                i_pid,  
     637                                (long long int)p_stream->pid[i_pid].i_pcr,  
     638                                (long long int)i_prev_pcr, 
     639                                i_delta,  
     640                                i_bytes ); 
     641                        if( i_delta > 0 ) 
     642                            printf( "%lld", (i_bytes*8)/(i_delta/1000) ); 
     643                        printf( "\n" ); 
     644 
     645                        /* Initialize the arrival time */ 
     646                        gettimeofday( &tv, NULL ); 
     647                        time_prev = (tv.tv_sec*1000) + (tv.tv_usec/1000); 
     648                        i_bytes = 0; 
     649                    } 
    605650                    if( b_discontinuity_seen ) 
    606651                    { 
     
    622667        /* Read next packet */ 
    623668        if( filename ) 
     669        { 
    624670            b_ok = ReadPacket( i_fd, p_data); 
     671            i_bytes += 188; 
     672        } 
    625673#ifdef HAVE_SYS_SOCKET_H 
    626674        else 
     675        { 
    627676            b_ok = ReadPacketFromSocket( i_fd, p_data, i_mtu ); 
     677            i_bytes += i_mtu; 
     678        } 
    628679#endif 
    629680    }