예제 #1
0
static void* serial_thread_func(void* arg)
{
    SERIAL_DEVICE* serial = (SERIAL_DEVICE*)arg;

    while (1)
    {
        freerdp_thread_wait(serial->thread);

        serial->nfds = 1;
        FD_ZERO(&serial->read_fds);
        FD_ZERO(&serial->write_fds);

        serial->tv.tv_sec = 20;
        serial->tv.tv_usec = 0;
        serial->select_timeout = 0;

        if (freerdp_thread_is_stopped(serial->thread))
            break;

        freerdp_thread_reset(serial->thread);
        serial_process_irp_list(serial);

        if (wait_obj_is_set(serial->in_event))
        {
            if (serial_check_fds(serial))
                wait_obj_clear(serial->in_event);
        }
    }

    freerdp_thread_quit(serial->thread);

    return NULL;
}
예제 #2
0
static void svc_plugin_process_data_in(rdpSvcPlugin* plugin)
{
	svc_data_in_item* item;

	while (1)
	{
		/* terminate signal */
		if (freerdp_thread_is_stopped(plugin->priv->thread))
			break;

		freerdp_thread_lock(plugin->priv->thread);
		item = list_dequeue(plugin->priv->data_in_list);
		freerdp_thread_unlock(plugin->priv->thread);

		if (item != NULL)
		{
			/* the ownership of the data is passed to the callback */
			if (item->data_in)
				IFCALL(plugin->receive_callback, plugin, item->data_in);
			if (item->event_in)
				IFCALL(plugin->event_callback, plugin, item->event_in);
			xfree(item);
		}
		else
			break;
	}
}
예제 #3
0
static void* svc_plugin_thread_func(void* arg)
{
	rdpSvcPlugin* plugin = (rdpSvcPlugin*)arg;

	DEBUG_SVC("in");

	IFCALL(plugin->connect_callback, plugin);

	while (1)
	{
		if (plugin->interval_ms > 0)
			freerdp_thread_wait_timeout(plugin->priv->thread, plugin->interval_ms);
		else
			freerdp_thread_wait(plugin->priv->thread);

		if (freerdp_thread_is_stopped(plugin->priv->thread))
			break;

		freerdp_thread_reset(plugin->priv->thread);
		svc_plugin_process_data_in(plugin);

		if (plugin->interval_ms > 0)
			IFCALL(plugin->interval_callback, plugin);
	}

	freerdp_thread_quit(plugin->priv->thread);

	DEBUG_SVC("out");

	return 0;
}
예제 #4
0
static void* audin_alsa_thread_func(void* arg)
{
	int error;
	uint8* buffer;
	int rbytes_per_frame;
	int tbytes_per_frame;
	snd_pcm_t* capture_handle = NULL;
	AudinALSADevice* alsa = (AudinALSADevice*) arg;

	DEBUG_DVC("in");

	rbytes_per_frame = alsa->actual_channels * alsa->bytes_per_channel;
	tbytes_per_frame = alsa->target_channels * alsa->bytes_per_channel;
	alsa->buffer = (uint8*) xzalloc(tbytes_per_frame * alsa->frames_per_packet);
	alsa->buffer_frames = 0;
	buffer = (uint8*) xzalloc(rbytes_per_frame * alsa->frames_per_packet);
	memset(&alsa->adpcm, 0, sizeof(ADPCM));
	do
	{
		if ((error = snd_pcm_open(&capture_handle, alsa->device_name, SND_PCM_STREAM_CAPTURE, 0)) < 0)
		{
			DEBUG_WARN("snd_pcm_open (%s)", snd_strerror(error));
			break;
		}
		if (!audin_alsa_set_params(alsa, capture_handle))
		{
			break;
		}

		while (!freerdp_thread_is_stopped(alsa->thread))
		{
			error = snd_pcm_readi(capture_handle, buffer, alsa->frames_per_packet);
			if (error == -EPIPE)
			{
				snd_pcm_recover(capture_handle, error, 0);
				continue;
			}
			else if (error < 0)
			{
				DEBUG_WARN("snd_pcm_readi (%s)", snd_strerror(error));
				break;
			}
			if (!audin_alsa_thread_receive(alsa, buffer, error * rbytes_per_frame))
				break;
		}
	} while (0);

	xfree(buffer);
	xfree(alsa->buffer);
	alsa->buffer = NULL;
	if (capture_handle)
		snd_pcm_close(capture_handle);

	freerdp_thread_quit(alsa->thread);

	DEBUG_DVC("out");

	return NULL;
}
예제 #5
0
파일: sfreerdp.c 프로젝트: 4hosi/FreeRDP
static void* tf_debug_channel_thread_func(void* arg)
{
	void* fd;
	STREAM* s;
	void* buffer;
	UINT32 bytes_returned = 0;
	testPeerContext* context = (testPeerContext*) arg;
	freerdp_thread* thread = context->debug_channel_thread;

	if (WTSVirtualChannelQuery(context->debug_channel, WTSVirtualFileHandle, &buffer, &bytes_returned) == TRUE)
	{
		fd = *((void**) buffer);
		WTSFreeMemory(buffer);
		thread->signals[thread->num_signals++] = CreateFileDescriptorEvent(NULL, TRUE, FALSE, ((int) (long) fd));
	}

	s = stream_new(4096);

	WTSVirtualChannelWrite(context->debug_channel, (BYTE*) "test1", 5, NULL);

	while (1)
	{
		freerdp_thread_wait(thread);

		if (freerdp_thread_is_stopped(thread))
			break;

		stream_set_pos(s, 0);

		if (WTSVirtualChannelRead(context->debug_channel, 0, stream_get_head(s),
			stream_get_size(s), &bytes_returned) == FALSE)
		{
			if (bytes_returned == 0)
				break;

			stream_check_size(s, bytes_returned);

			if (WTSVirtualChannelRead(context->debug_channel, 0, stream_get_head(s),
				stream_get_size(s), &bytes_returned) == FALSE)
			{
				/* should not happen */
				break;
			}
		}

		stream_set_pos(s, bytes_returned);

		printf("got %d bytes\n", bytes_returned);
	}

	stream_free(s);
	freerdp_thread_quit(thread);

	return 0;
}
예제 #6
0
static void* tf_debug_channel_thread_func(void* arg)
{
	void* fd;
	STREAM* s;
	void* buffer;
	uint32 bytes_returned = 0;
	testPeerContext* context = (testPeerContext*) arg;
	freerdp_thread* thread = context->debug_channel_thread;

	if (WTSVirtualChannelQuery(context->debug_channel, WTSVirtualFileHandle, &buffer, &bytes_returned) == true)
	{
		fd = *((void**)buffer);
		WTSFreeMemory(buffer);
		thread->signals[thread->num_signals++] = wait_obj_new_with_fd(fd);
	}

	s = stream_new(4096);

	WTSVirtualChannelWrite(context->debug_channel, (uint8*) "test1", 5, NULL);

	while (1)
	{
		freerdp_thread_wait(thread);
		if (freerdp_thread_is_stopped(thread))
			break;

		stream_set_pos(s, 0);
		if (WTSVirtualChannelRead(context->debug_channel, 0, stream_get_head(s),
			stream_get_size(s), &bytes_returned) == false)
		{
			if (bytes_returned == 0)
				break;
			stream_check_size(s, bytes_returned);
			if (WTSVirtualChannelRead(context->debug_channel, 0, stream_get_head(s),
				stream_get_size(s), &bytes_returned) == false)
			{
				/* should not happen */
				break;
			}
		}
		stream_set_pos(s, bytes_returned);

		printf("got %d bytes\n", bytes_returned);
	}

	stream_free(s);
	freerdp_thread_quit(thread);

	return 0;
}
예제 #7
0
static void* printer_thread_func(void* arg) {
	PRINTER_DEVICE* printer_dev = (PRINTER_DEVICE*) arg;

	while (1) {
		freerdp_thread_wait(printer_dev->thread);

		if (freerdp_thread_is_stopped(printer_dev->thread))
			break;

		freerdp_thread_reset(printer_dev->thread);
		printer_process_irp_list(printer_dev);
	}

	freerdp_thread_quit(printer_dev->thread);

	return NULL;
}
예제 #8
0
static void printer_process_irp_list(PRINTER_DEVICE* printer_dev) {
	IRP* irp;

	while (1) {
		if (freerdp_thread_is_stopped(printer_dev->thread))
			break;

		freerdp_thread_lock(printer_dev->thread);
		irp = (IRP*) list_dequeue(printer_dev->irp_list);
		freerdp_thread_unlock(printer_dev->thread);

		if (irp == NULL)
			break;

		printer_process_irp(printer_dev, irp);
	}
}
예제 #9
0
static void parallel_process_irp_list(PARALLEL_DEVICE* parallel)
{
	IRP* irp;

	while (1)
	{
		if (freerdp_thread_is_stopped(parallel->thread))
			break;

		irp = (IRP*) InterlockedPopEntrySList(parallel->pIrpList);

		if (irp == NULL)
			break;

		parallel_process_irp(parallel, irp);
	}
}
예제 #10
0
static void printer_process_irp_list(PRINTER_DEVICE* printer_dev)
{
    IRP* irp;

    while (1)
    {
        if (freerdp_thread_is_stopped(printer_dev->thread))
            break;

        irp = (IRP*) InterlockedPopEntrySList(printer_dev->pIrpList);

        if (irp == NULL)
            break;

        printer_process_irp(printer_dev, irp);
    }
}
예제 #11
0
static void
scard_process_irp_list(SCARD_DEVICE* scard)
{
	IRP *irp;

	while (!freerdp_thread_is_stopped(scard->thread))
	{
		freerdp_thread_lock(scard->thread);
		irp = (IRP *) list_dequeue(scard->irp_list);
		freerdp_thread_unlock(scard->thread);

		if (irp == NULL)
			break;

		scard_process_irp(scard, irp);
	}
}
예제 #12
0
static void parallel_process_irp_list(PARALLEL_DEVICE* parallel)
{
    IRP* irp;

    while (1)
    {
        if (freerdp_thread_is_stopped(parallel->thread))
            break;

        freerdp_thread_lock(parallel->thread);
        irp = (IRP*) list_dequeue(parallel->irp_list);
        freerdp_thread_unlock(parallel->thread);

        if (irp == NULL)
            break;

        parallel_process_irp(parallel, irp);
    }
}
예제 #13
0
static void* parallel_thread_func(void* arg)
{
    PARALLEL_DEVICE* parallel = (PARALLEL_DEVICE*) arg;

    while (1)
    {
        freerdp_thread_wait(parallel->thread);

        if (freerdp_thread_is_stopped(parallel->thread))
            break;

        freerdp_thread_reset(parallel->thread);
        parallel_process_irp_list(parallel);
    }

    freerdp_thread_quit(parallel->thread);

    return NULL;
}
예제 #14
0
static void serial_process_irp_list(SERIAL_DEVICE* serial)
{
    IRP* irp;

    while (1)
    {
        if (freerdp_thread_is_stopped(serial->thread))
            break;

        freerdp_thread_lock(serial->thread);
        irp = (IRP*)list_dequeue(serial->irp_list);
        freerdp_thread_unlock(serial->thread);

        if (irp == NULL)
            break;

        serial_process_irp(serial, irp);
    }
}
예제 #15
0
static void *
scard_thread_func(void* arg)
{
	SCARD_DEVICE* scard = (SCARD_DEVICE*) arg;

	while (1)
	{
		freerdp_thread_wait(scard->thread);

		if (freerdp_thread_is_stopped(scard->thread))
			break;

		freerdp_thread_reset(scard->thread);
		scard_process_irp_list(scard);
	}

	freerdp_thread_quit(scard->thread);

	return NULL;
}
예제 #16
0
static boolean audin_alsa_thread_receive(AudinALSADevice* alsa, uint8* src, int size)
{
	int frames;
	int cframes;
	int ret = 0;
	int encoded_size;
	uint8* encoded_data;
	int rbytes_per_frame;
	int tbytes_per_frame;

	rbytes_per_frame = alsa->actual_channels * alsa->bytes_per_channel;
	tbytes_per_frame = alsa->target_channels * alsa->bytes_per_channel;

	if ((alsa->target_rate == alsa->actual_rate) &&
		(alsa->target_channels == alsa->actual_channels))
	{
		frames = size / rbytes_per_frame;
	}
	else
	{
		alsa->dsp_context->resample(alsa->dsp_context, src, alsa->bytes_per_channel,
			alsa->actual_channels, alsa->actual_rate, size / rbytes_per_frame,
			alsa->target_channels, alsa->target_rate);
		frames = alsa->dsp_context->resampled_frames;
		DEBUG_DVC("resampled %d frames at %d to %d frames at %d",
			size / rbytes_per_frame, alsa->actual_rate, frames, alsa->target_rate);
		size = frames * tbytes_per_frame;
		src = alsa->dsp_context->resampled_buffer;
	}

	while (frames > 0)
	{
		if (freerdp_thread_is_stopped(alsa->thread))
			break;

		cframes = alsa->frames_per_packet - alsa->buffer_frames;
		if (cframes > frames)
			cframes = frames;
		memcpy(alsa->buffer + alsa->buffer_frames * tbytes_per_frame,
			src, cframes * tbytes_per_frame);
		alsa->buffer_frames += cframes;
		if (alsa->buffer_frames >= alsa->frames_per_packet)
		{
			if (alsa->wformat == 0x11)
			{
				alsa->dsp_context->encode_ima_adpcm(alsa->dsp_context,
					alsa->buffer, alsa->buffer_frames * tbytes_per_frame,
					alsa->target_channels, alsa->block_size);
				encoded_data = alsa->dsp_context->adpcm_buffer;
				encoded_size = alsa->dsp_context->adpcm_size;
				DEBUG_DVC("encoded %d to %d",
					alsa->buffer_frames * tbytes_per_frame, encoded_size);
			}
			else
			{
				encoded_data = alsa->buffer;
				encoded_size = alsa->buffer_frames * tbytes_per_frame;
			}

			if (freerdp_thread_is_stopped(alsa->thread))
			{
				ret = 0;
				frames = 0;
			}
			else
				ret = alsa->receive(encoded_data, encoded_size, alsa->user_data);
			alsa->buffer_frames = 0;
			if (!ret)
				break;
		}
		src += cframes * tbytes_per_frame;
		frames -= cframes;
	}

	return ret;
}
예제 #17
0
파일: audin.c 프로젝트: 5m3ntarios/FreeRDP
static void* audin_server_thread_func(void* arg)
{
	void* fd;
	STREAM* s;
	void* buffer;
	BYTE MessageId;
	BOOL ready = FALSE;
	UINT32 bytes_returned = 0;
	audin_server* audin = (audin_server*) arg;
	freerdp_thread* thread = audin->audin_channel_thread;

	if (WTSVirtualChannelQuery(audin->audin_channel, WTSVirtualFileHandle, &buffer, &bytes_returned) == TRUE)
	{
		fd = *((void**)buffer);
		WTSFreeMemory(buffer);
		thread->signals[thread->num_signals++] = wait_obj_new_with_fd(fd);
	}

	/* Wait for the client to confirm that the Audio Input dynamic channel is ready */
	while (1)
	{
		freerdp_thread_wait(thread);
		if (freerdp_thread_is_stopped(thread))
			break;

		if (WTSVirtualChannelQuery(audin->audin_channel, WTSVirtualChannelReady, &buffer, &bytes_returned) == FALSE)
			break;
		ready = *((BOOL*)buffer);
		WTSFreeMemory(buffer);
		if (ready)
			break;
	}

	s = stream_new(4096);

	if (ready)
	{
		audin_server_send_version(audin, s);
	}

	while (ready)
	{
		freerdp_thread_wait(thread);
		
		if (freerdp_thread_is_stopped(thread))
			break;

		stream_set_pos(s, 0);

		if (WTSVirtualChannelRead(audin->audin_channel, 0, stream_get_head(s),
			stream_get_size(s), &bytes_returned) == FALSE)
		{
			if (bytes_returned == 0)
				break;
			
			stream_check_size(s, (int) bytes_returned);

			if (WTSVirtualChannelRead(audin->audin_channel, 0, stream_get_head(s),
				stream_get_size(s), &bytes_returned) == FALSE)
				break;
		}
		if (bytes_returned < 1)
			continue;

		stream_read_BYTE(s, MessageId);
		bytes_returned--;
		switch (MessageId)
		{
			case MSG_SNDIN_VERSION:
				if (audin_server_recv_version(audin, s, bytes_returned))
					audin_server_send_formats(audin, s);
				break;

			case MSG_SNDIN_FORMATS:
				if (audin_server_recv_formats(audin, s, bytes_returned))
					audin_server_send_open(audin, s);
				break;

			case MSG_SNDIN_OPEN_REPLY:
				audin_server_recv_open_reply(audin, s, bytes_returned);
				break;

			case MSG_SNDIN_DATA_INCOMING:
				break;

			case MSG_SNDIN_DATA:
				audin_server_recv_data(audin, s, bytes_returned);
				break;

			case MSG_SNDIN_FORMATCHANGE:
				break;

			default:
				printf("audin_server_thread_func: unknown MessageId %d\n", MessageId);
				break;
		}
	}

	stream_free(s);
	WTSVirtualChannelClose(audin->audin_channel);
	audin->audin_channel = NULL;
	freerdp_thread_quit(thread);

	return NULL;
}
예제 #18
0
파일: rdpsnd.c 프로젝트: mgariepy/FreeRDP
static void* rdpsnd_server_thread_func(void* arg)
{
	void* fd;
	STREAM* s;
	void* buffer;
	BYTE msgType;
	UINT16 BodySize;
	UINT32 bytes_returned = 0;
	rdpsnd_server* rdpsnd = (rdpsnd_server*) arg;
	freerdp_thread* thread = rdpsnd->rdpsnd_channel_thread;

	if (WTSVirtualChannelQuery(rdpsnd->rdpsnd_channel, WTSVirtualFileHandle, &buffer, &bytes_returned) == TRUE)
	{
		fd = *((void**)buffer);
		WTSFreeMemory(buffer);
		thread->signals[thread->num_signals++] = wait_obj_new_with_fd(fd);
	}

	s = stream_new(4096);

	rdpsnd_server_send_formats(rdpsnd, s);

	while (1)
	{
		freerdp_thread_wait(thread);
		
		if (freerdp_thread_is_stopped(thread))
			break;

		stream_set_pos(s, 0);

		if (WTSVirtualChannelRead(rdpsnd->rdpsnd_channel, 0, stream_get_head(s),
			stream_get_size(s), &bytes_returned) == FALSE)
		{
			if (bytes_returned == 0)
				break;
			
			stream_check_size(s, (int) bytes_returned);

			if (WTSVirtualChannelRead(rdpsnd->rdpsnd_channel, 0, stream_get_head(s),
				stream_get_size(s), &bytes_returned) == FALSE)
				break;
		}

		stream_read_BYTE(s, msgType);
		stream_seek_BYTE(s); /* bPad */
		stream_read_UINT16(s, BodySize);

		if (BodySize + 4 > (int) bytes_returned)
			continue;

		switch (msgType)
		{
			case SNDC_FORMATS:
				if (rdpsnd_server_recv_formats(rdpsnd, s))
				{
					IFCALL(rdpsnd->context.Activated, &rdpsnd->context);
				}
				break;
			default:
				break;
		}
	}

	stream_free(s);
	freerdp_thread_quit(thread);

	return 0;
}