|
From: libvidcap c. <lib...@li...> - 2007-12-03 14:09:10
|
Revision: 72
http://libvidcap.svn.sourceforge.net/libvidcap/?rev=72&view=rev
Author: bcholew
Date: 2007-12-03 06:09:08 -0800 (Mon, 03 Dec 2007)
Log Message:
-----------
Use abstracted thread and mutex functions in v4l and qt sapis.
Modified Paths:
--------------
trunk/src/sapi_qt.c
trunk/src/sapi_v4l.c
Modified: trunk/src/sapi_qt.c
===================================================================
--- trunk/src/sapi_qt.c 2007-12-03 14:07:46 UTC (rev 71)
+++ trunk/src/sapi_qt.c 2007-12-03 14:09:08 UTC (rev 72)
@@ -23,7 +23,6 @@
*
*/
-#include <pthread.h>
#include <stdlib.h>
#include <strings.h>
@@ -40,8 +39,9 @@
struct sapi_qt_context
{
- pthread_mutex_t mutex;
- pthread_t notify_thread;
+ vc_mutex mutex;
+ vc_thread notify_thread;
+ unsigned int notify_thread_id;
int notifying;
struct sg_manager mgr;
@@ -52,7 +52,8 @@
struct sg_source * src;
int capturing;
- pthread_t capture_thread;
+ vc_thread capture_thread;
+ unsigned int capture_thread_id;
TimeValue last_time;
long frame_count;
@@ -61,20 +62,20 @@
};
static int
-mutex_lock(pthread_mutex_t * mutex)
+mutex_lock(vc_mutex * mutex)
{
- int err = pthread_mutex_lock(mutex);
+ int err = vc_mutex_lock(mutex);
if ( err )
- log_error("failed pthread_mutex_lock() %d\n", err);
+ log_error("failed vc_mutex_lock() %d\n", err);
return err;
}
static int
-mutex_unlock(pthread_mutex_t * mutex)
+mutex_unlock(vc_mutex * mutex)
{
- int err = pthread_mutex_unlock(mutex);
+ int err = vc_mutex_unlock(mutex);
if ( err )
- log_error("failed pthread_mutex_unlock() %d\n", err);
+ log_error("failed vc_mutex_unlock() %d\n", err);
return err;
}
@@ -372,7 +373,7 @@
return ts;
}
-static void *
+static unsigned int
capture_thread_proc(void * data)
{
struct sapi_src_context * src_ctx =
@@ -392,22 +393,32 @@
if ( map_fourcc_to_ostype(src_ctx->fmt_native.fourcc, &pixel_format) )
{
- log_error("invalid pixel format '%s'\n",
+ log_error("invalid pixel format '%s' (0x%0x)\n",
vidcap_fourcc_string_get(
- src_ctx->fmt_native.fourcc));
- return (void *)-1;
+ src_ctx->fmt_native.fourcc),
+ src_ctx->fmt_native.fourcc);
+
+ ret = -2;
+ sapi_src_capture_notify(src_ctx, 0, 0, 0, ret);
+ return ret;
}
if ( sg_source_format_set(qt_src_ctx->src,
src_ctx->fmt_native.width,
src_ctx->fmt_native.height,
fps, pixel_format) )
- return (void *)-1;
+ {
+ ret = -3;
+ sapi_src_capture_notify(src_ctx, 0, 0, 0, ret);
+ return ret;
+ }
if ( qt_src_ctx->decomp_session )
{
log_error("decomp session already setup\n");
- return (void *)-1;
+ ret = -4;
+ sapi_src_capture_notify(src_ctx, 0, 0, 0, ret);
+ return ret;
}
qt_src_ctx->last_time = 0;
@@ -415,10 +426,18 @@
if ( sg_source_capture_start(qt_src_ctx->src, source_capture_callback,
(long)src_ctx) )
- return (void *)-1;
+ {
+ ret = -5;
+ sapi_src_capture_notify(src_ctx, 0, 0, 0, ret);
+ return ret;
+ }
if ( source_decomp_session_setup(src_ctx) )
- return (void *)-1;
+ {
+ ret = -6;
+ sapi_src_capture_notify(src_ctx, 0, 0, 0, ret);
+ return ret;
+ }
while ( qt_src_ctx->capturing )
{
@@ -426,8 +445,8 @@
if ( sg_source_capture_poll(qt_src_ctx->src) )
{
- sapi_src_capture_notify(src_ctx, 0, 0, 0, -1);
- ret = -1;
+ ret = -7;
+ sapi_src_capture_notify(src_ctx, 0, 0, 0, ret);
goto bail;
}
@@ -436,8 +455,9 @@
if ( errno != -EINTR )
{
log_error("failed nanosleep() %d\n", errno);
- ret = -1;
- goto bail;
+ ret = -8;
+ sapi_src_capture_notify(src_ctx, 0, 0, 0, ret);
+ goto bail;
}
}
}
@@ -445,12 +465,12 @@
bail:
if ( source_decomp_session_takedown(src_ctx) )
- ret = -1;
+ ret -= 100;
if ( sg_source_capture_stop(qt_src_ctx->src) )
- ret = -1;
+ ret -= -1000;
- return (void *)ret;
+ return ret;
}
static int
@@ -462,10 +482,11 @@
qt_src_ctx->capturing = 1;
- if ( (ret = pthread_create(&qt_src_ctx->capture_thread, 0,
- capture_thread_proc, src_ctx)) )
+ if ( (ret = vc_create_thread(&qt_src_ctx->capture_thread,
+ capture_thread_proc,
+ src_ctx, &qt_src_ctx->capture_thread_id)) )
{
- log_error("failed pthread_create() for capture thread %d\n",
+ log_error("failed vc_thread_create() for capture thread %d\n",
ret);
return -1;
}
@@ -480,20 +501,15 @@
(struct sapi_qt_src_context *)src_ctx->priv;
int ret;
- int thread_ret;
qt_src_ctx->capturing = 0;
- if ( (ret = pthread_join(qt_src_ctx->capture_thread,
- (void *)&thread_ret)) )
+ if ( (ret = vc_thread_join(&qt_src_ctx->capture_thread)) )
{
- log_error("failed pthread_join() %d\n", ret);
+ log_error("failed vc_thread_join() %d\n", ret);
return -1;
}
- if ( thread_ret )
- log_warn("capture_thread_proc returned %d\n", thread_ret);
-
return 0;
}
@@ -674,7 +690,7 @@
return -1;
}
-static void *
+static unsigned int
notify_thread_proc(void * data)
{
struct sapi_context * sapi_ctx = (struct sapi_context *)data;
@@ -690,18 +706,18 @@
int source_count;
if ( mutex_lock(&qt_ctx->mutex) )
- return (void *)-1;
+ return -1;
if ( sg_manager_update(&qt_ctx->mgr) )
{
mutex_unlock(&qt_ctx->mutex);
- return (void *)-1;
+ return -1;
}
source_count = sg_manager_source_count(&qt_ctx->mgr);
if ( mutex_unlock(&qt_ctx->mutex) )
- return (void *)-1;
+ return -1;
if ( source_count != last_source_count &&
sapi_ctx->notify_callback )
@@ -716,7 +732,7 @@
if ( errno != -EINTR )
{
log_error("failed nanosleep() %d\n", errno);
- return (void *)-1;
+ return -1;
}
}
}
@@ -729,20 +745,16 @@
{
struct sapi_qt_context * qt_ctx =
(struct sapi_qt_context *)sapi_ctx->priv;
- int thread_ret;
int ret;
qt_ctx->notifying = 0;
- if ( (ret = pthread_join(qt_ctx->notify_thread, (void *)&thread_ret)) )
+ if ( (ret = vc_thread_join(&qt_ctx->notify_thread)) )
{
- log_error("failed pthread_join() notify thread %d\n", ret);
+ log_error("failed vc_thread_join() notify thread %d\n", ret);
return -1;
}
- if ( thread_ret )
- log_warn("notify_thread_proc returned %d\n", thread_ret);
-
return 0;
}
@@ -758,10 +770,10 @@
qt_ctx->notifying = 1;
- if ( (ret = pthread_create(&qt_ctx->notify_thread, 0,
- notify_thread_proc, sapi_ctx)) )
+ if ( (ret = vc_create_thread(&qt_ctx->notify_thread, notify_thread_proc,
+ sapi_ctx, &qt_ctx->notify_thread_id)) )
{
- log_error("failed pthread_create() for notify thread %d\n",
+ log_error("failed vc_thread_create() for notify thread %d\n",
ret);
return -1;
}
@@ -791,7 +803,7 @@
ExitMovies();
- pthread_mutex_destroy(&qt_ctx->mutex);
+ vc_mutex_destroy(&qt_ctx->mutex);
free(sapi_ctx->user_src_list.list);
free(qt_ctx);
@@ -810,9 +822,9 @@
return -1;
}
- if ( pthread_mutex_init(&qt_ctx->mutex, 0) )
+ if ( vc_mutex_init(&qt_ctx->mutex) )
{
- log_error("failed pthread_mutex_init()\n");
+ log_error("failed vc_mutex_init()\n");
return -1;
}
Modified: trunk/src/sapi_v4l.c
===================================================================
--- trunk/src/sapi_v4l.c 2007-12-03 14:07:46 UTC (rev 71)
+++ trunk/src/sapi_v4l.c 2007-12-03 14:09:08 UTC (rev 72)
@@ -26,7 +26,6 @@
#include <errno.h>
#include <fcntl.h>
#include <linux/videodev.h>
-#include <pthread.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
@@ -51,8 +50,9 @@
struct sapi_v4l_context
{
- pthread_mutex_t mutex;
- pthread_t notify_thread;
+ vc_mutex mutex;
+ vc_thread notify_thread;
+ unsigned int notify_thread_id;
int notifying;
struct sapi_src_list acquired_src_list;
};
@@ -71,7 +71,8 @@
struct video_mbuf mbuf;
int capturing;
- pthread_t capture_thread;
+ vc_thread capture_thread;
+ unsigned int capture_thread_id;
};
static int
@@ -533,7 +534,7 @@
return 0;
}
-static void *
+static unsigned int
capture_thread_proc(void * data)
{
struct sapi_src_context * src_ctx =
@@ -554,7 +555,7 @@
if ( fb_base == (void *)-1 )
{
log_error("failed mmap() %d\n", errno);
- return (void *)-1;
+ return -1;
}
if ( capture_kickoff(src_ctx, started_frame_count) )
@@ -575,8 +576,8 @@
goto bail;
}
- sapi_src_capture_notify(src_ctx, fb_base +
- v4l_src_ctx->mbuf.offsets[capture_frame],
+ sapi_src_capture_notify(src_ctx, (char *)(fb_base +
+ v4l_src_ctx->mbuf.offsets[capture_frame]),
capture_size,
0,
0);
@@ -603,7 +604,7 @@
if ( munmap((void *)fb_base, v4l_src_ctx->mbuf.size) == -1 )
{
log_error("failed munmap() %d\n", errno);
- return (void *)-1;
+ return -1;
}
return 0;
@@ -612,7 +613,7 @@
if ( munmap((void *)fb_base, v4l_src_ctx->mbuf.size) == -1 )
log_warn("failed munmap() %d\n", errno);
- return (void *)-1;
+ return -1;
}
static int
@@ -624,10 +625,11 @@
v4l_src_ctx->capturing = 1;
- if ( (ret = pthread_create(&v4l_src_ctx->capture_thread, 0,
- capture_thread_proc, src_ctx)) )
+ if ( (ret = vc_create_thread(&v4l_src_ctx->capture_thread,
+ capture_thread_proc, src_ctx,
+ &v4l_src_ctx->capture_thread_id)) )
{
- log_error("failed pthread_create() for capture thread %d\n",
+ log_error("failed vc_create_thread() for capture thread %d\n",
ret);
return -1;
}
@@ -641,20 +643,15 @@
struct sapi_v4l_src_context * v4l_src_ctx =
(struct sapi_v4l_src_context *)src_ctx->priv;
int ret;
- int thread_ret;
v4l_src_ctx->capturing = 0;
- if ( (ret = pthread_join(v4l_src_ctx->capture_thread,
- (void *)&thread_ret)) )
+ if ( (ret = vc_thread_join(&v4l_src_ctx->capture_thread)) )
{
- log_error("failed pthread_join() %d\n", ret);
+ log_error("failed vc_thread_join() %d\n", ret);
return -1;
}
- if ( thread_ret )
- log_warn("capture_thread_proc returned %d\n", thread_ret);
-
return 0;
}
@@ -928,7 +925,7 @@
return -1;
}
-static void *
+static unsigned int
notify_thread_proc(void * data)
{
struct sapi_context * sapi_ctx = (struct sapi_context *)data;
@@ -939,18 +936,18 @@
while ( v4l_ctx->notifying )
{
- pthread_mutex_lock(&v4l_ctx->mutex);
+ vc_mutex_lock(&v4l_ctx->mutex);
/* TODO: look for devices */
- pthread_mutex_unlock(&v4l_ctx->mutex);
+ vc_mutex_unlock(&v4l_ctx->mutex);
if ( nanosleep(&wait_ts, 0) )
{
if ( errno != -EINTR )
{
log_error("failed nanosleep() %d\n", errno);
- return (void *)-1;
+ return -1;
}
}
}
@@ -963,20 +960,16 @@
{
struct sapi_v4l_context * v4l_ctx =
(struct sapi_v4l_context *)sapi_ctx->priv;
- int thread_ret;
int ret;
v4l_ctx->notifying = 0;
- if ( (ret = pthread_join(v4l_ctx->notify_thread, (void *)&thread_ret)) )
+ if ( (ret = vc_thread_join(&v4l_ctx->notify_thread)) )
{
- log_error("failed pthread_join() notify thread %d\n", ret);
+ log_error("failed vc_thread_join() notify thread %d\n", ret);
return -1;
}
- if ( thread_ret )
- log_warn("notify_thread_proc returned %d\n", thread_ret);
-
return 0;
}
@@ -992,10 +985,11 @@
v4l_ctx->notifying = 1;
- if ( (ret = pthread_create(&v4l_ctx->notify_thread, 0,
- notify_thread_proc, sapi_ctx)) )
+ if ( (ret = vc_create_thread(&v4l_ctx->notify_thread,
+ notify_thread_proc, sapi_ctx,
+ &v4l_ctx->notify_thread_id)) )
{
- log_error("failed pthread_create() for notify thread %d\n",
+ log_error("failed vc_create_thread() for notify thread %d\n",
ret);
return -1;
}
@@ -1009,7 +1003,7 @@
struct sapi_v4l_context * v4l_ctx =
(struct sapi_v4l_context *)sapi_ctx->priv;
- pthread_mutex_destroy(&v4l_ctx->mutex);
+ vc_mutex_destroy(&v4l_ctx->mutex);
free(sapi_ctx->user_src_list.list);
free(v4l_ctx);
@@ -1028,9 +1022,9 @@
return -1;
}
- if ( pthread_mutex_init(&v4l_ctx->mutex, 0) )
+ if ( vc_mutex_init(&v4l_ctx->mutex) )
{
- log_error("failed pthread_mutex_init()\n");
+ log_error("failed vc_mutex_init()\n");
return -1;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|