From edf5971cefc98695503dca3fee2d47cd849e56c3 Mon Sep 17 00:00:00 2001 From: Laxmikant Rashinkar Date: Fri, 9 Nov 2012 19:55:21 -0800 Subject: [PATCH] o in login dialog set sesman-X11rdp as the default module o added support for video redirection without using TSMF --- Makefile.am | 3 +- configure.ac | 1 + sesman/chansrv/chansrv.c | 8 +++- xrdp/xrdp.ini | 28 ++++++------ xrdpapi/simple.c | 15 ++++--- xrdpapi/vrplayer.c | 95 ++++++++++++++++++++++++++++++++++++++++ xrdpapi/vrplayer.mk | 5 +++ xrdpapi/xrdpapi.c | 59 +++++++++++++------------ xrdpapi/xrdpapi.h | 29 ++++++------ 9 files changed, 179 insertions(+), 64 deletions(-) create mode 100644 xrdpapi/vrplayer.c create mode 100644 xrdpapi/vrplayer.mk diff --git a/Makefile.am b/Makefile.am index d5ac84b1..134afce4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -20,4 +20,5 @@ SUBDIRS = \ docs \ instfiles \ genkeymap \ - xrdpapi + xrdpapi \ + xrdpvr diff --git a/configure.ac b/configure.ac index b29ce965..610b7e19 100644 --- a/configure.ac +++ b/configure.ac @@ -122,6 +122,7 @@ AC_CONFIG_FILES([Makefile instfiles/pam.d/Makefile genkeymap/Makefile xrdpapi/Makefile + xrdpvr/Makefile ]) # fontdump/Makefile # xrdp/cursors/Makefile diff --git a/sesman/chansrv/chansrv.c b/sesman/chansrv/chansrv.c index 836a693b..8bcdb62b 100644 --- a/sesman/chansrv/chansrv.c +++ b/sesman/chansrv/chansrv.c @@ -695,7 +695,6 @@ my_api_trans_conn_in(struct trans *trans, struct trans *new_trans) int index; char chan_pri; - g_writeln("my_api_trans_conn_in:"); if ((trans == 0) || (trans != g_api_lis_trans) || (new_trans == 0)) { return 1; @@ -750,7 +749,8 @@ my_api_trans_conn_in(struct trans *trans, struct trans *new_trans) for (index = 0; index < g_num_chan_items; index++) { - LOG(10, (" %s %s", ad->header, g_chan_items[index].name)); + LOG(10, ("my_api_trans_conn_in: %s %s", ad->header, + g_chan_items[index].name)); if (g_strcasecmp(ad->header, g_chan_items[index].name) == 0) { @@ -759,6 +759,10 @@ my_api_trans_conn_in(struct trans *trans, struct trans *new_trans) break; } } + if (index == g_num_chan_items) + { + g_writeln("did not find SVC named %s", ad->header); + } } new_trans->callback_data = ad; diff --git a/xrdp/xrdp.ini b/xrdp/xrdp.ini index 963b75d9..58daa6af 100644 --- a/xrdp/xrdp.ini +++ b/xrdp/xrdp.ini @@ -42,8 +42,18 @@ rdpsnd=true drdynvc=true cliprdr=true rail=true +xrdpvr=true [xrdp1] +name=sesman-X11rdp +lib=libxup.so +username=ask +password=ask +ip=127.0.0.1 +port=-1 +xserverbpp=24 + +[xrdp2] name=sesman-Xvnc lib=libvnc.so username=ask @@ -51,7 +61,7 @@ password=ask ip=127.0.0.1 port=-1 -[xrdp2] +[xrdp3] name=console lib=libvnc.so ip=127.0.0.1 @@ -59,7 +69,7 @@ port=5900 username=na password=ask -[xrdp3] +[xrdp4] name=vnc-any lib=libvnc.so ip=ask @@ -70,7 +80,7 @@ password=ask #pampassword=asksame #pamsessionmng=127.0.0.1 -[xrdp4] +[xrdp5] name=sesman-any lib=libvnc.so ip=ask @@ -78,13 +88,13 @@ port=-1 username=ask password=ask -[xrdp5] +[xrdp6] name=rdp-any lib=librdp.so ip=ask port=ask3389 -[xrdp6] +[xrdp7] name=freerdp-any lib=libxrdpfreerdp1.so ip=ask @@ -92,11 +102,3 @@ port=ask3389 username=ask password=ask -[xrdp7] -name=sesman-X11rdp -lib=libxup.so -username=ask -password=ask -ip=127.0.0.1 -port=-1 -xserverbpp=24 diff --git a/xrdpapi/simple.c b/xrdpapi/simple.c index e6f5bd16..afe1a22c 100644 --- a/xrdpapi/simple.c +++ b/xrdpapi/simple.c @@ -101,6 +101,7 @@ run_echo_test() /* open a virtual channel named ECHO */ channel = WTSVirtualChannelOpenEx(WTS_CURRENT_SESSION, "ECHO", WTS_CHANNEL_OPTION_DYNAMIC_PRI_LOW); + if (channel == NULL) { printf("### WTSVirtualChannelOpenEx() failed!\n"); @@ -117,6 +118,7 @@ run_echo_test() /* write data to virtual channel */ count = (bytes_left > 1700) ? 1700 : bytes_left; rv = WTSVirtualChannelWrite(channel, wr_ptr, count, &bytes_written); + if ((rv == 0) || (bytes_written == 0)) { printf("### WTSVirtualChannelWrite() failed\n"); @@ -129,6 +131,7 @@ run_echo_test() { /* read back the echo */ rv = WTSVirtualChannelRead(channel, 5000, in_buf, count, &bytes_read); + if ((rv == 0) || (bytes_read == 0)) { printf("### WTSVirtualChannelRead() failed\n"); @@ -145,6 +148,7 @@ run_echo_test() return -1; } } + count -= bytes_read; } @@ -153,26 +157,27 @@ run_echo_test() printf("### pkt %d passed echo test\n", pkt_count++); } - WTSVirtualChannelClose(channel); - return 0; + WTSVirtualChannelClose(channel); + return 0; } int run_tsmf_test() { - void *channel; + void *channel; printf("this test not yet implemented!\n"); return 1; /* open virtual channel */ channel = WTSVirtualChannelOpenEx(WTS_CURRENT_SESSION, "TSMF", WTS_CHANNEL_OPTION_DYNAMIC_PRI_LOW); + if (channel == NULL) { printf("### WTSVirtualChannelOpenEx() failed!\n"); return 1; } - WTSVirtualChannelClose(channel); - return 0; + WTSVirtualChannelClose(channel); + return 0; } diff --git a/xrdpapi/vrplayer.c b/xrdpapi/vrplayer.c new file mode 100644 index 00000000..442ef35e --- /dev/null +++ b/xrdpapi/vrplayer.c @@ -0,0 +1,95 @@ +/** + * xrdp: A Remote Desktop Protocol server. + * + * Copyright (C) Laxmikant Rashinkar 2012 LK.Rashinkar@gmail.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * a program that uses xrdpapi and ffmpeg to redirect media streams + * to a FreeRDP client where it is decompressed and played locally + * + */ + +/****************************************************************************** + * build instructions: make -f vrplayer.mk + * setup environment: export LD_LIBRARY_PATH=".libs:../xrdpvr/.libs" + * run vrplayer: vrplayer + *****************************************************************************/ + +#ifdef __WIN32__ +#include +#endif + +#include +#include +#include +#include +#include +#include + +#include "xrdpapi.h" +#include "xrdpvr.h" + +void +extract_32(uint32_t *value, char *buf) +{ + *value = ((buf[3] << 24) & 0xff000000) + | ((buf[2] << 16) & 0x00ff0000) + | ((buf[1] << 8) & 0x0000ff00) + | (buf[0] & 0x000000ff); +} + +int +main(int argc, char **argv) +{ + char *data; + char *data1; + void *channel; + int written = 0; + int rv; + int first_time = 1; + int length; + int bytes_read; + + if (argc < 2) + { + printf("usage: vrplayer >\n"); + return 1; + } + + /* open a virtual channel and connect to remote client */ + channel = WTSVirtualChannelOpenEx(WTS_CURRENT_SESSION, "xrdpvr", 0); + + if (channel == NULL) + { + fprintf(stderr, "WTSVirtualChannelOpenEx() failed\n"); + return 1; + } + + /* initialize the player */ + if (xrdpvr_init_player(channel, 101, argv[1])) + { + fprintf(stderr, "failed to initialize the player\n"); + return 1; + } + + /* send compressed media data to client; client will decompress */ + /* the media and play it locally */ + xrdpvr_play_media(channel, 101, argv[1]); + + /* perform clean up */ + xrdpvr_deinit_player(channel, 101); + + WTSVirtualChannelClose(channel); + return 0; +} diff --git a/xrdpapi/vrplayer.mk b/xrdpapi/vrplayer.mk new file mode 100644 index 00000000..15daf0f6 --- /dev/null +++ b/xrdpapi/vrplayer.mk @@ -0,0 +1,5 @@ +CFLAGS = -I../xrdpvr +LIBS = -L./.libs -L../xrdpvr/.libs -lxrdpapi -lxrdpvr -lavformat + +vrplayer: vrplayer.o + gcc $(CFLAGS) vrplayer.c -o vrplayer $(LIBS) diff --git a/xrdpapi/xrdpapi.c b/xrdpapi/xrdpapi.c index e320ef5d..973deb48 100644 --- a/xrdpapi/xrdpapi.c +++ b/xrdpapi/xrdpapi.c @@ -152,57 +152,57 @@ WTSVirtualChannelOpenEx(unsigned int SessionId, const char *pVirtualName, return wts; } +/* + * write data to client connection + * + * @return 0 on success, -1 on error /*****************************************************************************/ int WTSVirtualChannelWrite(void *hChannelHandle, const char *Buffer, unsigned int Length, unsigned int *pBytesWritten) { struct wts_obj *wts; - int error; - int lerrno; + int rv; - wts = (struct wts_obj *)hChannelHandle; + wts = (struct wts_obj *) hChannelHandle; + + *pBytesWritten = 0; if (wts == 0) { - return 0; + LLOGLN(10, ("WTSVirtualChannelWrite: wts is NULL")); + return -1; } if (wts->status != 1) { - return 0; + LLOGLN(10, ("WTSVirtualChannelWrite: wts->status != 1")); + return -1; } - if (can_send(wts->fd, 0)) + if (!can_send(wts->fd, 0)) { - error = send(wts->fd, Buffer, Length, 0); + return 0; /* can't write now, ok to try again */ + } - if (error == -1) - { - lerrno = errno; + rv = send(wts->fd, Buffer, Length, 0); + LLOGLN(10, ("WTSVirtualChannelWrite: send() reted %d", rv)); - if ((lerrno == EWOULDBLOCK) || (lerrno == EAGAIN) || - (lerrno == EINPROGRESS)) - { - *pBytesWritten = 0; - return 1; - } + if (rv >= 0) + { + /* success, but zero bytes may have been written */ + *pBytesWritten = rv; + return 0; + } - return 0; - } - else if (error == 0) - { - return 0; - } - else if (error > 0) - { - *pBytesWritten = error; - return 1; - } + /* error, but is it ok to try again? */ + if ((rv == EWOULDBLOCK) || (rv == EAGAIN) || (rv == EINPROGRESS)) + { + return 0; /* failed to send, but should try again */ } - *pBytesWritten = 0; - return 1; + /* fatal error */ + return -1; } /*****************************************************************************/ @@ -241,6 +241,7 @@ WTSVirtualChannelRead(void *hChannelHandle, unsigned int TimeOut, *pBytesRead = 0; return 1; } + return 0; } else if (rv == 0) diff --git a/xrdpapi/xrdpapi.h b/xrdpapi/xrdpapi.h index fdb998cf..81e5acd5 100644 --- a/xrdpapi/xrdpapi.h +++ b/xrdpapi/xrdpapi.h @@ -45,32 +45,33 @@ typedef enum _WTS_VIRTUAL_CLASS { WTSVirtualClientData, WTSVirtualFileHandle -} WTS_VIRTUAL_CLASS; +} +WTS_VIRTUAL_CLASS; /* * Reference: * http://msdn.microsoft.com/en-us/library/windows/desktop/aa383464(v=vs.85).aspx */ -void* WTSVirtualChannelOpen(void* hServer, unsigned int SessionId, - const char* pVirtualName); +void *WTSVirtualChannelOpen(void *hServer, unsigned int SessionId, + const char *pVirtualName); -void* WTSVirtualChannelOpenEx(unsigned int SessionId, - const char* pVirtualName, unsigned int flags); +void *WTSVirtualChannelOpenEx(unsigned int SessionId, + const char *pVirtualName, unsigned int flags); -int WTSVirtualChannelWrite(void* hChannelHandle, const char* Buffer, - unsigned int Length, unsigned int* pBytesWritten); +int WTSVirtualChannelWrite(void *hChannelHandle, const char *Buffer, + unsigned int Length, unsigned int *pBytesWritten); -int WTSVirtualChannelRead(void* hChannelHandle, unsigned int TimeOut, - char* Buffer, unsigned int BufferSize, - unsigned int* pBytesRead); +int WTSVirtualChannelRead(void *hChannelHandle, unsigned int TimeOut, + char *Buffer, unsigned int BufferSize, + unsigned int *pBytesRead); -int WTSVirtualChannelClose(void* hChannelHandle); +int WTSVirtualChannelClose(void *hChannelHandle); -int WTSVirtualChannelQuery(void* hChannelHandle, WTS_VIRTUAL_CLASS WtsVirtualClass, - void** ppBuffer, unsigned int* pBytesReturned); +int WTSVirtualChannelQuery(void *hChannelHandle, WTS_VIRTUAL_CLASS WtsVirtualClass, + void **ppBuffer, unsigned int *pBytesReturned); -void WTSFreeMemory(void* pMemory); +void WTSFreeMemory(void *pMemory); #ifdef __cplusplus }