Esempio n. 1
0
static DWORD WINAPI wf_peer_mirror_monitor(LPVOID lpParam)
{
	DWORD fps;
	wfInfo* wfi;
	DWORD beg, end;
	DWORD diff, rate;
	freerdp_peer* client;
	wfPeerContext* context;

	fps = 24;
	rate = 1000 / fps;
	client = (freerdp_peer*) lpParam;
	context = (wfPeerContext*) client->context;
	wfi = context->info;
	
	while (1)
	{
		beg = GetTickCount();

		if (wf_info_lock(wfi) > 0)
		{
			if (wfi->peerCount > 0)
			{
				wf_info_update_changes(wfi);

				if (wf_info_have_updates(wfi))
				{
					wf_update_encode(wfi);
					SetEvent(wfi->updateEvent);
				}
			}

			wf_info_unlock(wfi);
		}

		end = GetTickCount();
		diff = end - beg;

		if (diff < rate)
		{
			Sleep(rate - diff);
		}
	}
	
	wf_info_lock(wfi);
	wfi->threadCount--;
	wf_info_unlock(wfi);

	return 0;
}
Esempio n. 2
0
void wf_update_encoder_reset(wfInfo* wfi)
{
	if (wf_info_lock(wfi) > 0)
	{
		printf("Resetting encoder\n");

		if (wfi->rfx_context)
		{
			rfx_context_reset(wfi->rfx_context);
		}
		else
		{
			wfi->rfx_context = rfx_context_new();
			wfi->rfx_context->mode = RLGR3;
			wfi->rfx_context->width = wfi->width;
			wfi->rfx_context->height = wfi->height;
			rfx_context_set_pixel_format(wfi->rfx_context, RDP_PIXEL_FORMAT_B8G8R8A8);
			wfi->s = stream_new(0xFFFF);
		}

		wf_info_invalidate_full_screen(wfi);

		wf_info_unlock(wfi);
	}
}
Esempio n. 3
0
void wf_peer_init(freerdp_peer* client)
{
	wfInfo* wfi;

	client->context_size = sizeof(wfPeerContext);
	client->ContextNew = (psPeerContextNew) wf_peer_context_new;
	client->ContextFree = (psPeerContextFree) wf_peer_context_free;
	
	freerdp_peer_context_new(client);

	wfi = ((wfPeerContext*) client->context)->info;

	wf_info_lock(wfi);

	if (wfi->threadCount < 1)
	{
		if (CreateThread(NULL, 0, wf_peer_mirror_monitor, client, 0, NULL) != 0)
		{
			wfi->threadCount++;
			printf("started monitor thread\n");
		}
		else
		{
			_tprintf(_T("failed to create monitor thread\n"));
		}
	}

	wf_info_unlock(wfi);
}
Esempio n. 4
0
BOOL wf_info_peer_register(wfInfo* wfi, wfPeerContext* context)
{
	int i;
	int peerId;

	if (!wfi || !context)
		return FALSE;

	if (!wf_info_lock(wfi))
		return FALSE;

	if (wfi->peerCount == WF_INFO_MAXPEERS)
		goto fail_peer_count;

	context->info = wfi;
	if (!(context->updateEvent = CreateEvent(NULL, TRUE, FALSE, NULL)))
		goto fail_update_event;

	//get the offset of the top left corner of selected screen
	EnumDisplayMonitors(NULL, NULL, wf_info_monEnumCB, 0);
	_IDcount = 0;

#ifdef WITH_DXGI_1_2
	if (wfi->peerCount == 0)
		if (wf_dxgi_init(wfi) != 0)
			goto fail_driver_init;
#else
	if (!wf_mirror_driver_activate(wfi))
		goto fail_driver_init;
#endif
	//look through the array of peers until an empty slot
	for (i = 0; i < WF_INFO_MAXPEERS; ++i)
	{
		//empty index will be our peer id
		if (wfi->peers[i] == NULL)
		{
			peerId = i;
			break;
		}
	}

	wfi->peers[peerId] = ((rdpContext*) context)->peer;
	wfi->peers[peerId]->pId = peerId;
	wfi->peerCount++;

	WLog_INFO(TAG, "Registering Peer: id=%d #=%d", peerId, wfi->peerCount);
	wf_info_unlock(wfi);
	wfreerdp_server_peer_callback_event(peerId, WF_SRV_CALLBACK_EVENT_CONNECT);

	return TRUE;

fail_driver_init:
	CloseHandle(context->updateEvent);
	context->updateEvent = NULL;
fail_update_event:
fail_peer_count:
	context->socketClose = TRUE;
	wf_info_unlock(wfi);
	return FALSE;
}
Esempio n. 5
0
void wf_info_peer_register(wfInfo* wfi, wfPeerContext* context)
{
    if (wf_info_lock(wfi) > 0)
    {
        int i;
        int peerId;
        if (wfi->peerCount == WF_INFO_MAXPEERS)
        {
            context->socketClose = TRUE;
            wf_info_unlock(wfi);
            return;
        }

        context->info = wfi;
        context->updateEvent = CreateEvent(NULL, TRUE, FALSE, NULL);

        //get the offset of the top left corner of selected screen
        EnumDisplayMonitors(NULL, NULL, wf_info_monEnumCB, 0);
        _IDcount = 0;

#ifdef WITH_WIN8
        if (wfi->peerCount == 0)
            wf_dxgi_init(wfi);
#else
        if (wf_mirror_driver_activate(wfi) == FALSE)
        {
            context->socketClose = TRUE;
            wf_info_unlock(wfi);
            return;
        }
#endif
        //look trhough the array of peers until an empty slot
        for(i=0; i<WF_INFO_MAXPEERS; ++i)
        {
            //empty index will be our peer id
            if (wfi->peers[i] == NULL)
            {
                peerId = i;
                break;
            }
        }

        wfi->peers[peerId] = ((rdpContext*) context)->peer;
        wfi->peers[peerId]->pId = peerId;
        wfi->peerCount++;
        printf("Registering Peer: id=%d #=%d\n", peerId, wfi->peerCount);

        wf_info_unlock(wfi);

        wfreerdp_server_peer_callback_event(peerId, WF_SRV_CALLBACK_EVENT_CONNECT);
    }
}
Esempio n. 6
0
DWORD WINAPI wf_update_thread(LPVOID lpParam)
{
    int index;
    DWORD fps;
    wfInfo* wfi;
    DWORD beg, end;
    DWORD diff, rate;

    wfi = (wfInfo*) lpParam;

    fps = wfi->framesPerSecond;
    rate = 1000 / fps;

    while (1)
    {
        beg = GetTickCount();

        if (wf_info_lock(wfi) > 0)
        {
            if (wfi->peerCount > 0)
            {
                wf_info_update_changes(wfi);

                if (wf_info_have_updates(wfi))
                {
                    wf_update_encode(wfi);

                    for (index = 0; index < wfi->peerCount; index++)
                        SetEvent(wfi->peers[index]->updateEvent);

                    for (index = 0; index < wfi->peerCount; index++)
                        WaitForSingleObject(wfi->updateSemaphore, INFINITE);

                    wfi->lastUpdate = wfi->nextUpdate;
                }
            }

            wf_info_unlock(wfi);
        }

        end = GetTickCount();
        diff = end - beg;

        if (diff < rate)
        {
            Sleep(rate - diff);
        }
    }

    return 0;
}
Esempio n. 7
0
void wf_update_peer_activate(wfInfo* wfi, wfPeerContext* context)
{
	if (wf_info_lock(wfi) > 0)
	{
		if (wfi->activePeerCount < 1)
		{
#ifndef WITH_WIN8
			wf_mirror_driver_activate(wfi);
#endif
			ResumeThread(wfi->updateThread);
		}

		wf_update_encoder_reset(wfi);
		wfi->activePeerCount++;

		printf("Activating Peer Updates: %d\n", wfi->activePeerCount);

		wf_info_unlock(wfi);
	}
}
Esempio n. 8
0
void wf_update_peer_deactivate(wfInfo* wfi, wfPeerContext* context)
{
	if (wf_info_lock(wfi) > 0)
	{
		freerdp_peer* client = ((rdpContext*) context)->peer;

		if (client->activated)
		{
			if (wfi->activePeerCount <= 1)
			{
				wf_mirror_driver_deactivate(wfi);
			}

			client->activated = FALSE;
			wfi->activePeerCount--;

			printf("Deactivating Peer Updates: %d\n", wfi->activePeerCount);
		}

		wf_info_unlock(wfi);
	}
}
Esempio n. 9
0
void wf_info_peer_unregister(wfInfo* wfi, wfPeerContext* context)
{
	if (wf_info_lock(wfi) > 0)
	{
		int peerId;

		peerId = ((rdpContext*) context)->peer->pId;
		wfi->peers[peerId] = NULL;
		wfi->peerCount--;
		CloseHandle(context->updateEvent);
		WLog_INFO(TAG, "Unregistering Peer: id=%d, #=%d", peerId, wfi->peerCount);

#ifdef WITH_DXGI_1_2
		if (wfi->peerCount == 0)
			wf_dxgi_cleanup(wfi);
#endif

		wf_info_unlock(wfi);

		wfreerdp_server_peer_callback_event(peerId, WF_SRV_CALLBACK_EVENT_DISCONNECT);
	}
}
Esempio n. 10
0
DWORD WINAPI wf_update_thread(LPVOID lpParam)
{
	int index;
	DWORD fps;
	wfInfo* wfi;
	DWORD beg, end;
	DWORD diff, rate;

	wfi = (wfInfo*) lpParam;

	fps = wfi->framesPerSecond;
	rate = 1000 / fps;

	while (1)
	{
		beg = GetTickCount();

		if (wf_info_lock(wfi) > 0)
		{
			if (wfi->activePeerCount > 0)
			{
				wf_info_update_changes(wfi);

				if (wf_info_have_updates(wfi))
				{
					wf_update_encode(wfi);

					//printf("Start of parallel sending\n");

					for (index = 0; index < wfi->peerCount; index++)
					{
						if (wfi->peers[index]->activated)
						{
							//printf("Setting event for %d of %d\n", index + 1, wfi->activePeerCount);
							SetEvent(((wfPeerContext*) wfi->peers[index]->context)->updateEvent);
						}
					}

					for (index = 0; index < wfi->activePeerCount; index++)
					{
						//printf("Waiting for %d of %d\n", index + 1, wfi->activePeerCount);
						WaitForSingleObject(wfi->updateSemaphore, INFINITE);
					}

					//printf("End of parallel sending\n");

					wf_info_clear_invalid_region(wfi);
				}
			}

			wf_info_unlock(wfi);
		}

		end = GetTickCount();
		diff = end - beg;

		if (diff < rate)
		{
			Sleep(rate - diff);
		}
	}

	//printf("Exiting Update Thread\n");

	return 0;
}