Changeset 820

Show
Ignore:
Timestamp:
02/29/08 20:37:26 (5 months ago)
Author:
astrange
Message:

Write frame-dropping stats to the log if logging is on.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/FFusionCodec.c

    r819 r820  
    9191}; 
    9292 
     93struct per_frame_decode_stats 
     94{ 
     95        unsigned                begin_calls; 
     96        unsigned                decode_calls; 
     97        unsigned                draw_calls; 
     98        unsigned                end_calls; 
     99}; 
     100 
     101struct decode_stats 
     102{ 
     103        struct per_frame_decode_stats type[4]; 
     104        int             max_frames_begun; 
     105        int             max_frames_decoded; 
     106}; 
     107 
    93108typedef struct 
    94109{ 
     
    111126        FFusionData             data; 
    112127        struct decode_glob      decode; 
     128        struct decode_stats stats; 
    113129} FFusionGlobalsRecord, *FFusionGlobals; 
    114130 
     
    168184#include <QuickTime/ComponentDispatchHelper.c> 
    169185 
    170 void *launchUpdateChecker(void *args) 
     186static void *launchUpdateChecker(void *args) 
    171187{ 
    172188        FSRef *ref = (FSRef *)args; 
     
    210226        pthread_t thread; 
    211227        pthread_create(&thread, NULL, launchUpdateChecker, updateCheckRef); 
     228} 
     229 
     230static void RecomputeMaxCounts(FFusionGlobals glob) 
     231{ 
     232        int i; 
     233        unsigned begun = 0, decoded = 0, ended = 0, drawn = 0; 
     234         
     235        for (i = 0; i < 4; i++) { 
     236                struct per_frame_decode_stats *f = &glob->stats.type[i]; 
     237                 
     238                begun += f->begin_calls; 
     239                decoded += f->decode_calls; 
     240                drawn += f->draw_calls; 
     241                ended += f->end_calls; 
     242        } 
     243         
     244        signed begin_diff = begun - ended, decode_diff = decoded - drawn; 
     245         
     246        if (abs(begin_diff) > glob->stats.max_frames_begun) glob->stats.max_frames_begun = begin_diff; 
     247        if (abs(decode_diff) > glob->stats.max_frames_decoded) glob->stats.max_frames_decoded = decode_diff; 
     248} 
     249 
     250static void DumpFrameDropStats(FFusionGlobals glob) 
     251{ 
     252        static const char types[4] = {'?', 'I', 'P', 'B'}; 
     253        int i; 
     254         
     255        if (!glob->fileLog || glob->decode.lastFrame == 0) return; 
     256         
     257        Codecprintf(glob->fileLog, "Type\t| BeginBand\t| DecodeBand\t| DrawBand\t| dropped before decode\t| dropped before draw\n"); 
     258         
     259        for (i = 0; i < 4; i++) { 
     260                struct per_frame_decode_stats *f = &glob->stats.type[i]; 
     261                                 
     262                Codecprintf(glob->fileLog, "%c\t| %d\t\t| %d\t\t| %d\t\t| %d/%f%%\t\t| %d/%f%%\n", types[i], f->begin_calls, f->decode_calls, f->draw_calls, 
     263                                        f->begin_calls - f->decode_calls,(f->begin_calls > f->decode_calls) ? ((float)(f->begin_calls - f->decode_calls)/(float)f->begin_calls) * 100. : 0., 
     264                                        f->decode_calls - f->draw_calls,(f->decode_calls > f->draw_calls) ? ((float)(f->decode_calls - f->draw_calls)/(float)f->decode_calls) * 100. : 0.); 
     265        } 
    212266} 
    213267 
     
    316370{ 
    317371    FFusionDebugPrint("%p closed.\n", glob); 
     372        DumpFrameDropStats(glob); 
    318373 
    319374    // Make sure to close the base component and deallocate our storage 
     
    436491                cap->baseCodecShouldCallDecodeBandForAllFrames = true; 
    437492                cap->subCodecSupportsScheduledBackwardsPlaybackWithDifferenceFrames = !doExperimentalFlags; 
    438                  
    439         //  XXX enabling this seems to cause rare visible artifacts in h.264? 
    440493                cap->subCodecSupportsDrawInDecodeOrder = doExperimentalFlags;  
    441494                cap->subCodecSupportsDecodeSmoothing = true;  
     
    10231076        myDrp->GOPStartFrameNumber = glob->begin.lastIFrame; 
    10241077         
     1078        glob->stats.type[drp->frameType].begin_calls++; 
     1079        RecomputeMaxCounts(glob); 
    10251080        FFusionDebugPrint("%p BeginBand: frame #%d type %d. (%sskippable)\n", glob, myDrp->frameNumber, type, not(skippable)); 
     1081         
    10261082    return noErr; 
    10271083} 
     
    10501106    FFusionDecompressRecord *myDrp = (FFusionDecompressRecord *)drp->userDecompressRecord; 
    10511107         
     1108        glob->stats.type[drp->frameType].decode_calls++; 
     1109        RecomputeMaxCounts(glob); 
    10521110        FFusionDebugPrint("%p DecodeBand #%d qtType %d. (packed %d)\n", glob, myDrp->frameNumber, drp->frameType, glob->packedType); 
    10531111 
     
    11781236        int i, j; 
    11791237         
     1238        glob->stats.type[drp->frameType].draw_calls++; 
     1239        RecomputeMaxCounts(glob); 
    11801240        FFusionDebugPrint("%p DrawBand #%d. (%sdecoded)\n", glob, myDrp->frameNumber, not(myDrp->decoded)); 
    11811241         
     
    12711331{ 
    12721332        FFusionDecompressRecord *myDrp = (FFusionDecompressRecord *)drp->userDecompressRecord; 
     1333        glob->stats.type[drp->frameType].end_calls++; 
    12731334        FFusionDebugPrint("%p EndBand #%d.\n", glob, myDrp->frameNumber); 
     1335         
    12741336    return noErr; 
    12751337}