-moved lines for generating frame count, fps and fps avarage value from nex_frame to input_available routine.

-solved bug for fps values > 1
tested with qcam backend and connectix b/w camera
merge-requests/2/head
Gerard Klaver 2005-05-07 14:12:57 +00:00
rodzic f1c46bb165
commit bf8310305e
1 zmienionych plików z 44 dodań i 33 usunięć

Wyświetl plik

@ -130,17 +130,19 @@ static struct
char picmsg_ps[50];
int value_rgb;
int value_txt;
double fps;
double fps_av;
double fps_old1;
double fps_old2;
double fps_old3;
long f_count;
time_t time1;
time_t time2;
int i_time;
}
win;
/* forward declarations: */
int main (int argc, char **argv);
@ -1023,6 +1025,9 @@ input_available (gpointer ignore, gint source, GdkInputCondition cond)
SANE_Int len;
u_char *dst;
double max_value = 60; /* min. 1 frame per min. */
double frame_time = 50; /* dummy value */
DBG (DBG_debug, "xcam: input available: enter\n");
if (!win.playing)
@ -1049,6 +1054,7 @@ input_available (gpointer ignore, gint source, GdkInputCondition cond)
while (1)
{
DBG (DBG_debug, "input available: enter sane_read\n");
status = sane_read (gsg_dialog_get_device (dialog),
win.buf + remaining, buf_size - remaining, &len);
if (status != SANE_STATUS_GOOD)
@ -1074,6 +1080,37 @@ input_available (gpointer ignore, gint source, GdkInputCondition cond)
stop_camera ();
return;
}
win.f_count++;
update_param (dialog, 0);
win.i_time++;
if (win.i_time >= 30)
{
time (&win.time2); /* time marker */
frame_time = difftime (win.time2, win.time1);
if (frame_time > max_value)
{
frame_time = max_value;
}
win.fps_old3 = win.fps_old2;
win.fps_old2 = win.fps_old1;
win.fps_old1 = win.fps;
win.fps = 30 / frame_time; /* correction for loop 30 */
/* avarage last 4 frames times */
win.fps_av =
(win.fps_old3 + win.fps_old2 + win.fps_old1 + win.fps) / 4;
DBG (DBG_debug,
"xcam: input_available fps count=%d, frame_time * 30 = %2.3f, fps=%2.3f, fps_av=%2.3f\n",
win.f_count, frame_time, win.fps, win.fps_av);
win.i_time = 0;
time (&win.time1); /* time marker for new sequence */
}
update_param (dialog, 0);
if (!len)
break;
@ -1134,12 +1171,6 @@ next_frame (void)
char buf[256];
SANE_Status status;
int fd;
double max_value = 60; /* min. 1 frame per min. */
double frame_time = 50; /* dummy value */
double fps_old1 = 0;
double fps_old2 = 0;
double fps_old3 = 0;
DBG (DBG_debug, "xcam: next frame enter\n");
buttons_disable ();
@ -1191,29 +1222,7 @@ next_frame (void)
win.x = 0;
win.remaining = 0;
win.f_count++;
time (&win.time2); /* time marker */
frame_time = difftime (win.time2, win.time1);
if (frame_time >= max_value)
{
frame_time = max_value;
}
fps_old3 = fps_old2;
fps_old2 = fps_old1;
fps_old1 = win.fps;
win.fps = 1 / frame_time;
/* avarage last 4 frames times */
win.fps_av = (fps_old3 + fps_old2 + fps_old1 + win.fps) / 4;
DBG (DBG_debug, "xcam: fps count=%d, fps=%2.3f, fps_av=%2.3f\n", win.f_count,
win.fps, win.fps_av);
update_param (dialog, 0);
time (&win.time1); /* time marker for new sequence */
buttons_enable ();
if (sane_set_io_mode (gsg_dialog_get_device (dialog), SANE_TRUE)
@ -1244,7 +1253,7 @@ play_stop_button (GtkWidget * widget, gpointer client_data,
}
else if (win.gdk_input_tag < 0)
{
win.playing = TRUE;
win.playing = TRUE;
gtk_label_set (GTK_LABEL (win.play_stop_label), " Stop ");
DBG (DBG_debug, "xcam: wait for stop button to be pushed\n");
next_frame ();
@ -1761,13 +1770,15 @@ main (int argc, char **argv)
gtk_container_add (GTK_CONTAINER (frame), hbox);
gtk_widget_show (hbox);
win.info_label = gtk_label_new ("0 x 0 0 kByte \n0 f_count \n0 fps 0 fps_av");
win.info_label =
gtk_label_new ("0 x 0 0 kByte \n0 f_count \n0 fps 0 fps_av");
gtk_box_pack_start (GTK_BOX (hbox), win.info_label, FALSE, FALSE, 0);
gtk_widget_show (win.info_label);
win.f_count = 0;
win.fps = 0;
win.fps_av = 0;
win.i_time = 0;
time (&win.time1); /* first time marker */
update_param (dialog, 0);