comparison mplayer.c @ 13857:38424a8eb0ea

reworked the status line to avoid scrolling and remove duplicate code.
author reimar
date Tue, 02 Nov 2004 23:06:12 +0000
parents fb83e23e94ce
children 4178a4eee72c
comparison
equal deleted inserted replaced
13856:335778f9e6ae 13857:38424a8eb0ea
781 * will be done automatically by replacing our main() if we include SDL.h. 781 * will be done automatically by replacing our main() if we include SDL.h.
782 */ 782 */
783 #if defined(SYS_DARWIN) && defined(HAVE_SDL) 783 #if defined(SYS_DARWIN) && defined(HAVE_SDL)
784 #include <SDL.h> 784 #include <SDL.h>
785 #endif 785 #endif
786
787 /**
788 * \brief append a formatted string
789 * \param buf buffer to print into
790 * \param pos position of terminating 0 in buf
791 * \param len maximum number of characters in buf, not including terminating 0
792 * \param format printf format string
793 */
794 static void saddf(char *buf, unsigned *pos, int len, const char *format, ...)
795 {
796 va_list va;
797 va_start(va, format);
798 *pos += vsnprintf(&buf[*pos], len - *pos, format, va);
799 va_end(va);
800 if (*pos >= len ) {
801 buf[len] = 0;
802 *pos = len;
803 }
804 }
805
806 /**
807 * \brief print the status line
808 * \param a_pos audio position
809 * \param a_v A-V desynchronization
810 * \param corr amount out A-V synchronization
811 */
812 static void print_status(float a_pos, float a_v, float corr)
813 {
814 int width;
815 char *line;
816 unsigned pos = 0;
817 #ifndef __MINGW32__
818 struct winsize ws;
819 if (ioctl(0, TIOCGWINSZ, &ws) != -1 && ws.ws_col)
820 width = ws.ws_col;
821 else
822 #endif
823 width = 80;
824 line = malloc(width + 1); // one additional for terminating null
825
826 // Audio time
827 if (sh_audio) {
828 saddf(line, &pos, width, "A:%6.1f ", a_pos);
829 if (!sh_video) {
830 // convert time to HH:MM:SS.F format
831 long tenths = 10 * a_pos;
832 int f1 = tenths % 10;
833 int ss = (tenths / 10) % 60;
834 int mm = (tenths / 600) % 60;
835 int hh = (tenths / 36000) % 100;
836 saddf(line, &pos, width, "(");
837 if (hh > 0)
838 saddf(line, &pos, width, "%2d:", hh);
839 if (hh > 0 || mm > 0)
840 saddf(line, &pos, width, "%02d:", mm);
841 saddf(line, &pos, width, "%02d.", ss);
842 saddf(line, &pos, width, "%1d", f1);
843 saddf(line, &pos, width, ") ");
844 }
845 }
846
847 // Video time
848 if (sh_video)
849 saddf(line, &pos, width, "V:%6.1f ", sh_video->pts);
850
851 // A-V sync
852 if (sh_audio && sh_video)
853 saddf(line, &pos, width, "A-V:%7.3f ct:%7.3f ", a_v, corr);
854
855 // Video stats
856 if (sh_video)
857 saddf(line, &pos, width, "%3d/%3d ",
858 (int)sh_video->num_frames,
859 (int)sh_video->num_frames_decoded);
860
861 // CPU usage
862 if (sh_video) {
863 if (sh_video->timer > 0.5)
864 saddf(line, &pos, width, "%2d%% %2d%% %4.1f%% ",
865 (int)(100.0*video_time_usage*playback_speed/(double)sh_video->timer),
866 (int)(100.0*vout_time_usage*playback_speed/(double)sh_video->timer),
867 (100.0*audio_time_usage*playback_speed/(double)sh_video->timer));
868 else
869 saddf(line, &pos, width, "??%% ??%% ??,?%% ");
870 } else if (sh_audio) {
871 if (sh_audio->delay > 0.5)
872 saddf(line, &pos, width, "%4.1f%% ",
873 100.0*audio_time_usage/(double)sh_audio->delay);
874 else
875 saddf(line, &pos, width, "??,?%% ");
876 }
877
878 // VO stats
879 if (sh_video)
880 saddf(line, &pos, width, "%d %d ", drop_frame_cnt, output_quality);
881
882 #ifdef USE_STREAM_CACHE
883 // cache stats
884 if (stream_cache_size > 0)
885 saddf(line, &pos, width, "%d%% ", cache_fill_status);
886 #endif
887
888 // other
889 if (playback_speed != 1)
890 saddf(line, &pos, width, "%4.2fx ", playback_speed);
891
892 // end
893 memset(&line[pos], ' ', width - pos);
894 line[width] = 0;
895 mp_msg(MSGT_AVSYNC, MSGL_STATUS, "%s\r", line);
896 free(line);
897 }
786 898
787 /** 899 /**
788 * \brief build a chain of audio filters that converts the input format 900 * \brief build a chain of audio filters that converts the input format
789 * to the ao's format, taking into account the current playback_speed. 901 * to the ao's format, taking into account the current playback_speed.
790 * \param sh_audio describes the requested input format of the chain. 902 * \param sh_audio describes the requested input format of the chain.
2111 } // while(sh_audio) 2223 } // while(sh_audio)
2112 2224
2113 if(!sh_video) { 2225 if(!sh_video) {
2114 // handle audio-only case: 2226 // handle audio-only case:
2115 if(!quiet) { 2227 if(!quiet) {
2116 // 2228 float a_pos = sh_audio->delay - audio_out->get_delay() * playback_speed;
2117 // convert time to HH:MM:SS.F format 2229 print_status(a_pos, 0, 0);
2118 //
2119 long tenths = 10 * (sh_audio->delay-audio_out->get_delay()*playback_speed);
2120 int hh = (tenths / 36000) % 100;
2121 int mm = (tenths / 600) % 60;
2122 int ss = (tenths / 10) % 60;
2123 int f1 = tenths % 10;
2124 char hhmmssf[16]; // only really need 11, but just in case...
2125 sprintf( hhmmssf, "%2d:%2d:%2d.%1d", hh, mm, ss, f1);
2126 if (0 == hh) {
2127 hhmmssf[1] = ' ';
2128 hhmmssf[2] = ' ';
2129 }
2130 // uncomment the next three lines to show leading zero ten-hours
2131 // else if (' ' == hhmmssf[0]) {
2132 // hhmmssf[0] = '0';
2133 // }
2134 if ((0 == hh) && (0 == mm)) {
2135 hhmmssf[4] = ' ';
2136 hhmmssf[5] = ' ';
2137 }
2138 else if ((' ' == hhmmssf[3]) && (' ' != hhmmssf[2])) {
2139 hhmmssf[3] = '0';
2140 }
2141 if ((' ' == hhmmssf[6]) && (' ' != hhmmssf[5])) {
2142 hhmmssf[6] = '0';
2143 }
2144 mp_msg(MSGT_AVSYNC,MSGL_STATUS,"A: %s %4.1f%% %d%% %4.2fx \r"
2145 ,hhmmssf
2146 ,(sh_audio->delay>0.5)?100.0*audio_time_usage/(double)sh_audio->delay:0
2147 ,cache_fill_status
2148 ,playback_speed
2149 );
2150 } 2230 }
2151 if(d_audio->eof) eof = PT_NEXT_ENTRY; 2231 if(d_audio->eof) eof = PT_NEXT_ENTRY;
2152 2232
2153 } else { 2233 } else {
2154 2234
2440 if(default_max_pts_correction>=0) 2520 if(default_max_pts_correction>=0)
2441 max_pts_correction=default_max_pts_correction; 2521 max_pts_correction=default_max_pts_correction;
2442 else 2522 else
2443 max_pts_correction=sh_video->frametime*0.10; // +-10% of time 2523 max_pts_correction=sh_video->frametime*0.10; // +-10% of time
2444 if(!frame_time_remaining){ sh_audio->delay+=x; c_total+=x;} // correction 2524 if(!frame_time_remaining){ sh_audio->delay+=x; c_total+=x;} // correction
2445 if(!quiet) mp_msg(MSGT_AVSYNC,MSGL_STATUS,"A:%6.1f V:%6.1f A-V:%7.3f ct:%7.3f %3d/%3d %2d%% %2d%% %4.1f%% %d %d %d%% %4.2fx\r", 2525 if(!quiet)
2446 a_pts-audio_delay-delay,v_pts,AV_delay,c_total, 2526 print_status(a_pts - audio_delay - delay, AV_delay, c_total);
2447 (int)sh_video->num_frames,(int)sh_video->num_frames_decoded,
2448 (sh_video->timer>0.5)?(int)(100.0*video_time_usage*playback_speed/(double)sh_video->timer):0,
2449 (sh_video->timer>0.5)?(int)(100.0*vout_time_usage*playback_speed/(double)sh_video->timer):0,
2450 (sh_video->timer>0.5)?(100.0*audio_time_usage*playback_speed/(double)sh_video->timer):0
2451 ,drop_frame_cnt
2452 ,output_quality
2453 ,cache_fill_status
2454 ,playback_speed
2455 );
2456 fflush(stdout);
2457 } 2527 }
2458 2528
2459 } else { 2529 } else {
2460 // No audio: 2530 // No audio:
2461 2531
2462 if(!quiet) 2532 if(!quiet)
2463 mp_msg(MSGT_AVSYNC,MSGL_STATUS,"V:%6.1f %3d %2d%% %2d%% %4.1f%% %d %d %d%%\r",sh_video->pts, 2533 print_status(0, 0, 0);
2464 (int)sh_video->num_frames,
2465 (sh_video->timer>0.5)?(int)(100.0*video_time_usage/(double)sh_video->timer):0,
2466 (sh_video->timer>0.5)?(int)(100.0*vout_time_usage/(double)sh_video->timer):0,
2467 (sh_video->timer>0.5)?(100.0*audio_time_usage/(double)sh_video->timer):0
2468 ,drop_frame_cnt
2469 ,output_quality
2470 ,cache_fill_status
2471 );
2472
2473 fflush(stdout);
2474 2534
2475 } 2535 }
2476 2536
2477 //============================ Auto QUALITY ============================ 2537 //============================ Auto QUALITY ============================
2478 2538