|
From: libvidcap c. m. <lib...@li...> - 2007-09-13 19:25:54
|
Revision: 20
http://libvidcap.svn.sourceforge.net/libvidcap/?rev=20&view=rev
Author: bcholew
Date: 2007-09-13 12:25:43 -0700 (Thu, 13 Sep 2007)
Log Message:
-----------
Don't enforce framerate if we're reporting an error in capture callback. Define source context capture_data of -1 to be invalid. Set capture_data to -1 whenever clearing capture callback. Check if capture_callback or capture_data are invalid before calling application capture callback - in case they're cleared by another thread during callback.
Modified Paths:
--------------
trunk/src/sapi.c
trunk/src/sapi.h
trunk/src/vidcap.c
Modified: trunk/src/sapi.c
===================================================================
--- trunk/src/sapi.c 2007-09-13 18:32:29 UTC (rev 19)
+++ trunk/src/sapi.c 2007-09-13 19:25:43 UTC (rev 20)
@@ -215,11 +215,19 @@
const char * video_data, int video_data_size,
int error_status)
{
- int send_frame;
struct vidcap_capture_info cap_info;
- send_frame = enforce_framerate(src_ctx);
+ // NOTE: We may be called here by a notification thread while
+ // the main thread is clearing the src_ctx ->capture_data and
+ // ->capture_callback from within vidcap_src_capture_stop()
+ vidcap_src_capture_callback cap_callback = src_ctx->capture_callback;
+ void * cap_data = src_ctx->capture_data;
+ int send_frame = 0;
+
+ if ( !error_status )
+ send_frame = enforce_framerate(src_ctx);
+
if ( send_frame < 0 )
error_status = -1000;
@@ -251,15 +259,16 @@
cap_info.video_data_size = video_data_size;
}
- if ( send_frame || error_status )
- src_ctx->capture_callback(src_ctx, src_ctx->capture_data,
- &cap_info);
+ if ( ( send_frame || error_status ) && cap_callback && cap_data != VIDCAP_INVALID_USER_DATA )
+ {
+ cap_callback(src_ctx, cap_data, &cap_info);
- if ( cap_info.error_status )
- {
- src_ctx->src_state = src_bound;
- src_ctx->capture_callback = 0;
- src_ctx->capture_data = 0;
+ if ( cap_info.error_status )
+ {
+ src_ctx->src_state = src_bound;
+ src_ctx->capture_callback = 0;
+ src_ctx->capture_data = VIDCAP_INVALID_USER_DATA;
+ }
}
return 0;
Modified: trunk/src/sapi.h
===================================================================
--- trunk/src/sapi.h 2007-09-13 18:32:29 UTC (rev 19)
+++ trunk/src/sapi.h 2007-09-13 19:25:43 UTC (rev 20)
@@ -30,6 +30,8 @@
#include "config.h"
#endif
+#define VIDCAP_INVALID_USER_DATA ((void *)-1)
+
#include "sapi_context.h"
#ifdef __cplusplus
Modified: trunk/src/vidcap.c
===================================================================
--- trunk/src/vidcap.c 2007-09-13 18:32:29 UTC (rev 19)
+++ trunk/src/vidcap.c 2007-09-13 19:25:43 UTC (rev 20)
@@ -439,6 +439,9 @@
struct sapi_src_context * src_ctx = (struct sapi_src_context *)src;
const int sliding_window_seconds = 4;
+ if ( user_data == VIDCAP_INVALID_USER_DATA )
+ return -3;
+
if ( src_ctx->src_state != src_bound )
return -1;
@@ -458,7 +461,7 @@
if ( (ret = src_ctx->start_capture(src_ctx)) )
{
src_ctx->capture_callback = 0;
- src_ctx->capture_data = 0;
+ src_ctx->capture_data = VIDCAP_INVALID_USER_DATA;
return ret;
}
@@ -482,7 +485,7 @@
sliding_window_destroy(src_ctx->frame_times);
src_ctx->capture_callback = 0;
- src_ctx->capture_data = 0;
+ src_ctx->capture_data = VIDCAP_INVALID_USER_DATA;
return ret;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|