[svn] / branches / dev-api-4 / xvidcore / vfw / src / status.c Repository:
ViewVC logotype

Diff of /branches/dev-api-4/xvidcore/vfw/src/status.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1114, Thu Aug 7 13:25:16 2003 UTC revision 1325, Fri Jan 23 11:03:48 2004 UTC
# Line 19  Line 19 
19   * along with this program; if not, write to the Free Software   * along with this program; if not, write to the Free Software
20   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21   *   *
22   * $Id: status.c,v 1.1.2.2 2003-08-07 13:25:16 syskin Exp $   * $Id: status.c,v 1.1.2.4 2004-01-23 11:03:48 syskin Exp $
23   *   *
24   *****************************************************************************/   *****************************************************************************/
25    
# Line 34  Line 34 
34    
35  #define CLR_BG      0  #define CLR_BG      0
36  #define CLR_FG      1  #define CLR_FG      1
37  #define CLR_QUANT   2  #define CLR_QUANT_I             2
38    #define CLR_QUANT_P             3
39    #define CLR_QUANT_B             4
40    
41  static void set_bic(RGBQUAD * rgb, int index, int r, int g, int b)  static void set_bic(RGBQUAD * rgb, int index, int r, int g, int b)
42  {  {
# Line 58  Line 60 
60    
61      if (s->count[0]>0) {      if (s->count[0]>0) {
62          for (i=0; i<31; i++) {          for (i=0; i<31; i++) {
63              unsigned int j_height = (s->height-s->tm.tmHeight)*s->quant[i]/s->max_quant_frames;                          /* i-vops */
64              if (j_height==0 && s->quant[i]>0) j_height=1;                          unsigned int j_height = (s->height-s->tm.tmHeight)*s->quant[0][i]/s->max_quant_frames;
65                            if (j_height==0 && s->quant[0][i]>0) j_height=1;
66    
67              for(j=0; j < j_height; j++) {              for(j=0; j < j_height; j++) {
68                  memset(s->buffer + (s->tm.tmHeight+j)*s->stride + i*s->width31 + 1,                  memset(s->buffer + (s->tm.tmHeight+j)*s->stride + i*s->width31 + 1,
69                          CLR_QUANT, s->width31-1);                                                  CLR_QUANT_I, s->width31-1);
70                            }
71                            /* p/s-vops */
72                            j_height += (s->height-s->tm.tmHeight)*s->quant[1][i]/s->max_quant_frames;
73                            if (j_height==0 && s->quant[1][i]>0) j_height=1;
74    
75                            for(; j < j_height; j++) {
76                                    memset(s->buffer + (s->tm.tmHeight+j)*s->stride + i*s->width31 + 1,
77                                                    CLR_QUANT_P, s->width31-1);
78                            }
79                            /* b-vops */
80                            j_height += (s->height-s->tm.tmHeight)*s->quant[2][i]/s->max_quant_frames;
81                            if (j_height==0 && s->quant[2][i]>0) j_height=1;
82    
83                            for(; j < j_height; j++) {
84                                    memset(s->buffer + (s->tm.tmHeight+j)*s->stride + i*s->width31 + 1,
85                                                    CLR_QUANT_B, s->width31-1);
86              }              }
87          }          }
88      }      }
# Line 72  Line 91 
91    
92  static const char * number[31] = {  static const char * number[31] = {
93      "1", "2", "3", "4", "5", "6", "7", "8", "9",      "1", "2", "3", "4", "5", "6", "7", "8", "9",
94      "10","11","12","13","14","15","16","17","18","19",          "0","1","2","3","4","5","6","7","8","9",
95      "20","21","22","23","24","25","26","27","28","29",          "0","1","2","3","4","5","6","7","8","9",
96      "30","31"          "0","1"
97  };  };
98    
99    static double
100    avg_quant(int quants[31], int min, int max, char* buf)
101    {
102            int i, sum = 0, count = 0;
103            for (i = min; i <= max && i > 0; i++) {
104                    sum += i*quants[i-1];
105                    count += quants[i-1];
106            }
107    
108            if (count != 0) {
109                    double avg = (double)sum/(double)count;
110                    sprintf(buf, "%.2f", avg);
111                    return avg;
112            } else {
113                    buf[0] = 0;
114                    return 0.0;
115            }
116    }
117    
118  /* status window proc handlder */  /* status window proc handlder */
119    
# Line 115  Line 152 
152    
153          set_bic(s->bi->bmiColors, CLR_BG,       0,   0,   0);          set_bic(s->bi->bmiColors, CLR_BG,       0,   0,   0);
154          set_bic(s->bi->bmiColors, CLR_FG,     128, 128, 128);          set_bic(s->bi->bmiColors, CLR_FG,     128, 128, 128);
155          set_bic(s->bi->bmiColors, CLR_QUANT,    0, 255,   0);                  set_bic(s->bi->bmiColors, CLR_QUANT_I,  255, 0,   0);
156                    set_bic(s->bi->bmiColors, CLR_QUANT_P,  0, 0,   255);
157                    set_bic(s->bi->bmiColors, CLR_QUANT_B,  0, 192,   0);
158    
159          SelectObject(s->hDc, GetStockObject(SYSTEM_FONT));                  SelectObject(s->hDc, GetStockObject(DEFAULT_GUI_FONT));
160          SetBkColor(s->hDc, *(DWORD*)&s->bi->bmiColors[CLR_BG]);          SetBkColor(s->hDc, *(DWORD*)&s->bi->bmiColors[CLR_BG]);
161          SetTextColor(s->hDc, *(DWORD*)&s->bi->bmiColors[CLR_FG]);          SetTextColor(s->hDc, *(DWORD*)&s->bi->bmiColors[CLR_FG]);
162          GetTextMetrics(s->hDc, &s->tm);          GetTextMetrics(s->hDc, &s->tm);
# Line 154  Line 193 
193    
194      case WM_TIMER :      case WM_TIMER :
195          if (wParam==IDC_STATUS_GRAPH) {          if (wParam==IDC_STATUS_GRAPH) {
196                            double avg_q; char buf[16];
197    
198              SetDlgItemInt(hDlg, IDC_STATUS_I_NUM, s->count[1], FALSE);                          SetDlgItemInt(hDlg, IDC_STATUS_I_NUM, (unsigned int)s->count[1], FALSE);
199              SetDlgItemInt(hDlg, IDC_STATUS_P_NUM, s->count[2], FALSE);                          SetDlgItemInt(hDlg, IDC_STATUS_P_NUM, (unsigned int)s->count[2], FALSE);
200              SetDlgItemInt(hDlg, IDC_STATUS_B_NUM, s->count[3], FALSE);                          SetDlgItemInt(hDlg, IDC_STATUS_B_NUM, (unsigned int)s->count[3], FALSE);
201              SetDlgItemInt(hDlg, IDC_STATUS_NUM, s->count[0], FALSE);                          SetDlgItemInt(hDlg, IDC_STATUS_NUM, (unsigned int)s->count[0], FALSE);
202    
203              SetDlgItemInt(hDlg, IDC_STATUS_IQ_MIN, s->min_quant[1], FALSE);              SetDlgItemInt(hDlg, IDC_STATUS_IQ_MIN, s->min_quant[1], FALSE);
204              SetDlgItemInt(hDlg, IDC_STATUS_IQ_MAX, s->max_quant[1], FALSE);              SetDlgItemInt(hDlg, IDC_STATUS_IQ_MAX, s->max_quant[1], FALSE);
# Line 172  Line 212 
212              SetDlgItemInt(hDlg, IDC_STATUS_IL_MIN, s->min_length[1], FALSE);              SetDlgItemInt(hDlg, IDC_STATUS_IL_MIN, s->min_length[1], FALSE);
213              SetDlgItemInt(hDlg, IDC_STATUS_IL_MAX, s->max_length[1], FALSE);              SetDlgItemInt(hDlg, IDC_STATUS_IL_MAX, s->max_length[1], FALSE);
214              if (s->count[1]>0)              if (s->count[1]>0)
215                  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);
216              else              else
217                  SetDlgItemInt(hDlg, IDC_STATUS_IL_AVG, 0, FALSE);                  SetDlgItemInt(hDlg, IDC_STATUS_IL_AVG, 0, FALSE);
218              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);
219              SetDlgItemInt(hDlg, IDC_STATUS_PL_MIN, s->min_length[2], FALSE);              SetDlgItemInt(hDlg, IDC_STATUS_PL_MIN, s->min_length[2], FALSE);
220              SetDlgItemInt(hDlg, IDC_STATUS_PL_MAX, s->max_length[2], FALSE);              SetDlgItemInt(hDlg, IDC_STATUS_PL_MAX, s->max_length[2], FALSE);
221              if (s->count[2]>0)              if (s->count[2]>0)
222                  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);
223              else              else
224                  SetDlgItemInt(hDlg, IDC_STATUS_PL_AVG, 0, FALSE);                  SetDlgItemInt(hDlg, IDC_STATUS_PL_AVG, 0, FALSE);
225              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);
226              SetDlgItemInt(hDlg, IDC_STATUS_BL_MIN, s->min_length[3], FALSE);              SetDlgItemInt(hDlg, IDC_STATUS_BL_MIN, s->min_length[3], FALSE);
227              SetDlgItemInt(hDlg, IDC_STATUS_BL_MAX, s->max_length[3], FALSE);              SetDlgItemInt(hDlg, IDC_STATUS_BL_MAX, s->max_length[3], FALSE);
228              if (s->count[3]>0)              if (s->count[3]>0)
229                  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);
230              else              else
231                  SetDlgItemInt(hDlg, IDC_STATUS_BL_AVG, 0, FALSE);                  SetDlgItemInt(hDlg, IDC_STATUS_BL_AVG, 0, FALSE);
232              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);
233              SetDlgItemInt(hDlg, IDC_STATUS_L_MIN, s->min_length[0], FALSE);              SetDlgItemInt(hDlg, IDC_STATUS_L_MIN, s->min_length[0], FALSE);
234              SetDlgItemInt(hDlg, IDC_STATUS_L_MAX, s->max_length[0], FALSE);              SetDlgItemInt(hDlg, IDC_STATUS_L_MAX, s->max_length[0], FALSE);
235              if (s->count[0]>0)              if (s->count[0]>0)
236                  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);
237              else              else
238                  SetDlgItemInt(hDlg, IDC_STATUS_L_AVG, 0, FALSE);                  SetDlgItemInt(hDlg, IDC_STATUS_L_AVG, 0, FALSE);
239              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);
240    
241              if (s->count[0]>0) {              if (s->count[0]>0) {
242                  unsigned int kbits = 8*s->tot_length[0]/1000;                                  uint64_t kbits = 8*s->tot_length[0]/1000;
243                  double secs = (double)s->count[0]/s->fps;                  double secs = (double)s->count[0]/s->fps;
244                 SetDlgItemInt(hDlg, IDC_STATUS_KBPS, (int)(kbits/secs), FALSE);                 SetDlgItemInt(hDlg, IDC_STATUS_KBPS, (int)(kbits/secs), FALSE);
245              }else{              }else{
246                  SetDlgItemInt(hDlg, IDC_STATUS_KBPS, 0, FALSE);                  SetDlgItemInt(hDlg, IDC_STATUS_KBPS, 0, FALSE);
247              }              }
248    
249                            avg_q = avg_quant(s->quant[0], s->min_quant[1], s->max_quant[1], buf) * s->count[1];
250                            SetDlgItemText(hDlg, IDC_STATUS_IQ_AVG, buf);
251    
252                            avg_q += avg_quant(s->quant[1], s->min_quant[2], s->max_quant[2], buf) * s->count[2];
253                            SetDlgItemText(hDlg, IDC_STATUS_PQ_AVG, buf);
254    
255                            avg_q += avg_quant(s->quant[2], s->min_quant[3], s->max_quant[3], buf) * s->count[3];
256                            SetDlgItemText(hDlg, IDC_STATUS_BQ_AVG, buf);
257    
258                            if (s->count[0] != 0) avg_q /= (double)s->count[0];
259                            sprintf(buf, "%.2f", avg_q);
260                            SetDlgItemText(hDlg, IDC_STATUS_Q_AVG, buf);
261    
262              draw_graph(s);              draw_graph(s);
263              InvalidateRect(s->hGraph, NULL, FALSE);              InvalidateRect(s->hGraph, NULL, FALSE);
264          }          }
# Line 253  Line 306 
306    
307      s->fps = fps_base/fps_inc;      s->fps = fps_base/fps_inc;
308    
309      memset(s->quant, 0, 31*sizeof(int));          memset(s->quant[0], 0, 31*sizeof(int));
310            memset(s->quant[1], 0, 31*sizeof(int));
311            memset(s->quant[2], 0, 31*sizeof(int));
312      s->max_quant_frames = 0;      s->max_quant_frames = 0;
313      for (i=0; i<4; i++) {      for (i=0; i<4; i++) {
314          s->count[i] = 0;          s->count[i] = 0;
315          s->min_quant[i] = s->max_quant[i] = 0;          s->min_quant[i] = s->max_quant[i] = 0;
316          s->min_length[i] = s->max_length[i] = s->tot_length[i] = 0;                  s->min_length[i] = s->max_length[i] = 0;
317                    s->tot_length[i] = 0;
318      }      }
319    
320      s->hDlg = CreateDialogParam(g_hInst,      s->hDlg = CreateDialogParam(g_hInst,
# Line 269  Line 325 
325      ShowWindow(s->hDlg, SW_SHOW);      ShowWindow(s->hDlg, SW_SHOW);
326  }  }
327    
328    static char
329    type2char(int type)
330    {
331            if (type==XVID_TYPE_IVOP)
332                    return 'I';
333            if (type==XVID_TYPE_PVOP)
334                    return 'P';
335            if (type==XVID_TYPE_BVOP)
336                    return 'B';
337            return 'S';
338    }
339    
340    static void
341    status_debugoutput(status_t *s, int type, int length, int quant)
342    {
343            if (s->hDlg && IsDlgButtonChecked(s->hDlg,IDC_SHOWINTERNALS)==BST_CHECKED) {
344                    LRESULT litem;
345                    char buf[128];
346                    sprintf(buf, "[%6d] ->%c  q:%2d (%6d b)",
347                                    (unsigned int)(s->count[0]), type2char(type), quant, length);
348    
349                    SendDlgItemMessage (s->hDlg,IDC_DEBUGOUTPUT, LB_ADDSTRING, 0, (LPARAM)(LPSTR)buf);
350    
351                    litem = SendDlgItemMessage (s->hDlg, IDC_DEBUGOUTPUT, LB_GETCOUNT, 0, 0L);
352    
353                    if (litem > 12)
354                            litem = SendDlgItemMessage (s->hDlg,IDC_DEBUGOUTPUT, LB_DELETESTRING, 0, 0L);
355    
356                    SendDlgItemMessage(s->hDlg,IDC_DEBUGOUTPUT, LB_SETCURSEL, (WORD)(litem-1), 0L);
357            }
358    }
359    
360  /* feed stats info into the window */  /* feed stats info into the window */
361  void status_update(status_t *s, int type, int length, int quant)  void status_update(status_t *s, int type, int length, int quant)
362  {  {
         if (type == 4) type = 2; /* XVID_TYPE_SVOP to XVID_TYPE_PVOP */  
363      s->count[0]++;      s->count[0]++;
364      s->count[type]++;      s->count[type]++;
365    
366            status_debugoutput(s, type, length, quant);
367    
368            if (type == 4) type = 2; /* XVID_TYPE_SVOP to XVID_TYPE_PVOP */
369    
370      if (s->min_quant[0]==0 || quant<s->min_quant[0]) s->min_quant[0] = quant;      if (s->min_quant[0]==0 || quant<s->min_quant[0]) s->min_quant[0] = quant;
371      if (s->max_quant[0]==0 || quant>s->max_quant[0]) s->max_quant[0] = quant;      if (s->max_quant[0]==0 || quant>s->max_quant[0]) s->max_quant[0] = quant;
372      if (s->min_quant[type]==0 || quant<s->min_quant[type]) s->min_quant[type] = quant;      if (s->min_quant[type]==0 || quant<s->min_quant[type]) s->min_quant[type] = quant;
373      if (s->max_quant[type]==0|| quant>s->max_quant[type]) s->max_quant[type] = quant;      if (s->max_quant[type]==0|| quant>s->max_quant[type]) s->max_quant[type] = quant;
374    
375      s->quant[quant-1]++;          s->quant[type-1][quant-1]++;
376      if (s->quant[quant-1]>s->max_quant_frames)          if (s->quant[0][quant-1] + s->quant[1][quant-1] + s->quant[2][quant-1] > s->max_quant_frames)
377          s->max_quant_frames = s->quant[quant-1];                  s->max_quant_frames = s->quant[0][quant-1] + s->quant[1][quant-1] + s->quant[2][quant-1];
378    
379      if (s->min_length[0]==0 || length<s->min_length[0]) s->min_length[0] = length;      if (s->min_length[0]==0 || length<s->min_length[0]) s->min_length[0] = length;
380      if (s->max_length[0]==0 || length>s->max_length[0]) s->max_length[0] = length;      if (s->max_length[0]==0 || length>s->max_length[0]) s->max_length[0] = length;

Legend:
Removed from v.1114  
changed lines
  Added in v.1325

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4