--- branches/dev-api-4/xvidcore/vfw/src/status.c 2004/01/22 20:54:31 1324 +++ branches/dev-api-4/xvidcore/vfw/src/status.c 2004/01/23 11:03:48 1325 @@ -19,7 +19,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: status.c,v 1.1.2.3 2004-01-22 14:43:39 syskin Exp $ + * $Id: status.c,v 1.1.2.4 2004-01-23 11:03:48 syskin Exp $ * *****************************************************************************/ @@ -62,7 +62,7 @@ for (i=0; i<31; i++) { /* i-vops */ unsigned int j_height = (s->height-s->tm.tmHeight)*s->quant[0][i]/s->max_quant_frames; - if (j_height==0 && s->quant[1][i]>0) j_height=1; + if (j_height==0 && s->quant[0][i]>0) j_height=1; for(j=0; j < j_height; j++) { memset(s->buffer + (s->tm.tmHeight+j)*s->stride + i*s->width31 + 1, @@ -91,11 +91,29 @@ static const char * number[31] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", - "10","11","12","13","14","15","16","17","18","19", - "20","21","22","23","24","25","26","27","28","29", - "30","31" + "0","1","2","3","4","5","6","7","8","9", + "0","1","2","3","4","5","6","7","8","9", + "0","1" }; +static double +avg_quant(int quants[31], int min, int max, char* buf) +{ + int i, sum = 0, count = 0; + for (i = min; i <= max && i > 0; i++) { + sum += i*quants[i-1]; + count += quants[i-1]; + } + + if (count != 0) { + double avg = (double)sum/(double)count; + sprintf(buf, "%.2f", avg); + return avg; + } else { + buf[0] = 0; + return 0.0; + } +} /* status window proc handlder */ @@ -138,7 +156,7 @@ set_bic(s->bi->bmiColors, CLR_QUANT_P, 0, 0, 255); set_bic(s->bi->bmiColors, CLR_QUANT_B, 0, 192, 0); - SelectObject(s->hDc, GetStockObject(SYSTEM_FONT)); + SelectObject(s->hDc, GetStockObject(DEFAULT_GUI_FONT)); SetBkColor(s->hDc, *(DWORD*)&s->bi->bmiColors[CLR_BG]); SetTextColor(s->hDc, *(DWORD*)&s->bi->bmiColors[CLR_FG]); GetTextMetrics(s->hDc, &s->tm); @@ -175,11 +193,12 @@ case WM_TIMER : if (wParam==IDC_STATUS_GRAPH) { + double avg_q; char buf[16]; - SetDlgItemInt(hDlg, IDC_STATUS_I_NUM, s->count[1], FALSE); - SetDlgItemInt(hDlg, IDC_STATUS_P_NUM, s->count[2], FALSE); - SetDlgItemInt(hDlg, IDC_STATUS_B_NUM, s->count[3], FALSE); - SetDlgItemInt(hDlg, IDC_STATUS_NUM, s->count[0], FALSE); + SetDlgItemInt(hDlg, IDC_STATUS_I_NUM, (unsigned int)s->count[1], FALSE); + SetDlgItemInt(hDlg, IDC_STATUS_P_NUM, (unsigned int)s->count[2], FALSE); + SetDlgItemInt(hDlg, IDC_STATUS_B_NUM, (unsigned int)s->count[3], FALSE); + SetDlgItemInt(hDlg, IDC_STATUS_NUM, (unsigned int)s->count[0], FALSE); SetDlgItemInt(hDlg, IDC_STATUS_IQ_MIN, s->min_quant[1], FALSE); SetDlgItemInt(hDlg, IDC_STATUS_IQ_MAX, s->max_quant[1], FALSE); @@ -193,31 +212,31 @@ SetDlgItemInt(hDlg, IDC_STATUS_IL_MIN, s->min_length[1], FALSE); SetDlgItemInt(hDlg, IDC_STATUS_IL_MAX, s->max_length[1], FALSE); if (s->count[1]>0) - SetDlgItemInt(hDlg, IDC_STATUS_IL_AVG, s->tot_length[1]/s->count[1], FALSE); + SetDlgItemInt(hDlg, IDC_STATUS_IL_AVG, (unsigned int)(s->tot_length[1]/s->count[1]), FALSE); else SetDlgItemInt(hDlg, IDC_STATUS_IL_AVG, 0, FALSE); - SetDlgItemInt(hDlg, IDC_STATUS_IL_TOT, s->tot_length[1]/1024, FALSE); + SetDlgItemInt(hDlg, IDC_STATUS_IL_TOT, (unsigned int)(s->tot_length[1]/1024), FALSE); SetDlgItemInt(hDlg, IDC_STATUS_PL_MIN, s->min_length[2], FALSE); SetDlgItemInt(hDlg, IDC_STATUS_PL_MAX, s->max_length[2], FALSE); if (s->count[2]>0) - SetDlgItemInt(hDlg, IDC_STATUS_PL_AVG, s->tot_length[2]/s->count[2], FALSE); + SetDlgItemInt(hDlg, IDC_STATUS_PL_AVG, (unsigned int)(s->tot_length[2]/s->count[2]), FALSE); else SetDlgItemInt(hDlg, IDC_STATUS_PL_AVG, 0, FALSE); - SetDlgItemInt(hDlg, IDC_STATUS_PL_TOT, s->tot_length[2]/1024, FALSE); + SetDlgItemInt(hDlg, IDC_STATUS_PL_TOT, (unsigned int)(s->tot_length[2]/1024), FALSE); SetDlgItemInt(hDlg, IDC_STATUS_BL_MIN, s->min_length[3], FALSE); SetDlgItemInt(hDlg, IDC_STATUS_BL_MAX, s->max_length[3], FALSE); if (s->count[3]>0) - SetDlgItemInt(hDlg, IDC_STATUS_BL_AVG, s->tot_length[3]/s->count[3], FALSE); + SetDlgItemInt(hDlg, IDC_STATUS_BL_AVG, (unsigned int)(s->tot_length[3]/s->count[3]), FALSE); else SetDlgItemInt(hDlg, IDC_STATUS_BL_AVG, 0, FALSE); - SetDlgItemInt(hDlg, IDC_STATUS_BL_TOT, s->tot_length[3]/1024, FALSE); + SetDlgItemInt(hDlg, IDC_STATUS_BL_TOT, (unsigned int)(s->tot_length[3]/1024), FALSE); SetDlgItemInt(hDlg, IDC_STATUS_L_MIN, s->min_length[0], FALSE); SetDlgItemInt(hDlg, IDC_STATUS_L_MAX, s->max_length[0], FALSE); if (s->count[0]>0) - SetDlgItemInt(hDlg, IDC_STATUS_L_AVG, s->tot_length[0]/s->count[0], FALSE); + SetDlgItemInt(hDlg, IDC_STATUS_L_AVG, (int)(s->tot_length[0]/s->count[0]), FALSE); else SetDlgItemInt(hDlg, IDC_STATUS_L_AVG, 0, FALSE); - SetDlgItemInt(hDlg, IDC_STATUS_L_TOT, s->tot_length[0]/1024, FALSE); + SetDlgItemInt(hDlg, IDC_STATUS_L_TOT, (unsigned int)(s->tot_length[0]/1024), FALSE); if (s->count[0]>0) { uint64_t kbits = 8*s->tot_length[0]/1000; @@ -227,6 +246,19 @@ SetDlgItemInt(hDlg, IDC_STATUS_KBPS, 0, FALSE); } + avg_q = avg_quant(s->quant[0], s->min_quant[1], s->max_quant[1], buf) * s->count[1]; + SetDlgItemText(hDlg, IDC_STATUS_IQ_AVG, buf); + + avg_q += avg_quant(s->quant[1], s->min_quant[2], s->max_quant[2], buf) * s->count[2]; + SetDlgItemText(hDlg, IDC_STATUS_PQ_AVG, buf); + + avg_q += avg_quant(s->quant[2], s->min_quant[3], s->max_quant[3], buf) * s->count[3]; + SetDlgItemText(hDlg, IDC_STATUS_BQ_AVG, buf); + + if (s->count[0] != 0) avg_q /= (double)s->count[0]; + sprintf(buf, "%.2f", avg_q); + SetDlgItemText(hDlg, IDC_STATUS_Q_AVG, buf); + draw_graph(s); InvalidateRect(s->hGraph, NULL, FALSE); } @@ -274,7 +306,9 @@ s->fps = fps_base/fps_inc; - memset(s->quant, 0, 31*sizeof(int)); + memset(s->quant[0], 0, 31*sizeof(int)); + memset(s->quant[1], 0, 31*sizeof(int)); + memset(s->quant[2], 0, 31*sizeof(int)); s->max_quant_frames = 0; for (i=0; i<4; i++) { s->count[i] = 0; @@ -291,14 +325,48 @@ ShowWindow(s->hDlg, SW_SHOW); } +static char +type2char(int type) +{ + if (type==XVID_TYPE_IVOP) + return 'I'; + if (type==XVID_TYPE_PVOP) + return 'P'; + if (type==XVID_TYPE_BVOP) + return 'B'; + return 'S'; +} + +static void +status_debugoutput(status_t *s, int type, int length, int quant) +{ + if (s->hDlg && IsDlgButtonChecked(s->hDlg,IDC_SHOWINTERNALS)==BST_CHECKED) { + LRESULT litem; + char buf[128]; + sprintf(buf, "[%6d] ->%c q:%2d (%6d b)", + (unsigned int)(s->count[0]), type2char(type), quant, length); + + SendDlgItemMessage (s->hDlg,IDC_DEBUGOUTPUT, LB_ADDSTRING, 0, (LPARAM)(LPSTR)buf); + + litem = SendDlgItemMessage (s->hDlg, IDC_DEBUGOUTPUT, LB_GETCOUNT, 0, 0L); + + if (litem > 12) + litem = SendDlgItemMessage (s->hDlg,IDC_DEBUGOUTPUT, LB_DELETESTRING, 0, 0L); + + SendDlgItemMessage(s->hDlg,IDC_DEBUGOUTPUT, LB_SETCURSEL, (WORD)(litem-1), 0L); + } +} /* feed stats info into the window */ void status_update(status_t *s, int type, int length, int quant) { - if (type == 4) type = 2; /* XVID_TYPE_SVOP to XVID_TYPE_PVOP */ s->count[0]++; s->count[type]++; + status_debugoutput(s, type, length, quant); + + if (type == 4) type = 2; /* XVID_TYPE_SVOP to XVID_TYPE_PVOP */ + if (s->min_quant[0]==0 || quantmin_quant[0]) s->min_quant[0] = quant; if (s->max_quant[0]==0 || quant>s->max_quant[0]) s->max_quant[0] = quant; if (s->min_quant[type]==0 || quantmin_quant[type]) s->min_quant[type] = quant;