コード例 #1
0
ファイル: core.c プロジェクト: ABMNYZ/libfreenect
FREENECTAPI int freenect_process_events(freenect_context *ctx)
{
	struct timeval timeout;
	timeout.tv_sec = 60;
	timeout.tv_usec = 0;
	return freenect_process_events_timeout(ctx, &timeout);
}
コード例 #2
0
ファイル: Device.c プロジェクト: jarney/snackbot
void *freenect_threadfunc(void *arg)
{
    struct timeval timeout;
    
    timeout.tv_sec = 0;
    timeout.tv_usec = 10000;
    
    JavaVMAttachArgs attachArgs;
    attachArgs.version = JNI_VERSION_1_6;
    attachArgs.name = "Freenect event handler";
    attachArgs.group = NULL;
    
    (*jvm)->AttachCurrentThread(jvm, (void **) &thread_env, &attachArgs);
        
    // Set up JNIEnv
    //
    while (1) {
        int exit = 0;
        pthread_mutex_lock(&mutex);
        exit = !f_running;
        pthread_mutex_unlock(&mutex);

        if (exit) {
            break;
        }
        freenect_process_events_timeout(f_ctx, &timeout);
    }
    
    (*jvm)->DetachCurrentThread(jvm);
    
    return NULL;
}
コード例 #3
0
ファイル: freenect-helpers.c プロジェクト: TomMD/freenect
int process_events_timeout(freenect_context* ctx, int microseconds)
{
    struct timeval timeout;
    
    timeout.tv_sec = microseconds / 1000000;
    timeout.tv_usec = microseconds - timeout.tv_sec * 1000000;

    return freenect_process_events_timeout(ctx, &timeout);

}
コード例 #4
0
 void process() {
   while (thread_running_) {
     timeval t;
     t.tv_sec = 0;
     t.tv_usec = 10000;
     if (freenect_process_events_timeout(driver_, &t) < 0)
       throw std::runtime_error("freenect_process_events error");
     if (device_)
       device_->executeChanges();
   }
 }
コード例 #5
0
ファイル: libfreenect.hpp プロジェクト: ABMNYZ/libfreenect
		// Do not call directly, thread runs here
		void operator()() {
			while (!m_stop) {
				static timeval timeout = { 1, 0 };
				int res = freenect_process_events_timeout(m_ctx, &timeout);
				if (res < 0)
				{
					// libusb signals an error has occurred
					if (res == LIBUSB_ERROR_INTERRUPTED)
					{
						// This happens sometimes, it means that a system call in libusb was interrupted somehow (perhaps due to a signal)
						// The simple solution seems to be just ignore it.
						continue;
					}
					std::stringstream ss;
					ss << "Cannot process freenect events (libusb error code: " << res << ")";
					throw std::runtime_error(ss.str());
				}
			}
		}
コード例 #6
0
void *jit_freenect_capture_threadproc()//t_jit_freenect_grab *x) 
{
 
#ifdef NESADEBUG
#warning if crash remove=NULL
#endif
	freenect_context *context = NULL;
	
	postNesa("Threadproc called");//TODO:r
	
	if(!f_ctx){
		postNesa("f_ctx is null, calling init_Freenect");//TODO:r
		if (freenect_init(&context, NULL) < 0) {
			error("freenect_init() failed");
			goto out;
		}
		freenect_set_log_level(context, JIT_FREENECT_LOG_LEVEL);
		postNesa("freenect_init ok,id");//TODO: remove
	}
	
	f_ctx = context;
	
	struct timeval timeout;
	timeout.tv_sec = 60;
	timeout.tv_usec = 0;
	
	// loop until told to stop
	while (1) {
		
		//postNesaFlood("threadid=%i",x->id);
		// test if we're being asked to die, and if so return before we do the work
		if (x_systhread_cancel)
		{
			postNesa("stopping thread");
			break;
		}
		// this thread is used only to process freenect events
		// no need to lock the mutex
		//systhread_mutex_lock(x->x_mutex);	

		//if(f_ctx->first){
			//if(freenect_process_events(f_ctx) < 0){
		
		//if(freenect_active)
		//{
		if(f_ctx->first)
		if(freenect_process_events_timeout(f_ctx, &timeout)<0)
			{
				error("Could not process events.");
				//if (x->x_systhread_cancel) 
				break;
			}
		//}
		//else {
		//	postNesa("freenect_active=false\n");
		//}


		//}
		//else {
		//	post("not first");//TODO:remove
		//}
		//x->x_foo++;																// fiddle with shared data
		
		
		//systhread_mutex_unlock(x->x_mutex);
		
		//qelem_set(x->x_qelem);													// notify main thread using qelem mechanism
		
		//usleep(2500);
		//systhread_sleep(x->x_sleeptime);						// sleep a bit
	}

out:
	postNesa("Threadproc exits");//TODO:r
	
	
	//postNesa("Threadproc calls grab_close ,id=%i\n",x->id);//TODO:r
	// TODO: add notification through dupmoutlet
	//jit_freenect_grab_close(x, NULL, 0, NULL);
	
	freenect_shutdown(f_ctx);
	f_ctx = NULL;
	
	
	//x->x_systhread_cancel = false;							// reset cancel flag for next time, in case
	// the thread is created again
	
	systhread_exit(0);															// this can return a value to systhread_join();
	return NULL;
}