コード例 #1
0
ファイル: vidmix.c プロジェクト: traviscross/librem
static void *vidmix_thread(void *arg)
{
	struct vidmix_source *src = arg;
	struct vidmix *mix = src->mix;
	uint64_t ts = tmr_jiffies();

	pthread_mutex_lock(&src->mutex);

	while (src->run) {

		unsigned n, rows, idx;
		struct le *le;
		uint64_t now;

		pthread_mutex_unlock(&src->mutex);
		(void)usleep(4000);
		pthread_mutex_lock(&src->mutex);

		now = tmr_jiffies();

		if (ts > now)
			continue;

		if (!src->frame_tx) {
			ts += src->fint;
			continue;
		}

		pthread_rwlock_rdlock(&mix->rwlock);

		if (src->clear) {
			clear_frame(src->frame_tx);
			src->clear = false;
		}

		for (le=mix->srcl.head, n=0; le; le=le->next) {

			const struct vidmix_source *lsrc = le->data;

			if (lsrc == src && !src->selfview)
				continue;

			if (lsrc->content && src->content_hide)
				continue;

			if (lsrc == src->focus && src->focus_full)
				source_mix_full(src->frame_tx, lsrc->frame_rx);

			++n;
		}

		rows = calc_rows(n);

		for (le=mix->srcl.head, idx=0; le; le=le->next) {

			const struct vidmix_source *lsrc = le->data;

			if (lsrc == src && !src->selfview)
				continue;

			if (lsrc->content && src->content_hide)
				continue;

			if (lsrc == src->focus && src->focus_full)
				continue;

			source_mix(src->frame_tx, lsrc->frame_rx, n, rows, idx,
				   src->focus != NULL, src->focus == lsrc,
				   src->focus_full);

			if (src->focus != lsrc)
				++idx;
		}

		pthread_rwlock_unlock(&mix->rwlock);

		src->fh((uint32_t)ts * 90, src->frame_tx, src->arg);

		ts += src->fint;
	}

	pthread_mutex_unlock(&src->mutex);

	return NULL;
}
コード例 #2
0
ファイル: read_txt.cpp プロジェクト: mdmitr/surfit
bool one_columns_read(const char * filename, 
                      int col1, 
		      int skip_lines,
		      const char * delimiter, int grow_by,
		      vec *& vcol1,
		      int read_lines)
{
	FILE * file = fopen(filename, "rb");
	if (!file) {
		writelog(LOG_ERROR, "The file %s was not opened: %s",filename,strerror( errno ));
		return false;
	}
	if (ferror(file) != 0) {
		writelog(LOG_ERROR, "Loading from one-column file: file error.");
		fclose(file);
		return false;
	}
	
	if (grow_by == 250)
	{
		int size = file_size(file);
		grow_by = MAX(250,size/100);
	}


	char string_buf[MY_READ_BUF_SIZE];

	int i;
	for (i = 0; i < skip_lines; i++) {
		if (!fgets(string_buf,MY_READ_BUF_SIZE,file)) 
		{
			fclose(file);
			return false;
		}
		if (feof(file)) {
			fclose(file);
			return false;
		}
	};

	vcol1 = create_vec();
	vcol1->set_grow(grow_by);
	char * seps = strdup(delimiter);
	char * token = NULL;
	int columns = 0;
	int rows = 0;
	int lines_readed = 0;
	int current_column = 0;
	int size = 0;

	// calculate number of columns!
	fpos_t pos;
	if (fgetpos(file, &pos) != 0)
		goto one_columns_read_failed;

	if (!fgets(string_buf,MY_READ_BUF_SIZE,file)) 
		goto one_columns_read_failed;

	

	columns = calc_columns(string_buf, MY_READ_BUF_SIZE, seps);

	fread(string_buf, MY_READ_BUF_SIZE, sizeof(char), file);
	if (ferror(file) != 0)
		goto one_columns_read_failed;

	rows = calc_rows(string_buf, MY_READ_BUF_SIZE);

	if (fsetpos(file, &pos) != 0)
		goto one_columns_read_failed;
	
	if (col1 > columns)
		goto one_columns_read_failed;
	
	while (!feof(file) ) {
		if (!fgets(string_buf,MY_READ_BUF_SIZE,file)) {
			if (feof(file))
				break;
			goto one_columns_read_failed;
		}
		
		if (read_lines > 0) {
			lines_readed++;
			if (lines_readed > read_lines)
				break;
		}

		current_column = 0;
		token = strtok(string_buf, seps);
		REAL val1 = FLT_MAX, val2 = FLT_MAX;
		while (token != NULL) {
			if ((current_column+1 == col1) || (rows == 1)) {
				if (strlen(token) > 0)
					val1 = (REAL)ator(token);
				
			}

			if ((rows == 1) && (val1 != FLT_MAX))
			{
				vcol1->push_back(val1);
				val1 = FLT_MAX;
			}
				
			current_column++;
			token = strtok( NULL, seps );
		}

		if (
			(((val1 != FLT_MAX) || (col1 == 0))  && (rows != 1))
		   ) 
		{
			vcol1->push_back(val1);
		}
		val1 = FLT_MAX;
		
	}

	free(seps);
	fclose(file);
		
	return true;

one_columns_read_failed:

	fclose(file);
	free(seps);
	if (vcol1)
		vcol1->release();
	vcol1 = NULL;
	return false;
};