void counter_print(int encoding, int frame, int first, int last) { TCSession *session = tc_get_session(); vob_t *vob = session->job; struct timeval tv; struct timezone dummy_tz = {0,0}; double now, timediff, fps, time; int buf_im, buf_fl, buf_ex; /* Values of 'first' and `last' during last call (-1 = not called yet) */ static int old_first = -1, old_last = -1; /* Time of first call for this range */ static double start_time = 0; /* Time of last call */ static double old_time = 0; if (!session->progress_meter || !session->progress_rate || !counter_active || frame % session->progress_rate != 0 ) { return; } if (frame < 0 || first < 0) { static int warned = 0; if (!warned) { tc_log_warn(__FILE__, "invalid arguments to counter_print" " (%d,%d,%d,%d)", encoding, frame, first, last); warned = 1; } return; } #ifdef HAVE_GETTIMEOFDAY if (gettimeofday(&tv, &dummy_tz) != 0) { static int warned = 0; if (!warned) { tc_log_warn(__FILE__, "gettimeofday() failed!"); warned = 1; } return; } now = tv.tv_sec + (double)tv.tv_usec/1000000.0; #else now = time(NULL); #endif timediff = now - old_time; old_time = now; if (old_first != first || old_last != last) { /* In human-readable mode, start a new counter line for each range * if we don't know the total number of frames to be encoded. */ if (session->progress_meter == 1 && old_first != -1 && frames_to_encode == 0) fprintf(stderr, "\n"); start_time = now; old_first = first; old_last = last; /* We decrement the frame counts here to compensate for this frame * which took an unknown amount of time to complete. */ if (encoding && frames_to_encode > 0) frames_to_encode--; else if (!encoding && frames_to_skip > 0) frames_to_skip--; return; } /* Note that we don't add 1 to the numerator here, since start_time is * the time we were called for the first frame, so frame first+1 is one * one frame later than start_time, not two. */ if (now > start_time) { fps = (frame - first) / (now - start_time); } else { /* No time has passed (maybe we don't have gettimeofday()) */ fps = 0; } tc_framebuffer_get_counters(&buf_im, &buf_fl, &buf_ex); time = (double)frame / ((vob->ex_fps<1.0) ? 1.0 : vob->ex_fps); if (last == -1) { /* Can't calculate ETA, just display current timestamp */ print_counter_line(encoding, frame, first, -1, fps, -1, time, -1, buf_im, buf_fl, buf_ex); } else if (frames_to_encode == 0) { /* Total number of frames unknown, just display for current range */ double done = (double)(frame - first + 1) / (double)(last+1 - first); int secleft = fps>0 ? ((last+1)-frame) / fps : -1; print_counter_line(encoding, frame, first, last, fps, done, time, secleft, buf_im, buf_fl, buf_ex); } else { /* Estimate time remaining for entire run */ double done; int secleft; if (encoding) { encoded_frames++; encoded_time += timediff; } else { skipped_frames++; skipped_time += timediff; } if (encoded_frames > frames_to_encode) frames_to_encode = encoded_frames; if (skipped_frames > frames_to_skip) frames_to_skip = skipped_frames; if (encoded_frames == 0) { /* We don't know how long it will take to encode frames; avoid * understating the ETA, and just say we don't know */ secleft = -1; } else { double encode_fps, skip_fps, total_time; /* Find the processing speed for encoding and skipping */ encode_fps = encoded_time ? encoded_frames / encoded_time : 0; if (skipped_frames > 0 && skipped_time > 0) { skip_fps = skipped_frames / skipped_time; } else { /* Just assume the same FPS for skipping as for encoding. * Overstating the ETA isn't as bad as understating it, and * certainly better than giving the user "unknown" for an * entire encoding range. */ skip_fps = encode_fps; } if (encode_fps > 0) { /* Estimate the total processing time required */ total_time = (frames_to_encode / encode_fps) + (frames_to_skip / skip_fps); /* Determine time left (round up) */ secleft = ceil(total_time - (encoded_time + skipped_time)); } else { total_time = -1; secleft = -1; } /* Use the proper overall FPS in the status line */ fps = encoding ? encode_fps : skip_fps; } /* Just use the frame ratio for completion percentage */ done = (double)(encoded_frames + skipped_frames) / (double)(frames_to_encode + frames_to_skip); print_counter_line(encoding, frame, 0, highest_frame, fps, done, time, secleft, buf_im, buf_fl, buf_ex); } fflush(stdout); }
static rc_t CC walk_counters_exit_ref_pos( walk_data * data ) { rc_t rc = print_counter_line( data->ref_name, data->ref_pos, data->ref_base, data->depth, data->data ); return rc; }