Share Pastebin
Guest
Public paste!

dts and vfr

By: a guest | Jan 23rd, 2010 | Syntax: None | Size: 1.69 KB | Hits: 84 | Expires: Never
Copy text to clipboard
  1. // When processing VFR video, we need to be sure that long frame
  2. // durations don't cause there to be too few decoded reference
  3. // frames.  So we limit the dts nominal_frame_dur.
  4. // nominal_frame_dur = init_delay if bframes
  5. // nominal_frame_dur = init_delay/2 if bframes && bpyramid
  6. //
  7. // We also want to ensure that there are at most max_delayed_frames
  8. // that have been decoded but not yet displayed by the player.
  9. // max_delayed_frames = 1 if bframes
  10. // max_delayed_frames = 2 if bframes && bpyramid
  11.  
  12. int64_t dts;
  13. int64_t pts_hist[2];
  14. int min, max;
  15.  
  16. min = max = 0;
  17. if (max_delayed_frames == 2)
  18.     max = 1;
  19.  
  20. dts += MIN(nominal_frame_dur, this_frame_dur);
  21.  
  22. if ( pts > dts )
  23. {
  24.     // pts > dts means we are about to delay another frame
  25.     // unless we do something about it.
  26.     if ( num_delayed_frames == max_delayed_frames )
  27.     {
  28.         // The next dts is less than the pts and would therefore
  29.         // add another delayed frame pushing us above the max.
  30.         // So adjust dts such that we don't delay another frame.
  31.         if ( pts < pts_hist[min] )
  32.         {
  33.             dts = pts;
  34.         }
  35.         else if ( pts > pts_hist[max] )
  36.         {
  37.             dts = pts_hist[min];
  38.             pts_hist[min] = pts_hist[max];
  39.             pts_hist[max] = pts
  40.         }
  41.         else
  42.         {
  43.             dts = pts_hist[min];
  44.             pts_hist[min] = pts;
  45.         }
  46.     }
  47.     else
  48.     {
  49.         num_delayed_frames++;
  50.         if ( pts > pts_hist[max] )
  51.         {
  52.             pts_hist[min] = pts_hist[max];
  53.             pts_hist[max] = pts;
  54.         }
  55.         else
  56.         {
  57.             pts_hist[min] = pts;
  58.         }
  59.     }
  60. }
  61. else if ( pts < dts )
  62. {
  63.     dts = pts;
  64. }