Revision: 70
http://libvidcap.svn.sourceforge.net/libvidcap/?rev=70&view=rev
Author: bcholew
Date: 2007-12-03 06:04:37 -0800 (Mon, 03 Dec 2007)
Log Message:
-----------
Screen out dataless capture callbacks. Adjust timer thread's sleep time to be more precise.
Modified Paths:
--------------
trunk/src/sapi.c
Modified: trunk/src/sapi.c
===================================================================
--- trunk/src/sapi.c 2007-11-26 19:32:59 UTC (rev 69)
+++ trunk/src/sapi.c 2007-12-03 14:04:37 UTC (rev 70)
@@ -219,6 +219,13 @@
if ( !frame )
return -1;
+ /* Screen-out useless callbacks */
+ if ( video_data_size < 1 && !error_status )
+ {
+ log_info("callback with no data?\n");
+ return 0;
+ }
+
frame->video_data_size = video_data_size;
frame->error_status = error_status;
frame->stride = stride;
@@ -398,8 +405,6 @@
{
struct sapi_src_context * src_ctx = args;
struct timeval tv_now;
-
- /* change to faster rate at capture time, and reduce when capture stopped */
const long idle_state_sleep_period_ms = 100;
long sleep_ms = idle_state_sleep_period_ms;
int first_time = 1;
@@ -420,14 +425,13 @@
src_ctx->frame_time_next.tv_sec = tv_now.tv_sec;
src_ctx->frame_time_next.tv_usec = tv_now.tv_usec;
- log_info("capture timer thread now running\n");
src_ctx->capture_timer_thread_started = 1;
while ( !src_ctx->kill_timer_thread )
{
gettimeofday(&tv_now, 0);
- /* time to attempt to read a frame? */
+ /* sleep or read? */
if ( capture_error || src_ctx->src_state != src_capturing ||
!tv_greater_or_equal(&tv_now, &src_ctx->frame_time_next) )
{
@@ -436,7 +440,17 @@
sleep_ms = idle_state_sleep_period_ms;
first_time = 1;
}
+ else if ( !capture_error )
+ {
+ /* sleep just enough */
+ sleep_ms = ((src_ctx->frame_time_next.tv_sec - tv_now.tv_sec) *
+ 1000000L + src_ctx->frame_time_next.tv_usec -
+ tv_now.tv_usec) / 1000L;
+ }
+ if ( sleep_ms < 0 )
+ sleep_ms = 0;
+
vc_millisleep(sleep_ms);
}
else
@@ -458,16 +472,11 @@
/* re-initialize when next to check for a frame */
src_ctx->frame_time_next.tv_sec = tv_now.tv_sec;
src_ctx->frame_time_next.tv_usec = tv_now.tv_usec;
-
- sleep_ms = (1000 / sleeps_per_capture) *
- src_ctx->fmt_nominal.fps_denominator /
- src_ctx->fmt_nominal.fps_numerator;
}
if ( !first_time )
{
/* update when next to check for a frame */
- /* FIXME: reduce round-off */
tv_add_usecs(&src_ctx->frame_time_next, &src_ctx->frame_time_next,
1000000 *
src_ctx->fmt_nominal.fps_denominator /
@@ -488,8 +497,6 @@
src_ctx->timer_thread_idle = 1;
}
- log_info("capture timer thread now exiting...\n");
-
return 0;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|